thindx 0.0.0-unsound.5

Thin DirectX wrappers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#![cfg_attr(not(feature = "9ex"), allow(unused_imports))]

use crate::*;
use crate::d3d9::*;

use winapi::shared::d3d9::{IDirect3DDevice9Ex, IDirect3DDevice9};
use winapi::shared::d3d9types::*;
use winapi::um::unknwnbase::IUnknown;
use winapi::um::wingdi::*;

use std::convert::TryInto;
use std::ptr::*;



/// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nn-d3d9-idirect3ddevice9ex)\]
/// (extends [Device])
/// Core interface used for general rendering, resource creation, etc.
#[cfg(feature = "9ex")]
#[derive(Clone)] #[repr(transparent)]
pub struct DeviceEx(pub(crate) mcom::Rc<IDirect3DDevice9Ex>);

#[cfg(feature = "9ex")] unsafe impl AsSafe<IUnknown             > for DeviceEx { fn as_safe(&self) -> &IUnknown            { &***self.0 } }
#[cfg(feature = "9ex")] unsafe impl AsSafe<IDirect3DDevice9     > for DeviceEx { fn as_safe(&self) -> &IDirect3DDevice9    { &**self.0 } }
#[cfg(feature = "9ex")] unsafe impl AsSafe<IDirect3DDevice9Ex   > for DeviceEx { fn as_safe(&self) -> &IDirect3DDevice9Ex  { &*self.0 } }



/// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nn-d3d9-idirect3ddevice9ex)\]
/// IDirect3DDevice9Ex extension methods
///
/// ### Methods
///
/// | thindx                                                                        | docs.microsoft.com                | Description |
/// | ----------------------------------------------------------------------------- | --------------------------------- | ----------- |
/// | [check_device_state](Self::check_device_state)                                | [CheckDeviceState]                | Reports the current cooperative-level status of the Direct3D device for a windowed or full-screen application.
/// | [check_resource_residency](Self::check_resource_residency)                    | [CheckResourceResidency]          | Checks an array of resources to determine if it is likely that they will cause a large stall at Draw time because the system must make the resources GPU-accessible.
/// | [compose_rects](Self::compose_rects)                                          | [ComposeRects]                    | Copy a text string to one surface using an alphabet of glyphs on another surface. Composition is done by the GPU using bitwise operations.
/// | [create_depth_stencil_surface_ex](Self::create_depth_stencil_surface_ex)      | [CreateDepthStencilSurfaceEx]     | Creates a depth-stencil surface.
/// | [create_offscreen_plain_surface_ex](Self::create_offscreen_plain_surface_ex)  | [CreateOffscreenPlainSurfaceEx]   | Create an off-screen surface.
/// | [create_render_target_ex](Self::create_render_target_ex)                      | [CreateRenderTargetEx]            | Creates a render-target surface.
/// | [get_display_mode_ex](Self::get_display_mode_ex)                              | [GetDisplayModeEx]                | Retrieves the display mode's spatial resolution, color resolution, refresh frequency, and rotation settings.
/// | [get_gpu_thread_priority](Self::get_gpu_thread_priority)                      | [GetGPUThreadPriority]            | Get the priority of the GPU thread.
/// | [get_maximum_frame_latency](Self::get_maximum_frame_latency)                  | [GetMaximumFrameLatency]          | Retrieves the number of frames of data that the system is allowed to queue.
/// | [present_ex](Self::present_ex)                                                | [PresentEx]                       | Swap the swapchain's next buffer with the front buffer.
/// | [reset_ex](Self::reset_ex)                                                    | [ResetEx]                         | Resets the type, size, and format of the swap chain with all other surfaces persistent.
/// | [set_convolution_mono_kernel](Self::set_convolution_mono_kernel)              | [SetConvolutionMonoKernel]        | Prepare the texture sampler for monochrome convolution filtering on a single-color texture.
/// | [set_gpu_thread_priority](Self::set_gpu_thread_priority)                      | [SetGPUThreadPriority]            | Set the priority on the GPU thread.
/// | [set_maximum_frame_latency](Self::set_maximum_frame_latency)                  | [SetMaximumFrameLatency]          | Set the number of frames that the system is allowed to queue for rendering.
/// | [test_cooperative_level](Self::test_cooperative_level)                        | [TestCooperativeLevel]            | Reports the current cooperative-level status of the Direct3D device for a windowed or full-screen application.
/// | [wait_for_vblank](Self::wait_for_vblank)                                      | [WaitForVBlank]                   | Suspend execution of the calling thread until the next vertical blank signal.
///
/// [CheckDeviceState]:                 https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-checkdevicestate
/// [CheckResourceResidency]:           https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-checkresourceresidency
/// [ComposeRects]:                     https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-composerects
/// [CreateDepthStencilSurfaceEx]:      https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-createdepthstencilsurfaceex
/// [CreateOffscreenPlainSurfaceEx]:    https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-createoffscreenplainsurfaceex
/// [CreateRenderTargetEx]:             https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-createrendertargetex
/// [GetDisplayModeEx]:                 https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-getdisplaymodeex
/// [GetGPUThreadPriority]:             https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-getgputhreadpriority
/// [GetMaximumFrameLatency]:           https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-getmaximumframelatency
/// [PresentEx]:                        https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-presentex
/// [ResetEx]:                          https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-resetex
/// [SetConvolutionMonoKernel]:         https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setconvolutionmonokernel
/// [SetGPUThreadPriority]:             https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setgputhreadpriority
/// [SetMaximumFrameLatency]:           https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setmaximumframelatency
/// [TestCooperativeLevel]:             https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-testcooperativelevel
/// [WaitForVBlank]:                    https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-waitforvblank
///
#[cfg(feature = "9ex")]
pub trait IDirect3DDevice9ExExt : AsSafe<IDirect3DDevice9Ex> {
    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-checkdevicestate)\]
    /// IDirect3DDevice9Ex::CheckDeviceState
    ///
    /// Reports the current cooperative-level status of the Direct3D device for a windowed or full-screen application.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::DEVICEHUNG]
    /// *   [D3DERR::DEVICELOST]
    /// *   [D3DERR::DEVICEREMOVED]
    /// *   [D3DERR::OUTOFVIDEOMEMORY]
    /// *   [D3DERR::INVALIDCALL]
    /// *   [D3D::S_PRESENT_OCCLUDED]
    /// *   [D3D::S_PRESENT_MODE_CHANGED]
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn check_device_state(&self, destination_window: impl AsHWND) -> ErrorKind {
        ErrorKind(unsafe { self.as_winapi().CheckDeviceState(destination_window.as_hwnd()) })
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-checkresourceresidency )\]
    /// IDirect3DDevice9Ex::CheckResourceResidency
    ///
    /// Checks an array of resources to determine if it is likely that they will cause a large stall at Draw time because the system must make the resources GPU-accessible.
    ///
    /// ### Returns
    ///
    /// *   [THINERR::SLICE_OVERFLOW]    if `resources.len()` > `65535`
    /// *   [D3DERR::INVALIDCALL]       ???
    /// *   Ok(
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    #[doc(hidden)]
    fn _xxx_check_resource_residency(&self, resources: &mut [Resource]) -> ErrorKind {
        // FIXME: Taking resources as a value slice is bloody annoying, but we can't cast `&[&Resource]` sanely.
        // FIXME: mut casts bellow are sketch as heck

        // "... up to a maximum of 65535."
        let len : u16 = match resources.len().try_into() {
            Ok(len) => len,
            Err(_) => return THINERR::SLICE_OVERFLOW,
        };
        let len = u32::from(len);
        let resources = resources.as_mut_ptr().cast(); // XXX
        ErrorKind(unsafe { self.as_winapi().CheckResourceResidency(resources, len) })
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-composerects)\]
    /// IDirect3DDevice9Ex::ComposeRects
    ///
    /// Copy a text string to one surface using an alphabet of glyphs on another surface.
    /// Composition is done by the GPU using bitwise operations.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn compose_rects(&self, src: &Surface, dst: &Surface, src_rect_descs: &VertexBuffer, num_rects: u32, dst_rect_descs: &VertexBuffer, operation: impl Into<ComposeRectsOp>, xoffset: i32, yoffset: i32) -> Result<(), MethodError> {
        let (src, dst, src_rect_descs, dst_rect_descs) = (src.as_raw(), dst.as_raw(), src_rect_descs.as_raw(), dst_rect_descs.as_raw());
        let operation = operation.into().into();

        let hr = unsafe { self.as_winapi().ComposeRects(src, dst, src_rect_descs, num_rects, dst_rect_descs, operation, xoffset, yoffset) };
        MethodError::check("IDirect3DDevice9Ex::ComposeRects", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-createdepthstencilsurfaceex)\]
    /// IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx
    ///
    /// Creates a depth-stencil surface.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok([Surface])
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn create_depth_stencil_surface_ex(&self, width: u32, height: u32, format: impl Into<Format>, multi_sample: impl Into<MultiSampleType>, multi_sample_quality: u32, discard: bool, _shared_handle: impl SharedHandleParam, usage: impl Into<Usage>) -> Result<Surface, MethodError> {
        let format = format.into().into();
        let multi_sample = multi_sample.into().into();
        let discard = discard.into();
        let shared_handle = null_mut();
        let usage = usage.into().into();

        let mut surface = null_mut();
        let hr = unsafe { self.as_winapi().CreateDepthStencilSurfaceEx(width, height, format, multi_sample, multi_sample_quality, discard, &mut surface, shared_handle, usage) };
        MethodError::check("IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx", hr)?;
        Ok(unsafe { Surface::from_raw(surface) })
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-createoffscreenplainsurfaceex)\]
    /// IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx
    ///
    /// Create an off-screen surface.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok([Surface])
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn create_offscreen_plain_surface_ex(&self, width: u32, height: u32, format: impl Into<Format>, pool: impl Into<Pool>, _shared_handle: impl SharedHandleParam, usage: impl Into<Usage>) -> Result<Surface, MethodError> {
        let format = format.into().into();
        let pool = pool.into().into();
        let shared_handle = null_mut();
        let usage = usage.into().into();

        let mut surface = null_mut();
        let hr = unsafe { self.as_winapi().CreateOffscreenPlainSurfaceEx(width, height, format, pool, &mut surface, shared_handle, usage) };
        MethodError::check("IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx", hr)?;
        Ok(unsafe { Surface::from_raw(surface) })
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-createrendertargetex)\]
    /// IDirect3DDevice9Ex::CreateRenderTargetEx
    ///
    /// Creates a render-target surface.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok([Surface])
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn create_render_target_ex(&self, width: u32, height: u32, format: impl Into<Format>, multi_sample: impl Into<MultiSampleType>, multi_sample_quality: u32, lockable: bool, _shared_handle: impl SharedHandleParam, usage: impl Into<Usage>) -> Result<Surface, MethodError> {
        let format = format.into().into();
        let multi_sample = multi_sample.into().into();
        let lockable = lockable.into();
        let shared_handle = null_mut();
        let usage = usage.into().into();

        let mut surface = null_mut();
        let hr = unsafe { self.as_winapi().CreateRenderTargetEx(width, height, format, multi_sample, multi_sample_quality, lockable, &mut surface, shared_handle, usage) };
        MethodError::check("IDirect3DDevice9Ex::CreateRenderTargetEx", hr)?;
        Ok(unsafe { Surface::from_raw(surface) })
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-getdisplaymodeex)\]
    /// IDirect3DDevice9Ex::GetDisplayModeEx
    ///
    /// Retrieves the display mode's spatial resolution, color resolution, refresh frequency, and rotation settings.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok([D3DDISPLAYMODEEX])
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn get_display_mode_ex(&self, swap_chain: u32) -> Result<(D3DDISPLAYMODEEX, DisplayRotation), MethodError> {
        let mut display_mode_ex = unsafe { std::mem::zeroed::<D3DDISPLAYMODEEX>() };
        let mut rotation = 0;
        let hr = unsafe { self.as_winapi().GetDisplayModeEx(swap_chain, &mut display_mode_ex, &mut rotation) };
        MethodError::check("IDirect3DDevice9Ex::GetDisplayModeEx", hr)?;
        Ok((display_mode_ex, DisplayRotation::from_unchecked(rotation)))
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-getgputhreadpriority)\]
    /// IDirect3DDevice9Ex::GetGPUThreadPriority
    ///
    /// Get the priority of the GPU thread.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::DEVICEREMOVED]
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(`priority`) where `-7` <= `priority` <= `7`
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn get_gpu_thread_priority(&self) -> Result<i32, MethodError> {
        let mut pri = 0;
        let hr = unsafe { self.as_winapi().GetGPUThreadPriority(&mut pri) };
        MethodError::check("IDirect3DDevice9Ex::GetGPUThreadPriority", hr)?;
        Ok(pri)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-getmaximumframelatency)\]
    /// IDirect3DDevice9Ex::GetMaximumFrameLatency
    ///
    /// Retrieves the number of frames of data that the system is allowed to queue.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::DEVICELOST]
    /// *   [D3DERR::DEVICEREMOVED]
    /// *   [D3DERR::DRIVERINTERNALERROR]
    /// *   [D3DERR::INVALIDCALL]
    /// *   [D3DERR::OUTOFVIDEOMEMORY]
    /// *   Ok(`frames`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn get_maximum_frame_latency(&self) -> Result<u32, MethodError> {
        let mut max_latency = 0;
        let hr = unsafe { self.as_winapi().GetMaximumFrameLatency(&mut max_latency) };
        MethodError::check("IDirect3DDevice9Ex::GetMaximumFrameLatency", hr)?;
        Ok(max_latency)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-presentex)\]
    /// IDirect3DDevice9Ex::PresentEx
    ///
    /// Swap the swapchain's next buffer with the front buffer.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::DEVICELOST]
    /// *   [D3DERR::DEVICEHUNG]
    /// *   [D3DERR::DEVICEREMOVED]
    /// *   [D3DERR::OUTOFVIDEOMEMORY]
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn present_ex<'r>(&self, source_rect: impl IntoRectOrFull, dest_rect: impl IntoRectOrFull, dest_window_override: impl AsHWND, dirty_region: impl Into<Option<&'r RgnData>>, flags: impl Into<Present>) -> Result<(), MethodError> {
        let source_rect = source_rect.into_rect();
        let dest_rect   = dest_rect.into_rect();
        let source_rect = source_rect.as_ref().map_or(null(), |r| &**r);
        let dest_rect   = dest_rect.as_ref().map_or(null(), |r| &**r);
        let dirty_region= dirty_region.into();
        let flags       = flags.into().into();

        let dirty_region = match dirty_region {
            None => null::<RGNDATA>(),
            Some(dr) => {
                if dr.rdh.dwSize as usize   != std::mem::size_of::<RGNDATAHEADER>() { return Err(MethodError("Device::present", THINERR::INVALID_STRUCT_FIELD)); }
                if dr.rdh.iType             != RDH_RECTANGLES                       { return Err(MethodError("Device::present", THINERR::INVALID_STRUCT_FIELD)); }
                if dr.rdh.nCount as usize   > dr.buffer.len()                       { return Err(MethodError("Device::present", THINERR::INVALID_STRUCT_FIELD)); }
                if dr.rdh.nRgnSize as usize > std::mem::size_of_val(dr)             { return Err(MethodError("Device::present", THINERR::INVALID_STRUCT_FIELD)); }
                let dr : *const RgnData = dr;
                dr.cast()
            },
        };

        let hr = unsafe { self.as_winapi().PresentEx(source_rect.cast(), dest_rect.cast(), dest_window_override.as_hwnd(), dirty_region, flags) };
        MethodError::check("IDirect3DDevice9Ex::PresentEx", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-resetex)\]
    /// IDirect3DDevice9Ex::ResetEx
    ///
    /// Resets the type, size, and format of the swap chain with all other surfaces persistent.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::DEVICELOST]
    /// *   [D3DERR::DEVICEHUNG]
    /// *   [D3DERR::INVALIDCALL] ?
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn reset_ex<'mode>(&self, presentation_parameters: &mut D3DPRESENT_PARAMETERS, fullscreen_display_mode: impl Into<Option<&'mode mut D3DDISPLAYMODEEX>>) -> Result<(), MethodError> {
        let fullscreen_display_mode = fullscreen_display_mode.into().map_or(null_mut(), |dm| dm);
        let hr = unsafe { self.as_winapi().ResetEx(presentation_parameters, fullscreen_display_mode) };
        MethodError::check("IDirect3DDevice9Ex::ResetEx", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setconvolutionmonokernel)\]
    /// IDirect3DDevice9Ex::SetConvolutionMonoKernel
    ///
    /// Prepare the texture sampler for monochrome convolution filtering on a single-color texture.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn set_convolution_mono_kernel_unweighted(&self, width: u32, height: u32) -> Result<(), MethodError> {
        let hr = unsafe { self.as_winapi().SetConvolutionMonoKernel(width, height, null_mut(), null_mut()) };
        MethodError::check("IDirect3DDevice9Ex::SetConvolutionMonoKernel", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setconvolutionmonokernel)\]
    /// IDirect3DDevice9Ex::SetConvolutionMonoKernel
    ///
    /// Prepare the texture sampler for monochrome convolution filtering on a single-color texture.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn set_convolution_mono_kernel(&self, rows: &mut [f32], cols: &mut [f32]) -> Result<(), MethodError> {
        // XXX: should rows/cols be non-mut?  Not sure if d3d *actually* writes those values or not...
        let width  : u32 = rows.len().try_into().map_err(|_| MethodError("DeviceEx::set_convolution_mono_kernel", THINERR::SLICE_OVERFLOW))?;
        let height : u32 = cols.len().try_into().map_err(|_| MethodError("DeviceEx::set_convolution_mono_kernel", THINERR::SLICE_OVERFLOW))?;
        let hr = unsafe { self.as_winapi().SetConvolutionMonoKernel(width, height, rows.as_mut_ptr(), cols.as_mut_ptr()) };
        MethodError::check("IDirect3DDevice9Ex::SetConvolutionMonoKernel", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setgputhreadpriority)\]
    /// IDirect3DDevice9Ex::SetGPUThreadPriority
    ///
    /// Set the priority on the GPU thread.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   [D3DERR::DEVICEREMOVED]
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn set_gpu_thread_priority(&self, priority: i32) -> Result<(), MethodError> {
        let hr = unsafe { self.as_winapi().SetGPUThreadPriority(priority) };
        MethodError::check("IDirect3DDevice9Ex::SetGPUThreadPriority", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-setmaximumframelatency)\]
    /// IDirect3DDevice9Ex::SetMaximumFrameLatency
    ///
    /// Set the number of frames that the system is allowed to queue for rendering.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(`()`)
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn set_maximum_frame_latency(&self, max_latency: u32) -> Result<(), MethodError> {
        let hr = unsafe { self.as_winapi().SetMaximumFrameLatency(max_latency) };
        MethodError::check("IDirect3DDevice9Ex::SetMaximumFrameLatency", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-testcooperativelevel)\]
    /// IDirect3DDevice9Ex::TestCooperativeLevel
    ///
    /// Reports the current cooperative-level status of the Direct3D device for a windowed or full-screen application.
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    #[deprecated = "docs claim test_cooperative_level is no longer available for use - instead, use check_device_state"]
    fn test_cooperative_level(&self) -> Result<(), MethodError> {
        let hr = unsafe { self.as_winapi().TestCooperativeLevel() };
        MethodError::check("IDirect3DDevice9Ex::TestCooperativeLevel", hr)
    }

    /// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9ex-waitforvblank)\]
    /// IDirect3DDevice9Ex::WaitForVBlank
    ///
    ///
    ///
    /// ### Returns
    ///
    /// *   [D3DERR::INVALIDCALL]
    /// *   Ok(
    ///
    /// ### Example
    ///
    /// ```rust
    /// # use dev::d3d9::*; let device = device_ex_test();
    /// // TODO
    /// ```
    fn wait_for_vblank(&self, swap_chain: u32) -> Result<(), MethodError> {
        let hr = unsafe { self.as_winapi().WaitForVBlank(swap_chain) };
        MethodError::check("IDirect3DDevice9Ex::WaitForVBlank", hr)
    }
}

#[cfg(feature = "9ex")]
impl<T: AsSafe<IDirect3DDevice9Ex>> IDirect3DDevice9ExExt for T {}