user32: Properly handle integer atoms specified as strings in class names.
[wine/multimedia.git] / dlls / ddraw / surface.c
blob646ea1acb62089031a792b4eb2bb914ee2d26087
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 implicitely 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);
543 return DDERR_NOTFOUND;
546 /*****************************************************************************
547 * IDirectDrawSurface7::Lock
549 * Locks the surface and returns a pointer to the surface's memory
551 * Params:
552 * Rect: Rectangle to lock. If NULL, the whole surface is locked
553 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
554 * Flags: Locking flags, e.g Read only or write only
555 * h: An event handle that's not used and must be NULL
557 * Returns:
558 * DD_OK on success
559 * DDERR_INVALIDPARAMS if DDSD is NULL
560 * For more details, see IWineD3DSurface::LockRect
562 *****************************************************************************/
563 static HRESULT WINAPI
564 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
565 RECT *Rect,
566 DDSURFACEDESC2 *DDSD,
567 DWORD Flags,
568 HANDLE h)
570 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
571 WINED3DLOCKED_RECT LockedRect;
572 HRESULT hr;
573 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
575 if(!DDSD)
576 return DDERR_INVALIDPARAMS;
578 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
579 EnterCriticalSection(&ddraw_cs);
580 if (Rect)
582 if ((Rect->left < 0)
583 || (Rect->top < 0)
584 || (Rect->left > Rect->right)
585 || (Rect->top > Rect->bottom)
586 || (Rect->right > This->surface_desc.dwWidth)
587 || (Rect->bottom > This->surface_desc.dwHeight))
589 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
590 LeaveCriticalSection(&ddraw_cs);
591 return DDERR_INVALIDPARAMS;
595 /* Should I check for the handle to be NULL?
597 * The DDLOCK flags and the D3DLOCK flags are equal
598 * for the supported values. The others are ignored by WineD3D
601 if(DDSD->dwSize != sizeof(DDSURFACEDESC) &&
602 DDSD->dwSize != sizeof(DDSURFACEDESC2))
604 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS);
605 LeaveCriticalSection(&ddraw_cs);
606 return DDERR_INVALIDPARAMS;
609 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
610 &LockedRect,
611 Rect,
612 Flags);
613 if(hr != D3D_OK)
615 LeaveCriticalSection(&ddraw_cs);
616 switch(hr)
618 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
619 * specific error. But since IWineD3DSurface::LockRect returns that error in this
620 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
621 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
622 * is much easier to do it in one place in ddraw
624 case WINED3DERR_INVALIDCALL: return DDERR_SURFACEBUSY;
625 default: return hr;
629 /* Override the memory area. The pitch should be set already. Strangely windows
630 * does not set the LPSURFACE flag on locked surfaces !?!.
631 * DDSD->dwFlags |= DDSD_LPSURFACE;
633 This->surface_desc.lpSurface = LockedRect.pBits;
634 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
636 TRACE("locked surface returning description :\n");
637 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
639 LeaveCriticalSection(&ddraw_cs);
640 return DD_OK;
643 /*****************************************************************************
644 * IDirectDrawSurface7::Unlock
646 * Unlocks an locked surface
648 * Params:
649 * Rect: Not used by this implementation
651 * Returns:
652 * D3D_OK on success
653 * For more details, see IWineD3DSurface::UnlockRect
655 *****************************************************************************/
656 static HRESULT WINAPI
657 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
658 RECT *pRect)
660 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
661 HRESULT hr;
662 TRACE("(%p)->(%p)\n", This, pRect);
664 EnterCriticalSection(&ddraw_cs);
665 hr = IWineD3DSurface_UnlockRect(This->WineD3DSurface);
666 if(SUCCEEDED(hr))
668 This->surface_desc.lpSurface = NULL;
670 LeaveCriticalSection(&ddraw_cs);
671 return hr;
674 /*****************************************************************************
675 * IDirectDrawSurface7::Flip
677 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
678 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
679 * the flip target is passed to WineD3D, even if the app didn't specify one
681 * Params:
682 * DestOverride: Specifies the surface that will become the new front
683 * buffer. If NULL, the current back buffer is used
684 * Flags: some DirectDraw flags, see include/ddraw.h
686 * Returns:
687 * DD_OK on success
688 * DDERR_NOTFLIPPABLE if no flip target could be found
689 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
690 * For more details, see IWineD3DSurface::Flip
692 *****************************************************************************/
693 static HRESULT WINAPI
694 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
695 IDirectDrawSurface7 *DestOverride,
696 DWORD Flags)
698 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
699 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
700 IDirectDrawSurface7 *Override7;
701 HRESULT hr;
702 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
704 /* Flip has to be called from a front buffer
705 * What about overlay surfaces, AFAIK they can flip too?
707 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
708 return DDERR_INVALIDOBJECT; /* Unckecked */
710 EnterCriticalSection(&ddraw_cs);
712 /* WineD3D doesn't keep track of attached surface, so find the target */
713 if(!Override)
715 DDSCAPS2 Caps;
717 memset(&Caps, 0, sizeof(Caps));
718 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
719 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
720 if(hr != DD_OK)
722 ERR("Can't find a flip target\n");
723 LeaveCriticalSection(&ddraw_cs);
724 return DDERR_NOTFLIPPABLE; /* Unchecked */
726 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
728 /* For the GetAttachedSurface */
729 IDirectDrawSurface7_Release(Override7);
732 hr = IWineD3DSurface_Flip(This->WineD3DSurface,
733 Override->WineD3DSurface,
734 Flags);
735 LeaveCriticalSection(&ddraw_cs);
736 return hr;
739 /*****************************************************************************
740 * IDirectDrawSurface7::Blt
742 * Performs a blit on the surface
744 * Params:
745 * DestRect: Destination rectangle, can be NULL
746 * SrcSurface: Source surface, can be NULL
747 * SrcRect: Source rectange, can be NULL
748 * Flags: Blt flags
749 * DDBltFx: Some extended blt parameters, connected to the flags
751 * Returns:
752 * D3D_OK on success
753 * See IWineD3DSurface::Blt for more details
755 *****************************************************************************/
756 static HRESULT WINAPI
757 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
758 RECT *DestRect,
759 IDirectDrawSurface7 *SrcSurface,
760 RECT *SrcRect,
761 DWORD Flags,
762 DDBLTFX *DDBltFx)
764 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
765 HRESULT hr;
766 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
767 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
769 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
770 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
772 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
773 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
774 return DDERR_INVALIDPARAMS;
777 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
778 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
779 return DDERR_INVALIDPARAMS;
782 /* Sizes can change, therefore hold the lock when testing the rectangles */
783 EnterCriticalSection(&ddraw_cs);
784 if(DestRect)
786 if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right ||
787 DestRect->right > This->surface_desc.dwWidth ||
788 DestRect->bottom > This->surface_desc.dwHeight)
790 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
791 LeaveCriticalSection(&ddraw_cs);
792 return DDERR_INVALIDRECT;
795 if(Src && SrcRect)
797 if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right ||
798 SrcRect->right > Src->surface_desc.dwWidth ||
799 SrcRect->bottom > Src->surface_desc.dwHeight)
801 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
802 LeaveCriticalSection(&ddraw_cs);
803 return DDERR_INVALIDRECT;
807 if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
808 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
809 LeaveCriticalSection(&ddraw_cs);
810 return DDERR_INVALIDPARAMS;
813 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
814 * and replace the ddraw surfaces with the wined3d surfaces
815 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
817 hr = IWineD3DSurface_Blt(This->WineD3DSurface,
818 DestRect,
819 Src ? Src->WineD3DSurface : NULL,
820 SrcRect,
821 Flags,
822 (WINEDDBLTFX *) DDBltFx,
823 WINED3DTEXF_POINT);
825 LeaveCriticalSection(&ddraw_cs);
826 switch(hr)
828 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
829 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
830 default: return hr;
834 /*****************************************************************************
835 * IDirectDrawSurface7::AddAttachedSurface
837 * Attaches a surface to another surface. How the surface attachments work
838 * is not totally understood yet, and this method is prone to problems.
839 * he surface that is attached is AddRef-ed.
841 * Tests with complex surfaces suggest that the surface attachments form a
842 * tree, but no method to test this has been found yet.
844 * The attachment list consists of a first surface (first_attached) and
845 * for each surface a pointer to the next attached surface (next_attached).
846 * For the first surface, and a surface that has no attachments
847 * first_attached points to the surface itself. A surface that has
848 * no successors in the chain has next_attached set to NULL.
850 * Newly attached surfaces are attached right after the root surface.
851 * If a surface is attached to a complex surface compound, it's attached to
852 * the surface that the app requested, not the complex root. See
853 * GetAttachedSurface for a description how surfaces are found.
855 * This is how the current implementation works, and it was coded by looking
856 * at the needs of the applications.
858 * So far only Z-Buffer attachments are tested, and they are activated in
859 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
860 * Back buffers should work in 2D mode, but they are not tested(They can be
861 * attached in older iface versions). Rendering to the front buffer and
862 * switching between that and double buffering is not yet implemented in
863 * WineD3D, so for 3D it might have unexpected results.
865 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
866 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
867 * performs additional checks. Version 7 of this interface is much more restrictive
868 * than its predecessors.
870 * Params:
871 * Attach: Surface to attach to iface
873 * Returns:
874 * DD_OK on success
875 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
877 *****************************************************************************/
878 HRESULT WINAPI
879 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This,
880 IDirectDrawSurfaceImpl *Surf)
882 TRACE("(%p)->(%p)\n", This, Surf);
884 if(Surf == This)
885 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
887 EnterCriticalSection(&ddraw_cs);
889 /* Check if the surface is already attached somewhere */
890 if( (Surf->next_attached != NULL) ||
891 (Surf->first_attached != Surf) )
893 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
894 * What happens if one surface is attached to 2 different surfaces?
896 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);
897 LeaveCriticalSection(&ddraw_cs);
898 return DDERR_SURFACEALREADYATTACHED;
901 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
902 Surf->next_attached = This->next_attached;
903 Surf->first_attached = This->first_attached;
904 This->next_attached = Surf;
906 /* Check if the WineD3D depth stencil needs updating */
907 if(This->ddraw->d3ddevice)
909 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
912 /* MSDN:
913 * "This method increments the reference count of the surface being attached."
915 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(Surf, IDirectDrawSurface7));
916 LeaveCriticalSection(&ddraw_cs);
917 return DD_OK;
920 static HRESULT WINAPI
921 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7 *iface,
922 IDirectDrawSurface7 *Attach)
924 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
925 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
927 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
928 if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
931 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
932 Surf->surface_desc.ddsCaps.dwCaps);
933 return DDERR_CANNOTATTACHSURFACE;
936 return IDirectDrawSurfaceImpl_AddAttachedSurface(This,
937 Surf);
939 /*****************************************************************************
940 * IDirectDrawSurface7::DeleteAttachedSurface
942 * Removes a surface from the attachment chain. The surface's refcount
943 * is decreased by one after it has been removed
945 * Params:
946 * Flags: Some flags, not used by this implementation
947 * Attach: Surface to detach
949 * Returns:
950 * DD_OK on success
951 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
953 *****************************************************************************/
954 static HRESULT WINAPI
955 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
956 DWORD Flags,
957 IDirectDrawSurface7 *Attach)
959 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
960 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
961 IDirectDrawSurfaceImpl *Prev = This;
962 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
964 EnterCriticalSection(&ddraw_cs);
965 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
967 LeaveCriticalSection(&ddraw_cs);
968 return DDERR_CANNOTDETACHSURFACE;
971 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
972 if (This->surface_desc.ddsCaps.dwCaps &
973 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
975 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
976 /* FIXME: we should probably also subtract from dwMipMapCount of this
977 * and all parent surfaces */
980 /* Find the predecessor of the detached surface */
981 while(Prev)
983 if(Prev->next_attached == Surf) break;
984 Prev = Prev->next_attached;
987 /* There must be a surface, otherwise there's a bug */
988 assert(Prev != NULL);
990 /* Unchain the surface */
991 Prev->next_attached = Surf->next_attached;
992 Surf->next_attached = NULL;
993 Surf->first_attached = Surf;
995 /* Check if the WineD3D depth stencil needs updating */
996 if(This->ddraw->d3ddevice)
998 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
1001 IDirectDrawSurface7_Release(Attach);
1002 LeaveCriticalSection(&ddraw_cs);
1003 return DD_OK;
1006 /*****************************************************************************
1007 * IDirectDrawSurface7::AddOverlayDirtyRect
1009 * "This method is not currently implemented"
1011 * Params:
1012 * Rect: ?
1014 * Returns:
1015 * DDERR_UNSUPPORTED
1017 *****************************************************************************/
1018 static HRESULT WINAPI
1019 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
1020 LPRECT Rect)
1022 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1023 TRACE("(%p)->(%p)\n",This,Rect);
1025 /* MSDN says it's not implemented. I could forward it to WineD3D,
1026 * then we'd implement it, but I don't think that's a good idea
1027 * (Stefan Dösinger)
1029 #if 0
1030 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
1031 #endif
1032 return DDERR_UNSUPPORTED; /* unchecked */
1035 /*****************************************************************************
1036 * IDirectDrawSurface7::GetDC
1038 * Returns a GDI device context for the surface
1040 * Params:
1041 * hdc: Address of a HDC variable to store the dc to
1043 * Returns:
1044 * DD_OK on success
1045 * DDERR_INVALIDPARAMS if hdc is NULL
1046 * For details, see IWineD3DSurface::GetDC
1048 *****************************************************************************/
1049 static HRESULT WINAPI
1050 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
1051 HDC *hdc)
1053 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1054 HRESULT hr;
1055 TRACE("(%p)->(%p): Relay\n", This, hdc);
1057 if(!hdc)
1058 return DDERR_INVALIDPARAMS;
1060 EnterCriticalSection(&ddraw_cs);
1061 hr = IWineD3DSurface_GetDC(This->WineD3DSurface,
1062 hdc);
1063 LeaveCriticalSection(&ddraw_cs);
1064 return hr;
1067 /*****************************************************************************
1068 * IDirectDrawSurface7::ReleaseDC
1070 * Releases the DC that was constructed with GetDC
1072 * Params:
1073 * hdc: HDC to release
1075 * Returns:
1076 * DD_OK on success
1077 * For more details, see IWineD3DSurface::ReleaseDC
1079 *****************************************************************************/
1080 static HRESULT WINAPI
1081 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
1082 HDC hdc)
1084 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1085 HRESULT hr;
1086 TRACE("(%p)->(%p): Relay\n", This, hdc);
1088 EnterCriticalSection(&ddraw_cs);
1089 hr = IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
1090 LeaveCriticalSection(&ddraw_cs);
1091 return hr;
1094 /*****************************************************************************
1095 * IDirectDrawSurface7::GetCaps
1097 * Returns the surface's caps
1099 * Params:
1100 * Caps: Address to write the caps to
1102 * Returns:
1103 * DD_OK on success
1104 * DDERR_INVALIDPARAMS if Caps is NULL
1106 *****************************************************************************/
1107 static HRESULT WINAPI
1108 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
1109 DDSCAPS2 *Caps)
1111 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1112 TRACE("(%p)->(%p)\n",This,Caps);
1114 if(!Caps)
1115 return DDERR_INVALIDPARAMS;
1117 *Caps = This->surface_desc.ddsCaps;
1118 return DD_OK;
1121 /*****************************************************************************
1122 * IDirectDrawSurface7::SetPriority
1124 * Sets a texture priority for managed textures.
1126 * Params:
1127 * Priority: The new priority
1129 * Returns:
1130 * DD_OK on success
1131 * For more details, see IWineD3DSurface::SetPriority
1133 *****************************************************************************/
1134 static HRESULT WINAPI
1135 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
1137 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1138 HRESULT hr;
1139 TRACE("(%p)->(%d): Relay!\n",This,Priority);
1141 EnterCriticalSection(&ddraw_cs);
1142 hr = IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
1143 LeaveCriticalSection(&ddraw_cs);
1144 return hr;
1147 /*****************************************************************************
1148 * IDirectDrawSurface7::GetPriority
1150 * Returns the surface's priority
1152 * Params:
1153 * Priority: Address of a variable to write the priority to
1155 * Returns:
1156 * D3D_OK on success
1157 * DDERR_INVALIDPARAMS if Priority == NULL
1158 * For more details, see IWineD3DSurface::GetPriority
1160 *****************************************************************************/
1161 static HRESULT WINAPI
1162 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1163 DWORD *Priority)
1165 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1166 TRACE("(%p)->(%p): Relay\n",This,Priority);
1168 if(!Priority)
1170 return DDERR_INVALIDPARAMS;
1173 EnterCriticalSection(&ddraw_cs);
1174 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1175 LeaveCriticalSection(&ddraw_cs);
1176 return DD_OK;
1179 /*****************************************************************************
1180 * IDirectDrawSurface7::SetPrivateData
1182 * Stores some data in the surface that is intended for the application's
1183 * use.
1185 * Params:
1186 * tag: GUID that identifies the data
1187 * Data: Pointer to the private data
1188 * Size: Size of the private data
1189 * Flags: Some flags
1191 * Returns:
1192 * D3D_OK on success
1193 * For more details, see IWineD3DSurface::SetPrivateData
1195 *****************************************************************************/
1196 static HRESULT WINAPI
1197 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1198 REFGUID tag,
1199 void *Data,
1200 DWORD Size,
1201 DWORD Flags)
1203 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1204 HRESULT hr;
1205 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1207 EnterCriticalSection(&ddraw_cs);
1208 hr = IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1209 tag,
1210 Data,
1211 Size,
1212 Flags);
1213 LeaveCriticalSection(&ddraw_cs);
1214 switch(hr)
1216 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1217 default: return hr;
1221 /*****************************************************************************
1222 * IDirectDrawSurface7::GetPrivateData
1224 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1226 * Params:
1227 * tag: GUID of the data to return
1228 * Data: Address where to write the data to
1229 * Size: Size of the buffer at Data
1231 * Returns:
1232 * DD_OK on success
1233 * DDERR_INVALIDPARAMS if Data is NULL
1234 * For more details, see IWineD3DSurface::GetPrivateData
1236 *****************************************************************************/
1237 static HRESULT WINAPI
1238 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1239 REFGUID tag,
1240 void *Data,
1241 DWORD *Size)
1243 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1244 HRESULT hr;
1245 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1247 if(!Data)
1248 return DDERR_INVALIDPARAMS;
1250 EnterCriticalSection(&ddraw_cs);
1251 hr = IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1252 tag,
1253 Data,
1254 Size);
1255 LeaveCriticalSection(&ddraw_cs);
1256 return hr;
1259 /*****************************************************************************
1260 * IDirectDrawSurface7::FreePrivateData
1262 * Frees private data stored in the surface
1264 * Params:
1265 * tag: Tag of the data to free
1267 * Returns:
1268 * D3D_OK on success
1269 * For more details, see IWineD3DSurface::FreePrivateData
1271 *****************************************************************************/
1272 static HRESULT WINAPI
1273 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1274 REFGUID tag)
1276 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1277 HRESULT hr;
1278 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1280 EnterCriticalSection(&ddraw_cs);
1281 hr = IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1282 LeaveCriticalSection(&ddraw_cs);
1283 return hr;
1286 /*****************************************************************************
1287 * IDirectDrawSurface7::PageLock
1289 * Prevents a sysmem surface from being paged out
1291 * Params:
1292 * Flags: Not used, must be 0(unchecked)
1294 * Returns:
1295 * DD_OK, because it's a stub
1297 *****************************************************************************/
1298 static HRESULT WINAPI
1299 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1300 DWORD Flags)
1302 TRACE("(%p)->(%x)\n", iface, Flags);
1304 /* This is Windows memory management related - we don't need this */
1305 return DD_OK;
1308 /*****************************************************************************
1309 * IDirectDrawSurface7::PageUnlock
1311 * Allows a sysmem surface to be paged out
1313 * Params:
1314 * Flags: Not used, must be 0(unckeched)
1316 * Returns:
1317 * DD_OK, because it's a stub
1319 *****************************************************************************/
1320 static HRESULT WINAPI
1321 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1322 DWORD Flags)
1324 TRACE("(%p)->(%x)\n", iface, Flags);
1326 return DD_OK;
1329 /*****************************************************************************
1330 * IDirectDrawSurface7::BltBatch
1332 * An unimplemented function
1334 * Params:
1337 * Returns:
1338 * DDERR_UNSUPPORTED
1340 *****************************************************************************/
1341 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1343 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1345 /* MSDN: "not currently implemented" */
1346 return DDERR_UNSUPPORTED;
1349 /*****************************************************************************
1350 * IDirectDrawSurface7::EnumAttachedSurfaces
1352 * Enumerates all surfaces attached to this surface
1354 * Params:
1355 * context: Pointer to pass unmodified to the callback
1356 * cb: Callback function to call for each surface
1358 * Returns:
1359 * DD_OK on success
1360 * DDERR_INVALIDPARAMS if cb is NULL
1362 *****************************************************************************/
1363 static HRESULT WINAPI
1364 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1365 void *context,
1366 LPDDENUMSURFACESCALLBACK7 cb)
1368 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1369 IDirectDrawSurfaceImpl *surf;
1370 DDSURFACEDESC2 desc;
1371 int i;
1373 /* Attached surfaces aren't handled in WineD3D */
1374 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1376 if(!cb)
1377 return DDERR_INVALIDPARAMS;
1379 EnterCriticalSection(&ddraw_cs);
1380 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
1382 surf = This->complex_array[i];
1383 if(!surf) break;
1385 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1386 desc = surf->surface_desc;
1387 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1388 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1390 LeaveCriticalSection(&ddraw_cs);
1391 return DD_OK;
1395 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1397 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1398 desc = surf->surface_desc;
1399 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1400 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1402 LeaveCriticalSection(&ddraw_cs);
1403 return DD_OK;
1407 TRACE(" end of enumeration.\n");
1409 LeaveCriticalSection(&ddraw_cs);
1410 return DD_OK;
1413 /*****************************************************************************
1414 * IDirectDrawSurface7::EnumOverlayZOrders
1416 * "Enumerates the overlay surfaces on the specified destination"
1418 * Params:
1419 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1420 * context: context to pass back to the callback
1421 * cb: callback function to call for each enumerated surface
1423 * Returns:
1424 * DD_OK, because it's a stub
1426 *****************************************************************************/
1427 static HRESULT WINAPI
1428 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1429 DWORD Flags,
1430 void *context,
1431 LPDDENUMSURFACESCALLBACK7 cb)
1433 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1435 return DD_OK;
1438 /*****************************************************************************
1439 * IDirectDrawSurface7::GetBltStatus
1441 * Returns the blitting status
1443 * Params:
1444 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1446 * Returns:
1447 * See IWineD3DSurface::Blt
1449 *****************************************************************************/
1450 static HRESULT WINAPI
1451 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1452 DWORD Flags)
1454 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1455 HRESULT hr;
1456 TRACE("(%p)->(%x): Relay\n", This, Flags);
1458 EnterCriticalSection(&ddraw_cs);
1459 hr = IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1460 LeaveCriticalSection(&ddraw_cs);
1461 switch(hr)
1463 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1464 default: return hr;
1468 /*****************************************************************************
1469 * IDirectDrawSurface7::GetColorKey
1471 * Returns the color key assigned to the surface
1473 * Params:
1474 * Flags: Some flags
1475 * CKey: Address to store the key to
1477 * Returns:
1478 * DD_OK on success
1479 * DDERR_INVALIDPARAMS if CKey is NULL
1481 *****************************************************************************/
1482 static HRESULT WINAPI
1483 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1484 DWORD Flags,
1485 DDCOLORKEY *CKey)
1487 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1488 * isn't there? That's like saying that an int isn't there. (Which MS
1489 * has done in other docs.) */
1490 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1491 TRACE("(%p)->(%08x,%p)\n", This, Flags, CKey);
1493 if(!CKey)
1494 return DDERR_INVALIDPARAMS;
1496 EnterCriticalSection(&ddraw_cs);
1497 switch (Flags)
1499 case DDCKEY_DESTBLT:
1500 *CKey = This->surface_desc.ddckCKDestBlt;
1501 break;
1503 case DDCKEY_DESTOVERLAY:
1504 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1505 break;
1507 case DDCKEY_SRCBLT:
1508 *CKey = This->surface_desc.ddckCKSrcBlt;
1509 break;
1511 case DDCKEY_SRCOVERLAY:
1512 *CKey = This->surface_desc.ddckCKSrcOverlay;
1513 break;
1515 default:
1516 LeaveCriticalSection(&ddraw_cs);
1517 return DDERR_INVALIDPARAMS;
1520 LeaveCriticalSection(&ddraw_cs);
1521 return DD_OK;
1524 /*****************************************************************************
1525 * IDirectDrawSurface7::GetFlipStatus
1527 * Returns the flipping status of the surface
1529 * Params:
1530 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1532 * Returns:
1533 * See IWineD3DSurface::GetFlipStatus
1535 *****************************************************************************/
1536 static HRESULT WINAPI
1537 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1538 DWORD Flags)
1540 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1541 HRESULT hr;
1542 TRACE("(%p)->(%x): Relay\n", This, Flags);
1544 EnterCriticalSection(&ddraw_cs);
1545 hr = IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1546 LeaveCriticalSection(&ddraw_cs);
1547 switch(hr)
1549 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1550 default: return hr;
1554 /*****************************************************************************
1555 * IDirectDrawSurface7::GetOverlayPosition
1557 * Returns the display coordinates of a visible and active overlay surface
1559 * Params:
1563 * Returns:
1564 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1565 *****************************************************************************/
1566 static HRESULT WINAPI
1567 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1568 LONG *X,
1569 LONG *Y) {
1570 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1571 HRESULT hr;
1572 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1574 EnterCriticalSection(&ddraw_cs);
1575 hr = IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1578 LeaveCriticalSection(&ddraw_cs);
1579 return hr;
1582 /*****************************************************************************
1583 * IDirectDrawSurface7::GetPixelFormat
1585 * Returns the pixel format of the Surface
1587 * Params:
1588 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1589 * format should be written
1591 * Returns:
1592 * DD_OK on success
1593 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1595 *****************************************************************************/
1596 static HRESULT WINAPI
1597 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1598 DDPIXELFORMAT *PixelFormat)
1600 /* What is DDERR_INVALIDSURFACETYPE for here? */
1601 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1602 TRACE("(%p)->(%p)\n",This,PixelFormat);
1604 if(!PixelFormat)
1605 return DDERR_INVALIDPARAMS;
1607 EnterCriticalSection(&ddraw_cs);
1608 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1609 LeaveCriticalSection(&ddraw_cs);
1611 return DD_OK;
1615 /*****************************************************************************
1616 * IDirectDrawSurface7::GetSurfaceDesc
1618 * Returns the description of this surface
1620 * Params:
1621 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1622 * surface desc
1624 * Returns:
1625 * DD_OK on success
1626 * DDERR_INVALIDPARAMS if DDSD is NULL
1628 *****************************************************************************/
1629 static HRESULT WINAPI
1630 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1631 DDSURFACEDESC2 *DDSD)
1633 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1635 TRACE("(%p)->(%p)\n",This,DDSD);
1637 if(!DDSD)
1638 return DDERR_INVALIDPARAMS;
1640 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
1642 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
1643 return DDERR_INVALIDPARAMS;
1646 EnterCriticalSection(&ddraw_cs);
1647 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1648 TRACE("Returning surface desc:\n");
1649 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1651 LeaveCriticalSection(&ddraw_cs);
1652 return DD_OK;
1655 /*****************************************************************************
1656 * IDirectDrawSurface7::Initialize
1658 * Initializes the surface. This is a no-op in Wine
1660 * Params:
1661 * DD: Pointer to an DirectDraw interface
1662 * DDSD: Surface description for initialization
1664 * Returns:
1665 * DDERR_ALREADYINITIALIZED
1667 *****************************************************************************/
1668 static HRESULT WINAPI
1669 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1670 IDirectDraw *DD,
1671 DDSURFACEDESC2 *DDSD)
1673 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1674 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1675 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1677 return DDERR_ALREADYINITIALIZED;
1680 /*****************************************************************************
1681 * IDirectDrawSurface7::IsLost
1683 * Checks if the surface is lost
1685 * Returns:
1686 * DD_OK, if the surface is useable
1687 * DDERR_ISLOST if the surface is lost
1688 * See IWineD3DSurface::IsLost for more details
1690 *****************************************************************************/
1691 static HRESULT WINAPI
1692 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1694 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1695 HRESULT hr;
1696 TRACE("(%p)\n", This);
1698 EnterCriticalSection(&ddraw_cs);
1699 /* We lose the surface if the implementation was changed */
1700 if(This->ImplType != This->ddraw->ImplType)
1702 /* But this shouldn't happen. When we change the implementation,
1703 * all surfaces are re-created automatically, and their content
1704 * is copied
1706 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1707 LeaveCriticalSection(&ddraw_cs);
1708 return DDERR_SURFACELOST;
1711 hr = IWineD3DSurface_IsLost(This->WineD3DSurface);
1712 LeaveCriticalSection(&ddraw_cs);
1713 switch(hr)
1715 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1716 * WineD3D uses the same error for surfaces
1718 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
1719 default: return hr;
1723 /*****************************************************************************
1724 * IDirectDrawSurface7::Restore
1726 * Restores a lost surface. This makes the surface usable again, but
1727 * doesn't reload its old contents
1729 * Returns:
1730 * DD_OK on success
1731 * See IWineD3DSurface::Restore for more details
1733 *****************************************************************************/
1734 static HRESULT WINAPI
1735 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1737 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1738 HRESULT hr;
1739 TRACE("(%p)\n", This);
1741 EnterCriticalSection(&ddraw_cs);
1742 if(This->ImplType != This->ddraw->ImplType)
1744 /* Call the recreation callback. Make sure to AddRef first */
1745 IDirectDrawSurface_AddRef(iface);
1746 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1747 &This->surface_desc,
1748 NULL /* Not needed */);
1750 hr = IWineD3DSurface_Restore(This->WineD3DSurface);
1751 LeaveCriticalSection(&ddraw_cs);
1752 return hr;
1755 /*****************************************************************************
1756 * IDirectDrawSurface7::SetOverlayPosition
1758 * Changes the display coordinates of an overlay surface
1760 * Params:
1761 * X:
1762 * Y:
1764 * Returns:
1765 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1766 *****************************************************************************/
1767 static HRESULT WINAPI
1768 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1769 LONG X,
1770 LONG Y)
1772 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1773 HRESULT hr;
1774 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1776 EnterCriticalSection(&ddraw_cs);
1777 hr = IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1780 LeaveCriticalSection(&ddraw_cs);
1781 return hr;
1784 /*****************************************************************************
1785 * IDirectDrawSurface7::UpdateOverlay
1787 * Modifies the attributes of an overlay surface.
1789 * Params:
1790 * SrcRect: The section of the source being used for the overlay
1791 * DstSurface: Address of the surface that is overlaid
1792 * DstRect: Place of the overlay
1793 * Flags: some DDOVER_* flags
1795 * Returns:
1796 * DDERR_UNSUPPORTED, because we don't support overlays
1798 *****************************************************************************/
1799 static HRESULT WINAPI
1800 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1801 LPRECT SrcRect,
1802 IDirectDrawSurface7 *DstSurface,
1803 LPRECT DstRect,
1804 DWORD Flags,
1805 LPDDOVERLAYFX FX)
1807 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1808 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1809 HRESULT hr;
1810 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1812 EnterCriticalSection(&ddraw_cs);
1813 hr = IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1814 SrcRect,
1815 Dst ? Dst->WineD3DSurface : NULL,
1816 DstRect,
1817 Flags,
1818 (WINEDDOVERLAYFX *) FX);
1819 LeaveCriticalSection(&ddraw_cs);
1820 return hr;
1823 /*****************************************************************************
1824 * IDirectDrawSurface7::UpdateOverlayDisplay
1826 * The DX7 sdk says that it's not implemented
1828 * Params:
1829 * Flags: ?
1831 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1833 *****************************************************************************/
1834 static HRESULT WINAPI
1835 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1836 DWORD Flags)
1838 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1839 TRACE("(%p)->(%x)\n", This, Flags);
1840 return DDERR_UNSUPPORTED;
1843 /*****************************************************************************
1844 * IDirectDrawSurface7::UpdateOverlayZOrder
1846 * Sets an overlay's Z order
1848 * Params:
1849 * Flags: DDOVERZ_* flags
1850 * DDSRef: Defines the relative position in the overlay chain
1852 * Returns:
1853 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1855 *****************************************************************************/
1856 static HRESULT WINAPI
1857 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1858 DWORD Flags,
1859 IDirectDrawSurface7 *DDSRef)
1861 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1862 HRESULT hr;
1863 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1865 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1866 EnterCriticalSection(&ddraw_cs);
1867 hr = IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1868 Flags,
1869 Ref ? Ref->WineD3DSurface : NULL);
1870 LeaveCriticalSection(&ddraw_cs);
1871 return hr;
1874 /*****************************************************************************
1875 * IDirectDrawSurface7::GetDDInterface
1877 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1878 * surface belongs to
1880 * Params:
1881 * DD: Address to write the interface pointer to
1883 * Returns:
1884 * DD_OK on success
1885 * DDERR_INVALIDPARAMS if DD is NULL
1887 *****************************************************************************/
1888 static HRESULT WINAPI
1889 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1890 void **DD)
1892 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1894 TRACE("(%p)->(%p)\n",This,DD);
1896 if(!DD)
1897 return DDERR_INVALIDPARAMS;
1899 switch(This->version)
1901 case 7:
1902 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1903 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1904 break;
1906 case 4:
1907 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1908 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1909 break;
1911 case 2:
1912 *((IDirectDraw2 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
1913 IDirectDraw_AddRef( *(IDirectDraw2 **) DD);
1914 break;
1916 case 1:
1917 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1918 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1919 break;
1923 return DD_OK;
1926 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1927 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1929 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1930 volatile IDirectDrawSurfaceImpl* vThis = This;
1932 TRACE("(%p)\n",This);
1933 EnterCriticalSection(&ddraw_cs);
1934 /* A uniqueness value of 0 is apparently special.
1935 * This needs to be checked.
1936 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1938 while (1) {
1939 DWORD old_uniqueness_value = vThis->uniqueness_value;
1940 DWORD new_uniqueness_value = old_uniqueness_value+1;
1942 if (old_uniqueness_value == 0) break;
1943 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1945 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1946 old_uniqueness_value,
1947 new_uniqueness_value)
1948 == old_uniqueness_value)
1949 break;
1952 LeaveCriticalSection(&ddraw_cs);
1953 return DD_OK;
1956 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1958 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1960 TRACE("(%p)->(%p)\n",This,pValue);
1961 EnterCriticalSection(&ddraw_cs);
1962 *pValue = This->uniqueness_value;
1963 LeaveCriticalSection(&ddraw_cs);
1964 return DD_OK;
1967 /*****************************************************************************
1968 * IDirectDrawSurface7::SetLOD
1970 * Sets the level of detail of a texture
1972 * Params:
1973 * MaxLOD: LOD to set
1975 * Returns:
1976 * DD_OK on success
1977 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1979 *****************************************************************************/
1980 static HRESULT WINAPI
1981 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1982 DWORD MaxLOD)
1984 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1985 HRESULT hr;
1986 TRACE("(%p)->(%d)\n", This, MaxLOD);
1988 EnterCriticalSection(&ddraw_cs);
1989 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1991 LeaveCriticalSection(&ddraw_cs);
1992 return DDERR_INVALIDOBJECT;
1995 if(!This->wineD3DTexture)
1997 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1998 LeaveCriticalSection(&ddraw_cs);
1999 return DDERR_INVALIDOBJECT;
2002 hr = IWineD3DBaseTexture_SetLOD(This->wineD3DTexture,
2003 MaxLOD);
2004 LeaveCriticalSection(&ddraw_cs);
2005 return hr;
2008 /*****************************************************************************
2009 * IDirectDrawSurface7::GetLOD
2011 * Returns the level of detail of a Direct3D texture
2013 * Params:
2014 * MaxLOD: Address to write the LOD to
2016 * Returns:
2017 * DD_OK on success
2018 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2019 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2021 *****************************************************************************/
2022 static HRESULT WINAPI
2023 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
2024 DWORD *MaxLOD)
2026 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2027 TRACE("(%p)->(%p)\n", This, MaxLOD);
2029 if(!MaxLOD)
2030 return DDERR_INVALIDPARAMS;
2032 EnterCriticalSection(&ddraw_cs);
2033 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2035 LeaveCriticalSection(&ddraw_cs);
2036 return DDERR_INVALIDOBJECT;
2039 *MaxLOD = IWineD3DBaseTexture_GetLOD(This->wineD3DTexture);
2040 LeaveCriticalSection(&ddraw_cs);
2041 return DD_OK;
2044 /*****************************************************************************
2045 * IDirectDrawSurface7::BltFast
2047 * Performs a fast Blit.
2049 * Params:
2050 * dstx: The x coordinate to blit to on the destination
2051 * dsty: The y coordinate to blit to on the destination
2052 * Source: The source surface
2053 * rsrc: The source rectangle
2054 * trans: Type of transfer. Some DDBLTFAST_* flags
2056 * Returns:
2057 * DD_OK on success
2058 * For more details, see IWineD3DSurface::BltFast
2060 *****************************************************************************/
2061 static HRESULT WINAPI
2062 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
2063 DWORD dstx,
2064 DWORD dsty,
2065 IDirectDrawSurface7 *Source,
2066 RECT *rsrc,
2067 DWORD trans)
2069 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2070 HRESULT hr;
2071 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
2072 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
2074 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2075 * in that case
2077 if(rsrc)
2079 if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right ||
2080 rsrc->right > src->surface_desc.dwWidth ||
2081 rsrc->bottom > src->surface_desc.dwHeight)
2083 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2084 return DDERR_INVALIDRECT;
2086 if(dstx + rsrc->right - rsrc->left > This->surface_desc.dwWidth ||
2087 dsty + rsrc->bottom - rsrc->top > This->surface_desc.dwHeight)
2089 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2090 return DDERR_INVALIDRECT;
2093 else
2095 if(dstx + src->surface_desc.dwWidth > This->surface_desc.dwWidth ||
2096 dsty + src->surface_desc.dwHeight > This->surface_desc.dwHeight)
2098 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2099 return DDERR_INVALIDRECT;
2103 EnterCriticalSection(&ddraw_cs);
2104 hr = IWineD3DSurface_BltFast(This->WineD3DSurface,
2105 dstx, dsty,
2106 src ? src->WineD3DSurface : NULL,
2107 rsrc,
2108 trans);
2109 LeaveCriticalSection(&ddraw_cs);
2110 switch(hr)
2112 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
2113 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
2114 default: return hr;
2118 /*****************************************************************************
2119 * IDirectDrawSurface7::GetClipper
2121 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2122 * surface
2124 * Params:
2125 * Clipper: Address to store the interface pointer at
2127 * Returns:
2128 * DD_OK on success
2129 * DDERR_INVALIDPARAMS if Clipper is NULL
2130 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2132 *****************************************************************************/
2133 static HRESULT WINAPI
2134 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
2135 IDirectDrawClipper **Clipper)
2137 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2138 TRACE("(%p)->(%p)\n", This, Clipper);
2140 if(!Clipper)
2142 LeaveCriticalSection(&ddraw_cs);
2143 return DDERR_INVALIDPARAMS;
2146 EnterCriticalSection(&ddraw_cs);
2147 if(This->clipper == NULL)
2149 LeaveCriticalSection(&ddraw_cs);
2150 return DDERR_NOCLIPPERATTACHED;
2153 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
2154 IDirectDrawClipper_AddRef(*Clipper);
2155 LeaveCriticalSection(&ddraw_cs);
2156 return DD_OK;
2159 /*****************************************************************************
2160 * IDirectDrawSurface7::SetClipper
2162 * Sets a clipper for the surface
2164 * Params:
2165 * Clipper: IDirectDrawClipper interface of the clipper to set
2167 * Returns:
2168 * DD_OK on success
2170 *****************************************************************************/
2171 static HRESULT WINAPI
2172 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
2173 IDirectDrawClipper *Clipper)
2175 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2176 IDirectDrawClipperImpl *oldClipper = This->clipper;
2177 HRESULT hr;
2178 TRACE("(%p)->(%p)\n",This,Clipper);
2180 EnterCriticalSection(&ddraw_cs);
2181 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
2183 LeaveCriticalSection(&ddraw_cs);
2184 return DD_OK;
2187 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
2189 if (Clipper != NULL)
2190 IDirectDrawClipper_AddRef(Clipper);
2191 if(oldClipper)
2192 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper, IDirectDrawClipper));
2194 hr = IWineD3DSurface_SetClipper(This->WineD3DSurface, This->clipper ? This->clipper->wineD3DClipper : NULL);
2195 LeaveCriticalSection(&ddraw_cs);
2196 return hr;
2199 /*****************************************************************************
2200 * IDirectDrawSurface7::SetSurfaceDesc
2202 * Sets the surface description. It can override the pixel format, the surface
2203 * memory, ...
2204 * It's not really tested.
2206 * Params:
2207 * DDSD: Pointer to the new surface description to set
2208 * Flags: Some flags
2210 * Returns:
2211 * DD_OK on success
2212 * DDERR_INVALIDPARAMS if DDSD is NULL
2214 *****************************************************************************/
2215 static HRESULT WINAPI
2216 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
2217 DDSURFACEDESC2 *DDSD,
2218 DWORD Flags)
2220 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2221 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
2222 HRESULT hr;
2223 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
2225 if(!DDSD)
2226 return DDERR_INVALIDPARAMS;
2228 EnterCriticalSection(&ddraw_cs);
2229 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
2231 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
2233 if(newFormat == WINED3DFMT_UNKNOWN)
2235 ERR("Requested to set an unknown pixelformat\n");
2236 LeaveCriticalSection(&ddraw_cs);
2237 return DDERR_INVALIDPARAMS;
2239 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
2241 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
2242 newFormat);
2243 if(hr != DD_OK)
2245 LeaveCriticalSection(&ddraw_cs);
2246 return hr;
2250 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
2252 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2253 DDCKEY_DESTOVERLAY,
2254 (WINEDDCOLORKEY *) &DDSD->u3.ddckCKDestOverlay);
2256 if (DDSD->dwFlags & DDSD_CKDESTBLT)
2258 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2259 DDCKEY_DESTBLT,
2260 (WINEDDCOLORKEY *) &DDSD->ddckCKDestBlt);
2262 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
2264 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2265 DDCKEY_SRCOVERLAY,
2266 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcOverlay);
2268 if (DDSD->dwFlags & DDSD_CKSRCBLT)
2270 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2271 DDCKEY_SRCBLT,
2272 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcBlt);
2274 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
2276 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
2277 if(hr != WINED3D_OK)
2279 /* No need for a trace here, wined3d does that for us */
2280 LeaveCriticalSection(&ddraw_cs);
2281 switch(hr)
2283 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2284 default: break; /* Go on */
2290 This->surface_desc = *DDSD;
2292 LeaveCriticalSection(&ddraw_cs);
2293 return DD_OK;
2296 /*****************************************************************************
2297 * IDirectDrawSurface7::GetPalette
2299 * Returns the IDirectDrawPalette interface of the palette currently assigned
2300 * to the surface
2302 * Params:
2303 * Pal: Address to write the interface pointer to
2305 * Returns:
2306 * DD_OK on success
2307 * DDERR_INVALIDPARAMS if Pal is NULL
2309 *****************************************************************************/
2310 static HRESULT WINAPI
2311 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
2312 IDirectDrawPalette **Pal)
2314 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2315 IWineD3DPalette *wPal;
2316 HRESULT hr;
2317 TRACE("(%p)->(%p): Relay\n", This, Pal);
2319 if(!Pal)
2320 return DDERR_INVALIDPARAMS;
2322 EnterCriticalSection(&ddraw_cs);
2323 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
2324 if(hr != DD_OK)
2326 LeaveCriticalSection(&ddraw_cs);
2327 return hr;
2330 if(wPal)
2332 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2334 else
2336 *Pal = NULL;
2337 hr = DDERR_NOPALETTEATTACHED;
2340 LeaveCriticalSection(&ddraw_cs);
2341 return hr;
2344 /*****************************************************************************
2345 * SetColorKeyEnum
2347 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2348 * recursively in the surface tree
2350 *****************************************************************************/
2351 struct SCKContext
2353 HRESULT ret;
2354 WINEDDCOLORKEY *CKey;
2355 DWORD Flags;
2358 static HRESULT WINAPI
2359 SetColorKeyEnum(IDirectDrawSurface7 *surface,
2360 DDSURFACEDESC2 *desc,
2361 void *context)
2363 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, surface);
2364 struct SCKContext *ctx = context;
2365 HRESULT hr;
2367 hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2368 ctx->Flags,
2369 ctx->CKey);
2370 if(hr != DD_OK)
2372 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
2373 ctx->ret = hr;
2376 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
2377 context,
2378 SetColorKeyEnum);
2379 IDirectDrawSurface7_Release(surface);
2380 return DDENUMRET_OK;
2383 /*****************************************************************************
2384 * IDirectDrawSurface7::SetColorKey
2386 * Sets the color keying options for the surface. Observations showed that
2387 * in case of complex surfaces the color key has to be assigned to all
2388 * sublevels.
2390 * Params:
2391 * Flags: DDCKEY_*
2392 * CKey: The new color key
2394 * Returns:
2395 * DD_OK on success
2396 * See IWineD3DSurface::SetColorKey for details
2398 *****************************************************************************/
2399 static HRESULT WINAPI
2400 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2401 DWORD Flags,
2402 DDCOLORKEY *CKey)
2404 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2405 struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) CKey, Flags };
2406 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2408 EnterCriticalSection(&ddraw_cs);
2409 if (CKey)
2411 switch (Flags & ~DDCKEY_COLORSPACE)
2413 case DDCKEY_DESTBLT:
2414 This->surface_desc.ddckCKDestBlt = *CKey;
2415 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
2416 break;
2418 case DDCKEY_DESTOVERLAY:
2419 This->surface_desc.u3.ddckCKDestOverlay = *CKey;
2420 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
2421 break;
2423 case DDCKEY_SRCOVERLAY:
2424 This->surface_desc.ddckCKSrcOverlay = *CKey;
2425 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
2426 break;
2428 case DDCKEY_SRCBLT:
2429 This->surface_desc.ddckCKSrcBlt = *CKey;
2430 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
2431 break;
2433 default:
2434 LeaveCriticalSection(&ddraw_cs);
2435 return DDERR_INVALIDPARAMS;
2438 else
2440 switch (Flags & ~DDCKEY_COLORSPACE)
2442 case DDCKEY_DESTBLT:
2443 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
2444 break;
2446 case DDCKEY_DESTOVERLAY:
2447 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
2448 break;
2450 case DDCKEY_SRCOVERLAY:
2451 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
2452 break;
2454 case DDCKEY_SRCBLT:
2455 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
2456 break;
2458 default:
2459 LeaveCriticalSection(&ddraw_cs);
2460 return DDERR_INVALIDPARAMS;
2463 ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2464 Flags,
2465 ctx.CKey);
2466 IDirectDrawSurface7_EnumAttachedSurfaces(iface,
2467 (void *) &ctx,
2468 SetColorKeyEnum);
2469 LeaveCriticalSection(&ddraw_cs);
2470 switch(ctx.ret)
2472 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2473 default: return ctx.ret;
2477 /*****************************************************************************
2478 * IDirectDrawSurface7::SetPalette
2480 * Assigns a DirectDrawPalette object to the surface
2482 * Params:
2483 * Pal: Interface to the palette to set
2485 * Returns:
2486 * DD_OK on success
2488 *****************************************************************************/
2489 static HRESULT WINAPI
2490 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2491 IDirectDrawPalette *Pal)
2493 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2494 IDirectDrawPalette *oldPal;
2495 IDirectDrawSurfaceImpl *surf;
2496 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2497 HRESULT hr;
2498 TRACE("(%p)->(%p)\n", This, Pal);
2500 /* Find the old palette */
2501 EnterCriticalSection(&ddraw_cs);
2502 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2503 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
2505 LeaveCriticalSection(&ddraw_cs);
2506 return hr;
2508 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2510 /* Set the new Palette */
2511 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2512 PalImpl ? PalImpl->wineD3DPalette : NULL);
2513 /* AddRef the Palette */
2514 if(Pal) IDirectDrawPalette_AddRef(Pal);
2516 /* Release the old palette */
2517 if(oldPal) IDirectDrawPalette_Release(oldPal);
2519 /* If this is a front buffer, also update the back buffers
2520 * TODO: How do things work for palettized cube textures?
2522 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2524 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2525 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
2527 surf = This;
2528 while(1)
2530 IDirectDrawSurface7 *attach;
2531 HRESULT hr;
2532 hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2533 &caps2, &attach);
2534 if(hr != DD_OK)
2536 break;
2539 TRACE("Setting palette on %p\n", attach);
2540 IDirectDrawSurface7_SetPalette(attach,
2541 Pal);
2542 surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, attach);
2543 IDirectDrawSurface7_Release(attach);
2547 LeaveCriticalSection(&ddraw_cs);
2548 return DD_OK;
2551 /*****************************************************************************
2552 * The VTable
2553 *****************************************************************************/
2555 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2557 /*** IUnknown ***/
2558 IDirectDrawSurfaceImpl_QueryInterface,
2559 IDirectDrawSurfaceImpl_AddRef,
2560 IDirectDrawSurfaceImpl_Release,
2561 /*** IDirectDrawSurface ***/
2562 IDirectDrawSurface7Impl_AddAttachedSurface,
2563 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2564 IDirectDrawSurfaceImpl_Blt,
2565 IDirectDrawSurfaceImpl_BltBatch,
2566 IDirectDrawSurfaceImpl_BltFast,
2567 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2568 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2569 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2570 IDirectDrawSurfaceImpl_Flip,
2571 IDirectDrawSurfaceImpl_GetAttachedSurface,
2572 IDirectDrawSurfaceImpl_GetBltStatus,
2573 IDirectDrawSurfaceImpl_GetCaps,
2574 IDirectDrawSurfaceImpl_GetClipper,
2575 IDirectDrawSurfaceImpl_GetColorKey,
2576 IDirectDrawSurfaceImpl_GetDC,
2577 IDirectDrawSurfaceImpl_GetFlipStatus,
2578 IDirectDrawSurfaceImpl_GetOverlayPosition,
2579 IDirectDrawSurfaceImpl_GetPalette,
2580 IDirectDrawSurfaceImpl_GetPixelFormat,
2581 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2582 IDirectDrawSurfaceImpl_Initialize,
2583 IDirectDrawSurfaceImpl_IsLost,
2584 IDirectDrawSurfaceImpl_Lock,
2585 IDirectDrawSurfaceImpl_ReleaseDC,
2586 IDirectDrawSurfaceImpl_Restore,
2587 IDirectDrawSurfaceImpl_SetClipper,
2588 IDirectDrawSurfaceImpl_SetColorKey,
2589 IDirectDrawSurfaceImpl_SetOverlayPosition,
2590 IDirectDrawSurfaceImpl_SetPalette,
2591 IDirectDrawSurfaceImpl_Unlock,
2592 IDirectDrawSurfaceImpl_UpdateOverlay,
2593 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2594 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2595 /*** IDirectDrawSurface2 ***/
2596 IDirectDrawSurfaceImpl_GetDDInterface,
2597 IDirectDrawSurfaceImpl_PageLock,
2598 IDirectDrawSurfaceImpl_PageUnlock,
2599 /*** IDirectDrawSurface3 ***/
2600 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2601 /*** IDirectDrawSurface4 ***/
2602 IDirectDrawSurfaceImpl_SetPrivateData,
2603 IDirectDrawSurfaceImpl_GetPrivateData,
2604 IDirectDrawSurfaceImpl_FreePrivateData,
2605 IDirectDrawSurfaceImpl_GetUniquenessValue,
2606 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2607 /*** IDirectDrawSurface7 ***/
2608 IDirectDrawSurfaceImpl_SetPriority,
2609 IDirectDrawSurfaceImpl_GetPriority,
2610 IDirectDrawSurfaceImpl_SetLOD,
2611 IDirectDrawSurfaceImpl_GetLOD