push 22b3e00525a9a3743634eb8f21ffe1bf98bf885e
[wine/hacks.git] / dlls / ddraw / surface.c
blobbde2234e9d24af4a6cdba1d5d4ee16e3f3261e5d
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 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)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 = iface;
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 = &This->IDirectDrawSurface3_vtbl;
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 = &This->IDirectDrawGammaControl_vtbl;
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((IDirect3D7 *)&This->ddraw->IDirect3D7_vtbl, riid, (IDirectDrawSurface7 *)This, &d3d);
121 *obj = d3d ? (IDirect3DDevice *)&((IDirect3DDeviceImpl *)d3d)->IDirect3DDevice_vtbl : NULL;
122 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
124 return S_OK;
126 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
127 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
129 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
131 *obj = &This->IDirect3DTexture_vtbl;
132 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
134 else
136 *obj = &This->IDirect3DTexture2_vtbl;
137 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
139 IUnknown_AddRef( (IUnknown *) *obj);
140 return S_OK;
143 ERR("No interface\n");
144 return E_NOINTERFACE;
147 /*****************************************************************************
148 * IDirectDrawSurface7::AddRef
150 * A normal addref implementation
152 * Returns:
153 * The new refcount
155 *****************************************************************************/
156 static ULONG WINAPI
157 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
159 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
160 ULONG refCount = InterlockedIncrement(&This->ref);
162 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
163 return refCount;
166 /*****************************************************************************
167 * IDirectDrawSurfaceImpl_Destroy
169 * A helper function for IDirectDrawSurface7::Release
171 * Frees the surface, regardless of its refcount.
172 * See IDirectDrawSurface7::Release for more information
174 * Params:
175 * This: Surface to free
177 *****************************************************************************/
178 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
180 TRACE("(%p)\n", This);
182 /* Check the refcount and give a warning */
183 if(This->ref > 1)
185 /* This can happen when a complex surface is destroyed,
186 * because the 2nd surface was addref()ed when the app
187 * called GetAttachedSurface
189 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
192 /* Check for attached surfaces and detach them */
193 if(This->first_attached != This)
195 /* Well, this shouldn't happen: The surface being attached is addref()ed
196 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
197 * is called, because the refcount is held. It looks like the app released()
198 * it often enough to force this
200 IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)This->first_attached;
201 IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)This;
203 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
205 /* The refcount will drop to -1 here */
206 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
208 ERR("(%p) DeleteAttachedSurface failed!\n", This);
212 while(This->next_attached != NULL)
214 IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)This;
215 IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)This->next_attached;
217 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
219 ERR("(%p) DeleteAttachedSurface failed!\n", This);
220 assert(0);
224 /* Now destroy the surface. Wait: It could have been released if we are a texture */
225 if(This->WineD3DSurface)
226 IWineD3DSurface_Release(This->WineD3DSurface);
228 /* Having a texture handle set implies that the device still exists */
229 if(This->Handle)
231 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
232 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
235 /* Reduce the ddraw surface count */
236 InterlockedDecrement(&This->ddraw->surfaces);
237 list_remove(&This->surface_list_entry);
239 HeapFree(GetProcessHeap(), 0, This);
242 /*****************************************************************************
243 * IDirectDrawSurface7::Release
245 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
246 * surface is destroyed.
248 * Destroying the surface is a bit tricky. For the connection between
249 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
250 * It has a nice graph explaining the connection.
252 * What happens here is basically this:
253 * When a surface is destroyed, its WineD3DSurface is released,
254 * and the refcount of the DirectDraw interface is reduced by 1. If it has
255 * complex surfaces attached to it, then these surfaces are destroyed too,
256 * regardless of their refcount. If any surface being destroyed has another
257 * surface attached to it (with a "soft" attachment, not complex), then
258 * this surface is detached with DeleteAttachedSurface.
260 * When the surface is a texture, the WineD3DTexture is released.
261 * If the surface is the Direct3D render target, then the D3D
262 * capabilities of the WineD3DDevice are uninitialized, which causes the
263 * swapchain to be released.
265 * When a complex sublevel falls to ref zero, then this is ignored.
267 * Returns:
268 * The new refcount
270 *****************************************************************************/
271 static ULONG WINAPI
272 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
274 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
275 ULONG ref;
276 TRACE("(%p) : Releasing from %d\n", This, This->ref);
277 ref = InterlockedDecrement(&This->ref);
279 if (ref == 0)
282 IDirectDrawSurfaceImpl *surf;
283 IDirectDrawImpl *ddraw;
284 IUnknown *ifaceToRelease = This->ifaceToRelease;
285 UINT i;
287 /* Complex attached surfaces are destroyed implicitly when the root is released */
288 EnterCriticalSection(&ddraw_cs);
289 if(!This->is_complex_root)
291 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
292 LeaveCriticalSection(&ddraw_cs);
293 return ref;
295 ddraw = This->ddraw;
297 /* If it's a texture, destroy the WineD3DTexture.
298 * WineD3D will destroy the IParent interfaces
299 * of the sublevels, which destroys the WineD3DSurfaces.
300 * Set the surfaces to NULL to avoid destroying them again later
302 if(This->wineD3DTexture)
304 IWineD3DBaseTexture_Release(This->wineD3DTexture);
306 /* If it's the RenderTarget, destroy the d3ddevice */
307 else if(This->wineD3DSwapChain)
309 if((ddraw->d3d_initialized) && (This == ddraw->d3d_target)) {
310 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
312 /* Unset any index buffer, just to be sure */
313 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
314 IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
315 IWineD3DDevice_SetVertexDeclaration(ddraw->wineD3DDevice, NULL);
316 for(i = 0; i < ddraw->numConvertedDecls; i++)
318 IWineD3DVertexDeclaration_Release(ddraw->decls[i].decl);
320 HeapFree(GetProcessHeap(), 0, ddraw->decls);
321 ddraw->numConvertedDecls = 0;
323 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice, D3D7CB_DestroyDepthStencilSurface, D3D7CB_DestroySwapChain) != D3D_OK)
325 /* Not good */
326 ERR("(%p) Failed to uninit 3D\n", This);
328 else
330 /* Free the d3d window if one was created */
331 if(ddraw->d3d_window != 0 && ddraw->d3d_window != ddraw->dest_window)
333 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
334 DestroyWindow(ddraw->d3d_window);
335 ddraw->d3d_window = 0;
337 /* Unset the pointers */
340 This->wineD3DSwapChain = NULL; /* Uninit3D releases the swapchain */
341 ddraw->d3d_initialized = FALSE;
342 ddraw->d3d_target = NULL;
343 } else {
344 IWineD3DDevice_UninitGDI(ddraw->wineD3DDevice, D3D7CB_DestroySwapChain);
345 This->wineD3DSwapChain = NULL;
348 /* Reset to the default surface implementation type. This is needed if apps use
349 * non render target surfaces and expect blits to work after destroying the render
350 * target.
352 * TODO: Recreate existing offscreen surfaces
354 ddraw->ImplType = DefaultSurfaceType;
356 /* Write a trace because D3D unloading was the reason for many
357 * crashes during development.
359 TRACE("(%p) D3D unloaded\n", This);
361 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
362 DDSCAPS_3DDEVICE |
363 DDSCAPS_TEXTURE ) )
365 /* It's a render target, but no swapchain was created.
366 * The IParent interfaces have to be released manually.
367 * The same applies for textures without an
368 * IWineD3DTexture object attached
370 IParent *Parent;
372 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
374 if(This->complex_array[i])
376 /* Only the topmost level can have more than 1 surfaces in the complex
377 * attachment array(Cube texture roots), for all others there is only
378 * one
380 surf = This->complex_array[i];
381 while(surf)
383 IWineD3DSurface_GetParent(surf->WineD3DSurface,
384 (IUnknown **) &Parent);
385 IParent_Release(Parent); /* For the getParent */
386 IParent_Release(Parent); /* To release it */
387 surf = surf->complex_array[0];
392 /* Now the top-level surface */
393 IWineD3DSurface_GetParent(This->WineD3DSurface,
394 (IUnknown **) &Parent);
395 IParent_Release(Parent); /* For the getParent */
396 IParent_Release(Parent); /* To release it */
399 /* The refcount test shows that the palette is detached when the surface is destroyed */
400 IDirectDrawSurface7_SetPalette((IDirectDrawSurface7 *)This, NULL);
402 /* Loop through all complex attached surfaces,
403 * and destroy them.
405 * Yet again, only the root can have more than one complexly attached surface, all the others
406 * have a total of one;
408 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
410 if(!This->complex_array[i]) break;
412 surf = This->complex_array[i];
413 This->complex_array[i] = NULL;
414 while(surf)
416 IDirectDrawSurfaceImpl *destroy = surf;
417 surf = surf->complex_array[0]; /* Iterate through the "tree" */
418 IDirectDrawSurfaceImpl_Destroy(destroy); /* Destroy it */
422 /* Destroy the root surface.
424 IDirectDrawSurfaceImpl_Destroy(This);
426 /* Reduce the ddraw refcount */
427 if(ifaceToRelease) IUnknown_Release(ifaceToRelease);
428 LeaveCriticalSection(&ddraw_cs);
431 return ref;
434 /*****************************************************************************
435 * IDirectDrawSurface7::GetAttachedSurface
437 * Returns an attached surface with the requested caps. Surface attachment
438 * and complex surfaces are not clearly described by the MSDN or sdk,
439 * so this method is tricky and likely to contain problems.
440 * This implementation searches the complex list first, then the
441 * attachment chain.
443 * The chains are searched from This down to the last surface in the chain,
444 * not from the first element in the chain. The first surface found is
445 * returned. The MSDN says that this method fails if more than one surface
446 * matches the caps, but it is not sure if that is right. The attachment
447 * structure may not even allow two matching surfaces.
449 * The found surface is AddRef-ed before it is returned.
451 * Params:
452 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
453 * Surface: Address to store the found surface
455 * Returns:
456 * DD_OK on success
457 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
458 * DDERR_NOTFOUND if no surface was found
460 *****************************************************************************/
461 static HRESULT WINAPI
462 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
463 DDSCAPS2 *Caps,
464 IDirectDrawSurface7 **Surface)
466 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
467 IDirectDrawSurfaceImpl *surf;
468 DDSCAPS2 our_caps;
469 int i;
471 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
472 EnterCriticalSection(&ddraw_cs);
474 if(This->version < 7)
476 /* Earlier dx apps put garbage into these members, clear them */
477 our_caps.dwCaps = Caps->dwCaps;
478 our_caps.dwCaps2 = 0;
479 our_caps.dwCaps3 = 0;
480 our_caps.dwCaps4 = 0;
482 else
484 our_caps = *Caps;
487 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 */
489 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
491 surf = This->complex_array[i];
492 if(!surf) break;
494 if (TRACE_ON(ddraw))
496 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
497 surf->surface_desc.ddsCaps.dwCaps,
498 surf->surface_desc.ddsCaps.dwCaps2,
499 surf->surface_desc.ddsCaps.dwCaps3,
500 surf->surface_desc.ddsCaps.dwCaps4);
503 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
504 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
506 /* MSDN: "This method fails if more than one surface is attached
507 * that matches the capabilities requested."
509 * Not sure how to test this.
512 TRACE("(%p): Returning surface %p\n", This, surf);
513 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
514 *Surface = (IDirectDrawSurface7 *)surf;
515 IDirectDrawSurface7_AddRef(*Surface);
516 LeaveCriticalSection(&ddraw_cs);
517 return DD_OK;
521 /* Next, look at the attachment chain */
522 surf = This;
524 while( (surf = surf->next_attached) )
526 if (TRACE_ON(ddraw))
528 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
529 surf->surface_desc.ddsCaps.dwCaps,
530 surf->surface_desc.ddsCaps.dwCaps2,
531 surf->surface_desc.ddsCaps.dwCaps3,
532 surf->surface_desc.ddsCaps.dwCaps4);
535 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
536 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
538 TRACE("(%p): Returning surface %p\n", This, surf);
539 *Surface = (IDirectDrawSurface7 *)surf;
540 IDirectDrawSurface7_AddRef(*Surface);
541 LeaveCriticalSection(&ddraw_cs);
542 return DD_OK;
546 TRACE("(%p) Didn't find a valid surface\n", This);
547 LeaveCriticalSection(&ddraw_cs);
549 *Surface = NULL;
550 return DDERR_NOTFOUND;
553 /*****************************************************************************
554 * IDirectDrawSurface7::Lock
556 * Locks the surface and returns a pointer to the surface's memory
558 * Params:
559 * Rect: Rectangle to lock. If NULL, the whole surface is locked
560 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
561 * Flags: Locking flags, e.g Read only or write only
562 * h: An event handle that's not used and must be NULL
564 * Returns:
565 * DD_OK on success
566 * DDERR_INVALIDPARAMS if DDSD is NULL
567 * For more details, see IWineD3DSurface::LockRect
569 *****************************************************************************/
570 static HRESULT WINAPI
571 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
572 RECT *Rect,
573 DDSURFACEDESC2 *DDSD,
574 DWORD Flags,
575 HANDLE h)
577 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
578 WINED3DLOCKED_RECT LockedRect;
579 HRESULT hr;
580 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
582 if(!DDSD)
583 return DDERR_INVALIDPARAMS;
585 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
586 EnterCriticalSection(&ddraw_cs);
588 /* Should I check for the handle to be NULL?
590 * The DDLOCK flags and the D3DLOCK flags are equal
591 * for the supported values. The others are ignored by WineD3D
594 if(DDSD->dwSize != sizeof(DDSURFACEDESC) &&
595 DDSD->dwSize != sizeof(DDSURFACEDESC2))
597 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS);
598 LeaveCriticalSection(&ddraw_cs);
599 return DDERR_INVALIDPARAMS;
602 /* Windows zeroes this if the rect is invalid */
603 DDSD->lpSurface = 0;
605 if (Rect)
607 if ((Rect->left < 0)
608 || (Rect->top < 0)
609 || (Rect->left > Rect->right)
610 || (Rect->top > Rect->bottom)
611 || (Rect->right > This->surface_desc.dwWidth)
612 || (Rect->bottom > This->surface_desc.dwHeight))
614 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
615 LeaveCriticalSection(&ddraw_cs);
616 return DDERR_INVALIDPARAMS;
620 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
621 &LockedRect,
622 Rect,
623 Flags);
624 if(hr != D3D_OK)
626 LeaveCriticalSection(&ddraw_cs);
627 switch(hr)
629 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
630 * specific error. But since IWineD3DSurface::LockRect returns that error in this
631 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
632 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
633 * is much easier to do it in one place in ddraw
635 case WINED3DERR_INVALIDCALL: return DDERR_SURFACEBUSY;
636 default: return hr;
640 /* Override the memory area. The pitch should be set already. Strangely windows
641 * does not set the LPSURFACE flag on locked surfaces !?!.
642 * DDSD->dwFlags |= DDSD_LPSURFACE;
644 This->surface_desc.lpSurface = LockedRect.pBits;
645 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
647 TRACE("locked surface returning description :\n");
648 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
650 LeaveCriticalSection(&ddraw_cs);
651 return DD_OK;
654 /*****************************************************************************
655 * IDirectDrawSurface7::Unlock
657 * Unlocks an locked surface
659 * Params:
660 * Rect: Not used by this implementation
662 * Returns:
663 * D3D_OK on success
664 * For more details, see IWineD3DSurface::UnlockRect
666 *****************************************************************************/
667 static HRESULT WINAPI
668 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
669 RECT *pRect)
671 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
672 HRESULT hr;
673 TRACE("(%p)->(%p)\n", This, pRect);
675 EnterCriticalSection(&ddraw_cs);
676 hr = IWineD3DSurface_UnlockRect(This->WineD3DSurface);
677 if(SUCCEEDED(hr))
679 This->surface_desc.lpSurface = NULL;
681 LeaveCriticalSection(&ddraw_cs);
682 return hr;
685 /*****************************************************************************
686 * IDirectDrawSurface7::Flip
688 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
689 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
690 * the flip target is passed to WineD3D, even if the app didn't specify one
692 * Params:
693 * DestOverride: Specifies the surface that will become the new front
694 * buffer. If NULL, the current back buffer is used
695 * Flags: some DirectDraw flags, see include/ddraw.h
697 * Returns:
698 * DD_OK on success
699 * DDERR_NOTFLIPPABLE if no flip target could be found
700 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
701 * For more details, see IWineD3DSurface::Flip
703 *****************************************************************************/
704 static HRESULT WINAPI
705 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
706 IDirectDrawSurface7 *DestOverride,
707 DWORD Flags)
709 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
710 IDirectDrawSurfaceImpl *Override = (IDirectDrawSurfaceImpl *)DestOverride;
711 IDirectDrawSurface7 *Override7;
712 HRESULT hr;
713 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
715 /* Flip has to be called from a front buffer
716 * What about overlay surfaces, AFAIK they can flip too?
718 if( !(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_OVERLAY)) )
719 return DDERR_INVALIDOBJECT; /* Unchecked */
721 EnterCriticalSection(&ddraw_cs);
723 /* WineD3D doesn't keep track of attached surface, so find the target */
724 if(!Override)
726 DDSCAPS2 Caps;
728 memset(&Caps, 0, sizeof(Caps));
729 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
730 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
731 if(hr != DD_OK)
733 ERR("Can't find a flip target\n");
734 LeaveCriticalSection(&ddraw_cs);
735 return DDERR_NOTFLIPPABLE; /* Unchecked */
737 Override = (IDirectDrawSurfaceImpl *)Override7;
739 /* For the GetAttachedSurface */
740 IDirectDrawSurface7_Release(Override7);
743 hr = IWineD3DSurface_Flip(This->WineD3DSurface,
744 Override->WineD3DSurface,
745 Flags);
746 LeaveCriticalSection(&ddraw_cs);
747 return hr;
750 /*****************************************************************************
751 * IDirectDrawSurface7::Blt
753 * Performs a blit on the surface
755 * Params:
756 * DestRect: Destination rectangle, can be NULL
757 * SrcSurface: Source surface, can be NULL
758 * SrcRect: Source rectangle, can be NULL
759 * Flags: Blt flags
760 * DDBltFx: Some extended blt parameters, connected to the flags
762 * Returns:
763 * D3D_OK on success
764 * See IWineD3DSurface::Blt for more details
766 *****************************************************************************/
767 static HRESULT WINAPI
768 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
769 RECT *DestRect,
770 IDirectDrawSurface7 *SrcSurface,
771 RECT *SrcRect,
772 DWORD Flags,
773 DDBLTFX *DDBltFx)
775 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
776 IDirectDrawSurfaceImpl *Src = (IDirectDrawSurfaceImpl *)SrcSurface;
777 HRESULT hr;
778 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
780 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
781 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
783 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
784 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
785 return DDERR_INVALIDPARAMS;
788 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
789 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
790 return DDERR_INVALIDPARAMS;
793 /* Sizes can change, therefore hold the lock when testing the rectangles */
794 EnterCriticalSection(&ddraw_cs);
795 if(DestRect)
797 if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right ||
798 DestRect->right > This->surface_desc.dwWidth ||
799 DestRect->bottom > This->surface_desc.dwHeight)
801 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
802 LeaveCriticalSection(&ddraw_cs);
803 return DDERR_INVALIDRECT;
806 if(Src && SrcRect)
808 if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right ||
809 SrcRect->right > Src->surface_desc.dwWidth ||
810 SrcRect->bottom > Src->surface_desc.dwHeight)
812 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
813 LeaveCriticalSection(&ddraw_cs);
814 return DDERR_INVALIDRECT;
818 if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
819 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
820 LeaveCriticalSection(&ddraw_cs);
821 return DDERR_INVALIDPARAMS;
824 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
825 * and replace the ddraw surfaces with the wined3d surfaces
826 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
828 hr = IWineD3DSurface_Blt(This->WineD3DSurface,
829 DestRect,
830 Src ? Src->WineD3DSurface : NULL,
831 SrcRect,
832 Flags,
833 (WINEDDBLTFX *) DDBltFx,
834 WINED3DTEXF_POINT);
836 LeaveCriticalSection(&ddraw_cs);
837 switch(hr)
839 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
840 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
841 default: return hr;
845 /*****************************************************************************
846 * IDirectDrawSurface7::AddAttachedSurface
848 * Attaches a surface to another surface. How the surface attachments work
849 * is not totally understood yet, and this method is prone to problems.
850 * he surface that is attached is AddRef-ed.
852 * Tests with complex surfaces suggest that the surface attachments form a
853 * tree, but no method to test this has been found yet.
855 * The attachment list consists of a first surface (first_attached) and
856 * for each surface a pointer to the next attached surface (next_attached).
857 * For the first surface, and a surface that has no attachments
858 * first_attached points to the surface itself. A surface that has
859 * no successors in the chain has next_attached set to NULL.
861 * Newly attached surfaces are attached right after the root surface.
862 * If a surface is attached to a complex surface compound, it's attached to
863 * the surface that the app requested, not the complex root. See
864 * GetAttachedSurface for a description how surfaces are found.
866 * This is how the current implementation works, and it was coded by looking
867 * at the needs of the applications.
869 * So far only Z-Buffer attachments are tested, and they are activated in
870 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
871 * Back buffers should work in 2D mode, but they are not tested(They can be
872 * attached in older iface versions). Rendering to the front buffer and
873 * switching between that and double buffering is not yet implemented in
874 * WineD3D, so for 3D it might have unexpected results.
876 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
877 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
878 * performs additional checks. Version 7 of this interface is much more restrictive
879 * than its predecessors.
881 * Params:
882 * Attach: Surface to attach to iface
884 * Returns:
885 * DD_OK on success
886 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
888 *****************************************************************************/
889 HRESULT WINAPI
890 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This,
891 IDirectDrawSurfaceImpl *Surf)
893 TRACE("(%p)->(%p)\n", This, Surf);
895 if(Surf == This)
896 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
898 EnterCriticalSection(&ddraw_cs);
900 /* Check if the surface is already attached somewhere */
901 if( (Surf->next_attached != NULL) ||
902 (Surf->first_attached != Surf) )
904 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
905 * What happens if one surface is attached to 2 different surfaces?
907 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);
908 LeaveCriticalSection(&ddraw_cs);
909 return DDERR_SURFACEALREADYATTACHED;
912 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
913 Surf->next_attached = This->next_attached;
914 Surf->first_attached = This->first_attached;
915 This->next_attached = Surf;
917 /* Check if the WineD3D depth stencil needs updating */
918 if(This->ddraw->d3ddevice)
920 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
923 /* MSDN:
924 * "This method increments the reference count of the surface being attached."
926 IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)Surf);
927 LeaveCriticalSection(&ddraw_cs);
928 return DD_OK;
931 static HRESULT WINAPI
932 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7 *iface,
933 IDirectDrawSurface7 *Attach)
935 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
936 IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach;
938 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
939 if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
942 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
943 Surf->surface_desc.ddsCaps.dwCaps);
944 return DDERR_CANNOTATTACHSURFACE;
947 return IDirectDrawSurfaceImpl_AddAttachedSurface(This,
948 Surf);
950 /*****************************************************************************
951 * IDirectDrawSurface7::DeleteAttachedSurface
953 * Removes a surface from the attachment chain. The surface's refcount
954 * is decreased by one after it has been removed
956 * Params:
957 * Flags: Some flags, not used by this implementation
958 * Attach: Surface to detach
960 * Returns:
961 * DD_OK on success
962 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
964 *****************************************************************************/
965 static HRESULT WINAPI
966 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
967 DWORD Flags,
968 IDirectDrawSurface7 *Attach)
970 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
971 IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach;
972 IDirectDrawSurfaceImpl *Prev = This;
973 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
975 EnterCriticalSection(&ddraw_cs);
976 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
978 LeaveCriticalSection(&ddraw_cs);
979 return DDERR_CANNOTDETACHSURFACE;
982 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
983 if (This->surface_desc.ddsCaps.dwCaps &
984 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
986 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
987 /* FIXME: we should probably also subtract from dwMipMapCount of this
988 * and all parent surfaces */
991 /* Find the predecessor of the detached surface */
992 while(Prev)
994 if(Prev->next_attached == Surf) break;
995 Prev = Prev->next_attached;
998 /* There must be a surface, otherwise there's a bug */
999 assert(Prev != NULL);
1001 /* Unchain the surface */
1002 Prev->next_attached = Surf->next_attached;
1003 Surf->next_attached = NULL;
1004 Surf->first_attached = Surf;
1006 /* Check if the WineD3D depth stencil needs updating */
1007 if(This->ddraw->d3ddevice)
1009 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
1012 IDirectDrawSurface7_Release(Attach);
1013 LeaveCriticalSection(&ddraw_cs);
1014 return DD_OK;
1017 /*****************************************************************************
1018 * IDirectDrawSurface7::AddOverlayDirtyRect
1020 * "This method is not currently implemented"
1022 * Params:
1023 * Rect: ?
1025 * Returns:
1026 * DDERR_UNSUPPORTED
1028 *****************************************************************************/
1029 static HRESULT WINAPI
1030 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
1031 LPRECT Rect)
1033 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1034 TRACE("(%p)->(%p)\n",This,Rect);
1036 /* MSDN says it's not implemented. I could forward it to WineD3D,
1037 * then we'd implement it, but I don't think that's a good idea
1038 * (Stefan Dösinger)
1040 #if 0
1041 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
1042 #endif
1043 return DDERR_UNSUPPORTED; /* unchecked */
1046 /*****************************************************************************
1047 * IDirectDrawSurface7::GetDC
1049 * Returns a GDI device context for the surface
1051 * Params:
1052 * hdc: Address of a HDC variable to store the dc to
1054 * Returns:
1055 * DD_OK on success
1056 * DDERR_INVALIDPARAMS if hdc is NULL
1057 * For details, see IWineD3DSurface::GetDC
1059 *****************************************************************************/
1060 static HRESULT WINAPI
1061 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
1062 HDC *hdc)
1064 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1065 HRESULT hr;
1066 TRACE("(%p)->(%p): Relay\n", This, hdc);
1068 if(!hdc)
1069 return DDERR_INVALIDPARAMS;
1071 EnterCriticalSection(&ddraw_cs);
1072 hr = IWineD3DSurface_GetDC(This->WineD3DSurface,
1073 hdc);
1074 LeaveCriticalSection(&ddraw_cs);
1075 return hr;
1078 /*****************************************************************************
1079 * IDirectDrawSurface7::ReleaseDC
1081 * Releases the DC that was constructed with GetDC
1083 * Params:
1084 * hdc: HDC to release
1086 * Returns:
1087 * DD_OK on success
1088 * For more details, see IWineD3DSurface::ReleaseDC
1090 *****************************************************************************/
1091 static HRESULT WINAPI
1092 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
1093 HDC hdc)
1095 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1096 HRESULT hr;
1097 TRACE("(%p)->(%p): Relay\n", This, hdc);
1099 EnterCriticalSection(&ddraw_cs);
1100 hr = IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
1101 LeaveCriticalSection(&ddraw_cs);
1102 return hr;
1105 /*****************************************************************************
1106 * IDirectDrawSurface7::GetCaps
1108 * Returns the surface's caps
1110 * Params:
1111 * Caps: Address to write the caps to
1113 * Returns:
1114 * DD_OK on success
1115 * DDERR_INVALIDPARAMS if Caps is NULL
1117 *****************************************************************************/
1118 static HRESULT WINAPI
1119 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
1120 DDSCAPS2 *Caps)
1122 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1123 TRACE("(%p)->(%p)\n",This,Caps);
1125 if(!Caps)
1126 return DDERR_INVALIDPARAMS;
1128 *Caps = This->surface_desc.ddsCaps;
1129 return DD_OK;
1132 /*****************************************************************************
1133 * IDirectDrawSurface7::SetPriority
1135 * Sets a texture priority for managed textures.
1137 * Params:
1138 * Priority: The new priority
1140 * Returns:
1141 * DD_OK on success
1142 * For more details, see IWineD3DSurface::SetPriority
1144 *****************************************************************************/
1145 static HRESULT WINAPI
1146 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
1148 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1149 HRESULT hr;
1150 TRACE("(%p)->(%d): Relay!\n",This,Priority);
1152 EnterCriticalSection(&ddraw_cs);
1153 hr = IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
1154 LeaveCriticalSection(&ddraw_cs);
1155 return hr;
1158 /*****************************************************************************
1159 * IDirectDrawSurface7::GetPriority
1161 * Returns the surface's priority
1163 * Params:
1164 * Priority: Address of a variable to write the priority to
1166 * Returns:
1167 * D3D_OK on success
1168 * DDERR_INVALIDPARAMS if Priority == NULL
1169 * For more details, see IWineD3DSurface::GetPriority
1171 *****************************************************************************/
1172 static HRESULT WINAPI
1173 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1174 DWORD *Priority)
1176 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1177 TRACE("(%p)->(%p): Relay\n",This,Priority);
1179 if(!Priority)
1181 return DDERR_INVALIDPARAMS;
1184 EnterCriticalSection(&ddraw_cs);
1185 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1186 LeaveCriticalSection(&ddraw_cs);
1187 return DD_OK;
1190 /*****************************************************************************
1191 * IDirectDrawSurface7::SetPrivateData
1193 * Stores some data in the surface that is intended for the application's
1194 * use.
1196 * Params:
1197 * tag: GUID that identifies the data
1198 * Data: Pointer to the private data
1199 * Size: Size of the private data
1200 * Flags: Some flags
1202 * Returns:
1203 * D3D_OK on success
1204 * For more details, see IWineD3DSurface::SetPrivateData
1206 *****************************************************************************/
1207 static HRESULT WINAPI
1208 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1209 REFGUID tag,
1210 void *Data,
1211 DWORD Size,
1212 DWORD Flags)
1214 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1215 HRESULT hr;
1216 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1218 EnterCriticalSection(&ddraw_cs);
1219 hr = IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1220 tag,
1221 Data,
1222 Size,
1223 Flags);
1224 LeaveCriticalSection(&ddraw_cs);
1225 switch(hr)
1227 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1228 default: return hr;
1232 /*****************************************************************************
1233 * IDirectDrawSurface7::GetPrivateData
1235 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1237 * Params:
1238 * tag: GUID of the data to return
1239 * Data: Address where to write the data to
1240 * Size: Size of the buffer at Data
1242 * Returns:
1243 * DD_OK on success
1244 * DDERR_INVALIDPARAMS if Data is NULL
1245 * For more details, see IWineD3DSurface::GetPrivateData
1247 *****************************************************************************/
1248 static HRESULT WINAPI
1249 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1250 REFGUID tag,
1251 void *Data,
1252 DWORD *Size)
1254 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1255 HRESULT hr;
1256 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1258 if(!Data)
1259 return DDERR_INVALIDPARAMS;
1261 EnterCriticalSection(&ddraw_cs);
1262 hr = IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1263 tag,
1264 Data,
1265 Size);
1266 LeaveCriticalSection(&ddraw_cs);
1267 return hr;
1270 /*****************************************************************************
1271 * IDirectDrawSurface7::FreePrivateData
1273 * Frees private data stored in the surface
1275 * Params:
1276 * tag: Tag of the data to free
1278 * Returns:
1279 * D3D_OK on success
1280 * For more details, see IWineD3DSurface::FreePrivateData
1282 *****************************************************************************/
1283 static HRESULT WINAPI
1284 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1285 REFGUID tag)
1287 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1288 HRESULT hr;
1289 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1291 EnterCriticalSection(&ddraw_cs);
1292 hr = IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1293 LeaveCriticalSection(&ddraw_cs);
1294 return hr;
1297 /*****************************************************************************
1298 * IDirectDrawSurface7::PageLock
1300 * Prevents a sysmem surface from being paged out
1302 * Params:
1303 * Flags: Not used, must be 0(unchecked)
1305 * Returns:
1306 * DD_OK, because it's a stub
1308 *****************************************************************************/
1309 static HRESULT WINAPI
1310 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1311 DWORD Flags)
1313 TRACE("(%p)->(%x)\n", iface, Flags);
1315 /* This is Windows memory management related - we don't need this */
1316 return DD_OK;
1319 /*****************************************************************************
1320 * IDirectDrawSurface7::PageUnlock
1322 * Allows a sysmem surface to be paged out
1324 * Params:
1325 * Flags: Not used, must be 0(unchecked)
1327 * Returns:
1328 * DD_OK, because it's a stub
1330 *****************************************************************************/
1331 static HRESULT WINAPI
1332 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1333 DWORD Flags)
1335 TRACE("(%p)->(%x)\n", iface, Flags);
1337 return DD_OK;
1340 /*****************************************************************************
1341 * IDirectDrawSurface7::BltBatch
1343 * An unimplemented function
1345 * Params:
1348 * Returns:
1349 * DDERR_UNSUPPORTED
1351 *****************************************************************************/
1352 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1354 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1356 /* MSDN: "not currently implemented" */
1357 return DDERR_UNSUPPORTED;
1360 /*****************************************************************************
1361 * IDirectDrawSurface7::EnumAttachedSurfaces
1363 * Enumerates all surfaces attached to this surface
1365 * Params:
1366 * context: Pointer to pass unmodified to the callback
1367 * cb: Callback function to call for each surface
1369 * Returns:
1370 * DD_OK on success
1371 * DDERR_INVALIDPARAMS if cb is NULL
1373 *****************************************************************************/
1374 static HRESULT WINAPI
1375 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1376 void *context,
1377 LPDDENUMSURFACESCALLBACK7 cb)
1379 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1380 IDirectDrawSurfaceImpl *surf;
1381 DDSURFACEDESC2 desc;
1382 int i;
1384 /* Attached surfaces aren't handled in WineD3D */
1385 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1387 if(!cb)
1388 return DDERR_INVALIDPARAMS;
1390 EnterCriticalSection(&ddraw_cs);
1391 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
1393 surf = This->complex_array[i];
1394 if(!surf) break;
1396 IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)surf);
1397 desc = surf->surface_desc;
1398 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1399 if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL)
1401 LeaveCriticalSection(&ddraw_cs);
1402 return DD_OK;
1406 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1408 IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)surf);
1409 desc = surf->surface_desc;
1410 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1411 if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL)
1413 LeaveCriticalSection(&ddraw_cs);
1414 return DD_OK;
1418 TRACE(" end of enumeration.\n");
1420 LeaveCriticalSection(&ddraw_cs);
1421 return DD_OK;
1424 /*****************************************************************************
1425 * IDirectDrawSurface7::EnumOverlayZOrders
1427 * "Enumerates the overlay surfaces on the specified destination"
1429 * Params:
1430 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1431 * context: context to pass back to the callback
1432 * cb: callback function to call for each enumerated surface
1434 * Returns:
1435 * DD_OK, because it's a stub
1437 *****************************************************************************/
1438 static HRESULT WINAPI
1439 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1440 DWORD Flags,
1441 void *context,
1442 LPDDENUMSURFACESCALLBACK7 cb)
1444 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1446 return DD_OK;
1449 /*****************************************************************************
1450 * IDirectDrawSurface7::GetBltStatus
1452 * Returns the blitting status
1454 * Params:
1455 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1457 * Returns:
1458 * See IWineD3DSurface::Blt
1460 *****************************************************************************/
1461 static HRESULT WINAPI
1462 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1463 DWORD Flags)
1465 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1466 HRESULT hr;
1467 TRACE("(%p)->(%x): Relay\n", This, Flags);
1469 EnterCriticalSection(&ddraw_cs);
1470 hr = IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1471 LeaveCriticalSection(&ddraw_cs);
1472 switch(hr)
1474 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1475 default: return hr;
1479 /*****************************************************************************
1480 * IDirectDrawSurface7::GetColorKey
1482 * Returns the color key assigned to the surface
1484 * Params:
1485 * Flags: Some flags
1486 * CKey: Address to store the key to
1488 * Returns:
1489 * DD_OK on success
1490 * DDERR_INVALIDPARAMS if CKey is NULL
1492 *****************************************************************************/
1493 static HRESULT WINAPI
1494 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1495 DWORD Flags,
1496 DDCOLORKEY *CKey)
1498 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1499 TRACE("(%p)->(%08x,%p)\n", This, Flags, CKey);
1501 if(!CKey)
1502 return DDERR_INVALIDPARAMS;
1504 EnterCriticalSection(&ddraw_cs);
1506 switch (Flags)
1508 case DDCKEY_DESTBLT:
1509 if (!(This->surface_desc.dwFlags & DDSD_CKDESTBLT))
1511 LeaveCriticalSection(&ddraw_cs);
1512 return DDERR_NOCOLORKEY;
1514 *CKey = This->surface_desc.ddckCKDestBlt;
1515 break;
1517 case DDCKEY_DESTOVERLAY:
1518 if (!(This->surface_desc.dwFlags & DDSD_CKDESTOVERLAY))
1520 LeaveCriticalSection(&ddraw_cs);
1521 return DDERR_NOCOLORKEY;
1523 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1524 break;
1526 case DDCKEY_SRCBLT:
1527 if (!(This->surface_desc.dwFlags & DDSD_CKSRCBLT))
1529 LeaveCriticalSection(&ddraw_cs);
1530 return DDERR_NOCOLORKEY;
1532 *CKey = This->surface_desc.ddckCKSrcBlt;
1533 break;
1535 case DDCKEY_SRCOVERLAY:
1536 if (!(This->surface_desc.dwFlags & DDSD_CKSRCOVERLAY))
1538 LeaveCriticalSection(&ddraw_cs);
1539 return DDERR_NOCOLORKEY;
1541 *CKey = This->surface_desc.ddckCKSrcOverlay;
1542 break;
1544 default:
1545 LeaveCriticalSection(&ddraw_cs);
1546 return DDERR_INVALIDPARAMS;
1549 LeaveCriticalSection(&ddraw_cs);
1550 return DD_OK;
1553 /*****************************************************************************
1554 * IDirectDrawSurface7::GetFlipStatus
1556 * Returns the flipping status of the surface
1558 * Params:
1559 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1561 * Returns:
1562 * See IWineD3DSurface::GetFlipStatus
1564 *****************************************************************************/
1565 static HRESULT WINAPI
1566 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1567 DWORD Flags)
1569 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1570 HRESULT hr;
1571 TRACE("(%p)->(%x): Relay\n", This, Flags);
1573 EnterCriticalSection(&ddraw_cs);
1574 hr = IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1575 LeaveCriticalSection(&ddraw_cs);
1576 switch(hr)
1578 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1579 default: return hr;
1583 /*****************************************************************************
1584 * IDirectDrawSurface7::GetOverlayPosition
1586 * Returns the display coordinates of a visible and active overlay surface
1588 * Params:
1592 * Returns:
1593 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1594 *****************************************************************************/
1595 static HRESULT WINAPI
1596 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1597 LONG *X,
1598 LONG *Y) {
1599 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1600 HRESULT hr;
1601 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1603 EnterCriticalSection(&ddraw_cs);
1604 hr = IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1607 LeaveCriticalSection(&ddraw_cs);
1608 return hr;
1611 /*****************************************************************************
1612 * IDirectDrawSurface7::GetPixelFormat
1614 * Returns the pixel format of the Surface
1616 * Params:
1617 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1618 * format should be written
1620 * Returns:
1621 * DD_OK on success
1622 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1624 *****************************************************************************/
1625 static HRESULT WINAPI
1626 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1627 DDPIXELFORMAT *PixelFormat)
1629 /* What is DDERR_INVALIDSURFACETYPE for here? */
1630 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1631 TRACE("(%p)->(%p)\n",This,PixelFormat);
1633 if(!PixelFormat)
1634 return DDERR_INVALIDPARAMS;
1636 EnterCriticalSection(&ddraw_cs);
1637 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1638 LeaveCriticalSection(&ddraw_cs);
1640 return DD_OK;
1644 /*****************************************************************************
1645 * IDirectDrawSurface7::GetSurfaceDesc
1647 * Returns the description of this surface
1649 * Params:
1650 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1651 * surface desc
1653 * Returns:
1654 * DD_OK on success
1655 * DDERR_INVALIDPARAMS if DDSD is NULL
1657 *****************************************************************************/
1658 static HRESULT WINAPI
1659 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1660 DDSURFACEDESC2 *DDSD)
1662 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1664 TRACE("(%p)->(%p)\n",This,DDSD);
1666 if(!DDSD)
1667 return DDERR_INVALIDPARAMS;
1669 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
1671 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
1672 return DDERR_INVALIDPARAMS;
1675 EnterCriticalSection(&ddraw_cs);
1676 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1677 TRACE("Returning surface desc:\n");
1678 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1680 LeaveCriticalSection(&ddraw_cs);
1681 return DD_OK;
1684 /*****************************************************************************
1685 * IDirectDrawSurface7::Initialize
1687 * Initializes the surface. This is a no-op in Wine
1689 * Params:
1690 * DD: Pointer to an DirectDraw interface
1691 * DDSD: Surface description for initialization
1693 * Returns:
1694 * DDERR_ALREADYINITIALIZED
1696 *****************************************************************************/
1697 static HRESULT WINAPI
1698 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1699 IDirectDraw *DD,
1700 DDSURFACEDESC2 *DDSD)
1702 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1703 IDirectDrawImpl *ddimpl = DD ? ddraw_from_ddraw1(DD) : NULL;
1704 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1706 return DDERR_ALREADYINITIALIZED;
1709 /*****************************************************************************
1710 * IDirectDrawSurface7::IsLost
1712 * Checks if the surface is lost
1714 * Returns:
1715 * DD_OK, if the surface is usable
1716 * DDERR_ISLOST if the surface is lost
1717 * See IWineD3DSurface::IsLost for more details
1719 *****************************************************************************/
1720 static HRESULT WINAPI
1721 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1723 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1724 HRESULT hr;
1725 TRACE("(%p)\n", This);
1727 EnterCriticalSection(&ddraw_cs);
1728 /* We lose the surface if the implementation was changed */
1729 if(This->ImplType != This->ddraw->ImplType)
1731 /* But this shouldn't happen. When we change the implementation,
1732 * all surfaces are re-created automatically, and their content
1733 * is copied
1735 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1736 LeaveCriticalSection(&ddraw_cs);
1737 return DDERR_SURFACELOST;
1740 hr = IWineD3DSurface_IsLost(This->WineD3DSurface);
1741 LeaveCriticalSection(&ddraw_cs);
1742 switch(hr)
1744 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1745 * WineD3D uses the same error for surfaces
1747 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
1748 default: return hr;
1752 /*****************************************************************************
1753 * IDirectDrawSurface7::Restore
1755 * Restores a lost surface. This makes the surface usable again, but
1756 * doesn't reload its old contents
1758 * Returns:
1759 * DD_OK on success
1760 * See IWineD3DSurface::Restore for more details
1762 *****************************************************************************/
1763 static HRESULT WINAPI
1764 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1766 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1767 HRESULT hr;
1768 TRACE("(%p)\n", This);
1770 EnterCriticalSection(&ddraw_cs);
1771 if(This->ImplType != This->ddraw->ImplType)
1773 /* Call the recreation callback. Make sure to AddRef first */
1774 IDirectDrawSurface_AddRef(iface);
1775 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1776 &This->surface_desc,
1777 NULL /* Not needed */);
1779 hr = IWineD3DSurface_Restore(This->WineD3DSurface);
1780 LeaveCriticalSection(&ddraw_cs);
1781 return hr;
1784 /*****************************************************************************
1785 * IDirectDrawSurface7::SetOverlayPosition
1787 * Changes the display coordinates of an overlay surface
1789 * Params:
1790 * X:
1791 * Y:
1793 * Returns:
1794 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1795 *****************************************************************************/
1796 static HRESULT WINAPI
1797 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1798 LONG X,
1799 LONG Y)
1801 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1802 HRESULT hr;
1803 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1805 EnterCriticalSection(&ddraw_cs);
1806 hr = IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1809 LeaveCriticalSection(&ddraw_cs);
1810 return hr;
1813 /*****************************************************************************
1814 * IDirectDrawSurface7::UpdateOverlay
1816 * Modifies the attributes of an overlay surface.
1818 * Params:
1819 * SrcRect: The section of the source being used for the overlay
1820 * DstSurface: Address of the surface that is overlaid
1821 * DstRect: Place of the overlay
1822 * Flags: some DDOVER_* flags
1824 * Returns:
1825 * DDERR_UNSUPPORTED, because we don't support overlays
1827 *****************************************************************************/
1828 static HRESULT WINAPI
1829 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1830 LPRECT SrcRect,
1831 IDirectDrawSurface7 *DstSurface,
1832 LPRECT DstRect,
1833 DWORD Flags,
1834 LPDDOVERLAYFX FX)
1836 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1837 IDirectDrawSurfaceImpl *Dst = (IDirectDrawSurfaceImpl *)DstSurface;
1838 HRESULT hr;
1839 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1841 EnterCriticalSection(&ddraw_cs);
1842 hr = IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1843 SrcRect,
1844 Dst ? Dst->WineD3DSurface : NULL,
1845 DstRect,
1846 Flags,
1847 (WINEDDOVERLAYFX *) FX);
1848 LeaveCriticalSection(&ddraw_cs);
1849 switch(hr) {
1850 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1851 case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE;
1852 case WINEDDERR_OVERLAYNOTVISIBLE: return DDERR_OVERLAYNOTVISIBLE;
1853 default:
1854 return hr;
1858 /*****************************************************************************
1859 * IDirectDrawSurface7::UpdateOverlayDisplay
1861 * The DX7 sdk says that it's not implemented
1863 * Params:
1864 * Flags: ?
1866 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1868 *****************************************************************************/
1869 static HRESULT WINAPI
1870 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1871 DWORD Flags)
1873 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1874 TRACE("(%p)->(%x)\n", This, Flags);
1875 return DDERR_UNSUPPORTED;
1878 /*****************************************************************************
1879 * IDirectDrawSurface7::UpdateOverlayZOrder
1881 * Sets an overlay's Z order
1883 * Params:
1884 * Flags: DDOVERZ_* flags
1885 * DDSRef: Defines the relative position in the overlay chain
1887 * Returns:
1888 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1890 *****************************************************************************/
1891 static HRESULT WINAPI
1892 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1893 DWORD Flags,
1894 IDirectDrawSurface7 *DDSRef)
1896 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1897 IDirectDrawSurfaceImpl *Ref = (IDirectDrawSurfaceImpl *)DDSRef;
1898 HRESULT hr;
1900 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1901 EnterCriticalSection(&ddraw_cs);
1902 hr = IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1903 Flags,
1904 Ref ? Ref->WineD3DSurface : NULL);
1905 LeaveCriticalSection(&ddraw_cs);
1906 return hr;
1909 /*****************************************************************************
1910 * IDirectDrawSurface7::GetDDInterface
1912 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1913 * surface belongs to
1915 * Params:
1916 * DD: Address to write the interface pointer to
1918 * Returns:
1919 * DD_OK on success
1920 * DDERR_INVALIDPARAMS if DD is NULL
1922 *****************************************************************************/
1923 static HRESULT WINAPI
1924 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1925 void **DD)
1927 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1929 TRACE("(%p)->(%p)\n",This,DD);
1931 if(!DD)
1932 return DDERR_INVALIDPARAMS;
1934 switch(This->version)
1936 case 7:
1937 *DD = This->ddraw;
1938 break;
1940 case 4:
1941 *DD = &This->ddraw->IDirectDraw4_vtbl;
1942 break;
1944 case 2:
1945 *DD = &This->ddraw->IDirectDraw2_vtbl;
1946 break;
1948 case 1:
1949 *DD = &This->ddraw->IDirectDraw_vtbl;
1950 break;
1953 IUnknown_AddRef((IUnknown *)*DD);
1955 return DD_OK;
1958 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1959 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1961 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1962 volatile IDirectDrawSurfaceImpl* vThis = This;
1964 TRACE("(%p)\n",This);
1965 EnterCriticalSection(&ddraw_cs);
1966 /* A uniqueness value of 0 is apparently special.
1967 * This needs to be checked.
1968 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1970 while (1) {
1971 DWORD old_uniqueness_value = vThis->uniqueness_value;
1972 DWORD new_uniqueness_value = old_uniqueness_value+1;
1974 if (old_uniqueness_value == 0) break;
1975 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1977 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1978 old_uniqueness_value,
1979 new_uniqueness_value)
1980 == old_uniqueness_value)
1981 break;
1984 LeaveCriticalSection(&ddraw_cs);
1985 return DD_OK;
1988 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1990 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1992 TRACE("(%p)->(%p)\n",This,pValue);
1993 EnterCriticalSection(&ddraw_cs);
1994 *pValue = This->uniqueness_value;
1995 LeaveCriticalSection(&ddraw_cs);
1996 return DD_OK;
1999 /*****************************************************************************
2000 * IDirectDrawSurface7::SetLOD
2002 * Sets the level of detail of a texture
2004 * Params:
2005 * MaxLOD: LOD to set
2007 * Returns:
2008 * DD_OK on success
2009 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2011 *****************************************************************************/
2012 static HRESULT WINAPI
2013 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
2014 DWORD MaxLOD)
2016 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2017 HRESULT hr;
2018 TRACE("(%p)->(%d)\n", This, MaxLOD);
2020 EnterCriticalSection(&ddraw_cs);
2021 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2023 LeaveCriticalSection(&ddraw_cs);
2024 return DDERR_INVALIDOBJECT;
2027 if(!This->wineD3DTexture)
2029 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
2030 LeaveCriticalSection(&ddraw_cs);
2031 return DDERR_INVALIDOBJECT;
2034 hr = IWineD3DBaseTexture_SetLOD(This->wineD3DTexture,
2035 MaxLOD);
2036 LeaveCriticalSection(&ddraw_cs);
2037 return hr;
2040 /*****************************************************************************
2041 * IDirectDrawSurface7::GetLOD
2043 * Returns the level of detail of a Direct3D texture
2045 * Params:
2046 * MaxLOD: Address to write the LOD to
2048 * Returns:
2049 * DD_OK on success
2050 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2051 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2053 *****************************************************************************/
2054 static HRESULT WINAPI
2055 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
2056 DWORD *MaxLOD)
2058 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2059 TRACE("(%p)->(%p)\n", This, MaxLOD);
2061 if(!MaxLOD)
2062 return DDERR_INVALIDPARAMS;
2064 EnterCriticalSection(&ddraw_cs);
2065 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2067 LeaveCriticalSection(&ddraw_cs);
2068 return DDERR_INVALIDOBJECT;
2071 *MaxLOD = IWineD3DBaseTexture_GetLOD(This->wineD3DTexture);
2072 LeaveCriticalSection(&ddraw_cs);
2073 return DD_OK;
2076 /*****************************************************************************
2077 * IDirectDrawSurface7::BltFast
2079 * Performs a fast Blit.
2081 * Params:
2082 * dstx: The x coordinate to blit to on the destination
2083 * dsty: The y coordinate to blit to on the destination
2084 * Source: The source surface
2085 * rsrc: The source rectangle
2086 * trans: Type of transfer. Some DDBLTFAST_* flags
2088 * Returns:
2089 * DD_OK on success
2090 * For more details, see IWineD3DSurface::BltFast
2092 *****************************************************************************/
2093 static HRESULT WINAPI
2094 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
2095 DWORD dstx,
2096 DWORD dsty,
2097 IDirectDrawSurface7 *Source,
2098 RECT *rsrc,
2099 DWORD trans)
2101 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2102 IDirectDrawSurfaceImpl *src = (IDirectDrawSurfaceImpl *)Source;
2103 HRESULT hr;
2104 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
2106 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2107 * in that case
2109 if(rsrc)
2111 if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right ||
2112 rsrc->right > src->surface_desc.dwWidth ||
2113 rsrc->bottom > src->surface_desc.dwHeight)
2115 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2116 return DDERR_INVALIDRECT;
2118 if(dstx + rsrc->right - rsrc->left > This->surface_desc.dwWidth ||
2119 dsty + rsrc->bottom - rsrc->top > This->surface_desc.dwHeight)
2121 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2122 return DDERR_INVALIDRECT;
2125 else
2127 if(dstx + src->surface_desc.dwWidth > This->surface_desc.dwWidth ||
2128 dsty + src->surface_desc.dwHeight > This->surface_desc.dwHeight)
2130 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2131 return DDERR_INVALIDRECT;
2135 EnterCriticalSection(&ddraw_cs);
2136 hr = IWineD3DSurface_BltFast(This->WineD3DSurface,
2137 dstx, dsty,
2138 src ? src->WineD3DSurface : NULL,
2139 rsrc,
2140 trans);
2141 LeaveCriticalSection(&ddraw_cs);
2142 switch(hr)
2144 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
2145 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
2146 default: return hr;
2150 /*****************************************************************************
2151 * IDirectDrawSurface7::GetClipper
2153 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2154 * surface
2156 * Params:
2157 * Clipper: Address to store the interface pointer at
2159 * Returns:
2160 * DD_OK on success
2161 * DDERR_INVALIDPARAMS if Clipper is NULL
2162 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2164 *****************************************************************************/
2165 static HRESULT WINAPI
2166 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
2167 IDirectDrawClipper **Clipper)
2169 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2170 TRACE("(%p)->(%p)\n", This, Clipper);
2172 if(!Clipper)
2174 LeaveCriticalSection(&ddraw_cs);
2175 return DDERR_INVALIDPARAMS;
2178 EnterCriticalSection(&ddraw_cs);
2179 if(This->clipper == NULL)
2181 LeaveCriticalSection(&ddraw_cs);
2182 return DDERR_NOCLIPPERATTACHED;
2185 *Clipper = (IDirectDrawClipper *)This->clipper;
2186 IDirectDrawClipper_AddRef(*Clipper);
2187 LeaveCriticalSection(&ddraw_cs);
2188 return DD_OK;
2191 /*****************************************************************************
2192 * IDirectDrawSurface7::SetClipper
2194 * Sets a clipper for the surface
2196 * Params:
2197 * Clipper: IDirectDrawClipper interface of the clipper to set
2199 * Returns:
2200 * DD_OK on success
2202 *****************************************************************************/
2203 static HRESULT WINAPI
2204 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
2205 IDirectDrawClipper *Clipper)
2207 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2208 IDirectDrawClipperImpl *oldClipper = This->clipper;
2209 HWND clipWindow;
2210 HRESULT hr;
2211 TRACE("(%p)->(%p)\n",This,Clipper);
2213 EnterCriticalSection(&ddraw_cs);
2214 if ((IDirectDrawClipperImpl *)Clipper == This->clipper)
2216 LeaveCriticalSection(&ddraw_cs);
2217 return DD_OK;
2220 This->clipper = (IDirectDrawClipperImpl *)Clipper;
2222 if (Clipper != NULL)
2223 IDirectDrawClipper_AddRef(Clipper);
2224 if(oldClipper)
2225 IDirectDrawClipper_Release((IDirectDrawClipper *)oldClipper);
2227 hr = IWineD3DSurface_SetClipper(This->WineD3DSurface, This->clipper ? This->clipper->wineD3DClipper : NULL);
2229 if(This->wineD3DSwapChain) {
2230 clipWindow = NULL;
2231 if(Clipper) {
2232 IDirectDrawClipper_GetHWnd(Clipper, &clipWindow);
2235 if(clipWindow) {
2236 IWineD3DSwapChain_SetDestWindowOverride(This->wineD3DSwapChain,
2237 clipWindow);
2238 } else {
2239 IWineD3DSwapChain_SetDestWindowOverride(This->wineD3DSwapChain,
2240 This->ddraw->d3d_window);
2244 LeaveCriticalSection(&ddraw_cs);
2245 return hr;
2248 /*****************************************************************************
2249 * IDirectDrawSurface7::SetSurfaceDesc
2251 * Sets the surface description. It can override the pixel format, the surface
2252 * memory, ...
2253 * It's not really tested.
2255 * Params:
2256 * DDSD: Pointer to the new surface description to set
2257 * Flags: Some flags
2259 * Returns:
2260 * DD_OK on success
2261 * DDERR_INVALIDPARAMS if DDSD is NULL
2263 *****************************************************************************/
2264 static HRESULT WINAPI
2265 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
2266 DDSURFACEDESC2 *DDSD,
2267 DWORD Flags)
2269 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2270 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
2271 HRESULT hr;
2272 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
2274 if(!DDSD)
2275 return DDERR_INVALIDPARAMS;
2277 EnterCriticalSection(&ddraw_cs);
2278 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
2280 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
2282 if(newFormat == WINED3DFMT_UNKNOWN)
2284 ERR("Requested to set an unknown pixelformat\n");
2285 LeaveCriticalSection(&ddraw_cs);
2286 return DDERR_INVALIDPARAMS;
2288 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
2290 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
2291 newFormat);
2292 if(hr != DD_OK)
2294 LeaveCriticalSection(&ddraw_cs);
2295 return hr;
2299 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
2301 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2302 DDCKEY_DESTOVERLAY,
2303 (WINEDDCOLORKEY *) &DDSD->u3.ddckCKDestOverlay);
2305 if (DDSD->dwFlags & DDSD_CKDESTBLT)
2307 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2308 DDCKEY_DESTBLT,
2309 (WINEDDCOLORKEY *) &DDSD->ddckCKDestBlt);
2311 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
2313 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2314 DDCKEY_SRCOVERLAY,
2315 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcOverlay);
2317 if (DDSD->dwFlags & DDSD_CKSRCBLT)
2319 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2320 DDCKEY_SRCBLT,
2321 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcBlt);
2323 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
2325 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
2326 if(hr != WINED3D_OK)
2328 /* No need for a trace here, wined3d does that for us */
2329 switch(hr)
2331 case WINED3DERR_INVALIDCALL:
2332 LeaveCriticalSection(&ddraw_cs);
2333 return DDERR_INVALIDPARAMS;
2334 default:
2335 break; /* Go on */
2340 This->surface_desc = *DDSD;
2342 LeaveCriticalSection(&ddraw_cs);
2343 return DD_OK;
2346 /*****************************************************************************
2347 * IDirectDrawSurface7::GetPalette
2349 * Returns the IDirectDrawPalette interface of the palette currently assigned
2350 * to the surface
2352 * Params:
2353 * Pal: Address to write the interface pointer to
2355 * Returns:
2356 * DD_OK on success
2357 * DDERR_INVALIDPARAMS if Pal is NULL
2359 *****************************************************************************/
2360 static HRESULT WINAPI
2361 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
2362 IDirectDrawPalette **Pal)
2364 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2365 IWineD3DPalette *wPal;
2366 HRESULT hr;
2367 TRACE("(%p)->(%p): Relay\n", This, Pal);
2369 if(!Pal)
2370 return DDERR_INVALIDPARAMS;
2372 EnterCriticalSection(&ddraw_cs);
2373 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
2374 if(hr != DD_OK)
2376 LeaveCriticalSection(&ddraw_cs);
2377 return hr;
2380 if(wPal)
2382 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2384 else
2386 *Pal = NULL;
2387 hr = DDERR_NOPALETTEATTACHED;
2390 LeaveCriticalSection(&ddraw_cs);
2391 return hr;
2394 /*****************************************************************************
2395 * SetColorKeyEnum
2397 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2398 * recursively in the surface tree
2400 *****************************************************************************/
2401 struct SCKContext
2403 HRESULT ret;
2404 WINEDDCOLORKEY *CKey;
2405 DWORD Flags;
2408 static HRESULT WINAPI
2409 SetColorKeyEnum(IDirectDrawSurface7 *surface,
2410 DDSURFACEDESC2 *desc,
2411 void *context)
2413 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)surface;
2414 struct SCKContext *ctx = context;
2415 HRESULT hr;
2417 hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2418 ctx->Flags,
2419 ctx->CKey);
2420 if(hr != DD_OK)
2422 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
2423 ctx->ret = hr;
2426 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
2427 context,
2428 SetColorKeyEnum);
2429 IDirectDrawSurface7_Release(surface);
2430 return DDENUMRET_OK;
2433 /*****************************************************************************
2434 * IDirectDrawSurface7::SetColorKey
2436 * Sets the color keying options for the surface. Observations showed that
2437 * in case of complex surfaces the color key has to be assigned to all
2438 * sublevels.
2440 * Params:
2441 * Flags: DDCKEY_*
2442 * CKey: The new color key
2444 * Returns:
2445 * DD_OK on success
2446 * See IWineD3DSurface::SetColorKey for details
2448 *****************************************************************************/
2449 static HRESULT WINAPI
2450 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2451 DWORD Flags,
2452 DDCOLORKEY *CKey)
2454 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2455 struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) CKey, Flags };
2456 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2458 EnterCriticalSection(&ddraw_cs);
2459 if (CKey)
2461 switch (Flags & ~DDCKEY_COLORSPACE)
2463 case DDCKEY_DESTBLT:
2464 This->surface_desc.ddckCKDestBlt = *CKey;
2465 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
2466 break;
2468 case DDCKEY_DESTOVERLAY:
2469 This->surface_desc.u3.ddckCKDestOverlay = *CKey;
2470 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
2471 break;
2473 case DDCKEY_SRCOVERLAY:
2474 This->surface_desc.ddckCKSrcOverlay = *CKey;
2475 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
2476 break;
2478 case DDCKEY_SRCBLT:
2479 This->surface_desc.ddckCKSrcBlt = *CKey;
2480 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
2481 break;
2483 default:
2484 LeaveCriticalSection(&ddraw_cs);
2485 return DDERR_INVALIDPARAMS;
2488 else
2490 switch (Flags & ~DDCKEY_COLORSPACE)
2492 case DDCKEY_DESTBLT:
2493 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
2494 break;
2496 case DDCKEY_DESTOVERLAY:
2497 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
2498 break;
2500 case DDCKEY_SRCOVERLAY:
2501 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
2502 break;
2504 case DDCKEY_SRCBLT:
2505 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
2506 break;
2508 default:
2509 LeaveCriticalSection(&ddraw_cs);
2510 return DDERR_INVALIDPARAMS;
2513 ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2514 Flags,
2515 ctx.CKey);
2516 IDirectDrawSurface7_EnumAttachedSurfaces(iface,
2517 &ctx,
2518 SetColorKeyEnum);
2519 LeaveCriticalSection(&ddraw_cs);
2520 switch(ctx.ret)
2522 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2523 default: return ctx.ret;
2527 /*****************************************************************************
2528 * IDirectDrawSurface7::SetPalette
2530 * Assigns a DirectDrawPalette object to the surface
2532 * Params:
2533 * Pal: Interface to the palette to set
2535 * Returns:
2536 * DD_OK on success
2538 *****************************************************************************/
2539 static HRESULT WINAPI
2540 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2541 IDirectDrawPalette *Pal)
2543 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2544 IDirectDrawPalette *oldPal;
2545 IDirectDrawSurfaceImpl *surf;
2546 IDirectDrawPaletteImpl *PalImpl = (IDirectDrawPaletteImpl *)Pal;
2547 HRESULT hr;
2548 TRACE("(%p)->(%p)\n", This, Pal);
2550 if (!(This->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 |
2551 DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8))) {
2552 return DDERR_INVALIDPIXELFORMAT;
2555 /* Find the old palette */
2556 EnterCriticalSection(&ddraw_cs);
2557 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2558 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
2560 LeaveCriticalSection(&ddraw_cs);
2561 return hr;
2563 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2565 /* Set the new Palette */
2566 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2567 PalImpl ? PalImpl->wineD3DPalette : NULL);
2568 /* AddRef the Palette */
2569 if(Pal) IDirectDrawPalette_AddRef(Pal);
2571 /* Release the old palette */
2572 if(oldPal) IDirectDrawPalette_Release(oldPal);
2574 /* If this is a front buffer, also update the back buffers
2575 * TODO: How do things work for palettized cube textures?
2577 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2579 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2580 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
2582 surf = This;
2583 while(1)
2585 IDirectDrawSurface7 *attach;
2586 HRESULT hr;
2587 hr = IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)surf, &caps2, &attach);
2588 if(hr != DD_OK)
2590 break;
2593 TRACE("Setting palette on %p\n", attach);
2594 IDirectDrawSurface7_SetPalette(attach,
2595 Pal);
2596 surf = (IDirectDrawSurfaceImpl *)attach;
2597 IDirectDrawSurface7_Release(attach);
2601 LeaveCriticalSection(&ddraw_cs);
2602 return DD_OK;
2605 /*****************************************************************************
2606 * The VTable
2607 *****************************************************************************/
2609 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2611 /*** IUnknown ***/
2612 IDirectDrawSurfaceImpl_QueryInterface,
2613 IDirectDrawSurfaceImpl_AddRef,
2614 IDirectDrawSurfaceImpl_Release,
2615 /*** IDirectDrawSurface ***/
2616 IDirectDrawSurface7Impl_AddAttachedSurface,
2617 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2618 IDirectDrawSurfaceImpl_Blt,
2619 IDirectDrawSurfaceImpl_BltBatch,
2620 IDirectDrawSurfaceImpl_BltFast,
2621 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2622 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2623 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2624 IDirectDrawSurfaceImpl_Flip,
2625 IDirectDrawSurfaceImpl_GetAttachedSurface,
2626 IDirectDrawSurfaceImpl_GetBltStatus,
2627 IDirectDrawSurfaceImpl_GetCaps,
2628 IDirectDrawSurfaceImpl_GetClipper,
2629 IDirectDrawSurfaceImpl_GetColorKey,
2630 IDirectDrawSurfaceImpl_GetDC,
2631 IDirectDrawSurfaceImpl_GetFlipStatus,
2632 IDirectDrawSurfaceImpl_GetOverlayPosition,
2633 IDirectDrawSurfaceImpl_GetPalette,
2634 IDirectDrawSurfaceImpl_GetPixelFormat,
2635 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2636 IDirectDrawSurfaceImpl_Initialize,
2637 IDirectDrawSurfaceImpl_IsLost,
2638 IDirectDrawSurfaceImpl_Lock,
2639 IDirectDrawSurfaceImpl_ReleaseDC,
2640 IDirectDrawSurfaceImpl_Restore,
2641 IDirectDrawSurfaceImpl_SetClipper,
2642 IDirectDrawSurfaceImpl_SetColorKey,
2643 IDirectDrawSurfaceImpl_SetOverlayPosition,
2644 IDirectDrawSurfaceImpl_SetPalette,
2645 IDirectDrawSurfaceImpl_Unlock,
2646 IDirectDrawSurfaceImpl_UpdateOverlay,
2647 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2648 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2649 /*** IDirectDrawSurface2 ***/
2650 IDirectDrawSurfaceImpl_GetDDInterface,
2651 IDirectDrawSurfaceImpl_PageLock,
2652 IDirectDrawSurfaceImpl_PageUnlock,
2653 /*** IDirectDrawSurface3 ***/
2654 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2655 /*** IDirectDrawSurface4 ***/
2656 IDirectDrawSurfaceImpl_SetPrivateData,
2657 IDirectDrawSurfaceImpl_GetPrivateData,
2658 IDirectDrawSurfaceImpl_FreePrivateData,
2659 IDirectDrawSurfaceImpl_GetUniquenessValue,
2660 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2661 /*** IDirectDrawSurface7 ***/
2662 IDirectDrawSurfaceImpl_SetPriority,
2663 IDirectDrawSurfaceImpl_GetPriority,
2664 IDirectDrawSurfaceImpl_SetLOD,
2665 IDirectDrawSurfaceImpl_GetLOD