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
42 #include "wine/exception.h"
48 #include "ddraw_private.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
53 /*****************************************************************************
54 * IUnknown parts follow
55 *****************************************************************************/
57 /*****************************************************************************
58 * IDirectDrawSurface7::QueryInterface
60 * A normal QueryInterface implementation. For QueryInterface rules
61 * see ddraw.c, IDirectDraw7::QueryInterface. This method
62 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
63 * in all versions, the IDirectDrawGammaControl interface and it can
64 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
67 * riid: The interface id queried for
68 * obj: Address to write the pointer to
72 * E_NOINTERFACE if the requested interface wasn't found
74 *****************************************************************************/
76 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
80 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
82 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
86 return DDERR_INVALIDPARAMS;
88 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
89 if (IsEqualGUID(riid, &IID_IUnknown)
90 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
91 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
93 IUnknown_AddRef(iface);
94 *obj = ICOM_INTERFACE(This, IDirectDrawSurface7);
95 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
98 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
99 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
100 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
102 IUnknown_AddRef(iface);
103 *obj = ICOM_INTERFACE(This, IDirectDrawSurface3);
104 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
107 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
109 IUnknown_AddRef(iface);
110 *obj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
111 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
114 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
115 IsEqualGUID(riid, &IID_IDirect3DHALDevice) )
117 IDirect3DDevice7 *d3d;
119 /* Call into IDirect3D7 for creation */
120 IDirect3D7_CreateDevice(ICOM_INTERFACE(This->ddraw, IDirect3D7),
122 ICOM_INTERFACE(This, IDirectDrawSurface7),
125 *obj = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice, d3d);
126 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
130 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
131 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
133 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
135 *obj = ICOM_INTERFACE(This, IDirect3DTexture);
136 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
140 *obj = ICOM_INTERFACE(This, IDirect3DTexture2);
141 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
143 IUnknown_AddRef( (IUnknown *) *obj);
147 ERR("No interface\n");
148 return E_NOINTERFACE;
151 /*****************************************************************************
152 * IDirectDrawSurface7::AddRef
154 * A normal addref implementation
159 *****************************************************************************/
161 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
163 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
164 ULONG refCount = InterlockedIncrement(&This->ref);
166 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
170 /*****************************************************************************
171 * IDirectDrawSurfaceImpl_Destroy
173 * A helper function for IDirectDrawSurface7::Release
175 * Frees the surface, regardless of its refcount.
176 * See IDirectDrawSurface7::Release for more information
179 * This: Surface to free
181 *****************************************************************************/
182 static void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
184 TRACE("(%p)\n", This);
186 /* Check the refcount and give a warning */
189 /* This can happen when a complex surface is destroyed,
190 * because the 2nd surface was addref()ed when the app
191 * called GetAttachedSurface
193 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
196 /* Check for attached surfaces and detach them */
197 if(This->first_attached != This)
199 /* Well, this shouldn't happen: The surface being attached is addref()ed
200 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
201 * is called, because the refcount is held. It looks like the app released()
202 * it often enough to force this
204 IDirectDrawSurface7 *root = ICOM_INTERFACE(This->first_attached, IDirectDrawSurface7);
205 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This, IDirectDrawSurface7);
207 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
209 /* The refcount will drop to -1 here */
210 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
212 ERR("(%p) DeleteAttachedSurface failed!\n", This);
216 while(This->next_attached != NULL)
218 IDirectDrawSurface7 *root = ICOM_INTERFACE(This, IDirectDrawSurface7);
219 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This->next_attached, IDirectDrawSurface7);
221 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
223 ERR("(%p) DeleteAttachedSurface failed!\n", This);
228 /* Now destroy the surface. Wait: It could have been released if we are a texture */
229 if(This->WineD3DSurface)
230 IWineD3DSurface_Release(This->WineD3DSurface);
232 /* Having a texture handle set implies that the device still exists */
235 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
236 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
239 /* Reduce the ddraw surface count */
240 InterlockedDecrement(&This->ddraw->surfaces);
242 This->prev->next = This->next;
245 assert(This->ddraw->surface_list == This);
246 This->ddraw->surface_list = This->next;
249 This->next->prev = This->prev;
251 HeapFree(GetProcessHeap(), 0, This);
254 /*****************************************************************************
255 * IDirectDrawSurface7::Release
257 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
258 * surface is destroyed.
260 * Destroying the surface is a bit tricky. For the connection between
261 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
262 * It has a nice graph explaining the connection.
264 * What happens here is basically this:
265 * When a surface is destroyed, its WineD3DSurface is released,
266 * and the refcount of the DirectDraw interface is reduced by 1. If it has
267 * complex surfaces attached to it, then these surfaces are destroyed too,
268 * regardless of their refcount. If any surface being destroyed has another
269 * surface attached to it (with a "soft" attachment, not complex), then
270 * this surface is detached with DeleteAttachedSurface.
272 * When the surface is a texture, the WineD3DTexture is released.
273 * If the surface is the Direct3D render target, then the D3D
274 * capabilities of the WineD3DDevice are uninitialized, which causes the
275 * swapchain to be released.
280 *****************************************************************************/
282 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
284 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
286 TRACE("(%p) : Releasing from %d\n", This, This->ref);
287 ref = InterlockedDecrement(&This->ref);
292 IDirectDrawSurfaceImpl *surf;
293 IDirectDrawImpl *ddraw;
294 IUnknown *ifaceToRelease = This->ifaceToRelease;
296 /* Complex attached surfaces are destroyed implicitely when the root is released */
297 if(This->first_complex != This)
299 WARN("(%p) Attempt to destroy a surface that is attached to a complex root %p\n", This, This->first_complex);
304 /* If it's a texture, destroy the WineD3DTexture.
305 * WineD3D will destroy the IParent interfaces
306 * of the sublevels, which destroys the WineD3DSurfaces.
307 * Set the surfaces to NULL to avoid destroying them again later
309 if(This->wineD3DTexture)
311 IWineD3DTexture_Release(This->wineD3DTexture);
313 /* If it's the RenderTarget, destroy the d3ddevice */
314 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
316 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
318 /* Unset any index buffer, just to be sure */
319 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, 0);
321 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
324 ERR("(%p) Failed to uninit 3D\n", This);
328 /* Free the d3d window if one was created */
329 if(ddraw->d3d_window != 0)
331 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
332 DestroyWindow(ddraw->d3d_window);
333 ddraw->d3d_window = 0;
335 /* Unset the pointers */
338 ddraw->d3d_initialized = FALSE;
339 ddraw->d3d_target = NULL;
341 /* Write a trace because D3D unloading was the reason for many
342 * crashes during development.
344 TRACE("(%p) D3D unloaded\n", This);
346 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
350 /* It's a render target, but no swapchain was created.
351 * The IParent interfaces have to be released manually.
352 * The same applies for textures without an
353 * IWineD3DTexture object attached
360 IWineD3DSurface_GetParent(surf->WineD3DSurface,
361 (IUnknown **) &Parent);
362 IParent_Release(Parent); /* For the getParent */
363 IParent_Release(Parent); /* To release it */
364 surf = surf->next_complex;
368 /* The refcount test shows that the palette is detached when the surface is destroyed */
369 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
372 /* Loop through all complex attached surfaces,
375 while( (surf = This->next_complex) )
377 This->next_complex = surf->next_complex; /* Unchain it from the complex listing */
378 IDirectDrawSurfaceImpl_Destroy(surf); /* Destroy it */
381 /* Destroy the surface.
383 IDirectDrawSurfaceImpl_Destroy(This);
385 /* Reduce the ddraw refcount */
386 IUnknown_Release(ifaceToRelease);
392 /*****************************************************************************
393 * IDirectDrawSurface7::GetAttachedSurface
395 * Returns an attached surface with the requested caps. Surface attachment
396 * and complex surfaces are not clearly described by the MSDN or sdk,
397 * so this method is tricky and likely to contain problems.
398 * This implementation searches the complex chain first, then the
399 * attachment chain, and then it checks if the caps match to itself.
401 * The chains are searched from This down to the last surface in the chain,
402 * not from the first element in the chain. The first surface found is
403 * returned. The MSDN says that this method fails if more than one surface
404 * matches the caps, but apparently this is incorrect.
406 * The found surface is AddRef-ed before it is returned.
409 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
410 * Surface: Address to store the found surface
414 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
415 * DDERR_NOTFOUND if no surface was found
417 *****************************************************************************/
418 static HRESULT WINAPI
419 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
421 IDirectDrawSurface7 **Surface)
423 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
424 IDirectDrawSurfaceImpl *surf;
427 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
431 if(This->version < 7)
433 /* Earlier dx apps put garbage into these members, clear them */
434 our_caps.dwCaps2 = 0;
435 our_caps.dwCaps3 = 0;
436 our_caps.dwCaps4 = 0;
439 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 */
441 /* First, look at the complex chain */
444 while( (surf = surf->next_complex) )
448 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
449 surf->surface_desc.ddsCaps.dwCaps,
450 surf->surface_desc.ddsCaps.dwCaps2,
451 surf->surface_desc.ddsCaps.dwCaps3,
452 surf->surface_desc.ddsCaps.dwCaps4);
455 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
456 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
458 /* MSDN: "This method fails if more than one surface is attached
459 * that matches the capabilities requested."
461 * The mipmap demo of the DirectX7 sdk shows what to do here:
462 * apparently apps expect the first found surface to be returned.
465 TRACE("(%p): Returning surface %p\n", This, surf);
466 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
467 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
468 IDirectDrawSurface7_AddRef(*Surface);
473 /* Next, look at the attachment chain */
476 while( (surf = surf->next_attached) )
480 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
481 surf->surface_desc.ddsCaps.dwCaps,
482 surf->surface_desc.ddsCaps.dwCaps2,
483 surf->surface_desc.ddsCaps.dwCaps3,
484 surf->surface_desc.ddsCaps.dwCaps4);
487 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
488 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
490 /* MSDN: "This method fails if more than one surface is attached
491 * that matches the capabilities requested."
493 * The mipmap demo of the DirectX7 sdk shows what to do here:
494 * apparently apps expect the first found surface to be returned.
497 TRACE("(%p): Returning surface %p\n", This, surf);
498 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
499 IDirectDrawSurface7_AddRef(*Surface);
506 if (((This->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
507 ((This->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2) &&
508 This == This->first_complex)
511 TRACE("(%p): Returning surface %p\n", This, This);
512 *Surface = ICOM_INTERFACE(This, IDirectDrawSurface7);
513 IDirectDrawSurface7_AddRef(*Surface);
518 /* What to do here? Continue with the surface root?? */
520 TRACE("(%p) Didn't find a valid surface\n", This);
521 return DDERR_NOTFOUND;
524 /*****************************************************************************
525 * IDirectDrawSurface7::Lock
527 * Locks the surface and returns a pointer to the surface's memory
530 * Rect: Rectangle to lock. If NULL, the whole surface is locked
531 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
532 * Flags: Locking flags, e.g Read only or write only
533 * h: An event handle that's not used and must be NULL
537 * DDERR_INVALIDPARAMS if DDSD is NULL
538 * For more details, see IWineD3DSurface::LockRect
540 *****************************************************************************/
541 static HRESULT WINAPI
542 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
544 DDSURFACEDESC2 *DDSD,
548 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
549 WINED3DLOCKED_RECT LockedRect;
551 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
554 return DDERR_INVALIDPARAMS;
556 /* Should I check for the handle to be NULL?
558 * The DDLOCK flags and the D3DLOCK flags are equal
559 * for the supported values. The others are ignored by WineD3D
562 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
563 * that means it doesn't have dwSize set. Init it to some sane
566 if(DDSD->dwSize <= sizeof(DDSURFACEDESC))
568 DDSD->dwSize = sizeof(DDSURFACEDESC);
572 DDSD->dwSize = sizeof(DDSURFACEDESC2);
575 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
576 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
580 if(hr != D3D_OK) return hr;
582 /* Override the memory area and the pitch */
583 DDSD->dwFlags |= DDSD_LPSURFACE;
584 DDSD->lpSurface = LockedRect.pBits;
585 DDSD->dwFlags |= DDSD_PITCH;
586 DDSD->u1.lPitch = LockedRect.Pitch;
588 TRACE("locked surface returning description :\n");
589 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
594 /*****************************************************************************
595 * IDirectDrawSurface7::Unlock
597 * Unlocks an locked surface
600 * Rect: Not used by this implementation
604 * For more details, see IWineD3DSurface::UnlockRect
606 *****************************************************************************/
607 static HRESULT WINAPI
608 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
611 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
612 TRACE("(%p)->(%p)\n", This, pRect);
614 return IWineD3DSurface_UnlockRect(This->WineD3DSurface);
617 /*****************************************************************************
618 * IDirectDrawSurface7::Flip
620 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
621 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
622 * the flip target is passed to WineD3D, even if the app didn't specify one
625 * DestOverride: Specifies the surface that will become the new front
626 * buffer. If NULL, the current back buffer is used
627 * Flags: some DirectDraw flags, see include/ddraw.h
631 * DDERR_NOTFLIPPABLE if no flip target could be found
632 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
633 * For more details, see IWineD3DSurface::Flip
635 *****************************************************************************/
636 static HRESULT WINAPI
637 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
638 IDirectDrawSurface7 *DestOverride,
641 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
642 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
643 IDirectDrawSurface7 *Override7;
645 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
647 /* Flip has to be called from a front buffer
648 * What about overlay surfaces, AFAIK they can flip too?
650 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
651 return DDERR_INVALIDOBJECT; /* Unckecked */
653 /* WineD3D doesn't keep track of attached surface, so find the target */
658 memset(&Caps, 0, sizeof(Caps));
659 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
660 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
663 ERR("Can't find a flip target\n");
664 return DDERR_NOTFLIPPABLE; /* Unchecked */
666 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
668 /* For the GetAttachedSurface */
669 IDirectDrawSurface7_Release(Override7);
672 return IWineD3DSurface_Flip(This->WineD3DSurface,
673 Override->WineD3DSurface,
677 /*****************************************************************************
678 * IDirectDrawSurface7::Blt
680 * Performs a blit on the surface
683 * DestRect: Destination rectangle, can be NULL
684 * SrcSurface: Source surface, can be NULL
685 * SrcRect: Source rectange, can be NULL
687 * DDBltFx: Some extended blt parameters, connected to the flags
691 * See IWineD3DSurface::Blt for more details
693 *****************************************************************************/
694 static HRESULT WINAPI
695 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
697 IDirectDrawSurface7 *SrcSurface,
702 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
703 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
704 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
706 return IWineD3DSurface_Blt(This->WineD3DSurface,
708 Src ? Src->WineD3DSurface : NULL,
714 /*****************************************************************************
715 * IDirectDrawSurface7::AddAttachedSurface
717 * Attaches a surface to another surface. Surface attachments are
718 * incorrectly described in the SDK and the MSDN, and this method
719 * is prone to bugs. The surface that is attached is AddRef-ed.
721 * The attachment list consists of a first surface (first_attached) and
722 * for each surface a pointer to the next attached surface (next_attached).
723 * For the first surface, and a surface that has no attachments
724 * first_attached points to the surface itself. A surface that has
725 * no successors in the chain has next_attached set to NULL.
727 * Newly attached surfaces are attached right after the root surface. The
728 * complex chains are handled separately in a similar chain, with
729 * first_complex and next_complex. If a surface is attached to a complex
730 * surface compound, it's attached to the surface that the app requested,
731 * not the complex root. See GetAttachedSurface for a description
732 * how surfaces are found.
734 * This is how the current implementation works, and it was coded by looking
735 * at the needs of the applications.
737 * So far only Z-Buffer attachments are tested, but there's no code yet
738 * to activate them. Mipmaps could be tricky to activate in WineD3D.
739 * Back buffers should work in 2D mode, but they are not tested.
740 * Rendering to the primary surface and switching between that and
741 * double buffering is not yet implemented in WineD3D, so for 3D it might
742 * have unexpected results.
745 * Attach: Surface to attach to iface
749 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
751 *****************************************************************************/
752 static HRESULT WINAPI
753 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
754 IDirectDrawSurface7 *Attach)
756 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
757 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
758 TRACE("(%p)->(%p)\n", This, Surf);
760 /* Should I make sure to add it to the first complex surface? */
763 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
765 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
766 * But apparently backbuffers and mipmaps can be attached too. */
768 /* Set MIPMAPSUBLEVEL if this seems to be one */
769 if (This->surface_desc.ddsCaps.dwCaps &
770 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
772 Surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
773 /* FIXME: we should probably also add to dwMipMapCount of this
774 * and all parent surfaces (update create_texture if you do) */
777 /* Check if the surface is already attached somewhere */
778 if( (Surf->next_attached != NULL) ||
779 (Surf->first_attached != Surf) )
781 ERR("(%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);
782 return DDERR_CANNOTATTACHSURFACE;
785 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
786 Surf->next_attached = This->next_attached;
787 Surf->first_attached = This->first_attached;
788 This->next_attached = Surf;
791 * "This method increments the reference count of the surface being attached."
793 IDirectDrawSurface7_AddRef(Attach);
797 /*****************************************************************************
798 * IDirectDrawSurface7::DeleteAttachedSurface
800 * Removes a surface from the attachment chain. The surface's refcount
801 * is decreased by one after it has been removed
804 * Flags: Some flags, not used by this implementation
805 * Attach: Surface to detach
809 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
811 *****************************************************************************/
812 static HRESULT WINAPI
813 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
815 IDirectDrawSurface7 *Attach)
817 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
818 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
819 IDirectDrawSurfaceImpl *Prev = This;
820 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
822 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
823 return DDERR_SURFACENOTATTACHED; /* unchecked */
825 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
826 if (This->surface_desc.ddsCaps.dwCaps &
827 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
829 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
830 /* FIXME: we should probably also subtract from dwMipMapCount of this
831 * and all parent surfaces */
834 /* Find the predecessor of the detached surface */
837 if(Prev->next_attached == Surf) break;
838 Prev = Prev->next_attached;
841 /* There must be a surface, otherwise there's a bug */
842 assert(Prev != NULL);
844 /* Unchain the surface */
845 Prev->next_attached = Surf->next_attached;
846 Surf->next_attached = NULL;
847 Surf->first_attached = Surf;
849 IDirectDrawSurface7_Release(Attach);
853 /*****************************************************************************
854 * IDirectDrawSurface7::AddOverlayDirtyRect
856 * "This method is not currently implemented"
864 *****************************************************************************/
865 static HRESULT WINAPI
866 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
869 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
870 TRACE("(%p)->(%p)\n",This,Rect);
872 /* MSDN says it's not implemented. I could forward it to WineD3D,
873 * then we'd implement it, but I don't think that's a good idea
877 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
879 return DDERR_UNSUPPORTED; /* unchecked */
882 /*****************************************************************************
883 * IDirectDrawSurface7::GetDC
885 * Returns a GDI device context for the surface
888 * hdc: Address of a HDC variable to store the dc to
892 * DDERR_INVALIDPARAMS if hdc is NULL
893 * For details, see IWineD3DSurface::GetDC
895 *****************************************************************************/
896 static HRESULT WINAPI
897 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
900 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
901 TRACE("(%p)->(%p): Relay\n", This, hdc);
904 return DDERR_INVALIDPARAMS;
906 return IWineD3DSurface_GetDC(This->WineD3DSurface,
910 /*****************************************************************************
911 * IDirectDrawSurface7::ReleaseDC
913 * Releases the DC that was constructed with GetDC
916 * hdc: HDC to release
920 * For more details, see IWineD3DSurface::ReleaseDC
922 *****************************************************************************/
923 static HRESULT WINAPI
924 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
927 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
928 TRACE("(%p)->(%p): Relay\n", This, hdc);
930 return IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
933 /*****************************************************************************
934 * IDirectDrawSurface7::GetCaps
936 * Returns the surface's caps
939 * Caps: Address to write the caps to
943 * DDERR_INVALIDPARAMS if Caps is NULL
945 *****************************************************************************/
946 static HRESULT WINAPI
947 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
950 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
951 TRACE("(%p)->(%p)\n",This,Caps);
954 return DDERR_INVALIDPARAMS;
956 *Caps = This->surface_desc.ddsCaps;
960 /*****************************************************************************
961 * IDirectDrawSurface7::SetPriority
963 * Sets a texture priority for managed textures.
966 * Priority: The new priority
970 * For more details, see IWineD3DSurface::SetPriority
972 *****************************************************************************/
973 static HRESULT WINAPI
974 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
976 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
977 TRACE("(%p)->(%d): Relay!\n",This,Priority);
979 return IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
982 /*****************************************************************************
983 * IDirectDrawSurface7::GetPriority
985 * Returns the surface's priority
988 * Priority: Address of a variable to write the priority to
992 * DDERR_INVALIDPARAMS if Priority == NULL
993 * For more details, see IWineD3DSurface::GetPriority
995 *****************************************************************************/
996 static HRESULT WINAPI
997 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1000 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1001 TRACE("(%p)->(%p): Relay\n",This,Priority);
1004 return DDERR_INVALIDPARAMS;
1006 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1010 /*****************************************************************************
1011 * IDirectDrawSurface7::SetPrivateData
1013 * Stores some data in the surface that is intended for the application's
1017 * tag: GUID that identifies the data
1018 * Data: Pointer to the private data
1019 * Size: Size of the private data
1024 * For more details, see IWineD3DSurface::SetPrivateData
1026 *****************************************************************************/
1027 static HRESULT WINAPI
1028 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1034 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1035 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1037 return IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1044 /*****************************************************************************
1045 * IDirectDrawSurface7::GetPrivateData
1047 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1050 * tag: GUID of the data to return
1051 * Data: Address where to write the data to
1052 * Size: Size of the buffer at Data
1056 * DDERR_INVALIDPARAMS if Data is NULL
1057 * For more details, see IWineD3DSurface::GetPrivateData
1059 *****************************************************************************/
1060 static HRESULT WINAPI
1061 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1066 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1067 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1070 return DDERR_INVALIDPARAMS;
1072 return IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1078 /*****************************************************************************
1079 * IDirectDrawSurface7::FreePrivateData
1081 * Frees private data stored in the surface
1084 * tag: Tag of the data to free
1088 * For more details, see IWineD3DSurface::FreePrivateData
1090 *****************************************************************************/
1091 static HRESULT WINAPI
1092 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1095 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1096 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1098 return IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1101 /*****************************************************************************
1102 * IDirectDrawSurface7::PageLock
1104 * Prevents a sysmem surface from being paged out
1107 * Flags: Not used, must be 0(unchecked)
1110 * DD_OK, because it's a stub
1112 *****************************************************************************/
1113 static HRESULT WINAPI
1114 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1117 TRACE("(%p)->(%x)\n", iface, Flags);
1119 /* This is Windows memory management related - we don't need this */
1123 /*****************************************************************************
1124 * IDirectDrawSurface7::PageUnlock
1126 * Allows a sysmem surface to be paged out
1129 * Flags: Not used, must be 0(unckeched)
1132 * DD_OK, because it's a stub
1134 *****************************************************************************/
1135 static HRESULT WINAPI
1136 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1139 TRACE("(%p)->(%x)\n", iface, Flags);
1144 /*****************************************************************************
1145 * IDirectDrawSurface7::BltBatch
1147 * An unimplemented function
1155 *****************************************************************************/
1156 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1158 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1160 /* MSDN: "not currently implemented" */
1161 return DDERR_UNSUPPORTED;
1164 /*****************************************************************************
1165 * IDirectDrawSurface7::EnumAttachedSurfaces
1167 * Enumerates all surfaces attached to this surface
1170 * context: Pointer to pass unmodified to the callback
1171 * cb: Callback function to call for each surface
1175 * DDERR_INVALIDPARAMS if cb is NULL
1177 *****************************************************************************/
1178 static HRESULT WINAPI
1179 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1181 LPDDENUMSURFACESCALLBACK7 cb)
1183 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1184 IDirectDrawSurfaceImpl *surf;
1185 DDSURFACEDESC2 desc;
1187 /* Attached surfaces aren't handled in WineD3D */
1188 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1191 return DDERR_INVALIDPARAMS;
1193 for (surf = This->next_complex; surf != NULL; surf = surf->next_complex)
1195 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1196 desc = surf->surface_desc;
1197 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1198 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1202 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1204 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1205 desc = surf->surface_desc;
1206 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1207 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1211 TRACE(" end of enumeration.\n");
1216 /*****************************************************************************
1217 * IDirectDrawSurface7::EnumOverlayZOrders
1219 * "Enumerates the overlay surfaces on the specified destination"
1222 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1223 * context: context to pass back to the callback
1224 * cb: callback function to call for each enumerated surface
1227 * DD_OK, because it's a stub
1229 *****************************************************************************/
1230 static HRESULT WINAPI
1231 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1234 LPDDENUMSURFACESCALLBACK7 cb)
1236 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1241 /*****************************************************************************
1242 * IDirectDrawSurface7::GetBltStatus
1244 * Returns the blitting status
1247 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1250 * See IWineD3DSurface::Blt
1252 *****************************************************************************/
1253 static HRESULT WINAPI
1254 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1257 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1258 TRACE("(%p)->(%x): Relay\n", This, Flags);
1260 return IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1263 /*****************************************************************************
1264 * IDirectDrawSurface7::GetColorKey
1266 * Returns the color key assigned to the surface
1270 * CKey: Address to store the key to
1274 * DDERR_INVALIDPARAMS if CKey is NULL
1276 *****************************************************************************/
1277 static HRESULT WINAPI
1278 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1282 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1283 * isn't there? That's like saying that an int isn't there. (Which MS
1284 * has done in other docs.) */
1286 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1289 return DDERR_INVALIDPARAMS;
1293 case DDCKEY_DESTBLT:
1294 *CKey = This->surface_desc.ddckCKDestBlt;
1297 case DDCKEY_DESTOVERLAY:
1298 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1302 *CKey = This->surface_desc.ddckCKSrcBlt;
1305 case DDCKEY_SRCOVERLAY:
1306 *CKey = This->surface_desc.ddckCKSrcOverlay;
1310 return DDERR_INVALIDPARAMS;
1316 /*****************************************************************************
1317 * IDirectDrawSurface7::GetFlipStatus
1319 * Returns the flipping status of the surface
1322 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1325 * See IWineD3DSurface::GetFlipStatus
1327 *****************************************************************************/
1328 static HRESULT WINAPI
1329 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1332 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1333 TRACE("(%p)->(%x): Relay\n", This, Flags);
1335 return IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1338 /*****************************************************************************
1339 * IDirectDrawSurface7::GetOverlayPosition
1341 * Returns the display coordinates of a visible and active overlay surface
1348 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1349 *****************************************************************************/
1350 static HRESULT WINAPI
1351 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1354 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1355 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1357 return IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1362 /*****************************************************************************
1363 * IDirectDrawSurface7::GetPixelFormat
1365 * Returns the pixel format of the Surface
1368 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1369 * format should be written
1373 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1375 *****************************************************************************/
1376 static HRESULT WINAPI
1377 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1378 DDPIXELFORMAT *PixelFormat)
1380 /* What is DDERR_INVALIDSURFACETYPE for here? */
1381 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1382 TRACE("(%p)->(%p)\n",This,PixelFormat);
1385 return DDERR_INVALIDPARAMS;
1387 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1393 /*****************************************************************************
1394 * IDirectDrawSurface7::GetSurfaceDesc
1396 * Returns the description of this surface
1399 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1404 * DDERR_INVALIDPARAMS if DDSD is NULL
1406 *****************************************************************************/
1407 static HRESULT WINAPI
1408 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1409 DDSURFACEDESC2 *DDSD)
1411 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1413 TRACE("(%p)->(%p)\n",This,DDSD);
1416 return DDERR_INVALIDPARAMS;
1418 if ((DDSD->dwSize < sizeof(DDSURFACEDESC)) ||
1419 (DDSD->dwSize > sizeof(DDSURFACEDESC2)))
1421 ERR("Impossible/Strange struct size %d.\n",DDSD->dwSize);
1422 return DDERR_GENERIC;
1425 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1426 TRACE("Returning surface desc:\n");
1427 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1432 /*****************************************************************************
1433 * IDirectDrawSurface7::Initialize
1435 * Initializes the surface. This is a no-op in Wine
1438 * DD: Pointer to an DirectDraw interface
1439 * DDSD: Surface description for initialization
1442 * DDERR_ALREADYINITIALIZED
1444 *****************************************************************************/
1445 static HRESULT WINAPI
1446 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1448 DDSURFACEDESC2 *DDSD)
1450 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1451 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1452 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1454 return DDERR_ALREADYINITIALIZED;
1457 /*****************************************************************************
1458 * IDirectDrawSurface7::IsLost
1460 * Checks if the surface is lost
1463 * DD_OK, if the surface is useable
1464 * DDERR_ISLOST if the surface is lost
1465 * See IWineD3DSurface::IsLost for more details
1467 *****************************************************************************/
1468 static HRESULT WINAPI
1469 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1471 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1472 TRACE("(%p)\n", This);
1474 /* We lose the surface if the implementation was changed */
1475 if(This->ImplType != This->ddraw->ImplType)
1477 /* But this shouldn't happen. When we change the implementation,
1478 * all surfaces are re-created automatically, and their content
1481 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1482 return DDERR_SURFACELOST;
1485 return IWineD3DSurface_IsLost(This->WineD3DSurface);
1488 /*****************************************************************************
1489 * IDirectDrawSurface7::Restore
1491 * Restores a lost surface. This makes the surface usable again, but
1492 * doesn't reload its old contents
1496 * See IWineD3DSurface::Restore for more details
1498 *****************************************************************************/
1499 static HRESULT WINAPI
1500 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1502 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1503 TRACE("(%p)\n", This);
1505 if(This->ImplType != This->ddraw->ImplType)
1507 /* Call the recreation callback. Make sure to AddRef first */
1508 IDirectDrawSurface_AddRef(iface);
1509 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1510 &This->surface_desc,
1511 NULL /* Not needed */);
1513 return IWineD3DSurface_Restore(This->WineD3DSurface);
1516 /*****************************************************************************
1517 * IDirectDrawSurface7::SetOverlayPosition
1519 * Changes the display coordinates of an overlay surface
1526 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1527 *****************************************************************************/
1528 static HRESULT WINAPI
1529 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1533 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1534 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1536 return IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1541 /*****************************************************************************
1542 * IDirectDrawSurface7::UpdateOverlay
1544 * Modifies the attributes of an overlay surface.
1547 * SrcRect: The section of the source being used for the overlay
1548 * DstSurface: Address of the surface that is overlaid
1549 * DstRect: Place of the overlay
1550 * Flags: some DDOVER_* flags
1553 * DDERR_UNSUPPORTED, because we don't support overlays
1555 *****************************************************************************/
1556 static HRESULT WINAPI
1557 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1559 IDirectDrawSurface7 *DstSurface,
1564 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1565 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1566 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1568 return IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1570 Dst ? Dst->WineD3DSurface : NULL,
1573 (WINEDDOVERLAYFX *) FX);
1576 /*****************************************************************************
1577 * IDirectDrawSurface7::UpdateOverlayDisplay
1579 * The DX7 sdk says that it's not implemented
1584 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1586 *****************************************************************************/
1587 static HRESULT WINAPI
1588 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1591 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1592 TRACE("(%p)->(%x)\n", This, Flags);
1593 return DDERR_UNSUPPORTED;
1596 /*****************************************************************************
1597 * IDirectDrawSurface7::UpdateOverlayZOrder
1599 * Sets an overlay's Z order
1602 * Flags: DDOVERZ_* flags
1603 * DDSRef: Defines the relative position in the overlay chain
1606 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1608 *****************************************************************************/
1609 static HRESULT WINAPI
1610 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1612 IDirectDrawSurface7 *DDSRef)
1614 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1615 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1617 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1618 return IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1620 Ref ? Ref->WineD3DSurface : NULL);
1623 /*****************************************************************************
1624 * IDirectDrawSurface7::GetDDInterface
1626 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1627 * surface belongs to
1630 * DD: Address to write the interface pointer to
1634 * DDERR_INVALIDPARAMS if DD is NULL
1636 *****************************************************************************/
1637 static HRESULT WINAPI
1638 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1641 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1643 /* It is not quite correct to use the same lpVtable for the different
1644 * IDirectDrawSurface versions because the GetDDInterface return different interfaces
1646 FIXME("(%p)->(%p)\n",This,DD);
1649 return DDERR_INVALIDPARAMS;
1651 switch(This->version)
1654 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1655 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1659 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1660 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1664 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1665 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1673 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1674 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1676 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1677 volatile IDirectDrawSurfaceImpl* vThis = This;
1679 TRACE("(%p)\n",This);
1680 /* A uniqueness value of 0 is apparently special.
1681 * This needs to be checked. */
1683 DWORD old_uniqueness_value = vThis->uniqueness_value;
1684 DWORD new_uniqueness_value = old_uniqueness_value+1;
1686 if (old_uniqueness_value == 0) break;
1687 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1689 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1690 old_uniqueness_value,
1691 new_uniqueness_value)
1692 == old_uniqueness_value)
1699 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1701 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1703 TRACE("(%p)->(%p)\n",This,pValue);
1704 *pValue = This->uniqueness_value;
1708 /*****************************************************************************
1709 * IDirectDrawSurface7::SetLOD
1711 * Sets the level of detail of a texture
1714 * MaxLOD: LOD to set
1718 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1720 *****************************************************************************/
1721 static HRESULT WINAPI
1722 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1725 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1726 TRACE("(%p)->(%d)\n", This, MaxLOD);
1728 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1729 return DDERR_INVALIDOBJECT;
1731 if(!This->wineD3DTexture)
1733 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1734 return DDERR_INVALIDOBJECT;
1737 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1741 /*****************************************************************************
1742 * IDirectDrawSurface7::GetLOD
1744 * Returns the level of detail of a Direct3D texture
1747 * MaxLOD: Address to write the LOD to
1751 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1752 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1754 *****************************************************************************/
1755 static HRESULT WINAPI
1756 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1759 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1760 TRACE("(%p)->(%p)\n", This, MaxLOD);
1763 return DDERR_INVALIDPARAMS;
1765 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1766 return DDERR_INVALIDOBJECT;
1768 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1772 /*****************************************************************************
1773 * IDirectDrawSurface7::BltFast
1775 * Performs a fast Blit.
1778 * dstx: The x coordinate to blit to on the destination
1779 * dsty: The y coordinate to blit to on the destination
1780 * Source: The source surface
1781 * rsrc: The source rectangle
1782 * trans: Type of transfer. Some DDBLTFAST_* flags
1786 * For more details, see IWineD3DSurface::BltFast
1788 *****************************************************************************/
1789 static HRESULT WINAPI
1790 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1793 IDirectDrawSurface7 *Source,
1797 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1798 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1799 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1801 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1803 src ? src->WineD3DSurface : NULL,
1808 /*****************************************************************************
1809 * IDirectDrawSurface7::GetClipper
1811 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1815 * Clipper: Address to store the interface pointer at
1819 * DDERR_INVALIDPARAMS if Clipper is NULL
1820 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1822 *****************************************************************************/
1823 static HRESULT WINAPI
1824 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1825 IDirectDrawClipper **Clipper)
1827 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1828 TRACE("(%p)->(%p)\n", This, Clipper);
1831 return DDERR_INVALIDPARAMS;
1833 if(This->clipper == NULL)
1834 return DDERR_NOCLIPPERATTACHED;
1836 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1837 IDirectDrawClipper_AddRef(*Clipper);
1841 /*****************************************************************************
1842 * IDirectDrawSurface7::SetClipper
1844 * Sets a clipper for the surface
1847 * Clipper: IDirectDrawClipper interface of the clipper to set
1852 *****************************************************************************/
1853 static HRESULT WINAPI
1854 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1855 IDirectDrawClipper *Clipper)
1857 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1859 TRACE("(%p)->(%p)\n",This,Clipper);
1860 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1863 if (This->clipper != NULL)
1864 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1866 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1867 if (Clipper != NULL)
1868 IDirectDrawClipper_AddRef(Clipper);
1873 /*****************************************************************************
1874 * IDirectDrawSurface7::SetSurfaceDesc
1876 * Sets the surface description. It can override the pixel format, the surface
1878 * It's not really tested.
1881 * DDSD: Pointer to the new surface description to set
1886 * DDERR_INVALIDPARAMS if DDSD is NULL
1888 *****************************************************************************/
1889 static HRESULT WINAPI
1890 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1891 DDSURFACEDESC2 *DDSD,
1894 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1895 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1897 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
1900 return DDERR_INVALIDPARAMS;
1902 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1904 ERR("Setting the surface memory isn't supported yet\n");
1905 return DDERR_INVALIDPARAMS;
1908 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1910 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1912 if(newFormat == WINED3DFMT_UNKNOWN)
1914 ERR("Requested to set an unknown pixelformat\n");
1915 return DDERR_INVALIDPARAMS;
1917 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1919 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1921 if(hr != DD_OK) return hr;
1924 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1926 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1928 &DDSD->u3.ddckCKDestOverlay);
1930 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1932 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1934 &DDSD->ddckCKDestBlt);
1936 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1938 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1940 &DDSD->ddckCKSrcOverlay);
1942 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1944 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1946 &DDSD->ddckCKSrcBlt);
1948 if (DDSD->dwFlags & DDSD_LPSURFACE)
1950 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
1951 if(hr != WINED3D_OK)
1953 /* No need for a trace here, wined3d does that for us */
1958 This->surface_desc = *DDSD;
1963 /*****************************************************************************
1964 * IDirectDrawSurface7::GetPalette
1966 * Returns the IDirectDrawPalette interface of the palette currently assigned
1970 * Pal: Address to write the interface pointer to
1974 * DDERR_INVALIDPARAMS if Pal is NULL
1976 *****************************************************************************/
1977 static HRESULT WINAPI
1978 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1979 IDirectDrawPalette **Pal)
1981 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1982 IWineD3DPalette *wPal;
1984 TRACE("(%p)->(%p): Relay\n", This, Pal);
1987 return DDERR_INVALIDPARAMS;
1989 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1990 if(hr != DD_OK) return hr;
1994 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
1999 hr = DDERR_NOPALETTEATTACHED;
2005 /*****************************************************************************
2006 * IDirectDrawSurface7::SetColorKey
2008 * Sets the color keying options for the surface. Observations showed that
2009 * in case of complex surfaces the color key has to be assigned to all
2014 * CKey: The new color key
2018 * See IWineD3DSurface::SetColorKey for details
2020 *****************************************************************************/
2021 static HRESULT WINAPI
2022 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2026 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2027 IDirectDrawSurfaceImpl *surf;
2029 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2031 for(surf = This->first_complex; surf; surf = surf->next_complex)
2033 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
2038 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08x\n",
2039 surf->WineD3DSurface, hr);
2046 /*****************************************************************************
2047 * IDirectDrawSurface7::SetPalette
2049 * Assigns a DirectDrawPalette object to the surface
2052 * Pal: Interface to the palette to set
2057 *****************************************************************************/
2058 static HRESULT WINAPI
2059 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2060 IDirectDrawPalette *Pal)
2062 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2063 IDirectDrawPalette *oldPal;
2064 IDirectDrawSurfaceImpl *surf;
2065 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2067 TRACE("(%p)->(%p)\n", This, Pal);
2069 /* Find the old palette */
2070 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2071 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED) return hr;
2072 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2074 /* Set the new Palette */
2075 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2076 PalImpl ? PalImpl->wineD3DPalette : NULL);
2077 /* AddRef the Palette */
2078 if(Pal) IDirectDrawPalette_AddRef(Pal);
2080 /* Release the old palette */
2081 if(oldPal) IDirectDrawPalette_Release(oldPal);
2083 /* If this is a front buffer, also update the back buffers */
2084 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2086 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2088 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2096 /*****************************************************************************
2098 *****************************************************************************/
2100 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2103 IDirectDrawSurfaceImpl_QueryInterface,
2104 IDirectDrawSurfaceImpl_AddRef,
2105 IDirectDrawSurfaceImpl_Release,
2106 /*** IDirectDrawSurface ***/
2107 IDirectDrawSurfaceImpl_AddAttachedSurface,
2108 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2109 IDirectDrawSurfaceImpl_Blt,
2110 IDirectDrawSurfaceImpl_BltBatch,
2111 IDirectDrawSurfaceImpl_BltFast,
2112 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2113 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2114 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2115 IDirectDrawSurfaceImpl_Flip,
2116 IDirectDrawSurfaceImpl_GetAttachedSurface,
2117 IDirectDrawSurfaceImpl_GetBltStatus,
2118 IDirectDrawSurfaceImpl_GetCaps,
2119 IDirectDrawSurfaceImpl_GetClipper,
2120 IDirectDrawSurfaceImpl_GetColorKey,
2121 IDirectDrawSurfaceImpl_GetDC,
2122 IDirectDrawSurfaceImpl_GetFlipStatus,
2123 IDirectDrawSurfaceImpl_GetOverlayPosition,
2124 IDirectDrawSurfaceImpl_GetPalette,
2125 IDirectDrawSurfaceImpl_GetPixelFormat,
2126 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2127 IDirectDrawSurfaceImpl_Initialize,
2128 IDirectDrawSurfaceImpl_IsLost,
2129 IDirectDrawSurfaceImpl_Lock,
2130 IDirectDrawSurfaceImpl_ReleaseDC,
2131 IDirectDrawSurfaceImpl_Restore,
2132 IDirectDrawSurfaceImpl_SetClipper,
2133 IDirectDrawSurfaceImpl_SetColorKey,
2134 IDirectDrawSurfaceImpl_SetOverlayPosition,
2135 IDirectDrawSurfaceImpl_SetPalette,
2136 IDirectDrawSurfaceImpl_Unlock,
2137 IDirectDrawSurfaceImpl_UpdateOverlay,
2138 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2139 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2140 /*** IDirectDrawSurface2 ***/
2141 IDirectDrawSurfaceImpl_GetDDInterface,
2142 IDirectDrawSurfaceImpl_PageLock,
2143 IDirectDrawSurfaceImpl_PageUnlock,
2144 /*** IDirectDrawSurface3 ***/
2145 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2146 /*** IDirectDrawSurface4 ***/
2147 IDirectDrawSurfaceImpl_SetPrivateData,
2148 IDirectDrawSurfaceImpl_GetPrivateData,
2149 IDirectDrawSurfaceImpl_FreePrivateData,
2150 IDirectDrawSurfaceImpl_GetUniquenessValue,
2151 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2152 /*** IDirectDrawSurface7 ***/
2153 IDirectDrawSurfaceImpl_SetPriority,
2154 IDirectDrawSurfaceImpl_GetPriority,
2155 IDirectDrawSurfaceImpl_SetLOD,
2156 IDirectDrawSurfaceImpl_GetLOD