1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
8 * This file contains the (internal) driver registration functions,
9 * driver enumeration APIs and DirectDraw creation functions.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/port.h"
35 #define NONAMELESSUNION
42 #include "wine/exception.h"
48 #include "ddraw_private.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
53 /*****************************************************************************
54 * IUnknown parts follow
55 *****************************************************************************/
57 /*****************************************************************************
58 * IDirectDrawSurface7::QueryInterface
60 * A normal QueryInterface implementation. For QueryInterface rules
61 * see ddraw.c, IDirectDraw7::QueryInterface. This method
62 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
63 * in all versions, the IDirectDrawGammaControl interface and it can
64 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
67 * riid: The interface id queried for
68 * obj: Address to write the pointer to
72 * E_NOINTERFACE if the requested interface wasn't found
74 *****************************************************************************/
76 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
80 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
82 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
86 return DDERR_INVALIDPARAMS;
88 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
89 if (IsEqualGUID(riid, &IID_IUnknown)
90 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
91 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
93 IUnknown_AddRef(iface);
94 *obj = ICOM_INTERFACE(This, IDirectDrawSurface7);
95 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
98 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
99 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
100 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
102 IUnknown_AddRef(iface);
103 *obj = ICOM_INTERFACE(This, IDirectDrawSurface3);
104 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
107 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
109 IUnknown_AddRef(iface);
110 *obj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
111 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
114 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
115 IsEqualGUID(riid, &IID_IDirect3DHALDevice) )
117 IDirect3DDevice7 *d3d;
119 /* Call into IDirect3D7 for creation */
120 IDirect3D7_CreateDevice(ICOM_INTERFACE(This->ddraw, IDirect3D7),
122 ICOM_INTERFACE(This, IDirectDrawSurface7),
125 *obj = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice, d3d);
126 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
130 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
131 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
133 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
135 *obj = ICOM_INTERFACE(This, IDirect3DTexture);
136 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
140 *obj = ICOM_INTERFACE(This, IDirect3DTexture2);
141 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
143 IUnknown_AddRef( (IUnknown *) *obj);
147 ERR("No interface\n");
148 return E_NOINTERFACE;
151 /*****************************************************************************
152 * IDirectDrawSurface7::AddRef
154 * A normal addref implementation
159 *****************************************************************************/
161 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
163 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
164 ULONG refCount = InterlockedIncrement(&This->ref);
166 TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1);
170 /*****************************************************************************
171 * IDirectDrawSurfaceImpl_Destroy
173 * A helper function for IDirectDrawSurface7::Release
175 * Frees the surface, regardless of its refcount.
176 * See IDirectDrawSurface7::Release for more information
179 * This: Surface to free
181 *****************************************************************************/
182 static void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
184 TRACE("(%p)\n", This);
186 /* Check the refcount and give a warning */
189 /* This can happen when a complex surface is destroyed,
190 * because the 2nd surface was addref()ed when the app
191 * called GetAttachedSurface
193 WARN("(%p): Destroying surface with refount %ld\n", This, This->ref);
196 /* Check for attached surfaces and detach them */
197 if(This->first_attached != This)
199 /* Well, this shouldn't happen: The surface being attached is addref()ed
200 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
201 * is called, because the refcount is held. It looks like the app released()
202 * it often enough to force this
204 IDirectDrawSurface7 *root = ICOM_INTERFACE(This->first_attached, IDirectDrawSurface7);
205 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This, IDirectDrawSurface7);
207 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
209 /* The refcount will drop to -1 here */
210 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
212 ERR("(%p) DeleteAttachedSurface failed!\n", This);
216 while(This->next_attached != NULL)
218 IDirectDrawSurface7 *root = ICOM_INTERFACE(This, IDirectDrawSurface7);
219 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This->next_attached, IDirectDrawSurface7);
221 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
223 ERR("(%p) DeleteAttachedSurface failed!\n", This);
228 /* Now destroy the surface. Wait: It could have been released if we are a texture */
229 if(This->WineD3DSurface)
230 IWineD3DSurface_Release(This->WineD3DSurface);
232 /* Having a texture handle set implies that the device still exists */
235 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
236 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
239 /* Reduce the ddraw surface count */
240 InterlockedDecrement(&This->ddraw->surfaces);
242 This->prev->next = This->next;
245 assert(This->ddraw->surface_list == This);
246 This->ddraw->surface_list = This->next;
249 This->next->prev = This->prev;
251 HeapFree(GetProcessHeap(), 0, This);
254 /*****************************************************************************
255 * IDirectDrawSurface7::Release
257 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
258 * surface is destroyed.
260 * Destroying the surface is a bit tricky. For the connection between
261 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
262 * It has a nice graph explaining the connection.
264 * What happens here is basically this:
265 * When a surface is destroyed, its WineD3DSurface is released,
266 * and the refcount of the DirectDraw interface is reduced by 1. If it has
267 * complex surfaces attached to it, then these surfaces are destroyed too,
268 * regardless of their refcount. If any surface being destroyed has another
269 * surface attached to it (with a "soft" attachment, not complex), then
270 * this surface is detached with DeleteAttachedSurface.
272 * When the surface is a texture, the WineD3DTexture is released.
273 * If the surface is the Direct3D render target, then the D3D
274 * capabilities of the WineD3DDevice are uninitialized, which causes the
275 * swapchain to be released.
280 *****************************************************************************/
282 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
284 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
286 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
287 ref = InterlockedDecrement(&This->ref);
292 IDirectDrawSurfaceImpl *surf;
293 IDirectDrawImpl *ddraw;
295 /* Destroy all complex attached surfaces
296 * Therefore, start with the first surface,
297 * except for textures. Not entirely sure what has
298 * to happen exactly in this case
300 if( (This->first_complex != This) && !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE))
302 FIXME("(%p) Destroying a surface which is a attached to a complex root %p\n", This, This->first_complex);
306 /* If it's a texture, destroy the WineD3DTexture.
307 * WineD3D will destroy the IParent interfaces
308 * of the sublevels, which destroys the WineD3DSurfaces.
309 * Set the surfaces to NULL to avoid destroying them again later
311 if(This->wineD3DTexture)
313 IWineD3DTexture_Release(This->wineD3DTexture);
315 /* If it's the RenderTarget, destroy the d3ddevice */
316 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
318 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
320 /* Unset any index buffer, just to be sure */
321 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, 0);
323 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
326 ERR("(%p) Failed to uninit 3D\n", This);
330 /* Free the d3d window if one was created */
331 if(ddraw->d3d_window != 0)
333 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
334 DestroyWindow(ddraw->d3d_window);
335 ddraw->d3d_window = 0;
337 /* Unset the pointers */
340 ddraw->d3d_initialized = FALSE;
341 ddraw->d3d_target = NULL;
343 /* Write a trace because D3D unloading was the reason for many
344 * crashes during development.
346 TRACE("(%p) D3D unloaded\n", This);
348 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
352 /* It's a render target, but no swapchain was created.
353 * The IParent interfaces have to be released manually.
354 * The same applies for textures without an
355 * IWineD3DTexture object attached
362 IWineD3DSurface_GetParent(surf->WineD3DSurface,
363 (IUnknown **) &Parent);
364 IParent_Release(Parent); /* For the getParent */
365 IParent_Release(Parent); /* To release it */
366 surf = surf->next_complex;
370 /* The refcount test shows that the palette is detached when the surface is destroyed */
371 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
374 /* Loop through all complex attached surfaces,
377 while( (surf = This->next_complex) )
379 This->next_complex = surf->next_complex; /* Unchain it from the complex listing */
380 IDirectDrawSurfaceImpl_Destroy(surf); /* Destroy it */
383 /* Destroy the surface.
385 IDirectDrawSurfaceImpl_Destroy(This);
387 /* Reduce the ddraw refcount */
388 IDirectDraw7_Release(ICOM_INTERFACE(ddraw, IDirectDraw7));
394 /*****************************************************************************
395 * IDirectDrawSurface7::GetAttachedSurface
397 * Returns an attached surface with the requested caps. Surface attachment
398 * and complex surfaces are not clearly described by the MSDN or sdk,
399 * so this method is tricky and likely to contain problems.
400 * This implementation searches the complex chain first, then the
401 * attachment chain, and then it checks if the caps match to itself.
403 * The chains are searched from This down to the last surface in the chain,
404 * not from the first element in the chain. The first surface found is
405 * returned. The MSDN says that this method fails if more than one surface
406 * matches the caps, but apparently this is incorrect.
408 * The found surface is AddRef-ed before it is returned.
411 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
412 * Surface: Address to store the found surface
416 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
417 * DDERR_NOTFOUND if no surface was found
419 *****************************************************************************/
420 static HRESULT WINAPI
421 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
423 IDirectDrawSurface7 **Surface)
425 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
426 IDirectDrawSurfaceImpl *surf;
429 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
433 if(This->version < 7)
435 /* Earlier dx apps put garbage into these members, clear them */
436 our_caps.dwCaps2 = 0;
437 our_caps.dwCaps3 = 0;
438 our_caps.dwCaps4 = 0;
441 TRACE("(%p): Looking for caps: %lx,%lx,%lx,%lx\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.dwCaps4); /* FIXME: Better debugging */
443 /* First, look at the complex chain */
446 while( (surf = surf->next_complex) )
450 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx\n", surf,
451 surf->surface_desc.ddsCaps.dwCaps,
452 surf->surface_desc.ddsCaps.dwCaps2,
453 surf->surface_desc.ddsCaps.dwCaps3,
454 surf->surface_desc.ddsCaps.dwCaps4);
457 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
458 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
460 /* MSDN: "This method fails if more than one surface is attached
461 * that matches the capabilities requested."
463 * The mipmap demo of the DirectX7 sdk shows what to do here:
464 * apparently apps expect the first found surface to be returned.
467 TRACE("(%p): Returning surface %p\n", This, surf);
468 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
469 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
470 IDirectDrawSurface7_AddRef(*Surface);
475 /* Next, look at the attachment chain */
478 while( (surf = surf->next_attached) )
482 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx\n", surf,
483 surf->surface_desc.ddsCaps.dwCaps,
484 surf->surface_desc.ddsCaps.dwCaps2,
485 surf->surface_desc.ddsCaps.dwCaps3,
486 surf->surface_desc.ddsCaps.dwCaps4);
489 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
490 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
492 /* MSDN: "This method fails if more than one surface is attached
493 * that matches the capabilities requested."
495 * The mipmap demo of the DirectX7 sdk shows what to do here:
496 * apparently apps expect the first found surface to be returned.
499 TRACE("(%p): Returning surface %p\n", This, surf);
500 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
501 IDirectDrawSurface7_AddRef(*Surface);
508 if (((This->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
509 ((This->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2) &&
510 This == This->first_complex)
513 TRACE("(%p): Returning surface %p\n", This, This);
514 *Surface = ICOM_INTERFACE(This, IDirectDrawSurface7);
515 IDirectDrawSurface7_AddRef(*Surface);
520 /* What to do here? Continue with the surface root?? */
522 TRACE("(%p) Didn't find a valid surface\n", This);
523 return DDERR_NOTFOUND;
526 /*****************************************************************************
527 * IDirectDrawSurface7::Lock
529 * Locks the surface and returns a pointer to the surface's memory
532 * Rect: Rectangle to lock. If NULL, the whole surface is locked
533 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
534 * Flags: Locking flags, e.g Read only or write only
535 * h: An event handle that's not used and must be NULL
539 * DDERR_INVALIDPARAMS if DDSD is NULL
540 * For more details, see IWineD3DSurface::LockRect
542 *****************************************************************************/
543 static HRESULT WINAPI
544 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
546 DDSURFACEDESC2 *DDSD,
550 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
551 WINED3DLOCKED_RECT LockedRect;
553 TRACE("(%p)->(%p,%p,%lx,%p)\n", This, Rect, DDSD, Flags, h);
556 return DDERR_INVALIDPARAMS;
558 /* Should I check for the handle to be NULL?
560 * The DDLOCK flags and the D3DLOCK flags are equal
561 * for the supported values. The others are ignored by WineD3D
564 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
565 * that means it doesn't have dwSize set. Init it to some sane
568 if(DDSD->dwSize <= sizeof(DDSURFACEDESC))
570 DDSD->dwSize = sizeof(DDSURFACEDESC);
574 DDSD->dwSize = sizeof(DDSURFACEDESC2);
577 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
578 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
582 if(hr != D3D_OK) return hr;
584 /* Override the memory area and the pitch */
585 DDSD->dwFlags |= DDSD_LPSURFACE;
586 DDSD->lpSurface = LockedRect.pBits;
587 DDSD->dwFlags |= DDSD_PITCH;
588 DDSD->u1.lPitch = LockedRect.Pitch;
590 TRACE("locked surface returning description :\n");
591 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
596 /*****************************************************************************
597 * IDirectDrawSurface7::Unlock
599 * Unlocks an locked surface
602 * Rect: Not used by this implementation
606 * For more details, see IWineD3DSurface::UnlockRect
608 *****************************************************************************/
609 static HRESULT WINAPI
610 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
613 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
614 TRACE("(%p)->(%p)\n", This, pRect);
616 return IWineD3DSurface_UnlockRect(This->WineD3DSurface);
619 /*****************************************************************************
620 * IDirectDrawSurface7::Flip
622 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
623 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
624 * the flip target is passed to WineD3D, even if the app didn't specify one
627 * DestOverride: Specifies the surface that will become the new front
628 * buffer. If NULL, the current back buffer is used
629 * Flags: some DirectDraw flags, see include/ddraw.h
633 * DDERR_NOTFLIPPABLE if no flip target could be found
634 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
635 * For more details, see IWineD3DSurface::Flip
637 *****************************************************************************/
638 static HRESULT WINAPI
639 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
640 IDirectDrawSurface7 *DestOverride,
643 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
644 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
645 IDirectDrawSurface7 *Override7;
647 TRACE("(%p)->(%p,%lx)\n", This, DestOverride, Flags);
649 /* Flip has to be called from a front buffer
650 * What about overlay surfaces, AFAIK they can flip too?
652 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
653 return DDERR_INVALIDOBJECT; /* Unckecked */
655 /* WineD3D doesn't keep track of attached surface, so find the target */
660 memset(&Caps, 0, sizeof(Caps));
661 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
662 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
665 ERR("Can't find a flip target\n");
666 return DDERR_NOTFLIPPABLE; /* Unchecked */
668 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
670 /* For the GetAttachedSurface */
671 IDirectDrawSurface7_Release(Override7);
674 return IWineD3DSurface_Flip(This->WineD3DSurface,
675 Override->WineD3DSurface,
679 /*****************************************************************************
680 * IDirectDrawSurface7::Blt
682 * Performs a blit on the surface
685 * DestRect: Destination rectangle, can be NULL
686 * SrcSurface: Source surface, can be NULL
687 * SrcRect: Source rectange, can be NULL
689 * DDBltFx: Some extended blt parameters, connected to the flags
693 * See IWineD3DSurface::Blt for more details
695 *****************************************************************************/
696 static HRESULT WINAPI
697 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
699 IDirectDrawSurface7 *SrcSurface,
704 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
705 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
706 TRACE("(%p)->(%p,%p,%p,%lx,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
708 return IWineD3DSurface_Blt(This->WineD3DSurface,
710 Src ? Src->WineD3DSurface : NULL,
716 /*****************************************************************************
717 * IDirectDrawSurface7::AddAttachedSurface
719 * Attaches a surface to another surface. Surface attachments are
720 * incorrectly described in the SDK and the MSDN, and this method
721 * is prone to bugs. The surface that is attached is AddRef-ed.
723 * The attachment list consists of a first surface (first_attached) and
724 * for each surface a pointer to the next attached surface (next_attached).
725 * For the first surface, and a surface that has no attachments
726 * first_attached points to the surface itself. A surface that has
727 * no successors in the chain has next_attached set to NULL.
729 * Newly attached surfaces are attached right after the root surface. The
730 * complex chains are handled separately in a similar chain, with
731 * first_complex and next_complex. If a surface is attached to a complex
732 * surface compound, it's attached to the surface that the app requested,
733 * not the complex root. See GetAttachedSurface for a description
734 * how surfaces are found.
736 * This is how the current implementation works, and it was coded by looking
737 * at the needs of the applications.
739 * So far only Z-Buffer attachments are tested, but there's no code yet
740 * to activate them. Mipmaps could be tricky to activate in WineD3D.
741 * Back buffers should work in 2D mode, but they are not tested.
742 * Rendering to the primary surface and switching between that and
743 * double buffering is not yet implemented in WineD3D, so for 3D it might
744 * have unexpected results.
747 * Attach: Surface to attach to iface
751 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
753 *****************************************************************************/
754 static HRESULT WINAPI
755 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
756 IDirectDrawSurface7 *Attach)
758 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
759 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
760 TRACE("(%p)->(%p)\n", This, Surf);
762 /* Should I make sure to add it to the first complex surface? */
765 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
767 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
768 * But apparently backbuffers and mipmaps can be attached too. */
770 /* Set MIPMAPSUBLEVEL if this seems to be one */
771 if (This->surface_desc.ddsCaps.dwCaps &
772 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
774 Surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
775 /* FIXME: we should probably also add to dwMipMapCount of this
776 * and all parent surfaces (update create_texture if you do) */
779 /* Check if the surface is already attached somewhere */
780 if( (Surf->next_attached != NULL) ||
781 (Surf->first_attached != Surf) )
783 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);
784 return DDERR_CANNOTATTACHSURFACE;
787 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
788 Surf->next_attached = This->next_attached;
789 Surf->first_attached = This->first_attached;
790 This->next_attached = Surf;
793 * "This method increments the reference count of the surface being attached."
795 IDirectDrawSurface7_AddRef(Attach);
799 /*****************************************************************************
800 * IDirectDrawSurface7::DeleteAttachedSurface
802 * Removes a surface from the attachment chain. The surface's refcount
803 * is decreased by one after it has been removed
806 * Flags: Some flags, not used by this implementation
807 * Attach: Surface to detach
811 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
813 *****************************************************************************/
814 static HRESULT WINAPI
815 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
817 IDirectDrawSurface7 *Attach)
819 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
820 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
821 IDirectDrawSurfaceImpl *Prev = This;
822 TRACE("(%p)->(%08lx,%p)\n", This, Flags, Surf);
824 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
825 return DDERR_SURFACENOTATTACHED; /* unchecked */
827 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
828 if (This->surface_desc.ddsCaps.dwCaps &
829 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
831 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
832 /* FIXME: we should probably also subtract from dwMipMapCount of this
833 * and all parent surfaces */
836 /* Find the predecessor of the detached surface */
839 if(Prev->next_attached == Surf) break;
840 Prev = Prev->next_attached;
843 /* There must be a surface, otherwise there's a bug */
844 assert(Prev != NULL);
846 /* Unchain the surface */
847 Prev->next_attached = Surf->next_attached;
848 Surf->next_attached = NULL;
849 Surf->first_attached = Surf;
851 IDirectDrawSurface7_Release(Attach);
855 /*****************************************************************************
856 * IDirectDrawSurface7::AddOverlayDirtyRect
858 * "This method is not currently implemented"
866 *****************************************************************************/
867 static HRESULT WINAPI
868 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
871 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
872 TRACE("(%p)->(%p)\n",This,Rect);
874 /* MSDN says it's not implemented. I could forward it to WineD3D,
875 * then we'd implement it, but I don't think that's a good idea
879 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
881 return DDERR_UNSUPPORTED; /* unchecked */
884 /*****************************************************************************
885 * IDirectDrawSurface7::GetDC
887 * Returns a GDI device context for the surface
890 * hdc: Address of a HDC variable to store the dc to
894 * DDERR_INVALIDPARAMS if hdc is NULL
895 * For details, see IWineD3DSurface::GetDC
897 *****************************************************************************/
898 static HRESULT WINAPI
899 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
902 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
903 TRACE("(%p)->(%p): Relay\n", This, hdc);
906 return DDERR_INVALIDPARAMS;
908 return IWineD3DSurface_GetDC(This->WineD3DSurface,
912 /*****************************************************************************
913 * IDirectDrawSurface7::ReleaseDC
915 * Releases the DC that was constructed with GetDC
918 * hdc: HDC to release
922 * For more details, see IWineD3DSurface::ReleaseDC
924 *****************************************************************************/
925 static HRESULT WINAPI
926 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
929 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
930 TRACE("(%p)->(%p): Relay\n", This, hdc);
932 return IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
935 /*****************************************************************************
936 * IDirectDrawSurface7::GetCaps
938 * Returns the surface's caps
941 * Caps: Address to write the caps to
945 * DDERR_INVALIDPARAMS if Caps is NULL
947 *****************************************************************************/
948 static HRESULT WINAPI
949 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
952 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
953 TRACE("(%p)->(%p)\n",This,Caps);
956 return DDERR_INVALIDPARAMS;
958 *Caps = This->surface_desc.ddsCaps;
962 /*****************************************************************************
963 * IDirectDrawSurface7::SetPriority
965 * Sets a texture priority for managed textures.
968 * Priority: The new priority
972 * For more details, see IWineD3DSurface::SetPriority
974 *****************************************************************************/
975 static HRESULT WINAPI
976 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
978 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
979 TRACE("(%p)->(%ld): Relay!\n",This,Priority);
981 return IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
984 /*****************************************************************************
985 * IDirectDrawSurface7::GetPriority
987 * Returns the surface's priority
990 * Priority: Address of a variable to write the priority to
994 * DDERR_INVALIDPARAMS if Priority == NULL
995 * For more details, see IWineD3DSurface::GetPriority
997 *****************************************************************************/
998 static HRESULT WINAPI
999 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1002 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1003 TRACE("(%p)->(%p): Relay\n",This,Priority);
1006 return DDERR_INVALIDPARAMS;
1008 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1012 /*****************************************************************************
1013 * IDirectDrawSurface7::SetPrivateData
1015 * Stores some data in the surface that is intended for the application's
1019 * tag: GUID that identifies the data
1020 * Data: Pointer to the private data
1021 * Size: Size of the private data
1026 * For more details, see IWineD3DSurface::SetPrivateData
1028 *****************************************************************************/
1029 static HRESULT WINAPI
1030 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1036 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1037 TRACE("(%p)->(%s,%p,%ld,%lx): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1039 return IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1046 /*****************************************************************************
1047 * IDirectDrawSurface7::GetPrivateData
1049 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1052 * tag: GUID of the data to return
1053 * Data: Address where to write the data to
1054 * Size: Size of the buffer at Data
1058 * DDERR_INVALIDPARAMS if Data is NULL
1059 * For more details, see IWineD3DSurface::GetPrivateData
1061 *****************************************************************************/
1062 static HRESULT WINAPI
1063 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1068 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1069 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1072 return DDERR_INVALIDPARAMS;
1074 return IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1080 /*****************************************************************************
1081 * IDirectDrawSurface7::FreePrivateData
1083 * Frees private data stored in the surface
1086 * tag: Tag of the data to free
1090 * For more details, see IWineD3DSurface::FreePrivateData
1092 *****************************************************************************/
1093 static HRESULT WINAPI
1094 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1097 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1098 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1100 return IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1103 /*****************************************************************************
1104 * IDirectDrawSurface7::PageLock
1106 * Prevents a sysmem surface from being paged out
1109 * Flags: Not used, must be 0(unchecked)
1112 * DD_OK, because it's a stub
1114 *****************************************************************************/
1115 static HRESULT WINAPI
1116 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1119 TRACE("(%p)->(%lx)\n", iface, Flags);
1121 /* This is Windows memory management related - we don't need this */
1125 /*****************************************************************************
1126 * IDirectDrawSurface7::PageUnlock
1128 * Allows a sysmem surface to be paged out
1131 * Flags: Not used, must be 0(unckeched)
1134 * DD_OK, because it's a stub
1136 *****************************************************************************/
1137 static HRESULT WINAPI
1138 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1141 TRACE("(%p)->(%lx)\n", iface, Flags);
1146 /*****************************************************************************
1147 * IDirectDrawSurface7::BltBatch
1149 * An unimplemented function
1157 *****************************************************************************/
1158 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1160 TRACE("(%p)->(%p,%ld,%08lx)\n",iface,Batch,Count,Flags);
1162 /* MSDN: "not currently implemented" */
1163 return DDERR_UNSUPPORTED;
1166 /*****************************************************************************
1167 * IDirectDrawSurface7::EnumAttachedSurfaces
1169 * Enumerates all surfaces attached to this surface
1172 * context: Pointer to pass unmodified to the callback
1173 * cb: Callback function to call for each surface
1177 * DDERR_INVALIDPARAMS if cb is NULL
1179 *****************************************************************************/
1180 static HRESULT WINAPI
1181 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1183 LPDDENUMSURFACESCALLBACK7 cb)
1185 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1186 IDirectDrawSurfaceImpl *surf;
1187 DDSURFACEDESC2 desc;
1189 /* Attached surfaces aren't handled in WineD3D */
1190 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1193 return DDERR_INVALIDPARAMS;
1195 for (surf = This->next_complex; surf != NULL; surf = surf->next_complex)
1197 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1198 desc = surf->surface_desc;
1199 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1200 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1204 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1206 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1207 desc = surf->surface_desc;
1208 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1209 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1213 TRACE(" end of enumeration.\n");
1218 /*****************************************************************************
1219 * IDirectDrawSurface7::EnumOverlayZOrders
1221 * "Enumerates the overlay surfaces on the specified destination"
1224 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1225 * context: context to pass back to the callback
1226 * cb: callback function to call for each enumerated surface
1229 * DD_OK, because it's a stub
1231 *****************************************************************************/
1232 static HRESULT WINAPI
1233 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1236 LPDDENUMSURFACESCALLBACK7 cb)
1238 FIXME("(%p)->(%lx,%p,%p): Stub!\n", iface, Flags, context, cb);
1243 /*****************************************************************************
1244 * IDirectDrawSurface7::GetBltStatus
1246 * Returns the blitting status
1249 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1252 * See IWineD3DSurface::Blt
1254 *****************************************************************************/
1255 static HRESULT WINAPI
1256 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1259 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1260 TRACE("(%p)->(%lx): Relay\n", This, Flags);
1262 return IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1265 /*****************************************************************************
1266 * IDirectDrawSurface7::GetColorKey
1268 * Returns the color key assigned to the surface
1272 * CKey: Address to store the key to
1276 * DDERR_INVALIDPARAMS if CKey is NULL
1278 *****************************************************************************/
1279 static HRESULT WINAPI
1280 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1284 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1285 * isn't there? That's like saying that an int isn't there. (Which MS
1286 * has done in other docs.) */
1288 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1291 return DDERR_INVALIDPARAMS;
1295 case DDCKEY_DESTBLT:
1296 *CKey = This->surface_desc.ddckCKDestBlt;
1299 case DDCKEY_DESTOVERLAY:
1300 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1304 *CKey = This->surface_desc.ddckCKSrcBlt;
1307 case DDCKEY_SRCOVERLAY:
1308 *CKey = This->surface_desc.ddckCKSrcOverlay;
1312 return DDERR_INVALIDPARAMS;
1318 /*****************************************************************************
1319 * IDirectDrawSurface7::GetFlipStatus
1321 * Returns the flipping status of the surface
1324 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1327 * See IWineD3DSurface::GetFlipStatus
1329 *****************************************************************************/
1330 static HRESULT WINAPI
1331 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1334 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1335 TRACE("(%p)->(%lx): Relay\n", This, Flags);
1337 return IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1340 /*****************************************************************************
1341 * IDirectDrawSurface7::GetOverlayPosition
1343 * Returns the display coordinates of a visible and active overlay surface
1350 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1351 *****************************************************************************/
1352 static HRESULT WINAPI
1353 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1356 FIXME("(%p)->(%p,%p): Stub!\n", iface, X, Y);
1358 return DDERR_NOTAOVERLAYSURFACE;
1361 /*****************************************************************************
1362 * IDirectDrawSurface7::GetPixelFormat
1364 * Returns the pixel format of the Surface
1367 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1368 * format should be written
1372 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1374 *****************************************************************************/
1375 static HRESULT WINAPI
1376 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1377 DDPIXELFORMAT *PixelFormat)
1379 /* What is DDERR_INVALIDSURFACETYPE for here? */
1380 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1381 TRACE("(%p)->(%p)\n",This,PixelFormat);
1384 return DDERR_INVALIDPARAMS;
1386 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1392 /*****************************************************************************
1393 * IDirectDrawSurface7::GetSurfaceDesc
1395 * Returns the description of this surface
1398 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1403 * DDERR_INVALIDPARAMS if DDSD is NULL
1405 *****************************************************************************/
1406 static HRESULT WINAPI
1407 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1408 DDSURFACEDESC2 *DDSD)
1410 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1412 TRACE("(%p)->(%p)\n",This,DDSD);
1415 return DDERR_INVALIDPARAMS;
1417 if ((DDSD->dwSize < sizeof(DDSURFACEDESC)) ||
1418 (DDSD->dwSize > sizeof(DDSURFACEDESC2)))
1420 ERR("Impossible/Strange struct size %ld.\n",DDSD->dwSize);
1421 return DDERR_GENERIC;
1424 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1425 TRACE("Returning surface desc:\n");
1426 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1431 /*****************************************************************************
1432 * IDirectDrawSurface7::Initialize
1434 * Initializes the surface. This is a no-op in Wine
1437 * DD: Pointer to an DirectDraw interface
1438 * DDSD: Surface description for initialization
1441 * DDERR_ALREADYINITIALIZED
1443 *****************************************************************************/
1444 static HRESULT WINAPI
1445 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1447 DDSURFACEDESC2 *DDSD)
1449 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1450 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1451 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1453 return DDERR_ALREADYINITIALIZED;
1456 /*****************************************************************************
1457 * IDirectDrawSurface7::IsLost
1459 * Checks if the surface is lost
1462 * DD_OK, if the surface is useable
1463 * DDERR_ISLOST if the surface is lost
1464 * See IWineD3DSurface::IsLost for more details
1466 *****************************************************************************/
1467 static HRESULT WINAPI
1468 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1470 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1471 TRACE("(%p)\n", This);
1473 /* We lose the surface if the implementation was changed */
1474 if(This->ImplType != This->ddraw->ImplType)
1476 /* But this shouldn't happen. When we change the implementation,
1477 * all surfaces are re-created automatically, and their content
1480 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1481 return DDERR_SURFACELOST;
1484 return IWineD3DSurface_IsLost(This->WineD3DSurface);
1487 /*****************************************************************************
1488 * IDirectDrawSurface7::Restore
1490 * Restores a lost surface. This makes the surface usable again, but
1491 * doesn't reload its old contents
1495 * See IWineD3DSurface::Restore for more details
1497 *****************************************************************************/
1498 static HRESULT WINAPI
1499 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1501 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1502 TRACE("(%p)\n", This);
1504 if(This->ImplType != This->ddraw->ImplType)
1506 /* Call the recreation callback. Make sure to AddRef first */
1507 IDirectDrawSurface_AddRef(iface);
1508 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1509 &This->surface_desc,
1510 NULL /* Not needed */);
1512 return IWineD3DSurface_Restore(This->WineD3DSurface);
1515 /*****************************************************************************
1516 * IDirectDrawSurface7::SetOverlayPosition
1518 * Changes the display coordinates of an overlay surface
1525 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1526 *****************************************************************************/
1527 static HRESULT WINAPI
1528 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1532 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1533 FIXME("(%p)->(%ld,%ld): Stub!\n", This, X, Y);
1534 return DDERR_NOTAOVERLAYSURFACE;
1537 /*****************************************************************************
1538 * IDirectDrawSurface7::UpdateOverlay
1540 * Modifies the attributes of an overlay surface.
1543 * SrcRect: The section of the source being used for the overlay
1544 * DstSurface: Address of the surface that is overlaid
1545 * DstRect: Place of the overlay
1546 * Flags: some DDOVER_* flags
1549 * DDERR_UNSUPPORTED, because we don't support overlays
1551 *****************************************************************************/
1552 static HRESULT WINAPI
1553 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1555 IDirectDrawSurface7 *DstSurface,
1560 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1561 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1562 FIXME("(%p)->(%p,%p,%p,%lx,%p): Stub!\n", This, SrcRect, Dst, DstRect, Flags, FX);
1563 return DDERR_UNSUPPORTED;
1566 /*****************************************************************************
1567 * IDirectDrawSurface7::UpdateOverlayDisplay
1569 * The DX7 sdk says that it's not implemented
1574 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1576 *****************************************************************************/
1577 static HRESULT WINAPI
1578 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1581 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1582 TRACE("(%p)->(%lx)\n", This, Flags);
1583 return DDERR_UNSUPPORTED;
1586 /*****************************************************************************
1587 * IDirectDrawSurface7::UpdateOverlayZOrder
1589 * Sets an overlay's Z order
1592 * Flags: DDOVERZ_* flags
1593 * DDSRef: Defines the relative position in the overlay chain
1596 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1598 *****************************************************************************/
1599 static HRESULT WINAPI
1600 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1602 IDirectDrawSurface7 *DDSRef)
1604 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1605 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1606 FIXME("(%p)->(%lx,%p)\n", This, Flags, Ref);
1607 return DDERR_NOTAOVERLAYSURFACE;
1610 /*****************************************************************************
1611 * IDirectDrawSurface7::GetDDInterface
1613 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1614 * surface belongs to
1617 * DD: Address to write the interface pointer to
1621 * DDERR_INVALIDPARAMS if DD is NULL
1623 *****************************************************************************/
1624 static HRESULT WINAPI
1625 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1628 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1630 TRACE("(%p)->(%p)\n",This,DD);
1633 return DDERR_INVALIDPARAMS;
1635 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1636 IDirectDraw7_AddRef( (IDirectDraw7 *) *DD);
1641 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1642 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1644 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1645 volatile IDirectDrawSurfaceImpl* vThis = This;
1647 TRACE("(%p)\n",This);
1648 /* A uniqueness value of 0 is apparently special.
1649 * This needs to be checked. */
1651 DWORD old_uniqueness_value = vThis->uniqueness_value;
1652 DWORD new_uniqueness_value = old_uniqueness_value+1;
1654 if (old_uniqueness_value == 0) break;
1655 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1657 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1658 old_uniqueness_value,
1659 new_uniqueness_value)
1660 == old_uniqueness_value)
1667 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1669 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1671 TRACE("(%p)->(%p)\n",This,pValue);
1672 *pValue = This->uniqueness_value;
1676 /*****************************************************************************
1677 * IDirectDrawSurface7::SetLOD
1679 * Sets the level of detail of a texture
1682 * MaxLOD: LOD to set
1686 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1688 *****************************************************************************/
1689 static HRESULT WINAPI
1690 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1693 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1694 TRACE("(%p)->(%ld)\n", This, MaxLOD);
1696 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1697 return DDERR_INVALIDOBJECT;
1699 if(!This->wineD3DTexture)
1701 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1702 return DDERR_INVALIDOBJECT;
1705 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1709 /*****************************************************************************
1710 * IDirectDrawSurface7::GetLOD
1712 * Returns the level of detail of a Direct3D texture
1715 * MaxLOD: Address to write the LOD to
1719 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1720 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1722 *****************************************************************************/
1723 static HRESULT WINAPI
1724 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1727 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1728 TRACE("(%p)->(%p)\n", This, MaxLOD);
1731 return DDERR_INVALIDPARAMS;
1733 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1734 return DDERR_INVALIDOBJECT;
1736 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1740 /*****************************************************************************
1741 * IDirectDrawSurface7::BltFast
1743 * Performs a fast Blit.
1746 * dstx: The x coordinate to blit to on the destination
1747 * dsty: The y coordinate to blit to on the destination
1748 * Source: The source surface
1749 * rsrc: The source rectangle
1750 * trans: Type of transfer. Some DDBLTFAST_* flags
1754 * For more details, see IWineD3DSurface::BltFast
1756 *****************************************************************************/
1757 static HRESULT WINAPI
1758 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1761 IDirectDrawSurface7 *Source,
1765 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1766 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1767 TRACE("(%p)->(%ld,%ld,%p,%p,%ld): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1769 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1771 src ? src->WineD3DSurface : NULL,
1776 /*****************************************************************************
1777 * IDirectDrawSurface7::GetClipper
1779 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1783 * Clipper: Address to store the interface pointer at
1787 * DDERR_INVALIDPARAMS if Clipper is NULL
1788 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1790 *****************************************************************************/
1791 static HRESULT WINAPI
1792 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1793 IDirectDrawClipper **Clipper)
1795 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1796 TRACE("(%p)->(%p)\n", This, Clipper);
1799 return DDERR_INVALIDPARAMS;
1801 if(This->clipper == NULL)
1802 return DDERR_NOCLIPPERATTACHED;
1804 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1805 IDirectDrawClipper_AddRef(*Clipper);
1809 /*****************************************************************************
1810 * IDirectDrawSurface7::SetClipper
1812 * Sets a clipper for the surface
1815 * Clipper: IDirectDrawClipper interface of the clipper to set
1820 *****************************************************************************/
1821 static HRESULT WINAPI
1822 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1823 IDirectDrawClipper *Clipper)
1825 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1827 TRACE("(%p)->(%p)\n",This,Clipper);
1828 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1831 if (This->clipper != NULL)
1832 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1834 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1835 if (Clipper != NULL)
1836 IDirectDrawClipper_AddRef(Clipper);
1841 /*****************************************************************************
1842 * IDirectDrawSurface7::SetSurfaceDesc
1844 * Sets the surface description. It can override the pixel format, the surface
1846 * It's not really tested.
1849 * DDSD: Pointer to the new surface description to set
1854 * DDERR_INVALIDPARAMS if DDSD is NULL
1856 *****************************************************************************/
1857 static HRESULT WINAPI
1858 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1859 DDSURFACEDESC2 *DDSD,
1862 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1863 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1865 TRACE("(%p)->(%p,%lx)\n", This, DDSD, Flags);
1868 return DDERR_INVALIDPARAMS;
1870 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1872 ERR("Setting the surface memory isn't supported yet\n");
1873 return DDERR_INVALIDPARAMS;
1876 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1878 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1880 if(newFormat == WINED3DFMT_UNKNOWN)
1882 ERR("Requested to set an unknown pixelformat\n");
1883 return DDERR_INVALIDPARAMS;
1885 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1887 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1889 if(hr != DD_OK) return hr;
1892 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1894 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1896 &DDSD->u3.ddckCKDestOverlay);
1898 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1900 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1902 &DDSD->ddckCKDestBlt);
1904 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1906 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1908 &DDSD->ddckCKSrcOverlay);
1910 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1912 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1914 &DDSD->ddckCKSrcBlt);
1917 This->surface_desc = *DDSD;
1922 /*****************************************************************************
1923 * IDirectDrawSurface7::GetPalette
1925 * Returns the IDirectDrawPalette interface of the palette currently assigned
1929 * Pal: Address to write the interface pointer to
1933 * DDERR_INVALIDPARAMS if Pal is NULL
1935 *****************************************************************************/
1936 static HRESULT WINAPI
1937 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1938 IDirectDrawPalette **Pal)
1940 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1941 IWineD3DPalette *wPal;
1943 TRACE("(%p)->(%p): Relay\n", This, Pal);
1946 return DDERR_INVALIDPARAMS;
1948 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1949 if(hr != DD_OK) return hr;
1953 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
1963 /*****************************************************************************
1964 * IDirectDrawSurface7::SetColorKey
1966 * Sets the color keying options for the surface. Observations showed that
1967 * in case of complex surfaces the color key has to be assigned to all
1972 * CKey: The new color key
1976 * See IWineD3DSurface::SetColorKey for details
1978 *****************************************************************************/
1979 static HRESULT WINAPI
1980 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
1984 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1985 IDirectDrawSurfaceImpl *surf;
1987 TRACE("(%p)->(%lx,%p)\n", This, Flags, CKey);
1989 for(surf = This->first_complex; surf; surf = surf->next_complex)
1991 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
1996 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08lx\n",
1997 surf->WineD3DSurface, hr);
2004 /*****************************************************************************
2005 * IDirectDrawSurface7::SetPalette
2007 * Assigns a DirectDrawPalette object to the surface
2010 * Pal: Interface to the palette to set
2015 *****************************************************************************/
2016 static HRESULT WINAPI
2017 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2018 IDirectDrawPalette *Pal)
2020 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2021 IDirectDrawPalette *oldPal;
2022 IDirectDrawSurfaceImpl *surf;
2023 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2025 TRACE("(%p)->(%p)\n", This, Pal);
2027 /* Find the old palette */
2028 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2029 if(hr != DD_OK) return hr;
2030 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2032 /* Set the new Palette */
2033 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2034 PalImpl ? PalImpl->wineD3DPalette : NULL);
2035 /* AddRef the Palette */
2036 if(Pal) IDirectDrawPalette_AddRef(Pal);
2038 /* Release the old palette */
2039 if(oldPal) IDirectDrawPalette_Release(oldPal);
2041 /* If this is a front buffer, also update the back buffers */
2042 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2044 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2046 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2054 /*****************************************************************************
2056 *****************************************************************************/
2058 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2061 IDirectDrawSurfaceImpl_QueryInterface,
2062 IDirectDrawSurfaceImpl_AddRef,
2063 IDirectDrawSurfaceImpl_Release,
2064 /*** IDirectDrawSurface ***/
2065 IDirectDrawSurfaceImpl_AddAttachedSurface,
2066 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2067 IDirectDrawSurfaceImpl_Blt,
2068 IDirectDrawSurfaceImpl_BltBatch,
2069 IDirectDrawSurfaceImpl_BltFast,
2070 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2071 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2072 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2073 IDirectDrawSurfaceImpl_Flip,
2074 IDirectDrawSurfaceImpl_GetAttachedSurface,
2075 IDirectDrawSurfaceImpl_GetBltStatus,
2076 IDirectDrawSurfaceImpl_GetCaps,
2077 IDirectDrawSurfaceImpl_GetClipper,
2078 IDirectDrawSurfaceImpl_GetColorKey,
2079 IDirectDrawSurfaceImpl_GetDC,
2080 IDirectDrawSurfaceImpl_GetFlipStatus,
2081 IDirectDrawSurfaceImpl_GetOverlayPosition,
2082 IDirectDrawSurfaceImpl_GetPalette,
2083 IDirectDrawSurfaceImpl_GetPixelFormat,
2084 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2085 IDirectDrawSurfaceImpl_Initialize,
2086 IDirectDrawSurfaceImpl_IsLost,
2087 IDirectDrawSurfaceImpl_Lock,
2088 IDirectDrawSurfaceImpl_ReleaseDC,
2089 IDirectDrawSurfaceImpl_Restore,
2090 IDirectDrawSurfaceImpl_SetClipper,
2091 IDirectDrawSurfaceImpl_SetColorKey,
2092 IDirectDrawSurfaceImpl_SetOverlayPosition,
2093 IDirectDrawSurfaceImpl_SetPalette,
2094 IDirectDrawSurfaceImpl_Unlock,
2095 IDirectDrawSurfaceImpl_UpdateOverlay,
2096 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2097 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2098 /*** IDirectDrawSurface2 ***/
2099 IDirectDrawSurfaceImpl_GetDDInterface,
2100 IDirectDrawSurfaceImpl_PageLock,
2101 IDirectDrawSurfaceImpl_PageUnlock,
2102 /*** IDirectDrawSurface3 ***/
2103 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2104 /*** IDirectDrawSurface4 ***/
2105 IDirectDrawSurfaceImpl_SetPrivateData,
2106 IDirectDrawSurfaceImpl_GetPrivateData,
2107 IDirectDrawSurfaceImpl_FreePrivateData,
2108 IDirectDrawSurfaceImpl_GetUniquenessValue,
2109 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2110 /*** IDirectDrawSurface7 ***/
2111 IDirectDrawSurfaceImpl_SetPriority,
2112 IDirectDrawSurfaceImpl_GetPriority,
2113 IDirectDrawSurfaceImpl_SetLOD,
2114 IDirectDrawSurfaceImpl_GetLOD