ReactOS 0.4.17-dev-923-g4c9a150
vmr7_presenter.c
Go to the documentation of this file.
1/*
2 * Default allocator-presenter for the VMR7
3 *
4 * Copyright 2023 Zebediah Figura for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "quartz_private.h"
22
23#include "wine/debug.h"
24
26
28{
33
38
40};
41
43{
45}
46
48{
50
51 TRACE("presenter %p, iid %s, out %p.\n", presenter, debugstr_guid(iid), out);
52
53 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IVMRImagePresenter))
54 *out = iface;
55 else if (IsEqualGUID(iid, &IID_IVMRSurfaceAllocator))
57 else if (IsEqualGUID(iid, &IID_IVMRWindowlessControl))
58 *out = &presenter->IVMRWindowlessControl_iface;
59 else
60 {
61 *out = NULL;
62 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
63 return E_NOINTERFACE;
64 }
65
66 IUnknown_AddRef((IUnknown *)*out);
67 return S_OK;
68}
69
71{
74
75 TRACE("%p increasing refcount to %lu.\n", presenter, refcount);
76 return refcount;
77}
78
80{
83
84 TRACE("%p decreasing refcount to %lu.\n", presenter, refcount);
85 if (!refcount)
86 {
87 if (presenter->frontbuffer)
88 IDirectDrawSurface7_Release(presenter->frontbuffer);
89 IDirectDrawSurface7_Release(presenter->primary);
90 IDirectDraw7_Release(presenter->ddraw);
92 }
93 return refcount;
94}
95
97{
98 FIXME("iface %p, cookie %#Ix, stub!\n", iface, cookie);
99 return E_NOTIMPL;
100}
101
103{
104 FIXME("iface %p, cookie %#Ix, stub!\n", iface, cookie);
105 return E_NOTIMPL;
106}
107
110{
112 POINT point;
113 HRESULT hr;
114 RECT rect;
115
116 TRACE("iface %p, cookie %#Ix, info %p.\n", iface, cookie, info);
117
118 TRACE("flags %#lx, surface %p, start %s, end %s, aspect ratio %ldx%ld,\n",
119 info->dwFlags, info->lpSurf, debugstr_time(info->rtStart),
120 debugstr_time(info->rtEnd), info->szAspectRatio.cx, info->szAspectRatio.cy);
121 TRACE("src %s, dst %s, type-specific flags %#lx, interlace flags %#lx.\n",
122 wine_dbgstr_rect(&info->rcSrc), wine_dbgstr_rect(&info->rcDst),
123 info->dwTypeSpecificFlags, info->dwInterlaceFlags);
124
125 if (info->dwFlags & VMRSample_SrcDstRectsValid)
126 FIXME("Ignoring src/dst rects.\n");
127
128 GetClientRect(presenter->window, &rect);
129 point.x = point.y = 0;
130 ClientToScreen(presenter->window, &point);
132 if (FAILED(hr = IDirectDrawSurface7_Blt(presenter->primary, &rect, info->lpSurf, NULL, DDBLT_WAIT, NULL)))
133 ERR("Failed to blit, hr %#lx.\n", hr);
134
135 return S_OK;
136}
137
138static const IVMRImagePresenterVtbl image_presenter_vtbl =
139{
146};
147
149{
151}
152
154{
156
157 return IVMRImagePresenter_QueryInterface(&presenter->IVMRImagePresenter_iface, iid, out);
158}
159
161{
163
164 return IVMRImagePresenter_AddRef(&presenter->IVMRImagePresenter_iface);
165}
166
168{
170
171 return IVMRImagePresenter_Release(&presenter->IVMRImagePresenter_iface);
172}
173
176{
178 DDSURFACEDESC2 surface_desc = {.dwSize = sizeof(surface_desc)};
179 HRESULT hr;
180
181 TRACE("presenter %p, id %#Ix, info %p, count %p, surface %p.\n", presenter, id, info, count, surface);
182
184 surface_desc.dwWidth = info->lpHdr->biWidth;
185 surface_desc.dwHeight = info->lpHdr->biHeight;
186 surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
188 surface_desc.dwBackBufferCount = *count;
189
190 if (info->lpHdr->biCompression == BI_RGB)
191 {
192 if (info->lpHdr->biBitCount != 32)
193 {
194 FIXME("Unhandled bit depth %u.\n", info->lpHdr->biBitCount);
195 return E_NOTIMPL;
196 }
197
198 surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
199 surface_desc.ddpfPixelFormat.dwRGBBitCount = 32;
200 surface_desc.ddpfPixelFormat.dwRBitMask = 0x00ff0000;
201 surface_desc.ddpfPixelFormat.dwGBitMask = 0x0000ff00;
202 surface_desc.ddpfPixelFormat.dwBBitMask = 0x000000ff;
203 }
204 else
205 {
206 surface_desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
207 surface_desc.ddpfPixelFormat.dwFourCC = info->lpHdr->biCompression;
208 }
209
210 if (FAILED(hr = IDirectDraw7_CreateSurface(presenter->ddraw,
211 &surface_desc, &presenter->frontbuffer, NULL)))
212 {
213 WARN("Failed to create surface, hr %#lx.\n", hr);
214 return hr;
215 }
216 *surface = presenter->frontbuffer;
217 ++*count;
218
219 presenter->native_size = info->szNativeSize;
220 presenter->aspect_ratio = info->szAspectRatio;
221
222 return S_OK;
223}
224
226{
228 DDSURFACEDESC2 surface_desc = {.dwSize = sizeof(surface_desc)};
229
230 TRACE("presenter %p, id %#Ix.\n", presenter, id);
231
232 if (presenter->frontbuffer)
233 {
234 IDirectDrawSurface7_Release(presenter->frontbuffer);
235 presenter->frontbuffer = NULL;
236 }
237
238 return S_OK;
239}
240
243{
244 TRACE("iface %p, id %#Ix, surface %p, flags %#lx.\n", iface, id, surface, flags);
245 return S_OK;
246}
247
250{
251 FIXME("iface %p, notify %p, stub!\n", iface, notify);
252 return S_OK;
253}
254
255static const IVMRSurfaceAllocatorVtbl surface_allocator_vtbl =
256{
264};
265
267{
269}
270
272{
274
275 return IVMRImagePresenter_QueryInterface(&presenter->IVMRImagePresenter_iface, iid, out);
276}
277
279{
281
282 return IVMRImagePresenter_AddRef(&presenter->IVMRImagePresenter_iface);
283}
284
286{
288
289 return IVMRImagePresenter_Release(&presenter->IVMRImagePresenter_iface);
290}
291
293 LONG *width, LONG *height, LONG *aspect_width, LONG *aspect_height)
294{
296
297 TRACE("iface %p, width %p, height %p, aspect_width %p, aspect_height %p.\n",
298 iface, width, height, aspect_width, aspect_height);
299
300 if (width)
301 *width = presenter->native_size.cx;
302 if (height)
303 *height = presenter->native_size.cy;
304 if (aspect_width)
305 *aspect_width = presenter->aspect_ratio.cx;
306 if (aspect_height)
307 *aspect_height = presenter->aspect_ratio.cy;
308
309 TRACE("Returning size (%ld, %ld), aspect ratio (%ld, %ld).\n",
310 presenter->native_size.cx, presenter->native_size.cy,
311 presenter->aspect_ratio.cx, presenter->aspect_ratio.cy);
312 return S_OK;
313}
314
317{
318 FIXME("iface %p, width %p, height %p, stub!\n", iface, width, height);
319 return E_NOTIMPL;
320}
321
324{
325 FIXME("iface %p, width %p, height %p, stub!\n", iface, width, height);
326 return E_NOTIMPL;
327}
328
330 IVMRWindowlessControl *iface, const RECT *source, const RECT *dest)
331{
332 FIXME("iface %p, source %s, dest %s, stub!.\n", iface, wine_dbgstr_rect(source), wine_dbgstr_rect(dest));
333 return E_NOTIMPL;
334}
335
338{
339 FIXME("iface %p, source %p, dest %p.\n", iface, source, dest);
340 return E_NOTIMPL;
341}
342
345{
346 FIXME("iface %p, mode %p, stub!\n", iface, mode);
347 return E_NOTIMPL;
348}
349
352{
353 FIXME("iface %p, mode %#lx, stub!\n", iface, mode);
354 return E_NOTIMPL;
355}
356
359{
361 IDirectDrawClipper *clipper;
362 HRESULT hr;
363
364 TRACE("iface %p, window %p.\n", iface, window);
365
366 if (FAILED(hr = IDirectDraw7_CreateClipper(presenter->ddraw, 0, &clipper, NULL)))
367 ERR("Failed to create clipper, hr %#lx.\n", hr);
368 if (FAILED(hr = IDirectDrawClipper_SetHWnd(clipper, 0, window)))
369 ERR("Failed to set clip window, hr %#lx.\n", hr);
370 if (FAILED(hr = IDirectDrawSurface7_SetClipper(presenter->primary, clipper)))
371 ERR("Failed to set clipper, hr %#lx.\n", hr);
372 IDirectDrawClipper_Release(clipper);
373
374 presenter->window = window;
375
376 return S_OK;
377}
378
381{
382 FIXME("iface %p, window %p, dc %p, stub!\n", iface, window, dc);
383 return E_NOTIMPL;
384}
385
387{
388 FIXME("iface %p, stub!\n", iface);
389 return E_NOTIMPL;
390}
391
393{
394 FIXME("iface %p, image %p, stub!\n", iface, image);
395 return E_NOTIMPL;
396}
397
399{
400 FIXME("iface %p, color %#08lx, stub!\n", iface, color);
401 return E_NOTIMPL;
402}
403
405{
406 FIXME("iface %p, color %p, stub!\n", iface, color);
407 return E_NOTIMPL;
408}
409
411{
412 FIXME("iface %p, color %#08lx, stub!\n", iface, color);
413 return E_NOTIMPL;
414}
415
417{
418 FIXME("iface %p, color %p, stub!\n", iface, color);
419 return E_NOTIMPL;
420}
421
422static const IVMRWindowlessControlVtbl windowless_control_vtbl =
423{
442};
443
445{
446 struct vmr7_presenter *object;
447 HRESULT hr;
448
449 DDSURFACEDESC2 primary_desc =
450 {
451 .dwSize = sizeof(DDSURFACEDESC2),
453 .ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE,
454 };
455
456 TRACE("outer %p, out %p.\n", outer, out);
457
458 if (outer)
459 FIXME("Ignoring outer %p.\n", outer);
460
461 if (!(object = calloc(1, sizeof(*object))))
462 return E_OUTOFMEMORY;
463 object->IVMRImagePresenter_iface.lpVtbl = &image_presenter_vtbl;
464 object->IVMRSurfaceAllocator_iface.lpVtbl = &surface_allocator_vtbl;
465 object->IVMRWindowlessControl_iface.lpVtbl = &windowless_control_vtbl;
466 object->refcount = 1;
467
468 if (FAILED(hr = DirectDrawCreateEx(NULL, (void **)&object->ddraw, &IID_IDirectDraw7, NULL)))
469 {
470 ERR("Failed to create ddraw object, hr %#lx.\n", hr);
471 free(object);
472 return hr;
473 }
474
475 if (FAILED(hr = IDirectDraw7_SetCooperativeLevel(object->ddraw, NULL, DDSCL_NORMAL)))
476 ERR("Failed to set cooperative level, hr %#lx.\n", hr);
477
478 if (FAILED(hr = IDirectDraw7_CreateSurface(object->ddraw, &primary_desc, &object->primary, NULL)))
479 ERR("Failed to create primary surface, hr %#lx.\n", hr);
480
481 TRACE("Created VMR7 default presenter %p.\n", object);
482 *out = (IUnknown *)&object->IVMRSurfaceAllocator_iface;
483 return S_OK;
484}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
const GUID IID_IUnknown
RECT rect
Definition: combotst.c:67
HDC dc
Definition: cylfrac.c:34
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define free
Definition: debug_ros.c:5
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
HRESULT WINAPI DirectDrawCreateEx(LPGUID lpGUID, LPVOID *lplpDD, REFIID id, LPUNKNOWN pUnkOuter)
Definition: main.c:139
#define DDPF_FOURCC
Definition: ddsformat.c:58
#define DDPF_RGB
Definition: ddsformat.c:60
@ VMRSample_SrcDstRectsValid
Definition: vmrender.idl:46
POINTL point
Definition: edittest.c:50
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint color
Definition: glext.h:6243
GLenum mode
Definition: glext.h:6217
GLbitfield flags
Definition: glext.h:7161
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
static HDC
Definition: imagelist.c:88
static IHTMLWindow2 * window
Definition: events.c:77
static char * dest
Definition: rtl.c:149
static IUnknown * outer
Definition: compobj.c:82
int notify
Definition: msacm.c:1366
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
DWORD IDirectDrawSurface7
Definition: vmrender.idl:20
DWORD IDirectDraw7
Definition: vmrender.idl:21
BOOL WINAPI ClientToScreen(_In_ HWND, _Inout_ LPPOINT)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define calloc
Definition: rosglue.h:14
#define DDSD_WIDTH
Definition: ddraw.h:212
#define DDSD_PIXELFORMAT
Definition: ddraw.h:218
#define DDSCL_NORMAL
Definition: ddraw.h:537
struct _DDSURFACEDESC2 DDSURFACEDESC2
#define DDSD_HEIGHT
Definition: ddraw.h:211
#define DDSCAPS_PRIMARYSURFACE
Definition: ddraw.h:260
#define DDSCAPS_OFFSCREENPLAIN
Definition: ddraw.h:257
#define DDSCAPS_FLIP
Definition: ddraw.h:255
#define DDBLT_WAIT
Definition: ddraw.h:571
#define DDSD_CAPS
Definition: ddraw.h:210
#define DDSD_BACKBUFFERCOUNT
Definition: ddraw.h:214
#define DDSCAPS_COMPLEX
Definition: ddraw.h:254
#define TRACE(s)
Definition: solgame.cpp:4
static const char * debugstr_time(REFERENCE_TIME time)
Definition: strmbase.h:32
Definition: dcommon.idl:28
DWORD dwBBitMask
Definition: ddraw.h:1108
DWORD dwSize
Definition: ddraw.h:1072
DWORD dwFourCC
Definition: ddraw.h:1074
DWORD dwRGBBitCount
Definition: ddraw.h:1077
DWORD dwRBitMask
Definition: ddraw.h:1087
DWORD dwGBitMask
Definition: ddraw.h:1096
DWORD dwFlags
Definition: ddraw.h:1073
DWORD dwCaps
Definition: ddraw.h:734
DWORD dwWidth
Definition: ddraw.h:1157
DWORD dwHeight
Definition: ddraw.h:1156
DDSCAPS2 ddsCaps
Definition: ddraw.h:1190
DDPIXELFORMAT ddpfPixelFormat
Definition: ddraw.h:1187
DWORD dwBackBufferCount
Definition: ddraw.h:1165
DWORD dwFlags
Definition: ddraw.h:1155
DWORD dwSize
Definition: ddraw.h:1154
LONG y
Definition: windef.h:130
LONG x
Definition: windef.h:129
Definition: cookie.c:34
Definition: image.c:84
IVMRImagePresenter IVMRImagePresenter_iface
Definition: vmr7.c:3189
IDirectDraw7 * ddraw
Definition: vmr7.c:3192
LONG refcount
Definition: vmr7.c:3190
IVMRSurfaceAllocator IVMRSurfaceAllocator_iface
Definition: vmr7.c:3188
IVMRImagePresenter IVMRImagePresenter_iface
IVMRSurfaceAllocator IVMRSurfaceAllocator_iface
IDirectDraw7 * ddraw
IDirectDrawSurface7 * primary
IVMRWindowlessControl IVMRWindowlessControl_iface
IDirectDrawSurface7 * frontbuffer
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define BI_RGB
Definition: uefivid.c:46
static HRESULT WINAPI windowless_control_GetBorderColor(IVMRWindowlessControl *iface, COLORREF *color)
static HRESULT WINAPI surface_allocator_QueryInterface(IVMRSurfaceAllocator *iface, REFIID iid, void **out)
static struct vmr7_presenter * impl_from_IVMRSurfaceAllocator(IVMRSurfaceAllocator *iface)
static ULONG WINAPI image_presenter_Release(IVMRImagePresenter *iface)
static struct vmr7_presenter * impl_from_IVMRWindowlessControl(IVMRWindowlessControl *iface)
static HRESULT WINAPI windowless_control_GetMaxIdealVideoSize(IVMRWindowlessControl *iface, LONG *width, LONG *height)
static HRESULT WINAPI image_presenter_QueryInterface(IVMRImagePresenter *iface, REFIID iid, void **out)
static HRESULT WINAPI windowless_control_SetVideoClippingWindow(IVMRWindowlessControl *iface, HWND window)
static ULONG WINAPI windowless_control_AddRef(IVMRWindowlessControl *iface)
static HRESULT WINAPI windowless_control_RepaintVideo(IVMRWindowlessControl *iface, HWND window, HDC dc)
static ULONG WINAPI surface_allocator_AddRef(IVMRSurfaceAllocator *iface)
static HRESULT WINAPI surface_allocator_FreeSurface(IVMRSurfaceAllocator *iface, DWORD_PTR id)
static ULONG WINAPI surface_allocator_Release(IVMRSurfaceAllocator *iface)
static HRESULT WINAPI windowless_control_SetVideoPosition(IVMRWindowlessControl *iface, const RECT *source, const RECT *dest)
static HRESULT WINAPI windowless_control_SetBorderColor(IVMRWindowlessControl *iface, COLORREF color)
static HRESULT WINAPI windowless_control_GetMinIdealVideoSize(IVMRWindowlessControl *iface, LONG *width, LONG *height)
static const IVMRSurfaceAllocatorVtbl surface_allocator_vtbl
static HRESULT WINAPI windowless_control_SetAspectRatioMode(IVMRWindowlessControl *iface, DWORD mode)
static HRESULT WINAPI surface_allocator_AdviseNotify(IVMRSurfaceAllocator *iface, IVMRSurfaceAllocatorNotify *notify)
static HRESULT WINAPI image_presenter_PresentImage(IVMRImagePresenter *iface, DWORD_PTR cookie, VMRPRESENTATIONINFO *info)
static HRESULT WINAPI surface_allocator_AllocateSurface(IVMRSurfaceAllocator *iface, DWORD_PTR id, VMRALLOCATIONINFO *info, DWORD *count, IDirectDrawSurface7 **surface)
static const IVMRWindowlessControlVtbl windowless_control_vtbl
static ULONG WINAPI windowless_control_Release(IVMRWindowlessControl *iface)
static HRESULT WINAPI windowless_control_SetColorKey(IVMRWindowlessControl *iface, COLORREF color)
static HRESULT WINAPI windowless_control_QueryInterface(IVMRWindowlessControl *iface, REFIID iid, void **out)
static struct vmr7_presenter * impl_from_IVMRImagePresenter(IVMRImagePresenter *iface)
static HRESULT WINAPI windowless_control_GetNativeVideoSize(IVMRWindowlessControl *iface, LONG *width, LONG *height, LONG *aspect_width, LONG *aspect_height)
static HRESULT WINAPI windowless_control_GetAspectRatioMode(IVMRWindowlessControl *iface, DWORD *mode)
static HRESULT WINAPI windowless_control_GetVideoPosition(IVMRWindowlessControl *iface, RECT *source, RECT *dest)
static ULONG WINAPI image_presenter_AddRef(IVMRImagePresenter *iface)
static HRESULT WINAPI image_presenter_StartPresenting(IVMRImagePresenter *iface, DWORD_PTR cookie)
static HRESULT WINAPI windowless_control_DisplayModeChanged(IVMRWindowlessControl *iface)
static HRESULT WINAPI windowless_control_GetCurrentImage(IVMRWindowlessControl *iface, BYTE **image)
static HRESULT WINAPI image_presenter_StopPresenting(IVMRImagePresenter *iface, DWORD_PTR cookie)
static HRESULT WINAPI surface_allocator_PrepareSurface(IVMRSurfaceAllocator *iface, DWORD_PTR id, IDirectDrawSurface7 *surface, DWORD flags)
static const IVMRImagePresenterVtbl image_presenter_vtbl
static HRESULT WINAPI windowless_control_GetColorKey(IVMRWindowlessControl *iface, COLORREF *color)
HRESULT vmr7_presenter_create(IUnknown *outer, IUnknown **out)
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
DWORD COLORREF
Definition: windef.h:100
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:3479
unsigned char BYTE
Definition: xxhash.c:193