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
27 #include "wine/port.h"
35 #define NONAMELESSUNION
41 #include "wine/exception.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)
65 * riid: The interface id queried for
66 * obj: Address to write the pointer to
70 * E_NOINTERFACE if the requested interface wasn't found
72 *****************************************************************************/
74 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
78 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
80 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
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);
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);
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);
112 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
113 IsEqualGUID(riid, &IID_IDirect3DHALDevice) )
115 IDirect3DDevice7 *d3d;
117 /* Call into IDirect3D7 for creation */
118 IDirect3D7_CreateDevice(ICOM_INTERFACE(This->ddraw, IDirect3D7),
120 ICOM_INTERFACE(This, IDirectDrawSurface7),
123 *obj = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice, d3d);
124 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
128 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
129 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
131 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
133 *obj = ICOM_INTERFACE(This, IDirect3DTexture);
134 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
138 *obj = ICOM_INTERFACE(This, IDirect3DTexture2);
139 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
141 IUnknown_AddRef( (IUnknown *) *obj);
145 ERR("No interface\n");
146 return E_NOINTERFACE;
149 /*****************************************************************************
150 * IDirectDrawSurface7::AddRef
152 * A normal addref implementation
157 *****************************************************************************/
159 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
161 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
162 ULONG refCount = InterlockedIncrement(&This->ref);
164 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
168 /*****************************************************************************
169 * IDirectDrawSurfaceImpl_Destroy
171 * A helper function for IDirectDrawSurface7::Release
173 * Frees the surface, regardless of its refcount.
174 * See IDirectDrawSurface7::Release for more information
177 * This: Surface to free
179 *****************************************************************************/
180 static void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
182 TRACE("(%p)\n", This);
184 /* Check the refcount and give a warning */
187 /* This can happen when a complex surface is destroyed,
188 * because the 2nd surface was addref()ed when the app
189 * called GetAttachedSurface
191 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
194 /* Check for attached surfaces and detach them */
195 if(This->first_attached != This)
197 /* Well, this shouldn't happen: The surface being attached is addref()ed
198 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
199 * is called, because the refcount is held. It looks like the app released()
200 * it often enough to force this
202 IDirectDrawSurface7 *root = ICOM_INTERFACE(This->first_attached, IDirectDrawSurface7);
203 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This, IDirectDrawSurface7);
205 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
207 /* The refcount will drop to -1 here */
208 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
210 ERR("(%p) DeleteAttachedSurface failed!\n", This);
214 while(This->next_attached != NULL)
216 IDirectDrawSurface7 *root = ICOM_INTERFACE(This, IDirectDrawSurface7);
217 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This->next_attached, IDirectDrawSurface7);
219 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
221 ERR("(%p) DeleteAttachedSurface failed!\n", This);
226 /* Now destroy the surface. Wait: It could have been released if we are a texture */
227 if(This->WineD3DSurface)
228 IWineD3DSurface_Release(This->WineD3DSurface);
230 /* Having a texture handle set implies that the device still exists */
233 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
234 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
237 /* Reduce the ddraw surface count */
238 InterlockedDecrement(&This->ddraw->surfaces);
239 list_remove(&This->surface_list_entry);
241 HeapFree(GetProcessHeap(), 0, This);
244 /*****************************************************************************
245 * IDirectDrawSurface7::Release
247 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
248 * surface is destroyed.
250 * Destroying the surface is a bit tricky. For the connection between
251 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
252 * It has a nice graph explaining the connection.
254 * What happens here is basically this:
255 * When a surface is destroyed, its WineD3DSurface is released,
256 * and the refcount of the DirectDraw interface is reduced by 1. If it has
257 * complex surfaces attached to it, then these surfaces are destroyed too,
258 * regardless of their refcount. If any surface being destroyed has another
259 * surface attached to it (with a "soft" attachment, not complex), then
260 * this surface is detached with DeleteAttachedSurface.
262 * When the surface is a texture, the WineD3DTexture is released.
263 * If the surface is the Direct3D render target, then the D3D
264 * capabilities of the WineD3DDevice are uninitialized, which causes the
265 * swapchain to be released.
267 * When a complex sublevel falls to ref zero, then this is ignored.
272 *****************************************************************************/
274 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
276 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
278 TRACE("(%p) : Releasing from %d\n", This, This->ref);
279 ref = InterlockedDecrement(&This->ref);
284 IDirectDrawSurfaceImpl *surf;
285 IDirectDrawImpl *ddraw;
286 IUnknown *ifaceToRelease = This->ifaceToRelease;
289 /* Complex attached surfaces are destroyed implicitely when the root is released */
290 EnterCriticalSection(&ddraw_cs);
291 if(!This->is_complex_root)
293 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
294 LeaveCriticalSection(&ddraw_cs);
299 /* If it's a texture, destroy the WineD3DTexture.
300 * WineD3D will destroy the IParent interfaces
301 * of the sublevels, which destroys the WineD3DSurfaces.
302 * Set the surfaces to NULL to avoid destroying them again later
304 if(This->wineD3DTexture)
306 IWineD3DBaseTexture_Release(This->wineD3DTexture);
308 /* If it's the RenderTarget, destroy the d3ddevice */
309 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
311 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
313 /* Unset any index buffer, just to be sure */
314 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL);
315 IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
317 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice, D3D7CB_DestroyDepthStencilSurface, D3D7CB_DestroySwapChain) != D3D_OK)
320 ERR("(%p) Failed to uninit 3D\n", This);
324 /* Free the d3d window if one was created */
325 if(ddraw->d3d_window != 0)
327 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
328 DestroyWindow(ddraw->d3d_window);
329 ddraw->d3d_window = 0;
331 /* Unset the pointers */
334 ddraw->d3d_initialized = FALSE;
335 ddraw->d3d_target = NULL;
337 /* Write a trace because D3D unloading was the reason for many
338 * crashes during development.
340 TRACE("(%p) D3D unloaded\n", This);
342 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
346 /* It's a render target, but no swapchain was created.
347 * The IParent interfaces have to be released manually.
348 * The same applies for textures without an
349 * IWineD3DTexture object attached
353 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
355 if(This->complex_array[i])
357 /* Only the topmost level can have more than 1 surfaces in the complex
358 * attachment array(Cube texture roots), for all others there is only
361 surf = This->complex_array[i];
364 IWineD3DSurface_GetParent(surf->WineD3DSurface,
365 (IUnknown **) &Parent);
366 IParent_Release(Parent); /* For the getParent */
367 IParent_Release(Parent); /* To release it */
368 surf = surf->complex_array[0];
373 /* Now the top-level surface */
374 IWineD3DSurface_GetParent(This->WineD3DSurface,
375 (IUnknown **) &Parent);
376 IParent_Release(Parent); /* For the getParent */
377 IParent_Release(Parent); /* To release it */
380 /* The refcount test shows that the palette is detached when the surface is destroyed */
381 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
384 /* Loop through all complex attached surfaces,
387 * Yet again, only the root can have more than one complexly attached surface, all the others
388 * have a total of one;
390 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
392 if(!This->complex_array[i]) break;
394 surf = This->complex_array[i];
395 This->complex_array[i] = NULL;
398 IDirectDrawSurfaceImpl *destroy = surf;
399 surf = surf->complex_array[0]; /* Iterate through the "tree" */
400 IDirectDrawSurfaceImpl_Destroy(destroy); /* Destroy it */
404 /* Destroy the root surface.
406 IDirectDrawSurfaceImpl_Destroy(This);
408 /* Reduce the ddraw refcount */
409 if(ifaceToRelease) IUnknown_Release(ifaceToRelease);
410 LeaveCriticalSection(&ddraw_cs);
416 /*****************************************************************************
417 * IDirectDrawSurface7::GetAttachedSurface
419 * Returns an attached surface with the requested caps. Surface attachment
420 * and complex surfaces are not clearly described by the MSDN or sdk,
421 * so this method is tricky and likely to contain problems.
422 * This implementation searches the complex list first, then the
425 * The chains are searched from This down to the last surface in the chain,
426 * not from the first element in the chain. The first surface found is
427 * returned. The MSDN says that this method fails if more than one surface
428 * matches the caps, but it is not sure if that is right. The attachment
429 * structure may not even allow two matching surfaces.
431 * The found surface is AddRef-ed before it is returned.
434 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
435 * Surface: Address to store the found surface
439 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
440 * DDERR_NOTFOUND if no surface was found
442 *****************************************************************************/
443 static HRESULT WINAPI
444 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
446 IDirectDrawSurface7 **Surface)
448 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
449 IDirectDrawSurfaceImpl *surf;
453 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
454 EnterCriticalSection(&ddraw_cs);
458 if(This->version < 7)
460 /* Earlier dx apps put garbage into these members, clear them */
461 our_caps.dwCaps2 = 0;
462 our_caps.dwCaps3 = 0;
463 our_caps.dwCaps4 = 0;
466 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 */
468 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
470 surf = This->complex_array[i];
475 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
476 surf->surface_desc.ddsCaps.dwCaps,
477 surf->surface_desc.ddsCaps.dwCaps2,
478 surf->surface_desc.ddsCaps.dwCaps3,
479 surf->surface_desc.ddsCaps.dwCaps4);
482 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
483 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
485 /* MSDN: "This method fails if more than one surface is attached
486 * that matches the capabilities requested."
488 * Not sure how to test this.
491 TRACE("(%p): Returning surface %p\n", This, surf);
492 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
493 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
494 IDirectDrawSurface7_AddRef(*Surface);
495 LeaveCriticalSection(&ddraw_cs);
500 /* Next, look at the attachment chain */
503 while( (surf = surf->next_attached) )
507 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
508 surf->surface_desc.ddsCaps.dwCaps,
509 surf->surface_desc.ddsCaps.dwCaps2,
510 surf->surface_desc.ddsCaps.dwCaps3,
511 surf->surface_desc.ddsCaps.dwCaps4);
514 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
515 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
517 TRACE("(%p): Returning surface %p\n", This, surf);
518 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
519 IDirectDrawSurface7_AddRef(*Surface);
520 LeaveCriticalSection(&ddraw_cs);
525 TRACE("(%p) Didn't find a valid surface\n", This);
526 LeaveCriticalSection(&ddraw_cs);
527 return DDERR_NOTFOUND;
530 /*****************************************************************************
531 * IDirectDrawSurface7::Lock
533 * Locks the surface and returns a pointer to the surface's memory
536 * Rect: Rectangle to lock. If NULL, the whole surface is locked
537 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
538 * Flags: Locking flags, e.g Read only or write only
539 * h: An event handle that's not used and must be NULL
543 * DDERR_INVALIDPARAMS if DDSD is NULL
544 * For more details, see IWineD3DSurface::LockRect
546 *****************************************************************************/
547 static HRESULT WINAPI
548 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
550 DDSURFACEDESC2 *DDSD,
554 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
555 WINED3DLOCKED_RECT LockedRect;
557 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
560 return DDERR_INVALIDPARAMS;
562 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
563 EnterCriticalSection(&ddraw_cs);
568 || (Rect->left > Rect->right)
569 || (Rect->top > Rect->bottom)
570 || (Rect->right > This->surface_desc.dwWidth)
571 || (Rect->bottom > This->surface_desc.dwHeight))
573 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
574 LeaveCriticalSection(&ddraw_cs);
575 return DDERR_INVALIDPARAMS;
579 /* Should I check for the handle to be NULL?
581 * The DDLOCK flags and the D3DLOCK flags are equal
582 * for the supported values. The others are ignored by WineD3D
585 if(DDSD->dwSize != sizeof(DDSURFACEDESC) &&
586 DDSD->dwSize != sizeof(DDSURFACEDESC2))
588 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS);
589 LeaveCriticalSection(&ddraw_cs);
590 return DDERR_INVALIDPARAMS;
593 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
599 LeaveCriticalSection(&ddraw_cs);
603 /* Override the memory area. The pitch should be set already. Strangely windows
604 * does not set the LPSURFACE flag on locked surfaces !?!.
605 * DDSD->dwFlags |= DDSD_LPSURFACE;
607 This->surface_desc.lpSurface = LockedRect.pBits;
608 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
610 TRACE("locked surface returning description :\n");
611 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
613 LeaveCriticalSection(&ddraw_cs);
617 /*****************************************************************************
618 * IDirectDrawSurface7::Unlock
620 * Unlocks an locked surface
623 * Rect: Not used by this implementation
627 * For more details, see IWineD3DSurface::UnlockRect
629 *****************************************************************************/
630 static HRESULT WINAPI
631 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
634 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
636 TRACE("(%p)->(%p)\n", This, pRect);
638 EnterCriticalSection(&ddraw_cs);
639 hr = IWineD3DSurface_UnlockRect(This->WineD3DSurface);
642 This->surface_desc.lpSurface = NULL;
644 LeaveCriticalSection(&ddraw_cs);
648 /*****************************************************************************
649 * IDirectDrawSurface7::Flip
651 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
652 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
653 * the flip target is passed to WineD3D, even if the app didn't specify one
656 * DestOverride: Specifies the surface that will become the new front
657 * buffer. If NULL, the current back buffer is used
658 * Flags: some DirectDraw flags, see include/ddraw.h
662 * DDERR_NOTFLIPPABLE if no flip target could be found
663 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
664 * For more details, see IWineD3DSurface::Flip
666 *****************************************************************************/
667 static HRESULT WINAPI
668 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
669 IDirectDrawSurface7 *DestOverride,
672 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
673 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
674 IDirectDrawSurface7 *Override7;
676 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
678 /* Flip has to be called from a front buffer
679 * What about overlay surfaces, AFAIK they can flip too?
681 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
682 return DDERR_INVALIDOBJECT; /* Unckecked */
684 EnterCriticalSection(&ddraw_cs);
686 /* WineD3D doesn't keep track of attached surface, so find the target */
691 memset(&Caps, 0, sizeof(Caps));
692 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
693 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
696 ERR("Can't find a flip target\n");
697 LeaveCriticalSection(&ddraw_cs);
698 return DDERR_NOTFLIPPABLE; /* Unchecked */
700 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
702 /* For the GetAttachedSurface */
703 IDirectDrawSurface7_Release(Override7);
706 hr = IWineD3DSurface_Flip(This->WineD3DSurface,
707 Override->WineD3DSurface,
709 LeaveCriticalSection(&ddraw_cs);
713 /*****************************************************************************
714 * IDirectDrawSurface7::Blt
716 * Performs a blit on the surface
719 * DestRect: Destination rectangle, can be NULL
720 * SrcSurface: Source surface, can be NULL
721 * SrcRect: Source rectange, can be NULL
723 * DDBltFx: Some extended blt parameters, connected to the flags
727 * See IWineD3DSurface::Blt for more details
729 *****************************************************************************/
730 static HRESULT WINAPI
731 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
733 IDirectDrawSurface7 *SrcSurface,
738 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
740 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
741 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
743 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
744 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
746 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
747 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
748 return DDERR_INVALIDPARAMS;
751 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
752 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
753 return DDERR_INVALIDPARAMS;
756 /* Sizes can change, therefore hold the lock when testing the rectangles */
757 EnterCriticalSection(&ddraw_cs);
760 if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right ||
761 DestRect->right > This->surface_desc.dwWidth ||
762 DestRect->bottom > This->surface_desc.dwHeight)
764 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
765 LeaveCriticalSection(&ddraw_cs);
766 return DDERR_INVALIDRECT;
771 if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right ||
772 SrcRect->right > Src->surface_desc.dwWidth ||
773 SrcRect->bottom > Src->surface_desc.dwHeight)
775 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
776 LeaveCriticalSection(&ddraw_cs);
777 return DDERR_INVALIDRECT;
781 if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
782 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
783 LeaveCriticalSection(&ddraw_cs);
784 return DDERR_INVALIDPARAMS;
787 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
788 * and replace the ddraw surfaces with the wined3d surfaces
789 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
791 hr = IWineD3DSurface_Blt(This->WineD3DSurface,
793 Src ? Src->WineD3DSurface : NULL,
796 (WINEDDBLTFX *) DDBltFx,
799 LeaveCriticalSection(&ddraw_cs);
802 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
803 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
808 /*****************************************************************************
809 * IDirectDrawSurface7::AddAttachedSurface
811 * Attaches a surface to another surface. How the surface attachments work
812 * is not totally understood yet, and this method is prone to problems.
813 * he surface that is attached is AddRef-ed.
815 * Tests with complex surfaces suggest that the surface attachments form a
816 * tree, but no method to test this has been found yet.
818 * The attachment list consists of a first surface (first_attached) and
819 * for each surface a pointer to the next attached surface (next_attached).
820 * For the first surface, and a surface that has no attachments
821 * first_attached points to the surface itself. A surface that has
822 * no successors in the chain has next_attached set to NULL.
824 * Newly attached surfaces are attached right after the root surface.
825 * If a surface is attached to a complex surface compound, it's attached to
826 * the surface that the app requested, not the complex root. See
827 * GetAttachedSurface for a description how surfaces are found.
829 * This is how the current implementation works, and it was coded by looking
830 * at the needs of the applications.
832 * So far only Z-Buffer attachments are tested, and they are activated in
833 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
834 * Back buffers should work in 2D mode, but they are not tested(They can be
835 * attached in older iface versions). Rendering to the front buffer and
836 * switching between that and double buffering is not yet implemented in
837 * WineD3D, so for 3D it might have unexpected results.
839 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
840 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
841 * performs additional checks. Version 7 of this interface is much more restrictive
842 * than its predecessors.
845 * Attach: Surface to attach to iface
849 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
851 *****************************************************************************/
853 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This,
854 IDirectDrawSurfaceImpl *Surf)
856 TRACE("(%p)->(%p)\n", This, Surf);
859 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
861 EnterCriticalSection(&ddraw_cs);
863 /* Check if the surface is already attached somewhere */
864 if( (Surf->next_attached != NULL) ||
865 (Surf->first_attached != Surf) )
867 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
868 * What happens if one surface is attached to 2 different surfaces?
870 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);
871 LeaveCriticalSection(&ddraw_cs);
872 return DDERR_SURFACEALREADYATTACHED;
875 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
876 Surf->next_attached = This->next_attached;
877 Surf->first_attached = This->first_attached;
878 This->next_attached = Surf;
880 /* Check if the WineD3D depth stencil needs updating */
881 if(This->ddraw->d3ddevice)
883 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
887 * "This method increments the reference count of the surface being attached."
889 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(Surf, IDirectDrawSurface7));
890 LeaveCriticalSection(&ddraw_cs);
894 static HRESULT WINAPI
895 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7 *iface,
896 IDirectDrawSurface7 *Attach)
898 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
899 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
901 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
902 if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
905 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
906 Surf->surface_desc.ddsCaps.dwCaps);
907 return DDERR_CANNOTATTACHSURFACE;
910 return IDirectDrawSurfaceImpl_AddAttachedSurface(This,
913 /*****************************************************************************
914 * IDirectDrawSurface7::DeleteAttachedSurface
916 * Removes a surface from the attachment chain. The surface's refcount
917 * is decreased by one after it has been removed
920 * Flags: Some flags, not used by this implementation
921 * Attach: Surface to detach
925 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
927 *****************************************************************************/
928 static HRESULT WINAPI
929 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
931 IDirectDrawSurface7 *Attach)
933 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
934 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
935 IDirectDrawSurfaceImpl *Prev = This;
936 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
938 EnterCriticalSection(&ddraw_cs);
939 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
941 LeaveCriticalSection(&ddraw_cs);
942 return DDERR_CANNOTDETACHSURFACE;
945 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
946 if (This->surface_desc.ddsCaps.dwCaps &
947 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
949 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
950 /* FIXME: we should probably also subtract from dwMipMapCount of this
951 * and all parent surfaces */
954 /* Find the predecessor of the detached surface */
957 if(Prev->next_attached == Surf) break;
958 Prev = Prev->next_attached;
961 /* There must be a surface, otherwise there's a bug */
962 assert(Prev != NULL);
964 /* Unchain the surface */
965 Prev->next_attached = Surf->next_attached;
966 Surf->next_attached = NULL;
967 Surf->first_attached = Surf;
969 /* Check if the WineD3D depth stencil needs updating */
970 if(This->ddraw->d3ddevice)
972 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
975 IDirectDrawSurface7_Release(Attach);
976 LeaveCriticalSection(&ddraw_cs);
980 /*****************************************************************************
981 * IDirectDrawSurface7::AddOverlayDirtyRect
983 * "This method is not currently implemented"
991 *****************************************************************************/
992 static HRESULT WINAPI
993 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
996 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
997 TRACE("(%p)->(%p)\n",This,Rect);
999 /* MSDN says it's not implemented. I could forward it to WineD3D,
1000 * then we'd implement it, but I don't think that's a good idea
1001 * (Stefan Dösinger)
1004 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
1006 return DDERR_UNSUPPORTED; /* unchecked */
1009 /*****************************************************************************
1010 * IDirectDrawSurface7::GetDC
1012 * Returns a GDI device context for the surface
1015 * hdc: Address of a HDC variable to store the dc to
1019 * DDERR_INVALIDPARAMS if hdc is NULL
1020 * For details, see IWineD3DSurface::GetDC
1022 *****************************************************************************/
1023 static HRESULT WINAPI
1024 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
1027 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1029 TRACE("(%p)->(%p): Relay\n", This, hdc);
1032 return DDERR_INVALIDPARAMS;
1034 EnterCriticalSection(&ddraw_cs);
1035 hr = IWineD3DSurface_GetDC(This->WineD3DSurface,
1037 LeaveCriticalSection(&ddraw_cs);
1041 /*****************************************************************************
1042 * IDirectDrawSurface7::ReleaseDC
1044 * Releases the DC that was constructed with GetDC
1047 * hdc: HDC to release
1051 * For more details, see IWineD3DSurface::ReleaseDC
1053 *****************************************************************************/
1054 static HRESULT WINAPI
1055 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
1058 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1060 TRACE("(%p)->(%p): Relay\n", This, hdc);
1062 EnterCriticalSection(&ddraw_cs);
1063 hr = IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
1064 LeaveCriticalSection(&ddraw_cs);
1068 /*****************************************************************************
1069 * IDirectDrawSurface7::GetCaps
1071 * Returns the surface's caps
1074 * Caps: Address to write the caps to
1078 * DDERR_INVALIDPARAMS if Caps is NULL
1080 *****************************************************************************/
1081 static HRESULT WINAPI
1082 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
1085 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1086 TRACE("(%p)->(%p)\n",This,Caps);
1089 return DDERR_INVALIDPARAMS;
1091 *Caps = This->surface_desc.ddsCaps;
1095 /*****************************************************************************
1096 * IDirectDrawSurface7::SetPriority
1098 * Sets a texture priority for managed textures.
1101 * Priority: The new priority
1105 * For more details, see IWineD3DSurface::SetPriority
1107 *****************************************************************************/
1108 static HRESULT WINAPI
1109 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
1111 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1113 TRACE("(%p)->(%d): Relay!\n",This,Priority);
1115 EnterCriticalSection(&ddraw_cs);
1116 hr = IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
1117 LeaveCriticalSection(&ddraw_cs);
1121 /*****************************************************************************
1122 * IDirectDrawSurface7::GetPriority
1124 * Returns the surface's priority
1127 * Priority: Address of a variable to write the priority to
1131 * DDERR_INVALIDPARAMS if Priority == NULL
1132 * For more details, see IWineD3DSurface::GetPriority
1134 *****************************************************************************/
1135 static HRESULT WINAPI
1136 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1139 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1140 TRACE("(%p)->(%p): Relay\n",This,Priority);
1144 return DDERR_INVALIDPARAMS;
1147 EnterCriticalSection(&ddraw_cs);
1148 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1149 LeaveCriticalSection(&ddraw_cs);
1153 /*****************************************************************************
1154 * IDirectDrawSurface7::SetPrivateData
1156 * Stores some data in the surface that is intended for the application's
1160 * tag: GUID that identifies the data
1161 * Data: Pointer to the private data
1162 * Size: Size of the private data
1167 * For more details, see IWineD3DSurface::SetPrivateData
1169 *****************************************************************************/
1170 static HRESULT WINAPI
1171 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1177 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1179 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1181 EnterCriticalSection(&ddraw_cs);
1182 hr = IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1187 LeaveCriticalSection(&ddraw_cs);
1190 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1195 /*****************************************************************************
1196 * IDirectDrawSurface7::GetPrivateData
1198 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1201 * tag: GUID of the data to return
1202 * Data: Address where to write the data to
1203 * Size: Size of the buffer at Data
1207 * DDERR_INVALIDPARAMS if Data is NULL
1208 * For more details, see IWineD3DSurface::GetPrivateData
1210 *****************************************************************************/
1211 static HRESULT WINAPI
1212 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1217 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1219 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1222 return DDERR_INVALIDPARAMS;
1224 EnterCriticalSection(&ddraw_cs);
1225 hr = IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1229 LeaveCriticalSection(&ddraw_cs);
1233 /*****************************************************************************
1234 * IDirectDrawSurface7::FreePrivateData
1236 * Frees private data stored in the surface
1239 * tag: Tag of the data to free
1243 * For more details, see IWineD3DSurface::FreePrivateData
1245 *****************************************************************************/
1246 static HRESULT WINAPI
1247 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1250 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1252 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1254 EnterCriticalSection(&ddraw_cs);
1255 hr = IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1256 LeaveCriticalSection(&ddraw_cs);
1260 /*****************************************************************************
1261 * IDirectDrawSurface7::PageLock
1263 * Prevents a sysmem surface from being paged out
1266 * Flags: Not used, must be 0(unchecked)
1269 * DD_OK, because it's a stub
1271 *****************************************************************************/
1272 static HRESULT WINAPI
1273 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1276 TRACE("(%p)->(%x)\n", iface, Flags);
1278 /* This is Windows memory management related - we don't need this */
1282 /*****************************************************************************
1283 * IDirectDrawSurface7::PageUnlock
1285 * Allows a sysmem surface to be paged out
1288 * Flags: Not used, must be 0(unckeched)
1291 * DD_OK, because it's a stub
1293 *****************************************************************************/
1294 static HRESULT WINAPI
1295 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1298 TRACE("(%p)->(%x)\n", iface, Flags);
1303 /*****************************************************************************
1304 * IDirectDrawSurface7::BltBatch
1306 * An unimplemented function
1314 *****************************************************************************/
1315 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1317 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1319 /* MSDN: "not currently implemented" */
1320 return DDERR_UNSUPPORTED;
1323 /*****************************************************************************
1324 * IDirectDrawSurface7::EnumAttachedSurfaces
1326 * Enumerates all surfaces attached to this surface
1329 * context: Pointer to pass unmodified to the callback
1330 * cb: Callback function to call for each surface
1334 * DDERR_INVALIDPARAMS if cb is NULL
1336 *****************************************************************************/
1337 static HRESULT WINAPI
1338 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1340 LPDDENUMSURFACESCALLBACK7 cb)
1342 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1343 IDirectDrawSurfaceImpl *surf;
1344 DDSURFACEDESC2 desc;
1347 /* Attached surfaces aren't handled in WineD3D */
1348 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1351 return DDERR_INVALIDPARAMS;
1353 EnterCriticalSection(&ddraw_cs);
1354 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
1356 surf = This->complex_array[i];
1359 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1360 desc = surf->surface_desc;
1361 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1362 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1364 LeaveCriticalSection(&ddraw_cs);
1369 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1371 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1372 desc = surf->surface_desc;
1373 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1374 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1376 LeaveCriticalSection(&ddraw_cs);
1381 TRACE(" end of enumeration.\n");
1383 LeaveCriticalSection(&ddraw_cs);
1387 /*****************************************************************************
1388 * IDirectDrawSurface7::EnumOverlayZOrders
1390 * "Enumerates the overlay surfaces on the specified destination"
1393 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1394 * context: context to pass back to the callback
1395 * cb: callback function to call for each enumerated surface
1398 * DD_OK, because it's a stub
1400 *****************************************************************************/
1401 static HRESULT WINAPI
1402 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1405 LPDDENUMSURFACESCALLBACK7 cb)
1407 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1412 /*****************************************************************************
1413 * IDirectDrawSurface7::GetBltStatus
1415 * Returns the blitting status
1418 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1421 * See IWineD3DSurface::Blt
1423 *****************************************************************************/
1424 static HRESULT WINAPI
1425 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1428 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1430 TRACE("(%p)->(%x): Relay\n", This, Flags);
1432 EnterCriticalSection(&ddraw_cs);
1433 hr = IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1434 LeaveCriticalSection(&ddraw_cs);
1437 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1442 /*****************************************************************************
1443 * IDirectDrawSurface7::GetColorKey
1445 * Returns the color key assigned to the surface
1449 * CKey: Address to store the key to
1453 * DDERR_INVALIDPARAMS if CKey is NULL
1455 *****************************************************************************/
1456 static HRESULT WINAPI
1457 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1461 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1462 * isn't there? That's like saying that an int isn't there. (Which MS
1463 * has done in other docs.) */
1464 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1465 TRACE("(%p)->(%08x,%p)\n", This, Flags, CKey);
1468 return DDERR_INVALIDPARAMS;
1470 EnterCriticalSection(&ddraw_cs);
1473 case DDCKEY_DESTBLT:
1474 *CKey = This->surface_desc.ddckCKDestBlt;
1477 case DDCKEY_DESTOVERLAY:
1478 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1482 *CKey = This->surface_desc.ddckCKSrcBlt;
1485 case DDCKEY_SRCOVERLAY:
1486 *CKey = This->surface_desc.ddckCKSrcOverlay;
1490 LeaveCriticalSection(&ddraw_cs);
1491 return DDERR_INVALIDPARAMS;
1494 LeaveCriticalSection(&ddraw_cs);
1498 /*****************************************************************************
1499 * IDirectDrawSurface7::GetFlipStatus
1501 * Returns the flipping status of the surface
1504 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1507 * See IWineD3DSurface::GetFlipStatus
1509 *****************************************************************************/
1510 static HRESULT WINAPI
1511 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1514 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1516 TRACE("(%p)->(%x): Relay\n", This, Flags);
1518 EnterCriticalSection(&ddraw_cs);
1519 hr = IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1520 LeaveCriticalSection(&ddraw_cs);
1523 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1528 /*****************************************************************************
1529 * IDirectDrawSurface7::GetOverlayPosition
1531 * Returns the display coordinates of a visible and active overlay surface
1538 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1539 *****************************************************************************/
1540 static HRESULT WINAPI
1541 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1544 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1546 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1548 EnterCriticalSection(&ddraw_cs);
1549 hr = IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1552 LeaveCriticalSection(&ddraw_cs);
1556 /*****************************************************************************
1557 * IDirectDrawSurface7::GetPixelFormat
1559 * Returns the pixel format of the Surface
1562 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1563 * format should be written
1567 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1569 *****************************************************************************/
1570 static HRESULT WINAPI
1571 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1572 DDPIXELFORMAT *PixelFormat)
1574 /* What is DDERR_INVALIDSURFACETYPE for here? */
1575 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1576 TRACE("(%p)->(%p)\n",This,PixelFormat);
1579 return DDERR_INVALIDPARAMS;
1581 EnterCriticalSection(&ddraw_cs);
1582 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1583 LeaveCriticalSection(&ddraw_cs);
1589 /*****************************************************************************
1590 * IDirectDrawSurface7::GetSurfaceDesc
1592 * Returns the description of this surface
1595 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1600 * DDERR_INVALIDPARAMS if DDSD is NULL
1602 *****************************************************************************/
1603 static HRESULT WINAPI
1604 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1605 DDSURFACEDESC2 *DDSD)
1607 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1609 TRACE("(%p)->(%p)\n",This,DDSD);
1612 return DDERR_INVALIDPARAMS;
1614 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
1616 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
1617 return DDERR_INVALIDPARAMS;
1620 EnterCriticalSection(&ddraw_cs);
1621 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1622 TRACE("Returning surface desc:\n");
1623 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1625 LeaveCriticalSection(&ddraw_cs);
1629 /*****************************************************************************
1630 * IDirectDrawSurface7::Initialize
1632 * Initializes the surface. This is a no-op in Wine
1635 * DD: Pointer to an DirectDraw interface
1636 * DDSD: Surface description for initialization
1639 * DDERR_ALREADYINITIALIZED
1641 *****************************************************************************/
1642 static HRESULT WINAPI
1643 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1645 DDSURFACEDESC2 *DDSD)
1647 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1648 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1649 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1651 return DDERR_ALREADYINITIALIZED;
1654 /*****************************************************************************
1655 * IDirectDrawSurface7::IsLost
1657 * Checks if the surface is lost
1660 * DD_OK, if the surface is useable
1661 * DDERR_ISLOST if the surface is lost
1662 * See IWineD3DSurface::IsLost for more details
1664 *****************************************************************************/
1665 static HRESULT WINAPI
1666 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1668 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1670 TRACE("(%p)\n", This);
1672 EnterCriticalSection(&ddraw_cs);
1673 /* We lose the surface if the implementation was changed */
1674 if(This->ImplType != This->ddraw->ImplType)
1676 /* But this shouldn't happen. When we change the implementation,
1677 * all surfaces are re-created automatically, and their content
1680 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1681 LeaveCriticalSection(&ddraw_cs);
1682 return DDERR_SURFACELOST;
1685 hr = IWineD3DSurface_IsLost(This->WineD3DSurface);
1686 LeaveCriticalSection(&ddraw_cs);
1689 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1690 * WineD3D uses the same error for surfaces
1692 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
1697 /*****************************************************************************
1698 * IDirectDrawSurface7::Restore
1700 * Restores a lost surface. This makes the surface usable again, but
1701 * doesn't reload its old contents
1705 * See IWineD3DSurface::Restore for more details
1707 *****************************************************************************/
1708 static HRESULT WINAPI
1709 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1711 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1713 TRACE("(%p)\n", This);
1715 EnterCriticalSection(&ddraw_cs);
1716 if(This->ImplType != This->ddraw->ImplType)
1718 /* Call the recreation callback. Make sure to AddRef first */
1719 IDirectDrawSurface_AddRef(iface);
1720 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1721 &This->surface_desc,
1722 NULL /* Not needed */);
1724 hr = IWineD3DSurface_Restore(This->WineD3DSurface);
1725 LeaveCriticalSection(&ddraw_cs);
1729 /*****************************************************************************
1730 * IDirectDrawSurface7::SetOverlayPosition
1732 * Changes the display coordinates of an overlay surface
1739 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1740 *****************************************************************************/
1741 static HRESULT WINAPI
1742 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1746 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1748 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1750 EnterCriticalSection(&ddraw_cs);
1751 hr = IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1754 LeaveCriticalSection(&ddraw_cs);
1758 /*****************************************************************************
1759 * IDirectDrawSurface7::UpdateOverlay
1761 * Modifies the attributes of an overlay surface.
1764 * SrcRect: The section of the source being used for the overlay
1765 * DstSurface: Address of the surface that is overlaid
1766 * DstRect: Place of the overlay
1767 * Flags: some DDOVER_* flags
1770 * DDERR_UNSUPPORTED, because we don't support overlays
1772 *****************************************************************************/
1773 static HRESULT WINAPI
1774 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1776 IDirectDrawSurface7 *DstSurface,
1781 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1782 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1784 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1786 EnterCriticalSection(&ddraw_cs);
1787 hr = IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1789 Dst ? Dst->WineD3DSurface : NULL,
1792 (WINEDDOVERLAYFX *) FX);
1793 LeaveCriticalSection(&ddraw_cs);
1797 /*****************************************************************************
1798 * IDirectDrawSurface7::UpdateOverlayDisplay
1800 * The DX7 sdk says that it's not implemented
1805 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1807 *****************************************************************************/
1808 static HRESULT WINAPI
1809 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1812 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1813 TRACE("(%p)->(%x)\n", This, Flags);
1814 return DDERR_UNSUPPORTED;
1817 /*****************************************************************************
1818 * IDirectDrawSurface7::UpdateOverlayZOrder
1820 * Sets an overlay's Z order
1823 * Flags: DDOVERZ_* flags
1824 * DDSRef: Defines the relative position in the overlay chain
1827 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1829 *****************************************************************************/
1830 static HRESULT WINAPI
1831 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1833 IDirectDrawSurface7 *DDSRef)
1835 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1837 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1839 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1840 EnterCriticalSection(&ddraw_cs);
1841 hr = IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1843 Ref ? Ref->WineD3DSurface : NULL);
1844 LeaveCriticalSection(&ddraw_cs);
1848 /*****************************************************************************
1849 * IDirectDrawSurface7::GetDDInterface
1851 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1852 * surface belongs to
1855 * DD: Address to write the interface pointer to
1859 * DDERR_INVALIDPARAMS if DD is NULL
1861 *****************************************************************************/
1862 static HRESULT WINAPI
1863 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1866 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1868 TRACE("(%p)->(%p)\n",This,DD);
1871 return DDERR_INVALIDPARAMS;
1873 switch(This->version)
1876 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1877 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1881 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1882 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1886 *((IDirectDraw2 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
1887 IDirectDraw_AddRef( *(IDirectDraw2 **) DD);
1891 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1892 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1900 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1901 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1903 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1904 volatile IDirectDrawSurfaceImpl* vThis = This;
1906 TRACE("(%p)\n",This);
1907 EnterCriticalSection(&ddraw_cs);
1908 /* A uniqueness value of 0 is apparently special.
1909 * This needs to be checked.
1910 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1913 DWORD old_uniqueness_value = vThis->uniqueness_value;
1914 DWORD new_uniqueness_value = old_uniqueness_value+1;
1916 if (old_uniqueness_value == 0) break;
1917 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1919 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1920 old_uniqueness_value,
1921 new_uniqueness_value)
1922 == old_uniqueness_value)
1926 LeaveCriticalSection(&ddraw_cs);
1930 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1932 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1934 TRACE("(%p)->(%p)\n",This,pValue);
1935 EnterCriticalSection(&ddraw_cs);
1936 *pValue = This->uniqueness_value;
1937 LeaveCriticalSection(&ddraw_cs);
1941 /*****************************************************************************
1942 * IDirectDrawSurface7::SetLOD
1944 * Sets the level of detail of a texture
1947 * MaxLOD: LOD to set
1951 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1953 *****************************************************************************/
1954 static HRESULT WINAPI
1955 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1958 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1960 TRACE("(%p)->(%d)\n", This, MaxLOD);
1962 EnterCriticalSection(&ddraw_cs);
1963 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1965 LeaveCriticalSection(&ddraw_cs);
1966 return DDERR_INVALIDOBJECT;
1969 if(!This->wineD3DTexture)
1971 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1972 LeaveCriticalSection(&ddraw_cs);
1973 return DDERR_INVALIDOBJECT;
1976 hr = IWineD3DBaseTexture_SetLOD(This->wineD3DTexture,
1978 LeaveCriticalSection(&ddraw_cs);
1982 /*****************************************************************************
1983 * IDirectDrawSurface7::GetLOD
1985 * Returns the level of detail of a Direct3D texture
1988 * MaxLOD: Address to write the LOD to
1992 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1993 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1995 *****************************************************************************/
1996 static HRESULT WINAPI
1997 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
2000 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2001 TRACE("(%p)->(%p)\n", This, MaxLOD);
2004 return DDERR_INVALIDPARAMS;
2006 EnterCriticalSection(&ddraw_cs);
2007 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2009 LeaveCriticalSection(&ddraw_cs);
2010 return DDERR_INVALIDOBJECT;
2013 *MaxLOD = IWineD3DBaseTexture_GetLOD(This->wineD3DTexture);
2014 LeaveCriticalSection(&ddraw_cs);
2018 /*****************************************************************************
2019 * IDirectDrawSurface7::BltFast
2021 * Performs a fast Blit.
2024 * dstx: The x coordinate to blit to on the destination
2025 * dsty: The y coordinate to blit to on the destination
2026 * Source: The source surface
2027 * rsrc: The source rectangle
2028 * trans: Type of transfer. Some DDBLTFAST_* flags
2032 * For more details, see IWineD3DSurface::BltFast
2034 *****************************************************************************/
2035 static HRESULT WINAPI
2036 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
2039 IDirectDrawSurface7 *Source,
2043 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2045 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
2046 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
2048 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2053 if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right ||
2054 rsrc->right > src->surface_desc.dwWidth ||
2055 rsrc->bottom > src->surface_desc.dwHeight)
2057 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2058 return DDERR_INVALIDRECT;
2060 if(dstx + rsrc->right - rsrc->left > This->surface_desc.dwWidth ||
2061 dsty + rsrc->bottom - rsrc->top > This->surface_desc.dwHeight)
2063 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2064 return DDERR_INVALIDRECT;
2069 if(dstx + src->surface_desc.dwWidth > This->surface_desc.dwWidth ||
2070 dsty + src->surface_desc.dwHeight > This->surface_desc.dwHeight)
2072 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2073 return DDERR_INVALIDRECT;
2077 EnterCriticalSection(&ddraw_cs);
2078 hr = IWineD3DSurface_BltFast(This->WineD3DSurface,
2080 src ? src->WineD3DSurface : NULL,
2083 LeaveCriticalSection(&ddraw_cs);
2086 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
2087 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
2092 /*****************************************************************************
2093 * IDirectDrawSurface7::GetClipper
2095 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2099 * Clipper: Address to store the interface pointer at
2103 * DDERR_INVALIDPARAMS if Clipper is NULL
2104 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2106 *****************************************************************************/
2107 static HRESULT WINAPI
2108 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
2109 IDirectDrawClipper **Clipper)
2111 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2112 TRACE("(%p)->(%p)\n", This, Clipper);
2116 LeaveCriticalSection(&ddraw_cs);
2117 return DDERR_INVALIDPARAMS;
2120 EnterCriticalSection(&ddraw_cs);
2121 if(This->clipper == NULL)
2123 LeaveCriticalSection(&ddraw_cs);
2124 return DDERR_NOCLIPPERATTACHED;
2127 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
2128 IDirectDrawClipper_AddRef(*Clipper);
2129 LeaveCriticalSection(&ddraw_cs);
2133 /*****************************************************************************
2134 * IDirectDrawSurface7::SetClipper
2136 * Sets a clipper for the surface
2139 * Clipper: IDirectDrawClipper interface of the clipper to set
2144 *****************************************************************************/
2145 static HRESULT WINAPI
2146 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
2147 IDirectDrawClipper *Clipper)
2149 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2150 IDirectDrawClipperImpl *oldClipper = This->clipper;
2152 TRACE("(%p)->(%p)\n",This,Clipper);
2154 EnterCriticalSection(&ddraw_cs);
2155 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
2157 LeaveCriticalSection(&ddraw_cs);
2161 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
2163 if (Clipper != NULL)
2164 IDirectDrawClipper_AddRef(Clipper);
2166 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper, IDirectDrawClipper));
2168 hr = IWineD3DSurface_SetClipper(This->WineD3DSurface, This->clipper ? This->clipper->wineD3DClipper : NULL);
2169 LeaveCriticalSection(&ddraw_cs);
2173 /*****************************************************************************
2174 * IDirectDrawSurface7::SetSurfaceDesc
2176 * Sets the surface description. It can override the pixel format, the surface
2178 * It's not really tested.
2181 * DDSD: Pointer to the new surface description to set
2186 * DDERR_INVALIDPARAMS if DDSD is NULL
2188 *****************************************************************************/
2189 static HRESULT WINAPI
2190 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
2191 DDSURFACEDESC2 *DDSD,
2194 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2195 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
2197 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
2200 return DDERR_INVALIDPARAMS;
2202 EnterCriticalSection(&ddraw_cs);
2203 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
2205 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
2207 if(newFormat == WINED3DFMT_UNKNOWN)
2209 ERR("Requested to set an unknown pixelformat\n");
2210 LeaveCriticalSection(&ddraw_cs);
2211 return DDERR_INVALIDPARAMS;
2213 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
2215 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
2219 LeaveCriticalSection(&ddraw_cs);
2224 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
2226 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2228 (WINEDDCOLORKEY *) &DDSD->u3.ddckCKDestOverlay);
2230 if (DDSD->dwFlags & DDSD_CKDESTBLT)
2232 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2234 (WINEDDCOLORKEY *) &DDSD->ddckCKDestBlt);
2236 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
2238 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2240 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcOverlay);
2242 if (DDSD->dwFlags & DDSD_CKSRCBLT)
2244 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2246 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcBlt);
2248 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
2250 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
2251 if(hr != WINED3D_OK)
2253 /* No need for a trace here, wined3d does that for us */
2254 LeaveCriticalSection(&ddraw_cs);
2257 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2258 default: break; /* Go on */
2264 This->surface_desc = *DDSD;
2266 LeaveCriticalSection(&ddraw_cs);
2270 /*****************************************************************************
2271 * IDirectDrawSurface7::GetPalette
2273 * Returns the IDirectDrawPalette interface of the palette currently assigned
2277 * Pal: Address to write the interface pointer to
2281 * DDERR_INVALIDPARAMS if Pal is NULL
2283 *****************************************************************************/
2284 static HRESULT WINAPI
2285 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
2286 IDirectDrawPalette **Pal)
2288 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2289 IWineD3DPalette *wPal;
2291 TRACE("(%p)->(%p): Relay\n", This, Pal);
2294 return DDERR_INVALIDPARAMS;
2296 EnterCriticalSection(&ddraw_cs);
2297 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
2300 LeaveCriticalSection(&ddraw_cs);
2306 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2311 hr = DDERR_NOPALETTEATTACHED;
2314 LeaveCriticalSection(&ddraw_cs);
2318 /*****************************************************************************
2321 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2322 * recursively in the surface tree
2324 *****************************************************************************/
2328 WINEDDCOLORKEY *CKey;
2332 static HRESULT WINAPI
2333 SetColorKeyEnum(IDirectDrawSurface7 *surface,
2334 DDSURFACEDESC2 *desc,
2337 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, surface);
2338 struct SCKContext *ctx = context;
2341 hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2346 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
2350 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
2353 IDirectDrawSurface7_Release(surface);
2354 return DDENUMRET_OK;
2357 /*****************************************************************************
2358 * IDirectDrawSurface7::SetColorKey
2360 * Sets the color keying options for the surface. Observations showed that
2361 * in case of complex surfaces the color key has to be assigned to all
2366 * CKey: The new color key
2370 * See IWineD3DSurface::SetColorKey for details
2372 *****************************************************************************/
2373 static HRESULT WINAPI
2374 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2378 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2379 struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) CKey, Flags };
2380 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2382 EnterCriticalSection(&ddraw_cs);
2385 switch (Flags & ~DDCKEY_COLORSPACE)
2387 case DDCKEY_DESTBLT:
2388 This->surface_desc.ddckCKDestBlt = *CKey;
2389 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
2392 case DDCKEY_DESTOVERLAY:
2393 This->surface_desc.u3.ddckCKDestOverlay = *CKey;
2394 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
2397 case DDCKEY_SRCOVERLAY:
2398 This->surface_desc.ddckCKSrcOverlay = *CKey;
2399 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
2403 This->surface_desc.ddckCKSrcBlt = *CKey;
2404 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
2408 LeaveCriticalSection(&ddraw_cs);
2409 return DDERR_INVALIDPARAMS;
2414 switch (Flags & ~DDCKEY_COLORSPACE)
2416 case DDCKEY_DESTBLT:
2417 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
2420 case DDCKEY_DESTOVERLAY:
2421 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
2424 case DDCKEY_SRCOVERLAY:
2425 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
2429 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
2433 LeaveCriticalSection(&ddraw_cs);
2434 return DDERR_INVALIDPARAMS;
2437 ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2440 IDirectDrawSurface7_EnumAttachedSurfaces(iface,
2443 LeaveCriticalSection(&ddraw_cs);
2446 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2447 default: return ctx.ret;
2451 /*****************************************************************************
2452 * IDirectDrawSurface7::SetPalette
2454 * Assigns a DirectDrawPalette object to the surface
2457 * Pal: Interface to the palette to set
2462 *****************************************************************************/
2463 static HRESULT WINAPI
2464 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2465 IDirectDrawPalette *Pal)
2467 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2468 IDirectDrawPalette *oldPal;
2469 IDirectDrawSurfaceImpl *surf;
2470 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2472 TRACE("(%p)->(%p)\n", This, Pal);
2474 /* Find the old palette */
2475 EnterCriticalSection(&ddraw_cs);
2476 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2477 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
2479 LeaveCriticalSection(&ddraw_cs);
2482 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2484 /* Set the new Palette */
2485 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2486 PalImpl ? PalImpl->wineD3DPalette : NULL);
2487 /* AddRef the Palette */
2488 if(Pal) IDirectDrawPalette_AddRef(Pal);
2490 /* Release the old palette */
2491 if(oldPal) IDirectDrawPalette_Release(oldPal);
2493 /* If this is a front buffer, also update the back buffers
2494 * TODO: How do things work for palettized cube textures?
2496 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2498 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2499 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
2504 IDirectDrawSurface7 *attach;
2506 hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2513 TRACE("Setting palette on %p\n", attach);
2514 IDirectDrawSurface7_SetPalette(attach,
2516 surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, attach);
2517 IDirectDrawSurface7_Release(attach);
2521 LeaveCriticalSection(&ddraw_cs);
2525 /*****************************************************************************
2527 *****************************************************************************/
2529 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2532 IDirectDrawSurfaceImpl_QueryInterface,
2533 IDirectDrawSurfaceImpl_AddRef,
2534 IDirectDrawSurfaceImpl_Release,
2535 /*** IDirectDrawSurface ***/
2536 IDirectDrawSurface7Impl_AddAttachedSurface,
2537 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2538 IDirectDrawSurfaceImpl_Blt,
2539 IDirectDrawSurfaceImpl_BltBatch,
2540 IDirectDrawSurfaceImpl_BltFast,
2541 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2542 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2543 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2544 IDirectDrawSurfaceImpl_Flip,
2545 IDirectDrawSurfaceImpl_GetAttachedSurface,
2546 IDirectDrawSurfaceImpl_GetBltStatus,
2547 IDirectDrawSurfaceImpl_GetCaps,
2548 IDirectDrawSurfaceImpl_GetClipper,
2549 IDirectDrawSurfaceImpl_GetColorKey,
2550 IDirectDrawSurfaceImpl_GetDC,
2551 IDirectDrawSurfaceImpl_GetFlipStatus,
2552 IDirectDrawSurfaceImpl_GetOverlayPosition,
2553 IDirectDrawSurfaceImpl_GetPalette,
2554 IDirectDrawSurfaceImpl_GetPixelFormat,
2555 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2556 IDirectDrawSurfaceImpl_Initialize,
2557 IDirectDrawSurfaceImpl_IsLost,
2558 IDirectDrawSurfaceImpl_Lock,
2559 IDirectDrawSurfaceImpl_ReleaseDC,
2560 IDirectDrawSurfaceImpl_Restore,
2561 IDirectDrawSurfaceImpl_SetClipper,
2562 IDirectDrawSurfaceImpl_SetColorKey,
2563 IDirectDrawSurfaceImpl_SetOverlayPosition,
2564 IDirectDrawSurfaceImpl_SetPalette,
2565 IDirectDrawSurfaceImpl_Unlock,
2566 IDirectDrawSurfaceImpl_UpdateOverlay,
2567 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2568 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2569 /*** IDirectDrawSurface2 ***/
2570 IDirectDrawSurfaceImpl_GetDDInterface,
2571 IDirectDrawSurfaceImpl_PageLock,
2572 IDirectDrawSurfaceImpl_PageUnlock,
2573 /*** IDirectDrawSurface3 ***/
2574 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2575 /*** IDirectDrawSurface4 ***/
2576 IDirectDrawSurfaceImpl_SetPrivateData,
2577 IDirectDrawSurfaceImpl_GetPrivateData,
2578 IDirectDrawSurfaceImpl_FreePrivateData,
2579 IDirectDrawSurfaceImpl_GetUniquenessValue,
2580 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2581 /*** IDirectDrawSurface7 ***/
2582 IDirectDrawSurfaceImpl_SetPriority,
2583 IDirectDrawSurfaceImpl_GetPriority,
2584 IDirectDrawSurfaceImpl_SetLOD,
2585 IDirectDrawSurfaceImpl_GetLOD