2 * Copyright 2014 Michael Müller for Pipelight
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "physicalmonitorenumerationapi.h"
27 #include "lowlevelmonitorconfigurationapi.h"
28 #include "highlevelmonitorconfigurationapi.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(dxva2
);
36 #define D3DFMT_NV12 MAKEFOURCC('N','V','1','2')
38 enum device_handle_flags
40 HANDLE_FLAG_OPEN
= 0x1,
41 HANDLE_FLAG_INVALID
= 0x2,
47 IDirect3DStateBlock9
*state_block
;
52 IDirect3DDeviceManager9 IDirect3DDeviceManager9_iface
;
53 IDirectXVideoProcessorService IDirectXVideoProcessorService_iface
;
54 IDirectXVideoDecoderService IDirectXVideoDecoderService_iface
;
57 IDirect3DDevice9
*device
;
60 struct device_handle
*handles
;
64 HANDLE locking_handle
;
67 CONDITION_VARIABLE lock
;
70 struct video_processor
72 IDirectXVideoProcessor IDirectXVideoProcessor_iface
;
75 IDirectXVideoProcessorService
*service
;
77 DXVA2_VideoDesc video_desc
;
79 unsigned int max_substreams
;
82 static BOOL
dxva_array_reserve(void **elements
, size_t *capacity
, size_t count
, size_t size
)
84 size_t new_capacity
, max_capacity
;
87 if (count
<= *capacity
)
90 max_capacity
= ~(SIZE_T
)0 / size
;
91 if (count
> max_capacity
)
94 new_capacity
= max(4, *capacity
);
95 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
97 if (new_capacity
< count
)
98 new_capacity
= max_capacity
;
100 if (!(new_elements
= realloc(*elements
, new_capacity
* size
)))
103 *elements
= new_elements
;
104 *capacity
= new_capacity
;
109 static struct device_manager
*impl_from_IDirect3DDeviceManager9(IDirect3DDeviceManager9
*iface
)
111 return CONTAINING_RECORD(iface
, struct device_manager
, IDirect3DDeviceManager9_iface
);
114 static struct device_manager
*impl_from_IDirectXVideoProcessorService(IDirectXVideoProcessorService
*iface
)
116 return CONTAINING_RECORD(iface
, struct device_manager
, IDirectXVideoProcessorService_iface
);
119 static struct device_manager
*impl_from_IDirectXVideoDecoderService(IDirectXVideoDecoderService
*iface
)
121 return CONTAINING_RECORD(iface
, struct device_manager
, IDirectXVideoDecoderService_iface
);
124 static struct video_processor
*impl_from_IDirectXVideoProcessor(IDirectXVideoProcessor
*iface
)
126 return CONTAINING_RECORD(iface
, struct video_processor
, IDirectXVideoProcessor_iface
);
129 static const DXVA2_VideoProcessorCaps software_processor_caps
=
131 .DeviceCaps
= DXVA2_VPDev_SoftwareDevice
,
132 .InputPool
= D3DPOOL_SYSTEMMEM
,
133 .VideoProcessorOperations
= DXVA2_VideoProcess_PlanarAlpha
| DXVA2_VideoProcess_YUV2RGB
|
134 DXVA2_VideoProcess_StretchX
| DXVA2_VideoProcess_StretchY
| DXVA2_VideoProcess_SubRects
|
135 DXVA2_VideoProcess_SubStreams
| DXVA2_VideoProcess_SubStreamsExtended
| DXVA2_VideoProcess_YUV2RGBExtended
,
138 static const DXVA2_VideoProcessorCaps progressive_processor_caps
=
140 .DeviceCaps
= DXVA2_VPDev_HardwareDevice
,
141 .InputPool
= D3DPOOL_DEFAULT
,
142 .VideoProcessorOperations
= DXVA2_VideoProcess_YUV2RGB
| DXVA2_VideoProcess_StretchX
| DXVA2_VideoProcess_StretchY
,
145 static HRESULT WINAPI
video_processor_QueryInterface(IDirectXVideoProcessor
*iface
, REFIID riid
, void **obj
)
147 if (IsEqualIID(riid
, &IID_IDirectXVideoProcessor
) ||
148 IsEqualIID(riid
, &IID_IUnknown
))
151 IDirectXVideoProcessor_AddRef(iface
);
155 WARN("Unsupported interface %s.\n", debugstr_guid(riid
));
157 return E_NOINTERFACE
;
160 static ULONG WINAPI
video_processor_AddRef(IDirectXVideoProcessor
*iface
)
162 struct video_processor
*processor
= impl_from_IDirectXVideoProcessor(iface
);
163 ULONG refcount
= InterlockedIncrement(&processor
->refcount
);
165 TRACE("%p, refcount %lu.\n", iface
, refcount
);
170 static ULONG WINAPI
video_processor_Release(IDirectXVideoProcessor
*iface
)
172 struct video_processor
*processor
= impl_from_IDirectXVideoProcessor(iface
);
173 ULONG refcount
= InterlockedDecrement(&processor
->refcount
);
175 TRACE("%p, refcount %lu.\n", iface
, refcount
);
179 IDirectXVideoProcessorService_Release(processor
->service
);
186 static HRESULT WINAPI
video_processor_GetVideoProcessorService(IDirectXVideoProcessor
*iface
,
187 IDirectXVideoProcessorService
**service
)
189 struct video_processor
*processor
= impl_from_IDirectXVideoProcessor(iface
);
191 TRACE("%p, %p.\n", iface
, service
);
193 *service
= processor
->service
;
194 IDirectXVideoProcessorService_AddRef(*service
);
199 static HRESULT WINAPI
video_processor_GetCreationParameters(IDirectXVideoProcessor
*iface
,
200 GUID
*device
, DXVA2_VideoDesc
*video_desc
, D3DFORMAT
*rt_format
, UINT
*max_substreams
)
202 struct video_processor
*processor
= impl_from_IDirectXVideoProcessor(iface
);
204 TRACE("%p, %p, %p, %p, %p.\n", iface
, device
, video_desc
, rt_format
, max_substreams
);
206 if (!device
&& !video_desc
&& !rt_format
&& !max_substreams
)
210 *device
= processor
->device
;
212 *video_desc
= processor
->video_desc
;
214 *rt_format
= processor
->rt_format
;
216 *max_substreams
= processor
->max_substreams
;
221 static HRESULT WINAPI
video_processor_GetVideoProcessorCaps(IDirectXVideoProcessor
*iface
,
222 DXVA2_VideoProcessorCaps
*caps
)
224 struct video_processor
*processor
= impl_from_IDirectXVideoProcessor(iface
);
226 TRACE("%p, %p.\n", iface
, caps
);
228 if (IsEqualGUID(&processor
->device
, &DXVA2_VideoProcSoftwareDevice
))
230 *caps
= software_processor_caps
;
232 else if (IsEqualGUID(&processor
->device
, &DXVA2_VideoProcProgressiveDevice
))
234 *caps
= progressive_processor_caps
;
238 FIXME("Unsupported device %s.\n", debugstr_guid(&processor
->device
));
245 static HRESULT WINAPI
video_processor_GetProcAmpRange(IDirectXVideoProcessor
*iface
, UINT cap
, DXVA2_ValueRange
*range
)
247 FIXME("%p, %u, %p.\n", iface
, cap
, range
);
252 static HRESULT WINAPI
video_processor_GetFilterPropertyRange(IDirectXVideoProcessor
*iface
, UINT setting
,
253 DXVA2_ValueRange
*range
)
255 FIXME("%p, %u, %p.\n", iface
, setting
, range
);
260 static BOOL
intersect_rect(RECT
*dest
, const RECT
*src1
, const RECT
*src2
)
262 if (IsRectEmpty(src1
) || IsRectEmpty(src2
) ||
263 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
264 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
269 dest
->left
= max(src1
->left
, src2
->left
);
270 dest
->right
= min(src1
->right
, src2
->right
);
271 dest
->top
= max(src1
->top
, src2
->top
);
272 dest
->bottom
= min(src1
->bottom
, src2
->bottom
);
277 static D3DCOLOR
video_processor_get_background_color(const DXVA2_AYUVSample16
*ayuv
)
282 y
= (ayuv
->Y
>> 8) - 16;
283 cb
= (ayuv
->Cb
>> 8) - 128;
284 cr
= (ayuv
->Cr
>> 8) - 128;
286 y
= 255.0f
* y
/ 219.0f
;
287 cb
= 255.0f
* cb
/ 224.0f
;
288 cr
= 255.0f
* cr
/ 224.0f
;
291 g
= y
- 0.344 * cb
- 0.714 * cr
;
294 return D3DCOLOR_XRGB(r
, g
, b
);
297 static HRESULT WINAPI
video_processor_VideoProcessBlt(IDirectXVideoProcessor
*iface
, IDirect3DSurface9
*rt
,
298 const DXVA2_VideoProcessBltParams
*params
, const DXVA2_VideoSample
*samples
, UINT sample_count
,
299 HANDLE
*complete_handle
)
301 IDirect3DDevice9
*device
;
306 TRACE("%p, %p, %p, %p, %u, %p.\n", iface
, rt
, params
, samples
, sample_count
, complete_handle
);
308 if (params
->BackgroundColor
.Alpha
!= 0xffff)
310 WARN("Unexpected background alpha %#x.\n", params
->BackgroundColor
.Alpha
);
314 if (FAILED(hr
= IDirect3DSurface9_GetDevice(rt
, &device
)))
316 WARN("Failed to get surface device, hr %#lx.\n", hr
);
320 IDirect3DDevice9_ColorFill(device
, rt
, ¶ms
->TargetRect
, video_processor_get_background_color(¶ms
->BackgroundColor
));
322 for (i
= 0; i
< sample_count
; ++i
)
324 dst_rect
= params
->TargetRect
;
326 if (!intersect_rect(&dst_rect
, &dst_rect
, &samples
[i
].DstRect
))
329 if (FAILED(hr
= IDirect3DDevice9_StretchRect(device
, samples
[i
].SrcSurface
, &samples
[i
].SrcRect
,
330 rt
, &dst_rect
, D3DTEXF_POINT
)))
332 WARN("Failed to copy sample %u, hr %#lx.\n", i
, hr
);
336 IDirect3DDevice9_Release(device
);
341 static const IDirectXVideoProcessorVtbl video_processor_vtbl
=
343 video_processor_QueryInterface
,
344 video_processor_AddRef
,
345 video_processor_Release
,
346 video_processor_GetVideoProcessorService
,
347 video_processor_GetCreationParameters
,
348 video_processor_GetVideoProcessorCaps
,
349 video_processor_GetProcAmpRange
,
350 video_processor_GetFilterPropertyRange
,
351 video_processor_VideoProcessBlt
,
354 static HRESULT WINAPI
device_manager_processor_service_QueryInterface(IDirectXVideoProcessorService
*iface
,
355 REFIID riid
, void **obj
)
357 struct device_manager
*manager
= impl_from_IDirectXVideoProcessorService(iface
);
359 if (IsEqualIID(riid
, &IID_IDirectXVideoProcessorService
) ||
360 IsEqualIID(riid
, &IID_IDirectXVideoAccelerationService
) ||
361 IsEqualIID(riid
, &IID_IUnknown
))
365 else if (IsEqualIID(riid
, &IID_IDirectXVideoDecoderService
))
367 *obj
= &manager
->IDirectXVideoDecoderService_iface
;
371 WARN("Unsupported interface %s.\n", debugstr_guid(riid
));
373 return E_NOINTERFACE
;
376 IUnknown_AddRef((IUnknown
*)*obj
);
380 static ULONG WINAPI
device_manager_processor_service_AddRef(IDirectXVideoProcessorService
*iface
)
382 struct device_manager
*manager
= impl_from_IDirectXVideoProcessorService(iface
);
383 return IDirect3DDeviceManager9_AddRef(&manager
->IDirect3DDeviceManager9_iface
);
386 static ULONG WINAPI
device_manager_processor_service_Release(IDirectXVideoProcessorService
*iface
)
388 struct device_manager
*manager
= impl_from_IDirectXVideoProcessorService(iface
);
389 return IDirect3DDeviceManager9_Release(&manager
->IDirect3DDeviceManager9_iface
);
392 static HRESULT WINAPI
device_manager_processor_service_CreateSurface(IDirectXVideoProcessorService
*iface
,
393 UINT width
, UINT height
, UINT backbuffers
, D3DFORMAT format
, D3DPOOL pool
, DWORD usage
, DWORD dxvaType
,
394 IDirect3DSurface9
**surfaces
, HANDLE
*shared_handle
)
396 struct device_manager
*manager
= impl_from_IDirectXVideoProcessorService(iface
);
400 TRACE("%p, %u, %u, %u, %u, %u, %lu, %lu, %p, %p.\n", iface
, width
, height
, backbuffers
, format
, pool
, usage
, dxvaType
,
401 surfaces
, shared_handle
);
403 if (backbuffers
>= UINT_MAX
)
406 memset(surfaces
, 0, (backbuffers
+ 1) * sizeof(*surfaces
));
408 for (i
= 0; i
< backbuffers
+ 1; ++i
)
410 if (FAILED(hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(manager
->device
, width
, height
, format
,
411 pool
, &surfaces
[i
], NULL
)))
417 for (j
= 0; j
< i
; ++j
)
421 IDirect3DSurface9_Release(surfaces
[j
]);
430 static HRESULT WINAPI
device_manager_processor_service_RegisterVideoProcessorSoftwareDevice(
431 IDirectXVideoProcessorService
*iface
, void *callbacks
)
433 FIXME("%p, %p.\n", iface
, callbacks
);
438 struct dxva_processor_device_desc
441 const D3DFORMAT
*input_formats
;
444 static const D3DFORMAT software_processor_input_formats
[] =
446 D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
, D3DFMT_YUY2
, 0
449 static const D3DFORMAT progressive_processor_input_formats
[] =
451 D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
, D3DFMT_YUY2
, D3DFMT_NV12
, 0
454 static const struct dxva_processor_device_desc processor_devices
[] =
456 { &DXVA2_VideoProcProgressiveDevice
, progressive_processor_input_formats
},
457 { &DXVA2_VideoProcSoftwareDevice
, software_processor_input_formats
},
460 static BOOL
dxva_is_supported_stream_format(const DXVA2_VideoDesc
*video_desc
, const D3DFORMAT
*formats
)
464 if (*formats
== video_desc
->Format
) return TRUE
;
471 static HRESULT WINAPI
device_manager_processor_service_GetVideoProcessorDeviceGuids(
472 IDirectXVideoProcessorService
*iface
, const DXVA2_VideoDesc
*video_desc
, UINT
*count
, GUID
**guids
)
476 FIXME("%p, %p, %p, %p semi-stub.\n", iface
, video_desc
, count
, guids
);
480 if (!(*guids
= CoTaskMemAlloc(ARRAY_SIZE(processor_devices
) * sizeof(**guids
))))
481 return E_OUTOFMEMORY
;
483 for (i
= 0; i
< ARRAY_SIZE(processor_devices
); ++i
)
485 if (dxva_is_supported_stream_format(video_desc
, processor_devices
[i
].input_formats
))
487 (*guids
)[*count
] = *processor_devices
[i
].guid
;
494 CoTaskMemFree(*guids
);
502 static HRESULT WINAPI
device_manager_processor_service_GetVideoProcessorRenderTargets(
503 IDirectXVideoProcessorService
*iface
, REFGUID deviceguid
, const DXVA2_VideoDesc
*video_desc
, UINT
*count
,
506 TRACE("%p, %s, %p, %p, %p.\n", iface
, debugstr_guid(deviceguid
), video_desc
, count
, formats
);
508 if (IsEqualGUID(deviceguid
, &DXVA2_VideoProcSoftwareDevice
))
510 if (!dxva_is_supported_stream_format(video_desc
, software_processor_input_formats
))
512 WARN("Unsupported content format %#x.\n", video_desc
->Format
);
516 if (!(*formats
= CoTaskMemAlloc(2 * sizeof(**formats
))))
517 return E_OUTOFMEMORY
;
520 (*formats
)[0] = D3DFMT_X8R8G8B8
;
521 (*formats
)[1] = D3DFMT_A8R8G8B8
;
525 else if (IsEqualGUID(deviceguid
, &DXVA2_VideoProcProgressiveDevice
))
527 if (!dxva_is_supported_stream_format(video_desc
, progressive_processor_input_formats
))
529 WARN("Unsupported content format %#x.\n", video_desc
->Format
);
533 if (!(*formats
= CoTaskMemAlloc(2 * sizeof(**formats
))))
534 return E_OUTOFMEMORY
;
537 (*formats
)[0] = D3DFMT_X8R8G8B8
;
538 (*formats
)[1] = D3DFMT_NV12
;
543 FIXME("Unsupported device %s.\n", debugstr_guid(deviceguid
));
548 static HRESULT WINAPI
device_manager_processor_service_GetVideoProcessorSubStreamFormats(
549 IDirectXVideoProcessorService
*iface
, REFGUID deviceguid
, const DXVA2_VideoDesc
*video_desc
,
550 D3DFORMAT rt_format
, UINT
*count
, D3DFORMAT
**formats
)
552 FIXME("%p, %s, %p, %u, %p, %p.\n", iface
, debugstr_guid(deviceguid
), video_desc
, rt_format
, count
, formats
);
557 static HRESULT WINAPI
device_manager_processor_service_GetVideoProcessorCaps(
558 IDirectXVideoProcessorService
*iface
, REFGUID device
, const DXVA2_VideoDesc
*video_desc
,
559 D3DFORMAT rt_format
, DXVA2_VideoProcessorCaps
*caps
)
561 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_guid(device
), video_desc
, rt_format
, caps
);
563 if (IsEqualGUID(device
, &DXVA2_VideoProcSoftwareDevice
))
565 *caps
= software_processor_caps
;
567 else if (IsEqualGUID(device
, &DXVA2_VideoProcProgressiveDevice
))
569 *caps
= progressive_processor_caps
;
573 FIXME("Unrecognized device %s.\n", debugstr_guid(device
));
580 static HRESULT WINAPI
device_manager_processor_service_GetProcAmpRange(
581 IDirectXVideoProcessorService
*iface
, REFGUID deviceguid
, const DXVA2_VideoDesc
*video_desc
,
582 D3DFORMAT rt_format
, UINT ProcAmpCap
, DXVA2_ValueRange
*range
)
584 FIXME("%p, %s, %p, %u, %u, %p.\n", iface
, debugstr_guid(deviceguid
), video_desc
, rt_format
, ProcAmpCap
, range
);
589 static HRESULT WINAPI
device_manager_processor_service_GetFilterPropertyRange(
590 IDirectXVideoProcessorService
*iface
, REFGUID deviceguid
, const DXVA2_VideoDesc
*video_desc
,
591 D3DFORMAT rt_format
, UINT filter_setting
, DXVA2_ValueRange
*range
)
593 FIXME("%p, %s, %p, %d, %d, %p.\n", iface
, debugstr_guid(deviceguid
), video_desc
, rt_format
, filter_setting
, range
);
598 static HRESULT WINAPI
device_manager_processor_service_CreateVideoProcessor(IDirectXVideoProcessorService
*iface
,
599 REFGUID device
, const DXVA2_VideoDesc
*video_desc
, D3DFORMAT rt_format
, UINT max_substreams
,
600 IDirectXVideoProcessor
**processor
)
602 struct video_processor
*object
;
604 FIXME("%p, %s, %p, %d, %u, %p.\n", iface
, debugstr_guid(device
), video_desc
, rt_format
, max_substreams
,
607 /* FIXME: validate render target format */
609 if (max_substreams
>= 16)
611 WARN("Invalid substreams count %u.\n", max_substreams
);
615 if (!(object
= calloc(1, sizeof(*object
))))
616 return E_OUTOFMEMORY
;
618 object
->IDirectXVideoProcessor_iface
.lpVtbl
= &video_processor_vtbl
;
619 object
->refcount
= 1;
620 object
->service
= iface
;
621 IDirectXVideoProcessorService_AddRef(object
->service
);
622 object
->device
= *device
;
623 object
->video_desc
= *video_desc
;
624 object
->rt_format
= rt_format
;
625 object
->max_substreams
= max_substreams
;
627 *processor
= &object
->IDirectXVideoProcessor_iface
;
632 static const IDirectXVideoProcessorServiceVtbl device_manager_processor_service_vtbl
=
634 device_manager_processor_service_QueryInterface
,
635 device_manager_processor_service_AddRef
,
636 device_manager_processor_service_Release
,
637 device_manager_processor_service_CreateSurface
,
638 device_manager_processor_service_RegisterVideoProcessorSoftwareDevice
,
639 device_manager_processor_service_GetVideoProcessorDeviceGuids
,
640 device_manager_processor_service_GetVideoProcessorRenderTargets
,
641 device_manager_processor_service_GetVideoProcessorSubStreamFormats
,
642 device_manager_processor_service_GetVideoProcessorCaps
,
643 device_manager_processor_service_GetProcAmpRange
,
644 device_manager_processor_service_GetFilterPropertyRange
,
645 device_manager_processor_service_CreateVideoProcessor
,
648 static HRESULT WINAPI
device_manager_decoder_service_QueryInterface(IDirectXVideoDecoderService
*iface
,
649 REFIID riid
, void **obj
)
651 if (IsEqualIID(riid
, &IID_IDirectXVideoDecoderService
) ||
652 IsEqualIID(riid
, &IID_IDirectXVideoAccelerationService
) ||
653 IsEqualIID(riid
, &IID_IUnknown
))
656 IDirectXVideoDecoderService_AddRef(iface
);
660 WARN("Unsupported interface %s.\n", debugstr_guid(riid
));
662 return E_NOINTERFACE
;
665 static ULONG WINAPI
device_manager_decoder_service_AddRef(IDirectXVideoDecoderService
*iface
)
667 struct device_manager
*manager
= impl_from_IDirectXVideoDecoderService(iface
);
668 return IDirect3DDeviceManager9_AddRef(&manager
->IDirect3DDeviceManager9_iface
);
671 static ULONG WINAPI
device_manager_decoder_service_Release(IDirectXVideoDecoderService
*iface
)
673 struct device_manager
*manager
= impl_from_IDirectXVideoDecoderService(iface
);
674 return IDirect3DDeviceManager9_Release(&manager
->IDirect3DDeviceManager9_iface
);
677 static HRESULT WINAPI
device_manager_decoder_service_CreateSurface(IDirectXVideoDecoderService
*iface
,
678 UINT width
, UINT height
, UINT backbuffers
, D3DFORMAT format
, D3DPOOL pool
, DWORD usage
, DWORD dxvaType
,
679 IDirect3DSurface9
**surfaces
, HANDLE
*shared_handle
)
681 FIXME("%p, %u, %u, %u, %#x, %d, %ld, %ld, %p, %p.\n", iface
, width
, height
, backbuffers
, format
, pool
, usage
,
682 dxvaType
, surfaces
, shared_handle
);
687 static HRESULT WINAPI
device_manager_decoder_service_GetDecoderDeviceGuids(IDirectXVideoDecoderService
*iface
,
688 UINT
*count
, GUID
**guids
)
690 FIXME("%p, %p, %p.\n", iface
, count
, guids
);
695 static HRESULT WINAPI
device_manager_decoder_service_GetDecoderRenderTargets(IDirectXVideoDecoderService
*iface
,
696 REFGUID guid
, UINT
*count
, D3DFORMAT
**formats
)
698 FIXME("%p, %s, %p, %p.\n", iface
, debugstr_guid(guid
), count
, formats
);
703 static HRESULT WINAPI
device_manager_decoder_service_GetDecoderConfigurations(IDirectXVideoDecoderService
*iface
,
704 REFGUID guid
, const DXVA2_VideoDesc
*video_desc
, void *reserved
, UINT
*count
, DXVA2_ConfigPictureDecode
**configs
)
706 FIXME("%p, %s, %p, %p, %p, %p.\n", iface
, debugstr_guid(guid
), video_desc
, reserved
, count
, configs
);
711 static HRESULT WINAPI
device_manager_decoder_service_CreateVideoDecoder(IDirectXVideoDecoderService
*iface
,
712 REFGUID guid
, const DXVA2_VideoDesc
*video_desc
, const DXVA2_ConfigPictureDecode
*config
, IDirect3DSurface9
**rts
,
713 UINT num_surfaces
, IDirectXVideoDecoder
**decoder
)
715 FIXME("%p, %s, %p, %p, %p, %u, %p.\n", iface
, debugstr_guid(guid
), video_desc
, config
, rts
, num_surfaces
,
721 static const IDirectXVideoDecoderServiceVtbl device_manager_decoder_service_vtbl
=
723 device_manager_decoder_service_QueryInterface
,
724 device_manager_decoder_service_AddRef
,
725 device_manager_decoder_service_Release
,
726 device_manager_decoder_service_CreateSurface
,
727 device_manager_decoder_service_GetDecoderDeviceGuids
,
728 device_manager_decoder_service_GetDecoderRenderTargets
,
729 device_manager_decoder_service_GetDecoderConfigurations
,
730 device_manager_decoder_service_CreateVideoDecoder
,
733 static HRESULT WINAPI
device_manager_QueryInterface(IDirect3DDeviceManager9
*iface
, REFIID riid
, void **obj
)
735 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
737 if (IsEqualIID(&IID_IDirect3DDeviceManager9
, riid
) ||
738 IsEqualIID(&IID_IUnknown
, riid
))
741 IDirect3DDeviceManager9_AddRef(iface
);
745 WARN("Unsupported interface %s.\n", debugstr_guid(riid
));
747 return E_NOINTERFACE
;
750 static ULONG WINAPI
device_manager_AddRef(IDirect3DDeviceManager9
*iface
)
752 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
753 ULONG refcount
= InterlockedIncrement(&manager
->refcount
);
755 TRACE("%p, refcount %lu.\n", iface
, refcount
);
760 static ULONG WINAPI
device_manager_Release(IDirect3DDeviceManager9
*iface
)
762 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
763 ULONG refcount
= InterlockedDecrement(&manager
->refcount
);
766 TRACE("%p, refcount %lu.\n", iface
, refcount
);
771 IDirect3DDevice9_Release(manager
->device
);
772 DeleteCriticalSection(&manager
->cs
);
773 for (i
= 0; i
< manager
->count
; ++i
)
775 if (manager
->handles
[i
].state_block
)
776 IDirect3DStateBlock9_Release(manager
->handles
[i
].state_block
);
778 free(manager
->handles
);
785 static HRESULT WINAPI
device_manager_ResetDevice(IDirect3DDeviceManager9
*iface
, IDirect3DDevice9
*device
,
788 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
791 TRACE("%p, %p, %#x.\n", iface
, device
, token
);
793 if (token
!= manager
->token
)
796 EnterCriticalSection(&manager
->cs
);
799 for (i
= 0; i
< manager
->count
; ++i
)
801 if (manager
->handles
[i
].state_block
)
802 IDirect3DStateBlock9_Release(manager
->handles
[i
].state_block
);
803 manager
->handles
[i
].state_block
= NULL
;
804 manager
->handles
[i
].flags
|= HANDLE_FLAG_INVALID
;
806 manager
->locking_handle
= NULL
;
807 IDirect3DDevice9_Release(manager
->device
);
809 manager
->device
= device
;
810 IDirect3DDevice9_AddRef(manager
->device
);
811 LeaveCriticalSection(&manager
->cs
);
813 WakeAllConditionVariable(&manager
->lock
);
818 static HRESULT WINAPI
device_manager_OpenDeviceHandle(IDirect3DDeviceManager9
*iface
, HANDLE
*hdevice
)
820 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
824 TRACE("%p, %p.\n", iface
, hdevice
);
828 EnterCriticalSection(&manager
->cs
);
829 if (!manager
->device
)
830 hr
= DXVA2_E_NOT_INITIALIZED
;
833 for (i
= 0; i
< manager
->count
; ++i
)
835 if (!(manager
->handles
[i
].flags
& HANDLE_FLAG_OPEN
))
837 manager
->handles
[i
].flags
|= HANDLE_FLAG_OPEN
;
838 *hdevice
= ULongToHandle(i
+ 1);
843 if (dxva_array_reserve((void **)&manager
->handles
, &manager
->capacity
, manager
->count
+ 1,
844 sizeof(*manager
->handles
)))
846 *hdevice
= ULongToHandle(manager
->count
+ 1);
847 manager
->handles
[manager
->count
].flags
= HANDLE_FLAG_OPEN
;
848 manager
->handles
[manager
->count
].state_block
= NULL
;
854 LeaveCriticalSection(&manager
->cs
);
859 static HRESULT
device_manager_get_handle_index(struct device_manager
*manager
, HANDLE hdevice
, size_t *idx
)
861 if (!hdevice
|| hdevice
> ULongToHandle(manager
->count
))
863 *idx
= (ULONG_PTR
)hdevice
- 1;
867 static HRESULT WINAPI
device_manager_CloseDeviceHandle(IDirect3DDeviceManager9
*iface
, HANDLE hdevice
)
869 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
873 TRACE("%p, %p.\n", iface
, hdevice
);
875 EnterCriticalSection(&manager
->cs
);
876 if (SUCCEEDED(hr
= device_manager_get_handle_index(manager
, hdevice
, &idx
)))
878 if (manager
->handles
[idx
].flags
& HANDLE_FLAG_OPEN
)
880 if (manager
->locking_handle
== hdevice
)
881 manager
->locking_handle
= NULL
;
882 manager
->handles
[idx
].flags
= 0;
883 if (idx
== manager
->count
- 1)
885 if (manager
->handles
[idx
].state_block
)
886 IDirect3DStateBlock9_Release(manager
->handles
[idx
].state_block
);
887 manager
->handles
[idx
].state_block
= NULL
;
892 LeaveCriticalSection(&manager
->cs
);
894 WakeAllConditionVariable(&manager
->lock
);
899 static HRESULT WINAPI
device_manager_TestDevice(IDirect3DDeviceManager9
*iface
, HANDLE hdevice
)
901 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
905 TRACE("%p, %p.\n", iface
, hdevice
);
907 EnterCriticalSection(&manager
->cs
);
908 if (SUCCEEDED(hr
= device_manager_get_handle_index(manager
, hdevice
, &idx
)))
910 unsigned int flags
= manager
->handles
[idx
].flags
;
912 if (flags
& HANDLE_FLAG_INVALID
)
913 hr
= DXVA2_E_NEW_VIDEO_DEVICE
;
914 else if (!(flags
& HANDLE_FLAG_OPEN
))
917 LeaveCriticalSection(&manager
->cs
);
922 static HRESULT WINAPI
device_manager_LockDevice(IDirect3DDeviceManager9
*iface
, HANDLE hdevice
,
923 IDirect3DDevice9
**device
, BOOL block
)
925 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
929 TRACE("%p, %p, %p, %d.\n", iface
, hdevice
, device
, block
);
931 EnterCriticalSection(&manager
->cs
);
932 if (!manager
->device
)
933 hr
= DXVA2_E_NOT_INITIALIZED
;
934 else if (SUCCEEDED(hr
= device_manager_get_handle_index(manager
, hdevice
, &idx
)))
936 if (manager
->locking_handle
&& !block
)
937 hr
= DXVA2_E_VIDEO_DEVICE_LOCKED
;
940 while (manager
->locking_handle
&& block
)
942 SleepConditionVariableCS(&manager
->lock
, &manager
->cs
, INFINITE
);
945 if (SUCCEEDED(hr
= device_manager_get_handle_index(manager
, hdevice
, &idx
)))
947 if (manager
->handles
[idx
].flags
& HANDLE_FLAG_INVALID
)
948 hr
= DXVA2_E_NEW_VIDEO_DEVICE
;
951 if (manager
->handles
[idx
].state_block
)
953 if (FAILED(IDirect3DStateBlock9_Apply(manager
->handles
[idx
].state_block
)))
954 WARN("Failed to apply state.\n");
955 IDirect3DStateBlock9_Release(manager
->handles
[idx
].state_block
);
956 manager
->handles
[idx
].state_block
= NULL
;
958 *device
= manager
->device
;
959 IDirect3DDevice9_AddRef(*device
);
960 manager
->locking_handle
= hdevice
;
965 LeaveCriticalSection(&manager
->cs
);
970 static HRESULT WINAPI
device_manager_UnlockDevice(IDirect3DDeviceManager9
*iface
, HANDLE hdevice
, BOOL savestate
)
972 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
976 TRACE("%p, %p, %d.\n", iface
, hdevice
, savestate
);
978 EnterCriticalSection(&manager
->cs
);
980 if (hdevice
!= manager
->locking_handle
)
982 else if (SUCCEEDED(hr
= device_manager_get_handle_index(manager
, hdevice
, &idx
)))
984 manager
->locking_handle
= NULL
;
986 IDirect3DDevice9_CreateStateBlock(manager
->device
, D3DSBT_ALL
, &manager
->handles
[idx
].state_block
);
989 LeaveCriticalSection(&manager
->cs
);
991 WakeAllConditionVariable(&manager
->lock
);
996 static HRESULT WINAPI
device_manager_GetVideoService(IDirect3DDeviceManager9
*iface
, HANDLE hdevice
, REFIID riid
,
999 struct device_manager
*manager
= impl_from_IDirect3DDeviceManager9(iface
);
1003 TRACE("%p, %p, %s, %p.\n", iface
, hdevice
, debugstr_guid(riid
), obj
);
1005 EnterCriticalSection(&manager
->cs
);
1006 if (SUCCEEDED(hr
= device_manager_get_handle_index(manager
, hdevice
, &idx
)))
1008 unsigned int flags
= manager
->handles
[idx
].flags
;
1010 if (flags
& HANDLE_FLAG_INVALID
)
1011 hr
= DXVA2_E_NEW_VIDEO_DEVICE
;
1012 else if (!(flags
& HANDLE_FLAG_OPEN
))
1015 hr
= IDirectXVideoProcessorService_QueryInterface(&manager
->IDirectXVideoProcessorService_iface
,
1018 LeaveCriticalSection(&manager
->cs
);
1023 static const IDirect3DDeviceManager9Vtbl device_manager_vtbl
=
1025 device_manager_QueryInterface
,
1026 device_manager_AddRef
,
1027 device_manager_Release
,
1028 device_manager_ResetDevice
,
1029 device_manager_OpenDeviceHandle
,
1030 device_manager_CloseDeviceHandle
,
1031 device_manager_TestDevice
,
1032 device_manager_LockDevice
,
1033 device_manager_UnlockDevice
,
1034 device_manager_GetVideoService
,
1037 BOOL WINAPI
CapabilitiesRequestAndCapabilitiesReply( HMONITOR monitor
, LPSTR buffer
, DWORD length
)
1039 FIXME("%p, %p, %ld: stub.\n", monitor
, buffer
, length
);
1041 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1045 HRESULT WINAPI
DXVA2CreateDirect3DDeviceManager9(UINT
*token
, IDirect3DDeviceManager9
**manager
)
1047 struct device_manager
*object
;
1049 TRACE("%p, %p.\n", token
, manager
);
1053 if (!(object
= calloc(1, sizeof(*object
))))
1054 return E_OUTOFMEMORY
;
1056 object
->IDirect3DDeviceManager9_iface
.lpVtbl
= &device_manager_vtbl
;
1057 object
->IDirectXVideoProcessorService_iface
.lpVtbl
= &device_manager_processor_service_vtbl
;
1058 object
->IDirectXVideoDecoderService_iface
.lpVtbl
= &device_manager_decoder_service_vtbl
;
1059 object
->refcount
= 1;
1060 object
->token
= GetTickCount();
1061 InitializeCriticalSection(&object
->cs
);
1062 InitializeConditionVariable(&object
->lock
);
1064 *token
= object
->token
;
1065 *manager
= &object
->IDirect3DDeviceManager9_iface
;
1070 HRESULT WINAPI
DXVA2CreateVideoService(IDirect3DDevice9
*device
, REFIID riid
, void **obj
)
1072 IDirect3DDeviceManager9
*manager
;
1077 TRACE("%p, %s, %p.\n", device
, debugstr_guid(riid
), obj
);
1079 if (FAILED(hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &manager
)))
1082 if (FAILED(hr
= IDirect3DDeviceManager9_ResetDevice(manager
, device
, token
)))
1085 if (FAILED(hr
= IDirect3DDeviceManager9_OpenDeviceHandle(manager
, &handle
)))
1088 hr
= IDirect3DDeviceManager9_GetVideoService(manager
, handle
, riid
, obj
);
1089 IDirect3DDeviceManager9_CloseDeviceHandle(manager
, handle
);
1092 IDirect3DDeviceManager9_Release(manager
);
1097 BOOL WINAPI
DegaussMonitor( HMONITOR monitor
)
1099 FIXME("(%p): stub\n", monitor
);
1101 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1105 BOOL WINAPI
DestroyPhysicalMonitor( HMONITOR monitor
)
1107 FIXME("(%p): stub\n", monitor
);
1109 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1113 BOOL WINAPI
DestroyPhysicalMonitors( DWORD arraySize
, LPPHYSICAL_MONITOR array
)
1115 FIXME("%lu, %p: stub.\n", arraySize
, array
);
1117 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1121 BOOL WINAPI
GetCapabilitiesStringLength( HMONITOR monitor
, LPDWORD length
)
1123 FIXME("(%p, %p): stub\n", monitor
, length
);
1125 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1129 BOOL WINAPI
GetMonitorBrightness( HMONITOR monitor
, LPDWORD minimum
, LPDWORD current
, LPDWORD maximum
)
1131 FIXME("(%p, %p, %p, %p): stub\n", monitor
, minimum
, current
, maximum
);
1133 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1137 BOOL WINAPI
GetMonitorCapabilities( HMONITOR monitor
, LPDWORD capabilities
, LPDWORD temperatures
)
1139 FIXME("(%p, %p, %p): stub\n", monitor
, capabilities
, temperatures
);
1141 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1146 BOOL WINAPI
GetMonitorColorTemperature( HMONITOR monitor
, LPMC_COLOR_TEMPERATURE temperature
)
1148 FIXME("(%p, %p): stub\n", monitor
, temperature
);
1150 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1154 BOOL WINAPI
GetMonitorContrast( HMONITOR monitor
, LPDWORD minimum
, LPDWORD current
, LPDWORD maximum
)
1156 FIXME("(%p, %p, %p, %p): stub\n", monitor
, minimum
, current
, maximum
);
1158 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1162 BOOL WINAPI
GetMonitorDisplayAreaPosition( HMONITOR monitor
, MC_POSITION_TYPE type
, LPDWORD minimum
,
1163 LPDWORD current
, LPDWORD maximum
)
1165 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor
, type
, minimum
, current
, maximum
);
1167 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1171 BOOL WINAPI
GetMonitorDisplayAreaSize( HMONITOR monitor
, MC_SIZE_TYPE type
, LPDWORD minimum
,
1172 LPDWORD current
, LPDWORD maximum
)
1174 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor
, type
, minimum
, current
, maximum
);
1176 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1180 BOOL WINAPI
GetMonitorRedGreenOrBlueDrive( HMONITOR monitor
, MC_DRIVE_TYPE type
, LPDWORD minimum
,
1181 LPDWORD current
, LPDWORD maximum
)
1183 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor
, type
, minimum
, current
, maximum
);
1185 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1189 BOOL WINAPI
GetMonitorRedGreenOrBlueGain( HMONITOR monitor
, MC_GAIN_TYPE type
, LPDWORD minimum
,
1190 LPDWORD current
, LPDWORD maximum
)
1192 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor
, type
, minimum
, current
, maximum
);
1194 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1198 BOOL WINAPI
GetMonitorTechnologyType( HMONITOR monitor
, LPMC_DISPLAY_TECHNOLOGY_TYPE type
)
1200 FIXME("(%p, %p): stub\n", monitor
, type
);
1202 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1206 BOOL WINAPI
GetNumberOfPhysicalMonitorsFromHMONITOR( HMONITOR monitor
, LPDWORD number
)
1208 FIXME("(%p, %p): stub\n", monitor
, number
);
1210 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1214 HRESULT WINAPI
GetNumberOfPhysicalMonitorsFromIDirect3DDevice9( IDirect3DDevice9
*device
, LPDWORD number
)
1216 FIXME("(%p, %p): stub\n", device
, number
);
1221 BOOL WINAPI
GetPhysicalMonitorsFromHMONITOR( HMONITOR monitor
, DWORD arraySize
, LPPHYSICAL_MONITOR array
)
1223 FIXME("%p, %lu, %p: stub.\n", monitor
, arraySize
, array
);
1225 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1229 HRESULT WINAPI
GetPhysicalMonitorsFromIDirect3DDevice9( IDirect3DDevice9
*device
, DWORD arraySize
, LPPHYSICAL_MONITOR array
)
1231 FIXME("%p, %lu, %p: stub.\n", device
, arraySize
, array
);
1236 BOOL WINAPI
GetTimingReport( HMONITOR monitor
, LPMC_TIMING_REPORT timingReport
)
1238 FIXME("(%p, %p): stub\n", monitor
, timingReport
);
1240 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1244 BOOL WINAPI
GetVCPFeatureAndVCPFeatureReply( HMONITOR monitor
, BYTE vcpCode
, LPMC_VCP_CODE_TYPE pvct
,
1245 LPDWORD current
, LPDWORD maximum
)
1247 FIXME("(%p, 0x%02x, %p, %p, %p): stub\n", monitor
, vcpCode
, pvct
, current
, maximum
);
1249 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1253 HRESULT WINAPI
OPMGetVideoOutputsFromHMONITOR( HMONITOR monitor
, /* OPM_VIDEO_OUTPUT_SEMANTICS */ int vos
,
1254 ULONG
*numVideoOutputs
, /* IOPMVideoOutput */ void ***videoOutputs
)
1256 FIXME("(%p, 0x%x, %p, %p): stub\n", monitor
, vos
, numVideoOutputs
, videoOutputs
);
1261 HRESULT WINAPI
OPMGetVideoOutputsFromIDirect3DDevice9Object( IDirect3DDevice9
*device
, /* OPM_VIDEO_OUTPUT_SEMANTICS */ int vos
,
1262 ULONG
*numVideoOutputs
, /* IOPMVideoOutput */ void ***videoOutputs
)
1264 FIXME("(%p, 0x%x, %p, %p): stub\n", device
, vos
, numVideoOutputs
, videoOutputs
);
1269 BOOL WINAPI
RestoreMonitorFactoryColorDefaults( HMONITOR monitor
)
1271 FIXME("(%p): stub\n", monitor
);
1273 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1277 BOOL WINAPI
RestoreMonitorFactoryDefaults( HMONITOR monitor
)
1279 FIXME("(%p): stub\n", monitor
);
1281 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1285 BOOL WINAPI
SaveCurrentMonitorSettings( HMONITOR monitor
)
1287 FIXME("(%p): stub\n", monitor
);
1289 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1293 BOOL WINAPI
SaveCurrentSettings( HMONITOR monitor
)
1295 FIXME("(%p): stub\n", monitor
);
1297 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1301 BOOL WINAPI
SetMonitorBrightness( HMONITOR monitor
, DWORD brightness
)
1303 FIXME("%p, %#lx: stub.\n", monitor
, brightness
);
1305 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1309 BOOL WINAPI
SetMonitorColorTemperature( HMONITOR monitor
, MC_COLOR_TEMPERATURE temperature
)
1311 FIXME("(%p, 0x%x): stub\n", monitor
, temperature
);
1313 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1317 BOOL WINAPI
SetMonitorContrast( HMONITOR monitor
, DWORD contrast
)
1319 FIXME("%p, %#lx: stub.\n", monitor
, contrast
);
1321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1325 BOOL WINAPI
SetMonitorDisplayAreaPosition( HMONITOR monitor
, MC_POSITION_TYPE type
, DWORD position
)
1327 FIXME("%p, 0x%x, %#lx: stub.\n", monitor
, type
, position
);
1329 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1333 BOOL WINAPI
SetMonitorDisplayAreaSize( HMONITOR monitor
, MC_SIZE_TYPE type
, DWORD size
)
1335 FIXME("%p, 0x%x, %#lx: stub.\n", monitor
, type
, size
);
1337 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1341 BOOL WINAPI
SetMonitorRedGreenOrBlueDrive( HMONITOR monitor
, MC_DRIVE_TYPE type
, DWORD drive
)
1343 FIXME("%p, 0x%x, %#lx: stub.\n", monitor
, type
, drive
);
1345 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1349 BOOL WINAPI
SetMonitorRedGreenOrBlueGain( HMONITOR monitor
, MC_GAIN_TYPE type
, DWORD gain
)
1351 FIXME("%p, 0x%x, %#lx: stub.\n", monitor
, type
, gain
);
1353 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1357 BOOL WINAPI
SetVCPFeature( HMONITOR monitor
, BYTE vcpCode
, DWORD value
)
1359 FIXME("%p, 0x%02x, %#lx: stub.\n", monitor
, vcpCode
, value
);
1361 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);