dxva2: Add video processor stub.
[wine.git] / dlls / dxva2 / main.c
blobaf6ad25697be955e141c040bfbd29e0fbe1d4c2b
1 /*
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
19 #define COBJMACROS
21 #include <stdarg.h>
22 #include <limits.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "d3d9.h"
26 #include "physicalmonitorenumerationapi.h"
27 #include "lowlevelmonitorconfigurationapi.h"
28 #include "highlevelmonitorconfigurationapi.h"
29 #include "initguid.h"
30 #include "dxva2api.h"
32 #include "wine/debug.h"
33 #include "wine/heap.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dxva2);
37 enum device_handle_flags
39 HANDLE_FLAG_OPEN = 0x1,
40 HANDLE_FLAG_INVALID = 0x2,
43 struct device_handle
45 unsigned int flags;
46 IDirect3DStateBlock9 *state_block;
49 struct device_manager
51 IDirect3DDeviceManager9 IDirect3DDeviceManager9_iface;
52 IDirectXVideoProcessorService IDirectXVideoProcessorService_iface;
53 LONG refcount;
55 IDirect3DDevice9 *device;
56 UINT token;
58 struct device_handle *handles;
59 size_t count;
60 size_t capacity;
62 HANDLE locking_handle;
64 CRITICAL_SECTION cs;
65 CONDITION_VARIABLE lock;
68 struct video_processor
70 IDirectXVideoProcessor IDirectXVideoProcessor_iface;
71 LONG refcount;
73 IDirectXVideoProcessorService *service;
76 static BOOL dxva_array_reserve(void **elements, size_t *capacity, size_t count, size_t size)
78 size_t new_capacity, max_capacity;
79 void *new_elements;
81 if (count <= *capacity)
82 return TRUE;
84 max_capacity = ~(SIZE_T)0 / size;
85 if (count > max_capacity)
86 return FALSE;
88 new_capacity = max(4, *capacity);
89 while (new_capacity < count && new_capacity <= max_capacity / 2)
90 new_capacity *= 2;
91 if (new_capacity < count)
92 new_capacity = max_capacity;
94 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
95 return FALSE;
97 *elements = new_elements;
98 *capacity = new_capacity;
100 return TRUE;
103 static struct device_manager *impl_from_IDirect3DDeviceManager9(IDirect3DDeviceManager9 *iface)
105 return CONTAINING_RECORD(iface, struct device_manager, IDirect3DDeviceManager9_iface);
108 static struct device_manager *impl_from_IDirectXVideoProcessorService(IDirectXVideoProcessorService *iface)
110 return CONTAINING_RECORD(iface, struct device_manager, IDirectXVideoProcessorService_iface);
113 static struct video_processor *impl_from_IDirectXVideoProcessor(IDirectXVideoProcessor *iface)
115 return CONTAINING_RECORD(iface, struct video_processor, IDirectXVideoProcessor_iface);
118 static HRESULT WINAPI video_processor_QueryInterface(IDirectXVideoProcessor *iface, REFIID riid, void **obj)
120 if (IsEqualIID(riid, &IID_IDirectXVideoProcessor) ||
121 IsEqualIID(riid, &IID_IUnknown))
123 *obj = iface;
124 IDirectXVideoProcessor_AddRef(iface);
125 return S_OK;
128 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
129 *obj = NULL;
130 return E_NOINTERFACE;
133 static ULONG WINAPI video_processor_AddRef(IDirectXVideoProcessor *iface)
135 struct video_processor *processor = impl_from_IDirectXVideoProcessor(iface);
136 ULONG refcount = InterlockedIncrement(&processor->refcount);
138 TRACE("%p, refcount %u.\n", iface, refcount);
140 return refcount;
143 static ULONG WINAPI video_processor_Release(IDirectXVideoProcessor *iface)
145 struct video_processor *processor = impl_from_IDirectXVideoProcessor(iface);
146 ULONG refcount = InterlockedDecrement(&processor->refcount);
148 TRACE("%p, refcount %u.\n", iface, refcount);
150 if (!refcount)
152 IDirectXVideoProcessorService_Release(processor->service);
153 heap_free(processor);
156 return refcount;
159 static HRESULT WINAPI video_processor_GetVideoProcessorService(IDirectXVideoProcessor *iface,
160 IDirectXVideoProcessorService **service)
162 struct video_processor *processor = impl_from_IDirectXVideoProcessor(iface);
164 TRACE("%p, %p.\n", iface, service);
166 *service = processor->service;
167 IDirectXVideoProcessorService_AddRef(*service);
169 return S_OK;
172 static HRESULT WINAPI video_processor_GetCreationParameters(IDirectXVideoProcessor *iface,
173 GUID *device, DXVA2_VideoDesc *video_desc, D3DFORMAT *rt_format, UINT *maxstreams)
175 FIXME("%p, %p, %p, %p, %p.\n", iface, device, video_desc, rt_format, maxstreams);
177 if (!device && !video_desc && !rt_format && !maxstreams)
178 return E_INVALIDARG;
180 return E_NOTIMPL;
183 static HRESULT WINAPI video_processor_GetVideoProcessorCaps(IDirectXVideoProcessor *iface,
184 DXVA2_VideoProcessorCaps *caps)
186 FIXME("%p, %p.\n", iface, caps);
188 return E_NOTIMPL;
191 static HRESULT WINAPI video_processor_GetProcAmpRange(IDirectXVideoProcessor *iface, UINT cap, DXVA2_ValueRange *range)
193 FIXME("%p, %u, %p.\n", iface, cap, range);
195 return E_NOTIMPL;
198 static HRESULT WINAPI video_processor_GetFilterPropertyRange(IDirectXVideoProcessor *iface, UINT setting,
199 DXVA2_ValueRange *range)
201 FIXME("%p, %u, %p.\n", iface, setting, range);
203 return E_NOTIMPL;
206 static HRESULT WINAPI video_processor_VideoProcessBlt(IDirectXVideoProcessor *iface, IDirect3DSurface9 *rt,
207 const DXVA2_VideoProcessBltParams *params, const DXVA2_VideoSample *samples, UINT sample_count,
208 HANDLE *complete_handle)
210 FIXME("%p, %p, %p, %p, %u, %p.\n", iface, rt, params, samples, sample_count, complete_handle);
212 return E_NOTIMPL;
215 static const IDirectXVideoProcessorVtbl video_processor_vtbl =
217 video_processor_QueryInterface,
218 video_processor_AddRef,
219 video_processor_Release,
220 video_processor_GetVideoProcessorService,
221 video_processor_GetCreationParameters,
222 video_processor_GetVideoProcessorCaps,
223 video_processor_GetProcAmpRange,
224 video_processor_GetFilterPropertyRange,
225 video_processor_VideoProcessBlt,
228 static HRESULT WINAPI device_manager_processor_service_QueryInterface(IDirectXVideoProcessorService *iface,
229 REFIID riid, void **obj)
231 if (IsEqualIID(riid, &IID_IDirectXVideoProcessorService) ||
232 IsEqualIID(riid, &IID_IDirectXVideoAccelerationService) ||
233 IsEqualIID(riid, &IID_IUnknown))
235 *obj = iface;
236 IDirectXVideoProcessorService_AddRef(iface);
237 return S_OK;
240 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
241 *obj = NULL;
242 return E_NOINTERFACE;
245 static ULONG WINAPI device_manager_processor_service_AddRef(IDirectXVideoProcessorService *iface)
247 struct device_manager *manager = impl_from_IDirectXVideoProcessorService(iface);
248 return IDirect3DDeviceManager9_AddRef(&manager->IDirect3DDeviceManager9_iface);
251 static ULONG WINAPI device_manager_processor_service_Release(IDirectXVideoProcessorService *iface)
253 struct device_manager *manager = impl_from_IDirectXVideoProcessorService(iface);
254 return IDirect3DDeviceManager9_Release(&manager->IDirect3DDeviceManager9_iface);
257 static HRESULT WINAPI device_manager_processor_service_CreateSurface(IDirectXVideoProcessorService *iface,
258 UINT width, UINT height, UINT backbuffers, D3DFORMAT format, D3DPOOL pool, DWORD usage, DWORD dxvaType,
259 IDirect3DSurface9 **surfaces, HANDLE *shared_handle)
261 struct device_manager *manager = impl_from_IDirectXVideoProcessorService(iface);
262 unsigned int i, j;
263 HRESULT hr;
265 TRACE("%p, %u, %u, %u, %u, %u, %u, %u, %p, %p.\n", iface, width, height, backbuffers, format, pool, usage, dxvaType,
266 surfaces, shared_handle);
268 if (backbuffers >= UINT_MAX)
269 return E_INVALIDARG;
271 memset(surfaces, 0, (backbuffers + 1) * sizeof(*surfaces));
273 for (i = 0; i < backbuffers + 1; ++i)
275 if (FAILED(hr = IDirect3DDevice9_CreateOffscreenPlainSurface(manager->device, width, height, format,
276 pool, &surfaces[i], NULL)))
277 break;
280 if (FAILED(hr))
282 for (j = 0; j < i; ++j)
284 if (surfaces[j])
286 IDirect3DSurface9_Release(surfaces[j]);
287 surfaces[j] = NULL;
292 return hr;
295 static HRESULT WINAPI device_manager_processor_service_RegisterVideoProcessorSoftwareDevice(
296 IDirectXVideoProcessorService *iface, void *callbacks)
298 FIXME("%p, %p.\n", iface, callbacks);
300 return E_NOTIMPL;
303 static HRESULT WINAPI device_manager_processor_service_GetVideoProcessorDeviceGuids(
304 IDirectXVideoProcessorService *iface, const DXVA2_VideoDesc *video_desc, UINT *count, GUID **guids)
306 FIXME("%p, %p, %p, %p semi-stub.\n", iface, video_desc, count, guids);
308 if (!(*guids = CoTaskMemAlloc(sizeof(**guids))))
309 return E_OUTOFMEMORY;
311 memcpy(*guids, &DXVA2_VideoProcSoftwareDevice, sizeof(**guids));
312 *count = 1;
314 return S_OK;
317 static HRESULT WINAPI device_manager_processor_service_GetVideoProcessorRenderTargets(
318 IDirectXVideoProcessorService *iface, REFGUID deviceguid, const DXVA2_VideoDesc *video_desc, UINT *count,
319 D3DFORMAT **formats)
321 TRACE("%p, %s, %p, %p, %p.\n", iface, debugstr_guid(deviceguid), video_desc, count, formats);
323 if (IsEqualGUID(deviceguid, &DXVA2_VideoProcSoftwareDevice))
325 /* FIXME: filter some input formats */
327 if (!(*formats = CoTaskMemAlloc(2 * sizeof(**formats))))
328 return E_OUTOFMEMORY;
330 *count = 2;
331 (*formats)[0] = D3DFMT_X8R8G8B8;
332 (*formats)[1] = D3DFMT_A8R8G8B8;
334 return S_OK;
336 else
337 FIXME("Unsupported device %s.\n", debugstr_guid(deviceguid));
339 return E_NOTIMPL;
342 static HRESULT WINAPI device_manager_processor_service_GetVideoProcessorSubStreamFormats(
343 IDirectXVideoProcessorService *iface, REFGUID deviceguid, const DXVA2_VideoDesc *video_desc,
344 D3DFORMAT rt_format, UINT *count, D3DFORMAT **formats)
346 FIXME("%p, %s, %p, %u, %p, %p.\n", iface, debugstr_guid(deviceguid), video_desc, rt_format, count, formats);
348 return E_NOTIMPL;
351 static HRESULT WINAPI device_manager_processor_service_GetVideoProcessorCaps(
352 IDirectXVideoProcessorService *iface, REFGUID deviceguid, const DXVA2_VideoDesc *video_desc,
353 D3DFORMAT rt_format, DXVA2_VideoProcessorCaps *caps)
355 FIXME("%p, %s, %p, %u, %p.\n", iface, debugstr_guid(deviceguid), video_desc, rt_format, caps);
357 return E_NOTIMPL;
360 static HRESULT WINAPI device_manager_processor_service_GetProcAmpRange(
361 IDirectXVideoProcessorService *iface, REFGUID deviceguid, const DXVA2_VideoDesc *video_desc,
362 D3DFORMAT rt_format, UINT ProcAmpCap, DXVA2_ValueRange *range)
364 FIXME("%p, %s, %p, %u, %u, %p.\n", iface, debugstr_guid(deviceguid), video_desc, rt_format, ProcAmpCap, range);
366 return E_NOTIMPL;
369 static HRESULT WINAPI device_manager_processor_service_GetFilterPropertyRange(
370 IDirectXVideoProcessorService *iface, REFGUID deviceguid, const DXVA2_VideoDesc *video_desc,
371 D3DFORMAT rt_format, UINT filter_setting, DXVA2_ValueRange *range)
373 FIXME("%p, %s, %p, %d, %d, %p.\n", iface, debugstr_guid(deviceguid), video_desc, rt_format, filter_setting, range);
375 return E_NOTIMPL;
378 static HRESULT WINAPI device_manager_processor_service_CreateVideoProcessor(IDirectXVideoProcessorService *iface,
379 REFGUID deviceguid, const DXVA2_VideoDesc *video_desc, D3DFORMAT rt_format, UINT max_substreams,
380 IDirectXVideoProcessor **processor)
382 struct video_processor *object;
384 FIXME("%p, %s, %p, %d, %u, %p.\n", iface, debugstr_guid(deviceguid), video_desc, rt_format, max_substreams,
385 processor);
387 /* FIXME: validate render target format */
389 if (!(object = heap_alloc_zero(sizeof(*object))))
390 return E_OUTOFMEMORY;
392 object->IDirectXVideoProcessor_iface.lpVtbl = &video_processor_vtbl;
393 object->refcount = 1;
394 object->service = iface;
395 IDirectXVideoProcessorService_AddRef(object->service);
397 *processor = &object->IDirectXVideoProcessor_iface;
399 return S_OK;
402 static const IDirectXVideoProcessorServiceVtbl device_manager_processor_service_vtbl =
404 device_manager_processor_service_QueryInterface,
405 device_manager_processor_service_AddRef,
406 device_manager_processor_service_Release,
407 device_manager_processor_service_CreateSurface,
408 device_manager_processor_service_RegisterVideoProcessorSoftwareDevice,
409 device_manager_processor_service_GetVideoProcessorDeviceGuids,
410 device_manager_processor_service_GetVideoProcessorRenderTargets,
411 device_manager_processor_service_GetVideoProcessorSubStreamFormats,
412 device_manager_processor_service_GetVideoProcessorCaps,
413 device_manager_processor_service_GetProcAmpRange,
414 device_manager_processor_service_GetFilterPropertyRange,
415 device_manager_processor_service_CreateVideoProcessor,
418 static HRESULT WINAPI device_manager_QueryInterface(IDirect3DDeviceManager9 *iface, REFIID riid, void **obj)
420 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
422 if (IsEqualIID(&IID_IDirect3DDeviceManager9, riid) ||
423 IsEqualIID(&IID_IUnknown, riid))
425 *obj = iface;
426 IDirect3DDeviceManager9_AddRef(iface);
427 return S_OK;
430 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
431 *obj = NULL;
432 return E_NOINTERFACE;
435 static ULONG WINAPI device_manager_AddRef(IDirect3DDeviceManager9 *iface)
437 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
438 ULONG refcount = InterlockedIncrement(&manager->refcount);
440 TRACE("%p, refcount %u.\n", iface, refcount);
442 return refcount;
445 static ULONG WINAPI device_manager_Release(IDirect3DDeviceManager9 *iface)
447 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
448 ULONG refcount = InterlockedDecrement(&manager->refcount);
449 size_t i;
451 TRACE("%p, refcount %u.\n", iface, refcount);
453 if (!refcount)
455 if (manager->device)
456 IDirect3DDevice9_Release(manager->device);
457 DeleteCriticalSection(&manager->cs);
458 for (i = 0; i < manager->count; ++i)
460 if (manager->handles[i].state_block)
461 IDirect3DStateBlock9_Release(manager->handles[i].state_block);
463 heap_free(manager->handles);
464 heap_free(manager);
467 return refcount;
470 static HRESULT WINAPI device_manager_ResetDevice(IDirect3DDeviceManager9 *iface, IDirect3DDevice9 *device,
471 UINT token)
473 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
474 size_t i;
476 TRACE("%p, %p, %#x.\n", iface, device, token);
478 if (token != manager->token)
479 return E_INVALIDARG;
481 EnterCriticalSection(&manager->cs);
482 if (manager->device)
484 for (i = 0; i < manager->count; ++i)
486 if (manager->handles[i].state_block)
487 IDirect3DStateBlock9_Release(manager->handles[i].state_block);
488 manager->handles[i].state_block = NULL;
489 manager->handles[i].flags |= HANDLE_FLAG_INVALID;
491 manager->locking_handle = NULL;
492 IDirect3DDevice9_Release(manager->device);
494 manager->device = device;
495 IDirect3DDevice9_AddRef(manager->device);
496 LeaveCriticalSection(&manager->cs);
498 WakeAllConditionVariable(&manager->lock);
500 return S_OK;
503 static HRESULT WINAPI device_manager_OpenDeviceHandle(IDirect3DDeviceManager9 *iface, HANDLE *hdevice)
505 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
506 HRESULT hr = S_OK;
507 size_t i;
509 TRACE("%p, %p.\n", iface, hdevice);
511 *hdevice = NULL;
513 EnterCriticalSection(&manager->cs);
514 if (!manager->device)
515 hr = DXVA2_E_NOT_INITIALIZED;
516 else
518 for (i = 0; i < manager->count; ++i)
520 if (!(manager->handles[i].flags & HANDLE_FLAG_OPEN))
522 manager->handles[i].flags |= HANDLE_FLAG_OPEN;
523 *hdevice = ULongToHandle(i + 1);
524 break;
528 if (dxva_array_reserve((void **)&manager->handles, &manager->capacity, manager->count + 1,
529 sizeof(*manager->handles)))
531 *hdevice = ULongToHandle(manager->count + 1);
532 manager->handles[manager->count].flags = HANDLE_FLAG_OPEN;
533 manager->handles[manager->count].state_block = NULL;
534 manager->count++;
536 else
537 hr = E_OUTOFMEMORY;
539 LeaveCriticalSection(&manager->cs);
541 return hr;
544 static HRESULT device_manager_get_handle_index(struct device_manager *manager, HANDLE hdevice, size_t *idx)
546 if (hdevice > ULongToHandle(manager->count))
547 return E_HANDLE;
548 *idx = (ULONG_PTR)hdevice - 1;
549 return S_OK;
552 static HRESULT WINAPI device_manager_CloseDeviceHandle(IDirect3DDeviceManager9 *iface, HANDLE hdevice)
554 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
555 HRESULT hr;
556 size_t idx;
558 TRACE("%p, %p.\n", iface, hdevice);
560 EnterCriticalSection(&manager->cs);
561 if (SUCCEEDED(hr = device_manager_get_handle_index(manager, hdevice, &idx)))
563 if (manager->handles[idx].flags & HANDLE_FLAG_OPEN)
565 if (manager->locking_handle == hdevice)
566 manager->locking_handle = NULL;
567 manager->handles[idx].flags = 0;
568 if (idx == manager->count - 1)
569 manager->count--;
570 if (manager->handles[idx].state_block)
571 IDirect3DStateBlock9_Release(manager->handles[idx].state_block);
572 manager->handles[idx].state_block = NULL;
574 else
575 hr = E_HANDLE;
577 LeaveCriticalSection(&manager->cs);
579 WakeAllConditionVariable(&manager->lock);
581 return hr;
584 static HRESULT WINAPI device_manager_TestDevice(IDirect3DDeviceManager9 *iface, HANDLE hdevice)
586 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
587 HRESULT hr;
588 size_t idx;
590 TRACE("%p, %p.\n", iface, hdevice);
592 EnterCriticalSection(&manager->cs);
593 if (SUCCEEDED(hr = device_manager_get_handle_index(manager, hdevice, &idx)))
595 unsigned int flags = manager->handles[idx].flags;
597 if (flags & HANDLE_FLAG_INVALID)
598 hr = DXVA2_E_NEW_VIDEO_DEVICE;
599 else if (!(flags & HANDLE_FLAG_OPEN))
600 hr = E_HANDLE;
602 LeaveCriticalSection(&manager->cs);
604 return hr;
607 static HRESULT WINAPI device_manager_LockDevice(IDirect3DDeviceManager9 *iface, HANDLE hdevice,
608 IDirect3DDevice9 **device, BOOL block)
610 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
611 HRESULT hr;
612 size_t idx;
614 TRACE("%p, %p, %p, %d.\n", iface, hdevice, device, block);
616 EnterCriticalSection(&manager->cs);
617 if (!manager->device)
618 hr = DXVA2_E_NOT_INITIALIZED;
619 else if (SUCCEEDED(hr = device_manager_get_handle_index(manager, hdevice, &idx)))
621 if (manager->locking_handle && !block)
622 hr = DXVA2_E_VIDEO_DEVICE_LOCKED;
623 else
625 while (manager->locking_handle && block)
627 SleepConditionVariableCS(&manager->lock, &manager->cs, INFINITE);
630 if (SUCCEEDED(hr = device_manager_get_handle_index(manager, hdevice, &idx)))
632 if (manager->handles[idx].flags & HANDLE_FLAG_INVALID)
633 hr = DXVA2_E_NEW_VIDEO_DEVICE;
634 else
636 if (manager->handles[idx].state_block)
638 if (FAILED(IDirect3DStateBlock9_Apply(manager->handles[idx].state_block)))
639 WARN("Failed to apply state.\n");
640 IDirect3DStateBlock9_Release(manager->handles[idx].state_block);
641 manager->handles[idx].state_block = NULL;
643 *device = manager->device;
644 IDirect3DDevice9_AddRef(*device);
645 manager->locking_handle = hdevice;
650 LeaveCriticalSection(&manager->cs);
652 return hr;
655 static HRESULT WINAPI device_manager_UnlockDevice(IDirect3DDeviceManager9 *iface, HANDLE hdevice, BOOL savestate)
657 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
658 HRESULT hr;
659 size_t idx;
661 TRACE("%p, %p, %d.\n", iface, hdevice, savestate);
663 EnterCriticalSection(&manager->cs);
665 if (hdevice != manager->locking_handle)
666 hr = E_INVALIDARG;
667 else if (SUCCEEDED(hr = device_manager_get_handle_index(manager, hdevice, &idx)))
669 manager->locking_handle = NULL;
670 if (savestate)
671 IDirect3DDevice9_CreateStateBlock(manager->device, D3DSBT_ALL, &manager->handles[idx].state_block);
674 LeaveCriticalSection(&manager->cs);
676 WakeAllConditionVariable(&manager->lock);
678 return hr;
681 static HRESULT WINAPI device_manager_GetVideoService(IDirect3DDeviceManager9 *iface, HANDLE hdevice, REFIID riid,
682 void **obj)
684 struct device_manager *manager = impl_from_IDirect3DDeviceManager9(iface);
685 HRESULT hr;
686 size_t idx;
688 TRACE("%p, %p, %s, %p.\n", iface, hdevice, debugstr_guid(riid), obj);
690 EnterCriticalSection(&manager->cs);
691 if (SUCCEEDED(hr = device_manager_get_handle_index(manager, hdevice, &idx)))
693 unsigned int flags = manager->handles[idx].flags;
695 if (flags & HANDLE_FLAG_INVALID)
696 hr = DXVA2_E_NEW_VIDEO_DEVICE;
697 else if (!(flags & HANDLE_FLAG_OPEN))
698 hr = E_HANDLE;
699 else
700 hr = IDirectXVideoProcessorService_QueryInterface(&manager->IDirectXVideoProcessorService_iface,
701 riid, obj);
703 LeaveCriticalSection(&manager->cs);
705 return hr;
708 static const IDirect3DDeviceManager9Vtbl device_manager_vtbl =
710 device_manager_QueryInterface,
711 device_manager_AddRef,
712 device_manager_Release,
713 device_manager_ResetDevice,
714 device_manager_OpenDeviceHandle,
715 device_manager_CloseDeviceHandle,
716 device_manager_TestDevice,
717 device_manager_LockDevice,
718 device_manager_UnlockDevice,
719 device_manager_GetVideoService,
722 BOOL WINAPI CapabilitiesRequestAndCapabilitiesReply( HMONITOR monitor, LPSTR buffer, DWORD length )
724 FIXME("(%p, %p, %d): stub\n", monitor, buffer, length);
726 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
727 return FALSE;
730 HRESULT WINAPI DXVA2CreateDirect3DDeviceManager9(UINT *token, IDirect3DDeviceManager9 **manager)
732 struct device_manager *object;
734 TRACE("%p, %p.\n", token, manager);
736 *manager = NULL;
738 if (!(object = heap_alloc_zero(sizeof(*object))))
739 return E_OUTOFMEMORY;
741 object->IDirect3DDeviceManager9_iface.lpVtbl = &device_manager_vtbl;
742 object->IDirectXVideoProcessorService_iface.lpVtbl = &device_manager_processor_service_vtbl;
743 object->refcount = 1;
744 object->token = GetTickCount();
745 InitializeCriticalSection(&object->cs);
746 InitializeConditionVariable(&object->lock);
748 *token = object->token;
749 *manager = &object->IDirect3DDeviceManager9_iface;
751 return S_OK;
754 HRESULT WINAPI DXVA2CreateVideoService(IDirect3DDevice9 *device, REFIID riid, void **obj)
756 IDirect3DDeviceManager9 *manager;
757 HANDLE handle;
758 HRESULT hr;
759 UINT token;
761 TRACE("%p, %s, %p.\n", device, debugstr_guid(riid), obj);
763 if (FAILED(hr = DXVA2CreateDirect3DDeviceManager9(&token, &manager)))
764 return hr;
766 if (FAILED(hr = IDirect3DDeviceManager9_ResetDevice(manager, device, token)))
767 goto done;
769 if (FAILED(hr = IDirect3DDeviceManager9_OpenDeviceHandle(manager, &handle)))
770 goto done;
772 hr = IDirect3DDeviceManager9_GetVideoService(manager, handle, riid, obj);
773 IDirect3DDeviceManager9_CloseDeviceHandle(manager, handle);
775 done:
776 IDirect3DDeviceManager9_Release(manager);
778 return hr;
781 BOOL WINAPI DegaussMonitor( HMONITOR monitor )
783 FIXME("(%p): stub\n", monitor);
785 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
786 return FALSE;
789 BOOL WINAPI DestroyPhysicalMonitor( HMONITOR monitor )
791 FIXME("(%p): stub\n", monitor);
793 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
794 return FALSE;
797 BOOL WINAPI DestroyPhysicalMonitors( DWORD arraySize, LPPHYSICAL_MONITOR array )
799 FIXME("(0x%x, %p): stub\n", arraySize, array);
801 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
802 return FALSE;
805 BOOL WINAPI GetCapabilitiesStringLength( HMONITOR monitor, LPDWORD length )
807 FIXME("(%p, %p): stub\n", monitor, length);
809 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
810 return FALSE;
813 BOOL WINAPI GetMonitorBrightness( HMONITOR monitor, LPDWORD minimum, LPDWORD current, LPDWORD maximum )
815 FIXME("(%p, %p, %p, %p): stub\n", monitor, minimum, current, maximum);
817 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
818 return FALSE;
821 BOOL WINAPI GetMonitorCapabilities( HMONITOR monitor, LPDWORD capabilities, LPDWORD temperatures )
823 FIXME("(%p, %p, %p): stub\n", monitor, capabilities, temperatures);
825 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
826 return FALSE;
830 BOOL WINAPI GetMonitorColorTemperature( HMONITOR monitor, LPMC_COLOR_TEMPERATURE temperature )
832 FIXME("(%p, %p): stub\n", monitor, temperature);
834 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
835 return FALSE;
838 BOOL WINAPI GetMonitorContrast( HMONITOR monitor, LPDWORD minimum, LPDWORD current, LPDWORD maximum )
840 FIXME("(%p, %p, %p, %p): stub\n", monitor, minimum, current, maximum);
842 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
843 return FALSE;
846 BOOL WINAPI GetMonitorDisplayAreaPosition( HMONITOR monitor, MC_POSITION_TYPE type, LPDWORD minimum,
847 LPDWORD current, LPDWORD maximum )
849 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor, type, minimum, current, maximum);
851 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
852 return FALSE;
855 BOOL WINAPI GetMonitorDisplayAreaSize( HMONITOR monitor, MC_SIZE_TYPE type, LPDWORD minimum,
856 LPDWORD current, LPDWORD maximum )
858 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor, type, minimum, current, maximum);
860 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
861 return FALSE;
864 BOOL WINAPI GetMonitorRedGreenOrBlueDrive( HMONITOR monitor, MC_DRIVE_TYPE type, LPDWORD minimum,
865 LPDWORD current, LPDWORD maximum )
867 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor, type, minimum, current, maximum);
869 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
870 return FALSE;
873 BOOL WINAPI GetMonitorRedGreenOrBlueGain( HMONITOR monitor, MC_GAIN_TYPE type, LPDWORD minimum,
874 LPDWORD current, LPDWORD maximum )
876 FIXME("(%p, 0x%x, %p, %p, %p): stub\n", monitor, type, minimum, current, maximum);
878 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
879 return FALSE;
882 BOOL WINAPI GetMonitorTechnologyType( HMONITOR monitor, LPMC_DISPLAY_TECHNOLOGY_TYPE type )
884 FIXME("(%p, %p): stub\n", monitor, type);
886 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
887 return FALSE;
890 BOOL WINAPI GetNumberOfPhysicalMonitorsFromHMONITOR( HMONITOR monitor, LPDWORD number )
892 FIXME("(%p, %p): stub\n", monitor, number);
894 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
895 return FALSE;
898 HRESULT WINAPI GetNumberOfPhysicalMonitorsFromIDirect3DDevice9( IDirect3DDevice9 *device, LPDWORD number )
900 FIXME("(%p, %p): stub\n", device, number);
902 return E_NOTIMPL;
905 BOOL WINAPI GetPhysicalMonitorsFromHMONITOR( HMONITOR monitor, DWORD arraySize, LPPHYSICAL_MONITOR array )
907 FIXME("(%p, 0x%x, %p): stub\n", monitor, arraySize, array);
909 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
910 return FALSE;
913 HRESULT WINAPI GetPhysicalMonitorsFromIDirect3DDevice9( IDirect3DDevice9 *device, DWORD arraySize, LPPHYSICAL_MONITOR array )
915 FIXME("(%p, 0x%x, %p): stub\n", device, arraySize, array);
917 return E_NOTIMPL;
920 BOOL WINAPI GetTimingReport( HMONITOR monitor, LPMC_TIMING_REPORT timingReport )
922 FIXME("(%p, %p): stub\n", monitor, timingReport);
924 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
925 return FALSE;
928 BOOL WINAPI GetVCPFeatureAndVCPFeatureReply( HMONITOR monitor, BYTE vcpCode, LPMC_VCP_CODE_TYPE pvct,
929 LPDWORD current, LPDWORD maximum )
931 FIXME("(%p, 0x%02x, %p, %p, %p): stub\n", monitor, vcpCode, pvct, current, maximum);
933 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
934 return FALSE;
937 HRESULT WINAPI OPMGetVideoOutputsFromHMONITOR( HMONITOR monitor, /* OPM_VIDEO_OUTPUT_SEMANTICS */ int vos,
938 ULONG *numVideoOutputs, /* IOPMVideoOutput */ void ***videoOutputs )
940 FIXME("(%p, 0x%x, %p, %p): stub\n", monitor, vos, numVideoOutputs, videoOutputs);
942 return E_NOTIMPL;
945 HRESULT WINAPI OPMGetVideoOutputsFromIDirect3DDevice9Object( IDirect3DDevice9 *device, /* OPM_VIDEO_OUTPUT_SEMANTICS */ int vos,
946 ULONG *numVideoOutputs, /* IOPMVideoOutput */ void ***videoOutputs )
948 FIXME("(%p, 0x%x, %p, %p): stub\n", device, vos, numVideoOutputs, videoOutputs);
950 return E_NOTIMPL;
953 BOOL WINAPI RestoreMonitorFactoryColorDefaults( HMONITOR monitor )
955 FIXME("(%p): stub\n", monitor);
957 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
958 return FALSE;
961 BOOL WINAPI RestoreMonitorFactoryDefaults( HMONITOR monitor )
963 FIXME("(%p): stub\n", monitor);
965 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
966 return FALSE;
969 BOOL WINAPI SaveCurrentMonitorSettings( HMONITOR monitor )
971 FIXME("(%p): stub\n", monitor);
973 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
974 return FALSE;
977 BOOL WINAPI SaveCurrentSettings( HMONITOR monitor )
979 FIXME("(%p): stub\n", monitor);
981 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
982 return FALSE;
985 BOOL WINAPI SetMonitorBrightness( HMONITOR monitor, DWORD brightness )
987 FIXME("(%p, 0x%x): stub\n", monitor, brightness);
989 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
990 return FALSE;
993 BOOL WINAPI SetMonitorColorTemperature( HMONITOR monitor, MC_COLOR_TEMPERATURE temperature )
995 FIXME("(%p, 0x%x): stub\n", monitor, temperature);
997 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
998 return FALSE;
1001 BOOL WINAPI SetMonitorContrast( HMONITOR monitor, DWORD contrast )
1003 FIXME("(%p, 0x%x): stub\n", monitor, contrast);
1005 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1006 return FALSE;
1009 BOOL WINAPI SetMonitorDisplayAreaPosition( HMONITOR monitor, MC_POSITION_TYPE type, DWORD position )
1011 FIXME("(%p, 0x%x, 0x%x): stub\n", monitor, type, position);
1013 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1014 return FALSE;
1017 BOOL WINAPI SetMonitorDisplayAreaSize( HMONITOR monitor, MC_SIZE_TYPE type, DWORD size )
1019 FIXME("(%p, 0x%x, 0x%x): stub\n", monitor, type, size);
1021 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1022 return FALSE;
1025 BOOL WINAPI SetMonitorRedGreenOrBlueDrive( HMONITOR monitor, MC_DRIVE_TYPE type, DWORD drive )
1027 FIXME("(%p, 0x%x, 0x%x): stub\n", monitor, type, drive);
1029 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1030 return FALSE;
1033 BOOL WINAPI SetMonitorRedGreenOrBlueGain( HMONITOR monitor, MC_GAIN_TYPE type, DWORD gain )
1035 FIXME("(%p, 0x%x, 0x%x): stub\n", monitor, type, gain);
1037 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1038 return FALSE;
1041 BOOL WINAPI SetVCPFeature( HMONITOR monitor, BYTE vcpCode, DWORD value )
1043 FIXME("(%p, 0x%02x, 0x%x): stub\n", monitor, vcpCode, value);
1045 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1046 return FALSE;
1049 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
1051 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
1053 switch (fdwReason) {
1054 case DLL_WINE_PREATTACH:
1055 return FALSE; /* prefer native version */
1056 case DLL_PROCESS_ATTACH:
1057 DisableThreadLibraryCalls(hinstDLL);
1058 break;
1061 return TRUE;