winrt-Windows.Graphics.DirectX.Direct3D11.Interop 3.2.1__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 (27) hide show
  1. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/LICENSE +22 -0
  2. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/MANIFEST.in +3 -0
  3. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/PKG-INFO +39 -0
  4. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/README.md +13 -0
  5. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/interop.h +175 -0
  6. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/py.Windows.Graphics.DirectX.Direct3D11.Interop.cpp +339 -0
  7. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/pyproject.toml +54 -0
  8. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/requirements.txt +4 -0
  9. {winrt_windows_graphics_directx_direct3d11_interop-3.2.1 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/setup.py +14 -5
  10. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/version.txt +1 -0
  11. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/winrt/_winrt_windows_graphics_directx_direct3d11_interop.pyi +11 -0
  12. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/winrt/windows/graphics/directx/direct3d11/interop/__init__.py +131 -0
  13. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/PKG-INFO +39 -0
  14. {winrt_windows_graphics_directx_direct3d11_interop-3.2.1 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/SOURCES.txt +6 -1
  15. winrt_windows_graphics_directx_direct3d11_interop-4.1.0/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/requires.txt +2 -0
  16. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/PKG-INFO +0 -22
  17. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/README.md +0 -7
  18. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/py.Windows.Graphics.DirectX.Direct3D11.Interop.cpp +0 -217
  19. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/pyproject.toml +0 -45
  20. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/pywinrt-version.txt +0 -1
  21. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/winrt/_winrt_windows_graphics_directx_direct3d11_interop.pyi +0 -46
  22. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/winrt/windows/graphics/directx/direct3d11/interop/__init__.py +0 -13
  23. winrt_windows_graphics_directx_direct3d11_interop-3.2.1/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/PKG-INFO +0 -22
  24. {winrt_windows_graphics_directx_direct3d11_interop-3.2.1 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/setup.cfg +0 -0
  25. {winrt_windows_graphics_directx_direct3d11_interop-3.2.1 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt/windows/graphics/directx/direct3d11/interop/py.typed +0 -0
  26. {winrt_windows_graphics_directx_direct3d11_interop-3.2.1 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/dependency_links.txt +0 -0
  27. {winrt_windows_graphics_directx_direct3d11_interop-3.2.1 → winrt_windows_graphics_directx_direct3d11_interop-4.1.0}/winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/top_level.txt +0 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+ Copyright (c) 2021-2026 David Lechner <david@pybricks.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE
@@ -0,0 +1,3 @@
1
+ # WARNING: Please don't edit this file. It was automatically generated.
2
+
3
+ include interop.h
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: winrt-Windows.Graphics.DirectX.Direct3D11.Interop
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
+ License-Expression: MIT
6
+ Project-URL: Documentation, https://pywinrt.readthedocs.io
7
+ Project-URL: Repository, https://github.com/pywinrt/pywinrt
8
+ Project-URL: Changelog, https://github.com/pywinrt/pywinrt/blob/main/interop/winrt-Windows.Graphics.DirectX.Direct3D11.Interop/CHANGELOG.md
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Programming Language :: Python :: Implementation :: CPython
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: winrt-runtime<5,>=4.0.0
24
+ Requires-Dist: winrt-Windows.Graphics.DirectX.Direct3D11>=4!10.0.28000.2705
25
+ Dynamic: license-file
26
+
27
+ <!-- warning: Please don't edit this file. It was automatically generated. -->
28
+
29
+ # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
30
+
31
+ Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
32
+
33
+ This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
34
+
35
+ ```
36
+ pip install winrt-Windows.Graphics.DirectX.Direct3D11.Interop
37
+ ```
38
+
39
+ installs it with `winrt-Windows.Graphics.DirectX.Direct3D11`.
@@ -0,0 +1,13 @@
1
+ <!-- warning: Please don't edit this file. It was automatically generated. -->
2
+
3
+ # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
4
+
5
+ Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
6
+
7
+ This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
8
+
9
+ ```
10
+ pip install winrt-Windows.Graphics.DirectX.Direct3D11.Interop
11
+ ```
12
+
13
+ installs it with `winrt-Windows.Graphics.DirectX.Direct3D11`.
@@ -0,0 +1,175 @@
1
+ // WARNING: Please don't edit this file. It was copied from interop/interop.h
2
+ // by scripts/generate-pyproject.py.
3
+
4
+ // What an interop module needs to exchange WinRT objects and errors with
5
+ // winrt-runtime.
6
+ //
7
+ // An interop module shares no C ABI with the runtime and includes none of its
8
+ // headers. A WinRT object crosses as an interface pointer capsule, which
9
+ // winrt.runtime.interop.as_interface() makes from a projected object and
10
+ // winrt.runtime.interop.wrap_interface() makes a projected object from, and a
11
+ // failed call raises the exception that winrt.runtime.interop.hresult_error()
12
+ // builds. The capsule's name and those three functions are the whole
13
+ // contract, so this header can change freely.
14
+ //
15
+ // scripts/generate-pyproject.py copies this file into each interop package,
16
+ // so that its source distribution builds on its own.
17
+
18
+ #pragma once
19
+
20
+ #include <Python.h>
21
+
22
+ #include <windows.h>
23
+
24
+ #include <oleauto.h>
25
+
26
+ #include <cstddef>
27
+
28
+ namespace interop
29
+ {
30
+ /// The name every interface pointer capsule carries, in the runtime and in
31
+ /// every interop module alike. One holds a reference to a COM interface,
32
+ /// which its destructor releases.
33
+ inline constexpr char interface_capsule_name[] = "winrt.interface";
34
+
35
+ /// Releases the GIL for as long as it is in scope.
36
+ ///
37
+ /// A call into an object in another apartment, or one that sends a window
38
+ /// on another thread a message, waits for that thread, which may itself
39
+ /// be waiting for the GIL to run a Python handler.
40
+ class gil_released
41
+ {
42
+ public:
43
+ gil_released() noexcept : state{PyEval_SaveThread()}
44
+ {
45
+ }
46
+
47
+ gil_released(gil_released const&) = delete;
48
+ gil_released& operator=(gil_released const&) = delete;
49
+
50
+ ~gil_released() noexcept
51
+ {
52
+ PyEval_RestoreThread(state);
53
+ }
54
+
55
+ private:
56
+ PyThreadState* state;
57
+ };
58
+
59
+ /// The destructor of an interface pointer capsule this module made, which
60
+ /// may hold the last reference to the object.
61
+ inline void release_interface(PyObject* capsule) noexcept
62
+ {
63
+ auto const abi = PyCapsule_GetPointer(capsule, interface_capsule_name);
64
+ if (!abi)
65
+ {
66
+ PyErr_WriteUnraisable(capsule);
67
+ return;
68
+ }
69
+
70
+ gil_released const guard;
71
+ static_cast<IUnknown*>(abi)->Release();
72
+ }
73
+
74
+ /// Hands @p abi, and the reference that comes with it, to a new interface
75
+ /// pointer capsule. The reference is released if that fails.
76
+ inline PyObject* new_interface_capsule(IUnknown* abi) noexcept
77
+ {
78
+ auto const capsule
79
+ = PyCapsule_New(abi, interface_capsule_name, release_interface);
80
+ if (!capsule)
81
+ {
82
+ abi->Release();
83
+ }
84
+
85
+ return capsule;
86
+ }
87
+
88
+ /// Raises what winrt.runtime.interop.hresult_error() makes of @p hr and
89
+ /// @p info, the error info of the call that failed with it, which may be
90
+ /// @c nullptr. The reference to @p info moves in.
91
+ /// @returns nullptr, for the caller to return.
92
+ inline PyObject* set_hresult_error(HRESULT hr, IErrorInfo* info) noexcept
93
+ {
94
+ auto const capsule = info ? new_interface_capsule(info) : Py_NewRef(Py_None);
95
+ if (!capsule)
96
+ {
97
+ return nullptr;
98
+ }
99
+
100
+ auto const runtime = PyImport_ImportModule("winrt.runtime.interop");
101
+ if (!runtime)
102
+ {
103
+ Py_DECREF(capsule);
104
+ return nullptr;
105
+ }
106
+
107
+ auto const error = PyObject_CallMethod(
108
+ runtime, "hresult_error", "lO", static_cast<long>(hr), capsule);
109
+ Py_DECREF(runtime);
110
+ Py_DECREF(capsule);
111
+ if (!error)
112
+ {
113
+ return nullptr;
114
+ }
115
+
116
+ PyErr_SetObject(reinterpret_cast<PyObject*>(Py_TYPE(error)), error);
117
+ Py_DECREF(error);
118
+
119
+ return nullptr;
120
+ }
121
+
122
+ /// Raises what winrt.runtime.interop.hresult_error() makes of @p hr and of
123
+ /// the error info that the call that just failed with it left on this
124
+ /// thread.
125
+ /// @returns nullptr, for the caller to return.
126
+ inline PyObject* set_hresult_error(HRESULT hr) noexcept
127
+ {
128
+ // The error info belongs to the thread and the next failure replaces
129
+ // it, so it is taken before anything else can fail.
130
+ IErrorInfo* info{};
131
+ if (GetErrorInfo(0, &info) != S_OK)
132
+ {
133
+ info = nullptr;
134
+ }
135
+
136
+ return set_hresult_error(hr, info);
137
+ }
138
+
139
+ /// The @p I interface of what the interface pointer capsule @p capsule
140
+ /// holds, which the caller owns a reference to.
141
+ /// @returns false with a Python exception set when @p capsule is not one
142
+ /// or what it holds does not implement @p I.
143
+ template<typename I>
144
+ bool query_capsule(PyObject* capsule, I** result) noexcept
145
+ {
146
+ auto const abi = PyCapsule_GetPointer(capsule, interface_capsule_name);
147
+ if (!abi)
148
+ {
149
+ return false;
150
+ }
151
+
152
+ auto const hr = static_cast<IUnknown*>(abi)->QueryInterface(
153
+ __uuidof(I), reinterpret_cast<void**>(result));
154
+ if (FAILED(hr))
155
+ {
156
+ set_hresult_error(hr);
157
+ return false;
158
+ }
159
+
160
+ return true;
161
+ }
162
+
163
+ /// The slots of an interop module that has nothing to set up when it is
164
+ /// executed. It keeps no state, but it exchanges objects and errors with
165
+ /// winrt-runtime, which refuses any interpreter but the main one, so it
166
+ /// says the same.
167
+ inline PyModuleDef_Slot module_slots[]{
168
+ #ifdef Py_mod_multiple_interpreters
169
+ {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
170
+ #endif
171
+ #ifdef Py_mod_gil
172
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
173
+ #endif
174
+ {}};
175
+ } // namespace interop
@@ -0,0 +1,339 @@
1
+ #include "interop.h"
2
+
3
+ #include <d3d11.h>
4
+
5
+ #include <cstdint>
6
+ #include <memory>
7
+
8
+ #if __has_include("windows.graphics.directx.direct3d11.interop.h")
9
+ #include <windows.graphics.directx.direct3d11.interop.h>
10
+
11
+ #ifdef __MINGW32__
12
+ // mingw-w64 generates this header from an .idl that is missing this
13
+ // function, so declare it here. Everything else the header needs is
14
+ // there, including the C++ IDirect3DDxgiInterfaceAccess and its uuid.
15
+ extern "C" HRESULT __stdcall CreateDirect3D11SurfaceFromDXGISurface(
16
+ ::IDXGISurface* dgxiSurface, ::IInspectable** graphicsSurface);
17
+ #endif
18
+
19
+ #else
20
+ // some environments like MSYS2 don't have the interop header
21
+ #include <dxgi.h>
22
+ #include <inspectable.h>
23
+ #include <unknwn.h>
24
+
25
+ // https://gist.github.com/kennykerr/15a62c8218254bc908de672e5ed405fa
26
+
27
+ extern "C"
28
+ {
29
+ HRESULT __stdcall CreateDirect3D11DeviceFromDXGIDevice(
30
+ ::IDXGIDevice* dxgiDevice, ::IInspectable** graphicsDevice);
31
+
32
+ HRESULT __stdcall CreateDirect3D11SurfaceFromDXGISurface(
33
+ ::IDXGISurface* dgxiSurface, ::IInspectable** graphicsSurface);
34
+ }
35
+
36
+ DEFINE_GUID(
37
+ IID__x_Windows_Graphics_DirectX_Direct3D11_IDirect3DDxgiInterfaceAccess,
38
+ // clang-format off
39
+ 0xA9B3D012, 0x3DF2, 0x4EE3, 0xB8, 0xD1, 0x86, 0x95, 0xF4, 0x57, 0xD3, 0xC1
40
+ // clang-format on
41
+ );
42
+
43
+ namespace Windows::Graphics::DirectX::Direct3D11
44
+ {
45
+ MIDL_INTERFACE("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")
46
+ IDirect3DDxgiInterfaceAccess : ::IUnknown
47
+ {
48
+ virtual HRESULT STDMETHODCALLTYPE GetInterface(
49
+ REFIID riid, _COM_Outptr_ void** p) noexcept = 0;
50
+ };
51
+ } // namespace Windows::Graphics::DirectX::Direct3D11
52
+
53
+ #ifdef __CRT_UUID_DECL
54
+ __CRT_UUID_DECL(
55
+ Windows::Graphics::DirectX::Direct3D11::IDirect3DDxgiInterfaceAccess,
56
+ // clang-format off
57
+ 0xA9B3D012, 0x3DF2, 0x4EE3, 0xB8, 0xD1, 0x86, 0x95, 0xF4, 0x57, 0xD3, 0xC1
58
+ // clang-format on
59
+ );
60
+ #endif
61
+ #endif
62
+
63
+ // https://learn.microsoft.com/en-us/windows/win32/api/windows.graphics.directx.direct3d11.interop/
64
+
65
+ namespace
66
+ {
67
+ using ::Windows::Graphics::DirectX::Direct3D11::IDirect3DDxgiInterfaceAccess;
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
+
81
+ PyObject* create_direct3d11_device_from_dxgi_device(
82
+ PyObject* /*unused*/, PyObject* dxgi_device_obj) noexcept
83
+ {
84
+ auto const dxgi_device
85
+ = static_cast<IDXGIDevice*>(PyLong_AsVoidPtr(dxgi_device_obj));
86
+ if (!dxgi_device && PyErr_Occurred())
87
+ {
88
+ return nullptr;
89
+ }
90
+
91
+ ::IInspectable* d3d_device{};
92
+
93
+ auto const hr = CreateDirect3D11DeviceFromDXGIDevice(dxgi_device, &d3d_device);
94
+ if (FAILED(hr))
95
+ {
96
+ return interop::set_hresult_error(hr);
97
+ }
98
+
99
+ return interop::new_interface_capsule(d3d_device);
100
+ }
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
+
242
+ PyObject* create_direct3d11_surface_from_dxgi_surface(
243
+ PyObject* /*unused*/, PyObject* dxgi_surface_obj) noexcept
244
+ {
245
+ auto const dxgi_surface
246
+ = static_cast<IDXGISurface*>(PyLong_AsVoidPtr(dxgi_surface_obj));
247
+ if (!dxgi_surface && PyErr_Occurred())
248
+ {
249
+ return nullptr;
250
+ }
251
+
252
+ ::IInspectable* d3d_surface{};
253
+
254
+ auto const hr
255
+ = CreateDirect3D11SurfaceFromDXGISurface(dxgi_surface, &d3d_surface);
256
+ if (FAILED(hr))
257
+ {
258
+ return interop::set_hresult_error(hr);
259
+ }
260
+
261
+ return interop::new_interface_capsule(d3d_surface);
262
+ }
263
+
264
+ /// The @p I interface that the Direct3D object in @p capsule wraps, as an
265
+ /// integer that owns a reference to it.
266
+ template<typename I>
267
+ PyObject* get_dxgi_interface(PyObject* capsule) noexcept
268
+ {
269
+ IDirect3DDxgiInterfaceAccess* access{};
270
+ if (!interop::query_capsule(capsule, &access))
271
+ {
272
+ return nullptr;
273
+ }
274
+
275
+ I* result{};
276
+
277
+ auto const hr
278
+ = access->GetInterface(__uuidof(I), reinterpret_cast<void**>(&result));
279
+ access->Release();
280
+ if (FAILED(hr))
281
+ {
282
+ return interop::set_hresult_error(hr);
283
+ }
284
+
285
+ auto const value = PyLong_FromVoidPtr(result);
286
+ if (!value)
287
+ {
288
+ result->Release();
289
+ }
290
+
291
+ return value;
292
+ }
293
+
294
+ PyObject* get_dxgi_device_from_object(
295
+ PyObject* /*unused*/, PyObject* capsule) noexcept
296
+ {
297
+ return get_dxgi_interface<IDXGIDevice>(capsule);
298
+ }
299
+
300
+ PyObject* get_dxgi_surface_from_object(
301
+ PyObject* /*unused*/, PyObject* capsule) noexcept
302
+ {
303
+ return get_dxgi_interface<IDXGISurface>(capsule);
304
+ }
305
+
306
+ PyMethodDef module_methods[]{
307
+ {"create_direct3d11_device", create_direct3d11_device, METH_VARARGS, nullptr},
308
+ {"create_direct3d11_device_from_dxgi_device",
309
+ create_direct3d11_device_from_dxgi_device,
310
+ METH_O,
311
+ nullptr},
312
+ {"create_direct3d11_surface_from_dxgi_surface",
313
+ create_direct3d11_surface_from_dxgi_surface,
314
+ METH_O,
315
+ nullptr},
316
+ {"get_dxgi_device_from_object", get_dxgi_device_from_object, METH_O, nullptr},
317
+ {"get_dxgi_surface_from_object", get_dxgi_surface_from_object, METH_O, nullptr},
318
+ {}};
319
+
320
+ PyDoc_STRVAR(
321
+ module_doc,
322
+ "Interop functions for use with IDirect3DDevice and IDirect3DSurface.");
323
+
324
+ PyModuleDef module_def
325
+ = {PyModuleDef_HEAD_INIT,
326
+ "_winrt_windows_graphics_directx_direct3d11_interop",
327
+ module_doc,
328
+ 0,
329
+ module_methods,
330
+ interop::module_slots,
331
+ nullptr,
332
+ nullptr,
333
+ nullptr};
334
+ } // namespace
335
+
336
+ PyMODINIT_FUNC PyInit__winrt_windows_graphics_directx_direct3d11_interop(void) noexcept
337
+ {
338
+ return PyModuleDef_Init(&module_def);
339
+ }
@@ -0,0 +1,54 @@
1
+ # WARNING: Please don't edit this file. It was automatically generated.
2
+
3
+ [build-system]
4
+ requires = ["setuptools>=78"]
5
+ build-backend = "setuptools.build_meta"
6
+
7
+ [project]
8
+ name = "winrt-Windows.Graphics.DirectX.Direct3D11.Interop"
9
+ description = "Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the IDirect3DDevice and IDirect3DSurface that WinRT APIs take."
10
+ readme = "README.md"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ classifiers = [
14
+ "Operating System :: Microsoft :: Windows",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Programming Language :: Python :: 3.15",
21
+ "Programming Language :: Python :: Implementation :: CPython",
22
+ "Intended Audience :: Developers",
23
+ "Programming Language :: Python :: Free Threading :: 2 - Beta",
24
+ "Typing :: Typed",
25
+ ]
26
+ dynamic = ["version", "dependencies"]
27
+ requires-python = ">=3.11"
28
+
29
+ [project.urls]
30
+ Documentation = "https://pywinrt.readthedocs.io"
31
+ Repository = "https://github.com/pywinrt/pywinrt"
32
+ Changelog = "https://github.com/pywinrt/pywinrt/blob/main/interop/winrt-Windows.Graphics.DirectX.Direct3D11.Interop/CHANGELOG.md"
33
+
34
+ [tool.setuptools.dynamic]
35
+ version = { file = "version.txt" }
36
+ dependencies = { file = "requirements.txt" }
37
+
38
+ [tool.setuptools.packages.find]
39
+ include = ["winrt*"]
40
+
41
+ [tool.setuptools.package-data]
42
+ "*" = ["*.pyi", "py.typed"]
43
+
44
+ [tool.cibuildwheel]
45
+ # don't build for PyPy
46
+ skip = "pp*"
47
+ # suppress warnings about ARM64 testing
48
+ test-skip = "*-win_arm64"
49
+ test-command = "python -c \"import winrt._winrt_windows_graphics_directx_direct3d11_interop\""
50
+
51
+ [tool.cibuildwheel.windows]
52
+ archs = ["x86", "AMD64", "ARM64"]
53
+ # nothing here is copied in after the build, so there is no repair step
54
+ repair-wheel-command = ""
@@ -0,0 +1,4 @@
1
+ # This file is generated by scripts/generate-pyproject.py
2
+
3
+ winrt-runtime>=4.0.0,<5
4
+ winrt-Windows.Graphics.DirectX.Direct3D11>=4!10.0.28000.2705
@@ -1,16 +1,25 @@
1
1
  # WARNING: Please don't edit this file. It was automatically generated.
2
+ # setuptools does not annotate the build_ext methods this file overrides.
3
+ # pyright: reportUnknownMemberType=false
2
4
 
3
5
  from setuptools import Extension, setup
4
6
  from setuptools.command.build_ext import build_ext
5
- from winrt_sdk import get_include_dirs
7
+
8
+ INCLUDE_DIRS: list[str] = []
6
9
 
7
10
 
8
11
  class build_ext_ex(build_ext):
9
- def build_extension(self, ext):
12
+ def build_extension(self, ext: Extension) -> None:
13
+ # nothing in the projection uses dynamic_cast or typeid, so disabling
14
+ # RTTI costs nothing and makes the module about 15% smaller
10
15
  if self.compiler.compiler_type == "msvc":
11
- ext.extra_compile_args = ["/std:c++20", "/permissive-"]
16
+ ext.extra_compile_args = ["/std:c++20", "/permissive-", "/GR-"]
12
17
  elif self.compiler.compiler_type == "mingw32":
13
- ext.extra_compile_args = ["-std=c++20", "-D_WIN32_WINNT=_WIN32_WINNT_WIN10"]
18
+ ext.extra_compile_args = [
19
+ "-std=c++20",
20
+ "-fno-rtti",
21
+ "-D_WIN32_WINNT=_WIN32_WINNT_WIN10",
22
+ ]
14
23
  # GCC 15 complains about some things that it didn't in the past
15
24
  ext.extra_compile_args += ["-Wno-strict-aliasing", "-Wno-template-body"]
16
25
  ext.extra_link_args = ["-loleaut32"]
@@ -26,7 +35,7 @@ setup(
26
35
  Extension(
27
36
  "winrt._winrt_windows_graphics_directx_direct3d11_interop",
28
37
  sources=["py.Windows.Graphics.DirectX.Direct3D11.Interop.cpp"],
29
- include_dirs=get_include_dirs(),
38
+ include_dirs=INCLUDE_DIRS,
30
39
  libraries=["windowsapp", "D3D11"],
31
40
  )
32
41
  ],
@@ -0,0 +1,11 @@
1
+ from winrt.runtime.interop import InterfaceCapsule
2
+
3
+ def create_direct3d11_device(driver_type: int, flags: int, /) -> InterfaceCapsule: ...
4
+ def create_direct3d11_device_from_dxgi_device(
5
+ dxgi_device: int, /
6
+ ) -> InterfaceCapsule: ...
7
+ def create_direct3d11_surface_from_dxgi_surface(
8
+ dxgi_surface: int, /
9
+ ) -> InterfaceCapsule: ...
10
+ def get_dxgi_device_from_object(capsule: InterfaceCapsule, /) -> int: ...
11
+ def get_dxgi_surface_from_object(capsule: InterfaceCapsule, /) -> int: ...
@@ -0,0 +1,131 @@
1
+ from enum import IntEnum, IntFlag
2
+ from uuid import UUID
3
+
4
+ import winrt.runtime.interop as _runtime
5
+ import winrt._winrt_windows_graphics_directx_direct3d11_interop as _native
6
+ from winrt.system import Object
7
+ from winrt.windows.graphics.directx.direct3d11 import IDirect3DDevice, IDirect3DSurface
8
+
9
+ __all__ = [
10
+ "create_direct3d11_device",
11
+ "create_direct3d11_device_from_dxgi_device",
12
+ "create_direct3d11_surface_from_dxgi_surface",
13
+ "get_dxgi_device_from_object",
14
+ "get_dxgi_surface_from_object",
15
+ "D3dDriverType",
16
+ "D3d11CreateDeviceFlag",
17
+ ]
18
+
19
+ _IID_IINSPECTABLE = UUID("AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90")
20
+
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
+
68
+ def create_direct3d11_device_from_dxgi_device(dxgi_device: int, /) -> IDirect3DDevice:
69
+ """
70
+ Creates an instance of IDirect3DDevice from an IDXGIDevice.
71
+
72
+ Args:
73
+ dxgi_device (IDXGIDevice*): The IDXGIDevice to create the Direct3DDevice
74
+ from.
75
+
76
+ Returns:
77
+ A Direct3DDevice instance that wraps the DXGIDevice.
78
+ """
79
+ return _runtime.wrap_interface(
80
+ _native.create_direct3d11_device_from_dxgi_device(dxgi_device),
81
+ IDirect3DDevice,
82
+ )
83
+
84
+
85
+ def create_direct3d11_surface_from_dxgi_surface(
86
+ dxgi_surface: int, /
87
+ ) -> IDirect3DSurface:
88
+ """
89
+ Creates an instance of IDirect3DSurface from an IDXGISurface.
90
+
91
+ Args:
92
+ dxgi_surface (IDXGISurface*): The IDXGISurface to create the
93
+ Direct3DSurface from.
94
+
95
+ Returns:
96
+ A Direct3DSurface instance that wraps the DXGISurface.
97
+ """
98
+ return _runtime.wrap_interface(
99
+ _native.create_direct3d11_surface_from_dxgi_surface(dxgi_surface),
100
+ IDirect3DSurface,
101
+ )
102
+
103
+
104
+ def get_dxgi_device_from_object(device: Object, /) -> int:
105
+ """
106
+ Retrieves the IDXGIDevice from a Direct3D object.
107
+
108
+ Args:
109
+ device: The WinRT object to retrieve the IDXGIDevice from.
110
+
111
+ Returns:
112
+ Pointer to IDXGIDevice interface of the WinRT object.
113
+ """
114
+ return _native.get_dxgi_device_from_object(
115
+ _runtime.as_interface(device, _IID_IINSPECTABLE)
116
+ )
117
+
118
+
119
+ def get_dxgi_surface_from_object(surface: Object, /) -> int:
120
+ """
121
+ Retrieves the IDXGISurface from a Direct3D object.
122
+
123
+ Args:
124
+ surface: The WinRT object to retrieve the IDXGISurface from.
125
+
126
+ Returns:
127
+ Pointer to IDXGISurface interface of the WinRT object.
128
+ """
129
+ return _native.get_dxgi_surface_from_object(
130
+ _runtime.as_interface(surface, _IID_IINSPECTABLE)
131
+ )
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: winrt-Windows.Graphics.DirectX.Direct3D11.Interop
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
+ License-Expression: MIT
6
+ Project-URL: Documentation, https://pywinrt.readthedocs.io
7
+ Project-URL: Repository, https://github.com/pywinrt/pywinrt
8
+ Project-URL: Changelog, https://github.com/pywinrt/pywinrt/blob/main/interop/winrt-Windows.Graphics.DirectX.Direct3D11.Interop/CHANGELOG.md
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Programming Language :: Python :: Implementation :: CPython
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: winrt-runtime<5,>=4.0.0
24
+ Requires-Dist: winrt-Windows.Graphics.DirectX.Direct3D11>=4!10.0.28000.2705
25
+ Dynamic: license-file
26
+
27
+ <!-- warning: Please don't edit this file. It was automatically generated. -->
28
+
29
+ # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
30
+
31
+ Creates a Direct3D 11 device, and converts between DXGI devices and surfaces and the `IDirect3DDevice` and `IDirect3DSurface` that WinRT APIs take.
32
+
33
+ This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
34
+
35
+ ```
36
+ pip install winrt-Windows.Graphics.DirectX.Direct3D11.Interop
37
+ ```
38
+
39
+ installs it with `winrt-Windows.Graphics.DirectX.Direct3D11`.
@@ -1,12 +1,17 @@
1
+ LICENSE
2
+ MANIFEST.in
1
3
  README.md
4
+ interop.h
2
5
  py.Windows.Graphics.DirectX.Direct3D11.Interop.cpp
3
6
  pyproject.toml
4
- pywinrt-version.txt
7
+ requirements.txt
5
8
  setup.py
9
+ version.txt
6
10
  winrt/_winrt_windows_graphics_directx_direct3d11_interop.pyi
7
11
  winrt/windows/graphics/directx/direct3d11/interop/__init__.py
8
12
  winrt/windows/graphics/directx/direct3d11/interop/py.typed
9
13
  winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/PKG-INFO
10
14
  winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/SOURCES.txt
11
15
  winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/dependency_links.txt
16
+ winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/requires.txt
12
17
  winrt_Windows.Graphics.DirectX.Direct3D11.Interop.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ winrt-runtime<5,>=4.0.0
2
+ winrt-Windows.Graphics.DirectX.Direct3D11>=4!10.0.28000.2705
@@ -1,22 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: winrt-Windows.Graphics.DirectX.Direct3D11.Interop
3
- Version: 3.2.1
4
- Summary: Python projection of Windows Runtime (WinRT) APIs
5
- License-Expression: MIT
6
- Project-URL: Documentation, https://pywinrt.readthedocs.io
7
- Project-URL: Repository, https://github.com/pywinrt/pywinrt
8
- Project-URL: Changelog, https://github.com/pywinrt/pywinrt/blob/main/CHANGELOG.md
9
- Classifier: Operating System :: Microsoft :: Windows
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: Implementation :: CPython
12
- Classifier: Intended Audience :: Developers
13
- Requires-Python: >=3.9
14
- Description-Content-Type: text/markdown
15
-
16
- <!-- warning: Please don't edit this file. It was automatically generated. -->
17
-
18
- # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
19
-
20
- Windows Runtime (WinRT) APIs for for the `Windows.Graphics.DirectX.Direct3D11.Interop` namespace.
21
-
22
- This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
@@ -1,7 +0,0 @@
1
- <!-- warning: Please don't edit this file. It was automatically generated. -->
2
-
3
- # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
4
-
5
- Windows Runtime (WinRT) APIs for for the `Windows.Graphics.DirectX.Direct3D11.Interop` namespace.
6
-
7
- This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.
@@ -1,217 +0,0 @@
1
- #if __has_include("windows.graphics.directx.direct3d11.interop.h")
2
- #include <windows.graphics.directx.direct3d11.interop.h>
3
- #else
4
- // some environments like MSYS2 don't have the interop header
5
- #include <dxgi.h>
6
- #include <inspectable.h>
7
- #include <unknwn.h>
8
-
9
- // https://gist.github.com/kennykerr/15a62c8218254bc908de672e5ed405fa
10
-
11
- extern "C"
12
- {
13
- HRESULT __stdcall CreateDirect3D11DeviceFromDXGIDevice(
14
- ::IDXGIDevice* dxgiDevice, ::IInspectable** graphicsDevice);
15
-
16
- HRESULT __stdcall CreateDirect3D11SurfaceFromDXGISurface(
17
- ::IDXGISurface* dgxiSurface, ::IInspectable** graphicsSurface);
18
- }
19
-
20
- DEFINE_GUID(
21
- IID__x_Windows_Graphics_DirectX_Direct3D11_IDirect3DDxgiInterfaceAccess,
22
- // clang-format off
23
- 0xA9B3D012, 0x3DF2, 0x4EE3, 0xB8, 0xD1, 0x86, 0x95, 0xF4, 0x57, 0xD3, 0xC1
24
- // clang-format on
25
- );
26
-
27
- namespace Windows::Graphics::DirectX::Direct3D11
28
- {
29
- MIDL_INTERFACE("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")
30
- IDirect3DDxgiInterfaceAccess : ::IUnknown
31
- {
32
- virtual HRESULT STDMETHODCALLTYPE GetInterface(
33
- REFIID riid, _COM_Outptr_ void** p) noexcept
34
- = 0;
35
- };
36
- } // namespace Windows::Graphics::DirectX::Direct3D11
37
-
38
- #ifdef __CRT_UUID_DECL
39
- __CRT_UUID_DECL(
40
- Windows::Graphics::DirectX::Direct3D11::IDirect3DDxgiInterfaceAccess,
41
- // clang-format off
42
- 0xA9B3D012, 0x3DF2, 0x4EE3, 0xB8, 0xD1, 0x86, 0x95, 0xF4, 0x57, 0xD3, 0xC1
43
- // clang-format on
44
- );
45
- #endif
46
- #endif
47
-
48
- #include <winrt/Windows.Graphics.DirectX.Direct3D11.h>
49
- #include "pybase.h"
50
- #include "py.Windows.Graphics.DirectX.Direct3D11.h"
51
-
52
- // https://learn.microsoft.com/en-us/windows/win32/api/windows.graphics.directx.direct3d11.interop/
53
-
54
- namespace py::cpp::Windows::Graphics::DirectX::Direct3D11::Interop
55
- {
56
- static PyObject* create_direct3d11_device_from_dxgi_device(
57
- PyObject* /*unused*/, PyObject* dxgi_device_obj) noexcept
58
- {
59
- try
60
- {
61
- auto dxgi_device
62
- = reinterpret_cast<IDXGIDevice*>(PyLong_AsVoidPtr(dxgi_device_obj));
63
-
64
- if (!dxgi_device && PyErr_Occurred())
65
- {
66
- return nullptr;
67
- }
68
-
69
- winrt::com_ptr<::IInspectable> d3d_device;
70
- winrt::check_hresult(
71
- CreateDirect3D11DeviceFromDXGIDevice(dxgi_device, d3d_device.put()));
72
-
73
- return py::convert(
74
- d3d_device.as<
75
- winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice>());
76
- }
77
- catch (...)
78
- {
79
- py::to_PyErr();
80
- return nullptr;
81
- }
82
- }
83
-
84
- PyDoc_STRVAR(
85
- create_direct3d11_device_from_dxgi_device_doc,
86
- R"(Creates an instance of IDirect3DDevice from an IDXGIDevice.
87
-
88
- Args:
89
- dxgi_device (IDXGIDevice*): The IDXGIDevice to create the Direct3DDevice from.
90
-
91
- Returns:
92
- A Direct3DDevice instance that wraps the DXGIDevice.
93
- )");
94
-
95
- static PyObject* create_direct3d11_surface_from_dxgi_surface(
96
- PyObject* /*unused*/, PyObject* dxgi_surface_obj) noexcept
97
- {
98
- try
99
- {
100
- auto dxgi_surface
101
- = reinterpret_cast<IDXGISurface*>(PyLong_AsVoidPtr(dxgi_surface_obj));
102
-
103
- if (!dxgi_surface && PyErr_Occurred())
104
- {
105
- return nullptr;
106
- }
107
-
108
- winrt::com_ptr<::IInspectable> d3d_surface;
109
- winrt::check_hresult(CreateDirect3D11SurfaceFromDXGISurface(
110
- dxgi_surface, d3d_surface.put()));
111
-
112
- return py::convert(
113
- d3d_surface.as<
114
- winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DSurface>());
115
- }
116
- catch (...)
117
- {
118
- py::to_PyErr();
119
- return nullptr;
120
- }
121
- }
122
-
123
- PyDoc_STRVAR(
124
- create_direct3d11_surface_from_dxgi_surface_doc,
125
- R"(Creates an instance of IDirect3DSurface from an IDXGISurface.
126
-
127
- Args:
128
- dxgi_surface (IDXGISurface*): The IDXGISurface to create the Direct3DSurface from.
129
-
130
- Returns:
131
- A Direct3DSurface instance that wraps the DXGISurface.
132
- )");
133
-
134
- static PyObject* get_dxgi_device_from_object(
135
- PyObject* /*unused*/, PyObject* py_obj) noexcept
136
- {
137
- try
138
- {
139
- auto object
140
- = py::convert_to<winrt::Windows::Foundation::IInspectable>(py_obj);
141
- auto access = object.as<::Windows::Graphics::DirectX::Direct3D11::
142
- IDirect3DDxgiInterfaceAccess>();
143
- winrt::com_ptr<IDXGIDevice> result;
144
- winrt::check_hresult(
145
- access->GetInterface(winrt::guid_of<IDXGIDevice>(), result.put_void()));
146
-
147
- return PyLong_FromVoidPtr(result.detach());
148
- }
149
- catch (...)
150
- {
151
- py::to_PyErr();
152
- return nullptr;
153
- }
154
- }
155
-
156
- static PyObject* get_dxgi_surface_from_object(
157
- PyObject* /*unused*/, PyObject* py_obj) noexcept
158
- {
159
- try
160
- {
161
- auto object
162
- = py::convert_to<winrt::Windows::Foundation::IInspectable>(py_obj);
163
- auto access = object.as<::Windows::Graphics::DirectX::Direct3D11::
164
- IDirect3DDxgiInterfaceAccess>();
165
- winrt::com_ptr<IDXGISurface> result;
166
- winrt::check_hresult(access->GetInterface(
167
- winrt::guid_of<IDXGISurface>(), result.put_void()));
168
-
169
- return PyLong_FromVoidPtr(result.detach());
170
- }
171
- catch (...)
172
- {
173
- py::to_PyErr();
174
- return nullptr;
175
- }
176
- }
177
-
178
- static PyMethodDef module_methods[]{
179
- {"create_direct3d11_device_from_dxgi_device",
180
- create_direct3d11_device_from_dxgi_device,
181
- METH_O,
182
- create_direct3d11_device_from_dxgi_device_doc},
183
- {"create_direct3d11_surface_from_dxgi_surface",
184
- create_direct3d11_surface_from_dxgi_surface,
185
- METH_O,
186
- create_direct3d11_surface_from_dxgi_surface_doc},
187
- {"get_dxgi_device_from_object", get_dxgi_device_from_object, METH_O, nullptr},
188
- {"get_dxgi_surface_from_object", get_dxgi_surface_from_object, METH_O, nullptr},
189
- {}};
190
-
191
- PyDoc_STRVAR(
192
- module_doc,
193
- "Interop functions for use with IDirect3DDevice and IDirect3DSurface.");
194
-
195
- static PyModuleDef module_def
196
- = {PyModuleDef_HEAD_INIT,
197
- "_winrt_windows_graphics_directx_direct3d11_interop",
198
- module_doc,
199
- 0,
200
- module_methods,
201
- nullptr,
202
- nullptr,
203
- nullptr,
204
- nullptr};
205
- } // namespace py::cpp::Windows::Graphics::DirectX::Direct3D11::Interop
206
-
207
- PyMODINIT_FUNC PyInit__winrt_windows_graphics_directx_direct3d11_interop(void) noexcept
208
- {
209
- using namespace py::cpp::Windows::Graphics::DirectX::Direct3D11::Interop;
210
-
211
- if (py::import_winrt_runtime() == -1)
212
- {
213
- return nullptr;
214
- }
215
-
216
- return PyModule_Create(&module_def);
217
- }
@@ -1,45 +0,0 @@
1
- # WARNING: Please don't edit this file. It was automatically generated.
2
-
3
- [build-system]
4
- requires = ["setuptools>=78", "winrt-sdk"]
5
- build-backend = "setuptools.build_meta"
6
-
7
- [project]
8
- name = "winrt-Windows.Graphics.DirectX.Direct3D11.Interop"
9
- description = "Python projection of Windows Runtime (WinRT) APIs"
10
- readme = "README.md"
11
- license = "MIT"
12
- classifiers = [
13
- "Operating System :: Microsoft :: Windows",
14
- "Programming Language :: Python :: 3",
15
- "Programming Language :: Python :: Implementation :: CPython",
16
- "Intended Audience :: Developers",
17
- ]
18
- dynamic = ["version"]
19
- requires-python = ">=3.9"
20
-
21
- [project.urls]
22
- # Homepage = "https://github.com/pywinrt/pywinrt"
23
- Documentation = "https://pywinrt.readthedocs.io"
24
- Repository = "https://github.com/pywinrt/pywinrt"
25
- Changelog = "https://github.com/pywinrt/pywinrt/blob/main/CHANGELOG.md"
26
-
27
- [tool.setuptools.dynamic]
28
- version = { file = "pywinrt-version.txt" }
29
-
30
- [tool.setuptools.package-data]
31
- "*" = ["*.pyi", "py.typed"]
32
-
33
- [tool.cibuildwheel]
34
- # use local winrt-sdk build dependency
35
- environment = { PYTHONPATH="../../winrt-sdk/src" }
36
- # don't install winrt-sdk from PyPI
37
- build-frontend = { name = "build[uv]", args = ["--skip-dependency-check", "--no-isolation"] }
38
- before-build = "uv pip install setuptools"
39
- # don't build for PyPy
40
- skip = "pp*"
41
- # suppress warnings about ARM64 testing
42
- test-skip = "*-win_arm64"
43
-
44
- [tool.cibuildwheel.windows]
45
- archs = ["x86", "AMD64", "ARM64"]
@@ -1,46 +0,0 @@
1
- from winrt.windows.graphics.directx.direct3d11 import IDirect3DDevice
2
- from winrt.system import Object
3
-
4
- def create_direct3d11_device_from_dxgi_device(dxgi_device: int) -> IDirect3DDevice:
5
- """
6
- Creates an instance of IDirect3DDevice from an IDXGIDevice.
7
-
8
- Args:
9
- dxgi_device (IDXGIDevice*): The IDXGIDevice to create the Direct3DDevice from.
10
-
11
- Returns:
12
- A Direct3DDevice instance that wraps the DXGIDevice.
13
- """
14
-
15
- def create_direct3d11_surface_from_dxgi_surface(dxgi_surface: int) -> int:
16
- """
17
- Creates an instance of IDirect3DSurface from an IDXGISurface.
18
-
19
- Args:
20
- dxgi_surface (IDXGISurface*): The IDXGISurface to create the Direct3DSurface from.
21
-
22
- Returns:
23
- Pointer to IDirect3DSurface interface of the IDXGISurface.
24
- """
25
-
26
- def get_dxgi_device_from_object(object: Object) -> int:
27
- """
28
- Retrieves the IDXGIDevice from a Direct3D object.
29
-
30
- Args:
31
- object: The WinRT object to retrieve the IDXGIDevice from.
32
-
33
- Returns:
34
- Pointer to IDXGIDevice interface of the WinRT object.
35
- """
36
-
37
- def get_dxgi_surface_from_object(object: Object) -> int:
38
- """
39
- Retrieves the IDXGISurface from a Direct3D object.
40
-
41
- Args:
42
- object: The WinRT object to retrieve the IDXGISurface from.
43
-
44
- Returns:
45
- Pointer to IDXGISurface interface of the WinRT object.
46
- """
@@ -1,13 +0,0 @@
1
- from winrt._winrt_windows_graphics_directx_direct3d11_interop import (
2
- create_direct3d11_device_from_dxgi_device,
3
- create_direct3d11_surface_from_dxgi_surface,
4
- get_dxgi_device_from_object,
5
- get_dxgi_surface_from_object,
6
- )
7
-
8
- __all__ = [
9
- "create_direct3d11_device_from_dxgi_device",
10
- "create_direct3d11_surface_from_dxgi_surface",
11
- "get_dxgi_device_from_object",
12
- "get_dxgi_surface_from_object",
13
- ]
@@ -1,22 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: winrt-Windows.Graphics.DirectX.Direct3D11.Interop
3
- Version: 3.2.1
4
- Summary: Python projection of Windows Runtime (WinRT) APIs
5
- License-Expression: MIT
6
- Project-URL: Documentation, https://pywinrt.readthedocs.io
7
- Project-URL: Repository, https://github.com/pywinrt/pywinrt
8
- Project-URL: Changelog, https://github.com/pywinrt/pywinrt/blob/main/CHANGELOG.md
9
- Classifier: Operating System :: Microsoft :: Windows
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: Implementation :: CPython
12
- Classifier: Intended Audience :: Developers
13
- Requires-Python: >=3.9
14
- Description-Content-Type: text/markdown
15
-
16
- <!-- warning: Please don't edit this file. It was automatically generated. -->
17
-
18
- # winrt-Windows.Graphics.DirectX.Direct3D11.Interop
19
-
20
- Windows Runtime (WinRT) APIs for for the `Windows.Graphics.DirectX.Direct3D11.Interop` namespace.
21
-
22
- This package provides the `winrt.windows.graphics.directx.direct3d11.interop` module.