diff --git a/stubs/D3DShot/METADATA.toml b/stubs/D3DShot/METADATA.toml new file mode 100644 index 000000000000..d6bdd1ba0ba9 --- /dev/null +++ b/stubs/D3DShot/METADATA.toml @@ -0,0 +1,7 @@ +version = "0.1.*" +requires = ["types-Pillow"] + +[tool.stubtest] +# The library only works on Windows; we currently only run stubtest on Ubuntu for third-party stubs in CI. +# See #8660 +skip = true diff --git a/stubs/D3DShot/d3dshot/__init__.pyi b/stubs/D3DShot/d3dshot/__init__.pyi new file mode 100644 index 000000000000..17f1dd8e9f27 --- /dev/null +++ b/stubs/D3DShot/d3dshot/__init__.pyi @@ -0,0 +1,12 @@ +from d3dshot.capture_output import CaptureOutputs as CaptureOutputs +from d3dshot.d3dshot import D3DShot as D3DShot + +pil_is_available: bool +numpy_is_available: bool +pytorch_is_available: bool +pytorch_gpu_is_available: bool +capture_output_mapping: dict[str, CaptureOutputs] +capture_outputs: list[str] + +def determine_available_capture_outputs() -> list[CaptureOutputs]: ... +def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ... diff --git a/stubs/D3DShot/d3dshot/capture_output.pyi b/stubs/D3DShot/d3dshot/capture_output.pyi new file mode 100644 index 000000000000..aa68b092eb20 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_output.pyi @@ -0,0 +1,44 @@ +import enum +from _typeshed import Incomplete +from collections.abc import Sequence +from ctypes import _CVoidConstPLike +from typing_extensions import Literal, TypeAlias + +from PIL import Image + +_Frame: TypeAlias = Image.Image | Incomplete +# TODO: Complete types once we can import non-types dependencies +# See: #5768 +# from torch import Tensor +# from comtypes import IUnknown +# import numpy.typing as npt +# _Frame: TypeAlias = Image.Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | Tensor + +class CaptureOutputs(enum.Enum): + PIL: int + NUMPY: int + NUMPY_FLOAT: int + PYTORCH: int + PYTORCH_FLOAT: int + PYTORCH_GPU: int + PYTORCH_FLOAT_GPU: int + +class CaptureOutputError(BaseException): ... + +# All CaptureOutput methods just reference the backend. Making this both a base class and a wrapper. +class CaptureOutput: + # `backend` is a subclass of CaptureOutput based on the CaptureOutputs enum passed to __init__ + backend: CaptureOutput + def __init__(self, backend: CaptureOutputs = ...) -> None: ... + def process( + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, + ) -> _Frame: ... + def to_pil(self, frame: _Frame) -> Image.Image: ... + def stack(self, frames: Sequence[_Frame], stack_dimension: Literal["first", "last"]) -> _Frame: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/__init__.pyi b/stubs/D3DShot/d3dshot/capture_outputs/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi new file mode 100644 index 000000000000..083eeb798560 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -0,0 +1,29 @@ +from _typeshed import Incomplete +from collections.abc import Sequence +from ctypes import _CVoidConstPLike +from typing_extensions import Literal, TypeAlias + +from d3dshot.capture_output import CaptureOutput +from PIL import Image + +# TODO: Complete types once we can import non-types dependencies +# See: #5768 +# import numpy as np +# import numpy.typing as npt +# _NDArray: TypeAlias = npt.NDArray[np.int32] +_NDArray: TypeAlias = Incomplete + +class NumpyCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, + ) -> _NDArray: ... + def to_pil(self, frame: _NDArray) -> Image.Image: ... + def stack(self, frames: Sequence[_NDArray] | _NDArray, stack_dimension: Literal["first", "last"]) -> _NDArray: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi new file mode 100644 index 000000000000..49d4e5d7ea75 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -0,0 +1,5 @@ +from d3dshot.capture_outputs.numpy_capture_output import NumpyCaptureOutput + +# TODO: Once we can import non-types dependencies, this CaptureOutput should be float based +# See: #5768 +class NumpyFloatCaptureOutput(NumpyCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi new file mode 100644 index 000000000000..0a593d73357d --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pil_capture_output.pyi @@ -0,0 +1,25 @@ +from collections.abc import Sequence +from ctypes import _CVoidConstPLike +from typing import TypeVar +from typing_extensions import TypeAlias + +from d3dshot.capture_output import CaptureOutput +from PIL import Image + +_Unused: TypeAlias = object +_ImageT = TypeVar("_ImageT", bound=Image.Image) + +class PILCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, + ) -> Image.Image: ... + def to_pil(self, frame: _ImageT) -> _ImageT: ... + def stack(self, frames: Sequence[_ImageT], stack_dimension: _Unused) -> Sequence[_ImageT]: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi new file mode 100644 index 000000000000..4498bd52f01a --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -0,0 +1,27 @@ +from _typeshed import Incomplete +from collections.abc import Sequence +from ctypes import _CVoidConstPLike +from typing_extensions import Literal, TypeAlias + +from d3dshot.capture_output import CaptureOutput +from PIL import Image + +# TODO: Complete types once we can import non-types dependencies +# See: https://github.com/python/typeshed/issues/5768 +# from torch import Tensor +_Tensor: TypeAlias = Incomplete + +class PytorchCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + def process( + self, + pointer: _CVoidConstPLike, + pitch: int, + size: int, + width: int, + height: int, + region: tuple[int, int, int, int], + rotation: int, + ) -> _Tensor: ... + def to_pil(self, frame: _Tensor) -> Image.Image: ... + def stack(self, frames: Sequence[_Tensor], stack_dimension: Literal["first", "last"]) -> _Tensor: ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi new file mode 100644 index 000000000000..53e7a73d7a51 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -0,0 +1,3 @@ +from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput + +class PytorchFloatCaptureOutput(PytorchCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi new file mode 100644 index 000000000000..2e7c6c105a12 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -0,0 +1,3 @@ +from d3dshot.capture_outputs.pytorch_gpu_capture_output import PytorchGPUCaptureOutput + +class PytorchFloatGPUCaptureOutput(PytorchGPUCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi new file mode 100644 index 000000000000..d78cc60eb247 --- /dev/null +++ b/stubs/D3DShot/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -0,0 +1,3 @@ +from d3dshot.capture_outputs.pytorch_capture_output import PytorchCaptureOutput + +class PytorchGPUCaptureOutput(PytorchCaptureOutput): ... diff --git a/stubs/D3DShot/d3dshot/d3dshot.pyi b/stubs/D3DShot/d3dshot/d3dshot.pyi new file mode 100644 index 000000000000..5424517ee80c --- /dev/null +++ b/stubs/D3DShot/d3dshot/d3dshot.pyi @@ -0,0 +1,45 @@ +from collections import deque +from collections.abc import Iterable + +from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs, _Frame +from d3dshot.display import Display as Display + +class Singleton(type): ... + +class D3DShot(metaclass=Singleton): + displays: list[Display] + display: Display + capture_output: CaptureOutput + frame_buffer_size: int + frame_buffer: deque[_Frame] + previous_screenshot: _Frame | None + region: tuple[int, int, int, int] | None + + def __init__( + self, + capture_output: CaptureOutputs = ..., + frame_buffer_size: int = ..., + pil_is_available: bool = ..., + numpy_is_available: bool = ..., + pytorch_is_available: bool = ..., + pytorch_gpu_is_available: bool = ..., + ) -> None: ... + @property + def is_capturing(self) -> bool: ... + def get_latest_frame(self) -> _Frame | None: ... + def get_frame(self, frame_index: int) -> _Frame | None: ... + def get_frames(self, frame_indices: Iterable[int]) -> list[_Frame]: ... + def get_frame_stack(self, frame_indices: Iterable[int], stack_dimension: str | None = ...) -> _Frame: ... + def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> _Frame | None: ... + def screenshot_to_disk( + self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ... + ) -> str: ... + def frame_buffer_to_disk(self, directory: str | None = ...) -> None: ... + def capture(self, target_fps: int = ..., region: tuple[int, int, int, int] | None = ...) -> bool: ... + def screenshot_every(self, interval: float, region: tuple[int, int, int, int] | None = ...) -> bool: ... + def screenshot_to_disk_every( + self, interval: float, directory: str | None = ..., region: tuple[int, int, int, int] | None = ... + ) -> bool: ... + def stop(self) -> bool: ... + def benchmark(self) -> None: ... + def detect_displays(self) -> None: ... diff --git a/stubs/D3DShot/d3dshot/display.pyi b/stubs/D3DShot/d3dshot/display.pyi new file mode 100644 index 000000000000..fb30dd2b50c8 --- /dev/null +++ b/stubs/D3DShot/d3dshot/display.pyi @@ -0,0 +1,49 @@ +from ctypes import _Pointer +from typing_extensions import TypedDict + +from d3dshot.dll import _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn +from d3dshot.dll.d3d import ID3D11Device, ID3D11DeviceContext +from d3dshot.dll.dxgi import IDXGIAdapter, IDXGIOutput1, IDXGIOutputDuplication + +class _PositionDict(TypedDict): + left: int + top: int + right: int + bottom: int + +class Display: + name: str + adapter_name: str + resolution: tuple[int, int] + position: _PositionDict + rotation: int + scale_factor: float + is_primary: bool + hmonitor: int + dxgi_output: IDXGIOutput1 | None + dxgi_adapter: _Pointer[IDXGIAdapter] | None + # Note that Display.d3d_device and Display.d3d_device_context can never be None. + # Despite initially being set to None in __init__, + # they're always immediately set in _initialize_dxgi_output_duplication() + d3d_device: ID3D11Device + d3d_device_context: ID3D11DeviceContext + dxgi_output_duplication: _Pointer[IDXGIOutputDuplication] + + def __init__( + self, + name: str | None = ..., + adapter_name: str | None = ..., + resolution: tuple[int, int] | None = ..., + position: _PositionDict | None = ..., + rotation: int | None = ..., + scale_factor: float | None = ..., + is_primary: bool = ..., + hmonitor: int | None = ..., + dxgi_output: IDXGIOutput1 | None = ..., + dxgi_adapter: _Pointer[IDXGIAdapter] | None = ..., + ) -> None: ... + def capture( + self, process_func: _ProcessFunc[_ProcessFuncRegionArg, _ProcessFuncReturn] | None, region: _ProcessFuncRegionArg = ... + ) -> _ProcessFuncReturn: ... + @classmethod + def discover_displays(cls) -> list[Display]: ... diff --git a/stubs/D3DShot/d3dshot/dll/__init__.pyi b/stubs/D3DShot/d3dshot/dll/__init__.pyi new file mode 100644 index 000000000000..56e0e35b58ae --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/__init__.pyi @@ -0,0 +1,28 @@ +import sys +from _typeshed import Incomplete +from collections.abc import Callable +from ctypes import _CData, c_ulong +from ctypes.wintypes import PFLOAT +from typing import TypeVar +from typing_extensions import TypeAlias + +from d3dshot.capture_output import _Frame + +_ProcessFuncRegionArg = TypeVar("_ProcessFuncRegionArg", tuple[int, int, int, int], None) +_ProcessFuncReturn = TypeVar("_ProcessFuncReturn", _Frame, None) +# The _ProcessFunc alias is used in multiple submodules +_ProcessFunc: TypeAlias = Callable[[PFLOAT, int, int, int, int, _ProcessFuncRegionArg, int], _ProcessFuncReturn] # noqa: Y047 + +if sys.platform == "win32": + from ctypes import HRESULT + + _HRESULT: TypeAlias = HRESULT +else: + _HRESULT: TypeAlias = Incomplete + +# TODO: Use comtypes.IUnknown once we can import non-types dependencies +# See: #5768 +class _IUnknown(_CData): + def QueryInterface(self, interface: type, iid: _CData | None = ...) -> _HRESULT: ... + def AddRef(self) -> c_ulong: ... + def Release(self) -> c_ulong: ... diff --git a/stubs/D3DShot/d3dshot/dll/d3d.pyi b/stubs/D3DShot/d3dshot/dll/d3d.pyi new file mode 100644 index 000000000000..e412c2dbbeca --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/d3d.pyi @@ -0,0 +1,214 @@ +from ctypes import Structure, _Pointer, c_int32, c_uint, c_void_p +from ctypes.wintypes import FLOAT, UINT + +from d3dshot.dll import _HRESULT, _IUnknown +from d3dshot.dll.dxgi import IDXGIAdapter + +class DXGI_SAMPLE_DESC(Structure): + Count: UINT + Quality: UINT + +class D3D11_BOX(Structure): + left: UINT + top: UINT + front: UINT + right: UINT + bottom: UINT + back: UINT + +class D3D11_TEXTURE2D_DESC(Structure): + Width: UINT + Height: UINT + MipLevels: UINT + ArraySize: UINT + Format: UINT + SampleDesc: DXGI_SAMPLE_DESC + Usage: UINT + BindFlags: UINT + CPUAccessFlags: UINT + MiscFlags: UINT + +class ID3D11DeviceChild(_IUnknown): + def GetDevice(self) -> None: ... + def GetPrivateData(self) -> _HRESULT: ... + def SetPrivateData(self) -> _HRESULT: ... + def SetPrivateDataInterface(self) -> _HRESULT: ... + +class ID3D11Resource(ID3D11DeviceChild): + def GetType(self) -> None: ... + def SetEvictionPriority(self) -> None: ... + def GetEvictionPriority(self) -> UINT: ... + +class ID3D11Texture2D(ID3D11Resource): + def GetDesc(self, __pDesc: _Pointer[D3D11_TEXTURE2D_DESC]) -> None: ... + +class ID3D11DeviceContext(ID3D11DeviceChild): + def VSSetConstantBuffers(self) -> None: ... + def PSSetShaderResources(self) -> None: ... + def PSSetShader(self) -> None: ... + def PSSetSamplers(self) -> None: ... + def VSSetShader(self) -> None: ... + def DrawIndexed(self) -> None: ... + def Draw(self) -> None: ... + def Map(self) -> _HRESULT: ... + def Unmap(self) -> None: ... + def PSSetConstantBuffers(self) -> None: ... + def IASetInputLayout(self) -> None: ... + def IASetVertexBuffers(self) -> None: ... + def IASetIndexBuffer(self) -> None: ... + def DrawIndexedInstanced(self) -> None: ... + def DrawInstanced(self) -> None: ... + def GSSetConstantBuffers(self) -> None: ... + def GSSetShader(self) -> None: ... + def IASetPrimitiveTopology(self) -> None: ... + def VSSetShaderResources(self) -> None: ... + def VSSetSamplers(self) -> None: ... + def Begin(self) -> None: ... + def End(self) -> None: ... + def GetData(self) -> _HRESULT: ... + def SetPredication(self) -> None: ... + def GSSetShaderResources(self) -> None: ... + def GSSetSamplers(self) -> None: ... + def OMSetRenderTargets(self) -> None: ... + def OMSetRenderTargetsAndUnorderedAccessViews(self) -> None: ... + def OMSetBlendState(self) -> None: ... + def OMSetDepthStencilState(self) -> None: ... + def SOSetTargets(self) -> None: ... + def DrawAuto(self) -> None: ... + def DrawIndexedInstancedIndirect(self) -> None: ... + def DrawInstancedIndirect(self) -> None: ... + def Dispatch(self) -> None: ... + def DispatchIndirect(self) -> None: ... + def RSSetState(self) -> None: ... + def RSSetViewports(self) -> None: ... + def RSSetScissorRects(self) -> None: ... + def CopySubresourceRegion( + self, + __pDstResource: _Pointer[ID3D11Resource], + __DstSubresource: UINT, + __DstX: UINT, + __DstY: UINT, + __DstZ: UINT, + __pSrcResource: _Pointer[ID3D11Resource], + __SrcSubresource: UINT, + __pSrcBox: _Pointer[D3D11_BOX], + ) -> None: ... + def CopyResource(self, __pDstResource: _Pointer[ID3D11Resource], __pSrcResource: _Pointer[ID3D11Resource]) -> None: ... + def UpdateSubresource(self) -> None: ... + def CopyStructureCount(self) -> None: ... + def ClearRenderTargetView(self) -> None: ... + def ClearUnorderedAccessViewUint(self) -> None: ... + def ClearUnorderedAccessViewFloat(self) -> None: ... + def ClearDepthStencilView(self) -> None: ... + def GenerateMips(self) -> None: ... + def SetResourceMinLOD(self) -> None: ... + def GetResourceMinLOD(self) -> FLOAT: ... + def ResolveSubresource(self) -> None: ... + def ExecuteCommandList(self) -> None: ... + def HSSetShaderResources(self) -> None: ... + def HSSetShader(self) -> None: ... + def HSSetSamplers(self) -> None: ... + def HSSetConstantBuffers(self) -> None: ... + def DSSetShaderResources(self) -> None: ... + def DSSetShader(self) -> None: ... + def DSSetSamplers(self) -> None: ... + def DSSetConstantBuffers(self) -> None: ... + def CSSetShaderResources(self) -> None: ... + def CSSetUnorderedAccessViews(self) -> None: ... + def CSSetShader(self) -> None: ... + def CSSetSamplers(self) -> None: ... + def CSSetConstantBuffers(self) -> None: ... + def VSGetConstantBuffers(self) -> None: ... + def PSGetShaderResources(self) -> None: ... + def PSGetShader(self) -> None: ... + def PSGetSamplers(self) -> None: ... + def VSGetShader(self) -> None: ... + def PSGetConstantBuffers(self) -> None: ... + def IAGetInputLayout(self) -> None: ... + def IAGetVertexBuffers(self) -> None: ... + def IAGetIndexBuffer(self) -> None: ... + def GSGetConstantBuffers(self) -> None: ... + def GSGetShader(self) -> None: ... + def IAGetPrimitiveTopology(self) -> None: ... + def VSGetShaderResources(self) -> None: ... + def VSGetSamplers(self) -> None: ... + def GetPredication(self) -> None: ... + def GSGetShaderResources(self) -> None: ... + def GSGetSamplers(self) -> None: ... + def OMGetRenderTargets(self) -> None: ... + def OMGetRenderTargetsAndUnorderedAccessViews(self) -> None: ... + def OMGetBlendState(self) -> None: ... + def OMGetDepthStencilState(self) -> None: ... + def SOGetTargets(self) -> None: ... + def RSGetState(self) -> None: ... + def RSGetViewports(self) -> None: ... + def RSGetScissorRects(self) -> None: ... + def HSGetShaderResources(self) -> None: ... + def HSGetShader(self) -> None: ... + def HSGetSamplers(self) -> None: ... + def HSGetConstantBuffers(self) -> None: ... + def DSGetShaderResources(self) -> None: ... + def DSGetShader(self) -> None: ... + def DSGetSamplers(self) -> None: ... + def DSGetConstantBuffers(self) -> None: ... + def CSGetShaderResources(self) -> None: ... + def CSGetUnorderedAccessViews(self) -> None: ... + def CSGetShader(self) -> None: ... + def CSGetSamplers(self) -> None: ... + def CSGetConstantBuffers(self) -> None: ... + def ClearState(self) -> None: ... + def Flush(self) -> None: ... + def GetType(self) -> None: ... + def GetContextFlags(self) -> UINT: ... + def FinishCommandList(self) -> _HRESULT: ... + +class ID3D11Device(_IUnknown): + def CreateBuffer(self) -> _HRESULT: ... + def CreateTexture1D(self) -> _HRESULT: ... + def CreateTexture2D( + self, + __pDesc: _Pointer[D3D11_TEXTURE2D_DESC], + __pInitialData: c_void_p, + __ppTexture2D: _Pointer[_Pointer[ID3D11Texture2D]], + ) -> _HRESULT: ... + def CreateTexture3D(self) -> _HRESULT: ... + def CreateShaderResourceView(self) -> _HRESULT: ... + def CreateUnorderedAccessView(self) -> _HRESULT: ... + def CreateRenderTargetView(self) -> _HRESULT: ... + def CreateDepthStencilView(self) -> _HRESULT: ... + def CreateInputLayout(self) -> _HRESULT: ... + def CreateVertexShader(self) -> _HRESULT: ... + def CreateGeometryShader(self) -> _HRESULT: ... + def CreateGeometryShaderWithStreamOutput(self) -> _HRESULT: ... + def CreatePixelShader(self) -> _HRESULT: ... + def CreateHullShader(self) -> _HRESULT: ... + def CreateDomainShader(self) -> _HRESULT: ... + def CreateComputeShader(self) -> _HRESULT: ... + def CreateClassLinkage(self) -> _HRESULT: ... + def CreateBlendState(self) -> _HRESULT: ... + def CreateDepthStencilState(self) -> _HRESULT: ... + def CreateRasterizerState(self) -> _HRESULT: ... + def CreateSamplerState(self) -> _HRESULT: ... + def CreateQuery(self) -> _HRESULT: ... + def CreatePredicate(self) -> _HRESULT: ... + def CreateCounter(self) -> _HRESULT: ... + def CreateDeferredContext(self) -> _HRESULT: ... + def OpenSharedResource(self) -> _HRESULT: ... + def CheckFormatSupport(self) -> _HRESULT: ... + def CheckMultisampleQualityLevels(self) -> _HRESULT: ... + def CheckCounterInfo(self) -> _HRESULT: ... + def CheckCounter(self) -> _HRESULT: ... + def CheckFeatureSupport(self) -> _HRESULT: ... + def GetPrivateData(self) -> _HRESULT: ... + def SetPrivateData(self) -> _HRESULT: ... + def SetPrivateDataInterface(self) -> _HRESULT: ... + def GetFeatureLevel(self) -> c_int32: ... + def GetCreationFlags(self) -> c_uint: ... + def GetDeviceRemovedReason(self) -> _HRESULT: ... + def GetImmediateContext(self, __ppImmediateContext: _Pointer[_Pointer[ID3D11DeviceContext]]) -> None: ... + def SetExceptionMode(self) -> _HRESULT: ... + def GetExceptionMode(self) -> c_uint: ... + +def initialize_d3d_device(dxgi_adapter: _Pointer[IDXGIAdapter]) -> tuple[ID3D11Device, ID3D11DeviceContext]: ... +def describe_d3d11_texture_2d(d3d11_texture_2d: ID3D11Texture2D) -> D3D11_TEXTURE2D_DESC: ... +def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: ID3D11Texture2D, d3d_device: ID3D11Device) -> ID3D11Texture2D: ... diff --git a/stubs/D3DShot/d3dshot/dll/dxgi.pyi b/stubs/D3DShot/d3dshot/dll/dxgi.pyi new file mode 100644 index 000000000000..d26d46867c5e --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/dxgi.pyi @@ -0,0 +1,154 @@ +from ctypes import Array, Structure, _Pointer, c_uint +from ctypes.wintypes import BOOL, DWORD, HMONITOR, INT, LARGE_INTEGER, LONG, PFLOAT, POINT, RECT, UINT, ULARGE_INTEGER, WCHAR +from typing_extensions import TypedDict + +from d3dshot.dll import _HRESULT, _IUnknown, _ProcessFunc, _ProcessFuncRegionArg, _ProcessFuncReturn +from d3dshot.dll.d3d import ID3D11Device + +class _DXGIOutputPosition(TypedDict): + left: LONG + top: LONG + right: LONG + bottom: LONG + +class _DXGIOutput(TypedDict): + name: str + position: _DXGIOutputPosition + resolution: tuple[tuple[LONG, LONG], tuple[LONG, LONG]] + rotation: int + is_attached_to_desktop: bool + +class LUID(Structure): + LowPart: DWORD + HighPart: LONG + +class DXGI_ADAPTER_DESC1(Structure): + Description: Array[WCHAR] + VendorId: UINT + DeviceId: UINT + SubSysId: UINT + Revision: UINT + DedicatedVideoMemory: ULARGE_INTEGER + DedicatedSystemMemory: ULARGE_INTEGER + SharedSystemMemory: ULARGE_INTEGER + AdapterLuid: LUID + Flags: UINT + +class DXGI_OUTPUT_DESC(Structure): + DeviceName: Array[WCHAR] + DesktopCoordinates: RECT + AttachedToDesktop: BOOL + Rotation: UINT + Monitor: HMONITOR + +class DXGI_OUTDUPL_POINTER_POSITION(Structure): + Position: POINT + Visible: BOOL + +class DXGI_OUTDUPL_FRAME_INFO(Structure): + LastPresentTime: LARGE_INTEGER + LastMouseUpdateTime: LARGE_INTEGER + AccumulatedFrames: UINT + RectsCoalesced: BOOL + ProtectedContentMaskedOut: BOOL + PointerPosition: DXGI_OUTDUPL_POINTER_POSITION + TotalMetadataBufferSize: UINT + PointerShapeBufferSize: UINT + +class DXGI_MAPPED_RECT(Structure): + Pitch: INT + pBits: PFLOAT + +class IDXGIObject(_IUnknown): + def SetPrivateData(self) -> _HRESULT: ... + def SetPrivateDataInterface(self) -> _HRESULT: ... + def GetPrivateData(self) -> _HRESULT: ... + def GetParent(self) -> _HRESULT: ... + +class IDXGIDeviceSubObject(IDXGIObject): + def GetDevice(self) -> _HRESULT: ... + +class IDXGIResource(IDXGIDeviceSubObject): + def GetSharedHandle(self) -> _HRESULT: ... + def GetUsage(self) -> _HRESULT: ... + def SetEvictionPriority(self) -> _HRESULT: ... + def GetEvictionPriority(self) -> _HRESULT: ... + +class IDXGISurface(IDXGIDeviceSubObject): + def GetDesc(self) -> _HRESULT: ... + def Map(self, __pLockedRect: _Pointer[DXGI_MAPPED_RECT], __MapFlags: UINT) -> _HRESULT: ... + def Unmap(self) -> _HRESULT: ... + +class IDXGIOutputDuplication(IDXGIObject): + def GetDesc(self) -> None: ... + def AcquireNextFrame( + self, + __TimeoutInMilliseconds: UINT, + __pFrameInfo: _Pointer[DXGI_OUTDUPL_FRAME_INFO], + __ppDesktopResource: _Pointer[_Pointer[IDXGIResource]], + ) -> _HRESULT: ... + def GetFrameDirtyRects(self) -> _HRESULT: ... + def GetFrameMoveRects(self) -> _HRESULT: ... + def GetFramePointerShape(self) -> _HRESULT: ... + def MapDesktopSurface(self) -> _HRESULT: ... + def UnMapDesktopSurface(self) -> _HRESULT: ... + def ReleaseFrame(self) -> _HRESULT: ... + +class IDXGIOutput(IDXGIObject): + def GetDesc(self, __pDesc: _Pointer[DXGI_OUTPUT_DESC]) -> _HRESULT: ... + def GetDisplayModeList(self) -> _HRESULT: ... + def FindClosestMatchingMode(self) -> _HRESULT: ... + def WaitForVBlank(self) -> _HRESULT: ... + def TakeOwnership(self) -> _HRESULT: ... + def ReleaseOwnership(self) -> None: ... + def GetGammaControlCapabilities(self) -> _HRESULT: ... + def SetGammaControl(self) -> _HRESULT: ... + def GetGammaControl(self) -> _HRESULT: ... + def SetDisplaySurface(self) -> _HRESULT: ... + def GetDisplaySurfaceData(self) -> _HRESULT: ... + def GetFrameStatistics(self) -> _HRESULT: ... + +class IDXGIOutput1(IDXGIOutput): + def GetDisplayModeList1(self) -> _HRESULT: ... + def FindClosestMatchingMode1(self) -> _HRESULT: ... + def GetDisplaySurfaceData1(self) -> _HRESULT: ... + def DuplicateOutput( + self, __pDevice: _Pointer[ID3D11Device], __ppOutputDuplication: _Pointer[_Pointer[IDXGIOutputDuplication]] + ) -> _HRESULT: ... + +class IDXGIAdapter(IDXGIObject): + def EnumOutputs(self, __Output: UINT, __ppOutput: _Pointer[_Pointer[IDXGIOutput]]) -> _HRESULT: ... + def GetDesc(self) -> _HRESULT: ... + def CheckInterfaceSupport(self) -> _HRESULT: ... + +class IDXGIAdapter1(IDXGIAdapter): + def GetDesc1(self, __pDesc: _Pointer[DXGI_ADAPTER_DESC1]) -> _HRESULT: ... + +class IDXGIFactory(IDXGIObject): + def EnumAdapters(self) -> _HRESULT: ... + def MakeWindowAssociation(self) -> _HRESULT: ... + def GetWindowAssociation(self) -> _HRESULT: ... + def CreateSwapChain(self) -> _HRESULT: ... + def CreateSoftwareAdapter(self) -> _HRESULT: ... + +class IDXGIFactory1(IDXGIFactory): + def EnumAdapters1(self, __Adapter: c_uint, __ppAdapter: _Pointer[_Pointer[IDXGIAdapter1]]) -> _HRESULT: ... + def IsCurrent(self) -> BOOL: ... + +def initialize_dxgi_factory() -> _Pointer[IDXGIFactory1]: ... +def discover_dxgi_adapters(dxgi_factory: IDXGIFactory1) -> list[_Pointer[IDXGIAdapter1]]: ... +def describe_dxgi_adapter(dxgi_adapter: IDXGIAdapter1) -> Array[WCHAR]: ... +def discover_dxgi_outputs(dxgi_adapter: IDXGIAdapter) -> list[_Pointer[IDXGIOutput1]]: ... +def describe_dxgi_output(dxgi_output: IDXGIOutput) -> _DXGIOutput: ... +def initialize_dxgi_output_duplication( + dxgi_output: IDXGIOutput1, d3d_device: _Pointer[ID3D11Device] +) -> _Pointer[IDXGIOutputDuplication]: ... +def get_dxgi_output_duplication_frame( + dxgi_output_duplication: IDXGIOutputDuplication, + d3d_device: ID3D11Device, + process_func: _ProcessFunc[_ProcessFuncRegionArg, _ProcessFuncReturn] | None = ..., + width: int = ..., + height: int = ..., + region: _ProcessFuncRegionArg = ..., + rotation: int = ..., +) -> _ProcessFuncReturn | None: ... diff --git a/stubs/D3DShot/d3dshot/dll/shcore.pyi b/stubs/D3DShot/d3dshot/dll/shcore.pyi new file mode 100644 index 000000000000..3fd5237ef7ba --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/shcore.pyi @@ -0,0 +1,3 @@ +from ctypes.wintypes import HMONITOR + +def get_scale_factor_for_monitor(hmonitor: HMONITOR) -> float: ... diff --git a/stubs/D3DShot/d3dshot/dll/user32.pyi b/stubs/D3DShot/d3dshot/dll/user32.pyi new file mode 100644 index 000000000000..a8dfaec82e68 --- /dev/null +++ b/stubs/D3DShot/d3dshot/dll/user32.pyi @@ -0,0 +1,13 @@ +import ctypes +from ctypes import wintypes + +class DISPLAY_DEVICE(ctypes.Structure): + cb: wintypes.DWORD + DeviceName: wintypes.WCHAR + DeviceString: wintypes.WCHAR + StateFlags: wintypes.DWORD + DeviceID: wintypes.WCHAR + DeviceKey: wintypes.WCHAR + +def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... +def get_hmonitor_by_point(x: wintypes.LONG, y: wintypes.LONG) -> wintypes.HMONITOR: ...