mshtml: Use heap_alloc_zero for allocating node objects.
[wine/wine-jacek.git] / dlls / ddraw / surface.c
blob3467a640ea25833bc54aad08676159b278bafffd
1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
8 * This file contains the (internal) driver registration functions,
9 * driver enumeration APIs and DirectDraw creation functions.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <stdlib.h>
34 #define COBJMACROS
35 #define NONAMELESSUNION
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "wingdi.h"
41 #include "wine/exception.h"
43 #include "ddraw.h"
44 #include "d3d.h"
46 #include "ddraw_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
51 /*****************************************************************************
52 * IUnknown parts follow
53 *****************************************************************************/
55 /*****************************************************************************
56 * IDirectDrawSurface7::QueryInterface
58 * A normal QueryInterface implementation. For QueryInterface rules
59 * see ddraw.c, IDirectDraw7::QueryInterface. This method
60 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
61 * in all versions, the IDirectDrawGammaControl interface and it can
62 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
64 * Params:
65 * riid: The interface id queried for
66 * obj: Address to write the pointer to
68 * Returns:
69 * S_OK on success
70 * E_NOINTERFACE if the requested interface wasn't found
72 *****************************************************************************/
73 static HRESULT WINAPI
74 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
75 REFIID riid,
76 void **obj)
78 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
80 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
81 *obj = NULL;
83 if(!riid)
84 return DDERR_INVALIDPARAMS;
86 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
87 if (IsEqualGUID(riid, &IID_IUnknown)
88 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
89 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
91 IUnknown_AddRef(iface);
92 *obj = ICOM_INTERFACE(This, IDirectDrawSurface7);
93 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
94 return S_OK;
96 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
97 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
98 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
100 IUnknown_AddRef(iface);
101 *obj = ICOM_INTERFACE(This, IDirectDrawSurface3);
102 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
103 return S_OK;
105 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
107 IUnknown_AddRef(iface);
108 *obj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
109 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
110 return S_OK;
112 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
113 IsEqualGUID(riid, &IID_IDirect3DHALDevice)||
114 IsEqualGUID(riid, &IID_IDirect3DRGBDevice) )
116 IDirect3DDevice7 *d3d;
118 /* Call into IDirect3D7 for creation */
119 IDirect3D7_CreateDevice(ICOM_INTERFACE(This->ddraw, IDirect3D7),
120 riid,
121 ICOM_INTERFACE(This, IDirectDrawSurface7),
122 &d3d);
124 *obj = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice, d3d);
125 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
127 return S_OK;
129 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
130 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
132 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
134 *obj = ICOM_INTERFACE(This, IDirect3DTexture);
135 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
137 else
139 *obj = ICOM_INTERFACE(This, IDirect3DTexture2);
140 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
142 IUnknown_AddRef( (IUnknown *) *obj);
143 return S_OK;
146 ERR("No interface\n");
147 return E_NOINTERFACE;
150 /*****************************************************************************
151 * IDirectDrawSurface7::AddRef
153 * A normal addref implementation
155 * Returns:
156 * The new refcount
158 *****************************************************************************/
159 static ULONG WINAPI
160 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
162 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
163 ULONG refCount = InterlockedIncrement(&This->ref);
165 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
166 return refCount;
169 /*****************************************************************************
170 * IDirectDrawSurfaceImpl_Destroy
172 * A helper function for IDirectDrawSurface7::Release
174 * Frees the surface, regardless of its refcount.
175 * See IDirectDrawSurface7::Release for more information
177 * Params:
178 * This: Surface to free
180 *****************************************************************************/
181 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
183 TRACE("(%p)\n", This);
185 /* Check the refcount and give a warning */
186 if(This->ref > 1)
188 /* This can happen when a complex surface is destroyed,
189 * because the 2nd surface was addref()ed when the app
190 * called GetAttachedSurface
192 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
195 /* Check for attached surfaces and detach them */
196 if(This->first_attached != This)
198 /* Well, this shouldn't happen: The surface being attached is addref()ed
199 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
200 * is called, because the refcount is held. It looks like the app released()
201 * it often enough to force this
203 IDirectDrawSurface7 *root = ICOM_INTERFACE(This->first_attached, IDirectDrawSurface7);
204 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This, IDirectDrawSurface7);
206 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
208 /* The refcount will drop to -1 here */
209 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
211 ERR("(%p) DeleteAttachedSurface failed!\n", This);
215 while(This->next_attached != NULL)
217 IDirectDrawSurface7 *root = ICOM_INTERFACE(This, IDirectDrawSurface7);
218 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This->next_attached, IDirectDrawSurface7);
220 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
222 ERR("(%p) DeleteAttachedSurface failed!\n", This);
223 assert(0);
227 /* Now destroy the surface. Wait: It could have been released if we are a texture */
228 if(This->WineD3DSurface)
229 IWineD3DSurface_Release(This->WineD3DSurface);
231 /* Having a texture handle set implies that the device still exists */
232 if(This->Handle)
234 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
235 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
238 /* Reduce the ddraw surface count */
239 InterlockedDecrement(&This->ddraw->surfaces);
240 list_remove(&This->surface_list_entry);
242 HeapFree(GetProcessHeap(), 0, This);
245 /*****************************************************************************
246 * IDirectDrawSurface7::Release
248 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
249 * surface is destroyed.
251 * Destroying the surface is a bit tricky. For the connection between
252 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
253 * It has a nice graph explaining the connection.
255 * What happens here is basically this:
256 * When a surface is destroyed, its WineD3DSurface is released,
257 * and the refcount of the DirectDraw interface is reduced by 1. If it has
258 * complex surfaces attached to it, then these surfaces are destroyed too,
259 * regardless of their refcount. If any surface being destroyed has another
260 * surface attached to it (with a "soft" attachment, not complex), then
261 * this surface is detached with DeleteAttachedSurface.
263 * When the surface is a texture, the WineD3DTexture is released.
264 * If the surface is the Direct3D render target, then the D3D
265 * capabilities of the WineD3DDevice are uninitialized, which causes the
266 * swapchain to be released.
268 * When a complex sublevel falls to ref zero, then this is ignored.
270 * Returns:
271 * The new refcount
273 *****************************************************************************/
274 static ULONG WINAPI
275 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
277 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
278 ULONG ref;
279 TRACE("(%p) : Releasing from %d\n", This, This->ref);
280 ref = InterlockedDecrement(&This->ref);
282 if (ref == 0)
285 IDirectDrawSurfaceImpl *surf;
286 IDirectDrawImpl *ddraw;
287 IUnknown *ifaceToRelease = This->ifaceToRelease;
288 int i;
290 /* Complex attached surfaces are destroyed implicitly when the root is released */
291 EnterCriticalSection(&ddraw_cs);
292 if(!This->is_complex_root)
294 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
295 LeaveCriticalSection(&ddraw_cs);
296 return ref;
298 ddraw = This->ddraw;
300 /* If it's a texture, destroy the WineD3DTexture.
301 * WineD3D will destroy the IParent interfaces
302 * of the sublevels, which destroys the WineD3DSurfaces.
303 * Set the surfaces to NULL to avoid destroying them again later
305 if(This->wineD3DTexture)
307 IWineD3DBaseTexture_Release(This->wineD3DTexture);
309 /* If it's the RenderTarget, destroy the d3ddevice */
310 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
312 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
314 /* Unset any index buffer, just to be sure */
315 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL);
316 IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
317 IWineD3DDevice_SetVertexDeclaration(ddraw->wineD3DDevice, NULL);
318 for(i = 0; i < ddraw->numConvertedDecls; i++)
320 IWineD3DVertexDeclaration_Release(ddraw->decls[i].decl);
322 HeapFree(GetProcessHeap(), 0, ddraw->decls);
323 ddraw->numConvertedDecls = 0;
325 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice, D3D7CB_DestroyDepthStencilSurface, D3D7CB_DestroySwapChain) != D3D_OK)
327 /* Not good */
328 ERR("(%p) Failed to uninit 3D\n", This);
330 else
332 /* Free the d3d window if one was created */
333 if(ddraw->d3d_window != 0)
335 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
336 DestroyWindow(ddraw->d3d_window);
337 ddraw->d3d_window = 0;
339 /* Unset the pointers */
342 ddraw->d3d_initialized = FALSE;
343 ddraw->d3d_target = NULL;
345 /* Reset to the default surface implementation type. This is needed if apps use
346 * non render target surfaces and expect blits to work after destroying the render
347 * target.
349 * TODO: Recreate existing offscreen surfaces
351 ddraw->ImplType = DefaultSurfaceType;
353 /* Write a trace because D3D unloading was the reason for many
354 * crashes during development.
356 TRACE("(%p) D3D unloaded\n", This);
358 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
359 DDSCAPS_3DDEVICE |
360 DDSCAPS_TEXTURE ) )
362 /* It's a render target, but no swapchain was created.
363 * The IParent interfaces have to be released manually.
364 * The same applies for textures without an
365 * IWineD3DTexture object attached
367 IParent *Parent;
369 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
371 if(This->complex_array[i])
373 /* Only the topmost level can have more than 1 surfaces in the complex
374 * attachment array(Cube texture roots), for all others there is only
375 * one
377 surf = This->complex_array[i];
378 while(surf)
380 IWineD3DSurface_GetParent(surf->WineD3DSurface,
381 (IUnknown **) &Parent);
382 IParent_Release(Parent); /* For the getParent */
383 IParent_Release(Parent); /* To release it */
384 surf = surf->complex_array[0];
389 /* Now the top-level surface */
390 IWineD3DSurface_GetParent(This->WineD3DSurface,
391 (IUnknown **) &Parent);
392 IParent_Release(Parent); /* For the getParent */
393 IParent_Release(Parent); /* To release it */
396 /* The refcount test shows that the palette is detached when the surface is destroyed */
397 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
398 NULL);
400 /* Loop through all complex attached surfaces,
401 * and destroy them.
403 * Yet again, only the root can have more than one complexly attached surface, all the others
404 * have a total of one;
406 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
408 if(!This->complex_array[i]) break;
410 surf = This->complex_array[i];
411 This->complex_array[i] = NULL;
412 while(surf)
414 IDirectDrawSurfaceImpl *destroy = surf;
415 surf = surf->complex_array[0]; /* Iterate through the "tree" */
416 IDirectDrawSurfaceImpl_Destroy(destroy); /* Destroy it */
420 /* Destroy the root surface.
422 IDirectDrawSurfaceImpl_Destroy(This);
424 /* Reduce the ddraw refcount */
425 if(ifaceToRelease) IUnknown_Release(ifaceToRelease);
426 LeaveCriticalSection(&ddraw_cs);
429 return ref;
432 /*****************************************************************************
433 * IDirectDrawSurface7::GetAttachedSurface
435 * Returns an attached surface with the requested caps. Surface attachment
436 * and complex surfaces are not clearly described by the MSDN or sdk,
437 * so this method is tricky and likely to contain problems.
438 * This implementation searches the complex list first, then the
439 * attachment chain.
441 * The chains are searched from This down to the last surface in the chain,
442 * not from the first element in the chain. The first surface found is
443 * returned. The MSDN says that this method fails if more than one surface
444 * matches the caps, but it is not sure if that is right. The attachment
445 * structure may not even allow two matching surfaces.
447 * The found surface is AddRef-ed before it is returned.
449 * Params:
450 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
451 * Surface: Address to store the found surface
453 * Returns:
454 * DD_OK on success
455 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
456 * DDERR_NOTFOUND if no surface was found
458 *****************************************************************************/
459 static HRESULT WINAPI
460 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
461 DDSCAPS2 *Caps,
462 IDirectDrawSurface7 **Surface)
464 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
465 IDirectDrawSurfaceImpl *surf;
466 DDSCAPS2 our_caps;
467 int i;
469 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
470 EnterCriticalSection(&ddraw_cs);
472 our_caps = *Caps;
474 if(This->version < 7)
476 /* Earlier dx apps put garbage into these members, clear them */
477 our_caps.dwCaps2 = 0;
478 our_caps.dwCaps3 = 0;
479 our_caps.dwCaps4 = 0;
482 TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.dwCaps4); /* FIXME: Better debugging */
484 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
486 surf = This->complex_array[i];
487 if(!surf) break;
489 if (TRACE_ON(ddraw))
491 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
492 surf->surface_desc.ddsCaps.dwCaps,
493 surf->surface_desc.ddsCaps.dwCaps2,
494 surf->surface_desc.ddsCaps.dwCaps3,
495 surf->surface_desc.ddsCaps.dwCaps4);
498 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
499 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
501 /* MSDN: "This method fails if more than one surface is attached
502 * that matches the capabilities requested."
504 * Not sure how to test this.
507 TRACE("(%p): Returning surface %p\n", This, surf);
508 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
509 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
510 IDirectDrawSurface7_AddRef(*Surface);
511 LeaveCriticalSection(&ddraw_cs);
512 return DD_OK;
516 /* Next, look at the attachment chain */
517 surf = This;
519 while( (surf = surf->next_attached) )
521 if (TRACE_ON(ddraw))
523 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
524 surf->surface_desc.ddsCaps.dwCaps,
525 surf->surface_desc.ddsCaps.dwCaps2,
526 surf->surface_desc.ddsCaps.dwCaps3,
527 surf->surface_desc.ddsCaps.dwCaps4);
530 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
531 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
533 TRACE("(%p): Returning surface %p\n", This, surf);
534 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
535 IDirectDrawSurface7_AddRef(*Surface);
536 LeaveCriticalSection(&ddraw_cs);
537 return DD_OK;
541 TRACE("(%p) Didn't find a valid surface\n", This);
542 LeaveCriticalSection(&ddraw_cs);
544 *Surface = NULL;
545 return DDERR_NOTFOUND;
548 /*****************************************************************************
549 * IDirectDrawSurface7::Lock
551 * Locks the surface and returns a pointer to the surface's memory
553 * Params:
554 * Rect: Rectangle to lock. If NULL, the whole surface is locked
555 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
556 * Flags: Locking flags, e.g Read only or write only
557 * h: An event handle that's not used and must be NULL
559 * Returns:
560 * DD_OK on success
561 * DDERR_INVALIDPARAMS if DDSD is NULL
562 * For more details, see IWineD3DSurface::LockRect
564 *****************************************************************************/
565 static HRESULT WINAPI
566 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
567 RECT *Rect,
568 DDSURFACEDESC2 *DDSD,
569 DWORD Flags,
570 HANDLE h)
572 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
573 WINED3DLOCKED_RECT LockedRect;
574 HRESULT hr;
575 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
577 if(!DDSD)
578 return DDERR_INVALIDPARAMS;
580 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
581 EnterCriticalSection(&ddraw_cs);
583 /* Should I check for the handle to be NULL?
585 * The DDLOCK flags and the D3DLOCK flags are equal
586 * for the supported values. The others are ignored by WineD3D
589 if(DDSD->dwSize != sizeof(DDSURFACEDESC) &&
590 DDSD->dwSize != sizeof(DDSURFACEDESC2))
592 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS);
593 LeaveCriticalSection(&ddraw_cs);
594 return DDERR_INVALIDPARAMS;
597 /* Windows zeroes this if the rect is invalid */
598 DDSD->lpSurface = 0;
600 if (Rect)
602 if ((Rect->left < 0)
603 || (Rect->top < 0)
604 || (Rect->left > Rect->right)
605 || (Rect->top > Rect->bottom)
606 || (Rect->right > This->surface_desc.dwWidth)
607 || (Rect->bottom > This->surface_desc.dwHeight))
609 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
610 LeaveCriticalSection(&ddraw_cs);
611 return DDERR_INVALIDPARAMS;
615 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
616 &LockedRect,
617 Rect,
618 Flags);
619 if(hr != D3D_OK)
621 LeaveCriticalSection(&ddraw_cs);
622 switch(hr)
624 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
625 * specific error. But since IWineD3DSurface::LockRect returns that error in this
626 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
627 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
628 * is much easier to do it in one place in ddraw
630 case WINED3DERR_INVALIDCALL: return DDERR_SURFACEBUSY;
631 default: return hr;
635 /* Override the memory area. The pitch should be set already. Strangely windows
636 * does not set the LPSURFACE flag on locked surfaces !?!.
637 * DDSD->dwFlags |= DDSD_LPSURFACE;
639 This->surface_desc.lpSurface = LockedRect.pBits;
640 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
642 TRACE("locked surface returning description :\n");
643 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
645 LeaveCriticalSection(&ddraw_cs);
646 return DD_OK;
649 /*****************************************************************************
650 * IDirectDrawSurface7::Unlock
652 * Unlocks an locked surface
654 * Params:
655 * Rect: Not used by this implementation
657 * Returns:
658 * D3D_OK on success
659 * For more details, see IWineD3DSurface::UnlockRect
661 *****************************************************************************/
662 static HRESULT WINAPI
663 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
664 RECT *pRect)
666 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
667 HRESULT hr;
668 TRACE("(%p)->(%p)\n", This, pRect);
670 EnterCriticalSection(&ddraw_cs);
671 hr = IWineD3DSurface_UnlockRect(This->WineD3DSurface);
672 if(SUCCEEDED(hr))
674 This->surface_desc.lpSurface = NULL;
676 LeaveCriticalSection(&ddraw_cs);
677 return hr;
680 /*****************************************************************************
681 * IDirectDrawSurface7::Flip
683 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
684 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
685 * the flip target is passed to WineD3D, even if the app didn't specify one
687 * Params:
688 * DestOverride: Specifies the surface that will become the new front
689 * buffer. If NULL, the current back buffer is used
690 * Flags: some DirectDraw flags, see include/ddraw.h
692 * Returns:
693 * DD_OK on success
694 * DDERR_NOTFLIPPABLE if no flip target could be found
695 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
696 * For more details, see IWineD3DSurface::Flip
698 *****************************************************************************/
699 static HRESULT WINAPI
700 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
701 IDirectDrawSurface7 *DestOverride,
702 DWORD Flags)
704 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
705 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
706 IDirectDrawSurface7 *Override7;
707 HRESULT hr;
708 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
710 /* Flip has to be called from a front buffer
711 * What about overlay surfaces, AFAIK they can flip too?
713 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
714 return DDERR_INVALIDOBJECT; /* Unchecked */
716 EnterCriticalSection(&ddraw_cs);
718 /* WineD3D doesn't keep track of attached surface, so find the target */
719 if(!Override)
721 DDSCAPS2 Caps;
723 memset(&Caps, 0, sizeof(Caps));
724 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
725 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
726 if(hr != DD_OK)
728 ERR("Can't find a flip target\n");
729 LeaveCriticalSection(&ddraw_cs);
730 return DDERR_NOTFLIPPABLE; /* Unchecked */
732 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
734 /* For the GetAttachedSurface */
735 IDirectDrawSurface7_Release(Override7);
738 hr = IWineD3DSurface_Flip(This->WineD3DSurface,
739 Override->WineD3DSurface,
740 Flags);
741 LeaveCriticalSection(&ddraw_cs);
742 return hr;
745 /*****************************************************************************
746 * IDirectDrawSurface7::Blt
748 * Performs a blit on the surface
750 * Params:
751 * DestRect: Destination rectangle, can be NULL
752 * SrcSurface: Source surface, can be NULL
753 * SrcRect: Source rectangle, can be NULL
754 * Flags: Blt flags
755 * DDBltFx: Some extended blt parameters, connected to the flags
757 * Returns:
758 * D3D_OK on success
759 * See IWineD3DSurface::Blt for more details
761 *****************************************************************************/
762 static HRESULT WINAPI
763 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
764 RECT *DestRect,
765 IDirectDrawSurface7 *SrcSurface,
766 RECT *SrcRect,
767 DWORD Flags,
768 DDBLTFX *DDBltFx)
770 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
771 HRESULT hr;
772 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
773 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
775 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
776 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
778 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
779 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
780 return DDERR_INVALIDPARAMS;
783 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
784 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
785 return DDERR_INVALIDPARAMS;
788 /* Sizes can change, therefore hold the lock when testing the rectangles */
789 EnterCriticalSection(&ddraw_cs);
790 if(DestRect)
792 if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right ||
793 DestRect->right > This->surface_desc.dwWidth ||
794 DestRect->bottom > This->surface_desc.dwHeight)
796 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
797 LeaveCriticalSection(&ddraw_cs);
798 return DDERR_INVALIDRECT;
801 if(Src && SrcRect)
803 if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right ||
804 SrcRect->right > Src->surface_desc.dwWidth ||
805 SrcRect->bottom > Src->surface_desc.dwHeight)
807 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
808 LeaveCriticalSection(&ddraw_cs);
809 return DDERR_INVALIDRECT;
813 if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
814 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
815 LeaveCriticalSection(&ddraw_cs);
816 return DDERR_INVALIDPARAMS;
819 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
820 * and replace the ddraw surfaces with the wined3d surfaces
821 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
823 hr = IWineD3DSurface_Blt(This->WineD3DSurface,
824 DestRect,
825 Src ? Src->WineD3DSurface : NULL,
826 SrcRect,
827 Flags,
828 (WINEDDBLTFX *) DDBltFx,
829 WINED3DTEXF_POINT);
831 LeaveCriticalSection(&ddraw_cs);
832 switch(hr)
834 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
835 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
836 default: return hr;
840 /*****************************************************************************
841 * IDirectDrawSurface7::AddAttachedSurface
843 * Attaches a surface to another surface. How the surface attachments work
844 * is not totally understood yet, and this method is prone to problems.
845 * he surface that is attached is AddRef-ed.
847 * Tests with complex surfaces suggest that the surface attachments form a
848 * tree, but no method to test this has been found yet.
850 * The attachment list consists of a first surface (first_attached) and
851 * for each surface a pointer to the next attached surface (next_attached).
852 * For the first surface, and a surface that has no attachments
853 * first_attached points to the surface itself. A surface that has
854 * no successors in the chain has next_attached set to NULL.
856 * Newly attached surfaces are attached right after the root surface.
857 * If a surface is attached to a complex surface compound, it's attached to
858 * the surface that the app requested, not the complex root. See
859 * GetAttachedSurface for a description how surfaces are found.
861 * This is how the current implementation works, and it was coded by looking
862 * at the needs of the applications.
864 * So far only Z-Buffer attachments are tested, and they are activated in
865 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
866 * Back buffers should work in 2D mode, but they are not tested(They can be
867 * attached in older iface versions). Rendering to the front buffer and
868 * switching between that and double buffering is not yet implemented in
869 * WineD3D, so for 3D it might have unexpected results.
871 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
872 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
873 * performs additional checks. Version 7 of this interface is much more restrictive
874 * than its predecessors.
876 * Params:
877 * Attach: Surface to attach to iface
879 * Returns:
880 * DD_OK on success
881 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
883 *****************************************************************************/
884 HRESULT WINAPI
885 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This,
886 IDirectDrawSurfaceImpl *Surf)
888 TRACE("(%p)->(%p)\n", This, Surf);
890 if(Surf == This)
891 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
893 EnterCriticalSection(&ddraw_cs);
895 /* Check if the surface is already attached somewhere */
896 if( (Surf->next_attached != NULL) ||
897 (Surf->first_attached != Surf) )
899 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
900 * What happens if one surface is attached to 2 different surfaces?
902 FIXME("(%p) The Surface %p is already attached somewhere else: next_attached = %p, first_attached = %p, can't handle by now\n", This, Surf, Surf->next_attached, Surf->first_attached);
903 LeaveCriticalSection(&ddraw_cs);
904 return DDERR_SURFACEALREADYATTACHED;
907 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
908 Surf->next_attached = This->next_attached;
909 Surf->first_attached = This->first_attached;
910 This->next_attached = Surf;
912 /* Check if the WineD3D depth stencil needs updating */
913 if(This->ddraw->d3ddevice)
915 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
918 /* MSDN:
919 * "This method increments the reference count of the surface being attached."
921 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(Surf, IDirectDrawSurface7));
922 LeaveCriticalSection(&ddraw_cs);
923 return DD_OK;
926 static HRESULT WINAPI
927 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7 *iface,
928 IDirectDrawSurface7 *Attach)
930 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
931 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
933 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
934 if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
937 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
938 Surf->surface_desc.ddsCaps.dwCaps);
939 return DDERR_CANNOTATTACHSURFACE;
942 return IDirectDrawSurfaceImpl_AddAttachedSurface(This,
943 Surf);
945 /*****************************************************************************
946 * IDirectDrawSurface7::DeleteAttachedSurface
948 * Removes a surface from the attachment chain. The surface's refcount
949 * is decreased by one after it has been removed
951 * Params:
952 * Flags: Some flags, not used by this implementation
953 * Attach: Surface to detach
955 * Returns:
956 * DD_OK on success
957 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
959 *****************************************************************************/
960 static HRESULT WINAPI
961 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
962 DWORD Flags,
963 IDirectDrawSurface7 *Attach)
965 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
966 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
967 IDirectDrawSurfaceImpl *Prev = This;
968 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
970 EnterCriticalSection(&ddraw_cs);
971 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
973 LeaveCriticalSection(&ddraw_cs);
974 return DDERR_CANNOTDETACHSURFACE;
977 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
978 if (This->surface_desc.ddsCaps.dwCaps &
979 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
981 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
982 /* FIXME: we should probably also subtract from dwMipMapCount of this
983 * and all parent surfaces */
986 /* Find the predecessor of the detached surface */
987 while(Prev)
989 if(Prev->next_attached == Surf) break;
990 Prev = Prev->next_attached;
993 /* There must be a surface, otherwise there's a bug */
994 assert(Prev != NULL);
996 /* Unchain the surface */
997 Prev->next_attached = Surf->next_attached;
998 Surf->next_attached = NULL;
999 Surf->first_attached = Surf;
1001 /* Check if the WineD3D depth stencil needs updating */
1002 if(This->ddraw->d3ddevice)
1004 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
1007 IDirectDrawSurface7_Release(Attach);
1008 LeaveCriticalSection(&ddraw_cs);
1009 return DD_OK;
1012 /*****************************************************************************
1013 * IDirectDrawSurface7::AddOverlayDirtyRect
1015 * "This method is not currently implemented"
1017 * Params:
1018 * Rect: ?
1020 * Returns:
1021 * DDERR_UNSUPPORTED
1023 *****************************************************************************/
1024 static HRESULT WINAPI
1025 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
1026 LPRECT Rect)
1028 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1029 TRACE("(%p)->(%p)\n",This,Rect);
1031 /* MSDN says it's not implemented. I could forward it to WineD3D,
1032 * then we'd implement it, but I don't think that's a good idea
1033 * (Stefan Dösinger)
1035 #if 0
1036 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
1037 #endif
1038 return DDERR_UNSUPPORTED; /* unchecked */
1041 /*****************************************************************************
1042 * IDirectDrawSurface7::GetDC
1044 * Returns a GDI device context for the surface
1046 * Params:
1047 * hdc: Address of a HDC variable to store the dc to
1049 * Returns:
1050 * DD_OK on success
1051 * DDERR_INVALIDPARAMS if hdc is NULL
1052 * For details, see IWineD3DSurface::GetDC
1054 *****************************************************************************/
1055 static HRESULT WINAPI
1056 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
1057 HDC *hdc)
1059 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1060 HRESULT hr;
1061 TRACE("(%p)->(%p): Relay\n", This, hdc);
1063 if(!hdc)
1064 return DDERR_INVALIDPARAMS;
1066 EnterCriticalSection(&ddraw_cs);
1067 hr = IWineD3DSurface_GetDC(This->WineD3DSurface,
1068 hdc);
1069 LeaveCriticalSection(&ddraw_cs);
1070 return hr;
1073 /*****************************************************************************
1074 * IDirectDrawSurface7::ReleaseDC
1076 * Releases the DC that was constructed with GetDC
1078 * Params:
1079 * hdc: HDC to release
1081 * Returns:
1082 * DD_OK on success
1083 * For more details, see IWineD3DSurface::ReleaseDC
1085 *****************************************************************************/
1086 static HRESULT WINAPI
1087 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
1088 HDC hdc)
1090 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1091 HRESULT hr;
1092 TRACE("(%p)->(%p): Relay\n", This, hdc);
1094 EnterCriticalSection(&ddraw_cs);
1095 hr = IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
1096 LeaveCriticalSection(&ddraw_cs);
1097 return hr;
1100 /*****************************************************************************
1101 * IDirectDrawSurface7::GetCaps
1103 * Returns the surface's caps
1105 * Params:
1106 * Caps: Address to write the caps to
1108 * Returns:
1109 * DD_OK on success
1110 * DDERR_INVALIDPARAMS if Caps is NULL
1112 *****************************************************************************/
1113 static HRESULT WINAPI
1114 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
1115 DDSCAPS2 *Caps)
1117 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1118 TRACE("(%p)->(%p)\n",This,Caps);
1120 if(!Caps)
1121 return DDERR_INVALIDPARAMS;
1123 *Caps = This->surface_desc.ddsCaps;
1124 return DD_OK;
1127 /*****************************************************************************
1128 * IDirectDrawSurface7::SetPriority
1130 * Sets a texture priority for managed textures.
1132 * Params:
1133 * Priority: The new priority
1135 * Returns:
1136 * DD_OK on success
1137 * For more details, see IWineD3DSurface::SetPriority
1139 *****************************************************************************/
1140 static HRESULT WINAPI
1141 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
1143 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1144 HRESULT hr;
1145 TRACE("(%p)->(%d): Relay!\n",This,Priority);
1147 EnterCriticalSection(&ddraw_cs);
1148 hr = IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
1149 LeaveCriticalSection(&ddraw_cs);
1150 return hr;
1153 /*****************************************************************************
1154 * IDirectDrawSurface7::GetPriority
1156 * Returns the surface's priority
1158 * Params:
1159 * Priority: Address of a variable to write the priority to
1161 * Returns:
1162 * D3D_OK on success
1163 * DDERR_INVALIDPARAMS if Priority == NULL
1164 * For more details, see IWineD3DSurface::GetPriority
1166 *****************************************************************************/
1167 static HRESULT WINAPI
1168 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1169 DWORD *Priority)
1171 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1172 TRACE("(%p)->(%p): Relay\n",This,Priority);
1174 if(!Priority)
1176 return DDERR_INVALIDPARAMS;
1179 EnterCriticalSection(&ddraw_cs);
1180 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1181 LeaveCriticalSection(&ddraw_cs);
1182 return DD_OK;
1185 /*****************************************************************************
1186 * IDirectDrawSurface7::SetPrivateData
1188 * Stores some data in the surface that is intended for the application's
1189 * use.
1191 * Params:
1192 * tag: GUID that identifies the data
1193 * Data: Pointer to the private data
1194 * Size: Size of the private data
1195 * Flags: Some flags
1197 * Returns:
1198 * D3D_OK on success
1199 * For more details, see IWineD3DSurface::SetPrivateData
1201 *****************************************************************************/
1202 static HRESULT WINAPI
1203 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1204 REFGUID tag,
1205 void *Data,
1206 DWORD Size,
1207 DWORD Flags)
1209 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1210 HRESULT hr;
1211 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1213 EnterCriticalSection(&ddraw_cs);
1214 hr = IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1215 tag,
1216 Data,
1217 Size,
1218 Flags);
1219 LeaveCriticalSection(&ddraw_cs);
1220 switch(hr)
1222 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1223 default: return hr;
1227 /*****************************************************************************
1228 * IDirectDrawSurface7::GetPrivateData
1230 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1232 * Params:
1233 * tag: GUID of the data to return
1234 * Data: Address where to write the data to
1235 * Size: Size of the buffer at Data
1237 * Returns:
1238 * DD_OK on success
1239 * DDERR_INVALIDPARAMS if Data is NULL
1240 * For more details, see IWineD3DSurface::GetPrivateData
1242 *****************************************************************************/
1243 static HRESULT WINAPI
1244 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1245 REFGUID tag,
1246 void *Data,
1247 DWORD *Size)
1249 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1250 HRESULT hr;
1251 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1253 if(!Data)
1254 return DDERR_INVALIDPARAMS;
1256 EnterCriticalSection(&ddraw_cs);
1257 hr = IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1258 tag,
1259 Data,
1260 Size);
1261 LeaveCriticalSection(&ddraw_cs);
1262 return hr;
1265 /*****************************************************************************
1266 * IDirectDrawSurface7::FreePrivateData
1268 * Frees private data stored in the surface
1270 * Params:
1271 * tag: Tag of the data to free
1273 * Returns:
1274 * D3D_OK on success
1275 * For more details, see IWineD3DSurface::FreePrivateData
1277 *****************************************************************************/
1278 static HRESULT WINAPI
1279 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1280 REFGUID tag)
1282 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1283 HRESULT hr;
1284 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1286 EnterCriticalSection(&ddraw_cs);
1287 hr = IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1288 LeaveCriticalSection(&ddraw_cs);
1289 return hr;
1292 /*****************************************************************************
1293 * IDirectDrawSurface7::PageLock
1295 * Prevents a sysmem surface from being paged out
1297 * Params:
1298 * Flags: Not used, must be 0(unchecked)
1300 * Returns:
1301 * DD_OK, because it's a stub
1303 *****************************************************************************/
1304 static HRESULT WINAPI
1305 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1306 DWORD Flags)
1308 TRACE("(%p)->(%x)\n", iface, Flags);
1310 /* This is Windows memory management related - we don't need this */
1311 return DD_OK;
1314 /*****************************************************************************
1315 * IDirectDrawSurface7::PageUnlock
1317 * Allows a sysmem surface to be paged out
1319 * Params:
1320 * Flags: Not used, must be 0(unchecked)
1322 * Returns:
1323 * DD_OK, because it's a stub
1325 *****************************************************************************/
1326 static HRESULT WINAPI
1327 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1328 DWORD Flags)
1330 TRACE("(%p)->(%x)\n", iface, Flags);
1332 return DD_OK;
1335 /*****************************************************************************
1336 * IDirectDrawSurface7::BltBatch
1338 * An unimplemented function
1340 * Params:
1343 * Returns:
1344 * DDERR_UNSUPPORTED
1346 *****************************************************************************/
1347 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1349 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1351 /* MSDN: "not currently implemented" */
1352 return DDERR_UNSUPPORTED;
1355 /*****************************************************************************
1356 * IDirectDrawSurface7::EnumAttachedSurfaces
1358 * Enumerates all surfaces attached to this surface
1360 * Params:
1361 * context: Pointer to pass unmodified to the callback
1362 * cb: Callback function to call for each surface
1364 * Returns:
1365 * DD_OK on success
1366 * DDERR_INVALIDPARAMS if cb is NULL
1368 *****************************************************************************/
1369 static HRESULT WINAPI
1370 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1371 void *context,
1372 LPDDENUMSURFACESCALLBACK7 cb)
1374 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1375 IDirectDrawSurfaceImpl *surf;
1376 DDSURFACEDESC2 desc;
1377 int i;
1379 /* Attached surfaces aren't handled in WineD3D */
1380 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1382 if(!cb)
1383 return DDERR_INVALIDPARAMS;
1385 EnterCriticalSection(&ddraw_cs);
1386 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
1388 surf = This->complex_array[i];
1389 if(!surf) break;
1391 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1392 desc = surf->surface_desc;
1393 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1394 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1396 LeaveCriticalSection(&ddraw_cs);
1397 return DD_OK;
1401 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1403 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1404 desc = surf->surface_desc;
1405 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1406 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1408 LeaveCriticalSection(&ddraw_cs);
1409 return DD_OK;
1413 TRACE(" end of enumeration.\n");
1415 LeaveCriticalSection(&ddraw_cs);
1416 return DD_OK;
1419 /*****************************************************************************
1420 * IDirectDrawSurface7::EnumOverlayZOrders
1422 * "Enumerates the overlay surfaces on the specified destination"
1424 * Params:
1425 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1426 * context: context to pass back to the callback
1427 * cb: callback function to call for each enumerated surface
1429 * Returns:
1430 * DD_OK, because it's a stub
1432 *****************************************************************************/
1433 static HRESULT WINAPI
1434 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1435 DWORD Flags,
1436 void *context,
1437 LPDDENUMSURFACESCALLBACK7 cb)
1439 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1441 return DD_OK;
1444 /*****************************************************************************
1445 * IDirectDrawSurface7::GetBltStatus
1447 * Returns the blitting status
1449 * Params:
1450 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1452 * Returns:
1453 * See IWineD3DSurface::Blt
1455 *****************************************************************************/
1456 static HRESULT WINAPI
1457 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1458 DWORD Flags)
1460 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1461 HRESULT hr;
1462 TRACE("(%p)->(%x): Relay\n", This, Flags);
1464 EnterCriticalSection(&ddraw_cs);
1465 hr = IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1466 LeaveCriticalSection(&ddraw_cs);
1467 switch(hr)
1469 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1470 default: return hr;
1474 /*****************************************************************************
1475 * IDirectDrawSurface7::GetColorKey
1477 * Returns the color key assigned to the surface
1479 * Params:
1480 * Flags: Some flags
1481 * CKey: Address to store the key to
1483 * Returns:
1484 * DD_OK on success
1485 * DDERR_INVALIDPARAMS if CKey is NULL
1487 *****************************************************************************/
1488 static HRESULT WINAPI
1489 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1490 DWORD Flags,
1491 DDCOLORKEY *CKey)
1493 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1494 * isn't there? That's like saying that an int isn't there. (Which MS
1495 * has done in other docs.) */
1496 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1497 TRACE("(%p)->(%08x,%p)\n", This, Flags, CKey);
1499 if(!CKey)
1500 return DDERR_INVALIDPARAMS;
1502 EnterCriticalSection(&ddraw_cs);
1503 switch (Flags)
1505 case DDCKEY_DESTBLT:
1506 *CKey = This->surface_desc.ddckCKDestBlt;
1507 break;
1509 case DDCKEY_DESTOVERLAY:
1510 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1511 break;
1513 case DDCKEY_SRCBLT:
1514 *CKey = This->surface_desc.ddckCKSrcBlt;
1515 break;
1517 case DDCKEY_SRCOVERLAY:
1518 *CKey = This->surface_desc.ddckCKSrcOverlay;
1519 break;
1521 default:
1522 LeaveCriticalSection(&ddraw_cs);
1523 return DDERR_INVALIDPARAMS;
1526 LeaveCriticalSection(&ddraw_cs);
1527 return DD_OK;
1530 /*****************************************************************************
1531 * IDirectDrawSurface7::GetFlipStatus
1533 * Returns the flipping status of the surface
1535 * Params:
1536 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1538 * Returns:
1539 * See IWineD3DSurface::GetFlipStatus
1541 *****************************************************************************/
1542 static HRESULT WINAPI
1543 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1544 DWORD Flags)
1546 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1547 HRESULT hr;
1548 TRACE("(%p)->(%x): Relay\n", This, Flags);
1550 EnterCriticalSection(&ddraw_cs);
1551 hr = IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1552 LeaveCriticalSection(&ddraw_cs);
1553 switch(hr)
1555 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1556 default: return hr;
1560 /*****************************************************************************
1561 * IDirectDrawSurface7::GetOverlayPosition
1563 * Returns the display coordinates of a visible and active overlay surface
1565 * Params:
1569 * Returns:
1570 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1571 *****************************************************************************/
1572 static HRESULT WINAPI
1573 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1574 LONG *X,
1575 LONG *Y) {
1576 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1577 HRESULT hr;
1578 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1580 EnterCriticalSection(&ddraw_cs);
1581 hr = IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1584 LeaveCriticalSection(&ddraw_cs);
1585 return hr;
1588 /*****************************************************************************
1589 * IDirectDrawSurface7::GetPixelFormat
1591 * Returns the pixel format of the Surface
1593 * Params:
1594 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1595 * format should be written
1597 * Returns:
1598 * DD_OK on success
1599 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1601 *****************************************************************************/
1602 static HRESULT WINAPI
1603 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1604 DDPIXELFORMAT *PixelFormat)
1606 /* What is DDERR_INVALIDSURFACETYPE for here? */
1607 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1608 TRACE("(%p)->(%p)\n",This,PixelFormat);
1610 if(!PixelFormat)
1611 return DDERR_INVALIDPARAMS;
1613 EnterCriticalSection(&ddraw_cs);
1614 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1615 LeaveCriticalSection(&ddraw_cs);
1617 return DD_OK;
1621 /*****************************************************************************
1622 * IDirectDrawSurface7::GetSurfaceDesc
1624 * Returns the description of this surface
1626 * Params:
1627 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1628 * surface desc
1630 * Returns:
1631 * DD_OK on success
1632 * DDERR_INVALIDPARAMS if DDSD is NULL
1634 *****************************************************************************/
1635 static HRESULT WINAPI
1636 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1637 DDSURFACEDESC2 *DDSD)
1639 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1641 TRACE("(%p)->(%p)\n",This,DDSD);
1643 if(!DDSD)
1644 return DDERR_INVALIDPARAMS;
1646 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
1648 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
1649 return DDERR_INVALIDPARAMS;
1652 EnterCriticalSection(&ddraw_cs);
1653 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1654 TRACE("Returning surface desc:\n");
1655 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1657 LeaveCriticalSection(&ddraw_cs);
1658 return DD_OK;
1661 /*****************************************************************************
1662 * IDirectDrawSurface7::Initialize
1664 * Initializes the surface. This is a no-op in Wine
1666 * Params:
1667 * DD: Pointer to an DirectDraw interface
1668 * DDSD: Surface description for initialization
1670 * Returns:
1671 * DDERR_ALREADYINITIALIZED
1673 *****************************************************************************/
1674 static HRESULT WINAPI
1675 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1676 IDirectDraw *DD,
1677 DDSURFACEDESC2 *DDSD)
1679 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1680 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1681 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1683 return DDERR_ALREADYINITIALIZED;
1686 /*****************************************************************************
1687 * IDirectDrawSurface7::IsLost
1689 * Checks if the surface is lost
1691 * Returns:
1692 * DD_OK, if the surface is useable
1693 * DDERR_ISLOST if the surface is lost
1694 * See IWineD3DSurface::IsLost for more details
1696 *****************************************************************************/
1697 static HRESULT WINAPI
1698 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1700 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1701 HRESULT hr;
1702 TRACE("(%p)\n", This);
1704 EnterCriticalSection(&ddraw_cs);
1705 /* We lose the surface if the implementation was changed */
1706 if(This->ImplType != This->ddraw->ImplType)
1708 /* But this shouldn't happen. When we change the implementation,
1709 * all surfaces are re-created automatically, and their content
1710 * is copied
1712 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1713 LeaveCriticalSection(&ddraw_cs);
1714 return DDERR_SURFACELOST;
1717 hr = IWineD3DSurface_IsLost(This->WineD3DSurface);
1718 LeaveCriticalSection(&ddraw_cs);
1719 switch(hr)
1721 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1722 * WineD3D uses the same error for surfaces
1724 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
1725 default: return hr;
1729 /*****************************************************************************
1730 * IDirectDrawSurface7::Restore
1732 * Restores a lost surface. This makes the surface usable again, but
1733 * doesn't reload its old contents
1735 * Returns:
1736 * DD_OK on success
1737 * See IWineD3DSurface::Restore for more details
1739 *****************************************************************************/
1740 static HRESULT WINAPI
1741 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1743 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1744 HRESULT hr;
1745 TRACE("(%p)\n", This);
1747 EnterCriticalSection(&ddraw_cs);
1748 if(This->ImplType != This->ddraw->ImplType)
1750 /* Call the recreation callback. Make sure to AddRef first */
1751 IDirectDrawSurface_AddRef(iface);
1752 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1753 &This->surface_desc,
1754 NULL /* Not needed */);
1756 hr = IWineD3DSurface_Restore(This->WineD3DSurface);
1757 LeaveCriticalSection(&ddraw_cs);
1758 return hr;
1761 /*****************************************************************************
1762 * IDirectDrawSurface7::SetOverlayPosition
1764 * Changes the display coordinates of an overlay surface
1766 * Params:
1767 * X:
1768 * Y:
1770 * Returns:
1771 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1772 *****************************************************************************/
1773 static HRESULT WINAPI
1774 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1775 LONG X,
1776 LONG Y)
1778 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1779 HRESULT hr;
1780 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1782 EnterCriticalSection(&ddraw_cs);
1783 hr = IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1786 LeaveCriticalSection(&ddraw_cs);
1787 return hr;
1790 /*****************************************************************************
1791 * IDirectDrawSurface7::UpdateOverlay
1793 * Modifies the attributes of an overlay surface.
1795 * Params:
1796 * SrcRect: The section of the source being used for the overlay
1797 * DstSurface: Address of the surface that is overlaid
1798 * DstRect: Place of the overlay
1799 * Flags: some DDOVER_* flags
1801 * Returns:
1802 * DDERR_UNSUPPORTED, because we don't support overlays
1804 *****************************************************************************/
1805 static HRESULT WINAPI
1806 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1807 LPRECT SrcRect,
1808 IDirectDrawSurface7 *DstSurface,
1809 LPRECT DstRect,
1810 DWORD Flags,
1811 LPDDOVERLAYFX FX)
1813 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1814 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1815 HRESULT hr;
1816 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1818 EnterCriticalSection(&ddraw_cs);
1819 hr = IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1820 SrcRect,
1821 Dst ? Dst->WineD3DSurface : NULL,
1822 DstRect,
1823 Flags,
1824 (WINEDDOVERLAYFX *) FX);
1825 LeaveCriticalSection(&ddraw_cs);
1826 return hr;
1829 /*****************************************************************************
1830 * IDirectDrawSurface7::UpdateOverlayDisplay
1832 * The DX7 sdk says that it's not implemented
1834 * Params:
1835 * Flags: ?
1837 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1839 *****************************************************************************/
1840 static HRESULT WINAPI
1841 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1842 DWORD Flags)
1844 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1845 TRACE("(%p)->(%x)\n", This, Flags);
1846 return DDERR_UNSUPPORTED;
1849 /*****************************************************************************
1850 * IDirectDrawSurface7::UpdateOverlayZOrder
1852 * Sets an overlay's Z order
1854 * Params:
1855 * Flags: DDOVERZ_* flags
1856 * DDSRef: Defines the relative position in the overlay chain
1858 * Returns:
1859 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1861 *****************************************************************************/
1862 static HRESULT WINAPI
1863 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1864 DWORD Flags,
1865 IDirectDrawSurface7 *DDSRef)
1867 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1868 HRESULT hr;
1869 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1871 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1872 EnterCriticalSection(&ddraw_cs);
1873 hr = IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1874 Flags,
1875 Ref ? Ref->WineD3DSurface : NULL);
1876 LeaveCriticalSection(&ddraw_cs);
1877 return hr;
1880 /*****************************************************************************
1881 * IDirectDrawSurface7::GetDDInterface
1883 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1884 * surface belongs to
1886 * Params:
1887 * DD: Address to write the interface pointer to
1889 * Returns:
1890 * DD_OK on success
1891 * DDERR_INVALIDPARAMS if DD is NULL
1893 *****************************************************************************/
1894 static HRESULT WINAPI
1895 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1896 void **DD)
1898 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1900 TRACE("(%p)->(%p)\n",This,DD);
1902 if(!DD)
1903 return DDERR_INVALIDPARAMS;
1905 switch(This->version)
1907 case 7:
1908 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1909 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1910 break;
1912 case 4:
1913 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1914 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1915 break;
1917 case 2:
1918 *((IDirectDraw2 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
1919 IDirectDraw_AddRef( *(IDirectDraw2 **) DD);
1920 break;
1922 case 1:
1923 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1924 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1925 break;
1929 return DD_OK;
1932 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1933 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1935 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1936 volatile IDirectDrawSurfaceImpl* vThis = This;
1938 TRACE("(%p)\n",This);
1939 EnterCriticalSection(&ddraw_cs);
1940 /* A uniqueness value of 0 is apparently special.
1941 * This needs to be checked.
1942 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1944 while (1) {
1945 DWORD old_uniqueness_value = vThis->uniqueness_value;
1946 DWORD new_uniqueness_value = old_uniqueness_value+1;
1948 if (old_uniqueness_value == 0) break;
1949 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1951 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1952 old_uniqueness_value,
1953 new_uniqueness_value)
1954 == old_uniqueness_value)
1955 break;
1958 LeaveCriticalSection(&ddraw_cs);
1959 return DD_OK;
1962 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1964 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1966 TRACE("(%p)->(%p)\n",This,pValue);
1967 EnterCriticalSection(&ddraw_cs);
1968 *pValue = This->uniqueness_value;
1969 LeaveCriticalSection(&ddraw_cs);
1970 return DD_OK;
1973 /*****************************************************************************
1974 * IDirectDrawSurface7::SetLOD
1976 * Sets the level of detail of a texture
1978 * Params:
1979 * MaxLOD: LOD to set
1981 * Returns:
1982 * DD_OK on success
1983 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1985 *****************************************************************************/
1986 static HRESULT WINAPI
1987 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1988 DWORD MaxLOD)
1990 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1991 HRESULT hr;
1992 TRACE("(%p)->(%d)\n", This, MaxLOD);
1994 EnterCriticalSection(&ddraw_cs);
1995 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1997 LeaveCriticalSection(&ddraw_cs);
1998 return DDERR_INVALIDOBJECT;
2001 if(!This->wineD3DTexture)
2003 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
2004 LeaveCriticalSection(&ddraw_cs);
2005 return DDERR_INVALIDOBJECT;
2008 hr = IWineD3DBaseTexture_SetLOD(This->wineD3DTexture,
2009 MaxLOD);
2010 LeaveCriticalSection(&ddraw_cs);
2011 return hr;
2014 /*****************************************************************************
2015 * IDirectDrawSurface7::GetLOD
2017 * Returns the level of detail of a Direct3D texture
2019 * Params:
2020 * MaxLOD: Address to write the LOD to
2022 * Returns:
2023 * DD_OK on success
2024 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2025 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2027 *****************************************************************************/
2028 static HRESULT WINAPI
2029 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
2030 DWORD *MaxLOD)
2032 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2033 TRACE("(%p)->(%p)\n", This, MaxLOD);
2035 if(!MaxLOD)
2036 return DDERR_INVALIDPARAMS;
2038 EnterCriticalSection(&ddraw_cs);
2039 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2041 LeaveCriticalSection(&ddraw_cs);
2042 return DDERR_INVALIDOBJECT;
2045 *MaxLOD = IWineD3DBaseTexture_GetLOD(This->wineD3DTexture);
2046 LeaveCriticalSection(&ddraw_cs);
2047 return DD_OK;
2050 /*****************************************************************************
2051 * IDirectDrawSurface7::BltFast
2053 * Performs a fast Blit.
2055 * Params:
2056 * dstx: The x coordinate to blit to on the destination
2057 * dsty: The y coordinate to blit to on the destination
2058 * Source: The source surface
2059 * rsrc: The source rectangle
2060 * trans: Type of transfer. Some DDBLTFAST_* flags
2062 * Returns:
2063 * DD_OK on success
2064 * For more details, see IWineD3DSurface::BltFast
2066 *****************************************************************************/
2067 static HRESULT WINAPI
2068 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
2069 DWORD dstx,
2070 DWORD dsty,
2071 IDirectDrawSurface7 *Source,
2072 RECT *rsrc,
2073 DWORD trans)
2075 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2076 HRESULT hr;
2077 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
2078 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
2080 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2081 * in that case
2083 if(rsrc)
2085 if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right ||
2086 rsrc->right > src->surface_desc.dwWidth ||
2087 rsrc->bottom > src->surface_desc.dwHeight)
2089 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2090 return DDERR_INVALIDRECT;
2092 if(dstx + rsrc->right - rsrc->left > This->surface_desc.dwWidth ||
2093 dsty + rsrc->bottom - rsrc->top > This->surface_desc.dwHeight)
2095 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2096 return DDERR_INVALIDRECT;
2099 else
2101 if(dstx + src->surface_desc.dwWidth > This->surface_desc.dwWidth ||
2102 dsty + src->surface_desc.dwHeight > This->surface_desc.dwHeight)
2104 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2105 return DDERR_INVALIDRECT;
2109 EnterCriticalSection(&ddraw_cs);
2110 hr = IWineD3DSurface_BltFast(This->WineD3DSurface,
2111 dstx, dsty,
2112 src ? src->WineD3DSurface : NULL,
2113 rsrc,
2114 trans);
2115 LeaveCriticalSection(&ddraw_cs);
2116 switch(hr)
2118 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
2119 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
2120 default: return hr;
2124 /*****************************************************************************
2125 * IDirectDrawSurface7::GetClipper
2127 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2128 * surface
2130 * Params:
2131 * Clipper: Address to store the interface pointer at
2133 * Returns:
2134 * DD_OK on success
2135 * DDERR_INVALIDPARAMS if Clipper is NULL
2136 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2138 *****************************************************************************/
2139 static HRESULT WINAPI
2140 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
2141 IDirectDrawClipper **Clipper)
2143 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2144 TRACE("(%p)->(%p)\n", This, Clipper);
2146 if(!Clipper)
2148 LeaveCriticalSection(&ddraw_cs);
2149 return DDERR_INVALIDPARAMS;
2152 EnterCriticalSection(&ddraw_cs);
2153 if(This->clipper == NULL)
2155 LeaveCriticalSection(&ddraw_cs);
2156 return DDERR_NOCLIPPERATTACHED;
2159 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
2160 IDirectDrawClipper_AddRef(*Clipper);
2161 LeaveCriticalSection(&ddraw_cs);
2162 return DD_OK;
2165 /*****************************************************************************
2166 * IDirectDrawSurface7::SetClipper
2168 * Sets a clipper for the surface
2170 * Params:
2171 * Clipper: IDirectDrawClipper interface of the clipper to set
2173 * Returns:
2174 * DD_OK on success
2176 *****************************************************************************/
2177 static HRESULT WINAPI
2178 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
2179 IDirectDrawClipper *Clipper)
2181 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2182 IDirectDrawClipperImpl *oldClipper = This->clipper;
2183 HRESULT hr;
2184 TRACE("(%p)->(%p)\n",This,Clipper);
2186 EnterCriticalSection(&ddraw_cs);
2187 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
2189 LeaveCriticalSection(&ddraw_cs);
2190 return DD_OK;
2193 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
2195 if (Clipper != NULL)
2196 IDirectDrawClipper_AddRef(Clipper);
2197 if(oldClipper)
2198 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper, IDirectDrawClipper));
2200 hr = IWineD3DSurface_SetClipper(This->WineD3DSurface, This->clipper ? This->clipper->wineD3DClipper : NULL);
2201 LeaveCriticalSection(&ddraw_cs);
2202 return hr;
2205 /*****************************************************************************
2206 * IDirectDrawSurface7::SetSurfaceDesc
2208 * Sets the surface description. It can override the pixel format, the surface
2209 * memory, ...
2210 * It's not really tested.
2212 * Params:
2213 * DDSD: Pointer to the new surface description to set
2214 * Flags: Some flags
2216 * Returns:
2217 * DD_OK on success
2218 * DDERR_INVALIDPARAMS if DDSD is NULL
2220 *****************************************************************************/
2221 static HRESULT WINAPI
2222 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
2223 DDSURFACEDESC2 *DDSD,
2224 DWORD Flags)
2226 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2227 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
2228 HRESULT hr;
2229 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
2231 if(!DDSD)
2232 return DDERR_INVALIDPARAMS;
2234 EnterCriticalSection(&ddraw_cs);
2235 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
2237 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
2239 if(newFormat == WINED3DFMT_UNKNOWN)
2241 ERR("Requested to set an unknown pixelformat\n");
2242 LeaveCriticalSection(&ddraw_cs);
2243 return DDERR_INVALIDPARAMS;
2245 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
2247 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
2248 newFormat);
2249 if(hr != DD_OK)
2251 LeaveCriticalSection(&ddraw_cs);
2252 return hr;
2256 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
2258 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2259 DDCKEY_DESTOVERLAY,
2260 (WINEDDCOLORKEY *) &DDSD->u3.ddckCKDestOverlay);
2262 if (DDSD->dwFlags & DDSD_CKDESTBLT)
2264 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2265 DDCKEY_DESTBLT,
2266 (WINEDDCOLORKEY *) &DDSD->ddckCKDestBlt);
2268 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
2270 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2271 DDCKEY_SRCOVERLAY,
2272 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcOverlay);
2274 if (DDSD->dwFlags & DDSD_CKSRCBLT)
2276 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2277 DDCKEY_SRCBLT,
2278 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcBlt);
2280 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
2282 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
2283 if(hr != WINED3D_OK)
2285 /* No need for a trace here, wined3d does that for us */
2286 LeaveCriticalSection(&ddraw_cs);
2287 switch(hr)
2289 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2290 default: break; /* Go on */
2296 This->surface_desc = *DDSD;
2298 LeaveCriticalSection(&ddraw_cs);
2299 return DD_OK;
2302 /*****************************************************************************
2303 * IDirectDrawSurface7::GetPalette
2305 * Returns the IDirectDrawPalette interface of the palette currently assigned
2306 * to the surface
2308 * Params:
2309 * Pal: Address to write the interface pointer to
2311 * Returns:
2312 * DD_OK on success
2313 * DDERR_INVALIDPARAMS if Pal is NULL
2315 *****************************************************************************/
2316 static HRESULT WINAPI
2317 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
2318 IDirectDrawPalette **Pal)
2320 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2321 IWineD3DPalette *wPal;
2322 HRESULT hr;
2323 TRACE("(%p)->(%p): Relay\n", This, Pal);
2325 if(!Pal)
2326 return DDERR_INVALIDPARAMS;
2328 EnterCriticalSection(&ddraw_cs);
2329 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
2330 if(hr != DD_OK)
2332 LeaveCriticalSection(&ddraw_cs);
2333 return hr;
2336 if(wPal)
2338 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2340 else
2342 *Pal = NULL;
2343 hr = DDERR_NOPALETTEATTACHED;
2346 LeaveCriticalSection(&ddraw_cs);
2347 return hr;
2350 /*****************************************************************************
2351 * SetColorKeyEnum
2353 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2354 * recursively in the surface tree
2356 *****************************************************************************/
2357 struct SCKContext
2359 HRESULT ret;
2360 WINEDDCOLORKEY *CKey;
2361 DWORD Flags;
2364 static HRESULT WINAPI
2365 SetColorKeyEnum(IDirectDrawSurface7 *surface,
2366 DDSURFACEDESC2 *desc,
2367 void *context)
2369 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, surface);
2370 struct SCKContext *ctx = context;
2371 HRESULT hr;
2373 hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2374 ctx->Flags,
2375 ctx->CKey);
2376 if(hr != DD_OK)
2378 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
2379 ctx->ret = hr;
2382 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
2383 context,
2384 SetColorKeyEnum);
2385 IDirectDrawSurface7_Release(surface);
2386 return DDENUMRET_OK;
2389 /*****************************************************************************
2390 * IDirectDrawSurface7::SetColorKey
2392 * Sets the color keying options for the surface. Observations showed that
2393 * in case of complex surfaces the color key has to be assigned to all
2394 * sublevels.
2396 * Params:
2397 * Flags: DDCKEY_*
2398 * CKey: The new color key
2400 * Returns:
2401 * DD_OK on success
2402 * See IWineD3DSurface::SetColorKey for details
2404 *****************************************************************************/
2405 static HRESULT WINAPI
2406 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2407 DWORD Flags,
2408 DDCOLORKEY *CKey)
2410 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2411 struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) CKey, Flags };
2412 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2414 EnterCriticalSection(&ddraw_cs);
2415 if (CKey)
2417 switch (Flags & ~DDCKEY_COLORSPACE)
2419 case DDCKEY_DESTBLT:
2420 This->surface_desc.ddckCKDestBlt = *CKey;
2421 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
2422 break;
2424 case DDCKEY_DESTOVERLAY:
2425 This->surface_desc.u3.ddckCKDestOverlay = *CKey;
2426 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
2427 break;
2429 case DDCKEY_SRCOVERLAY:
2430 This->surface_desc.ddckCKSrcOverlay = *CKey;
2431 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
2432 break;
2434 case DDCKEY_SRCBLT:
2435 This->surface_desc.ddckCKSrcBlt = *CKey;
2436 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
2437 break;
2439 default:
2440 LeaveCriticalSection(&ddraw_cs);
2441 return DDERR_INVALIDPARAMS;
2444 else
2446 switch (Flags & ~DDCKEY_COLORSPACE)
2448 case DDCKEY_DESTBLT:
2449 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
2450 break;
2452 case DDCKEY_DESTOVERLAY:
2453 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
2454 break;
2456 case DDCKEY_SRCOVERLAY:
2457 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
2458 break;
2460 case DDCKEY_SRCBLT:
2461 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
2462 break;
2464 default:
2465 LeaveCriticalSection(&ddraw_cs);
2466 return DDERR_INVALIDPARAMS;
2469 ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2470 Flags,
2471 ctx.CKey);
2472 IDirectDrawSurface7_EnumAttachedSurfaces(iface,
2473 (void *) &ctx,
2474 SetColorKeyEnum);
2475 LeaveCriticalSection(&ddraw_cs);
2476 switch(ctx.ret)
2478 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2479 default: return ctx.ret;
2483 /*****************************************************************************
2484 * IDirectDrawSurface7::SetPalette
2486 * Assigns a DirectDrawPalette object to the surface
2488 * Params:
2489 * Pal: Interface to the palette to set
2491 * Returns:
2492 * DD_OK on success
2494 *****************************************************************************/
2495 static HRESULT WINAPI
2496 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2497 IDirectDrawPalette *Pal)
2499 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2500 IDirectDrawPalette *oldPal;
2501 IDirectDrawSurfaceImpl *surf;
2502 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2503 HRESULT hr;
2504 TRACE("(%p)->(%p)\n", This, Pal);
2506 if (!(This->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 |
2507 DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8))) {
2508 return DDERR_INVALIDPIXELFORMAT;
2511 /* Find the old palette */
2512 EnterCriticalSection(&ddraw_cs);
2513 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2514 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
2516 LeaveCriticalSection(&ddraw_cs);
2517 return hr;
2519 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2521 /* Set the new Palette */
2522 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2523 PalImpl ? PalImpl->wineD3DPalette : NULL);
2524 /* AddRef the Palette */
2525 if(Pal) IDirectDrawPalette_AddRef(Pal);
2527 /* Release the old palette */
2528 if(oldPal) IDirectDrawPalette_Release(oldPal);
2530 /* If this is a front buffer, also update the back buffers
2531 * TODO: How do things work for palettized cube textures?
2533 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2535 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2536 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
2538 surf = This;
2539 while(1)
2541 IDirectDrawSurface7 *attach;
2542 HRESULT hr;
2543 hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2544 &caps2, &attach);
2545 if(hr != DD_OK)
2547 break;
2550 TRACE("Setting palette on %p\n", attach);
2551 IDirectDrawSurface7_SetPalette(attach,
2552 Pal);
2553 surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, attach);
2554 IDirectDrawSurface7_Release(attach);
2558 LeaveCriticalSection(&ddraw_cs);
2559 return DD_OK;
2562 /*****************************************************************************
2563 * The VTable
2564 *****************************************************************************/
2566 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2568 /*** IUnknown ***/
2569 IDirectDrawSurfaceImpl_QueryInterface,
2570 IDirectDrawSurfaceImpl_AddRef,
2571 IDirectDrawSurfaceImpl_Release,
2572 /*** IDirectDrawSurface ***/
2573 IDirectDrawSurface7Impl_AddAttachedSurface,
2574 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2575 IDirectDrawSurfaceImpl_Blt,
2576 IDirectDrawSurfaceImpl_BltBatch,
2577 IDirectDrawSurfaceImpl_BltFast,
2578 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2579 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2580 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2581 IDirectDrawSurfaceImpl_Flip,
2582 IDirectDrawSurfaceImpl_GetAttachedSurface,
2583 IDirectDrawSurfaceImpl_GetBltStatus,
2584 IDirectDrawSurfaceImpl_GetCaps,
2585 IDirectDrawSurfaceImpl_GetClipper,
2586 IDirectDrawSurfaceImpl_GetColorKey,
2587 IDirectDrawSurfaceImpl_GetDC,
2588 IDirectDrawSurfaceImpl_GetFlipStatus,
2589 IDirectDrawSurfaceImpl_GetOverlayPosition,
2590 IDirectDrawSurfaceImpl_GetPalette,
2591 IDirectDrawSurfaceImpl_GetPixelFormat,
2592 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2593 IDirectDrawSurfaceImpl_Initialize,
2594 IDirectDrawSurfaceImpl_IsLost,
2595 IDirectDrawSurfaceImpl_Lock,
2596 IDirectDrawSurfaceImpl_ReleaseDC,
2597 IDirectDrawSurfaceImpl_Restore,
2598 IDirectDrawSurfaceImpl_SetClipper,
2599 IDirectDrawSurfaceImpl_SetColorKey,
2600 IDirectDrawSurfaceImpl_SetOverlayPosition,
2601 IDirectDrawSurfaceImpl_SetPalette,
2602 IDirectDrawSurfaceImpl_Unlock,
2603 IDirectDrawSurfaceImpl_UpdateOverlay,
2604 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2605 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2606 /*** IDirectDrawSurface2 ***/
2607 IDirectDrawSurfaceImpl_GetDDInterface,
2608 IDirectDrawSurfaceImpl_PageLock,
2609 IDirectDrawSurfaceImpl_PageUnlock,
2610 /*** IDirectDrawSurface3 ***/
2611 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2612 /*** IDirectDrawSurface4 ***/
2613 IDirectDrawSurfaceImpl_SetPrivateData,
2614 IDirectDrawSurfaceImpl_GetPrivateData,
2615 IDirectDrawSurfaceImpl_FreePrivateData,
2616 IDirectDrawSurfaceImpl_GetUniquenessValue,
2617 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2618 /*** IDirectDrawSurface7 ***/
2619 IDirectDrawSurfaceImpl_SetPriority,
2620 IDirectDrawSurfaceImpl_GetPriority,
2621 IDirectDrawSurfaceImpl_SetLOD,
2622 IDirectDrawSurfaceImpl_GetLOD