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 %ld\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 %ld\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 %ld\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: %lx,%lx,%lx,%lx\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: %lx,%lx,%lx,%lx\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: %lx,%lx,%lx,%lx\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,%lx,%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,%lx)\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,%lx,%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)->(%08lx,%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)->(%ld): 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,%ld,%lx): 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)->(%lx)\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)->(%lx)\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,%ld,%08lx)\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)->(%lx,%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)->(%lx): 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)->(%lx): 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 %ld.\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)->(%ld,%ld): 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 FIXME("(%p)->(%p,%p,%p,%lx,%p): Stub!\n", This, SrcRect, Dst, DstRect, Flags, FX);
1567 return DDERR_UNSUPPORTED;
1570 /*****************************************************************************
1571 * IDirectDrawSurface7::UpdateOverlayDisplay
1573 * The DX7 sdk says that it's not implemented
1578 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1580 *****************************************************************************/
1581 static HRESULT WINAPI
1582 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1585 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1586 TRACE("(%p)->(%lx)\n", This, Flags);
1587 return DDERR_UNSUPPORTED;
1590 /*****************************************************************************
1591 * IDirectDrawSurface7::UpdateOverlayZOrder
1593 * Sets an overlay's Z order
1596 * Flags: DDOVERZ_* flags
1597 * DDSRef: Defines the relative position in the overlay chain
1600 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1602 *****************************************************************************/
1603 static HRESULT WINAPI
1604 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1606 IDirectDrawSurface7 *DDSRef)
1608 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1609 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1611 TRACE("(%p)->(%lx,%p): Relay\n", This, Flags, Ref);
1612 return IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1614 Ref ? Ref->WineD3DSurface : NULL);
1617 /*****************************************************************************
1618 * IDirectDrawSurface7::GetDDInterface
1620 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1621 * surface belongs to
1624 * DD: Address to write the interface pointer to
1628 * DDERR_INVALIDPARAMS if DD is NULL
1630 *****************************************************************************/
1631 static HRESULT WINAPI
1632 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1635 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1637 /* It is not quite correct to use the same lpVtable for the different
1638 * IDirectDrawSurface versions because the GetDDInterface return different interfaces
1640 FIXME("(%p)->(%p)\n",This,DD);
1643 return DDERR_INVALIDPARAMS;
1645 switch(This->version)
1648 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1649 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1653 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1654 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1658 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1659 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1667 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1668 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1670 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1671 volatile IDirectDrawSurfaceImpl* vThis = This;
1673 TRACE("(%p)\n",This);
1674 /* A uniqueness value of 0 is apparently special.
1675 * This needs to be checked. */
1677 DWORD old_uniqueness_value = vThis->uniqueness_value;
1678 DWORD new_uniqueness_value = old_uniqueness_value+1;
1680 if (old_uniqueness_value == 0) break;
1681 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1683 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1684 old_uniqueness_value,
1685 new_uniqueness_value)
1686 == old_uniqueness_value)
1693 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1695 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1697 TRACE("(%p)->(%p)\n",This,pValue);
1698 *pValue = This->uniqueness_value;
1702 /*****************************************************************************
1703 * IDirectDrawSurface7::SetLOD
1705 * Sets the level of detail of a texture
1708 * MaxLOD: LOD to set
1712 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1714 *****************************************************************************/
1715 static HRESULT WINAPI
1716 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1719 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1720 TRACE("(%p)->(%ld)\n", This, MaxLOD);
1722 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1723 return DDERR_INVALIDOBJECT;
1725 if(!This->wineD3DTexture)
1727 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1728 return DDERR_INVALIDOBJECT;
1731 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1735 /*****************************************************************************
1736 * IDirectDrawSurface7::GetLOD
1738 * Returns the level of detail of a Direct3D texture
1741 * MaxLOD: Address to write the LOD to
1745 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1746 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1748 *****************************************************************************/
1749 static HRESULT WINAPI
1750 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1753 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1754 TRACE("(%p)->(%p)\n", This, MaxLOD);
1757 return DDERR_INVALIDPARAMS;
1759 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1760 return DDERR_INVALIDOBJECT;
1762 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1766 /*****************************************************************************
1767 * IDirectDrawSurface7::BltFast
1769 * Performs a fast Blit.
1772 * dstx: The x coordinate to blit to on the destination
1773 * dsty: The y coordinate to blit to on the destination
1774 * Source: The source surface
1775 * rsrc: The source rectangle
1776 * trans: Type of transfer. Some DDBLTFAST_* flags
1780 * For more details, see IWineD3DSurface::BltFast
1782 *****************************************************************************/
1783 static HRESULT WINAPI
1784 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1787 IDirectDrawSurface7 *Source,
1791 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1792 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1793 TRACE("(%p)->(%ld,%ld,%p,%p,%ld): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1795 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1797 src ? src->WineD3DSurface : NULL,
1802 /*****************************************************************************
1803 * IDirectDrawSurface7::GetClipper
1805 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1809 * Clipper: Address to store the interface pointer at
1813 * DDERR_INVALIDPARAMS if Clipper is NULL
1814 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1816 *****************************************************************************/
1817 static HRESULT WINAPI
1818 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1819 IDirectDrawClipper **Clipper)
1821 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1822 TRACE("(%p)->(%p)\n", This, Clipper);
1825 return DDERR_INVALIDPARAMS;
1827 if(This->clipper == NULL)
1828 return DDERR_NOCLIPPERATTACHED;
1830 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1831 IDirectDrawClipper_AddRef(*Clipper);
1835 /*****************************************************************************
1836 * IDirectDrawSurface7::SetClipper
1838 * Sets a clipper for the surface
1841 * Clipper: IDirectDrawClipper interface of the clipper to set
1846 *****************************************************************************/
1847 static HRESULT WINAPI
1848 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1849 IDirectDrawClipper *Clipper)
1851 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1853 TRACE("(%p)->(%p)\n",This,Clipper);
1854 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1857 if (This->clipper != NULL)
1858 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1860 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1861 if (Clipper != NULL)
1862 IDirectDrawClipper_AddRef(Clipper);
1867 /*****************************************************************************
1868 * IDirectDrawSurface7::SetSurfaceDesc
1870 * Sets the surface description. It can override the pixel format, the surface
1872 * It's not really tested.
1875 * DDSD: Pointer to the new surface description to set
1880 * DDERR_INVALIDPARAMS if DDSD is NULL
1882 *****************************************************************************/
1883 static HRESULT WINAPI
1884 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1885 DDSURFACEDESC2 *DDSD,
1888 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1889 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1891 TRACE("(%p)->(%p,%lx)\n", This, DDSD, Flags);
1894 return DDERR_INVALIDPARAMS;
1896 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1898 ERR("Setting the surface memory isn't supported yet\n");
1899 return DDERR_INVALIDPARAMS;
1902 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1904 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1906 if(newFormat == WINED3DFMT_UNKNOWN)
1908 ERR("Requested to set an unknown pixelformat\n");
1909 return DDERR_INVALIDPARAMS;
1911 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1913 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1915 if(hr != DD_OK) return hr;
1918 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1920 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1922 &DDSD->u3.ddckCKDestOverlay);
1924 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1926 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1928 &DDSD->ddckCKDestBlt);
1930 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1932 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1934 &DDSD->ddckCKSrcOverlay);
1936 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1938 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1940 &DDSD->ddckCKSrcBlt);
1942 if (DDSD->dwFlags & DDSD_LPSURFACE)
1944 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
1945 if(hr != WINED3D_OK)
1947 /* No need for a trace here, wined3d does that for us */
1952 This->surface_desc = *DDSD;
1957 /*****************************************************************************
1958 * IDirectDrawSurface7::GetPalette
1960 * Returns the IDirectDrawPalette interface of the palette currently assigned
1964 * Pal: Address to write the interface pointer to
1968 * DDERR_INVALIDPARAMS if Pal is NULL
1970 *****************************************************************************/
1971 static HRESULT WINAPI
1972 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1973 IDirectDrawPalette **Pal)
1975 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1976 IWineD3DPalette *wPal;
1978 TRACE("(%p)->(%p): Relay\n", This, Pal);
1981 return DDERR_INVALIDPARAMS;
1983 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1984 if(hr != DD_OK) return hr;
1988 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
1993 hr = DDERR_NOPALETTEATTACHED;
1999 /*****************************************************************************
2000 * IDirectDrawSurface7::SetColorKey
2002 * Sets the color keying options for the surface. Observations showed that
2003 * in case of complex surfaces the color key has to be assigned to all
2008 * CKey: The new color key
2012 * See IWineD3DSurface::SetColorKey for details
2014 *****************************************************************************/
2015 static HRESULT WINAPI
2016 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2020 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2021 IDirectDrawSurfaceImpl *surf;
2023 TRACE("(%p)->(%lx,%p)\n", This, Flags, CKey);
2025 for(surf = This->first_complex; surf; surf = surf->next_complex)
2027 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
2032 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08lx\n",
2033 surf->WineD3DSurface, hr);
2040 /*****************************************************************************
2041 * IDirectDrawSurface7::SetPalette
2043 * Assigns a DirectDrawPalette object to the surface
2046 * Pal: Interface to the palette to set
2051 *****************************************************************************/
2052 static HRESULT WINAPI
2053 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2054 IDirectDrawPalette *Pal)
2056 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2057 IDirectDrawPalette *oldPal;
2058 IDirectDrawSurfaceImpl *surf;
2059 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2061 TRACE("(%p)->(%p)\n", This, Pal);
2063 /* Find the old palette */
2064 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2065 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED) return hr;
2066 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2068 /* Set the new Palette */
2069 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2070 PalImpl ? PalImpl->wineD3DPalette : NULL);
2071 /* AddRef the Palette */
2072 if(Pal) IDirectDrawPalette_AddRef(Pal);
2074 /* Release the old palette */
2075 if(oldPal) IDirectDrawPalette_Release(oldPal);
2077 /* If this is a front buffer, also update the back buffers */
2078 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2080 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2082 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2090 /*****************************************************************************
2092 *****************************************************************************/
2094 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2097 IDirectDrawSurfaceImpl_QueryInterface,
2098 IDirectDrawSurfaceImpl_AddRef,
2099 IDirectDrawSurfaceImpl_Release,
2100 /*** IDirectDrawSurface ***/
2101 IDirectDrawSurfaceImpl_AddAttachedSurface,
2102 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2103 IDirectDrawSurfaceImpl_Blt,
2104 IDirectDrawSurfaceImpl_BltBatch,
2105 IDirectDrawSurfaceImpl_BltFast,
2106 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2107 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2108 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2109 IDirectDrawSurfaceImpl_Flip,
2110 IDirectDrawSurfaceImpl_GetAttachedSurface,
2111 IDirectDrawSurfaceImpl_GetBltStatus,
2112 IDirectDrawSurfaceImpl_GetCaps,
2113 IDirectDrawSurfaceImpl_GetClipper,
2114 IDirectDrawSurfaceImpl_GetColorKey,
2115 IDirectDrawSurfaceImpl_GetDC,
2116 IDirectDrawSurfaceImpl_GetFlipStatus,
2117 IDirectDrawSurfaceImpl_GetOverlayPosition,
2118 IDirectDrawSurfaceImpl_GetPalette,
2119 IDirectDrawSurfaceImpl_GetPixelFormat,
2120 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2121 IDirectDrawSurfaceImpl_Initialize,
2122 IDirectDrawSurfaceImpl_IsLost,
2123 IDirectDrawSurfaceImpl_Lock,
2124 IDirectDrawSurfaceImpl_ReleaseDC,
2125 IDirectDrawSurfaceImpl_Restore,
2126 IDirectDrawSurfaceImpl_SetClipper,
2127 IDirectDrawSurfaceImpl_SetColorKey,
2128 IDirectDrawSurfaceImpl_SetOverlayPosition,
2129 IDirectDrawSurfaceImpl_SetPalette,
2130 IDirectDrawSurfaceImpl_Unlock,
2131 IDirectDrawSurfaceImpl_UpdateOverlay,
2132 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2133 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2134 /*** IDirectDrawSurface2 ***/
2135 IDirectDrawSurfaceImpl_GetDDInterface,
2136 IDirectDrawSurfaceImpl_PageLock,
2137 IDirectDrawSurfaceImpl_PageUnlock,
2138 /*** IDirectDrawSurface3 ***/
2139 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2140 /*** IDirectDrawSurface4 ***/
2141 IDirectDrawSurfaceImpl_SetPrivateData,
2142 IDirectDrawSurfaceImpl_GetPrivateData,
2143 IDirectDrawSurfaceImpl_FreePrivateData,
2144 IDirectDrawSurfaceImpl_GetUniquenessValue,
2145 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2146 /*** IDirectDrawSurface7 ***/
2147 IDirectDrawSurfaceImpl_SetPriority,
2148 IDirectDrawSurfaceImpl_GetPriority,
2149 IDirectDrawSurfaceImpl_SetLOD,
2150 IDirectDrawSurfaceImpl_GetLOD