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);
312 IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
314 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
317 ERR("(%p) Failed to uninit 3D\n", This);
321 /* Free the d3d window if one was created */
322 if(ddraw->d3d_window != 0)
324 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
325 DestroyWindow(ddraw->d3d_window);
326 ddraw->d3d_window = 0;
328 /* Unset the pointers */
331 ddraw->d3d_initialized = FALSE;
332 ddraw->d3d_target = NULL;
334 /* Write a trace because D3D unloading was the reason for many
335 * crashes during development.
337 TRACE("(%p) D3D unloaded\n", This);
339 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
343 /* It's a render target, but no swapchain was created.
344 * The IParent interfaces have to be released manually.
345 * The same applies for textures without an
346 * IWineD3DTexture object attached
353 IWineD3DSurface_GetParent(surf->WineD3DSurface,
354 (IUnknown **) &Parent);
355 IParent_Release(Parent); /* For the getParent */
356 IParent_Release(Parent); /* To release it */
357 surf = surf->next_complex;
361 /* The refcount test shows that the palette is detached when the surface is destroyed */
362 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
365 /* Loop through all complex attached surfaces,
368 while( (surf = This->next_complex) )
370 This->next_complex = surf->next_complex; /* Unchain it from the complex listing */
371 IDirectDrawSurfaceImpl_Destroy(surf); /* Destroy it */
374 /* Destroy the surface.
376 IDirectDrawSurfaceImpl_Destroy(This);
378 /* Reduce the ddraw refcount */
379 IUnknown_Release(ifaceToRelease);
385 /*****************************************************************************
386 * IDirectDrawSurface7::GetAttachedSurface
388 * Returns an attached surface with the requested caps. Surface attachment
389 * and complex surfaces are not clearly described by the MSDN or sdk,
390 * so this method is tricky and likely to contain problems.
391 * This implementation searches the complex chain first, then the
392 * attachment chain, and then it checks if the caps match to itself.
394 * The chains are searched from This down to the last surface in the chain,
395 * not from the first element in the chain. The first surface found is
396 * returned. The MSDN says that this method fails if more than one surface
397 * matches the caps, but apparently this is incorrect.
399 * The found surface is AddRef-ed before it is returned.
402 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
403 * Surface: Address to store the found surface
407 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
408 * DDERR_NOTFOUND if no surface was found
410 *****************************************************************************/
411 static HRESULT WINAPI
412 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
414 IDirectDrawSurface7 **Surface)
416 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
417 IDirectDrawSurfaceImpl *surf;
420 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
424 if(This->version < 7)
426 /* Earlier dx apps put garbage into these members, clear them */
427 our_caps.dwCaps2 = 0;
428 our_caps.dwCaps3 = 0;
429 our_caps.dwCaps4 = 0;
432 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 */
434 /* First, look at the complex chain */
437 while( (surf = surf->next_complex) )
441 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
442 surf->surface_desc.ddsCaps.dwCaps,
443 surf->surface_desc.ddsCaps.dwCaps2,
444 surf->surface_desc.ddsCaps.dwCaps3,
445 surf->surface_desc.ddsCaps.dwCaps4);
448 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
449 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
451 /* MSDN: "This method fails if more than one surface is attached
452 * that matches the capabilities requested."
454 * The mipmap demo of the DirectX7 sdk shows what to do here:
455 * apparently apps expect the first found surface to be returned.
458 TRACE("(%p): Returning surface %p\n", This, surf);
459 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
460 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
461 IDirectDrawSurface7_AddRef(*Surface);
466 /* Next, look at the attachment chain */
469 while( (surf = surf->next_attached) )
473 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
474 surf->surface_desc.ddsCaps.dwCaps,
475 surf->surface_desc.ddsCaps.dwCaps2,
476 surf->surface_desc.ddsCaps.dwCaps3,
477 surf->surface_desc.ddsCaps.dwCaps4);
480 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
481 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
483 /* MSDN: "This method fails if more than one surface is attached
484 * that matches the capabilities requested."
486 * The mipmap demo of the DirectX7 sdk shows what to do here:
487 * apparently apps expect the first found surface to be returned.
490 TRACE("(%p): Returning surface %p\n", This, surf);
491 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
492 IDirectDrawSurface7_AddRef(*Surface);
499 if (((This->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
500 ((This->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2) &&
501 This == This->first_complex)
504 TRACE("(%p): Returning surface %p\n", This, This);
505 *Surface = ICOM_INTERFACE(This, IDirectDrawSurface7);
506 IDirectDrawSurface7_AddRef(*Surface);
511 /* What to do here? Continue with the surface root?? */
513 TRACE("(%p) Didn't find a valid surface\n", This);
514 return DDERR_NOTFOUND;
517 /*****************************************************************************
518 * IDirectDrawSurface7::Lock
520 * Locks the surface and returns a pointer to the surface's memory
523 * Rect: Rectangle to lock. If NULL, the whole surface is locked
524 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
525 * Flags: Locking flags, e.g Read only or write only
526 * h: An event handle that's not used and must be NULL
530 * DDERR_INVALIDPARAMS if DDSD is NULL
531 * For more details, see IWineD3DSurface::LockRect
533 *****************************************************************************/
534 static HRESULT WINAPI
535 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
537 DDSURFACEDESC2 *DDSD,
541 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
542 WINED3DLOCKED_RECT LockedRect;
544 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
547 return DDERR_INVALIDPARAMS;
549 /* Should I check for the handle to be NULL?
551 * The DDLOCK flags and the D3DLOCK flags are equal
552 * for the supported values. The others are ignored by WineD3D
555 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
556 * that means it doesn't have dwSize set. Init it to some sane
559 if(DDSD->dwSize <= sizeof(DDSURFACEDESC))
561 DDSD->dwSize = sizeof(DDSURFACEDESC);
565 DDSD->dwSize = sizeof(DDSURFACEDESC2);
568 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
569 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
573 if(hr != D3D_OK) return hr;
575 /* Override the memory area and the pitch */
576 DDSD->dwFlags |= DDSD_LPSURFACE;
577 DDSD->lpSurface = LockedRect.pBits;
578 DDSD->dwFlags |= DDSD_PITCH;
579 DDSD->u1.lPitch = LockedRect.Pitch;
581 TRACE("locked surface returning description :\n");
582 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
587 /*****************************************************************************
588 * IDirectDrawSurface7::Unlock
590 * Unlocks an locked surface
593 * Rect: Not used by this implementation
597 * For more details, see IWineD3DSurface::UnlockRect
599 *****************************************************************************/
600 static HRESULT WINAPI
601 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
604 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
605 TRACE("(%p)->(%p)\n", This, pRect);
607 return IWineD3DSurface_UnlockRect(This->WineD3DSurface);
610 /*****************************************************************************
611 * IDirectDrawSurface7::Flip
613 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
614 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
615 * the flip target is passed to WineD3D, even if the app didn't specify one
618 * DestOverride: Specifies the surface that will become the new front
619 * buffer. If NULL, the current back buffer is used
620 * Flags: some DirectDraw flags, see include/ddraw.h
624 * DDERR_NOTFLIPPABLE if no flip target could be found
625 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
626 * For more details, see IWineD3DSurface::Flip
628 *****************************************************************************/
629 static HRESULT WINAPI
630 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
631 IDirectDrawSurface7 *DestOverride,
634 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
635 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
636 IDirectDrawSurface7 *Override7;
638 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
640 /* Flip has to be called from a front buffer
641 * What about overlay surfaces, AFAIK they can flip too?
643 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
644 return DDERR_INVALIDOBJECT; /* Unckecked */
646 /* WineD3D doesn't keep track of attached surface, so find the target */
651 memset(&Caps, 0, sizeof(Caps));
652 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
653 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
656 ERR("Can't find a flip target\n");
657 return DDERR_NOTFLIPPABLE; /* Unchecked */
659 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
661 /* For the GetAttachedSurface */
662 IDirectDrawSurface7_Release(Override7);
665 return IWineD3DSurface_Flip(This->WineD3DSurface,
666 Override->WineD3DSurface,
670 /*****************************************************************************
671 * IDirectDrawSurface7::Blt
673 * Performs a blit on the surface
676 * DestRect: Destination rectangle, can be NULL
677 * SrcSurface: Source surface, can be NULL
678 * SrcRect: Source rectange, can be NULL
680 * DDBltFx: Some extended blt parameters, connected to the flags
684 * See IWineD3DSurface::Blt for more details
686 *****************************************************************************/
687 static HRESULT WINAPI
688 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
690 IDirectDrawSurface7 *SrcSurface,
695 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
696 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
697 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
699 return IWineD3DSurface_Blt(This->WineD3DSurface,
701 Src ? Src->WineD3DSurface : NULL,
707 /*****************************************************************************
708 * IDirectDrawSurface7::AddAttachedSurface
710 * Attaches a surface to another surface. Surface attachments are
711 * incorrectly described in the SDK and the MSDN, and this method
712 * is prone to bugs. The surface that is attached is AddRef-ed.
714 * The attachment list consists of a first surface (first_attached) and
715 * for each surface a pointer to the next attached surface (next_attached).
716 * For the first surface, and a surface that has no attachments
717 * first_attached points to the surface itself. A surface that has
718 * no successors in the chain has next_attached set to NULL.
720 * Newly attached surfaces are attached right after the root surface. The
721 * complex chains are handled separately in a similar chain, with
722 * first_complex and next_complex. If a surface is attached to a complex
723 * surface compound, it's attached to the surface that the app requested,
724 * not the complex root. See GetAttachedSurface for a description
725 * how surfaces are found.
727 * This is how the current implementation works, and it was coded by looking
728 * at the needs of the applications.
730 * So far only Z-Buffer attachments are tested, but there's no code yet
731 * to activate them. Mipmaps could be tricky to activate in WineD3D.
732 * Back buffers should work in 2D mode, but they are not tested.
733 * Rendering to the primary surface and switching between that and
734 * double buffering is not yet implemented in WineD3D, so for 3D it might
735 * have unexpected results.
738 * Attach: Surface to attach to iface
742 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
744 *****************************************************************************/
745 static HRESULT WINAPI
746 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
747 IDirectDrawSurface7 *Attach)
749 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
750 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
751 TRACE("(%p)->(%p)\n", This, Surf);
753 /* Should I make sure to add it to the first complex surface? */
756 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
758 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
759 * But apparently backbuffers and mipmaps can be attached too. */
761 /* Set MIPMAPSUBLEVEL if this seems to be one */
762 if (This->surface_desc.ddsCaps.dwCaps &
763 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
765 Surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
766 /* FIXME: we should probably also add to dwMipMapCount of this
767 * and all parent surfaces (update create_texture if you do) */
770 /* Check if the surface is already attached somewhere */
771 if( (Surf->next_attached != NULL) ||
772 (Surf->first_attached != Surf) )
774 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);
775 return DDERR_CANNOTATTACHSURFACE;
778 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
779 Surf->next_attached = This->next_attached;
780 Surf->first_attached = This->first_attached;
781 This->next_attached = Surf;
783 /* Check if we attach a back buffer to the primary */
784 if(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER &&
785 This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
787 IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice,
788 Surf->WineD3DSurface);
792 * "This method increments the reference count of the surface being attached."
794 IDirectDrawSurface7_AddRef(Attach);
798 /*****************************************************************************
799 * IDirectDrawSurface7::DeleteAttachedSurface
801 * Removes a surface from the attachment chain. The surface's refcount
802 * is decreased by one after it has been removed
805 * Flags: Some flags, not used by this implementation
806 * Attach: Surface to detach
810 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
812 *****************************************************************************/
813 static HRESULT WINAPI
814 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
816 IDirectDrawSurface7 *Attach)
818 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
819 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
820 IDirectDrawSurfaceImpl *Prev = This;
821 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
823 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
824 return DDERR_SURFACENOTATTACHED; /* unchecked */
826 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
827 if (This->surface_desc.ddsCaps.dwCaps &
828 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
830 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
831 /* FIXME: we should probably also subtract from dwMipMapCount of this
832 * and all parent surfaces */
835 /* Find the predecessor of the detached surface */
838 if(Prev->next_attached == Surf) break;
839 Prev = Prev->next_attached;
842 /* There must be a surface, otherwise there's a bug */
843 assert(Prev != NULL);
845 /* Unchain the surface */
846 Prev->next_attached = Surf->next_attached;
847 Surf->next_attached = NULL;
848 Surf->first_attached = Surf;
850 /* Check if we attach a back buffer to the primary */
851 if(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER &&
852 This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
854 IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice,
858 IDirectDrawSurface7_Release(Attach);
862 /*****************************************************************************
863 * IDirectDrawSurface7::AddOverlayDirtyRect
865 * "This method is not currently implemented"
873 *****************************************************************************/
874 static HRESULT WINAPI
875 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
878 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
879 TRACE("(%p)->(%p)\n",This,Rect);
881 /* MSDN says it's not implemented. I could forward it to WineD3D,
882 * then we'd implement it, but I don't think that's a good idea
886 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
888 return DDERR_UNSUPPORTED; /* unchecked */
891 /*****************************************************************************
892 * IDirectDrawSurface7::GetDC
894 * Returns a GDI device context for the surface
897 * hdc: Address of a HDC variable to store the dc to
901 * DDERR_INVALIDPARAMS if hdc is NULL
902 * For details, see IWineD3DSurface::GetDC
904 *****************************************************************************/
905 static HRESULT WINAPI
906 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
909 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
910 TRACE("(%p)->(%p): Relay\n", This, hdc);
913 return DDERR_INVALIDPARAMS;
915 return IWineD3DSurface_GetDC(This->WineD3DSurface,
919 /*****************************************************************************
920 * IDirectDrawSurface7::ReleaseDC
922 * Releases the DC that was constructed with GetDC
925 * hdc: HDC to release
929 * For more details, see IWineD3DSurface::ReleaseDC
931 *****************************************************************************/
932 static HRESULT WINAPI
933 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
936 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
937 TRACE("(%p)->(%p): Relay\n", This, hdc);
939 return IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
942 /*****************************************************************************
943 * IDirectDrawSurface7::GetCaps
945 * Returns the surface's caps
948 * Caps: Address to write the caps to
952 * DDERR_INVALIDPARAMS if Caps is NULL
954 *****************************************************************************/
955 static HRESULT WINAPI
956 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
959 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
960 TRACE("(%p)->(%p)\n",This,Caps);
963 return DDERR_INVALIDPARAMS;
965 *Caps = This->surface_desc.ddsCaps;
969 /*****************************************************************************
970 * IDirectDrawSurface7::SetPriority
972 * Sets a texture priority for managed textures.
975 * Priority: The new priority
979 * For more details, see IWineD3DSurface::SetPriority
981 *****************************************************************************/
982 static HRESULT WINAPI
983 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
985 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
986 TRACE("(%p)->(%d): Relay!\n",This,Priority);
988 return IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
991 /*****************************************************************************
992 * IDirectDrawSurface7::GetPriority
994 * Returns the surface's priority
997 * Priority: Address of a variable to write the priority to
1001 * DDERR_INVALIDPARAMS if Priority == NULL
1002 * For more details, see IWineD3DSurface::GetPriority
1004 *****************************************************************************/
1005 static HRESULT WINAPI
1006 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1009 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1010 TRACE("(%p)->(%p): Relay\n",This,Priority);
1013 return DDERR_INVALIDPARAMS;
1015 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1019 /*****************************************************************************
1020 * IDirectDrawSurface7::SetPrivateData
1022 * Stores some data in the surface that is intended for the application's
1026 * tag: GUID that identifies the data
1027 * Data: Pointer to the private data
1028 * Size: Size of the private data
1033 * For more details, see IWineD3DSurface::SetPrivateData
1035 *****************************************************************************/
1036 static HRESULT WINAPI
1037 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1043 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1044 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1046 return IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1053 /*****************************************************************************
1054 * IDirectDrawSurface7::GetPrivateData
1056 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1059 * tag: GUID of the data to return
1060 * Data: Address where to write the data to
1061 * Size: Size of the buffer at Data
1065 * DDERR_INVALIDPARAMS if Data is NULL
1066 * For more details, see IWineD3DSurface::GetPrivateData
1068 *****************************************************************************/
1069 static HRESULT WINAPI
1070 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1075 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1076 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1079 return DDERR_INVALIDPARAMS;
1081 return IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1087 /*****************************************************************************
1088 * IDirectDrawSurface7::FreePrivateData
1090 * Frees private data stored in the surface
1093 * tag: Tag of the data to free
1097 * For more details, see IWineD3DSurface::FreePrivateData
1099 *****************************************************************************/
1100 static HRESULT WINAPI
1101 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1104 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1105 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1107 return IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1110 /*****************************************************************************
1111 * IDirectDrawSurface7::PageLock
1113 * Prevents a sysmem surface from being paged out
1116 * Flags: Not used, must be 0(unchecked)
1119 * DD_OK, because it's a stub
1121 *****************************************************************************/
1122 static HRESULT WINAPI
1123 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1126 TRACE("(%p)->(%x)\n", iface, Flags);
1128 /* This is Windows memory management related - we don't need this */
1132 /*****************************************************************************
1133 * IDirectDrawSurface7::PageUnlock
1135 * Allows a sysmem surface to be paged out
1138 * Flags: Not used, must be 0(unckeched)
1141 * DD_OK, because it's a stub
1143 *****************************************************************************/
1144 static HRESULT WINAPI
1145 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1148 TRACE("(%p)->(%x)\n", iface, Flags);
1153 /*****************************************************************************
1154 * IDirectDrawSurface7::BltBatch
1156 * An unimplemented function
1164 *****************************************************************************/
1165 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1167 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1169 /* MSDN: "not currently implemented" */
1170 return DDERR_UNSUPPORTED;
1173 /*****************************************************************************
1174 * IDirectDrawSurface7::EnumAttachedSurfaces
1176 * Enumerates all surfaces attached to this surface
1179 * context: Pointer to pass unmodified to the callback
1180 * cb: Callback function to call for each surface
1184 * DDERR_INVALIDPARAMS if cb is NULL
1186 *****************************************************************************/
1187 static HRESULT WINAPI
1188 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1190 LPDDENUMSURFACESCALLBACK7 cb)
1192 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1193 IDirectDrawSurfaceImpl *surf;
1194 DDSURFACEDESC2 desc;
1196 /* Attached surfaces aren't handled in WineD3D */
1197 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1200 return DDERR_INVALIDPARAMS;
1202 for (surf = This->next_complex; surf != NULL; surf = surf->next_complex)
1204 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1205 desc = surf->surface_desc;
1206 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1207 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1211 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1213 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1214 desc = surf->surface_desc;
1215 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1216 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1220 TRACE(" end of enumeration.\n");
1225 /*****************************************************************************
1226 * IDirectDrawSurface7::EnumOverlayZOrders
1228 * "Enumerates the overlay surfaces on the specified destination"
1231 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1232 * context: context to pass back to the callback
1233 * cb: callback function to call for each enumerated surface
1236 * DD_OK, because it's a stub
1238 *****************************************************************************/
1239 static HRESULT WINAPI
1240 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1243 LPDDENUMSURFACESCALLBACK7 cb)
1245 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1250 /*****************************************************************************
1251 * IDirectDrawSurface7::GetBltStatus
1253 * Returns the blitting status
1256 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1259 * See IWineD3DSurface::Blt
1261 *****************************************************************************/
1262 static HRESULT WINAPI
1263 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1266 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1267 TRACE("(%p)->(%x): Relay\n", This, Flags);
1269 return IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1272 /*****************************************************************************
1273 * IDirectDrawSurface7::GetColorKey
1275 * Returns the color key assigned to the surface
1279 * CKey: Address to store the key to
1283 * DDERR_INVALIDPARAMS if CKey is NULL
1285 *****************************************************************************/
1286 static HRESULT WINAPI
1287 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1291 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1292 * isn't there? That's like saying that an int isn't there. (Which MS
1293 * has done in other docs.) */
1295 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1298 return DDERR_INVALIDPARAMS;
1302 case DDCKEY_DESTBLT:
1303 *CKey = This->surface_desc.ddckCKDestBlt;
1306 case DDCKEY_DESTOVERLAY:
1307 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1311 *CKey = This->surface_desc.ddckCKSrcBlt;
1314 case DDCKEY_SRCOVERLAY:
1315 *CKey = This->surface_desc.ddckCKSrcOverlay;
1319 return DDERR_INVALIDPARAMS;
1325 /*****************************************************************************
1326 * IDirectDrawSurface7::GetFlipStatus
1328 * Returns the flipping status of the surface
1331 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1334 * See IWineD3DSurface::GetFlipStatus
1336 *****************************************************************************/
1337 static HRESULT WINAPI
1338 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1341 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1342 TRACE("(%p)->(%x): Relay\n", This, Flags);
1344 return IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1347 /*****************************************************************************
1348 * IDirectDrawSurface7::GetOverlayPosition
1350 * Returns the display coordinates of a visible and active overlay surface
1357 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1358 *****************************************************************************/
1359 static HRESULT WINAPI
1360 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1363 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1364 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1366 return IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1371 /*****************************************************************************
1372 * IDirectDrawSurface7::GetPixelFormat
1374 * Returns the pixel format of the Surface
1377 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1378 * format should be written
1382 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1384 *****************************************************************************/
1385 static HRESULT WINAPI
1386 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1387 DDPIXELFORMAT *PixelFormat)
1389 /* What is DDERR_INVALIDSURFACETYPE for here? */
1390 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1391 TRACE("(%p)->(%p)\n",This,PixelFormat);
1394 return DDERR_INVALIDPARAMS;
1396 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1402 /*****************************************************************************
1403 * IDirectDrawSurface7::GetSurfaceDesc
1405 * Returns the description of this surface
1408 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1413 * DDERR_INVALIDPARAMS if DDSD is NULL
1415 *****************************************************************************/
1416 static HRESULT WINAPI
1417 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1418 DDSURFACEDESC2 *DDSD)
1420 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1422 TRACE("(%p)->(%p)\n",This,DDSD);
1425 return DDERR_INVALIDPARAMS;
1427 if ((DDSD->dwSize < sizeof(DDSURFACEDESC)) ||
1428 (DDSD->dwSize > sizeof(DDSURFACEDESC2)))
1430 ERR("Impossible/Strange struct size %d.\n",DDSD->dwSize);
1431 return DDERR_GENERIC;
1434 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1435 TRACE("Returning surface desc:\n");
1436 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1441 /*****************************************************************************
1442 * IDirectDrawSurface7::Initialize
1444 * Initializes the surface. This is a no-op in Wine
1447 * DD: Pointer to an DirectDraw interface
1448 * DDSD: Surface description for initialization
1451 * DDERR_ALREADYINITIALIZED
1453 *****************************************************************************/
1454 static HRESULT WINAPI
1455 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1457 DDSURFACEDESC2 *DDSD)
1459 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1460 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1461 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1463 return DDERR_ALREADYINITIALIZED;
1466 /*****************************************************************************
1467 * IDirectDrawSurface7::IsLost
1469 * Checks if the surface is lost
1472 * DD_OK, if the surface is useable
1473 * DDERR_ISLOST if the surface is lost
1474 * See IWineD3DSurface::IsLost for more details
1476 *****************************************************************************/
1477 static HRESULT WINAPI
1478 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1480 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1481 TRACE("(%p)\n", This);
1483 /* We lose the surface if the implementation was changed */
1484 if(This->ImplType != This->ddraw->ImplType)
1486 /* But this shouldn't happen. When we change the implementation,
1487 * all surfaces are re-created automatically, and their content
1490 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1491 return DDERR_SURFACELOST;
1494 return IWineD3DSurface_IsLost(This->WineD3DSurface);
1497 /*****************************************************************************
1498 * IDirectDrawSurface7::Restore
1500 * Restores a lost surface. This makes the surface usable again, but
1501 * doesn't reload its old contents
1505 * See IWineD3DSurface::Restore for more details
1507 *****************************************************************************/
1508 static HRESULT WINAPI
1509 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1511 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1512 TRACE("(%p)\n", This);
1514 if(This->ImplType != This->ddraw->ImplType)
1516 /* Call the recreation callback. Make sure to AddRef first */
1517 IDirectDrawSurface_AddRef(iface);
1518 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1519 &This->surface_desc,
1520 NULL /* Not needed */);
1522 return IWineD3DSurface_Restore(This->WineD3DSurface);
1525 /*****************************************************************************
1526 * IDirectDrawSurface7::SetOverlayPosition
1528 * Changes the display coordinates of an overlay surface
1535 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1536 *****************************************************************************/
1537 static HRESULT WINAPI
1538 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1542 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1543 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1545 return IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1550 /*****************************************************************************
1551 * IDirectDrawSurface7::UpdateOverlay
1553 * Modifies the attributes of an overlay surface.
1556 * SrcRect: The section of the source being used for the overlay
1557 * DstSurface: Address of the surface that is overlaid
1558 * DstRect: Place of the overlay
1559 * Flags: some DDOVER_* flags
1562 * DDERR_UNSUPPORTED, because we don't support overlays
1564 *****************************************************************************/
1565 static HRESULT WINAPI
1566 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1568 IDirectDrawSurface7 *DstSurface,
1573 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1574 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1575 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1577 return IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1579 Dst ? Dst->WineD3DSurface : NULL,
1582 (WINEDDOVERLAYFX *) FX);
1585 /*****************************************************************************
1586 * IDirectDrawSurface7::UpdateOverlayDisplay
1588 * The DX7 sdk says that it's not implemented
1593 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1595 *****************************************************************************/
1596 static HRESULT WINAPI
1597 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1600 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1601 TRACE("(%p)->(%x)\n", This, Flags);
1602 return DDERR_UNSUPPORTED;
1605 /*****************************************************************************
1606 * IDirectDrawSurface7::UpdateOverlayZOrder
1608 * Sets an overlay's Z order
1611 * Flags: DDOVERZ_* flags
1612 * DDSRef: Defines the relative position in the overlay chain
1615 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1617 *****************************************************************************/
1618 static HRESULT WINAPI
1619 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1621 IDirectDrawSurface7 *DDSRef)
1623 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1624 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1626 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1627 return IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1629 Ref ? Ref->WineD3DSurface : NULL);
1632 /*****************************************************************************
1633 * IDirectDrawSurface7::GetDDInterface
1635 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1636 * surface belongs to
1639 * DD: Address to write the interface pointer to
1643 * DDERR_INVALIDPARAMS if DD is NULL
1645 *****************************************************************************/
1646 static HRESULT WINAPI
1647 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1650 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1652 /* It is not quite correct to use the same lpVtable for the different
1653 * IDirectDrawSurface versions because the GetDDInterface return different interfaces
1655 FIXME("(%p)->(%p)\n",This,DD);
1658 return DDERR_INVALIDPARAMS;
1660 switch(This->version)
1663 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1664 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1668 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1669 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1673 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1674 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1682 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1683 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1685 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1686 volatile IDirectDrawSurfaceImpl* vThis = This;
1688 TRACE("(%p)\n",This);
1689 /* A uniqueness value of 0 is apparently special.
1690 * This needs to be checked. */
1692 DWORD old_uniqueness_value = vThis->uniqueness_value;
1693 DWORD new_uniqueness_value = old_uniqueness_value+1;
1695 if (old_uniqueness_value == 0) break;
1696 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1698 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1699 old_uniqueness_value,
1700 new_uniqueness_value)
1701 == old_uniqueness_value)
1708 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1710 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1712 TRACE("(%p)->(%p)\n",This,pValue);
1713 *pValue = This->uniqueness_value;
1717 /*****************************************************************************
1718 * IDirectDrawSurface7::SetLOD
1720 * Sets the level of detail of a texture
1723 * MaxLOD: LOD to set
1727 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1729 *****************************************************************************/
1730 static HRESULT WINAPI
1731 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1734 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1735 TRACE("(%p)->(%d)\n", This, MaxLOD);
1737 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1738 return DDERR_INVALIDOBJECT;
1740 if(!This->wineD3DTexture)
1742 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1743 return DDERR_INVALIDOBJECT;
1746 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1750 /*****************************************************************************
1751 * IDirectDrawSurface7::GetLOD
1753 * Returns the level of detail of a Direct3D texture
1756 * MaxLOD: Address to write the LOD to
1760 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1761 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1763 *****************************************************************************/
1764 static HRESULT WINAPI
1765 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1768 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1769 TRACE("(%p)->(%p)\n", This, MaxLOD);
1772 return DDERR_INVALIDPARAMS;
1774 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1775 return DDERR_INVALIDOBJECT;
1777 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1781 /*****************************************************************************
1782 * IDirectDrawSurface7::BltFast
1784 * Performs a fast Blit.
1787 * dstx: The x coordinate to blit to on the destination
1788 * dsty: The y coordinate to blit to on the destination
1789 * Source: The source surface
1790 * rsrc: The source rectangle
1791 * trans: Type of transfer. Some DDBLTFAST_* flags
1795 * For more details, see IWineD3DSurface::BltFast
1797 *****************************************************************************/
1798 static HRESULT WINAPI
1799 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1802 IDirectDrawSurface7 *Source,
1806 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1807 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1808 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1810 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1812 src ? src->WineD3DSurface : NULL,
1817 /*****************************************************************************
1818 * IDirectDrawSurface7::GetClipper
1820 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1824 * Clipper: Address to store the interface pointer at
1828 * DDERR_INVALIDPARAMS if Clipper is NULL
1829 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1831 *****************************************************************************/
1832 static HRESULT WINAPI
1833 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1834 IDirectDrawClipper **Clipper)
1836 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1837 TRACE("(%p)->(%p)\n", This, Clipper);
1840 return DDERR_INVALIDPARAMS;
1842 if(This->clipper == NULL)
1843 return DDERR_NOCLIPPERATTACHED;
1845 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1846 IDirectDrawClipper_AddRef(*Clipper);
1850 /*****************************************************************************
1851 * IDirectDrawSurface7::SetClipper
1853 * Sets a clipper for the surface
1856 * Clipper: IDirectDrawClipper interface of the clipper to set
1861 *****************************************************************************/
1862 static HRESULT WINAPI
1863 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1864 IDirectDrawClipper *Clipper)
1866 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1868 TRACE("(%p)->(%p)\n",This,Clipper);
1869 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1872 if (This->clipper != NULL)
1873 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1875 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1876 if (Clipper != NULL)
1877 IDirectDrawClipper_AddRef(Clipper);
1882 /*****************************************************************************
1883 * IDirectDrawSurface7::SetSurfaceDesc
1885 * Sets the surface description. It can override the pixel format, the surface
1887 * It's not really tested.
1890 * DDSD: Pointer to the new surface description to set
1895 * DDERR_INVALIDPARAMS if DDSD is NULL
1897 *****************************************************************************/
1898 static HRESULT WINAPI
1899 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1900 DDSURFACEDESC2 *DDSD,
1903 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1904 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1906 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
1909 return DDERR_INVALIDPARAMS;
1911 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1913 ERR("Setting the surface memory isn't supported yet\n");
1914 return DDERR_INVALIDPARAMS;
1917 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1919 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1921 if(newFormat == WINED3DFMT_UNKNOWN)
1923 ERR("Requested to set an unknown pixelformat\n");
1924 return DDERR_INVALIDPARAMS;
1926 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1928 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1930 if(hr != DD_OK) return hr;
1933 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1935 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1937 &DDSD->u3.ddckCKDestOverlay);
1939 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1941 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1943 &DDSD->ddckCKDestBlt);
1945 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1947 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1949 &DDSD->ddckCKSrcOverlay);
1951 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1953 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1955 &DDSD->ddckCKSrcBlt);
1957 if (DDSD->dwFlags & DDSD_LPSURFACE)
1959 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
1960 if(hr != WINED3D_OK)
1962 /* No need for a trace here, wined3d does that for us */
1967 This->surface_desc = *DDSD;
1972 /*****************************************************************************
1973 * IDirectDrawSurface7::GetPalette
1975 * Returns the IDirectDrawPalette interface of the palette currently assigned
1979 * Pal: Address to write the interface pointer to
1983 * DDERR_INVALIDPARAMS if Pal is NULL
1985 *****************************************************************************/
1986 static HRESULT WINAPI
1987 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1988 IDirectDrawPalette **Pal)
1990 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1991 IWineD3DPalette *wPal;
1993 TRACE("(%p)->(%p): Relay\n", This, Pal);
1996 return DDERR_INVALIDPARAMS;
1998 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1999 if(hr != DD_OK) return hr;
2003 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2008 hr = DDERR_NOPALETTEATTACHED;
2014 /*****************************************************************************
2015 * IDirectDrawSurface7::SetColorKey
2017 * Sets the color keying options for the surface. Observations showed that
2018 * in case of complex surfaces the color key has to be assigned to all
2023 * CKey: The new color key
2027 * See IWineD3DSurface::SetColorKey for details
2029 *****************************************************************************/
2030 static HRESULT WINAPI
2031 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2035 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2036 IDirectDrawSurfaceImpl *surf;
2038 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2040 for(surf = This->first_complex; surf; surf = surf->next_complex)
2042 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
2047 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08x\n",
2048 surf->WineD3DSurface, hr);
2055 /*****************************************************************************
2056 * IDirectDrawSurface7::SetPalette
2058 * Assigns a DirectDrawPalette object to the surface
2061 * Pal: Interface to the palette to set
2066 *****************************************************************************/
2067 static HRESULT WINAPI
2068 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2069 IDirectDrawPalette *Pal)
2071 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2072 IDirectDrawPalette *oldPal;
2073 IDirectDrawSurfaceImpl *surf;
2074 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2076 TRACE("(%p)->(%p)\n", This, Pal);
2078 /* Find the old palette */
2079 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2080 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED) return hr;
2081 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2083 /* Set the new Palette */
2084 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2085 PalImpl ? PalImpl->wineD3DPalette : NULL);
2086 /* AddRef the Palette */
2087 if(Pal) IDirectDrawPalette_AddRef(Pal);
2089 /* Release the old palette */
2090 if(oldPal) IDirectDrawPalette_Release(oldPal);
2092 /* If this is a front buffer, also update the back buffers */
2093 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2095 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2097 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2105 /*****************************************************************************
2107 *****************************************************************************/
2109 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2112 IDirectDrawSurfaceImpl_QueryInterface,
2113 IDirectDrawSurfaceImpl_AddRef,
2114 IDirectDrawSurfaceImpl_Release,
2115 /*** IDirectDrawSurface ***/
2116 IDirectDrawSurfaceImpl_AddAttachedSurface,
2117 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2118 IDirectDrawSurfaceImpl_Blt,
2119 IDirectDrawSurfaceImpl_BltBatch,
2120 IDirectDrawSurfaceImpl_BltFast,
2121 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2122 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2123 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2124 IDirectDrawSurfaceImpl_Flip,
2125 IDirectDrawSurfaceImpl_GetAttachedSurface,
2126 IDirectDrawSurfaceImpl_GetBltStatus,
2127 IDirectDrawSurfaceImpl_GetCaps,
2128 IDirectDrawSurfaceImpl_GetClipper,
2129 IDirectDrawSurfaceImpl_GetColorKey,
2130 IDirectDrawSurfaceImpl_GetDC,
2131 IDirectDrawSurfaceImpl_GetFlipStatus,
2132 IDirectDrawSurfaceImpl_GetOverlayPosition,
2133 IDirectDrawSurfaceImpl_GetPalette,
2134 IDirectDrawSurfaceImpl_GetPixelFormat,
2135 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2136 IDirectDrawSurfaceImpl_Initialize,
2137 IDirectDrawSurfaceImpl_IsLost,
2138 IDirectDrawSurfaceImpl_Lock,
2139 IDirectDrawSurfaceImpl_ReleaseDC,
2140 IDirectDrawSurfaceImpl_Restore,
2141 IDirectDrawSurfaceImpl_SetClipper,
2142 IDirectDrawSurfaceImpl_SetColorKey,
2143 IDirectDrawSurfaceImpl_SetOverlayPosition,
2144 IDirectDrawSurfaceImpl_SetPalette,
2145 IDirectDrawSurfaceImpl_Unlock,
2146 IDirectDrawSurfaceImpl_UpdateOverlay,
2147 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2148 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2149 /*** IDirectDrawSurface2 ***/
2150 IDirectDrawSurfaceImpl_GetDDInterface,
2151 IDirectDrawSurfaceImpl_PageLock,
2152 IDirectDrawSurfaceImpl_PageUnlock,
2153 /*** IDirectDrawSurface3 ***/
2154 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2155 /*** IDirectDrawSurface4 ***/
2156 IDirectDrawSurfaceImpl_SetPrivateData,
2157 IDirectDrawSurfaceImpl_GetPrivateData,
2158 IDirectDrawSurfaceImpl_FreePrivateData,
2159 IDirectDrawSurfaceImpl_GetUniquenessValue,
2160 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2161 /*** IDirectDrawSurface7 ***/
2162 IDirectDrawSurfaceImpl_SetPriority,
2163 IDirectDrawSurfaceImpl_GetPriority,
2164 IDirectDrawSurfaceImpl_SetLOD,
2165 IDirectDrawSurfaceImpl_GetLOD