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 *****************************************************************************/
73 static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, REFIID riid, void **obj)
75 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
77 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
81 return DDERR_INVALIDPARAMS;
83 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
84 if (IsEqualGUID(riid, &IID_IUnknown)
85 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
86 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
88 IUnknown_AddRef(iface);
90 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
93 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
94 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
95 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
97 IUnknown_AddRef(iface);
98 *obj = &This->IDirectDrawSurface3_vtbl;
99 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
102 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
104 IUnknown_AddRef(iface);
105 *obj = &This->IDirectDrawGammaControl_vtbl;
106 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
109 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
110 IsEqualGUID(riid, &IID_IDirect3DHALDevice)||
111 IsEqualGUID(riid, &IID_IDirect3DRGBDevice) )
113 IDirect3DDevice7 *d3d;
115 /* Call into IDirect3D7 for creation */
116 IDirect3D7_CreateDevice((IDirect3D7 *)&This->ddraw->IDirect3D7_vtbl, riid, (IDirectDrawSurface7 *)This, &d3d);
120 *obj = (IDirect3DDevice *)&((IDirect3DDeviceImpl *)d3d)->IDirect3DDevice_vtbl;
121 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
125 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
126 return E_NOINTERFACE;
128 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
129 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
131 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
133 *obj = &This->IDirect3DTexture_vtbl;
134 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
138 *obj = &This->IDirect3DTexture2_vtbl;
139 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
141 IUnknown_AddRef( (IUnknown *) *obj);
145 ERR("No interface\n");
146 return E_NOINTERFACE;
149 static HRESULT WINAPI ddraw_surface3_QueryInterface(IDirectDrawSurface3 *iface, REFIID riid, void **object)
151 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
153 return ddraw_surface7_QueryInterface((IDirectDrawSurface7 *)surface_from_surface3(iface), riid, object);
156 /*****************************************************************************
157 * IDirectDrawSurface7::AddRef
159 * A normal addref implementation
164 *****************************************************************************/
165 static ULONG WINAPI ddraw_surface7_AddRef(IDirectDrawSurface7 *iface)
167 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
168 ULONG refCount = InterlockedIncrement(&This->ref);
170 if (refCount == 1 && This->WineD3DSurface)
172 EnterCriticalSection(&ddraw_cs);
173 IWineD3DSurface_AddRef(This->WineD3DSurface);
174 LeaveCriticalSection(&ddraw_cs);
177 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
181 static ULONG WINAPI ddraw_surface3_AddRef(IDirectDrawSurface3 *iface)
183 TRACE("iface %p.\n", iface);
185 return ddraw_surface7_AddRef((IDirectDrawSurface7 *)surface_from_surface3(iface));
188 /*****************************************************************************
189 * ddraw_surface_destroy
191 * A helper function for IDirectDrawSurface7::Release
193 * Frees the surface, regardless of its refcount.
194 * See IDirectDrawSurface7::Release for more information
197 * This: Surface to free
199 *****************************************************************************/
200 void ddraw_surface_destroy(IDirectDrawSurfaceImpl *This)
202 TRACE("(%p)\n", This);
204 /* Check the refcount and give a warning */
207 /* This can happen when a complex surface is destroyed,
208 * because the 2nd surface was addref()ed when the app
209 * called GetAttachedSurface
211 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
214 /* Check for attached surfaces and detach them */
215 if(This->first_attached != This)
217 /* Well, this shouldn't happen: The surface being attached is addref()ed
218 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
219 * is called, because the refcount is held. It looks like the app released()
220 * it often enough to force this
222 IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)This->first_attached;
223 IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)This;
225 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
227 /* The refcount will drop to -1 here */
228 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
230 ERR("(%p) DeleteAttachedSurface failed!\n", This);
234 while(This->next_attached != NULL)
236 IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)This;
237 IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)This->next_attached;
239 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
241 ERR("(%p) DeleteAttachedSurface failed!\n", This);
246 /* Now destroy the surface. Wait: It could have been released if we are a texture */
247 if(This->WineD3DSurface)
248 IWineD3DSurface_Release(This->WineD3DSurface);
250 /* Having a texture handle set implies that the device still exists */
253 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
254 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
257 /* Reduce the ddraw surface count */
258 InterlockedDecrement(&This->ddraw->surfaces);
259 list_remove(&This->surface_list_entry);
261 HeapFree(GetProcessHeap(), 0, This);
264 /*****************************************************************************
265 * IDirectDrawSurface7::Release
267 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
268 * surface is destroyed.
270 * Destroying the surface is a bit tricky. For the connection between
271 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
272 * It has a nice graph explaining the connection.
274 * What happens here is basically this:
275 * When a surface is destroyed, its WineD3DSurface is released,
276 * and the refcount of the DirectDraw interface is reduced by 1. If it has
277 * complex surfaces attached to it, then these surfaces are destroyed too,
278 * regardless of their refcount. If any surface being destroyed has another
279 * surface attached to it (with a "soft" attachment, not complex), then
280 * this surface is detached with DeleteAttachedSurface.
282 * When the surface is a texture, the WineD3DTexture is released.
283 * If the surface is the Direct3D render target, then the D3D
284 * capabilities of the WineD3DDevice are uninitialized, which causes the
285 * swapchain to be released.
287 * When a complex sublevel falls to ref zero, then this is ignored.
292 *****************************************************************************/
293 static ULONG WINAPI ddraw_surface7_Release(IDirectDrawSurface7 *iface)
295 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
297 TRACE("(%p) : Releasing from %d\n", This, This->ref);
298 ref = InterlockedDecrement(&This->ref);
303 IDirectDrawSurfaceImpl *surf;
304 IDirectDrawImpl *ddraw;
305 IUnknown *ifaceToRelease = This->ifaceToRelease;
308 /* Complex attached surfaces are destroyed implicitly when the root is released */
309 EnterCriticalSection(&ddraw_cs);
310 if(!This->is_complex_root)
312 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
313 LeaveCriticalSection(&ddraw_cs);
318 /* If it's a texture, destroy the WineD3DTexture.
319 * WineD3D will destroy the IParent interfaces
320 * of the sublevels, which destroys the WineD3DSurfaces.
321 * Set the surfaces to NULL to avoid destroying them again later
323 if(This->wineD3DTexture)
325 IWineD3DBaseTexture_Release(This->wineD3DTexture);
327 /* If it's the RenderTarget, destroy the d3ddevice */
328 else if(This->wineD3DSwapChain)
330 if((ddraw->d3d_initialized) && (This == ddraw->d3d_target)) {
331 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
333 /* Unset any index buffer, just to be sure */
334 IWineD3DDevice_SetIndexBuffer(ddraw->wineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
335 IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
336 IWineD3DDevice_SetVertexDeclaration(ddraw->wineD3DDevice, NULL);
337 for(i = 0; i < ddraw->numConvertedDecls; i++)
339 IWineD3DVertexDeclaration_Release(ddraw->decls[i].decl);
341 HeapFree(GetProcessHeap(), 0, ddraw->decls);
342 ddraw->numConvertedDecls = 0;
344 if (FAILED(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice, D3D7CB_DestroySwapChain)))
347 ERR("(%p) Failed to uninit 3D\n", This);
351 /* Free the d3d window if one was created */
352 if(ddraw->d3d_window != 0 && ddraw->d3d_window != ddraw->dest_window)
354 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
355 DestroyWindow(ddraw->d3d_window);
356 ddraw->d3d_window = 0;
358 /* Unset the pointers */
361 This->wineD3DSwapChain = NULL; /* Uninit3D releases the swapchain */
362 ddraw->d3d_initialized = FALSE;
363 ddraw->d3d_target = NULL;
365 IWineD3DDevice_UninitGDI(ddraw->wineD3DDevice, D3D7CB_DestroySwapChain);
366 This->wineD3DSwapChain = NULL;
369 /* Reset to the default surface implementation type. This is needed if apps use
370 * non render target surfaces and expect blits to work after destroying the render
373 * TODO: Recreate existing offscreen surfaces
375 ddraw->ImplType = DefaultSurfaceType;
377 /* Write a trace because D3D unloading was the reason for many
378 * crashes during development.
380 TRACE("(%p) D3D unloaded\n", This);
383 /* The refcount test shows that the palette is detached when the surface is destroyed */
384 IDirectDrawSurface7_SetPalette((IDirectDrawSurface7 *)This, NULL);
386 /* Loop through all complex attached surfaces,
389 * Yet again, only the root can have more than one complexly attached surface, all the others
390 * have a total of one;
392 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
394 if(!This->complex_array[i]) break;
396 surf = This->complex_array[i];
397 This->complex_array[i] = NULL;
400 IDirectDrawSurfaceImpl *destroy = surf;
401 surf = surf->complex_array[0]; /* Iterate through the "tree" */
402 ddraw_surface_destroy(destroy); /* Destroy it */
406 /* Destroy the root surface. */
407 ddraw_surface_destroy(This);
409 /* Reduce the ddraw refcount */
410 if(ifaceToRelease) IUnknown_Release(ifaceToRelease);
411 LeaveCriticalSection(&ddraw_cs);
417 static ULONG WINAPI ddraw_surface3_Release(IDirectDrawSurface3 *iface)
419 TRACE("iface %p.\n", iface);
421 return ddraw_surface7_Release((IDirectDrawSurface7 *)surface_from_surface3(iface));
424 /*****************************************************************************
425 * IDirectDrawSurface7::GetAttachedSurface
427 * Returns an attached surface with the requested caps. Surface attachment
428 * and complex surfaces are not clearly described by the MSDN or sdk,
429 * so this method is tricky and likely to contain problems.
430 * This implementation searches the complex list first, then the
433 * The chains are searched from This down to the last surface in the chain,
434 * not from the first element in the chain. The first surface found is
435 * returned. The MSDN says that this method fails if more than one surface
436 * matches the caps, but it is not sure if that is right. The attachment
437 * structure may not even allow two matching surfaces.
439 * The found surface is AddRef-ed before it is returned.
442 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
443 * Surface: Address to store the found surface
447 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
448 * DDERR_NOTFOUND if no surface was found
450 *****************************************************************************/
451 static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *iface,
452 DDSCAPS2 *Caps, IDirectDrawSurface7 **Surface)
454 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
455 IDirectDrawSurfaceImpl *surf;
459 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
460 EnterCriticalSection(&ddraw_cs);
462 if(This->version < 7)
464 /* Earlier dx apps put garbage into these members, clear them */
465 our_caps.dwCaps = Caps->dwCaps;
466 our_caps.dwCaps2 = 0;
467 our_caps.dwCaps3 = 0;
468 our_caps.dwCaps4 = 0;
475 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 */
477 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
479 surf = This->complex_array[i];
484 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
485 surf->surface_desc.ddsCaps.dwCaps,
486 surf->surface_desc.ddsCaps.dwCaps2,
487 surf->surface_desc.ddsCaps.dwCaps3,
488 surf->surface_desc.ddsCaps.dwCaps4);
491 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
492 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
494 /* MSDN: "This method fails if more than one surface is attached
495 * that matches the capabilities requested."
497 * Not sure how to test this.
500 TRACE("(%p): Returning surface %p\n", This, surf);
501 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
502 *Surface = (IDirectDrawSurface7 *)surf;
503 ddraw_surface7_AddRef(*Surface);
504 LeaveCriticalSection(&ddraw_cs);
509 /* Next, look at the attachment chain */
512 while( (surf = surf->next_attached) )
516 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
517 surf->surface_desc.ddsCaps.dwCaps,
518 surf->surface_desc.ddsCaps.dwCaps2,
519 surf->surface_desc.ddsCaps.dwCaps3,
520 surf->surface_desc.ddsCaps.dwCaps4);
523 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
524 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
526 TRACE("(%p): Returning surface %p\n", This, surf);
527 *Surface = (IDirectDrawSurface7 *)surf;
528 ddraw_surface7_AddRef(*Surface);
529 LeaveCriticalSection(&ddraw_cs);
534 TRACE("(%p) Didn't find a valid surface\n", This);
535 LeaveCriticalSection(&ddraw_cs);
538 return DDERR_NOTFOUND;
541 static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *iface,
542 DDSCAPS *caps, IDirectDrawSurface3 **attachment)
544 IDirectDrawSurface7 *attachment7;
548 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
550 caps2.dwCaps = caps->dwCaps;
555 hr = ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7 *)surface_from_surface3(iface),
556 &caps2, &attachment7);
557 if (FAILED(hr)) *attachment = NULL;
558 else *attachment = attachment7 ?
559 (IDirectDrawSurface3 *)&((IDirectDrawSurfaceImpl *)attachment7)->IDirectDrawSurface3_vtbl : NULL;
564 /*****************************************************************************
565 * IDirectDrawSurface7::Lock
567 * Locks the surface and returns a pointer to the surface's memory
570 * Rect: Rectangle to lock. If NULL, the whole surface is locked
571 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
572 * Flags: Locking flags, e.g Read only or write only
573 * h: An event handle that's not used and must be NULL
577 * DDERR_INVALIDPARAMS if DDSD is NULL
578 * For more details, see IWineD3DSurface::LockRect
580 *****************************************************************************/
581 static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface,
582 RECT *Rect, DDSURFACEDESC2 *DDSD, DWORD Flags, HANDLE h)
584 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
585 WINED3DLOCKED_RECT LockedRect;
587 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
590 return DDERR_INVALIDPARAMS;
592 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
593 EnterCriticalSection(&ddraw_cs);
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 /* Windows zeroes this if the rect is invalid */
616 || (Rect->left > Rect->right)
617 || (Rect->top > Rect->bottom)
618 || (Rect->right > This->surface_desc.dwWidth)
619 || (Rect->bottom > This->surface_desc.dwHeight))
621 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
622 LeaveCriticalSection(&ddraw_cs);
623 return DDERR_INVALIDPARAMS;
627 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
633 LeaveCriticalSection(&ddraw_cs);
636 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
637 * specific error. But since IWineD3DSurface::LockRect returns that error in this
638 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
639 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
640 * is much easier to do it in one place in ddraw
642 case WINED3DERR_INVALIDCALL: return DDERR_SURFACEBUSY;
647 /* Override the memory area. The pitch should be set already. Strangely windows
648 * does not set the LPSURFACE flag on locked surfaces !?!.
649 * DDSD->dwFlags |= DDSD_LPSURFACE;
651 This->surface_desc.lpSurface = LockedRect.pBits;
652 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
654 TRACE("locked surface returning description :\n");
655 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
657 LeaveCriticalSection(&ddraw_cs);
661 static HRESULT WINAPI ddraw_surface3_Lock(IDirectDrawSurface3 *iface, RECT *rect,
662 DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h)
664 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
665 iface, wine_dbgstr_rect(rect), surface_desc, flags, h);
667 return ddraw_surface7_Lock((IDirectDrawSurface7 *)surface_from_surface3(iface),
668 rect, (DDSURFACEDESC2 *)surface_desc, flags, h);
671 /*****************************************************************************
672 * IDirectDrawSurface7::Unlock
674 * Unlocks an locked surface
677 * Rect: Not used by this implementation
681 * For more details, see IWineD3DSurface::UnlockRect
683 *****************************************************************************/
684 static HRESULT WINAPI ddraw_surface7_Unlock(IDirectDrawSurface7 *iface, RECT *pRect)
686 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
688 TRACE("(%p)->(%p)\n", This, pRect);
690 EnterCriticalSection(&ddraw_cs);
691 hr = IWineD3DSurface_UnlockRect(This->WineD3DSurface);
694 This->surface_desc.lpSurface = NULL;
696 LeaveCriticalSection(&ddraw_cs);
700 static HRESULT WINAPI ddraw_surface3_Unlock(IDirectDrawSurface3 *iface, void *data)
702 TRACE("iface %p, data %p.\n", iface, data);
704 /* data might not be the LPRECT of later versions, so drop it. */
705 return ddraw_surface7_Unlock((IDirectDrawSurface7 *)surface_from_surface3(iface), NULL);
708 /*****************************************************************************
709 * IDirectDrawSurface7::Flip
711 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
712 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
713 * the flip target is passed to WineD3D, even if the app didn't specify one
716 * DestOverride: Specifies the surface that will become the new front
717 * buffer. If NULL, the current back buffer is used
718 * Flags: some DirectDraw flags, see include/ddraw.h
722 * DDERR_NOTFLIPPABLE if no flip target could be found
723 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
724 * For more details, see IWineD3DSurface::Flip
726 *****************************************************************************/
727 static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *DestOverride, DWORD Flags)
729 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
730 IDirectDrawSurfaceImpl *Override = (IDirectDrawSurfaceImpl *)DestOverride;
731 IDirectDrawSurface7 *Override7;
733 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
735 /* Flip has to be called from a front buffer
736 * What about overlay surfaces, AFAIK they can flip too?
738 if( !(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_OVERLAY)) )
739 return DDERR_INVALIDOBJECT; /* Unchecked */
741 EnterCriticalSection(&ddraw_cs);
743 /* WineD3D doesn't keep track of attached surface, so find the target */
748 memset(&Caps, 0, sizeof(Caps));
749 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
750 hr = ddraw_surface7_GetAttachedSurface(iface, &Caps, &Override7);
753 ERR("Can't find a flip target\n");
754 LeaveCriticalSection(&ddraw_cs);
755 return DDERR_NOTFLIPPABLE; /* Unchecked */
757 Override = (IDirectDrawSurfaceImpl *)Override7;
759 /* For the GetAttachedSurface */
760 ddraw_surface7_Release(Override7);
763 hr = IWineD3DSurface_Flip(This->WineD3DSurface,
764 Override->WineD3DSurface,
766 LeaveCriticalSection(&ddraw_cs);
770 static HRESULT WINAPI ddraw_surface3_Flip(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *dst, DWORD flags)
772 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
774 return ddraw_surface7_Flip((IDirectDrawSurface7 *)surface_from_surface3(iface),
775 dst ? (IDirectDrawSurface7 *)surface_from_surface3(dst) : NULL, flags);
778 /*****************************************************************************
779 * IDirectDrawSurface7::Blt
781 * Performs a blit on the surface
784 * DestRect: Destination rectangle, can be NULL
785 * SrcSurface: Source surface, can be NULL
786 * SrcRect: Source rectangle, can be NULL
788 * DDBltFx: Some extended blt parameters, connected to the flags
792 * See IWineD3DSurface::Blt for more details
794 *****************************************************************************/
795 static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestRect,
796 IDirectDrawSurface7 *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx)
798 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
799 IDirectDrawSurfaceImpl *Src = (IDirectDrawSurfaceImpl *)SrcSurface;
801 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
803 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
804 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
806 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
807 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
808 return DDERR_INVALIDPARAMS;
811 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
812 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
813 return DDERR_INVALIDPARAMS;
816 /* Sizes can change, therefore hold the lock when testing the rectangles */
817 EnterCriticalSection(&ddraw_cs);
820 if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right ||
821 DestRect->right > This->surface_desc.dwWidth ||
822 DestRect->bottom > This->surface_desc.dwHeight)
824 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
825 LeaveCriticalSection(&ddraw_cs);
826 return DDERR_INVALIDRECT;
831 if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right ||
832 SrcRect->right > Src->surface_desc.dwWidth ||
833 SrcRect->bottom > Src->surface_desc.dwHeight)
835 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
836 LeaveCriticalSection(&ddraw_cs);
837 return DDERR_INVALIDRECT;
841 if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
842 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
843 LeaveCriticalSection(&ddraw_cs);
844 return DDERR_INVALIDPARAMS;
847 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
848 * and replace the ddraw surfaces with the wined3d surfaces
849 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
851 hr = IWineD3DSurface_Blt(This->WineD3DSurface,
853 Src ? Src->WineD3DSurface : NULL,
856 (WINEDDBLTFX *) DDBltFx,
859 LeaveCriticalSection(&ddraw_cs);
862 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
863 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
868 static HRESULT WINAPI ddraw_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_rect,
869 IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
871 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %p, flags %#x, fx %p.\n",
872 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
874 return ddraw_surface7_Blt((IDirectDrawSurface7 *)surface_from_surface3(iface), dst_rect,
875 src_surface ? (IDirectDrawSurface7 *)surface_from_surface3(src_surface) : NULL, src_rect, flags, fx);
878 /*****************************************************************************
879 * IDirectDrawSurface7::AddAttachedSurface
881 * Attaches a surface to another surface. How the surface attachments work
882 * is not totally understood yet, and this method is prone to problems.
883 * he surface that is attached is AddRef-ed.
885 * Tests with complex surfaces suggest that the surface attachments form a
886 * tree, but no method to test this has been found yet.
888 * The attachment list consists of a first surface (first_attached) and
889 * for each surface a pointer to the next attached surface (next_attached).
890 * For the first surface, and a surface that has no attachments
891 * first_attached points to the surface itself. A surface that has
892 * no successors in the chain has next_attached set to NULL.
894 * Newly attached surfaces are attached right after the root surface.
895 * If a surface is attached to a complex surface compound, it's attached to
896 * the surface that the app requested, not the complex root. See
897 * GetAttachedSurface for a description how surfaces are found.
899 * This is how the current implementation works, and it was coded by looking
900 * at the needs of the applications.
902 * So far only Z-Buffer attachments are tested, and they are activated in
903 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
904 * Back buffers should work in 2D mode, but they are not tested(They can be
905 * attached in older iface versions). Rendering to the front buffer and
906 * switching between that and double buffering is not yet implemented in
907 * WineD3D, so for 3D it might have unexpected results.
909 * ddraw_surface_attach_surface is the real thing,
910 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
911 * performs additional checks. Version 7 of this interface is much more restrictive
912 * than its predecessors.
915 * Attach: Surface to attach to iface
919 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
921 *****************************************************************************/
922 static HRESULT WINAPI ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *Surf)
924 TRACE("(%p)->(%p)\n", This, Surf);
927 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
929 EnterCriticalSection(&ddraw_cs);
931 /* Check if the surface is already attached somewhere */
932 if( (Surf->next_attached != NULL) ||
933 (Surf->first_attached != Surf) )
935 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
936 * What happens if one surface is attached to 2 different surfaces?
938 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);
939 LeaveCriticalSection(&ddraw_cs);
940 return DDERR_SURFACEALREADYATTACHED;
943 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
944 Surf->next_attached = This->next_attached;
945 Surf->first_attached = This->first_attached;
946 This->next_attached = Surf;
948 /* Check if the WineD3D depth stencil needs updating */
949 if(This->ddraw->d3ddevice)
951 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
954 ddraw_surface7_AddRef((IDirectDrawSurface7 *)Surf);
955 LeaveCriticalSection(&ddraw_cs);
959 static HRESULT WINAPI ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *Attach)
961 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
962 IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach;
964 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
965 if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
968 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
969 Surf->surface_desc.ddsCaps.dwCaps);
970 return DDERR_CANNOTATTACHSURFACE;
973 return ddraw_surface_attach_surface(This, Surf);
976 static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *attachment)
978 IDirectDrawSurfaceImpl *surface = surface_from_surface3(iface);
979 IDirectDrawSurfaceImpl *attach_impl = surface_from_surface3(attachment);
981 TRACE("iface %p, attachment %p.\n", iface, attachment);
983 /* Tests suggest that
984 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
985 * -> offscreen plain surfaces can be attached to primaries
986 * -> primaries can be attached to offscreen plain surfaces
987 * -> z buffers can be attached to primaries */
988 if (surface->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN)
989 && attach_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN))
991 /* Sizes have to match */
992 if (attach_impl->surface_desc.dwWidth != surface->surface_desc.dwWidth
993 || attach_impl->surface_desc.dwHeight != surface->surface_desc.dwHeight)
995 WARN("Surface sizes do not match.\n");
996 return DDERR_CANNOTATTACHSURFACE;
1000 else if (surface->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE)
1001 && attach_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_ZBUFFER))
1007 WARN("Invalid attachment combination.\n");
1008 return DDERR_CANNOTATTACHSURFACE;
1011 return ddraw_surface_attach_surface(surface, attach_impl);
1014 /*****************************************************************************
1015 * IDirectDrawSurface7::DeleteAttachedSurface
1017 * Removes a surface from the attachment chain. The surface's refcount
1018 * is decreased by one after it has been removed
1021 * Flags: Some flags, not used by this implementation
1022 * Attach: Surface to detach
1026 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1028 *****************************************************************************/
1029 static HRESULT WINAPI ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
1030 DWORD Flags, IDirectDrawSurface7 *Attach)
1032 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1033 IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach;
1034 IDirectDrawSurfaceImpl *Prev = This;
1035 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
1037 EnterCriticalSection(&ddraw_cs);
1038 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
1040 LeaveCriticalSection(&ddraw_cs);
1041 return DDERR_CANNOTDETACHSURFACE;
1044 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1045 if (This->surface_desc.ddsCaps.dwCaps &
1046 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
1048 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
1049 /* FIXME: we should probably also subtract from dwMipMapCount of this
1050 * and all parent surfaces */
1053 /* Find the predecessor of the detached surface */
1056 if(Prev->next_attached == Surf) break;
1057 Prev = Prev->next_attached;
1060 /* There must be a surface, otherwise there's a bug */
1061 assert(Prev != NULL);
1063 /* Unchain the surface */
1064 Prev->next_attached = Surf->next_attached;
1065 Surf->next_attached = NULL;
1066 Surf->first_attached = Surf;
1068 /* Check if the WineD3D depth stencil needs updating */
1069 if(This->ddraw->d3ddevice)
1071 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
1074 ddraw_surface7_Release(Attach);
1075 LeaveCriticalSection(&ddraw_cs);
1079 static HRESULT WINAPI ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3 *iface,
1080 DWORD flags, IDirectDrawSurface3 *attachment)
1082 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
1084 return ddraw_surface7_DeleteAttachedSurface((IDirectDrawSurface7 *)surface_from_surface3(iface), flags,
1085 attachment ? (IDirectDrawSurface7 *)surface_from_surface3(attachment) : NULL);
1088 /*****************************************************************************
1089 * IDirectDrawSurface7::AddOverlayDirtyRect
1091 * "This method is not currently implemented"
1099 *****************************************************************************/
1100 static HRESULT WINAPI ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7 *iface, RECT *Rect)
1102 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1103 TRACE("(%p)->(%p)\n",This,Rect);
1105 /* MSDN says it's not implemented. I could forward it to WineD3D,
1106 * then we'd implement it, but I don't think that's a good idea
1107 * (Stefan Dösinger)
1110 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
1112 return DDERR_UNSUPPORTED; /* unchecked */
1115 static HRESULT WINAPI ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3 *iface, RECT *rect)
1117 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
1119 return ddraw_surface7_AddOverlayDirtyRect((IDirectDrawSurface7 *)surface_from_surface3(iface), rect);
1122 /*****************************************************************************
1123 * IDirectDrawSurface7::GetDC
1125 * Returns a GDI device context for the surface
1128 * hdc: Address of a HDC variable to store the dc to
1132 * DDERR_INVALIDPARAMS if hdc is NULL
1133 * For details, see IWineD3DSurface::GetDC
1135 *****************************************************************************/
1136 static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *hdc)
1138 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1140 TRACE("(%p)->(%p): Relay\n", This, hdc);
1143 return DDERR_INVALIDPARAMS;
1145 EnterCriticalSection(&ddraw_cs);
1146 hr = IWineD3DSurface_GetDC(This->WineD3DSurface,
1148 LeaveCriticalSection(&ddraw_cs);
1151 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1154 case WINED3DERR_INVALIDCALL:
1155 if(hdc) *hdc = NULL;
1156 return DDERR_INVALIDPARAMS;
1162 static HRESULT WINAPI ddraw_surface3_GetDC(IDirectDrawSurface3 *iface, HDC *dc)
1164 TRACE("iface %p, dc %p.\n", iface, dc);
1166 return ddraw_surface7_GetDC((IDirectDrawSurface7 *)surface_from_surface3(iface), dc);
1169 /*****************************************************************************
1170 * IDirectDrawSurface7::ReleaseDC
1172 * Releases the DC that was constructed with GetDC
1175 * hdc: HDC to release
1179 * For more details, see IWineD3DSurface::ReleaseDC
1181 *****************************************************************************/
1182 static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC hdc)
1184 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1186 TRACE("(%p)->(%p): Relay\n", This, hdc);
1188 EnterCriticalSection(&ddraw_cs);
1189 hr = IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
1190 LeaveCriticalSection(&ddraw_cs);
1194 static HRESULT WINAPI ddraw_surface3_ReleaseDC(IDirectDrawSurface3 *iface, HDC dc)
1196 TRACE("iface %p, dc %p.\n", iface, dc);
1198 return ddraw_surface7_ReleaseDC((IDirectDrawSurface7 *)surface_from_surface3(iface), dc);
1201 /*****************************************************************************
1202 * IDirectDrawSurface7::GetCaps
1204 * Returns the surface's caps
1207 * Caps: Address to write the caps to
1211 * DDERR_INVALIDPARAMS if Caps is NULL
1213 *****************************************************************************/
1214 static HRESULT WINAPI ddraw_surface7_GetCaps(IDirectDrawSurface7 *iface, DDSCAPS2 *Caps)
1216 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1217 TRACE("(%p)->(%p)\n",This,Caps);
1220 return DDERR_INVALIDPARAMS;
1222 *Caps = This->surface_desc.ddsCaps;
1226 static HRESULT WINAPI ddraw_surface3_GetCaps(IDirectDrawSurface3 *iface, DDSCAPS *caps)
1231 TRACE("iface %p, caps %p.\n", iface, caps);
1233 hr = ddraw_surface7_GetCaps((IDirectDrawSurface7 *)surface_from_surface3(iface), &caps2);
1234 if (FAILED(hr)) return hr;
1236 caps->dwCaps = caps2.dwCaps;
1240 /*****************************************************************************
1241 * IDirectDrawSurface7::SetPriority
1243 * Sets a texture priority for managed textures.
1246 * Priority: The new priority
1250 * For more details, see IWineD3DSurface::SetPriority
1252 *****************************************************************************/
1253 static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
1255 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1257 TRACE("(%p)->(%d): Relay!\n",This,Priority);
1259 EnterCriticalSection(&ddraw_cs);
1260 hr = IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
1261 LeaveCriticalSection(&ddraw_cs);
1265 /*****************************************************************************
1266 * IDirectDrawSurface7::GetPriority
1268 * Returns the surface's priority
1271 * Priority: Address of a variable to write the priority to
1275 * DDERR_INVALIDPARAMS if Priority == NULL
1276 * For more details, see IWineD3DSurface::GetPriority
1278 *****************************************************************************/
1279 static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWORD *Priority)
1281 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1282 TRACE("(%p)->(%p): Relay\n",This,Priority);
1286 return DDERR_INVALIDPARAMS;
1289 EnterCriticalSection(&ddraw_cs);
1290 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1291 LeaveCriticalSection(&ddraw_cs);
1295 /*****************************************************************************
1296 * IDirectDrawSurface7::SetPrivateData
1298 * Stores some data in the surface that is intended for the application's
1302 * tag: GUID that identifies the data
1303 * Data: Pointer to the private data
1304 * Size: Size of the private data
1309 * For more details, see IWineD3DSurface::SetPrivateData
1311 *****************************************************************************/
1312 static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface,
1313 REFGUID tag, void *Data, DWORD Size, DWORD Flags)
1315 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1317 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1319 EnterCriticalSection(&ddraw_cs);
1320 hr = IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1325 LeaveCriticalSection(&ddraw_cs);
1328 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1333 /*****************************************************************************
1334 * IDirectDrawSurface7::GetPrivateData
1336 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1339 * tag: GUID of the data to return
1340 * Data: Address where to write the data to
1341 * Size: Size of the buffer at Data
1345 * DDERR_INVALIDPARAMS if Data is NULL
1346 * For more details, see IWineD3DSurface::GetPrivateData
1348 *****************************************************************************/
1349 static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, REFGUID tag, void *Data, DWORD *Size)
1351 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1353 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1356 return DDERR_INVALIDPARAMS;
1358 EnterCriticalSection(&ddraw_cs);
1359 hr = IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1363 LeaveCriticalSection(&ddraw_cs);
1367 /*****************************************************************************
1368 * IDirectDrawSurface7::FreePrivateData
1370 * Frees private data stored in the surface
1373 * tag: Tag of the data to free
1377 * For more details, see IWineD3DSurface::FreePrivateData
1379 *****************************************************************************/
1380 static HRESULT WINAPI ddraw_surface7_FreePrivateData(IDirectDrawSurface7 *iface, REFGUID tag)
1382 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1384 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1386 EnterCriticalSection(&ddraw_cs);
1387 hr = IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1388 LeaveCriticalSection(&ddraw_cs);
1392 /*****************************************************************************
1393 * IDirectDrawSurface7::PageLock
1395 * Prevents a sysmem surface from being paged out
1398 * Flags: Not used, must be 0(unchecked)
1401 * DD_OK, because it's a stub
1403 *****************************************************************************/
1404 static HRESULT WINAPI ddraw_surface7_PageLock(IDirectDrawSurface7 *iface, DWORD Flags)
1406 TRACE("(%p)->(%x)\n", iface, Flags);
1408 /* This is Windows memory management related - we don't need this */
1412 static HRESULT WINAPI ddraw_surface3_PageLock(IDirectDrawSurface3 *iface, DWORD flags)
1414 TRACE("iface %p, flags %#x.\n", iface, flags);
1416 return ddraw_surface7_PageLock((IDirectDrawSurface7 *)surface_from_surface3(iface), flags);
1419 /*****************************************************************************
1420 * IDirectDrawSurface7::PageUnlock
1422 * Allows a sysmem surface to be paged out
1425 * Flags: Not used, must be 0(unchecked)
1428 * DD_OK, because it's a stub
1430 *****************************************************************************/
1431 static HRESULT WINAPI ddraw_surface7_PageUnlock(IDirectDrawSurface7 *iface, DWORD Flags)
1433 TRACE("(%p)->(%x)\n", iface, Flags);
1438 static HRESULT WINAPI ddraw_surface3_PageUnlock(IDirectDrawSurface3 *iface, DWORD flags)
1440 TRACE("iface %p, flags %#x.\n", iface, flags);
1442 return ddraw_surface7_PageUnlock((IDirectDrawSurface7 *)surface_from_surface3(iface), flags);
1445 /*****************************************************************************
1446 * IDirectDrawSurface7::BltBatch
1448 * An unimplemented function
1456 *****************************************************************************/
1457 static HRESULT WINAPI ddraw_surface7_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1459 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1461 /* MSDN: "not currently implemented" */
1462 return DDERR_UNSUPPORTED;
1465 static HRESULT WINAPI ddraw_surface3_BltBatch(IDirectDrawSurface3 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags)
1467 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
1469 return ddraw_surface7_BltBatch((IDirectDrawSurface7 *)surface_from_surface3(iface), batch, count, flags);
1472 /*****************************************************************************
1473 * IDirectDrawSurface7::EnumAttachedSurfaces
1475 * Enumerates all surfaces attached to this surface
1478 * context: Pointer to pass unmodified to the callback
1479 * cb: Callback function to call for each surface
1483 * DDERR_INVALIDPARAMS if cb is NULL
1485 *****************************************************************************/
1486 static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1487 void *context, LPDDENUMSURFACESCALLBACK7 cb)
1489 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1490 IDirectDrawSurfaceImpl *surf;
1491 DDSURFACEDESC2 desc;
1494 /* Attached surfaces aren't handled in WineD3D */
1495 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1498 return DDERR_INVALIDPARAMS;
1500 EnterCriticalSection(&ddraw_cs);
1501 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
1503 surf = This->complex_array[i];
1506 ddraw_surface7_AddRef((IDirectDrawSurface7 *)surf);
1507 desc = surf->surface_desc;
1508 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1509 if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL)
1511 LeaveCriticalSection(&ddraw_cs);
1516 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1518 ddraw_surface7_AddRef((IDirectDrawSurface7 *)surf);
1519 desc = surf->surface_desc;
1520 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1521 if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL)
1523 LeaveCriticalSection(&ddraw_cs);
1528 TRACE(" end of enumeration.\n");
1530 LeaveCriticalSection(&ddraw_cs);
1534 struct callback_info
1536 LPDDENUMSURFACESCALLBACK callback;
1540 static HRESULT CALLBACK EnumCallback(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context)
1542 const struct callback_info *info = context;
1544 return info->callback((IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface)->IDirectDrawSurface3_vtbl,
1545 (DDSURFACEDESC *)surface_desc, info->context);
1548 static HRESULT WINAPI ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3 *iface,
1549 void *context, LPDDENUMSURFACESCALLBACK callback)
1551 struct callback_info info;
1553 TRACE("iface %p, context %p, callback %p.\n", iface, context, callback);
1555 info.callback = callback;
1556 info.context = context;
1558 return ddraw_surface7_EnumAttachedSurfaces((IDirectDrawSurface7 *)surface_from_surface3(iface),
1559 &info, EnumCallback);
1562 /*****************************************************************************
1563 * IDirectDrawSurface7::EnumOverlayZOrders
1565 * "Enumerates the overlay surfaces on the specified destination"
1568 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1569 * context: context to pass back to the callback
1570 * cb: callback function to call for each enumerated surface
1573 * DD_OK, because it's a stub
1575 *****************************************************************************/
1576 static HRESULT WINAPI ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1577 DWORD Flags, void *context, LPDDENUMSURFACESCALLBACK7 cb)
1579 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1584 static HRESULT WINAPI ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3 *iface,
1585 DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback)
1587 struct callback_info info;
1589 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback);
1591 info.callback = callback;
1592 info.context = context;
1594 return ddraw_surface7_EnumOverlayZOrders((IDirectDrawSurface7 *)surface_from_surface3(iface),
1595 flags, &info, EnumCallback);
1598 /*****************************************************************************
1599 * IDirectDrawSurface7::GetBltStatus
1601 * Returns the blitting status
1604 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1607 * See IWineD3DSurface::Blt
1609 *****************************************************************************/
1610 static HRESULT WINAPI ddraw_surface7_GetBltStatus(IDirectDrawSurface7 *iface, DWORD Flags)
1612 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1614 TRACE("(%p)->(%x): Relay\n", This, Flags);
1616 EnterCriticalSection(&ddraw_cs);
1617 hr = IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1618 LeaveCriticalSection(&ddraw_cs);
1621 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1626 static HRESULT WINAPI ddraw_surface3_GetBltStatus(IDirectDrawSurface3 *iface, DWORD flags)
1628 TRACE("iface %p, flags %#x.\n", iface, flags);
1630 return ddraw_surface7_GetBltStatus((IDirectDrawSurface7 *)surface_from_surface3(iface), flags);
1633 /*****************************************************************************
1634 * IDirectDrawSurface7::GetColorKey
1636 * Returns the color key assigned to the surface
1640 * CKey: Address to store the key to
1644 * DDERR_INVALIDPARAMS if CKey is NULL
1646 *****************************************************************************/
1647 static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWORD Flags, DDCOLORKEY *CKey)
1649 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1650 TRACE("(%p)->(%08x,%p)\n", This, Flags, CKey);
1653 return DDERR_INVALIDPARAMS;
1655 EnterCriticalSection(&ddraw_cs);
1659 case DDCKEY_DESTBLT:
1660 if (!(This->surface_desc.dwFlags & DDSD_CKDESTBLT))
1662 LeaveCriticalSection(&ddraw_cs);
1663 return DDERR_NOCOLORKEY;
1665 *CKey = This->surface_desc.ddckCKDestBlt;
1668 case DDCKEY_DESTOVERLAY:
1669 if (!(This->surface_desc.dwFlags & DDSD_CKDESTOVERLAY))
1671 LeaveCriticalSection(&ddraw_cs);
1672 return DDERR_NOCOLORKEY;
1674 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1678 if (!(This->surface_desc.dwFlags & DDSD_CKSRCBLT))
1680 LeaveCriticalSection(&ddraw_cs);
1681 return DDERR_NOCOLORKEY;
1683 *CKey = This->surface_desc.ddckCKSrcBlt;
1686 case DDCKEY_SRCOVERLAY:
1687 if (!(This->surface_desc.dwFlags & DDSD_CKSRCOVERLAY))
1689 LeaveCriticalSection(&ddraw_cs);
1690 return DDERR_NOCOLORKEY;
1692 *CKey = This->surface_desc.ddckCKSrcOverlay;
1696 LeaveCriticalSection(&ddraw_cs);
1697 return DDERR_INVALIDPARAMS;
1700 LeaveCriticalSection(&ddraw_cs);
1704 static HRESULT WINAPI ddraw_surface3_GetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key)
1706 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
1708 return ddraw_surface7_GetColorKey((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, color_key);
1711 /*****************************************************************************
1712 * IDirectDrawSurface7::GetFlipStatus
1714 * Returns the flipping status of the surface
1717 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1720 * See IWineD3DSurface::GetFlipStatus
1722 *****************************************************************************/
1723 static HRESULT WINAPI ddraw_surface7_GetFlipStatus(IDirectDrawSurface7 *iface, DWORD Flags)
1725 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1727 TRACE("(%p)->(%x): Relay\n", This, Flags);
1729 EnterCriticalSection(&ddraw_cs);
1730 hr = IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1731 LeaveCriticalSection(&ddraw_cs);
1734 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1739 static HRESULT WINAPI ddraw_surface3_GetFlipStatus(IDirectDrawSurface3 *iface, DWORD flags)
1741 TRACE("iface %p, flags %#x.\n", iface, flags);
1743 return ddraw_surface7_GetFlipStatus((IDirectDrawSurface7 *)surface_from_surface3(iface), flags);
1746 /*****************************************************************************
1747 * IDirectDrawSurface7::GetOverlayPosition
1749 * Returns the display coordinates of a visible and active overlay surface
1756 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1757 *****************************************************************************/
1758 static HRESULT WINAPI ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7 *iface, LONG *X, LONG *Y)
1760 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1762 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1764 EnterCriticalSection(&ddraw_cs);
1765 hr = IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1768 LeaveCriticalSection(&ddraw_cs);
1772 static HRESULT WINAPI ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3 *iface, LONG *x, LONG *y)
1774 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
1776 return ddraw_surface7_GetOverlayPosition((IDirectDrawSurface7 *)surface_from_surface3(iface), x, y);
1779 /*****************************************************************************
1780 * IDirectDrawSurface7::GetPixelFormat
1782 * Returns the pixel format of the Surface
1785 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1786 * format should be written
1790 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1792 *****************************************************************************/
1793 static HRESULT WINAPI ddraw_surface7_GetPixelFormat(IDirectDrawSurface7 *iface, DDPIXELFORMAT *PixelFormat)
1795 /* What is DDERR_INVALIDSURFACETYPE for here? */
1796 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1797 TRACE("(%p)->(%p)\n",This,PixelFormat);
1800 return DDERR_INVALIDPARAMS;
1802 EnterCriticalSection(&ddraw_cs);
1803 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1804 LeaveCriticalSection(&ddraw_cs);
1809 static HRESULT WINAPI ddraw_surface3_GetPixelFormat(IDirectDrawSurface3 *iface, DDPIXELFORMAT *pixel_format)
1811 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
1813 return ddraw_surface7_GetPixelFormat((IDirectDrawSurface7 *)surface_from_surface3(iface), pixel_format);
1816 /*****************************************************************************
1817 * IDirectDrawSurface7::GetSurfaceDesc
1819 * Returns the description of this surface
1822 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1827 * DDERR_INVALIDPARAMS if DDSD is NULL
1829 *****************************************************************************/
1830 static HRESULT WINAPI ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7 *iface, DDSURFACEDESC2 *DDSD)
1832 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1834 TRACE("(%p)->(%p)\n",This,DDSD);
1837 return DDERR_INVALIDPARAMS;
1839 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
1841 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
1842 return DDERR_INVALIDPARAMS;
1845 EnterCriticalSection(&ddraw_cs);
1846 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1847 TRACE("Returning surface desc:\n");
1848 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1850 LeaveCriticalSection(&ddraw_cs);
1854 static HRESULT WINAPI ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface, DDSURFACEDESC *surface_desc)
1856 IDirectDrawSurfaceImpl *surface = surface_from_surface3(iface);
1858 TRACE("iface %p, surface_desc %p.\n", iface, surface_desc);
1860 if (!surface_desc) return DDERR_INVALIDPARAMS;
1862 if (surface_desc->dwSize != sizeof(DDSURFACEDESC))
1864 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc->dwSize);
1865 return DDERR_INVALIDPARAMS;
1868 EnterCriticalSection(&ddraw_cs);
1869 DD_STRUCT_COPY_BYSIZE(surface_desc, (DDSURFACEDESC *)&surface->surface_desc);
1870 TRACE("Returning surface desc:\n");
1871 if (TRACE_ON(ddraw))
1873 /* DDRAW_dump_surface_desc handles the smaller size */
1874 DDRAW_dump_surface_desc((DDSURFACEDESC2 *)surface_desc);
1877 LeaveCriticalSection(&ddraw_cs);
1881 /*****************************************************************************
1882 * IDirectDrawSurface7::Initialize
1884 * Initializes the surface. This is a no-op in Wine
1887 * DD: Pointer to an DirectDraw interface
1888 * DDSD: Surface description for initialization
1891 * DDERR_ALREADYINITIALIZED
1893 *****************************************************************************/
1894 static HRESULT WINAPI ddraw_surface7_Initialize(IDirectDrawSurface7 *iface,
1895 IDirectDraw *ddraw, DDSURFACEDESC2 *surface_desc)
1897 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
1899 return DDERR_ALREADYINITIALIZED;
1902 static HRESULT WINAPI ddraw_surface3_Initialize(IDirectDrawSurface3 *iface,
1903 IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
1905 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
1907 return ddraw_surface7_Initialize((IDirectDrawSurface7 *)surface_from_surface3(iface),
1908 ddraw, (DDSURFACEDESC2 *)surface_desc);
1911 /*****************************************************************************
1912 * IDirectDrawSurface7::IsLost
1914 * Checks if the surface is lost
1917 * DD_OK, if the surface is usable
1918 * DDERR_ISLOST if the surface is lost
1919 * See IWineD3DSurface::IsLost for more details
1921 *****************************************************************************/
1922 static HRESULT WINAPI ddraw_surface7_IsLost(IDirectDrawSurface7 *iface)
1924 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1926 TRACE("(%p)\n", This);
1928 EnterCriticalSection(&ddraw_cs);
1929 /* We lose the surface if the implementation was changed */
1930 if(This->ImplType != This->ddraw->ImplType)
1932 /* But this shouldn't happen. When we change the implementation,
1933 * all surfaces are re-created automatically, and their content
1936 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1937 LeaveCriticalSection(&ddraw_cs);
1938 return DDERR_SURFACELOST;
1941 hr = IWineD3DSurface_IsLost(This->WineD3DSurface);
1942 LeaveCriticalSection(&ddraw_cs);
1945 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1946 * WineD3D uses the same error for surfaces
1948 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
1953 static HRESULT WINAPI ddraw_surface3_IsLost(IDirectDrawSurface3 *iface)
1955 TRACE("iface %p.\n", iface);
1957 return ddraw_surface7_IsLost((IDirectDrawSurface7 *)surface_from_surface3(iface));
1960 /*****************************************************************************
1961 * IDirectDrawSurface7::Restore
1963 * Restores a lost surface. This makes the surface usable again, but
1964 * doesn't reload its old contents
1968 * See IWineD3DSurface::Restore for more details
1970 *****************************************************************************/
1971 static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
1973 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1975 TRACE("(%p)\n", This);
1977 EnterCriticalSection(&ddraw_cs);
1978 if(This->ImplType != This->ddraw->ImplType)
1980 /* Call the recreation callback. Make sure to AddRef first */
1981 IDirectDrawSurface_AddRef(iface);
1982 ddraw_recreate_surfaces_cb(iface, &This->surface_desc, NULL /* Not needed */);
1984 hr = IWineD3DSurface_Restore(This->WineD3DSurface);
1985 LeaveCriticalSection(&ddraw_cs);
1989 static HRESULT WINAPI ddraw_surface3_Restore(IDirectDrawSurface3 *iface)
1991 TRACE("iface %p.\n", iface);
1993 return ddraw_surface7_Restore((IDirectDrawSurface7 *)surface_from_surface3(iface));
1996 /*****************************************************************************
1997 * IDirectDrawSurface7::SetOverlayPosition
1999 * Changes the display coordinates of an overlay surface
2006 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
2007 *****************************************************************************/
2008 static HRESULT WINAPI ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7 *iface, LONG X, LONG Y)
2010 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2012 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
2014 EnterCriticalSection(&ddraw_cs);
2015 hr = IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
2018 LeaveCriticalSection(&ddraw_cs);
2022 static HRESULT WINAPI ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3 *iface, LONG x, LONG y)
2024 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
2026 return ddraw_surface7_SetOverlayPosition((IDirectDrawSurface7 *)surface_from_surface3(iface), x, y);
2029 /*****************************************************************************
2030 * IDirectDrawSurface7::UpdateOverlay
2032 * Modifies the attributes of an overlay surface.
2035 * SrcRect: The section of the source being used for the overlay
2036 * DstSurface: Address of the surface that is overlaid
2037 * DstRect: Place of the overlay
2038 * Flags: some DDOVER_* flags
2041 * DDERR_UNSUPPORTED, because we don't support overlays
2043 *****************************************************************************/
2044 static HRESULT WINAPI ddraw_surface7_UpdateOverlay(IDirectDrawSurface7 *iface, RECT *SrcRect,
2045 IDirectDrawSurface7 *DstSurface, RECT *DstRect, DWORD Flags, DDOVERLAYFX *FX)
2047 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2048 IDirectDrawSurfaceImpl *Dst = (IDirectDrawSurfaceImpl *)DstSurface;
2050 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
2052 EnterCriticalSection(&ddraw_cs);
2053 hr = IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
2055 Dst ? Dst->WineD3DSurface : NULL,
2058 (WINEDDOVERLAYFX *) FX);
2059 LeaveCriticalSection(&ddraw_cs);
2061 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2062 case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE;
2063 case WINEDDERR_OVERLAYNOTVISIBLE: return DDERR_OVERLAYNOTVISIBLE;
2069 static HRESULT WINAPI ddraw_surface3_UpdateOverlay(IDirectDrawSurface3 *iface, RECT *src_rect,
2070 IDirectDrawSurface3 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
2072 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
2073 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
2075 return ddraw_surface7_UpdateOverlay((IDirectDrawSurface7 *)surface_from_surface3(iface), src_rect,
2076 dst_surface ? (IDirectDrawSurface7 *)surface_from_surface3(dst_surface) : NULL, dst_rect, flags, fx);
2079 /*****************************************************************************
2080 * IDirectDrawSurface7::UpdateOverlayDisplay
2082 * The DX7 sdk says that it's not implemented
2087 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
2089 *****************************************************************************/
2090 static HRESULT WINAPI ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7 *iface, DWORD Flags)
2092 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2093 TRACE("(%p)->(%x)\n", This, Flags);
2094 return DDERR_UNSUPPORTED;
2097 static HRESULT WINAPI ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3 *iface, DWORD flags)
2099 TRACE("iface %p, flags %#x.\n", iface, flags);
2101 return ddraw_surface7_UpdateOverlayDisplay((IDirectDrawSurface7 *)surface_from_surface3(iface), flags);
2104 /*****************************************************************************
2105 * IDirectDrawSurface7::UpdateOverlayZOrder
2107 * Sets an overlay's Z order
2110 * Flags: DDOVERZ_* flags
2111 * DDSRef: Defines the relative position in the overlay chain
2114 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
2116 *****************************************************************************/
2117 static HRESULT WINAPI ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
2118 DWORD Flags, IDirectDrawSurface7 *DDSRef)
2120 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2121 IDirectDrawSurfaceImpl *Ref = (IDirectDrawSurfaceImpl *)DDSRef;
2124 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
2125 EnterCriticalSection(&ddraw_cs);
2126 hr = IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
2128 Ref ? Ref->WineD3DSurface : NULL);
2129 LeaveCriticalSection(&ddraw_cs);
2133 static HRESULT WINAPI ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3 *iface,
2134 DWORD flags, IDirectDrawSurface3 *reference)
2136 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
2138 return ddraw_surface7_UpdateOverlayZOrder((IDirectDrawSurface7 *)surface_from_surface3(iface), flags,
2139 reference ? (IDirectDrawSurface7 *)surface_from_surface3(reference) : NULL);
2142 /*****************************************************************************
2143 * IDirectDrawSurface7::GetDDInterface
2145 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
2146 * surface belongs to
2149 * DD: Address to write the interface pointer to
2153 * DDERR_INVALIDPARAMS if DD is NULL
2155 *****************************************************************************/
2156 static HRESULT WINAPI ddraw_surface7_GetDDInterface(IDirectDrawSurface7 *iface, void **DD)
2158 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2160 TRACE("(%p)->(%p)\n",This,DD);
2163 return DDERR_INVALIDPARAMS;
2165 switch(This->version)
2172 *DD = &This->ddraw->IDirectDraw4_vtbl;
2176 *DD = &This->ddraw->IDirectDraw2_vtbl;
2180 *DD = &This->ddraw->IDirectDraw_vtbl;
2184 IUnknown_AddRef((IUnknown *)*DD);
2189 static HRESULT WINAPI ddraw_surface3_GetDDInterface(IDirectDrawSurface3 *iface, void **ddraw)
2191 TRACE("iface %p, ddraw %p.\n", iface, ddraw);
2193 return ddraw_surface7_GetDDInterface((IDirectDrawSurface7 *)surface_from_surface3(iface), ddraw);
2196 /* This seems also windows implementation specific - I don't think WineD3D needs this */
2197 static HRESULT WINAPI ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
2199 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2200 volatile IDirectDrawSurfaceImpl* vThis = This;
2202 TRACE("(%p)\n",This);
2203 EnterCriticalSection(&ddraw_cs);
2204 /* A uniqueness value of 0 is apparently special.
2205 * This needs to be checked.
2206 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
2209 DWORD old_uniqueness_value = vThis->uniqueness_value;
2210 DWORD new_uniqueness_value = old_uniqueness_value+1;
2212 if (old_uniqueness_value == 0) break;
2213 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
2215 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
2216 old_uniqueness_value,
2217 new_uniqueness_value)
2218 == old_uniqueness_value)
2222 LeaveCriticalSection(&ddraw_cs);
2226 static HRESULT WINAPI ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7 *iface, DWORD *pValue)
2228 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2230 TRACE("(%p)->(%p)\n",This,pValue);
2231 EnterCriticalSection(&ddraw_cs);
2232 *pValue = This->uniqueness_value;
2233 LeaveCriticalSection(&ddraw_cs);
2237 /*****************************************************************************
2238 * IDirectDrawSurface7::SetLOD
2240 * Sets the level of detail of a texture
2243 * MaxLOD: LOD to set
2247 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2249 *****************************************************************************/
2250 static HRESULT WINAPI ddraw_surface7_SetLOD(IDirectDrawSurface7 *iface, DWORD MaxLOD)
2252 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2254 TRACE("(%p)->(%d)\n", This, MaxLOD);
2256 EnterCriticalSection(&ddraw_cs);
2257 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2259 LeaveCriticalSection(&ddraw_cs);
2260 return DDERR_INVALIDOBJECT;
2263 if(!This->wineD3DTexture)
2265 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
2266 LeaveCriticalSection(&ddraw_cs);
2267 return DDERR_INVALIDOBJECT;
2270 hr = IWineD3DBaseTexture_SetLOD(This->wineD3DTexture,
2272 LeaveCriticalSection(&ddraw_cs);
2276 /*****************************************************************************
2277 * IDirectDrawSurface7::GetLOD
2279 * Returns the level of detail of a Direct3D texture
2282 * MaxLOD: Address to write the LOD to
2286 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2287 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2289 *****************************************************************************/
2290 static HRESULT WINAPI ddraw_surface7_GetLOD(IDirectDrawSurface7 *iface, DWORD *MaxLOD)
2292 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2293 TRACE("(%p)->(%p)\n", This, MaxLOD);
2296 return DDERR_INVALIDPARAMS;
2298 EnterCriticalSection(&ddraw_cs);
2299 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2301 LeaveCriticalSection(&ddraw_cs);
2302 return DDERR_INVALIDOBJECT;
2305 *MaxLOD = IWineD3DBaseTexture_GetLOD(This->wineD3DTexture);
2306 LeaveCriticalSection(&ddraw_cs);
2310 /*****************************************************************************
2311 * IDirectDrawSurface7::BltFast
2313 * Performs a fast Blit.
2316 * dstx: The x coordinate to blit to on the destination
2317 * dsty: The y coordinate to blit to on the destination
2318 * Source: The source surface
2319 * rsrc: The source rectangle
2320 * trans: Type of transfer. Some DDBLTFAST_* flags
2324 * For more details, see IWineD3DSurface::BltFast
2326 *****************************************************************************/
2327 static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD dstx, DWORD dsty,
2328 IDirectDrawSurface7 *Source, RECT *rsrc, DWORD trans)
2330 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2331 IDirectDrawSurfaceImpl *src = (IDirectDrawSurfaceImpl *)Source;
2332 DWORD src_w, src_h, dst_w, dst_h;
2334 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
2336 dst_w = This->surface_desc.dwWidth;
2337 dst_h = This->surface_desc.dwHeight;
2339 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2344 if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right ||
2345 rsrc->right > src->surface_desc.dwWidth ||
2346 rsrc->bottom > src->surface_desc.dwHeight)
2348 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2349 return DDERR_INVALIDRECT;
2352 src_w = rsrc->right - rsrc->left;
2353 src_h = rsrc->bottom - rsrc->top;
2357 src_w = src->surface_desc.dwWidth;
2358 src_h = src->surface_desc.dwHeight;
2361 if (src_w > dst_w || dstx > dst_w - src_w
2362 || src_h > dst_h || dsty > dst_h - src_h)
2364 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
2365 return DDERR_INVALIDRECT;
2368 EnterCriticalSection(&ddraw_cs);
2369 hr = IWineD3DSurface_BltFast(This->WineD3DSurface,
2371 src ? src->WineD3DSurface : NULL,
2374 LeaveCriticalSection(&ddraw_cs);
2377 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
2378 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
2383 static HRESULT WINAPI ddraw_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD dst_x, DWORD dst_y,
2384 IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags)
2386 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
2387 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
2389 return ddraw_surface7_BltFast((IDirectDrawSurface7 *)surface_from_surface3(iface), dst_x, dst_y,
2390 src_surface ? (IDirectDrawSurface7 *)surface_from_surface3(src_surface) : NULL, src_rect, flags);
2393 /*****************************************************************************
2394 * IDirectDrawSurface7::GetClipper
2396 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2400 * Clipper: Address to store the interface pointer at
2404 * DDERR_INVALIDPARAMS if Clipper is NULL
2405 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2407 *****************************************************************************/
2408 static HRESULT WINAPI ddraw_surface7_GetClipper(IDirectDrawSurface7 *iface, IDirectDrawClipper **Clipper)
2410 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2411 TRACE("(%p)->(%p)\n", This, Clipper);
2415 LeaveCriticalSection(&ddraw_cs);
2416 return DDERR_INVALIDPARAMS;
2419 EnterCriticalSection(&ddraw_cs);
2420 if(This->clipper == NULL)
2422 LeaveCriticalSection(&ddraw_cs);
2423 return DDERR_NOCLIPPERATTACHED;
2426 *Clipper = (IDirectDrawClipper *)This->clipper;
2427 IDirectDrawClipper_AddRef(*Clipper);
2428 LeaveCriticalSection(&ddraw_cs);
2432 static HRESULT WINAPI ddraw_surface3_GetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper **clipper)
2434 TRACE("iface %p, clipper %p.\n", iface, clipper);
2436 return ddraw_surface7_GetClipper((IDirectDrawSurface7 *)surface_from_surface3(iface), clipper);
2439 /*****************************************************************************
2440 * IDirectDrawSurface7::SetClipper
2442 * Sets a clipper for the surface
2445 * Clipper: IDirectDrawClipper interface of the clipper to set
2450 *****************************************************************************/
2451 static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface, IDirectDrawClipper *Clipper)
2453 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2454 IDirectDrawClipperImpl *oldClipper = This->clipper;
2457 TRACE("(%p)->(%p)\n",This,Clipper);
2459 EnterCriticalSection(&ddraw_cs);
2460 if ((IDirectDrawClipperImpl *)Clipper == This->clipper)
2462 LeaveCriticalSection(&ddraw_cs);
2466 This->clipper = (IDirectDrawClipperImpl *)Clipper;
2468 if (Clipper != NULL)
2469 IDirectDrawClipper_AddRef(Clipper);
2471 IDirectDrawClipper_Release((IDirectDrawClipper *)oldClipper);
2473 hr = IWineD3DSurface_SetClipper(This->WineD3DSurface, This->clipper ? This->clipper->wineD3DClipper : NULL);
2475 if(This->wineD3DSwapChain) {
2478 IDirectDrawClipper_GetHWnd(Clipper, &clipWindow);
2482 IWineD3DSwapChain_SetDestWindowOverride(This->wineD3DSwapChain,
2485 IWineD3DSwapChain_SetDestWindowOverride(This->wineD3DSwapChain,
2486 This->ddraw->d3d_window);
2490 LeaveCriticalSection(&ddraw_cs);
2494 static HRESULT WINAPI ddraw_surface3_SetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper *clipper)
2496 TRACE("iface %p, clipper %p.\n", iface, clipper);
2498 return ddraw_surface7_SetClipper((IDirectDrawSurface7 *)surface_from_surface3(iface), clipper);
2501 /*****************************************************************************
2502 * IDirectDrawSurface7::SetSurfaceDesc
2504 * Sets the surface description. It can override the pixel format, the surface
2506 * It's not really tested.
2509 * DDSD: Pointer to the new surface description to set
2514 * DDERR_INVALIDPARAMS if DDSD is NULL
2516 *****************************************************************************/
2517 static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface, DDSURFACEDESC2 *DDSD, DWORD Flags)
2519 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2520 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
2522 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
2525 return DDERR_INVALIDPARAMS;
2527 EnterCriticalSection(&ddraw_cs);
2528 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
2530 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
2532 if(newFormat == WINED3DFMT_UNKNOWN)
2534 ERR("Requested to set an unknown pixelformat\n");
2535 LeaveCriticalSection(&ddraw_cs);
2536 return DDERR_INVALIDPARAMS;
2538 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
2540 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
2544 LeaveCriticalSection(&ddraw_cs);
2549 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
2551 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2553 (WINEDDCOLORKEY *) &DDSD->u3.ddckCKDestOverlay);
2555 if (DDSD->dwFlags & DDSD_CKDESTBLT)
2557 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2559 (WINEDDCOLORKEY *) &DDSD->ddckCKDestBlt);
2561 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
2563 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2565 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcOverlay);
2567 if (DDSD->dwFlags & DDSD_CKSRCBLT)
2569 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2571 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcBlt);
2573 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
2575 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
2576 if(hr != WINED3D_OK)
2578 /* No need for a trace here, wined3d does that for us */
2581 case WINED3DERR_INVALIDCALL:
2582 LeaveCriticalSection(&ddraw_cs);
2583 return DDERR_INVALIDPARAMS;
2590 This->surface_desc = *DDSD;
2592 LeaveCriticalSection(&ddraw_cs);
2596 static HRESULT WINAPI ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface,
2597 DDSURFACEDESC *surface_desc, DWORD flags)
2599 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags);
2601 return ddraw_surface7_SetSurfaceDesc((IDirectDrawSurface7 *)surface_from_surface3(iface),
2602 (DDSURFACEDESC2 *)surface_desc, flags);
2605 /*****************************************************************************
2606 * IDirectDrawSurface7::GetPalette
2608 * Returns the IDirectDrawPalette interface of the palette currently assigned
2612 * Pal: Address to write the interface pointer to
2616 * DDERR_INVALIDPARAMS if Pal is NULL
2618 *****************************************************************************/
2619 static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDirectDrawPalette **Pal)
2621 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2622 IWineD3DPalette *wPal;
2624 TRACE("(%p)->(%p): Relay\n", This, Pal);
2627 return DDERR_INVALIDPARAMS;
2629 EnterCriticalSection(&ddraw_cs);
2630 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
2633 LeaveCriticalSection(&ddraw_cs);
2639 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2644 hr = DDERR_NOPALETTEATTACHED;
2647 LeaveCriticalSection(&ddraw_cs);
2651 static HRESULT WINAPI ddraw_surface3_GetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette **palette)
2653 TRACE("iface %p, palette %p.\n", iface, palette);
2655 return ddraw_surface7_GetPalette((IDirectDrawSurface7 *)surface_from_surface3(iface), palette);
2658 /*****************************************************************************
2661 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2662 * recursively in the surface tree
2664 *****************************************************************************/
2668 WINEDDCOLORKEY *CKey;
2672 static HRESULT WINAPI
2673 SetColorKeyEnum(IDirectDrawSurface7 *surface,
2674 DDSURFACEDESC2 *desc,
2677 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)surface;
2678 struct SCKContext *ctx = context;
2681 hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2686 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
2690 ddraw_surface7_EnumAttachedSurfaces(surface, context, SetColorKeyEnum);
2691 ddraw_surface7_Release(surface);
2693 return DDENUMRET_OK;
2696 /*****************************************************************************
2697 * IDirectDrawSurface7::SetColorKey
2699 * Sets the color keying options for the surface. Observations showed that
2700 * in case of complex surfaces the color key has to be assigned to all
2705 * CKey: The new color key
2709 * See IWineD3DSurface::SetColorKey for details
2711 *****************************************************************************/
2712 static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWORD Flags, DDCOLORKEY *CKey)
2714 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2715 DDCOLORKEY FixedCKey;
2716 struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) (CKey ? &FixedCKey : NULL), Flags };
2717 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2719 EnterCriticalSection(&ddraw_cs);
2723 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
2724 if (FixedCKey.dwColorSpaceHighValue < FixedCKey.dwColorSpaceLowValue)
2725 FixedCKey.dwColorSpaceHighValue = FixedCKey.dwColorSpaceLowValue;
2727 switch (Flags & ~DDCKEY_COLORSPACE)
2729 case DDCKEY_DESTBLT:
2730 This->surface_desc.ddckCKDestBlt = FixedCKey;
2731 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
2734 case DDCKEY_DESTOVERLAY:
2735 This->surface_desc.u3.ddckCKDestOverlay = FixedCKey;
2736 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
2739 case DDCKEY_SRCOVERLAY:
2740 This->surface_desc.ddckCKSrcOverlay = FixedCKey;
2741 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
2745 This->surface_desc.ddckCKSrcBlt = FixedCKey;
2746 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
2750 LeaveCriticalSection(&ddraw_cs);
2751 return DDERR_INVALIDPARAMS;
2756 switch (Flags & ~DDCKEY_COLORSPACE)
2758 case DDCKEY_DESTBLT:
2759 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
2762 case DDCKEY_DESTOVERLAY:
2763 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
2766 case DDCKEY_SRCOVERLAY:
2767 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
2771 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
2775 LeaveCriticalSection(&ddraw_cs);
2776 return DDERR_INVALIDPARAMS;
2779 ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface, Flags, ctx.CKey);
2780 ddraw_surface7_EnumAttachedSurfaces(iface, &ctx, SetColorKeyEnum);
2781 LeaveCriticalSection(&ddraw_cs);
2784 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2785 default: return ctx.ret;
2789 static HRESULT WINAPI ddraw_surface3_SetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key)
2791 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
2793 return ddraw_surface7_SetColorKey((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, color_key);
2796 /*****************************************************************************
2797 * IDirectDrawSurface7::SetPalette
2799 * Assigns a DirectDrawPalette object to the surface
2802 * Pal: Interface to the palette to set
2807 *****************************************************************************/
2808 static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDirectDrawPalette *Pal)
2810 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2811 IDirectDrawPalette *oldPal;
2812 IDirectDrawSurfaceImpl *surf;
2813 IDirectDrawPaletteImpl *PalImpl = (IDirectDrawPaletteImpl *)Pal;
2815 TRACE("(%p)->(%p)\n", This, Pal);
2817 if (!(This->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 |
2818 DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8))) {
2819 return DDERR_INVALIDPIXELFORMAT;
2822 /* Find the old palette */
2823 EnterCriticalSection(&ddraw_cs);
2824 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2825 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
2827 LeaveCriticalSection(&ddraw_cs);
2830 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2832 /* Set the new Palette */
2833 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2834 PalImpl ? PalImpl->wineD3DPalette : NULL);
2835 /* AddRef the Palette */
2836 if(Pal) IDirectDrawPalette_AddRef(Pal);
2838 /* Release the old palette */
2839 if(oldPal) IDirectDrawPalette_Release(oldPal);
2841 /* If this is a front buffer, also update the back buffers
2842 * TODO: How do things work for palettized cube textures?
2844 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2846 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2847 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
2852 IDirectDrawSurface7 *attach;
2854 hr = ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7 *)surf, &caps2, &attach);
2860 TRACE("Setting palette on %p\n", attach);
2861 ddraw_surface7_SetPalette(attach, Pal);
2862 surf = (IDirectDrawSurfaceImpl *)attach;
2863 ddraw_surface7_Release(attach);
2867 LeaveCriticalSection(&ddraw_cs);
2871 static HRESULT WINAPI ddraw_surface3_SetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette *palette)
2873 TRACE("iface %p, palette %p.\n", iface, palette);
2875 return ddraw_surface7_SetPalette((IDirectDrawSurface7 *)surface_from_surface3(iface), palette);
2878 /*****************************************************************************
2880 *****************************************************************************/
2882 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2885 ddraw_surface7_QueryInterface,
2886 ddraw_surface7_AddRef,
2887 ddraw_surface7_Release,
2888 /* IDirectDrawSurface */
2889 ddraw_surface7_AddAttachedSurface,
2890 ddraw_surface7_AddOverlayDirtyRect,
2892 ddraw_surface7_BltBatch,
2893 ddraw_surface7_BltFast,
2894 ddraw_surface7_DeleteAttachedSurface,
2895 ddraw_surface7_EnumAttachedSurfaces,
2896 ddraw_surface7_EnumOverlayZOrders,
2897 ddraw_surface7_Flip,
2898 ddraw_surface7_GetAttachedSurface,
2899 ddraw_surface7_GetBltStatus,
2900 ddraw_surface7_GetCaps,
2901 ddraw_surface7_GetClipper,
2902 ddraw_surface7_GetColorKey,
2903 ddraw_surface7_GetDC,
2904 ddraw_surface7_GetFlipStatus,
2905 ddraw_surface7_GetOverlayPosition,
2906 ddraw_surface7_GetPalette,
2907 ddraw_surface7_GetPixelFormat,
2908 ddraw_surface7_GetSurfaceDesc,
2909 ddraw_surface7_Initialize,
2910 ddraw_surface7_IsLost,
2911 ddraw_surface7_Lock,
2912 ddraw_surface7_ReleaseDC,
2913 ddraw_surface7_Restore,
2914 ddraw_surface7_SetClipper,
2915 ddraw_surface7_SetColorKey,
2916 ddraw_surface7_SetOverlayPosition,
2917 ddraw_surface7_SetPalette,
2918 ddraw_surface7_Unlock,
2919 ddraw_surface7_UpdateOverlay,
2920 ddraw_surface7_UpdateOverlayDisplay,
2921 ddraw_surface7_UpdateOverlayZOrder,
2922 /* IDirectDrawSurface2 */
2923 ddraw_surface7_GetDDInterface,
2924 ddraw_surface7_PageLock,
2925 ddraw_surface7_PageUnlock,
2926 /* IDirectDrawSurface3 */
2927 ddraw_surface7_SetSurfaceDesc,
2928 /* IDirectDrawSurface4 */
2929 ddraw_surface7_SetPrivateData,
2930 ddraw_surface7_GetPrivateData,
2931 ddraw_surface7_FreePrivateData,
2932 ddraw_surface7_GetUniquenessValue,
2933 ddraw_surface7_ChangeUniquenessValue,
2934 /* IDirectDrawSurface7 */
2935 ddraw_surface7_SetPriority,
2936 ddraw_surface7_GetPriority,
2937 ddraw_surface7_SetLOD,
2938 ddraw_surface7_GetLOD,
2941 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl =
2944 ddraw_surface3_QueryInterface,
2945 ddraw_surface3_AddRef,
2946 ddraw_surface3_Release,
2947 /* IDirectDrawSurface */
2948 ddraw_surface3_AddAttachedSurface,
2949 ddraw_surface3_AddOverlayDirtyRect,
2951 ddraw_surface3_BltBatch,
2952 ddraw_surface3_BltFast,
2953 ddraw_surface3_DeleteAttachedSurface,
2954 ddraw_surface3_EnumAttachedSurfaces,
2955 ddraw_surface3_EnumOverlayZOrders,
2956 ddraw_surface3_Flip,
2957 ddraw_surface3_GetAttachedSurface,
2958 ddraw_surface3_GetBltStatus,
2959 ddraw_surface3_GetCaps,
2960 ddraw_surface3_GetClipper,
2961 ddraw_surface3_GetColorKey,
2962 ddraw_surface3_GetDC,
2963 ddraw_surface3_GetFlipStatus,
2964 ddraw_surface3_GetOverlayPosition,
2965 ddraw_surface3_GetPalette,
2966 ddraw_surface3_GetPixelFormat,
2967 ddraw_surface3_GetSurfaceDesc,
2968 ddraw_surface3_Initialize,
2969 ddraw_surface3_IsLost,
2970 ddraw_surface3_Lock,
2971 ddraw_surface3_ReleaseDC,
2972 ddraw_surface3_Restore,
2973 ddraw_surface3_SetClipper,
2974 ddraw_surface3_SetColorKey,
2975 ddraw_surface3_SetOverlayPosition,
2976 ddraw_surface3_SetPalette,
2977 ddraw_surface3_Unlock,
2978 ddraw_surface3_UpdateOverlay,
2979 ddraw_surface3_UpdateOverlayDisplay,
2980 ddraw_surface3_UpdateOverlayZOrder,
2981 /* IDirectDrawSurface2 */
2982 ddraw_surface3_GetDDInterface,
2983 ddraw_surface3_PageLock,
2984 ddraw_surface3_PageUnlock,
2985 /* IDirectDrawSurface3 */
2986 ddraw_surface3_SetSurfaceDesc,