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 /* Destroy all complex attached surfaces
297 * Therefore, start with the first surface,
298 * except for textures. Not entirely sure what has
299 * to happen exactly in this case
301 if( (This->first_complex != This) && !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE))
303 FIXME("(%p) Destroying a surface which is a attached to a complex root %p\n", This, This->first_complex);
307 /* If it's a texture, destroy the WineD3DTexture.
308 * WineD3D will destroy the IParent interfaces
309 * of the sublevels, which destroys the WineD3DSurfaces.
310 * Set the surfaces to NULL to avoid destroying them again later
312 if(This->wineD3DTexture)
314 IWineD3DTexture_Release(This->wineD3DTexture);
316 /* If it's the RenderTarget, destroy the d3ddevice */
317 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
319 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
321 /* Unset any index buffer, just to be sure */
322 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, 0);
324 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
327 ERR("(%p) Failed to uninit 3D\n", This);
331 /* Free the d3d window if one was created */
332 if(ddraw->d3d_window != 0)
334 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
335 DestroyWindow(ddraw->d3d_window);
336 ddraw->d3d_window = 0;
338 /* Unset the pointers */
341 ddraw->d3d_initialized = FALSE;
342 ddraw->d3d_target = NULL;
344 /* Write a trace because D3D unloading was the reason for many
345 * crashes during development.
347 TRACE("(%p) D3D unloaded\n", This);
349 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
353 /* It's a render target, but no swapchain was created.
354 * The IParent interfaces have to be released manually.
355 * The same applies for textures without an
356 * IWineD3DTexture object attached
363 IWineD3DSurface_GetParent(surf->WineD3DSurface,
364 (IUnknown **) &Parent);
365 IParent_Release(Parent); /* For the getParent */
366 IParent_Release(Parent); /* To release it */
367 surf = surf->next_complex;
371 /* The refcount test shows that the palette is detached when the surface is destroyed */
372 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
375 /* Loop through all complex attached surfaces,
378 while( (surf = This->next_complex) )
380 This->next_complex = surf->next_complex; /* Unchain it from the complex listing */
381 IDirectDrawSurfaceImpl_Destroy(surf); /* Destroy it */
384 /* Destroy the surface.
386 IDirectDrawSurfaceImpl_Destroy(This);
388 /* Reduce the ddraw refcount */
389 IUnknown_Release(ifaceToRelease);
395 /*****************************************************************************
396 * IDirectDrawSurface7::GetAttachedSurface
398 * Returns an attached surface with the requested caps. Surface attachment
399 * and complex surfaces are not clearly described by the MSDN or sdk,
400 * so this method is tricky and likely to contain problems.
401 * This implementation searches the complex chain first, then the
402 * attachment chain, and then it checks if the caps match to itself.
404 * The chains are searched from This down to the last surface in the chain,
405 * not from the first element in the chain. The first surface found is
406 * returned. The MSDN says that this method fails if more than one surface
407 * matches the caps, but apparently this is incorrect.
409 * The found surface is AddRef-ed before it is returned.
412 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
413 * Surface: Address to store the found surface
417 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
418 * DDERR_NOTFOUND if no surface was found
420 *****************************************************************************/
421 static HRESULT WINAPI
422 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
424 IDirectDrawSurface7 **Surface)
426 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
427 IDirectDrawSurfaceImpl *surf;
430 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
434 if(This->version < 7)
436 /* Earlier dx apps put garbage into these members, clear them */
437 our_caps.dwCaps2 = 0;
438 our_caps.dwCaps3 = 0;
439 our_caps.dwCaps4 = 0;
442 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 */
444 /* First, look at the complex chain */
447 while( (surf = surf->next_complex) )
451 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx\n", surf,
452 surf->surface_desc.ddsCaps.dwCaps,
453 surf->surface_desc.ddsCaps.dwCaps2,
454 surf->surface_desc.ddsCaps.dwCaps3,
455 surf->surface_desc.ddsCaps.dwCaps4);
458 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
459 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
461 /* MSDN: "This method fails if more than one surface is attached
462 * that matches the capabilities requested."
464 * The mipmap demo of the DirectX7 sdk shows what to do here:
465 * apparently apps expect the first found surface to be returned.
468 TRACE("(%p): Returning surface %p\n", This, surf);
469 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
470 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
471 IDirectDrawSurface7_AddRef(*Surface);
476 /* Next, look at the attachment chain */
479 while( (surf = surf->next_attached) )
483 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx\n", surf,
484 surf->surface_desc.ddsCaps.dwCaps,
485 surf->surface_desc.ddsCaps.dwCaps2,
486 surf->surface_desc.ddsCaps.dwCaps3,
487 surf->surface_desc.ddsCaps.dwCaps4);
490 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
491 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
493 /* MSDN: "This method fails if more than one surface is attached
494 * that matches the capabilities requested."
496 * The mipmap demo of the DirectX7 sdk shows what to do here:
497 * apparently apps expect the first found surface to be returned.
500 TRACE("(%p): Returning surface %p\n", This, surf);
501 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
502 IDirectDrawSurface7_AddRef(*Surface);
509 if (((This->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
510 ((This->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2) &&
511 This == This->first_complex)
514 TRACE("(%p): Returning surface %p\n", This, This);
515 *Surface = ICOM_INTERFACE(This, IDirectDrawSurface7);
516 IDirectDrawSurface7_AddRef(*Surface);
521 /* What to do here? Continue with the surface root?? */
523 TRACE("(%p) Didn't find a valid surface\n", This);
524 return DDERR_NOTFOUND;
527 /*****************************************************************************
528 * IDirectDrawSurface7::Lock
530 * Locks the surface and returns a pointer to the surface's memory
533 * Rect: Rectangle to lock. If NULL, the whole surface is locked
534 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
535 * Flags: Locking flags, e.g Read only or write only
536 * h: An event handle that's not used and must be NULL
540 * DDERR_INVALIDPARAMS if DDSD is NULL
541 * For more details, see IWineD3DSurface::LockRect
543 *****************************************************************************/
544 static HRESULT WINAPI
545 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
547 DDSURFACEDESC2 *DDSD,
551 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
552 WINED3DLOCKED_RECT LockedRect;
554 TRACE("(%p)->(%p,%p,%lx,%p)\n", This, Rect, DDSD, Flags, h);
557 return DDERR_INVALIDPARAMS;
559 /* Should I check for the handle to be NULL?
561 * The DDLOCK flags and the D3DLOCK flags are equal
562 * for the supported values. The others are ignored by WineD3D
565 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
566 * that means it doesn't have dwSize set. Init it to some sane
569 if(DDSD->dwSize <= sizeof(DDSURFACEDESC))
571 DDSD->dwSize = sizeof(DDSURFACEDESC);
575 DDSD->dwSize = sizeof(DDSURFACEDESC2);
578 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
579 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
583 if(hr != D3D_OK) return hr;
585 /* Override the memory area and the pitch */
586 DDSD->dwFlags |= DDSD_LPSURFACE;
587 DDSD->lpSurface = LockedRect.pBits;
588 DDSD->dwFlags |= DDSD_PITCH;
589 DDSD->u1.lPitch = LockedRect.Pitch;
591 TRACE("locked surface returning description :\n");
592 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
597 /*****************************************************************************
598 * IDirectDrawSurface7::Unlock
600 * Unlocks an locked surface
603 * Rect: Not used by this implementation
607 * For more details, see IWineD3DSurface::UnlockRect
609 *****************************************************************************/
610 static HRESULT WINAPI
611 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
614 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
615 TRACE("(%p)->(%p)\n", This, pRect);
617 return IWineD3DSurface_UnlockRect(This->WineD3DSurface);
620 /*****************************************************************************
621 * IDirectDrawSurface7::Flip
623 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
624 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
625 * the flip target is passed to WineD3D, even if the app didn't specify one
628 * DestOverride: Specifies the surface that will become the new front
629 * buffer. If NULL, the current back buffer is used
630 * Flags: some DirectDraw flags, see include/ddraw.h
634 * DDERR_NOTFLIPPABLE if no flip target could be found
635 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
636 * For more details, see IWineD3DSurface::Flip
638 *****************************************************************************/
639 static HRESULT WINAPI
640 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
641 IDirectDrawSurface7 *DestOverride,
644 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
645 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
646 IDirectDrawSurface7 *Override7;
648 TRACE("(%p)->(%p,%lx)\n", This, DestOverride, Flags);
650 /* Flip has to be called from a front buffer
651 * What about overlay surfaces, AFAIK they can flip too?
653 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
654 return DDERR_INVALIDOBJECT; /* Unckecked */
656 /* WineD3D doesn't keep track of attached surface, so find the target */
661 memset(&Caps, 0, sizeof(Caps));
662 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
663 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
666 ERR("Can't find a flip target\n");
667 return DDERR_NOTFLIPPABLE; /* Unchecked */
669 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
671 /* For the GetAttachedSurface */
672 IDirectDrawSurface7_Release(Override7);
675 return IWineD3DSurface_Flip(This->WineD3DSurface,
676 Override->WineD3DSurface,
680 /*****************************************************************************
681 * IDirectDrawSurface7::Blt
683 * Performs a blit on the surface
686 * DestRect: Destination rectangle, can be NULL
687 * SrcSurface: Source surface, can be NULL
688 * SrcRect: Source rectange, can be NULL
690 * DDBltFx: Some extended blt parameters, connected to the flags
694 * See IWineD3DSurface::Blt for more details
696 *****************************************************************************/
697 static HRESULT WINAPI
698 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
700 IDirectDrawSurface7 *SrcSurface,
705 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
706 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
707 TRACE("(%p)->(%p,%p,%p,%lx,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
709 return IWineD3DSurface_Blt(This->WineD3DSurface,
711 Src ? Src->WineD3DSurface : NULL,
717 /*****************************************************************************
718 * IDirectDrawSurface7::AddAttachedSurface
720 * Attaches a surface to another surface. Surface attachments are
721 * incorrectly described in the SDK and the MSDN, and this method
722 * is prone to bugs. The surface that is attached is AddRef-ed.
724 * The attachment list consists of a first surface (first_attached) and
725 * for each surface a pointer to the next attached surface (next_attached).
726 * For the first surface, and a surface that has no attachments
727 * first_attached points to the surface itself. A surface that has
728 * no successors in the chain has next_attached set to NULL.
730 * Newly attached surfaces are attached right after the root surface. The
731 * complex chains are handled separately in a similar chain, with
732 * first_complex and next_complex. If a surface is attached to a complex
733 * surface compound, it's attached to the surface that the app requested,
734 * not the complex root. See GetAttachedSurface for a description
735 * how surfaces are found.
737 * This is how the current implementation works, and it was coded by looking
738 * at the needs of the applications.
740 * So far only Z-Buffer attachments are tested, but there's no code yet
741 * to activate them. Mipmaps could be tricky to activate in WineD3D.
742 * Back buffers should work in 2D mode, but they are not tested.
743 * Rendering to the primary surface and switching between that and
744 * double buffering is not yet implemented in WineD3D, so for 3D it might
745 * have unexpected results.
748 * Attach: Surface to attach to iface
752 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
754 *****************************************************************************/
755 static HRESULT WINAPI
756 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
757 IDirectDrawSurface7 *Attach)
759 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
760 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
761 TRACE("(%p)->(%p)\n", This, Surf);
763 /* Should I make sure to add it to the first complex surface? */
766 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
768 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
769 * But apparently backbuffers and mipmaps can be attached too. */
771 /* Set MIPMAPSUBLEVEL if this seems to be one */
772 if (This->surface_desc.ddsCaps.dwCaps &
773 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
775 Surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
776 /* FIXME: we should probably also add to dwMipMapCount of this
777 * and all parent surfaces (update create_texture if you do) */
780 /* Check if the surface is already attached somewhere */
781 if( (Surf->next_attached != NULL) ||
782 (Surf->first_attached != Surf) )
784 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);
785 return DDERR_CANNOTATTACHSURFACE;
788 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
789 Surf->next_attached = This->next_attached;
790 Surf->first_attached = This->first_attached;
791 This->next_attached = Surf;
794 * "This method increments the reference count of the surface being attached."
796 IDirectDrawSurface7_AddRef(Attach);
800 /*****************************************************************************
801 * IDirectDrawSurface7::DeleteAttachedSurface
803 * Removes a surface from the attachment chain. The surface's refcount
804 * is decreased by one after it has been removed
807 * Flags: Some flags, not used by this implementation
808 * Attach: Surface to detach
812 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
814 *****************************************************************************/
815 static HRESULT WINAPI
816 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
818 IDirectDrawSurface7 *Attach)
820 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
821 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
822 IDirectDrawSurfaceImpl *Prev = This;
823 TRACE("(%p)->(%08lx,%p)\n", This, Flags, Surf);
825 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
826 return DDERR_SURFACENOTATTACHED; /* unchecked */
828 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
829 if (This->surface_desc.ddsCaps.dwCaps &
830 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
832 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
833 /* FIXME: we should probably also subtract from dwMipMapCount of this
834 * and all parent surfaces */
837 /* Find the predecessor of the detached surface */
840 if(Prev->next_attached == Surf) break;
841 Prev = Prev->next_attached;
844 /* There must be a surface, otherwise there's a bug */
845 assert(Prev != NULL);
847 /* Unchain the surface */
848 Prev->next_attached = Surf->next_attached;
849 Surf->next_attached = NULL;
850 Surf->first_attached = Surf;
852 IDirectDrawSurface7_Release(Attach);
856 /*****************************************************************************
857 * IDirectDrawSurface7::AddOverlayDirtyRect
859 * "This method is not currently implemented"
867 *****************************************************************************/
868 static HRESULT WINAPI
869 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
872 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
873 TRACE("(%p)->(%p)\n",This,Rect);
875 /* MSDN says it's not implemented. I could forward it to WineD3D,
876 * then we'd implement it, but I don't think that's a good idea
880 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
882 return DDERR_UNSUPPORTED; /* unchecked */
885 /*****************************************************************************
886 * IDirectDrawSurface7::GetDC
888 * Returns a GDI device context for the surface
891 * hdc: Address of a HDC variable to store the dc to
895 * DDERR_INVALIDPARAMS if hdc is NULL
896 * For details, see IWineD3DSurface::GetDC
898 *****************************************************************************/
899 static HRESULT WINAPI
900 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
903 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
904 TRACE("(%p)->(%p): Relay\n", This, hdc);
907 return DDERR_INVALIDPARAMS;
909 return IWineD3DSurface_GetDC(This->WineD3DSurface,
913 /*****************************************************************************
914 * IDirectDrawSurface7::ReleaseDC
916 * Releases the DC that was constructed with GetDC
919 * hdc: HDC to release
923 * For more details, see IWineD3DSurface::ReleaseDC
925 *****************************************************************************/
926 static HRESULT WINAPI
927 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
930 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
931 TRACE("(%p)->(%p): Relay\n", This, hdc);
933 return IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
936 /*****************************************************************************
937 * IDirectDrawSurface7::GetCaps
939 * Returns the surface's caps
942 * Caps: Address to write the caps to
946 * DDERR_INVALIDPARAMS if Caps is NULL
948 *****************************************************************************/
949 static HRESULT WINAPI
950 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
953 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
954 TRACE("(%p)->(%p)\n",This,Caps);
957 return DDERR_INVALIDPARAMS;
959 *Caps = This->surface_desc.ddsCaps;
963 /*****************************************************************************
964 * IDirectDrawSurface7::SetPriority
966 * Sets a texture priority for managed textures.
969 * Priority: The new priority
973 * For more details, see IWineD3DSurface::SetPriority
975 *****************************************************************************/
976 static HRESULT WINAPI
977 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
979 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
980 TRACE("(%p)->(%ld): Relay!\n",This,Priority);
982 return IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
985 /*****************************************************************************
986 * IDirectDrawSurface7::GetPriority
988 * Returns the surface's priority
991 * Priority: Address of a variable to write the priority to
995 * DDERR_INVALIDPARAMS if Priority == NULL
996 * For more details, see IWineD3DSurface::GetPriority
998 *****************************************************************************/
999 static HRESULT WINAPI
1000 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1003 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1004 TRACE("(%p)->(%p): Relay\n",This,Priority);
1007 return DDERR_INVALIDPARAMS;
1009 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1013 /*****************************************************************************
1014 * IDirectDrawSurface7::SetPrivateData
1016 * Stores some data in the surface that is intended for the application's
1020 * tag: GUID that identifies the data
1021 * Data: Pointer to the private data
1022 * Size: Size of the private data
1027 * For more details, see IWineD3DSurface::SetPrivateData
1029 *****************************************************************************/
1030 static HRESULT WINAPI
1031 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1037 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1038 TRACE("(%p)->(%s,%p,%ld,%lx): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1040 return IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1047 /*****************************************************************************
1048 * IDirectDrawSurface7::GetPrivateData
1050 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1053 * tag: GUID of the data to return
1054 * Data: Address where to write the data to
1055 * Size: Size of the buffer at Data
1059 * DDERR_INVALIDPARAMS if Data is NULL
1060 * For more details, see IWineD3DSurface::GetPrivateData
1062 *****************************************************************************/
1063 static HRESULT WINAPI
1064 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1069 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1070 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1073 return DDERR_INVALIDPARAMS;
1075 return IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1081 /*****************************************************************************
1082 * IDirectDrawSurface7::FreePrivateData
1084 * Frees private data stored in the surface
1087 * tag: Tag of the data to free
1091 * For more details, see IWineD3DSurface::FreePrivateData
1093 *****************************************************************************/
1094 static HRESULT WINAPI
1095 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1098 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1099 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1101 return IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1104 /*****************************************************************************
1105 * IDirectDrawSurface7::PageLock
1107 * Prevents a sysmem surface from being paged out
1110 * Flags: Not used, must be 0(unchecked)
1113 * DD_OK, because it's a stub
1115 *****************************************************************************/
1116 static HRESULT WINAPI
1117 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1120 TRACE("(%p)->(%lx)\n", iface, Flags);
1122 /* This is Windows memory management related - we don't need this */
1126 /*****************************************************************************
1127 * IDirectDrawSurface7::PageUnlock
1129 * Allows a sysmem surface to be paged out
1132 * Flags: Not used, must be 0(unckeched)
1135 * DD_OK, because it's a stub
1137 *****************************************************************************/
1138 static HRESULT WINAPI
1139 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1142 TRACE("(%p)->(%lx)\n", iface, Flags);
1147 /*****************************************************************************
1148 * IDirectDrawSurface7::BltBatch
1150 * An unimplemented function
1158 *****************************************************************************/
1159 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1161 TRACE("(%p)->(%p,%ld,%08lx)\n",iface,Batch,Count,Flags);
1163 /* MSDN: "not currently implemented" */
1164 return DDERR_UNSUPPORTED;
1167 /*****************************************************************************
1168 * IDirectDrawSurface7::EnumAttachedSurfaces
1170 * Enumerates all surfaces attached to this surface
1173 * context: Pointer to pass unmodified to the callback
1174 * cb: Callback function to call for each surface
1178 * DDERR_INVALIDPARAMS if cb is NULL
1180 *****************************************************************************/
1181 static HRESULT WINAPI
1182 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1184 LPDDENUMSURFACESCALLBACK7 cb)
1186 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1187 IDirectDrawSurfaceImpl *surf;
1188 DDSURFACEDESC2 desc;
1190 /* Attached surfaces aren't handled in WineD3D */
1191 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1194 return DDERR_INVALIDPARAMS;
1196 for (surf = This->next_complex; surf != NULL; surf = surf->next_complex)
1198 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1199 desc = surf->surface_desc;
1200 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1201 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1205 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1207 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1208 desc = surf->surface_desc;
1209 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1210 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1214 TRACE(" end of enumeration.\n");
1219 /*****************************************************************************
1220 * IDirectDrawSurface7::EnumOverlayZOrders
1222 * "Enumerates the overlay surfaces on the specified destination"
1225 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1226 * context: context to pass back to the callback
1227 * cb: callback function to call for each enumerated surface
1230 * DD_OK, because it's a stub
1232 *****************************************************************************/
1233 static HRESULT WINAPI
1234 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1237 LPDDENUMSURFACESCALLBACK7 cb)
1239 FIXME("(%p)->(%lx,%p,%p): Stub!\n", iface, Flags, context, cb);
1244 /*****************************************************************************
1245 * IDirectDrawSurface7::GetBltStatus
1247 * Returns the blitting status
1250 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1253 * See IWineD3DSurface::Blt
1255 *****************************************************************************/
1256 static HRESULT WINAPI
1257 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1260 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1261 TRACE("(%p)->(%lx): Relay\n", This, Flags);
1263 return IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1266 /*****************************************************************************
1267 * IDirectDrawSurface7::GetColorKey
1269 * Returns the color key assigned to the surface
1273 * CKey: Address to store the key to
1277 * DDERR_INVALIDPARAMS if CKey is NULL
1279 *****************************************************************************/
1280 static HRESULT WINAPI
1281 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1285 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1286 * isn't there? That's like saying that an int isn't there. (Which MS
1287 * has done in other docs.) */
1289 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1292 return DDERR_INVALIDPARAMS;
1296 case DDCKEY_DESTBLT:
1297 *CKey = This->surface_desc.ddckCKDestBlt;
1300 case DDCKEY_DESTOVERLAY:
1301 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1305 *CKey = This->surface_desc.ddckCKSrcBlt;
1308 case DDCKEY_SRCOVERLAY:
1309 *CKey = This->surface_desc.ddckCKSrcOverlay;
1313 return DDERR_INVALIDPARAMS;
1319 /*****************************************************************************
1320 * IDirectDrawSurface7::GetFlipStatus
1322 * Returns the flipping status of the surface
1325 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1328 * See IWineD3DSurface::GetFlipStatus
1330 *****************************************************************************/
1331 static HRESULT WINAPI
1332 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1335 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1336 TRACE("(%p)->(%lx): Relay\n", This, Flags);
1338 return IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1341 /*****************************************************************************
1342 * IDirectDrawSurface7::GetOverlayPosition
1344 * Returns the display coordinates of a visible and active overlay surface
1351 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1352 *****************************************************************************/
1353 static HRESULT WINAPI
1354 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1357 FIXME("(%p)->(%p,%p): Stub!\n", iface, X, Y);
1359 return DDERR_NOTAOVERLAYSURFACE;
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 FIXME("(%p)->(%ld,%ld): Stub!\n", This, X, Y);
1535 return DDERR_NOTAOVERLAYSURFACE;
1538 /*****************************************************************************
1539 * IDirectDrawSurface7::UpdateOverlay
1541 * Modifies the attributes of an overlay surface.
1544 * SrcRect: The section of the source being used for the overlay
1545 * DstSurface: Address of the surface that is overlaid
1546 * DstRect: Place of the overlay
1547 * Flags: some DDOVER_* flags
1550 * DDERR_UNSUPPORTED, because we don't support overlays
1552 *****************************************************************************/
1553 static HRESULT WINAPI
1554 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1556 IDirectDrawSurface7 *DstSurface,
1561 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1562 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1563 FIXME("(%p)->(%p,%p,%p,%lx,%p): Stub!\n", This, SrcRect, Dst, DstRect, Flags, FX);
1564 return DDERR_UNSUPPORTED;
1567 /*****************************************************************************
1568 * IDirectDrawSurface7::UpdateOverlayDisplay
1570 * The DX7 sdk says that it's not implemented
1575 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1577 *****************************************************************************/
1578 static HRESULT WINAPI
1579 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1582 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1583 TRACE("(%p)->(%lx)\n", This, Flags);
1584 return DDERR_UNSUPPORTED;
1587 /*****************************************************************************
1588 * IDirectDrawSurface7::UpdateOverlayZOrder
1590 * Sets an overlay's Z order
1593 * Flags: DDOVERZ_* flags
1594 * DDSRef: Defines the relative position in the overlay chain
1597 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1599 *****************************************************************************/
1600 static HRESULT WINAPI
1601 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1603 IDirectDrawSurface7 *DDSRef)
1605 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1606 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1607 FIXME("(%p)->(%lx,%p)\n", This, Flags, Ref);
1608 return DDERR_NOTAOVERLAYSURFACE;
1611 /*****************************************************************************
1612 * IDirectDrawSurface7::GetDDInterface
1614 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1615 * surface belongs to
1618 * DD: Address to write the interface pointer to
1622 * DDERR_INVALIDPARAMS if DD is NULL
1624 *****************************************************************************/
1625 static HRESULT WINAPI
1626 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1629 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1631 /* It is not quite correct to use the same lpVtable for the different
1632 * IDirectDrawSurface versions because the GetDDInterface return different interfaces
1634 FIXME("(%p)->(%p)\n",This,DD);
1637 return DDERR_INVALIDPARAMS;
1639 switch(This->version)
1642 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1643 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1647 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1648 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1652 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1653 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1661 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1662 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1664 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1665 volatile IDirectDrawSurfaceImpl* vThis = This;
1667 TRACE("(%p)\n",This);
1668 /* A uniqueness value of 0 is apparently special.
1669 * This needs to be checked. */
1671 DWORD old_uniqueness_value = vThis->uniqueness_value;
1672 DWORD new_uniqueness_value = old_uniqueness_value+1;
1674 if (old_uniqueness_value == 0) break;
1675 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1677 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1678 old_uniqueness_value,
1679 new_uniqueness_value)
1680 == old_uniqueness_value)
1687 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1689 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1691 TRACE("(%p)->(%p)\n",This,pValue);
1692 *pValue = This->uniqueness_value;
1696 /*****************************************************************************
1697 * IDirectDrawSurface7::SetLOD
1699 * Sets the level of detail of a texture
1702 * MaxLOD: LOD to set
1706 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1708 *****************************************************************************/
1709 static HRESULT WINAPI
1710 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1713 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1714 TRACE("(%p)->(%ld)\n", This, MaxLOD);
1716 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1717 return DDERR_INVALIDOBJECT;
1719 if(!This->wineD3DTexture)
1721 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1722 return DDERR_INVALIDOBJECT;
1725 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1729 /*****************************************************************************
1730 * IDirectDrawSurface7::GetLOD
1732 * Returns the level of detail of a Direct3D texture
1735 * MaxLOD: Address to write the LOD to
1739 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1740 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1742 *****************************************************************************/
1743 static HRESULT WINAPI
1744 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1747 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1748 TRACE("(%p)->(%p)\n", This, MaxLOD);
1751 return DDERR_INVALIDPARAMS;
1753 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1754 return DDERR_INVALIDOBJECT;
1756 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1760 /*****************************************************************************
1761 * IDirectDrawSurface7::BltFast
1763 * Performs a fast Blit.
1766 * dstx: The x coordinate to blit to on the destination
1767 * dsty: The y coordinate to blit to on the destination
1768 * Source: The source surface
1769 * rsrc: The source rectangle
1770 * trans: Type of transfer. Some DDBLTFAST_* flags
1774 * For more details, see IWineD3DSurface::BltFast
1776 *****************************************************************************/
1777 static HRESULT WINAPI
1778 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1781 IDirectDrawSurface7 *Source,
1785 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1786 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1787 TRACE("(%p)->(%ld,%ld,%p,%p,%ld): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1789 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1791 src ? src->WineD3DSurface : NULL,
1796 /*****************************************************************************
1797 * IDirectDrawSurface7::GetClipper
1799 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1803 * Clipper: Address to store the interface pointer at
1807 * DDERR_INVALIDPARAMS if Clipper is NULL
1808 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1810 *****************************************************************************/
1811 static HRESULT WINAPI
1812 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1813 IDirectDrawClipper **Clipper)
1815 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1816 TRACE("(%p)->(%p)\n", This, Clipper);
1819 return DDERR_INVALIDPARAMS;
1821 if(This->clipper == NULL)
1822 return DDERR_NOCLIPPERATTACHED;
1824 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1825 IDirectDrawClipper_AddRef(*Clipper);
1829 /*****************************************************************************
1830 * IDirectDrawSurface7::SetClipper
1832 * Sets a clipper for the surface
1835 * Clipper: IDirectDrawClipper interface of the clipper to set
1840 *****************************************************************************/
1841 static HRESULT WINAPI
1842 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1843 IDirectDrawClipper *Clipper)
1845 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1847 TRACE("(%p)->(%p)\n",This,Clipper);
1848 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1851 if (This->clipper != NULL)
1852 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1854 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1855 if (Clipper != NULL)
1856 IDirectDrawClipper_AddRef(Clipper);
1861 /*****************************************************************************
1862 * IDirectDrawSurface7::SetSurfaceDesc
1864 * Sets the surface description. It can override the pixel format, the surface
1866 * It's not really tested.
1869 * DDSD: Pointer to the new surface description to set
1874 * DDERR_INVALIDPARAMS if DDSD is NULL
1876 *****************************************************************************/
1877 static HRESULT WINAPI
1878 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1879 DDSURFACEDESC2 *DDSD,
1882 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1883 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1885 TRACE("(%p)->(%p,%lx)\n", This, DDSD, Flags);
1888 return DDERR_INVALIDPARAMS;
1890 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1892 ERR("Setting the surface memory isn't supported yet\n");
1893 return DDERR_INVALIDPARAMS;
1896 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1898 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1900 if(newFormat == WINED3DFMT_UNKNOWN)
1902 ERR("Requested to set an unknown pixelformat\n");
1903 return DDERR_INVALIDPARAMS;
1905 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1907 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1909 if(hr != DD_OK) return hr;
1912 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1914 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1916 &DDSD->u3.ddckCKDestOverlay);
1918 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1920 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1922 &DDSD->ddckCKDestBlt);
1924 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1926 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1928 &DDSD->ddckCKSrcOverlay);
1930 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1932 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1934 &DDSD->ddckCKSrcBlt);
1936 if (DDSD->dwFlags & DDSD_LPSURFACE)
1938 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
1939 if(hr != WINED3D_OK)
1941 /* No need for a trace here, wined3d does that for us */
1946 This->surface_desc = *DDSD;
1951 /*****************************************************************************
1952 * IDirectDrawSurface7::GetPalette
1954 * Returns the IDirectDrawPalette interface of the palette currently assigned
1958 * Pal: Address to write the interface pointer to
1962 * DDERR_INVALIDPARAMS if Pal is NULL
1964 *****************************************************************************/
1965 static HRESULT WINAPI
1966 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1967 IDirectDrawPalette **Pal)
1969 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1970 IWineD3DPalette *wPal;
1972 TRACE("(%p)->(%p): Relay\n", This, Pal);
1975 return DDERR_INVALIDPARAMS;
1977 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1978 if(hr != DD_OK) return hr;
1982 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
1992 /*****************************************************************************
1993 * IDirectDrawSurface7::SetColorKey
1995 * Sets the color keying options for the surface. Observations showed that
1996 * in case of complex surfaces the color key has to be assigned to all
2001 * CKey: The new color key
2005 * See IWineD3DSurface::SetColorKey for details
2007 *****************************************************************************/
2008 static HRESULT WINAPI
2009 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2013 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2014 IDirectDrawSurfaceImpl *surf;
2016 TRACE("(%p)->(%lx,%p)\n", This, Flags, CKey);
2018 for(surf = This->first_complex; surf; surf = surf->next_complex)
2020 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
2025 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08lx\n",
2026 surf->WineD3DSurface, hr);
2033 /*****************************************************************************
2034 * IDirectDrawSurface7::SetPalette
2036 * Assigns a DirectDrawPalette object to the surface
2039 * Pal: Interface to the palette to set
2044 *****************************************************************************/
2045 static HRESULT WINAPI
2046 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2047 IDirectDrawPalette *Pal)
2049 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2050 IDirectDrawPalette *oldPal;
2051 IDirectDrawSurfaceImpl *surf;
2052 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2054 TRACE("(%p)->(%p)\n", This, Pal);
2056 /* Find the old palette */
2057 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2058 if(hr != DD_OK) return hr;
2059 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2061 /* Set the new Palette */
2062 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2063 PalImpl ? PalImpl->wineD3DPalette : NULL);
2064 /* AddRef the Palette */
2065 if(Pal) IDirectDrawPalette_AddRef(Pal);
2067 /* Release the old palette */
2068 if(oldPal) IDirectDrawPalette_Release(oldPal);
2070 /* If this is a front buffer, also update the back buffers */
2071 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2073 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2075 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2083 /*****************************************************************************
2085 *****************************************************************************/
2087 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2090 IDirectDrawSurfaceImpl_QueryInterface,
2091 IDirectDrawSurfaceImpl_AddRef,
2092 IDirectDrawSurfaceImpl_Release,
2093 /*** IDirectDrawSurface ***/
2094 IDirectDrawSurfaceImpl_AddAttachedSurface,
2095 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2096 IDirectDrawSurfaceImpl_Blt,
2097 IDirectDrawSurfaceImpl_BltBatch,
2098 IDirectDrawSurfaceImpl_BltFast,
2099 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2100 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2101 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2102 IDirectDrawSurfaceImpl_Flip,
2103 IDirectDrawSurfaceImpl_GetAttachedSurface,
2104 IDirectDrawSurfaceImpl_GetBltStatus,
2105 IDirectDrawSurfaceImpl_GetCaps,
2106 IDirectDrawSurfaceImpl_GetClipper,
2107 IDirectDrawSurfaceImpl_GetColorKey,
2108 IDirectDrawSurfaceImpl_GetDC,
2109 IDirectDrawSurfaceImpl_GetFlipStatus,
2110 IDirectDrawSurfaceImpl_GetOverlayPosition,
2111 IDirectDrawSurfaceImpl_GetPalette,
2112 IDirectDrawSurfaceImpl_GetPixelFormat,
2113 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2114 IDirectDrawSurfaceImpl_Initialize,
2115 IDirectDrawSurfaceImpl_IsLost,
2116 IDirectDrawSurfaceImpl_Lock,
2117 IDirectDrawSurfaceImpl_ReleaseDC,
2118 IDirectDrawSurfaceImpl_Restore,
2119 IDirectDrawSurfaceImpl_SetClipper,
2120 IDirectDrawSurfaceImpl_SetColorKey,
2121 IDirectDrawSurfaceImpl_SetOverlayPosition,
2122 IDirectDrawSurfaceImpl_SetPalette,
2123 IDirectDrawSurfaceImpl_Unlock,
2124 IDirectDrawSurfaceImpl_UpdateOverlay,
2125 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2126 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2127 /*** IDirectDrawSurface2 ***/
2128 IDirectDrawSurfaceImpl_GetDDInterface,
2129 IDirectDrawSurfaceImpl_PageLock,
2130 IDirectDrawSurfaceImpl_PageUnlock,
2131 /*** IDirectDrawSurface3 ***/
2132 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2133 /*** IDirectDrawSurface4 ***/
2134 IDirectDrawSurfaceImpl_SetPrivateData,
2135 IDirectDrawSurfaceImpl_GetPrivateData,
2136 IDirectDrawSurfaceImpl_FreePrivateData,
2137 IDirectDrawSurfaceImpl_GetUniquenessValue,
2138 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2139 /*** IDirectDrawSurface7 ***/
2140 IDirectDrawSurfaceImpl_SetPriority,
2141 IDirectDrawSurfaceImpl_GetPriority,
2142 IDirectDrawSurfaceImpl_SetLOD,
2143 IDirectDrawSurfaceImpl_GetLOD