makefiles: Add a makefile for the po directory.
[wine.git] / dlls / ddrawex / surface.c
blob6f1637e644df0d7528f64e4201855676a311b8e4
1 /*
2 * Copyright 2008 Stefan Dösinger for CodeWeavers
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 #include "wine/debug.h"
21 #define COBJMACROS
23 #include "winbase.h"
24 #include "wingdi.h"
26 #include "ddraw.h"
27 #include "d3d.h"
29 #include "ddrawex_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
33 static struct ddrawex_surface *impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface)
35 return CONTAINING_RECORD(iface, struct ddrawex_surface, IDirectDrawSurface3_iface);
38 static struct ddrawex_surface *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface);
40 static struct ddrawex_surface *impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface)
42 return CONTAINING_RECORD(iface, struct ddrawex_surface, IDirectDrawSurface4_iface);
45 static HRESULT WINAPI ddrawex_surface4_QueryInterface(IDirectDrawSurface4 *iface, REFIID riid, void **out)
47 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
49 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
51 if (!riid)
53 *out = NULL;
54 return DDERR_INVALIDPARAMS;
57 if (IsEqualGUID(riid, &IID_IDirectDrawSurface4)
58 || IsEqualGUID(riid, &IID_IUnknown))
60 *out = &surface->IDirectDrawSurface4_iface;
62 else if (IsEqualGUID(riid, &IID_IDirectDrawSurface3)
63 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
64 || IsEqualGUID(riid, &IID_IDirectDrawSurface))
66 *out = &surface->IDirectDrawSurface3_iface;
68 else
70 if (IsEqualGUID(riid, &IID_IDirectDrawGammaControl))
71 FIXME("Implement IDirectDrawGammaControl in ddrawex.\n");
72 else if (IsEqualGUID(riid, &IID_IDirect3DHALDevice)
73 || IsEqualGUID(riid, &IID_IDirect3DRGBDevice))
74 FIXME("Test IDirect3DDevice in ddrawex.\n");
75 else if (IsEqualGUID(&IID_IDirect3DTexture2, riid)
76 || IsEqualGUID( &IID_IDirect3DTexture, riid))
77 FIXME("Implement IDirect3DTexture in ddrawex.\n");
79 *out = NULL;
80 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
81 return E_NOINTERFACE;
84 IUnknown_AddRef((IUnknown *)*out);
85 return S_OK;
88 static HRESULT WINAPI ddrawex_surface3_QueryInterface(IDirectDrawSurface3 *iface, REFIID riid, void **out)
90 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
92 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
94 return ddrawex_surface4_QueryInterface(&surface->IDirectDrawSurface4_iface, riid, out);
97 static ULONG WINAPI ddrawex_surface4_AddRef(IDirectDrawSurface4 *iface)
99 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
100 ULONG refcount = InterlockedIncrement(&surface->ref);
102 TRACE("%p increasing refcount to %u.\n", iface, refcount);
104 return refcount;
107 static ULONG WINAPI ddrawex_surface3_AddRef(IDirectDrawSurface3 *iface)
109 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
111 TRACE("iface %p.\n", iface);
113 return ddrawex_surface4_AddRef(&surface->IDirectDrawSurface4_iface);
116 static ULONG WINAPI ddrawex_surface4_Release(IDirectDrawSurface4 *iface)
118 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
119 ULONG refcount = InterlockedDecrement(&surface->ref);
121 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
123 if (!refcount)
125 IDirectDrawSurface4_FreePrivateData(surface->parent, &IID_DDrawexPriv);
126 IDirectDrawSurface4_Release(surface->parent);
127 HeapFree(GetProcessHeap(), 0, surface);
130 return refcount;
133 static ULONG WINAPI ddrawex_surface3_Release(IDirectDrawSurface3 *iface)
135 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
137 TRACE("iface %p.\n", iface);
139 return ddrawex_surface4_Release(&surface->IDirectDrawSurface4_iface);
142 static HRESULT WINAPI ddrawex_surface4_AddAttachedSurface(IDirectDrawSurface4 *iface,
143 IDirectDrawSurface4 *attachment)
145 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
146 struct ddrawex_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface4(attachment);
148 TRACE("iface %p, attachment %p.\n", iface, attachment);
150 return IDirectDrawSurface4_AddAttachedSurface(surface->parent, attachment_impl->parent);
153 static HRESULT WINAPI ddrawex_surface3_AddAttachedSurface(IDirectDrawSurface3 *iface,
154 IDirectDrawSurface3 *attachment)
156 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
157 struct ddrawex_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment);
159 TRACE("iface %p, attachment %p.\n", iface, attachment);
161 return ddrawex_surface4_AddAttachedSurface(&surface->IDirectDrawSurface4_iface,
162 attachment_impl ? &attachment_impl->IDirectDrawSurface4_iface : NULL);
165 static HRESULT WINAPI ddrawex_surface4_AddOverlayDirtyRect(IDirectDrawSurface4 *iface, RECT *rect)
167 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
169 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
171 return IDirectDrawSurface4_AddOverlayDirtyRect(surface->parent, rect);
174 static HRESULT WINAPI ddrawex_surface3_AddOverlayDirtyRect(IDirectDrawSurface3 *iface, RECT *rect)
176 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
178 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
180 return ddrawex_surface4_AddOverlayDirtyRect(&surface->IDirectDrawSurface4_iface, rect);
183 static HRESULT WINAPI ddrawex_surface4_Blt(IDirectDrawSurface4 *iface, RECT *dst_rect,
184 IDirectDrawSurface4 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
186 struct ddrawex_surface *dst = impl_from_IDirectDrawSurface4(iface);
187 struct ddrawex_surface *src = unsafe_impl_from_IDirectDrawSurface4(src_surface);
189 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
190 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
192 return IDirectDrawSurface4_Blt(dst->parent, dst_rect, src ? src->parent : NULL, src_rect, flags, fx);
195 static HRESULT WINAPI ddrawex_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_rect,
196 IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
198 struct ddrawex_surface *dst = impl_from_IDirectDrawSurface3(iface);
199 struct ddrawex_surface *src = unsafe_impl_from_IDirectDrawSurface3(src_surface);
201 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
202 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
204 return ddrawex_surface4_Blt(&dst->IDirectDrawSurface4_iface, dst_rect,
205 src ? &src->IDirectDrawSurface4_iface : NULL, src_rect, flags, fx);
208 static HRESULT WINAPI ddrawex_surface4_BltBatch(IDirectDrawSurface4 *iface,
209 DDBLTBATCH *batch, DWORD count, DWORD flags)
211 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
213 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
215 return IDirectDrawSurface4_BltBatch(surface->parent, batch, count, flags);
218 static HRESULT WINAPI ddrawex_surface3_BltBatch(IDirectDrawSurface3 *iface,
219 DDBLTBATCH *batch, DWORD count, DWORD flags)
221 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
223 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
225 return ddrawex_surface4_BltBatch(&surface->IDirectDrawSurface4_iface, batch, count, flags);
228 static HRESULT WINAPI ddrawex_surface4_BltFast(IDirectDrawSurface4 *iface, DWORD dst_x,
229 DWORD dst_y, IDirectDrawSurface4 *src_surface, RECT *src_rect, DWORD flags)
231 struct ddrawex_surface *dst = impl_from_IDirectDrawSurface4(iface);
232 struct ddrawex_surface *src = unsafe_impl_from_IDirectDrawSurface4(src_surface);
234 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
235 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
237 return IDirectDrawSurface4_BltFast(dst->parent, dst_x, dst_y,
238 src ? src->parent : NULL, src_rect, flags);
241 static HRESULT WINAPI ddrawex_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD dst_x,
242 DWORD dst_y, IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags)
244 struct ddrawex_surface *dst = impl_from_IDirectDrawSurface3(iface);
245 struct ddrawex_surface *src = unsafe_impl_from_IDirectDrawSurface3(src_surface);
247 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
248 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
250 return ddrawex_surface4_BltFast(&dst->IDirectDrawSurface4_iface, dst_x, dst_y,
251 src ? &src->IDirectDrawSurface4_iface : NULL, src_rect, flags);
254 static HRESULT WINAPI ddrawex_surface4_DeleteAttachedSurface(IDirectDrawSurface4 *iface,
255 DWORD flags, IDirectDrawSurface4 *attachment)
257 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
258 struct ddrawex_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface4(attachment);
260 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
262 return IDirectDrawSurface4_DeleteAttachedSurface(surface->parent,
263 flags, attachment_impl ? attachment_impl->parent : NULL);
266 static HRESULT WINAPI ddrawex_surface3_DeleteAttachedSurface(IDirectDrawSurface3 *iface,
267 DWORD flags, IDirectDrawSurface3 *attachment)
269 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
270 struct ddrawex_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment);
272 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
274 return ddrawex_surface4_DeleteAttachedSurface(&surface->IDirectDrawSurface4_iface,
275 flags, attachment_impl ? &attachment_impl->IDirectDrawSurface4_iface : NULL);
278 struct enumsurfaces_wrap
280 LPDDENUMSURFACESCALLBACK2 orig_cb;
281 void *orig_ctx;
284 static HRESULT WINAPI
285 enumsurfaces_wrap_cb(IDirectDrawSurface4 *surf, DDSURFACEDESC2 *desc, void *vctx)
287 struct enumsurfaces_wrap *ctx = vctx;
288 IDirectDrawSurface4 *outer = dds_get_outer(surf);
290 TRACE("Returning outer surface %p for inner surface %p\n", outer, surf);
291 IDirectDrawSurface4_AddRef(outer);
292 IDirectDrawSurface4_Release(surf);
293 return ctx->orig_cb(outer, desc, vctx);
296 static HRESULT WINAPI ddrawex_surface4_EnumAttachedSurfaces(IDirectDrawSurface4 *iface,
297 void *ctx, LPDDENUMSURFACESCALLBACK2 cb)
299 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
300 struct enumsurfaces_wrap cb_ctx;
302 TRACE("iface %p, ctx %p, cb %p.\n", iface, ctx, cb);
304 cb_ctx.orig_cb = cb;
305 cb_ctx.orig_ctx = ctx;
306 return IDirectDrawSurface4_EnumAttachedSurfaces(surface->parent, &cb_ctx, enumsurfaces_wrap_cb);
309 struct enumsurfaces_thunk
311 LPDDENUMSURFACESCALLBACK orig_cb;
312 void *orig_ctx;
315 static HRESULT WINAPI enumsurfaces_thunk_cb(IDirectDrawSurface4 *surf, DDSURFACEDESC2 *desc2,
316 void *vctx)
318 struct ddrawex_surface *surface = unsafe_impl_from_IDirectDrawSurface4(surf);
319 struct enumsurfaces_thunk *ctx = vctx;
320 DDSURFACEDESC desc;
322 TRACE("Thunking back to IDirectDrawSurface3\n");
323 IDirectDrawSurface3_AddRef(&surface->IDirectDrawSurface3_iface);
324 IDirectDrawSurface3_Release(surf);
325 DDSD2_to_DDSD(desc2, &desc);
326 return ctx->orig_cb((IDirectDrawSurface *)&surface->IDirectDrawSurface3_iface, &desc, ctx->orig_ctx);
329 static HRESULT WINAPI ddrawex_surface3_EnumAttachedSurfaces(IDirectDrawSurface3 *iface,
330 void *ctx, LPDDENUMSURFACESCALLBACK cb)
332 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
333 struct enumsurfaces_thunk cb_ctx;
335 TRACE("iface %p, ctx %p, cb %p.\n", iface, ctx, cb);
337 cb_ctx.orig_cb = cb;
338 cb_ctx.orig_ctx = ctx;
339 return ddrawex_surface4_EnumAttachedSurfaces(&surface->IDirectDrawSurface4_iface, &cb_ctx, enumsurfaces_thunk_cb);
342 static HRESULT WINAPI ddrawex_surface4_EnumOverlayZOrders(IDirectDrawSurface4 *iface,
343 DWORD flags, void *ctx, LPDDENUMSURFACESCALLBACK2 cb)
345 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
346 struct enumsurfaces_wrap cb_ctx;
348 TRACE("iface %p, flags %#x, ctx %p, cb %p.\n", iface, flags, ctx, cb);
350 cb_ctx.orig_cb = cb;
351 cb_ctx.orig_ctx = ctx;
352 return IDirectDrawSurface4_EnumOverlayZOrders(surface->parent, flags, &cb_ctx, enumsurfaces_wrap_cb);
355 static HRESULT WINAPI ddrawex_surface3_EnumOverlayZOrders(IDirectDrawSurface3 *iface,
356 DWORD flags, void *ctx, LPDDENUMSURFACESCALLBACK cb)
358 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
359 struct enumsurfaces_thunk cb_ctx;
361 TRACE("iface %p, flags %#x, ctx %p, cb %p.\n", iface, flags, ctx, cb);
363 cb_ctx.orig_cb = cb;
364 cb_ctx.orig_ctx = ctx;
365 return ddrawex_surface4_EnumOverlayZOrders(&surface->IDirectDrawSurface4_iface,
366 flags, &cb_ctx, enumsurfaces_thunk_cb);
369 static HRESULT WINAPI ddrawex_surface4_Flip(IDirectDrawSurface4 *iface, IDirectDrawSurface4 *dst, DWORD flags)
371 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
372 struct ddrawex_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface4(dst);
374 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
376 return IDirectDrawSurface4_Flip(surface->parent, dst_impl ? dst_impl->parent : NULL, flags);
379 static HRESULT WINAPI ddrawex_surface3_Flip(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *dst, DWORD flags)
381 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
382 struct ddrawex_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst);
384 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
386 return ddrawex_surface4_Flip(&surface->IDirectDrawSurface4_iface,
387 dst_impl ? &dst_impl->IDirectDrawSurface4_iface : NULL, flags);
390 static HRESULT WINAPI ddrawex_surface4_GetAttachedSurface(IDirectDrawSurface4 *iface,
391 DDSCAPS2 *caps, IDirectDrawSurface4 **attachment)
393 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
394 IDirectDrawSurface4 *inner = NULL;
395 HRESULT hr;
397 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
399 if (SUCCEEDED(hr = IDirectDrawSurface4_GetAttachedSurface(surface->parent, caps, &inner)))
401 *attachment = dds_get_outer(inner);
402 IDirectDrawSurface4_AddRef(*attachment);
403 IDirectDrawSurface4_Release(inner);
405 else
407 *attachment = NULL;
409 return hr;
412 static HRESULT WINAPI ddrawex_surface3_GetAttachedSurface(IDirectDrawSurface3 *iface,
413 DDSCAPS *caps, IDirectDrawSurface3 **attachment)
415 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
416 IDirectDrawSurface4 *surf4;
417 DDSCAPS2 caps2;
418 HRESULT hr;
420 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
422 memset(&caps2, 0, sizeof(caps2));
423 caps2.dwCaps = caps->dwCaps;
424 if (SUCCEEDED(hr = ddrawex_surface4_GetAttachedSurface(&surface->IDirectDrawSurface4_iface, &caps2, &surf4)))
426 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface3, (void **)attachment);
427 IDirectDrawSurface4_Release(surf4);
429 else
431 *attachment = NULL;
433 return hr;
436 static HRESULT WINAPI ddrawex_surface4_GetBltStatus(IDirectDrawSurface4 *iface, DWORD flags)
438 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
440 TRACE("iface %p, flags %#x.\n", iface, flags);
442 return IDirectDrawSurface4_GetBltStatus(surface->parent, flags);
445 static HRESULT WINAPI ddrawex_surface3_GetBltStatus(IDirectDrawSurface3 *iface, DWORD flags)
447 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
449 TRACE("iface %p, flags %#x.\n", iface, flags);
451 return ddrawex_surface4_GetBltStatus(&surface->IDirectDrawSurface4_iface, flags);
454 static HRESULT WINAPI ddrawex_surface4_GetCaps(IDirectDrawSurface4 *iface, DDSCAPS2 *caps)
456 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
458 TRACE("iface %p, caps %p.\n", iface, caps);
460 return IDirectDrawSurface4_GetCaps(surface->parent, caps);
463 static HRESULT WINAPI ddrawex_surface3_GetCaps(IDirectDrawSurface3 *iface, DDSCAPS *caps)
465 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
466 DDSCAPS2 caps2;
467 HRESULT hr;
469 TRACE("iface %p, caps %p.\n", iface, caps);
471 memset(&caps2, 0, sizeof(caps2));
472 memset(caps, 0, sizeof(*caps));
473 hr = IDirectDrawSurface4_GetCaps(&surface->IDirectDrawSurface4_iface, &caps2);
474 caps->dwCaps = caps2.dwCaps;
475 return hr;
478 static HRESULT WINAPI ddrawex_surface4_GetClipper(IDirectDrawSurface4 *iface, IDirectDrawClipper **clipper)
480 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
482 TRACE("iface %p, clipper %p.\n", iface, clipper);
484 return IDirectDrawSurface4_GetClipper(surface->parent, clipper);
487 static HRESULT WINAPI ddrawex_surface3_GetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper **clipper)
489 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
491 TRACE("iface %p, clipper %p.\n", iface, clipper);
493 return ddrawex_surface4_GetClipper(&surface->IDirectDrawSurface4_iface, clipper);
496 static HRESULT WINAPI ddrawex_surface4_GetColorKey(IDirectDrawSurface4 *iface, DWORD flags, DDCOLORKEY *color_key)
498 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
500 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
502 return IDirectDrawSurface4_GetColorKey(surface->parent, flags, color_key);
505 static HRESULT WINAPI ddrawex_surface3_GetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key)
507 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
509 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
511 return ddrawex_surface4_GetColorKey(&surface->IDirectDrawSurface4_iface, flags, color_key);
514 static HRESULT WINAPI ddrawex_surface4_GetDC(IDirectDrawSurface4 *iface, HDC *dc)
516 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
518 TRACE("iface %p, dc %p.\n", iface, dc);
520 if (surface->permanent_dc)
522 TRACE("Returning stored dc %p.\n", surface->hdc);
523 *dc = surface->hdc;
524 return DD_OK;
527 return IDirectDrawSurface4_GetDC(surface->parent, dc);
530 static HRESULT WINAPI ddrawex_surface3_GetDC(IDirectDrawSurface3 *iface, HDC *dc)
532 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
534 TRACE("iface %p, dc %p.\n", iface, dc);
536 return ddrawex_surface4_GetDC(&surface->IDirectDrawSurface4_iface, dc);
539 static HRESULT WINAPI ddrawex_surface4_GetFlipStatus(IDirectDrawSurface4 *iface, DWORD flags)
541 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
543 TRACE("iface %p, flags %#x.\n", iface, flags);
545 return IDirectDrawSurface4_GetFlipStatus(surface->parent, flags);
548 static HRESULT WINAPI ddrawex_surface3_GetFlipStatus(IDirectDrawSurface3 *iface, DWORD flags)
550 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
552 TRACE("iface %p, flags %#x.\n", iface, flags);
554 return ddrawex_surface4_GetFlipStatus(&surface->IDirectDrawSurface4_iface, flags);
557 static HRESULT WINAPI ddrawex_surface4_GetOverlayPosition(IDirectDrawSurface4 *iface, LONG *x, LONG *y)
559 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
561 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
563 return IDirectDrawSurface4_GetOverlayPosition(surface->parent, x, y);
566 static HRESULT WINAPI ddrawex_surface3_GetOverlayPosition(IDirectDrawSurface3 *iface, LONG *x, LONG *y)
568 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
570 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
572 return ddrawex_surface4_GetOverlayPosition(&surface->IDirectDrawSurface4_iface, x, y);
575 static HRESULT WINAPI ddrawex_surface4_GetPalette(IDirectDrawSurface4 *iface, IDirectDrawPalette **palette)
577 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
579 TRACE("iface %p, palette %p.\n", iface, palette);
581 return IDirectDrawSurface4_GetPalette(surface->parent, palette);
584 static HRESULT WINAPI ddrawex_surface3_GetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette **palette)
586 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
588 TRACE("iface %p, palette %p.\n", iface, palette);
590 return ddrawex_surface4_GetPalette(&surface->IDirectDrawSurface4_iface, palette);
593 static HRESULT WINAPI ddrawex_surface4_GetPixelFormat(IDirectDrawSurface4 *iface, DDPIXELFORMAT *pixel_format)
595 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
597 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
599 return IDirectDrawSurface4_GetPixelFormat(surface->parent, pixel_format);
602 static HRESULT WINAPI ddrawex_surface3_GetPixelFormat(IDirectDrawSurface3 *iface, DDPIXELFORMAT *pixel_format)
604 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
606 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
608 return ddrawex_surface4_GetPixelFormat(&surface->IDirectDrawSurface4_iface, pixel_format);
611 static HRESULT WINAPI ddrawex_surface4_GetSurfaceDesc(IDirectDrawSurface4 *iface, DDSURFACEDESC2 *desc)
613 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
614 HRESULT hr;
616 TRACE("iface %p, desc %p.\n", iface, desc);
618 if (SUCCEEDED(hr = IDirectDrawSurface4_GetSurfaceDesc(surface->parent, desc))
619 && surface->permanent_dc)
621 desc->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
622 desc->ddsCaps.dwCaps &= ~DDSCAPS_OWNDC;
625 return hr;
628 static HRESULT WINAPI ddrawex_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface, DDSURFACEDESC *desc)
630 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
631 DDSURFACEDESC2 ddsd2;
632 HRESULT hr;
634 TRACE("iface %p, desc %p.\n", iface, desc);
636 memset(&ddsd2, 0, sizeof(ddsd2));
637 ddsd2.dwSize = sizeof(ddsd2);
638 hr = ddrawex_surface4_GetSurfaceDesc(&surface->IDirectDrawSurface4_iface, &ddsd2);
639 DDSD2_to_DDSD(&ddsd2, desc);
641 return hr;
644 static HRESULT WINAPI ddrawex_surface4_Initialize(IDirectDrawSurface4 *iface,
645 IDirectDraw *ddraw, DDSURFACEDESC2 *desc)
647 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
648 IDirectDraw4 *outer_DD4;
649 IDirectDraw4 *inner_DD4;
650 IDirectDraw *inner_DD;
651 HRESULT hr;
653 TRACE("iface %p, ddraw %p, desc %p.\n", iface, ddraw, desc);
655 IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw4, (void **)&outer_DD4);
656 inner_DD4 = dd_get_inner(outer_DD4);
657 IDirectDraw4_Release(outer_DD4);
658 IDirectDraw4_QueryInterface(inner_DD4, &IID_IDirectDraw4, (void **)&inner_DD);
659 hr = IDirectDrawSurface4_Initialize(surface->parent, inner_DD, desc);
660 IDirectDraw_Release(inner_DD);
661 return hr;
664 static HRESULT WINAPI ddrawex_surface3_Initialize(IDirectDrawSurface3 *iface,
665 IDirectDraw *ddraw, DDSURFACEDESC *desc)
667 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
668 DDSURFACEDESC2 ddsd2;
670 TRACE("iface %p, ddraw %p, desc %p.\n", iface, ddraw, desc);
672 DDSD_to_DDSD2(desc, &ddsd2);
673 return ddrawex_surface4_Initialize(&surface->IDirectDrawSurface4_iface, ddraw, &ddsd2);
676 static HRESULT WINAPI ddrawex_surface4_IsLost(IDirectDrawSurface4 *iface)
678 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
680 TRACE("iface %p.\n", iface);
682 return IDirectDrawSurface4_IsLost(surface->parent);
685 static HRESULT WINAPI ddrawex_surface3_IsLost(IDirectDrawSurface3 *iface)
687 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
689 TRACE("iface %p.\n", iface);
691 return ddrawex_surface4_IsLost(&surface->IDirectDrawSurface4_iface);
694 static HRESULT WINAPI ddrawex_surface4_Lock(IDirectDrawSurface4 *iface, RECT *rect,
695 DDSURFACEDESC2 *desc, DWORD flags, HANDLE h)
697 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
698 HRESULT hr;
700 TRACE("iface %p, rect %s, desc %p, flags %#x, h %p.\n",
701 iface, wine_dbgstr_rect(rect), desc, flags, h);
703 if (SUCCEEDED(hr = IDirectDrawSurface4_Lock(surface->parent, rect, desc, flags, h))
704 && surface->permanent_dc)
706 desc->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
707 desc->ddsCaps.dwCaps &= ~DDSCAPS_OWNDC;
710 return hr;
713 static HRESULT WINAPI ddrawex_surface3_Lock(IDirectDrawSurface3 *iface, RECT *rect,
714 DDSURFACEDESC *desc, DWORD flags, HANDLE h)
716 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
717 DDSURFACEDESC2 ddsd2;
718 HRESULT hr;
720 TRACE("iface %p, rect %s, desc %p, flags %#x, h %p.\n",
721 iface, wine_dbgstr_rect(rect), desc, flags, h);
723 memset(&ddsd2, 0, sizeof(ddsd2));
724 ddsd2.dwSize = sizeof(ddsd2);
725 hr = ddrawex_surface4_Lock(&surface->IDirectDrawSurface4_iface, rect, &ddsd2, flags, h);
726 DDSD2_to_DDSD(&ddsd2, desc);
728 return hr;
731 static HRESULT WINAPI ddrawex_surface4_ReleaseDC(IDirectDrawSurface4 *iface, HDC dc)
733 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
735 TRACE("iface %p, dc %p.\n", iface, dc);
737 if (surface->permanent_dc)
739 TRACE("Surface has a permanent DC, not doing anything.\n");
740 return DD_OK;
743 return IDirectDrawSurface4_ReleaseDC(surface->parent, dc);
746 static HRESULT WINAPI ddrawex_surface3_ReleaseDC(IDirectDrawSurface3 *iface, HDC dc)
748 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
750 TRACE("iface %p, dc %p.\n", iface, dc);
752 return ddrawex_surface4_ReleaseDC(&surface->IDirectDrawSurface4_iface, dc);
755 static HRESULT WINAPI ddrawex_surface4_Restore(IDirectDrawSurface4 *iface)
757 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
759 TRACE("iface %p.\n", iface);
761 return IDirectDrawSurface4_Restore(surface->parent);
764 static HRESULT WINAPI ddrawex_surface3_Restore(IDirectDrawSurface3 *iface)
766 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
768 TRACE("iface %p.\n", iface);
770 return ddrawex_surface4_Restore(&surface->IDirectDrawSurface4_iface);
773 static HRESULT WINAPI ddrawex_surface4_SetClipper(IDirectDrawSurface4 *iface, IDirectDrawClipper *clipper)
775 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
777 TRACE("iface %p, clipper %p.\n", iface, clipper);
779 return IDirectDrawSurface4_SetClipper(surface->parent, clipper);
782 static HRESULT WINAPI ddrawex_surface3_SetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper *clipper)
784 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
786 TRACE("iface %p, clipper %p.\n", iface, clipper);
788 return ddrawex_surface4_SetClipper(&surface->IDirectDrawSurface4_iface, clipper);
791 static HRESULT WINAPI ddrawex_surface4_SetColorKey(IDirectDrawSurface4 *iface,
792 DWORD flags, DDCOLORKEY *color_key)
794 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
796 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
798 return IDirectDrawSurface4_SetColorKey(surface->parent, flags, color_key);
801 static HRESULT WINAPI ddrawex_surface3_SetColorKey(IDirectDrawSurface3 *iface,
802 DWORD flags, DDCOLORKEY *color_key)
804 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
806 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
808 return ddrawex_surface4_SetColorKey(&surface->IDirectDrawSurface4_iface, flags, color_key);
811 static HRESULT WINAPI ddrawex_surface4_SetOverlayPosition(IDirectDrawSurface4 *iface, LONG x, LONG y)
813 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
815 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
817 return IDirectDrawSurface4_SetOverlayPosition(surface->parent, x, y);
820 static HRESULT WINAPI ddrawex_surface3_SetOverlayPosition(IDirectDrawSurface3 *iface, LONG x, LONG y)
822 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
824 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
826 return ddrawex_surface4_SetOverlayPosition(&surface->IDirectDrawSurface4_iface, x, y);
829 static HRESULT WINAPI ddrawex_surface4_SetPalette(IDirectDrawSurface4 *iface, IDirectDrawPalette *palette)
831 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
833 TRACE("iface %p, palette %p.\n", iface, palette);
835 return IDirectDrawSurface4_SetPalette(surface->parent, palette);
838 static HRESULT WINAPI ddrawex_surface3_SetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette *palette)
840 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
842 TRACE("iface %p, palette %p.\n", iface, palette);
844 return ddrawex_surface4_SetPalette(&surface->IDirectDrawSurface4_iface, palette);
847 static HRESULT WINAPI ddrawex_surface4_Unlock(IDirectDrawSurface4 *iface, RECT *rect)
849 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
851 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
853 return IDirectDrawSurface4_Unlock(surface->parent, rect);
856 static HRESULT WINAPI ddrawex_surface3_Unlock(IDirectDrawSurface3 *iface, void *data)
858 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
860 TRACE("iface %p, data %p.\n", iface, data);
862 return ddrawex_surface4_Unlock(&surface->IDirectDrawSurface4_iface, NULL);
865 static HRESULT WINAPI ddrawex_surface4_UpdateOverlay(IDirectDrawSurface4 *iface, RECT *src_rect,
866 IDirectDrawSurface4 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
868 struct ddrawex_surface *src_impl = impl_from_IDirectDrawSurface4(iface);
869 struct ddrawex_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface4(dst_surface);
871 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
872 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
874 return IDirectDrawSurface4_UpdateOverlay(src_impl->parent, src_rect,
875 dst_impl ? dst_impl->parent : NULL, dst_rect, flags, fx);
878 static HRESULT WINAPI ddrawex_surface3_UpdateOverlay(IDirectDrawSurface3 *iface, RECT *src_rect,
879 IDirectDrawSurface3 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
881 struct ddrawex_surface *src_impl = impl_from_IDirectDrawSurface3(iface);
882 struct ddrawex_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst_surface);
884 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
885 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
887 return ddrawex_surface4_UpdateOverlay(&src_impl->IDirectDrawSurface4_iface, src_rect,
888 dst_impl ? &dst_impl->IDirectDrawSurface4_iface : NULL, dst_rect, flags, fx);
891 static HRESULT WINAPI ddrawex_surface4_UpdateOverlayDisplay(IDirectDrawSurface4 *iface, DWORD flags)
893 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
895 TRACE("iface %p, flags %#x.\n", iface, flags);
897 return IDirectDrawSurface4_UpdateOverlayDisplay(surface->parent, flags);
900 static HRESULT WINAPI ddrawex_surface3_UpdateOverlayDisplay(IDirectDrawSurface3 *iface, DWORD flags)
902 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
904 TRACE("iface %p, flags %#x.\n", iface, flags);
906 return ddrawex_surface4_UpdateOverlayDisplay(&surface->IDirectDrawSurface4_iface, flags);
909 static HRESULT WINAPI ddrawex_surface4_UpdateOverlayZOrder(IDirectDrawSurface4 *iface,
910 DWORD flags, IDirectDrawSurface4 *reference)
912 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
913 struct ddrawex_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface4(reference);
915 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
917 return IDirectDrawSurface4_UpdateOverlayZOrder(surface->parent,
918 flags, reference_impl ? reference_impl->parent : NULL);
921 static HRESULT WINAPI ddrawex_surface3_UpdateOverlayZOrder(IDirectDrawSurface3 *iface,
922 DWORD flags, IDirectDrawSurface3 *reference)
924 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
925 struct ddrawex_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface3(reference);
927 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
929 return ddrawex_surface4_UpdateOverlayZOrder(&surface->IDirectDrawSurface4_iface,
930 flags, reference_impl ? &reference_impl->IDirectDrawSurface4_iface : NULL);
933 static HRESULT WINAPI ddrawex_surface4_GetDDInterface(IDirectDrawSurface4 *iface, void **ddraw)
935 FIXME("iface %p, ddraw %p stub!\n", iface, ddraw);
937 /* This has to be implemented in ddrawex, ddraw's interface can't be used
938 * because it is pretty hard to tell which version of the ddraw interface
939 * is returned. */
940 *ddraw = NULL;
942 return E_FAIL;
945 static HRESULT WINAPI ddrawex_surface3_GetDDInterface(IDirectDrawSurface3 *iface, void **ddraw)
947 FIXME("iface %p, ddraw %p stub!\n", iface, ddraw);
949 /* A thunk it pretty pointless for the same reason that relaying to
950 * ddraw.dll works badly. */
951 *ddraw = NULL;
953 return E_FAIL;
956 static HRESULT WINAPI ddrawex_surface4_PageLock(IDirectDrawSurface4 *iface, DWORD flags)
958 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
960 TRACE("iface %p, flags %#x.\n", iface, flags);
962 return IDirectDrawSurface4_PageLock(surface->parent, flags);
965 static HRESULT WINAPI ddrawex_surface3_PageLock(IDirectDrawSurface3 *iface, DWORD flags)
967 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
969 TRACE("iface %p, flags %#x.\n", iface, flags);
971 return ddrawex_surface4_PageLock(&surface->IDirectDrawSurface4_iface, flags);
974 static HRESULT WINAPI ddrawex_surface4_PageUnlock(IDirectDrawSurface4 *iface, DWORD flags)
976 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
978 TRACE("iface %p, flags %#x.\n", iface, flags);
980 return IDirectDrawSurface4_PageUnlock(surface->parent, flags);
983 static HRESULT WINAPI ddrawex_surface3_PageUnlock(IDirectDrawSurface3 *iface, DWORD flags)
985 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
987 TRACE("iface %p, flags %#x.\n", iface, flags);
989 return ddrawex_surface4_PageUnlock(&surface->IDirectDrawSurface4_iface, flags);
992 static HRESULT WINAPI ddrawex_surface4_SetSurfaceDesc(IDirectDrawSurface4 *iface,
993 DDSURFACEDESC2 *desc, DWORD flags)
995 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
997 TRACE("iface %p, desc %p, flags %#x.\n", iface, desc, flags);
999 return IDirectDrawSurface4_SetSurfaceDesc(surface->parent, desc, flags);
1002 static HRESULT WINAPI ddrawex_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface,
1003 DDSURFACEDESC *desc, DWORD flags)
1005 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface3(iface);
1006 DDSURFACEDESC2 ddsd;
1008 TRACE("iface %p, desc %p, flags %#x.\n", iface, desc, flags);
1010 DDSD_to_DDSD2(desc, &ddsd);
1011 return ddrawex_surface4_SetSurfaceDesc(&surface->IDirectDrawSurface4_iface, &ddsd, flags);
1014 static HRESULT WINAPI ddrawex_surface4_SetPrivateData(IDirectDrawSurface4 *iface,
1015 REFGUID tag, void *data, DWORD data_size, DWORD flags)
1017 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
1019 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
1020 iface, debugstr_guid(tag), data, data_size, flags);
1022 /* To completely avoid this we'd have to clone the private data API in
1023 * ddrawex. */
1024 if (IsEqualGUID(&IID_DDrawexPriv, tag))
1025 FIXME("Application uses ddrawex's private GUID.\n");
1027 return IDirectDrawSurface4_SetPrivateData(surface->parent, tag, data, data_size, flags);
1030 static HRESULT WINAPI ddrawex_surface4_GetPrivateData(IDirectDrawSurface4 *iface,
1031 REFGUID tag, void *data, DWORD *data_size)
1033 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
1035 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
1036 iface, debugstr_guid(tag), data, data_size);
1038 /* To completely avoid this we'd have to clone the private data API in
1039 * ddrawex. */
1040 if (IsEqualGUID(&IID_DDrawexPriv, tag))
1041 FIXME("Application uses ddrawex's private GUID.\n");
1043 return IDirectDrawSurface4_GetPrivateData(surface->parent, tag, data, data_size);
1046 static HRESULT WINAPI ddrawex_surface4_FreePrivateData(IDirectDrawSurface4 *iface, REFGUID tag)
1048 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
1050 TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag));
1052 /* To completely avoid this we'd have to clone the private data API in
1053 * ddrawex. */
1054 if (IsEqualGUID(&IID_DDrawexPriv, tag))
1055 FIXME("Application uses ddrawex's private GUID.\n");
1057 return IDirectDrawSurface4_FreePrivateData(surface->parent, tag);
1060 static HRESULT WINAPI ddrawex_surface4_GetUniquenessValue(IDirectDrawSurface4 *iface, DWORD *value)
1062 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
1064 TRACE("iface %p, value %p.\n", iface, value);
1066 return IDirectDrawSurface4_GetUniquenessValue(surface->parent, value);
1069 static HRESULT WINAPI ddrawex_surface4_ChangeUniquenessValue(IDirectDrawSurface4 *iface)
1071 struct ddrawex_surface *surface = impl_from_IDirectDrawSurface4(iface);
1073 TRACE("iface %p.\n", iface);
1075 return IDirectDrawSurface4_ChangeUniquenessValue(surface->parent);
1078 static const IDirectDrawSurface3Vtbl ddrawex_surface3_vtbl =
1080 ddrawex_surface3_QueryInterface,
1081 ddrawex_surface3_AddRef,
1082 ddrawex_surface3_Release,
1083 ddrawex_surface3_AddAttachedSurface,
1084 ddrawex_surface3_AddOverlayDirtyRect,
1085 ddrawex_surface3_Blt,
1086 ddrawex_surface3_BltBatch,
1087 ddrawex_surface3_BltFast,
1088 ddrawex_surface3_DeleteAttachedSurface,
1089 ddrawex_surface3_EnumAttachedSurfaces,
1090 ddrawex_surface3_EnumOverlayZOrders,
1091 ddrawex_surface3_Flip,
1092 ddrawex_surface3_GetAttachedSurface,
1093 ddrawex_surface3_GetBltStatus,
1094 ddrawex_surface3_GetCaps,
1095 ddrawex_surface3_GetClipper,
1096 ddrawex_surface3_GetColorKey,
1097 ddrawex_surface3_GetDC,
1098 ddrawex_surface3_GetFlipStatus,
1099 ddrawex_surface3_GetOverlayPosition,
1100 ddrawex_surface3_GetPalette,
1101 ddrawex_surface3_GetPixelFormat,
1102 ddrawex_surface3_GetSurfaceDesc,
1103 ddrawex_surface3_Initialize,
1104 ddrawex_surface3_IsLost,
1105 ddrawex_surface3_Lock,
1106 ddrawex_surface3_ReleaseDC,
1107 ddrawex_surface3_Restore,
1108 ddrawex_surface3_SetClipper,
1109 ddrawex_surface3_SetColorKey,
1110 ddrawex_surface3_SetOverlayPosition,
1111 ddrawex_surface3_SetPalette,
1112 ddrawex_surface3_Unlock,
1113 ddrawex_surface3_UpdateOverlay,
1114 ddrawex_surface3_UpdateOverlayDisplay,
1115 ddrawex_surface3_UpdateOverlayZOrder,
1116 ddrawex_surface3_GetDDInterface,
1117 ddrawex_surface3_PageLock,
1118 ddrawex_surface3_PageUnlock,
1119 ddrawex_surface3_SetSurfaceDesc,
1122 static const IDirectDrawSurface4Vtbl ddrawex_surface4_vtbl =
1124 ddrawex_surface4_QueryInterface,
1125 ddrawex_surface4_AddRef,
1126 ddrawex_surface4_Release,
1127 ddrawex_surface4_AddAttachedSurface,
1128 ddrawex_surface4_AddOverlayDirtyRect,
1129 ddrawex_surface4_Blt,
1130 ddrawex_surface4_BltBatch,
1131 ddrawex_surface4_BltFast,
1132 ddrawex_surface4_DeleteAttachedSurface,
1133 ddrawex_surface4_EnumAttachedSurfaces,
1134 ddrawex_surface4_EnumOverlayZOrders,
1135 ddrawex_surface4_Flip,
1136 ddrawex_surface4_GetAttachedSurface,
1137 ddrawex_surface4_GetBltStatus,
1138 ddrawex_surface4_GetCaps,
1139 ddrawex_surface4_GetClipper,
1140 ddrawex_surface4_GetColorKey,
1141 ddrawex_surface4_GetDC,
1142 ddrawex_surface4_GetFlipStatus,
1143 ddrawex_surface4_GetOverlayPosition,
1144 ddrawex_surface4_GetPalette,
1145 ddrawex_surface4_GetPixelFormat,
1146 ddrawex_surface4_GetSurfaceDesc,
1147 ddrawex_surface4_Initialize,
1148 ddrawex_surface4_IsLost,
1149 ddrawex_surface4_Lock,
1150 ddrawex_surface4_ReleaseDC,
1151 ddrawex_surface4_Restore,
1152 ddrawex_surface4_SetClipper,
1153 ddrawex_surface4_SetColorKey,
1154 ddrawex_surface4_SetOverlayPosition,
1155 ddrawex_surface4_SetPalette,
1156 ddrawex_surface4_Unlock,
1157 ddrawex_surface4_UpdateOverlay,
1158 ddrawex_surface4_UpdateOverlayDisplay,
1159 ddrawex_surface4_UpdateOverlayZOrder,
1160 ddrawex_surface4_GetDDInterface,
1161 ddrawex_surface4_PageLock,
1162 ddrawex_surface4_PageUnlock,
1163 ddrawex_surface4_SetSurfaceDesc,
1164 ddrawex_surface4_SetPrivateData,
1165 ddrawex_surface4_GetPrivateData,
1166 ddrawex_surface4_FreePrivateData,
1167 ddrawex_surface4_GetUniquenessValue,
1168 ddrawex_surface4_ChangeUniquenessValue,
1171 static struct ddrawex_surface *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface)
1173 if (!iface || iface->lpVtbl != &ddrawex_surface3_vtbl)
1174 return NULL;
1175 return impl_from_IDirectDrawSurface3(iface);
1178 struct ddrawex_surface *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface)
1180 if (!iface || iface->lpVtbl != &ddrawex_surface4_vtbl)
1181 return NULL;
1182 return impl_from_IDirectDrawSurface4(iface);
1185 /* dds_get_outer
1187 * Given a surface from ddraw.dll it retrieves the pointer to the ddrawex.dll wrapper around it
1189 * Parameters:
1190 * inner: ddraw.dll surface to retrieve the outer surface from
1192 * Returns:
1193 * The surface wrapper. If there is none yet, a new one is created
1195 IDirectDrawSurface4 *dds_get_outer(IDirectDrawSurface4 *inner)
1197 IDirectDrawSurface4 *outer = NULL;
1198 DWORD size = sizeof(outer);
1199 HRESULT hr;
1200 if(!inner) return NULL;
1202 hr = IDirectDrawSurface4_GetPrivateData(inner,
1203 &IID_DDrawexPriv,
1204 &outer,
1205 &size);
1206 if(FAILED(hr) || outer == NULL)
1208 struct ddrawex_surface *impl;
1210 TRACE("Creating new ddrawex surface wrapper for surface %p\n", inner);
1211 impl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*impl));
1212 impl->ref = 1;
1213 impl->IDirectDrawSurface3_iface.lpVtbl = &ddrawex_surface3_vtbl;
1214 impl->IDirectDrawSurface4_iface.lpVtbl = &ddrawex_surface4_vtbl;
1215 IDirectDrawSurface4_AddRef(inner);
1216 impl->parent = inner;
1218 outer = &impl->IDirectDrawSurface4_iface;
1220 hr = IDirectDrawSurface4_SetPrivateData(inner,
1221 &IID_DDrawexPriv,
1222 &outer,
1223 sizeof(outer),
1224 0 /* Flags */);
1225 if(FAILED(hr))
1227 ERR("IDirectDrawSurface4_SetPrivateData failed\n");
1231 return outer;
1234 HRESULT prepare_permanent_dc(IDirectDrawSurface4 *iface)
1236 struct ddrawex_surface *surface = unsafe_impl_from_IDirectDrawSurface4(iface);
1237 HRESULT hr;
1239 surface->permanent_dc = TRUE;
1240 if (FAILED(hr = IDirectDrawSurface4_GetDC(surface->parent, &surface->hdc)))
1241 return hr;
1242 return IDirectDrawSurface4_ReleaseDC(surface->parent, surface->hdc);