winrt-Windows.Graphics.DirectX.Direct3D11.Interop 4.0.0__tar.gz → 4.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/PKG-INFO +3 -3
  2. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/README.md +1 -1
  3. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/py.Windows.Graphics.DirectX.Direct3D11.Interop.cpp +158 -0
  4. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/pyproject.toml +1 -1
  5. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/version.txt +1 -0
  6. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt/_winrt_windows_graphics_directx_direct3d11_interop.pyi +1 -0
  7. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt/windows/graphics/directx/direct3d11/interop/__init__.py +50 -0
  8. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info}/PKG-INFO +3 -3
  9. winrt_windows_graphics_directx_direct3d11_interop-4.0.0/version.txt +0 -1
  10. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/LICENSE +0 -0
  11. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/MANIFEST.in +0 -0
  12. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/interop.h +0 -0
  13. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/requirements.txt +0 -0
  14. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/setup.cfg +0 -0
  15. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/setup.py +0 -0
  16. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt/windows/graphics/directx/direct3d11/interop/py.typed +0 -0
  17. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/SOURCES.txt +0 -0
  18. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/dependency_links.txt +0 -0
  19. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/requires.txt +0 -0
  20. {winrt_windows_graphics_directx_direct3d11_interop-4.0.0 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winrt-Windows.Graphics.DirectX.Direct3D11.Interop
3
- Version: 4.0.0
4
- Summary: Converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take.
3
+ Version: 4.1.0
4
+ Summary: Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take.
5
5
  License-Expression: MIT
6
6
  Project-URL: Documentation, https://pywinrt.readthedocs.io
7
7
  Project-URL: Repository, https://github.com/pywinrt/pywinrt
@@ -28,7 +28,7 @@ Dynamic: license-file
28
28
 
29
29
  # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
30
30
 
31
- Converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
31
+ Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
32
32
 
33
33
  This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
34
34
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
4
4
 
5
- Converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
5
+ Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
6
6
 
7
7
  This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
8
8
 
@@ -1,5 +1,10 @@
1
1
  #include "interop.h"
2
2
 
3
+ #include <d3d11.h>
4
+
5
+ #include <cstdint>
6
+ #include <memory>
7
+
3
8
  #if __has_include("windows.graphics.directx.direct3d11.interop.h")
4
9
  #include <windows.graphics.directx.direct3d11.interop.h>
5
10
 
@@ -61,6 +66,18 @@ namespace
61
66
  {
62
67
  using ::Windows::Graphics::DirectX::Direct3D11::IDirect3DDxgiInterfaceAccess;
63
68
 
69
+ struct release_com
70
+ {
71
+ void operator()(::IUnknown* p) const noexcept
72
+ {
73
+ p->Release();
74
+ }
75
+ };
76
+
77
+ /// Owns a reference to a COM interface, which it releases.
78
+ template<typename I>
79
+ using com_owner = std::unique_ptr<I, release_com>;
80
+
64
81
  PyObject* create_direct3d11_device_from_dxgi_device(
65
82
  PyObject* /*unused*/, PyObject* dxgi_device_obj) noexcept
66
83
  {
@@ -82,6 +99,146 @@ namespace
82
99
  return interop::new_interface_capsule(d3d_device);
83
100
  }
84
101
 
102
+ /// PyLong_AsInt32() as Python 3.14 has it, which is how winrt-runtime
103
+ /// converts an enum that is not a flags enum.
104
+ /// @returns false with a Python error set.
105
+ bool as_int32(PyObject* obj, std::int32_t* value) noexcept
106
+ {
107
+ #if PY_VERSION_HEX >= 0x030E0000
108
+ return PyLong_AsInt32(obj, value) == 0;
109
+ #else
110
+ // a long is 32 bits on Windows, so this raises OverflowError for what
111
+ // does not fit, as PyLong_AsInt32() does
112
+ auto const result = PyLong_AsLong(obj);
113
+ if (result == -1 && PyErr_Occurred())
114
+ {
115
+ return false;
116
+ }
117
+
118
+ *value = result;
119
+ return true;
120
+ #endif
121
+ }
122
+
123
+ /// PyLong_AsUInt32() as Python 3.14 has it, which is how winrt-runtime
124
+ /// converts a flags enum: a negative number raises ValueError and one too
125
+ /// large OverflowError.
126
+ /// @returns false with a Python error set.
127
+ bool as_uint32(PyObject* obj, std::uint32_t* value) noexcept
128
+ {
129
+ #if PY_VERSION_HEX >= 0x030E0000
130
+ return PyLong_AsUInt32(obj, value) == 0;
131
+ #else
132
+ // This goes when the oldest Python supported is 3.14.
133
+ auto const result = PyLong_AsLongLong(obj);
134
+ if (result == -1 && PyErr_Occurred())
135
+ {
136
+ return false;
137
+ }
138
+
139
+ if (result < 0)
140
+ {
141
+ PyErr_SetString(PyExc_ValueError, "Cannot convert negative int");
142
+ return false;
143
+ }
144
+
145
+ if (result > UINT32_MAX)
146
+ {
147
+ PyErr_SetString(
148
+ PyExc_OverflowError, "Python int too large to convert to C uint32_t");
149
+ return false;
150
+ }
151
+
152
+ *value = static_cast<std::uint32_t>(result);
153
+ return true;
154
+ #endif
155
+ }
156
+
157
+ // https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11createdevice
158
+ PyObject* create_direct3d11_device(PyObject* /*unused*/, PyObject* args) noexcept
159
+ {
160
+ PyObject* driver_type_obj;
161
+ PyObject* flags_obj;
162
+
163
+ if (!PyArg_ParseTuple(args, "OO", &driver_type_obj, &flags_obj))
164
+ {
165
+ return nullptr;
166
+ }
167
+
168
+ std::int32_t driver_type;
169
+ if (!as_int32(driver_type_obj, &driver_type))
170
+ {
171
+ return nullptr;
172
+ }
173
+
174
+ // Only a value of D3D_DRIVER_TYPE may be cast to it. UNKNOWN and
175
+ // SOFTWARE are among them, and D3D11CreateDevice refuses them, since
176
+ // there is neither an adapter nor a software rasterizer.
177
+ if (driver_type < D3D_DRIVER_TYPE_UNKNOWN || driver_type > D3D_DRIVER_TYPE_WARP)
178
+ {
179
+ PyErr_Format(
180
+ PyExc_ValueError,
181
+ "%d is not a valid D3dDriverType",
182
+ static_cast<int>(driver_type));
183
+ return nullptr;
184
+ }
185
+
186
+ std::uint32_t flags;
187
+ if (!as_uint32(flags_obj, &flags))
188
+ {
189
+ return nullptr;
190
+ }
191
+
192
+ ID3D11Device* d3d11_device_abi{};
193
+ HRESULT hr;
194
+
195
+ {
196
+ // creating a hardware device can take tens of milliseconds
197
+ interop::gil_released const guard;
198
+ hr = D3D11CreateDevice(
199
+ nullptr,
200
+ static_cast<D3D_DRIVER_TYPE>(driver_type),
201
+ nullptr,
202
+ flags,
203
+ nullptr,
204
+ 0,
205
+ D3D11_SDK_VERSION,
206
+ &d3d11_device_abi,
207
+ nullptr,
208
+ nullptr);
209
+ }
210
+
211
+ // Neither this nor QueryInterface() sets error info, so whatever is on
212
+ // the thread was left by some earlier call and is not taken.
213
+ if (FAILED(hr))
214
+ {
215
+ return interop::set_hresult_error(hr, nullptr);
216
+ }
217
+
218
+ // An error is raised before these are released, when the function
219
+ // returns, so a release cannot replace the error info it takes.
220
+ com_owner<ID3D11Device> const d3d11_device{d3d11_device_abi};
221
+
222
+ IDXGIDevice* dxgi_device_abi{};
223
+ hr = d3d11_device->QueryInterface(
224
+ __uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgi_device_abi));
225
+ if (FAILED(hr))
226
+ {
227
+ return interop::set_hresult_error(hr, nullptr);
228
+ }
229
+
230
+ com_owner<IDXGIDevice> const dxgi_device{dxgi_device_abi};
231
+
232
+ ::IInspectable* d3d_device{};
233
+ hr = CreateDirect3D11DeviceFromDXGIDevice(dxgi_device.get(), &d3d_device);
234
+ if (FAILED(hr))
235
+ {
236
+ return interop::set_hresult_error(hr);
237
+ }
238
+
239
+ return interop::new_interface_capsule(d3d_device);
240
+ }
241
+
85
242
  PyObject* create_direct3d11_surface_from_dxgi_surface(
86
243
  PyObject* /*unused*/, PyObject* dxgi_surface_obj) noexcept
87
244
  {
@@ -147,6 +304,7 @@ namespace
147
304
  }
148
305
 
149
306
  PyMethodDef module_methods[]{
307
+ {"create_direct3d11_device", create_direct3d11_device, METH_VARARGS, nullptr},
150
308
  {"create_direct3d11_device_from_dxgi_device",
151
309
  create_direct3d11_device_from_dxgi_device,
152
310
  METH_O,
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "winrt-Windows.Graphics.DirectX.Direct3D11.Interop"
9
- description = "Converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take."
9
+ description = "Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take."
10
10
  readme = "README.md"
11
11
  license = "MIT"
12
12
  license-files = ["LICENSE"]
@@ -1,5 +1,6 @@
1
1
  from winrt.runtime.interop import InterfaceCapsule
2
2
 
3
+ def create_direct3d11_device(driver_type: int, flags: int, /) -> InterfaceCapsule: ...
3
4
  def create_direct3d11_device_from_dxgi_device(
4
5
  dxgi_device: int, /
5
6
  ) -> InterfaceCapsule: ...
@@ -1,3 +1,4 @@
1
+ from enum import IntEnum, IntFlag
1
2
  from uuid import UUID
2
3
 
3
4
  import winrt.runtime.interop as _runtime
@@ -6,15 +7,64 @@ from winrt.system import Object
6
7
  from winrt.windows.graphics.directx.direct3d11 import IDirect3DDevice, IDirect3DSurface
7
8
 
8
9
  __all__ = [
10
+ "create_direct3d11_device",
9
11
  "create_direct3d11_device_from_dxgi_device",
10
12
  "create_direct3d11_surface_from_dxgi_surface",
11
13
  "get_dxgi_device_from_object",
12
14
  "get_dxgi_surface_from_object",
15
+ "D3dDriverType",
16
+ "D3d11CreateDeviceFlag",
13
17
  ]
14
18
 
15
19
  _IID_IINSPECTABLE = UUID("AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90")
16
20
 
17
21
 
22
+ # https://learn.microsoft.com/en-us/windows/win32/api/d3dcommon/ne-d3dcommon-d3d_driver_type
23
+ # UNKNOWN and SOFTWARE are left out, since they need an adapter or a software
24
+ # rasterizer that create_direct3d11_device() does not take.
25
+ class D3dDriverType(IntEnum):
26
+ HARDWARE = 1
27
+ REFERENCE = 2
28
+ NULL = 3
29
+ WARP = 5
30
+
31
+
32
+ # https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_create_device_flag
33
+ # SWITCH_TO_REF is left out, since Direct3D 11 does not support it.
34
+ class D3d11CreateDeviceFlag(IntFlag):
35
+ SINGLE_THREADED = 0x1
36
+ DEBUG = 0x2
37
+ PREVENT_INTERNAL_THREADING_OPTIMIZATIONS = 0x8
38
+ BGRA_SUPPORT = 0x20
39
+ DEBUGGABLE = 0x40
40
+ PREVENT_ALTERING_LAYER_SETTINGS_FROM_REGISTRY = 0x80
41
+ DISABLE_GPU_TIMEOUT = 0x100
42
+ VIDEO_SUPPORT = 0x800
43
+
44
+
45
+ def create_direct3d11_device(
46
+ *,
47
+ driver_type: D3dDriverType = D3dDriverType.HARDWARE,
48
+ flags: D3d11CreateDeviceFlag = D3d11CreateDeviceFlag.BGRA_SUPPORT,
49
+ ) -> IDirect3DDevice:
50
+ """
51
+ Creates a Direct3D 11 device on the default adapter and wraps it in an
52
+ IDirect3DDevice.
53
+
54
+ Args:
55
+ driver_type: The driver to create the device with.
56
+ flags: The flags to create the device with. Windows.Graphics.Capture
57
+ needs BGRA_SUPPORT, which the default includes.
58
+
59
+ Returns:
60
+ A Direct3DDevice instance that wraps the new device.
61
+ """
62
+ return _runtime.wrap_interface(
63
+ _native.create_direct3d11_device(driver_type, flags),
64
+ IDirect3DDevice,
65
+ )
66
+
67
+
18
68
  def create_direct3d11_device_from_dxgi_device(dxgi_device: int, /) -> IDirect3DDevice:
19
69
  """
20
70
  Creates an instance of IDirect3DDevice from an IDXGIDevice.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winrt-Windows.Graphics.DirectX.Direct3D11.Interop
3
- Version: 4.0.0
4
- Summary: Converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take.
3
+ Version: 4.1.0
4
+ Summary: Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take.
5
5
  License-Expression: MIT
6
6
  Project-URL: Documentation, https://pywinrt.readthedocs.io
7
7
  Project-URL: Repository, https://github.com/pywinrt/pywinrt
@@ -28,7 +28,7 @@ Dynamic: license-file
28
28
 
29
29
  # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
30
30
 
31
- Converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
31
+ Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
32
32
 
33
33
  This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
34
34