1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
8 * This file contains the (internal) driver registration functions,
9 * driver enumeration APIs and DirectDraw creation functions.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/port.h"
35 #define NONAMELESSUNION
42 #include "wine/exception.h"
48 #include "ddraw_private.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
53 /*****************************************************************************
54 * IUnknown parts follow
55 *****************************************************************************/
57 /*****************************************************************************
58 * IDirectDrawSurface7::QueryInterface
60 * A normal QueryInterface implementation. For QueryInterface rules
61 * see ddraw.c, IDirectDraw7::QueryInterface. This method
62 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
63 * in all versions, the IDirectDrawGammaControl interface and it can
64 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
67 * riid: The interface id queried for
68 * obj: Address to write the pointer to
72 * E_NOINTERFACE if the requested interface wasn't found
74 *****************************************************************************/
76 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
80 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
82 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
86 return DDERR_INVALIDPARAMS;
88 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
89 if (IsEqualGUID(riid, &IID_IUnknown)
90 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
91 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
93 IUnknown_AddRef(iface);
94 *obj = ICOM_INTERFACE(This, IDirectDrawSurface7);
95 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
98 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
99 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
100 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
102 IUnknown_AddRef(iface);
103 *obj = ICOM_INTERFACE(This, IDirectDrawSurface3);
104 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
107 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
109 IUnknown_AddRef(iface);
110 *obj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
111 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
114 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
115 IsEqualGUID(riid, &IID_IDirect3DHALDevice) )
117 IDirect3DDevice7 *d3d;
119 /* Call into IDirect3D7 for creation */
120 IDirect3D7_CreateDevice(ICOM_INTERFACE(This->ddraw, IDirect3D7),
122 ICOM_INTERFACE(This, IDirectDrawSurface7),
125 *obj = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice, d3d);
126 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
130 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
131 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
133 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
135 *obj = ICOM_INTERFACE(This, IDirect3DTexture);
136 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
140 *obj = ICOM_INTERFACE(This, IDirect3DTexture2);
141 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
143 IUnknown_AddRef( (IUnknown *) *obj);
147 ERR("No interface\n");
148 return E_NOINTERFACE;
151 /*****************************************************************************
152 * IDirectDrawSurface7::AddRef
154 * A normal addref implementation
159 *****************************************************************************/
161 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
163 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
164 ULONG refCount = InterlockedIncrement(&This->ref);
166 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
170 /*****************************************************************************
171 * IDirectDrawSurfaceImpl_Destroy
173 * A helper function for IDirectDrawSurface7::Release
175 * Frees the surface, regardless of its refcount.
176 * See IDirectDrawSurface7::Release for more information
179 * This: Surface to free
181 *****************************************************************************/
182 static void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
184 TRACE("(%p)\n", This);
186 /* Check the refcount and give a warning */
189 /* This can happen when a complex surface is destroyed,
190 * because the 2nd surface was addref()ed when the app
191 * called GetAttachedSurface
193 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
196 /* Check for attached surfaces and detach them */
197 if(This->first_attached != This)
199 /* Well, this shouldn't happen: The surface being attached is addref()ed
200 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
201 * is called, because the refcount is held. It looks like the app released()
202 * it often enough to force this
204 IDirectDrawSurface7 *root = ICOM_INTERFACE(This->first_attached, IDirectDrawSurface7);
205 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This, IDirectDrawSurface7);
207 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
209 /* The refcount will drop to -1 here */
210 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
212 ERR("(%p) DeleteAttachedSurface failed!\n", This);
216 while(This->next_attached != NULL)
218 IDirectDrawSurface7 *root = ICOM_INTERFACE(This, IDirectDrawSurface7);
219 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This->next_attached, IDirectDrawSurface7);
221 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
223 ERR("(%p) DeleteAttachedSurface failed!\n", This);
228 /* Now destroy the surface. Wait: It could have been released if we are a texture */
229 if(This->WineD3DSurface)
230 IWineD3DSurface_Release(This->WineD3DSurface);
232 /* Having a texture handle set implies that the device still exists */
235 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
236 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
239 /* Reduce the ddraw surface count */
240 InterlockedDecrement(&This->ddraw->surfaces);
241 list_remove(&This->surface_list_entry);
243 HeapFree(GetProcessHeap(), 0, This);
246 /*****************************************************************************
247 * IDirectDrawSurface7::Release
249 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
250 * surface is destroyed.
252 * Destroying the surface is a bit tricky. For the connection between
253 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
254 * It has a nice graph explaining the connection.
256 * What happens here is basically this:
257 * When a surface is destroyed, its WineD3DSurface is released,
258 * and the refcount of the DirectDraw interface is reduced by 1. If it has
259 * complex surfaces attached to it, then these surfaces are destroyed too,
260 * regardless of their refcount. If any surface being destroyed has another
261 * surface attached to it (with a "soft" attachment, not complex), then
262 * this surface is detached with DeleteAttachedSurface.
264 * When the surface is a texture, the WineD3DTexture is released.
265 * If the surface is the Direct3D render target, then the D3D
266 * capabilities of the WineD3DDevice are uninitialized, which causes the
267 * swapchain to be released.
272 *****************************************************************************/
274 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
276 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
278 TRACE("(%p) : Releasing from %d\n", This, This->ref);
279 ref = InterlockedDecrement(&This->ref);
284 IDirectDrawSurfaceImpl *surf;
285 IDirectDrawImpl *ddraw;
286 IUnknown *ifaceToRelease = This->ifaceToRelease;
288 /* Complex attached surfaces are destroyed implicitely when the root is released */
289 if(This->first_complex != This)
291 WARN("(%p) Attempt to destroy a surface that is attached to a complex root %p\n", This, This->first_complex);
296 /* If it's a texture, destroy the WineD3DTexture.
297 * WineD3D will destroy the IParent interfaces
298 * of the sublevels, which destroys the WineD3DSurfaces.
299 * Set the surfaces to NULL to avoid destroying them again later
301 if(This->wineD3DTexture)
303 IWineD3DTexture_Release(This->wineD3DTexture);
305 /* If it's the RenderTarget, destroy the d3ddevice */
306 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
308 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
310 /* Unset any index buffer, just to be sure */
311 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, 0);
313 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
316 ERR("(%p) Failed to uninit 3D\n", This);
320 /* Free the d3d window if one was created */
321 if(ddraw->d3d_window != 0)
323 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
324 DestroyWindow(ddraw->d3d_window);
325 ddraw->d3d_window = 0;
327 /* Unset the pointers */
330 ddraw->d3d_initialized = FALSE;
331 ddraw->d3d_target = NULL;
333 /* Write a trace because D3D unloading was the reason for many
334 * crashes during development.
336 TRACE("(%p) D3D unloaded\n", This);
338 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
342 /* It's a render target, but no swapchain was created.
343 * The IParent interfaces have to be released manually.
344 * The same applies for textures without an
345 * IWineD3DTexture object attached
352 IWineD3DSurface_GetParent(surf->WineD3DSurface,
353 (IUnknown **) &Parent);
354 IParent_Release(Parent); /* For the getParent */
355 IParent_Release(Parent); /* To release it */
356 surf = surf->next_complex;
360 /* The refcount test shows that the palette is detached when the surface is destroyed */
361 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
364 /* Loop through all complex attached surfaces,
367 while( (surf = This->next_complex) )
369 This->next_complex = surf->next_complex; /* Unchain it from the complex listing */
370 IDirectDrawSurfaceImpl_Destroy(surf); /* Destroy it */
373 /* Destroy the surface.
375 IDirectDrawSurfaceImpl_Destroy(This);
377 /* Reduce the ddraw refcount */
378 IUnknown_Release(ifaceToRelease);
384 /*****************************************************************************
385 * IDirectDrawSurface7::GetAttachedSurface
387 * Returns an attached surface with the requested caps. Surface attachment
388 * and complex surfaces are not clearly described by the MSDN or sdk,
389 * so this method is tricky and likely to contain problems.
390 * This implementation searches the complex chain first, then the
391 * attachment chain, and then it checks if the caps match to itself.
393 * The chains are searched from This down to the last surface in the chain,
394 * not from the first element in the chain. The first surface found is
395 * returned. The MSDN says that this method fails if more than one surface
396 * matches the caps, but apparently this is incorrect.
398 * The found surface is AddRef-ed before it is returned.
401 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
402 * Surface: Address to store the found surface
406 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
407 * DDERR_NOTFOUND if no surface was found
409 *****************************************************************************/
410 static HRESULT WINAPI
411 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
413 IDirectDrawSurface7 **Surface)
415 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
416 IDirectDrawSurfaceImpl *surf;
419 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
423 if(This->version < 7)
425 /* Earlier dx apps put garbage into these members, clear them */
426 our_caps.dwCaps2 = 0;
427 our_caps.dwCaps3 = 0;
428 our_caps.dwCaps4 = 0;
431 TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.dwCaps4); /* FIXME: Better debugging */
433 /* First, look at the complex chain */
436 while( (surf = surf->next_complex) )
440 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
441 surf->surface_desc.ddsCaps.dwCaps,
442 surf->surface_desc.ddsCaps.dwCaps2,
443 surf->surface_desc.ddsCaps.dwCaps3,
444 surf->surface_desc.ddsCaps.dwCaps4);
447 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
448 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
450 /* MSDN: "This method fails if more than one surface is attached
451 * that matches the capabilities requested."
453 * The mipmap demo of the DirectX7 sdk shows what to do here:
454 * apparently apps expect the first found surface to be returned.
457 TRACE("(%p): Returning surface %p\n", This, surf);
458 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
459 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
460 IDirectDrawSurface7_AddRef(*Surface);
465 /* Next, look at the attachment chain */
468 while( (surf = surf->next_attached) )
472 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
473 surf->surface_desc.ddsCaps.dwCaps,
474 surf->surface_desc.ddsCaps.dwCaps2,
475 surf->surface_desc.ddsCaps.dwCaps3,
476 surf->surface_desc.ddsCaps.dwCaps4);
479 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
480 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
482 /* MSDN: "This method fails if more than one surface is attached
483 * that matches the capabilities requested."
485 * The mipmap demo of the DirectX7 sdk shows what to do here:
486 * apparently apps expect the first found surface to be returned.
489 TRACE("(%p): Returning surface %p\n", This, surf);
490 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
491 IDirectDrawSurface7_AddRef(*Surface);
498 if (((This->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
499 ((This->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2) &&
500 This == This->first_complex)
503 TRACE("(%p): Returning surface %p\n", This, This);
504 *Surface = ICOM_INTERFACE(This, IDirectDrawSurface7);
505 IDirectDrawSurface7_AddRef(*Surface);
510 /* What to do here? Continue with the surface root?? */
512 TRACE("(%p) Didn't find a valid surface\n", This);
513 return DDERR_NOTFOUND;
516 /*****************************************************************************
517 * IDirectDrawSurface7::Lock
519 * Locks the surface and returns a pointer to the surface's memory
522 * Rect: Rectangle to lock. If NULL, the whole surface is locked
523 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
524 * Flags: Locking flags, e.g Read only or write only
525 * h: An event handle that's not used and must be NULL
529 * DDERR_INVALIDPARAMS if DDSD is NULL
530 * For more details, see IWineD3DSurface::LockRect
532 *****************************************************************************/
533 static HRESULT WINAPI
534 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
536 DDSURFACEDESC2 *DDSD,
540 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
541 WINED3DLOCKED_RECT LockedRect;
543 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
546 return DDERR_INVALIDPARAMS;
548 /* Should I check for the handle to be NULL?
550 * The DDLOCK flags and the D3DLOCK flags are equal
551 * for the supported values. The others are ignored by WineD3D
554 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
555 * that means it doesn't have dwSize set. Init it to some sane
558 if(DDSD->dwSize <= sizeof(DDSURFACEDESC))
560 DDSD->dwSize = sizeof(DDSURFACEDESC);
564 DDSD->dwSize = sizeof(DDSURFACEDESC2);
567 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
568 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
572 if(hr != D3D_OK) return hr;
574 /* Override the memory area and the pitch */
575 DDSD->dwFlags |= DDSD_LPSURFACE;
576 DDSD->lpSurface = LockedRect.pBits;
577 DDSD->dwFlags |= DDSD_PITCH;
578 DDSD->u1.lPitch = LockedRect.Pitch;
580 TRACE("locked surface returning description :\n");
581 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
586 /*****************************************************************************
587 * IDirectDrawSurface7::Unlock
589 * Unlocks an locked surface
592 * Rect: Not used by this implementation
596 * For more details, see IWineD3DSurface::UnlockRect
598 *****************************************************************************/
599 static HRESULT WINAPI
600 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
603 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
604 TRACE("(%p)->(%p)\n", This, pRect);
606 return IWineD3DSurface_UnlockRect(This->WineD3DSurface);
609 /*****************************************************************************
610 * IDirectDrawSurface7::Flip
612 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
613 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
614 * the flip target is passed to WineD3D, even if the app didn't specify one
617 * DestOverride: Specifies the surface that will become the new front
618 * buffer. If NULL, the current back buffer is used
619 * Flags: some DirectDraw flags, see include/ddraw.h
623 * DDERR_NOTFLIPPABLE if no flip target could be found
624 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
625 * For more details, see IWineD3DSurface::Flip
627 *****************************************************************************/
628 static HRESULT WINAPI
629 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
630 IDirectDrawSurface7 *DestOverride,
633 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
634 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
635 IDirectDrawSurface7 *Override7;
637 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
639 /* Flip has to be called from a front buffer
640 * What about overlay surfaces, AFAIK they can flip too?
642 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
643 return DDERR_INVALIDOBJECT; /* Unckecked */
645 /* WineD3D doesn't keep track of attached surface, so find the target */
650 memset(&Caps, 0, sizeof(Caps));
651 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
652 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
655 ERR("Can't find a flip target\n");
656 return DDERR_NOTFLIPPABLE; /* Unchecked */
658 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
660 /* For the GetAttachedSurface */
661 IDirectDrawSurface7_Release(Override7);
664 return IWineD3DSurface_Flip(This->WineD3DSurface,
665 Override->WineD3DSurface,
669 /*****************************************************************************
670 * IDirectDrawSurface7::Blt
672 * Performs a blit on the surface
675 * DestRect: Destination rectangle, can be NULL
676 * SrcSurface: Source surface, can be NULL
677 * SrcRect: Source rectange, can be NULL
679 * DDBltFx: Some extended blt parameters, connected to the flags
683 * See IWineD3DSurface::Blt for more details
685 *****************************************************************************/
686 static HRESULT WINAPI
687 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
689 IDirectDrawSurface7 *SrcSurface,
694 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
695 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
696 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
698 return IWineD3DSurface_Blt(This->WineD3DSurface,
700 Src ? Src->WineD3DSurface : NULL,
706 /*****************************************************************************
707 * IDirectDrawSurface7::AddAttachedSurface
709 * Attaches a surface to another surface. Surface attachments are
710 * incorrectly described in the SDK and the MSDN, and this method
711 * is prone to bugs. The surface that is attached is AddRef-ed.
713 * The attachment list consists of a first surface (first_attached) and
714 * for each surface a pointer to the next attached surface (next_attached).
715 * For the first surface, and a surface that has no attachments
716 * first_attached points to the surface itself. A surface that has
717 * no successors in the chain has next_attached set to NULL.
719 * Newly attached surfaces are attached right after the root surface. The
720 * complex chains are handled separately in a similar chain, with
721 * first_complex and next_complex. If a surface is attached to a complex
722 * surface compound, it's attached to the surface that the app requested,
723 * not the complex root. See GetAttachedSurface for a description
724 * how surfaces are found.
726 * This is how the current implementation works, and it was coded by looking
727 * at the needs of the applications.
729 * So far only Z-Buffer attachments are tested, but there's no code yet
730 * to activate them. Mipmaps could be tricky to activate in WineD3D.
731 * Back buffers should work in 2D mode, but they are not tested.
732 * Rendering to the primary surface and switching between that and
733 * double buffering is not yet implemented in WineD3D, so for 3D it might
734 * have unexpected results.
737 * Attach: Surface to attach to iface
741 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
743 *****************************************************************************/
744 static HRESULT WINAPI
745 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
746 IDirectDrawSurface7 *Attach)
748 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
749 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
750 TRACE("(%p)->(%p)\n", This, Surf);
752 /* Should I make sure to add it to the first complex surface? */
755 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
757 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
758 * But apparently backbuffers and mipmaps can be attached too. */
760 /* Set MIPMAPSUBLEVEL if this seems to be one */
761 if (This->surface_desc.ddsCaps.dwCaps &
762 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
764 Surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
765 /* FIXME: we should probably also add to dwMipMapCount of this
766 * and all parent surfaces (update create_texture if you do) */
769 /* Check if the surface is already attached somewhere */
770 if( (Surf->next_attached != NULL) ||
771 (Surf->first_attached != Surf) )
773 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);
774 return DDERR_CANNOTATTACHSURFACE;
777 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
778 Surf->next_attached = This->next_attached;
779 Surf->first_attached = This->first_attached;
780 This->next_attached = Surf;
783 * "This method increments the reference count of the surface being attached."
785 IDirectDrawSurface7_AddRef(Attach);
789 /*****************************************************************************
790 * IDirectDrawSurface7::DeleteAttachedSurface
792 * Removes a surface from the attachment chain. The surface's refcount
793 * is decreased by one after it has been removed
796 * Flags: Some flags, not used by this implementation
797 * Attach: Surface to detach
801 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
803 *****************************************************************************/
804 static HRESULT WINAPI
805 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
807 IDirectDrawSurface7 *Attach)
809 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
810 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
811 IDirectDrawSurfaceImpl *Prev = This;
812 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
814 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
815 return DDERR_SURFACENOTATTACHED; /* unchecked */
817 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
818 if (This->surface_desc.ddsCaps.dwCaps &
819 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
821 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
822 /* FIXME: we should probably also subtract from dwMipMapCount of this
823 * and all parent surfaces */
826 /* Find the predecessor of the detached surface */
829 if(Prev->next_attached == Surf) break;
830 Prev = Prev->next_attached;
833 /* There must be a surface, otherwise there's a bug */
834 assert(Prev != NULL);
836 /* Unchain the surface */
837 Prev->next_attached = Surf->next_attached;
838 Surf->next_attached = NULL;
839 Surf->first_attached = Surf;
841 IDirectDrawSurface7_Release(Attach);
845 /*****************************************************************************
846 * IDirectDrawSurface7::AddOverlayDirtyRect
848 * "This method is not currently implemented"
856 *****************************************************************************/
857 static HRESULT WINAPI
858 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
861 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
862 TRACE("(%p)->(%p)\n",This,Rect);
864 /* MSDN says it's not implemented. I could forward it to WineD3D,
865 * then we'd implement it, but I don't think that's a good idea
869 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
871 return DDERR_UNSUPPORTED; /* unchecked */
874 /*****************************************************************************
875 * IDirectDrawSurface7::GetDC
877 * Returns a GDI device context for the surface
880 * hdc: Address of a HDC variable to store the dc to
884 * DDERR_INVALIDPARAMS if hdc is NULL
885 * For details, see IWineD3DSurface::GetDC
887 *****************************************************************************/
888 static HRESULT WINAPI
889 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
892 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
893 TRACE("(%p)->(%p): Relay\n", This, hdc);
896 return DDERR_INVALIDPARAMS;
898 return IWineD3DSurface_GetDC(This->WineD3DSurface,
902 /*****************************************************************************
903 * IDirectDrawSurface7::ReleaseDC
905 * Releases the DC that was constructed with GetDC
908 * hdc: HDC to release
912 * For more details, see IWineD3DSurface::ReleaseDC
914 *****************************************************************************/
915 static HRESULT WINAPI
916 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
919 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
920 TRACE("(%p)->(%p): Relay\n", This, hdc);
922 return IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
925 /*****************************************************************************
926 * IDirectDrawSurface7::GetCaps
928 * Returns the surface's caps
931 * Caps: Address to write the caps to
935 * DDERR_INVALIDPARAMS if Caps is NULL
937 *****************************************************************************/
938 static HRESULT WINAPI
939 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
942 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
943 TRACE("(%p)->(%p)\n",This,Caps);
946 return DDERR_INVALIDPARAMS;
948 *Caps = This->surface_desc.ddsCaps;
952 /*****************************************************************************
953 * IDirectDrawSurface7::SetPriority
955 * Sets a texture priority for managed textures.
958 * Priority: The new priority
962 * For more details, see IWineD3DSurface::SetPriority
964 *****************************************************************************/
965 static HRESULT WINAPI
966 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
968 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
969 TRACE("(%p)->(%d): Relay!\n",This,Priority);
971 return IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
974 /*****************************************************************************
975 * IDirectDrawSurface7::GetPriority
977 * Returns the surface's priority
980 * Priority: Address of a variable to write the priority to
984 * DDERR_INVALIDPARAMS if Priority == NULL
985 * For more details, see IWineD3DSurface::GetPriority
987 *****************************************************************************/
988 static HRESULT WINAPI
989 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
992 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
993 TRACE("(%p)->(%p): Relay\n",This,Priority);
996 return DDERR_INVALIDPARAMS;
998 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1002 /*****************************************************************************
1003 * IDirectDrawSurface7::SetPrivateData
1005 * Stores some data in the surface that is intended for the application's
1009 * tag: GUID that identifies the data
1010 * Data: Pointer to the private data
1011 * Size: Size of the private data
1016 * For more details, see IWineD3DSurface::SetPrivateData
1018 *****************************************************************************/
1019 static HRESULT WINAPI
1020 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1026 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1027 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1029 return IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1036 /*****************************************************************************
1037 * IDirectDrawSurface7::GetPrivateData
1039 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1042 * tag: GUID of the data to return
1043 * Data: Address where to write the data to
1044 * Size: Size of the buffer at Data
1048 * DDERR_INVALIDPARAMS if Data is NULL
1049 * For more details, see IWineD3DSurface::GetPrivateData
1051 *****************************************************************************/
1052 static HRESULT WINAPI
1053 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1058 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1059 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1062 return DDERR_INVALIDPARAMS;
1064 return IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1070 /*****************************************************************************
1071 * IDirectDrawSurface7::FreePrivateData
1073 * Frees private data stored in the surface
1076 * tag: Tag of the data to free
1080 * For more details, see IWineD3DSurface::FreePrivateData
1082 *****************************************************************************/
1083 static HRESULT WINAPI
1084 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1087 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1088 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1090 return IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1093 /*****************************************************************************
1094 * IDirectDrawSurface7::PageLock
1096 * Prevents a sysmem surface from being paged out
1099 * Flags: Not used, must be 0(unchecked)
1102 * DD_OK, because it's a stub
1104 *****************************************************************************/
1105 static HRESULT WINAPI
1106 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1109 TRACE("(%p)->(%x)\n", iface, Flags);
1111 /* This is Windows memory management related - we don't need this */
1115 /*****************************************************************************
1116 * IDirectDrawSurface7::PageUnlock
1118 * Allows a sysmem surface to be paged out
1121 * Flags: Not used, must be 0(unckeched)
1124 * DD_OK, because it's a stub
1126 *****************************************************************************/
1127 static HRESULT WINAPI
1128 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1131 TRACE("(%p)->(%x)\n", iface, Flags);
1136 /*****************************************************************************
1137 * IDirectDrawSurface7::BltBatch
1139 * An unimplemented function
1147 *****************************************************************************/
1148 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1150 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1152 /* MSDN: "not currently implemented" */
1153 return DDERR_UNSUPPORTED;
1156 /*****************************************************************************
1157 * IDirectDrawSurface7::EnumAttachedSurfaces
1159 * Enumerates all surfaces attached to this surface
1162 * context: Pointer to pass unmodified to the callback
1163 * cb: Callback function to call for each surface
1167 * DDERR_INVALIDPARAMS if cb is NULL
1169 *****************************************************************************/
1170 static HRESULT WINAPI
1171 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1173 LPDDENUMSURFACESCALLBACK7 cb)
1175 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1176 IDirectDrawSurfaceImpl *surf;
1177 DDSURFACEDESC2 desc;
1179 /* Attached surfaces aren't handled in WineD3D */
1180 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1183 return DDERR_INVALIDPARAMS;
1185 for (surf = This->next_complex; surf != NULL; surf = surf->next_complex)
1187 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1188 desc = surf->surface_desc;
1189 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1190 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1194 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1196 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1197 desc = surf->surface_desc;
1198 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1199 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1203 TRACE(" end of enumeration.\n");
1208 /*****************************************************************************
1209 * IDirectDrawSurface7::EnumOverlayZOrders
1211 * "Enumerates the overlay surfaces on the specified destination"
1214 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1215 * context: context to pass back to the callback
1216 * cb: callback function to call for each enumerated surface
1219 * DD_OK, because it's a stub
1221 *****************************************************************************/
1222 static HRESULT WINAPI
1223 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1226 LPDDENUMSURFACESCALLBACK7 cb)
1228 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1233 /*****************************************************************************
1234 * IDirectDrawSurface7::GetBltStatus
1236 * Returns the blitting status
1239 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1242 * See IWineD3DSurface::Blt
1244 *****************************************************************************/
1245 static HRESULT WINAPI
1246 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1249 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1250 TRACE("(%p)->(%x): Relay\n", This, Flags);
1252 return IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1255 /*****************************************************************************
1256 * IDirectDrawSurface7::GetColorKey
1258 * Returns the color key assigned to the surface
1262 * CKey: Address to store the key to
1266 * DDERR_INVALIDPARAMS if CKey is NULL
1268 *****************************************************************************/
1269 static HRESULT WINAPI
1270 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1274 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1275 * isn't there? That's like saying that an int isn't there. (Which MS
1276 * has done in other docs.) */
1278 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1281 return DDERR_INVALIDPARAMS;
1285 case DDCKEY_DESTBLT:
1286 *CKey = This->surface_desc.ddckCKDestBlt;
1289 case DDCKEY_DESTOVERLAY:
1290 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1294 *CKey = This->surface_desc.ddckCKSrcBlt;
1297 case DDCKEY_SRCOVERLAY:
1298 *CKey = This->surface_desc.ddckCKSrcOverlay;
1302 return DDERR_INVALIDPARAMS;
1308 /*****************************************************************************
1309 * IDirectDrawSurface7::GetFlipStatus
1311 * Returns the flipping status of the surface
1314 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1317 * See IWineD3DSurface::GetFlipStatus
1319 *****************************************************************************/
1320 static HRESULT WINAPI
1321 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1324 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1325 TRACE("(%p)->(%x): Relay\n", This, Flags);
1327 return IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1330 /*****************************************************************************
1331 * IDirectDrawSurface7::GetOverlayPosition
1333 * Returns the display coordinates of a visible and active overlay surface
1340 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1341 *****************************************************************************/
1342 static HRESULT WINAPI
1343 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1346 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1347 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1349 return IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1354 /*****************************************************************************
1355 * IDirectDrawSurface7::GetPixelFormat
1357 * Returns the pixel format of the Surface
1360 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1361 * format should be written
1365 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1367 *****************************************************************************/
1368 static HRESULT WINAPI
1369 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1370 DDPIXELFORMAT *PixelFormat)
1372 /* What is DDERR_INVALIDSURFACETYPE for here? */
1373 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1374 TRACE("(%p)->(%p)\n",This,PixelFormat);
1377 return DDERR_INVALIDPARAMS;
1379 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1385 /*****************************************************************************
1386 * IDirectDrawSurface7::GetSurfaceDesc
1388 * Returns the description of this surface
1391 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1396 * DDERR_INVALIDPARAMS if DDSD is NULL
1398 *****************************************************************************/
1399 static HRESULT WINAPI
1400 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1401 DDSURFACEDESC2 *DDSD)
1403 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1405 TRACE("(%p)->(%p)\n",This,DDSD);
1408 return DDERR_INVALIDPARAMS;
1410 if ((DDSD->dwSize < sizeof(DDSURFACEDESC)) ||
1411 (DDSD->dwSize > sizeof(DDSURFACEDESC2)))
1413 ERR("Impossible/Strange struct size %d.\n",DDSD->dwSize);
1414 return DDERR_GENERIC;
1417 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1418 TRACE("Returning surface desc:\n");
1419 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1424 /*****************************************************************************
1425 * IDirectDrawSurface7::Initialize
1427 * Initializes the surface. This is a no-op in Wine
1430 * DD: Pointer to an DirectDraw interface
1431 * DDSD: Surface description for initialization
1434 * DDERR_ALREADYINITIALIZED
1436 *****************************************************************************/
1437 static HRESULT WINAPI
1438 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1440 DDSURFACEDESC2 *DDSD)
1442 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1443 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1444 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1446 return DDERR_ALREADYINITIALIZED;
1449 /*****************************************************************************
1450 * IDirectDrawSurface7::IsLost
1452 * Checks if the surface is lost
1455 * DD_OK, if the surface is useable
1456 * DDERR_ISLOST if the surface is lost
1457 * See IWineD3DSurface::IsLost for more details
1459 *****************************************************************************/
1460 static HRESULT WINAPI
1461 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1463 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1464 TRACE("(%p)\n", This);
1466 /* We lose the surface if the implementation was changed */
1467 if(This->ImplType != This->ddraw->ImplType)
1469 /* But this shouldn't happen. When we change the implementation,
1470 * all surfaces are re-created automatically, and their content
1473 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1474 return DDERR_SURFACELOST;
1477 return IWineD3DSurface_IsLost(This->WineD3DSurface);
1480 /*****************************************************************************
1481 * IDirectDrawSurface7::Restore
1483 * Restores a lost surface. This makes the surface usable again, but
1484 * doesn't reload its old contents
1488 * See IWineD3DSurface::Restore for more details
1490 *****************************************************************************/
1491 static HRESULT WINAPI
1492 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1494 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1495 TRACE("(%p)\n", This);
1497 if(This->ImplType != This->ddraw->ImplType)
1499 /* Call the recreation callback. Make sure to AddRef first */
1500 IDirectDrawSurface_AddRef(iface);
1501 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1502 &This->surface_desc,
1503 NULL /* Not needed */);
1505 return IWineD3DSurface_Restore(This->WineD3DSurface);
1508 /*****************************************************************************
1509 * IDirectDrawSurface7::SetOverlayPosition
1511 * Changes the display coordinates of an overlay surface
1518 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1519 *****************************************************************************/
1520 static HRESULT WINAPI
1521 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1525 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1526 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1528 return IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1533 /*****************************************************************************
1534 * IDirectDrawSurface7::UpdateOverlay
1536 * Modifies the attributes of an overlay surface.
1539 * SrcRect: The section of the source being used for the overlay
1540 * DstSurface: Address of the surface that is overlaid
1541 * DstRect: Place of the overlay
1542 * Flags: some DDOVER_* flags
1545 * DDERR_UNSUPPORTED, because we don't support overlays
1547 *****************************************************************************/
1548 static HRESULT WINAPI
1549 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1551 IDirectDrawSurface7 *DstSurface,
1556 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1557 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1558 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1560 return IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1562 Dst ? Dst->WineD3DSurface : NULL,
1565 (WINEDDOVERLAYFX *) FX);
1568 /*****************************************************************************
1569 * IDirectDrawSurface7::UpdateOverlayDisplay
1571 * The DX7 sdk says that it's not implemented
1576 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1578 *****************************************************************************/
1579 static HRESULT WINAPI
1580 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1583 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1584 TRACE("(%p)->(%x)\n", This, Flags);
1585 return DDERR_UNSUPPORTED;
1588 /*****************************************************************************
1589 * IDirectDrawSurface7::UpdateOverlayZOrder
1591 * Sets an overlay's Z order
1594 * Flags: DDOVERZ_* flags
1595 * DDSRef: Defines the relative position in the overlay chain
1598 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1600 *****************************************************************************/
1601 static HRESULT WINAPI
1602 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1604 IDirectDrawSurface7 *DDSRef)
1606 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1607 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1609 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1610 return IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1612 Ref ? Ref->WineD3DSurface : NULL);
1615 /*****************************************************************************
1616 * IDirectDrawSurface7::GetDDInterface
1618 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1619 * surface belongs to
1622 * DD: Address to write the interface pointer to
1626 * DDERR_INVALIDPARAMS if DD is NULL
1628 *****************************************************************************/
1629 static HRESULT WINAPI
1630 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1633 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1635 /* It is not quite correct to use the same lpVtable for the different
1636 * IDirectDrawSurface versions because the GetDDInterface return different interfaces
1638 FIXME("(%p)->(%p)\n",This,DD);
1641 return DDERR_INVALIDPARAMS;
1643 switch(This->version)
1646 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1647 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1651 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1652 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1656 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1657 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1665 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1666 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1668 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1669 volatile IDirectDrawSurfaceImpl* vThis = This;
1671 TRACE("(%p)\n",This);
1672 /* A uniqueness value of 0 is apparently special.
1673 * This needs to be checked. */
1675 DWORD old_uniqueness_value = vThis->uniqueness_value;
1676 DWORD new_uniqueness_value = old_uniqueness_value+1;
1678 if (old_uniqueness_value == 0) break;
1679 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1681 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1682 old_uniqueness_value,
1683 new_uniqueness_value)
1684 == old_uniqueness_value)
1691 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1693 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1695 TRACE("(%p)->(%p)\n",This,pValue);
1696 *pValue = This->uniqueness_value;
1700 /*****************************************************************************
1701 * IDirectDrawSurface7::SetLOD
1703 * Sets the level of detail of a texture
1706 * MaxLOD: LOD to set
1710 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1712 *****************************************************************************/
1713 static HRESULT WINAPI
1714 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1717 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1718 TRACE("(%p)->(%d)\n", This, MaxLOD);
1720 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1721 return DDERR_INVALIDOBJECT;
1723 if(!This->wineD3DTexture)
1725 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1726 return DDERR_INVALIDOBJECT;
1729 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1733 /*****************************************************************************
1734 * IDirectDrawSurface7::GetLOD
1736 * Returns the level of detail of a Direct3D texture
1739 * MaxLOD: Address to write the LOD to
1743 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1744 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1746 *****************************************************************************/
1747 static HRESULT WINAPI
1748 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1751 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1752 TRACE("(%p)->(%p)\n", This, MaxLOD);
1755 return DDERR_INVALIDPARAMS;
1757 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1758 return DDERR_INVALIDOBJECT;
1760 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1764 /*****************************************************************************
1765 * IDirectDrawSurface7::BltFast
1767 * Performs a fast Blit.
1770 * dstx: The x coordinate to blit to on the destination
1771 * dsty: The y coordinate to blit to on the destination
1772 * Source: The source surface
1773 * rsrc: The source rectangle
1774 * trans: Type of transfer. Some DDBLTFAST_* flags
1778 * For more details, see IWineD3DSurface::BltFast
1780 *****************************************************************************/
1781 static HRESULT WINAPI
1782 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1785 IDirectDrawSurface7 *Source,
1789 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1790 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1791 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1793 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1795 src ? src->WineD3DSurface : NULL,
1800 /*****************************************************************************
1801 * IDirectDrawSurface7::GetClipper
1803 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1807 * Clipper: Address to store the interface pointer at
1811 * DDERR_INVALIDPARAMS if Clipper is NULL
1812 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1814 *****************************************************************************/
1815 static HRESULT WINAPI
1816 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1817 IDirectDrawClipper **Clipper)
1819 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1820 TRACE("(%p)->(%p)\n", This, Clipper);
1823 return DDERR_INVALIDPARAMS;
1825 if(This->clipper == NULL)
1826 return DDERR_NOCLIPPERATTACHED;
1828 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1829 IDirectDrawClipper_AddRef(*Clipper);
1833 /*****************************************************************************
1834 * IDirectDrawSurface7::SetClipper
1836 * Sets a clipper for the surface
1839 * Clipper: IDirectDrawClipper interface of the clipper to set
1844 *****************************************************************************/
1845 static HRESULT WINAPI
1846 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1847 IDirectDrawClipper *Clipper)
1849 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1851 TRACE("(%p)->(%p)\n",This,Clipper);
1852 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1855 if (This->clipper != NULL)
1856 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1858 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1859 if (Clipper != NULL)
1860 IDirectDrawClipper_AddRef(Clipper);
1865 /*****************************************************************************
1866 * IDirectDrawSurface7::SetSurfaceDesc
1868 * Sets the surface description. It can override the pixel format, the surface
1870 * It's not really tested.
1873 * DDSD: Pointer to the new surface description to set
1878 * DDERR_INVALIDPARAMS if DDSD is NULL
1880 *****************************************************************************/
1881 static HRESULT WINAPI
1882 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1883 DDSURFACEDESC2 *DDSD,
1886 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1887 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1889 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
1892 return DDERR_INVALIDPARAMS;
1894 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1896 ERR("Setting the surface memory isn't supported yet\n");
1897 return DDERR_INVALIDPARAMS;
1900 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1902 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1904 if(newFormat == WINED3DFMT_UNKNOWN)
1906 ERR("Requested to set an unknown pixelformat\n");
1907 return DDERR_INVALIDPARAMS;
1909 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1911 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1913 if(hr != DD_OK) return hr;
1916 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1918 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1920 &DDSD->u3.ddckCKDestOverlay);
1922 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1924 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1926 &DDSD->ddckCKDestBlt);
1928 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1930 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1932 &DDSD->ddckCKSrcOverlay);
1934 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1936 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1938 &DDSD->ddckCKSrcBlt);
1940 if (DDSD->dwFlags & DDSD_LPSURFACE)
1942 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
1943 if(hr != WINED3D_OK)
1945 /* No need for a trace here, wined3d does that for us */
1950 This->surface_desc = *DDSD;
1955 /*****************************************************************************
1956 * IDirectDrawSurface7::GetPalette
1958 * Returns the IDirectDrawPalette interface of the palette currently assigned
1962 * Pal: Address to write the interface pointer to
1966 * DDERR_INVALIDPARAMS if Pal is NULL
1968 *****************************************************************************/
1969 static HRESULT WINAPI
1970 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1971 IDirectDrawPalette **Pal)
1973 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1974 IWineD3DPalette *wPal;
1976 TRACE("(%p)->(%p): Relay\n", This, Pal);
1979 return DDERR_INVALIDPARAMS;
1981 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1982 if(hr != DD_OK) return hr;
1986 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
1991 hr = DDERR_NOPALETTEATTACHED;
1997 /*****************************************************************************
1998 * IDirectDrawSurface7::SetColorKey
2000 * Sets the color keying options for the surface. Observations showed that
2001 * in case of complex surfaces the color key has to be assigned to all
2006 * CKey: The new color key
2010 * See IWineD3DSurface::SetColorKey for details
2012 *****************************************************************************/
2013 static HRESULT WINAPI
2014 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2018 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2019 IDirectDrawSurfaceImpl *surf;
2021 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2023 for(surf = This->first_complex; surf; surf = surf->next_complex)
2025 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
2030 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08x\n",
2031 surf->WineD3DSurface, hr);
2038 /*****************************************************************************
2039 * IDirectDrawSurface7::SetPalette
2041 * Assigns a DirectDrawPalette object to the surface
2044 * Pal: Interface to the palette to set
2049 *****************************************************************************/
2050 static HRESULT WINAPI
2051 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2052 IDirectDrawPalette *Pal)
2054 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2055 IDirectDrawPalette *oldPal;
2056 IDirectDrawSurfaceImpl *surf;
2057 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2059 TRACE("(%p)->(%p)\n", This, Pal);
2061 /* Find the old palette */
2062 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2063 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED) return hr;
2064 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2066 /* Set the new Palette */
2067 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2068 PalImpl ? PalImpl->wineD3DPalette : NULL);
2069 /* AddRef the Palette */
2070 if(Pal) IDirectDrawPalette_AddRef(Pal);
2072 /* Release the old palette */
2073 if(oldPal) IDirectDrawPalette_Release(oldPal);
2075 /* If this is a front buffer, also update the back buffers */
2076 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2078 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2080 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2088 /*****************************************************************************
2090 *****************************************************************************/
2092 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2095 IDirectDrawSurfaceImpl_QueryInterface,
2096 IDirectDrawSurfaceImpl_AddRef,
2097 IDirectDrawSurfaceImpl_Release,
2098 /*** IDirectDrawSurface ***/
2099 IDirectDrawSurfaceImpl_AddAttachedSurface,
2100 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2101 IDirectDrawSurfaceImpl_Blt,
2102 IDirectDrawSurfaceImpl_BltBatch,
2103 IDirectDrawSurfaceImpl_BltFast,
2104 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2105 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2106 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2107 IDirectDrawSurfaceImpl_Flip,
2108 IDirectDrawSurfaceImpl_GetAttachedSurface,
2109 IDirectDrawSurfaceImpl_GetBltStatus,
2110 IDirectDrawSurfaceImpl_GetCaps,
2111 IDirectDrawSurfaceImpl_GetClipper,
2112 IDirectDrawSurfaceImpl_GetColorKey,
2113 IDirectDrawSurfaceImpl_GetDC,
2114 IDirectDrawSurfaceImpl_GetFlipStatus,
2115 IDirectDrawSurfaceImpl_GetOverlayPosition,
2116 IDirectDrawSurfaceImpl_GetPalette,
2117 IDirectDrawSurfaceImpl_GetPixelFormat,
2118 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2119 IDirectDrawSurfaceImpl_Initialize,
2120 IDirectDrawSurfaceImpl_IsLost,
2121 IDirectDrawSurfaceImpl_Lock,
2122 IDirectDrawSurfaceImpl_ReleaseDC,
2123 IDirectDrawSurfaceImpl_Restore,
2124 IDirectDrawSurfaceImpl_SetClipper,
2125 IDirectDrawSurfaceImpl_SetColorKey,
2126 IDirectDrawSurfaceImpl_SetOverlayPosition,
2127 IDirectDrawSurfaceImpl_SetPalette,
2128 IDirectDrawSurfaceImpl_Unlock,
2129 IDirectDrawSurfaceImpl_UpdateOverlay,
2130 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2131 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2132 /*** IDirectDrawSurface2 ***/
2133 IDirectDrawSurfaceImpl_GetDDInterface,
2134 IDirectDrawSurfaceImpl_PageLock,
2135 IDirectDrawSurfaceImpl_PageUnlock,
2136 /*** IDirectDrawSurface3 ***/
2137 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2138 /*** IDirectDrawSurface4 ***/
2139 IDirectDrawSurfaceImpl_SetPrivateData,
2140 IDirectDrawSurfaceImpl_GetPrivateData,
2141 IDirectDrawSurfaceImpl_FreePrivateData,
2142 IDirectDrawSurfaceImpl_GetUniquenessValue,
2143 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2144 /*** IDirectDrawSurface7 ***/
2145 IDirectDrawSurfaceImpl_SetPriority,
2146 IDirectDrawSurfaceImpl_GetPriority,
2147 IDirectDrawSurfaceImpl_SetLOD,
2148 IDirectDrawSurfaceImpl_GetLOD