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.
269 * When a complex sublevel falls to ref zero, then this is ignored.
274 *****************************************************************************/
276 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7
*iface
)
278 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
280 TRACE("(%p) : Releasing from %d\n", This
, This
->ref
);
281 ref
= InterlockedDecrement(&This
->ref
);
286 IDirectDrawSurfaceImpl
*surf
;
287 IDirectDrawImpl
*ddraw
;
288 IUnknown
*ifaceToRelease
= This
->ifaceToRelease
;
291 /* Complex attached surfaces are destroyed implicitely when the root is released */
292 if(!This
->is_complex_root
)
294 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
299 /* If it's a texture, destroy the WineD3DTexture.
300 * WineD3D will destroy the IParent interfaces
301 * of the sublevels, which destroys the WineD3DSurfaces.
302 * Set the surfaces to NULL to avoid destroying them again later
304 if(This
->wineD3DTexture
)
306 IWineD3DTexture_Release(This
->wineD3DTexture
);
308 /* If it's the RenderTarget, destroy the d3ddevice */
309 else if( (ddraw
->d3d_initialized
) && (This
== ddraw
->d3d_target
))
311 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This
);
313 /* Unset any index buffer, just to be sure */
314 IWineD3DDevice_SetIndices(ddraw
->wineD3DDevice
, NULL
, 0);
315 IWineD3DDevice_SetDepthStencilSurface(ddraw
->wineD3DDevice
, NULL
);
317 if(IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroyDepthStencilSurface
, D3D7CB_DestroySwapChain
) != D3D_OK
)
320 ERR("(%p) Failed to uninit 3D\n", This
);
324 /* Free the d3d window if one was created */
325 if(ddraw
->d3d_window
!= 0)
327 TRACE(" (%p) Destroying the hidden render window %p\n", This
, ddraw
->d3d_window
);
328 DestroyWindow(ddraw
->d3d_window
);
329 ddraw
->d3d_window
= 0;
331 /* Unset the pointers */
334 ddraw
->d3d_initialized
= FALSE
;
335 ddraw
->d3d_target
= NULL
;
337 /* Write a trace because D3D unloading was the reason for many
338 * crashes during development.
340 TRACE("(%p) D3D unloaded\n", This
);
342 else if(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
346 /* It's a render target, but no swapchain was created.
347 * The IParent interfaces have to be released manually.
348 * The same applies for textures without an
349 * IWineD3DTexture object attached
353 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
355 if(This
->complex_array
[i
])
357 /* Only the topmost level can have more than 1 surfaces in the complex
358 * attachment array(Cube texture roots), for all others there is only
361 surf
= This
->complex_array
[i
];
364 IWineD3DSurface_GetParent(surf
->WineD3DSurface
,
365 (IUnknown
**) &Parent
);
366 IParent_Release(Parent
); /* For the getParent */
367 IParent_Release(Parent
); /* To release it */
368 surf
= surf
->complex_array
[0];
373 /* Now the top-level surface */
374 IWineD3DSurface_GetParent(This
->WineD3DSurface
,
375 (IUnknown
**) &Parent
);
376 IParent_Release(Parent
); /* For the getParent */
377 IParent_Release(Parent
); /* To release it */
380 /* The refcount test shows that the palette is detached when the surface is destroyed */
381 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This
, IDirectDrawSurface7
),
384 /* Loop through all complex attached surfaces,
387 * Yet again, only the root can have more than one complexly attached surface, all the others
388 * have a total of one;
390 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
392 if(!This
->complex_array
[i
]) break;
394 surf
= This
->complex_array
[i
];
395 This
->complex_array
[i
] = NULL
;
398 IDirectDrawSurfaceImpl
*destroy
= surf
;
399 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
400 IDirectDrawSurfaceImpl_Destroy(destroy
); /* Destroy it */
404 /* Destroy the root surface.
406 IDirectDrawSurfaceImpl_Destroy(This
);
408 /* Reduce the ddraw refcount */
409 if(ifaceToRelease
) IUnknown_Release(ifaceToRelease
);
415 /*****************************************************************************
416 * IDirectDrawSurface7::GetAttachedSurface
418 * Returns an attached surface with the requested caps. Surface attachment
419 * and complex surfaces are not clearly described by the MSDN or sdk,
420 * so this method is tricky and likely to contain problems.
421 * This implementation searches the complex list first, then the
424 * The chains are searched from This down to the last surface in the chain,
425 * not from the first element in the chain. The first surface found is
426 * returned. The MSDN says that this method fails if more than one surface
427 * matches the caps, but it is not sure if that is right. The attachment
428 * structure may not even allow two matching surfaces.
430 * The found surface is AddRef-ed before it is returned.
433 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
434 * Surface: Address to store the found surface
438 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
439 * DDERR_NOTFOUND if no surface was found
441 *****************************************************************************/
442 static HRESULT WINAPI
443 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7
*iface
,
445 IDirectDrawSurface7
**Surface
)
447 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
448 IDirectDrawSurfaceImpl
*surf
;
452 TRACE("(%p)->(%p,%p)\n", This
, Caps
, Surface
);
456 if(This
->version
< 7)
458 /* Earlier dx apps put garbage into these members, clear them */
459 our_caps
.dwCaps2
= 0;
460 our_caps
.dwCaps3
= 0;
461 our_caps
.dwCaps4
= 0;
464 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 */
466 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
468 surf
= This
->complex_array
[i
];
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 * Not sure how to test this.
489 TRACE("(%p): Returning surface %p\n", This
, surf
);
490 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
491 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
492 IDirectDrawSurface7_AddRef(*Surface
);
497 /* Next, look at the attachment chain */
500 while( (surf
= surf
->next_attached
) )
504 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
505 surf
->surface_desc
.ddsCaps
.dwCaps
,
506 surf
->surface_desc
.ddsCaps
.dwCaps2
,
507 surf
->surface_desc
.ddsCaps
.dwCaps3
,
508 surf
->surface_desc
.ddsCaps
.dwCaps4
);
511 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
512 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
514 TRACE("(%p): Returning surface %p\n", This
, surf
);
515 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
516 IDirectDrawSurface7_AddRef(*Surface
);
521 TRACE("(%p) Didn't find a valid surface\n", This
);
522 return DDERR_NOTFOUND
;
525 /*****************************************************************************
526 * IDirectDrawSurface7::Lock
528 * Locks the surface and returns a pointer to the surface's memory
531 * Rect: Rectangle to lock. If NULL, the whole surface is locked
532 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
533 * Flags: Locking flags, e.g Read only or write only
534 * h: An event handle that's not used and must be NULL
538 * DDERR_INVALIDPARAMS if DDSD is NULL
539 * For more details, see IWineD3DSurface::LockRect
541 *****************************************************************************/
542 static HRESULT WINAPI
543 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7
*iface
,
545 DDSURFACEDESC2
*DDSD
,
549 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
550 WINED3DLOCKED_RECT LockedRect
;
552 TRACE("(%p)->(%p,%p,%x,%p)\n", This
, Rect
, DDSD
, Flags
, h
);
555 return DDERR_INVALIDPARAMS
;
557 /* Should I check for the handle to be NULL?
559 * The DDLOCK flags and the D3DLOCK flags are equal
560 * for the supported values. The others are ignored by WineD3D
563 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
564 * that means it doesn't have dwSize set. Init it to some sane
567 if(DDSD
->dwSize
<= sizeof(DDSURFACEDESC
))
569 DDSD
->dwSize
= sizeof(DDSURFACEDESC
);
573 DDSD
->dwSize
= sizeof(DDSURFACEDESC2
);
576 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
577 hr
= IWineD3DSurface_LockRect(This
->WineD3DSurface
,
581 if(hr
!= D3D_OK
) return hr
;
583 /* Override the memory area and the pitch */
584 DDSD
->dwFlags
|= DDSD_LPSURFACE
;
585 DDSD
->lpSurface
= LockedRect
.pBits
;
586 DDSD
->dwFlags
|= DDSD_PITCH
;
587 DDSD
->u1
.lPitch
= LockedRect
.Pitch
;
589 TRACE("locked surface returning description :\n");
590 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
595 /*****************************************************************************
596 * IDirectDrawSurface7::Unlock
598 * Unlocks an locked surface
601 * Rect: Not used by this implementation
605 * For more details, see IWineD3DSurface::UnlockRect
607 *****************************************************************************/
608 static HRESULT WINAPI
609 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7
*iface
,
612 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
613 TRACE("(%p)->(%p)\n", This
, pRect
);
615 return IWineD3DSurface_UnlockRect(This
->WineD3DSurface
);
618 /*****************************************************************************
619 * IDirectDrawSurface7::Flip
621 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
622 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
623 * the flip target is passed to WineD3D, even if the app didn't specify one
626 * DestOverride: Specifies the surface that will become the new front
627 * buffer. If NULL, the current back buffer is used
628 * Flags: some DirectDraw flags, see include/ddraw.h
632 * DDERR_NOTFLIPPABLE if no flip target could be found
633 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
634 * For more details, see IWineD3DSurface::Flip
636 *****************************************************************************/
637 static HRESULT WINAPI
638 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7
*iface
,
639 IDirectDrawSurface7
*DestOverride
,
642 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
643 IDirectDrawSurfaceImpl
*Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DestOverride
);
644 IDirectDrawSurface7
*Override7
;
646 TRACE("(%p)->(%p,%x)\n", This
, DestOverride
, Flags
);
648 /* Flip has to be called from a front buffer
649 * What about overlay surfaces, AFAIK they can flip too?
651 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
) )
652 return DDERR_INVALIDOBJECT
; /* Unckecked */
654 /* WineD3D doesn't keep track of attached surface, so find the target */
659 memset(&Caps
, 0, sizeof(Caps
));
660 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
661 hr
= IDirectDrawSurface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
664 ERR("Can't find a flip target\n");
665 return DDERR_NOTFLIPPABLE
; /* Unchecked */
667 Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Override7
);
669 /* For the GetAttachedSurface */
670 IDirectDrawSurface7_Release(Override7
);
673 return IWineD3DSurface_Flip(This
->WineD3DSurface
,
674 Override
->WineD3DSurface
,
678 /*****************************************************************************
679 * IDirectDrawSurface7::Blt
681 * Performs a blit on the surface
684 * DestRect: Destination rectangle, can be NULL
685 * SrcSurface: Source surface, can be NULL
686 * SrcRect: Source rectange, can be NULL
688 * DDBltFx: Some extended blt parameters, connected to the flags
692 * See IWineD3DSurface::Blt for more details
694 *****************************************************************************/
695 static HRESULT WINAPI
696 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7
*iface
,
698 IDirectDrawSurface7
*SrcSurface
,
703 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
705 IDirectDrawSurfaceImpl
*Src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, SrcSurface
);
706 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This
, DestRect
, Src
, SrcRect
, Flags
, DDBltFx
);
708 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
709 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
711 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
712 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
713 return DDERR_INVALIDPARAMS
;
716 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
717 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
718 return DDERR_INVALIDPARAMS
;
721 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
722 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
723 return DDERR_INVALIDPARAMS
;
726 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
727 * and replace the ddraw surfaces with the wined3d surfaces
728 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
730 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
,
732 Src
? Src
->WineD3DSurface
: NULL
,
735 (WINEDDBLTFX
*) DDBltFx
,
739 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
740 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
745 /*****************************************************************************
746 * IDirectDrawSurface7::AddAttachedSurface
748 * Attaches a surface to another surface. How the surface attachments work
749 * is not totally understood yet, and this method is prone to problems.
750 * he surface that is attached is AddRef-ed.
752 * Tests with complex surfaces suggest that the surface attachments form a
753 * tree, but no method to test this has been found yet.
755 * The attachment list consists of a first surface (first_attached) and
756 * for each surface a pointer to the next attached surface (next_attached).
757 * For the first surface, and a surface that has no attachments
758 * first_attached points to the surface itself. A surface that has
759 * no successors in the chain has next_attached set to NULL.
761 * Newly attached surfaces are attached right after the root surface.
762 * If a surface is attached to a complex surface compound, it's attached to
763 * the surface that the app requested, not the complex root. See
764 * GetAttachedSurface for a description how surfaces are found.
766 * This is how the current implementation works, and it was coded by looking
767 * at the needs of the applications.
769 * So far only Z-Buffer attachments are tested, and they are activated in
770 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
771 * Back buffers should work in 2D mode, but they are not tested(Not sure if
772 * they can be attached at all). Rendering to the primary surface and
773 * switching between that and double buffering is not yet implemented in
774 * WineD3D, so for 3D it might have unexpected results.
777 * Attach: Surface to attach to iface
781 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
783 *****************************************************************************/
784 static HRESULT WINAPI
785 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7
*iface
,
786 IDirectDrawSurface7
*Attach
)
788 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
789 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
790 TRACE("(%p)->(%p)\n", This
, Surf
);
792 /* Should I make sure to add it to the first complex surface? */
795 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
797 /* MSDN: Only Z buffer surfaces can be attached. An old comment said that apparently
798 * mipmaps and back buffers can be attached too, although our tests say no.
800 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
802 /* Write a fixme until we know for sure what is going on */
803 FIXME("Application tries to attach a non Z buffer surface. caps %08x\n",
804 Surf
->surface_desc
.ddsCaps
.dwCaps
);
805 return DDERR_CANNOTATTACHSURFACE
;
808 /* Set MIPMAPSUBLEVEL if this seems to be one */
809 if (This
->surface_desc
.ddsCaps
.dwCaps
&
810 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
812 Surf
->surface_desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
813 /* FIXME: we should probably also add to dwMipMapCount of this
814 * and all parent surfaces (update create_texture if you do) */
817 /* Check if the surface is already attached somewhere */
818 if( (Surf
->next_attached
!= NULL
) ||
819 (Surf
->first_attached
!= Surf
) )
821 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
);
822 return DDERR_CANNOTATTACHSURFACE
;
825 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
826 Surf
->next_attached
= This
->next_attached
;
827 Surf
->first_attached
= This
->first_attached
;
828 This
->next_attached
= Surf
;
830 /* Check if we attach a back buffer to the primary */
831 if(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
&&
832 This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
834 IWineD3DDevice_SetDepthStencilSurface(This
->ddraw
->wineD3DDevice
,
835 Surf
->WineD3DSurface
);
839 * "This method increments the reference count of the surface being attached."
841 IDirectDrawSurface7_AddRef(Attach
);
845 /*****************************************************************************
846 * IDirectDrawSurface7::DeleteAttachedSurface
848 * Removes a surface from the attachment chain. The surface's refcount
849 * is decreased by one after it has been removed
852 * Flags: Some flags, not used by this implementation
853 * Attach: Surface to detach
857 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
859 *****************************************************************************/
860 static HRESULT WINAPI
861 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
863 IDirectDrawSurface7
*Attach
)
865 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
866 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
867 IDirectDrawSurfaceImpl
*Prev
= This
;
868 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, Surf
);
870 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
871 return DDERR_SURFACENOTATTACHED
; /* unchecked */
873 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
874 if (This
->surface_desc
.ddsCaps
.dwCaps
&
875 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
877 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
878 /* FIXME: we should probably also subtract from dwMipMapCount of this
879 * and all parent surfaces */
882 /* Find the predecessor of the detached surface */
885 if(Prev
->next_attached
== Surf
) break;
886 Prev
= Prev
->next_attached
;
889 /* There must be a surface, otherwise there's a bug */
890 assert(Prev
!= NULL
);
892 /* Unchain the surface */
893 Prev
->next_attached
= Surf
->next_attached
;
894 Surf
->next_attached
= NULL
;
895 Surf
->first_attached
= Surf
;
897 /* Check if we attach a back buffer to the primary */
898 if(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
&&
899 This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
901 IWineD3DDevice_SetDepthStencilSurface(This
->ddraw
->wineD3DDevice
,
905 IDirectDrawSurface7_Release(Attach
);
909 /*****************************************************************************
910 * IDirectDrawSurface7::AddOverlayDirtyRect
912 * "This method is not currently implemented"
920 *****************************************************************************/
921 static HRESULT WINAPI
922 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
,
925 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
926 TRACE("(%p)->(%p)\n",This
,Rect
);
928 /* MSDN says it's not implemented. I could forward it to WineD3D,
929 * then we'd implement it, but I don't think that's a good idea
933 return IWineD3DSurface_AddOverlayDirtyRect(This
->WineD3DSurface
, pRect
);
935 return DDERR_UNSUPPORTED
; /* unchecked */
938 /*****************************************************************************
939 * IDirectDrawSurface7::GetDC
941 * Returns a GDI device context for the surface
944 * hdc: Address of a HDC variable to store the dc to
948 * DDERR_INVALIDPARAMS if hdc is NULL
949 * For details, see IWineD3DSurface::GetDC
951 *****************************************************************************/
952 static HRESULT WINAPI
953 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7
*iface
,
956 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
957 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
960 return DDERR_INVALIDPARAMS
;
962 return IWineD3DSurface_GetDC(This
->WineD3DSurface
,
966 /*****************************************************************************
967 * IDirectDrawSurface7::ReleaseDC
969 * Releases the DC that was constructed with GetDC
972 * hdc: HDC to release
976 * For more details, see IWineD3DSurface::ReleaseDC
978 *****************************************************************************/
979 static HRESULT WINAPI
980 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7
*iface
,
983 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
984 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
986 return IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
989 /*****************************************************************************
990 * IDirectDrawSurface7::GetCaps
992 * Returns the surface's caps
995 * Caps: Address to write the caps to
999 * DDERR_INVALIDPARAMS if Caps is NULL
1001 *****************************************************************************/
1002 static HRESULT WINAPI
1003 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7
*iface
,
1006 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1007 TRACE("(%p)->(%p)\n",This
,Caps
);
1010 return DDERR_INVALIDPARAMS
;
1012 *Caps
= This
->surface_desc
.ddsCaps
;
1016 /*****************************************************************************
1017 * IDirectDrawSurface7::SetPriority
1019 * Sets a texture priority for managed textures.
1022 * Priority: The new priority
1026 * For more details, see IWineD3DSurface::SetPriority
1028 *****************************************************************************/
1029 static HRESULT WINAPI
1030 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1032 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1033 TRACE("(%p)->(%d): Relay!\n",This
,Priority
);
1035 return IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1038 /*****************************************************************************
1039 * IDirectDrawSurface7::GetPriority
1041 * Returns the surface's priority
1044 * Priority: Address of a variable to write the priority to
1048 * DDERR_INVALIDPARAMS if Priority == NULL
1049 * For more details, see IWineD3DSurface::GetPriority
1051 *****************************************************************************/
1052 static HRESULT WINAPI
1053 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7
*iface
,
1056 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1057 TRACE("(%p)->(%p): Relay\n",This
,Priority
);
1060 return DDERR_INVALIDPARAMS
;
1062 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1066 /*****************************************************************************
1067 * IDirectDrawSurface7::SetPrivateData
1069 * Stores some data in the surface that is intended for the application's
1073 * tag: GUID that identifies the data
1074 * Data: Pointer to the private data
1075 * Size: Size of the private data
1080 * For more details, see IWineD3DSurface::SetPrivateData
1082 *****************************************************************************/
1083 static HRESULT WINAPI
1084 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7
*iface
,
1090 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1091 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This
, debugstr_guid(tag
), Data
, Size
, Flags
);
1093 return IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1100 /*****************************************************************************
1101 * IDirectDrawSurface7::GetPrivateData
1103 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1106 * tag: GUID of the data to return
1107 * Data: Address where to write the data to
1108 * Size: Size of the buffer at Data
1112 * DDERR_INVALIDPARAMS if Data is NULL
1113 * For more details, see IWineD3DSurface::GetPrivateData
1115 *****************************************************************************/
1116 static HRESULT WINAPI
1117 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7
*iface
,
1122 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1123 TRACE("(%p)->(%s,%p,%p): Relay\n", This
, debugstr_guid(tag
), Data
, Size
);
1126 return DDERR_INVALIDPARAMS
;
1128 return IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1134 /*****************************************************************************
1135 * IDirectDrawSurface7::FreePrivateData
1137 * Frees private data stored in the surface
1140 * tag: Tag of the data to free
1144 * For more details, see IWineD3DSurface::FreePrivateData
1146 *****************************************************************************/
1147 static HRESULT WINAPI
1148 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7
*iface
,
1151 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1152 TRACE("(%p)->(%s): Relay\n", This
, debugstr_guid(tag
));
1154 return IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1157 /*****************************************************************************
1158 * IDirectDrawSurface7::PageLock
1160 * Prevents a sysmem surface from being paged out
1163 * Flags: Not used, must be 0(unchecked)
1166 * DD_OK, because it's a stub
1168 *****************************************************************************/
1169 static HRESULT WINAPI
1170 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7
*iface
,
1173 TRACE("(%p)->(%x)\n", iface
, Flags
);
1175 /* This is Windows memory management related - we don't need this */
1179 /*****************************************************************************
1180 * IDirectDrawSurface7::PageUnlock
1182 * Allows a sysmem surface to be paged out
1185 * Flags: Not used, must be 0(unckeched)
1188 * DD_OK, because it's a stub
1190 *****************************************************************************/
1191 static HRESULT WINAPI
1192 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7
*iface
,
1195 TRACE("(%p)->(%x)\n", iface
, Flags
);
1200 /*****************************************************************************
1201 * IDirectDrawSurface7::BltBatch
1203 * An unimplemented function
1211 *****************************************************************************/
1212 static HRESULT WINAPI
IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1214 TRACE("(%p)->(%p,%d,%08x)\n",iface
,Batch
,Count
,Flags
);
1216 /* MSDN: "not currently implemented" */
1217 return DDERR_UNSUPPORTED
;
1220 /*****************************************************************************
1221 * IDirectDrawSurface7::EnumAttachedSurfaces
1223 * Enumerates all surfaces attached to this surface
1226 * context: Pointer to pass unmodified to the callback
1227 * cb: Callback function to call for each surface
1231 * DDERR_INVALIDPARAMS if cb is NULL
1233 *****************************************************************************/
1234 static HRESULT WINAPI
1235 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1237 LPDDENUMSURFACESCALLBACK7 cb
)
1239 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1240 IDirectDrawSurfaceImpl
*surf
;
1241 DDSURFACEDESC2 desc
;
1244 /* Attached surfaces aren't handled in WineD3D */
1245 TRACE("(%p)->(%p,%p)\n",This
,context
,cb
);
1248 return DDERR_INVALIDPARAMS
;
1250 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1252 surf
= This
->complex_array
[i
];
1255 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1256 desc
= surf
->surface_desc
;
1257 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1258 if (cb(ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1262 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1264 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1265 desc
= surf
->surface_desc
;
1266 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1267 if (cb( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1271 TRACE(" end of enumeration.\n");
1276 /*****************************************************************************
1277 * IDirectDrawSurface7::EnumOverlayZOrders
1279 * "Enumerates the overlay surfaces on the specified destination"
1282 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1283 * context: context to pass back to the callback
1284 * cb: callback function to call for each enumerated surface
1287 * DD_OK, because it's a stub
1289 *****************************************************************************/
1290 static HRESULT WINAPI
1291 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1294 LPDDENUMSURFACESCALLBACK7 cb
)
1296 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface
, Flags
, context
, cb
);
1301 /*****************************************************************************
1302 * IDirectDrawSurface7::GetBltStatus
1304 * Returns the blitting status
1307 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1310 * See IWineD3DSurface::Blt
1312 *****************************************************************************/
1313 static HRESULT WINAPI
1314 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7
*iface
,
1317 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1319 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1321 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1324 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1329 /*****************************************************************************
1330 * IDirectDrawSurface7::GetColorKey
1332 * Returns the color key assigned to the surface
1336 * CKey: Address to store the key to
1340 * DDERR_INVALIDPARAMS if CKey is NULL
1342 *****************************************************************************/
1343 static HRESULT WINAPI
1344 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7
*iface
,
1348 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1349 * isn't there? That's like saying that an int isn't there. (Which MS
1350 * has done in other docs.) */
1351 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1352 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, CKey
);
1355 return DDERR_INVALIDPARAMS
;
1359 case DDCKEY_DESTBLT
:
1360 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1363 case DDCKEY_DESTOVERLAY
:
1364 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1368 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1371 case DDCKEY_SRCOVERLAY
:
1372 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1376 return DDERR_INVALIDPARAMS
;
1382 /*****************************************************************************
1383 * IDirectDrawSurface7::GetFlipStatus
1385 * Returns the flipping status of the surface
1388 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1391 * See IWineD3DSurface::GetFlipStatus
1393 *****************************************************************************/
1394 static HRESULT WINAPI
1395 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7
*iface
,
1398 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1400 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1402 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1405 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1410 /*****************************************************************************
1411 * IDirectDrawSurface7::GetOverlayPosition
1413 * Returns the display coordinates of a visible and active overlay surface
1420 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1421 *****************************************************************************/
1422 static HRESULT WINAPI
1423 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7
*iface
,
1426 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1427 TRACE("(%p)->(%p,%p): Relay\n", This
, X
, Y
);
1429 return IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1434 /*****************************************************************************
1435 * IDirectDrawSurface7::GetPixelFormat
1437 * Returns the pixel format of the Surface
1440 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1441 * format should be written
1445 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1447 *****************************************************************************/
1448 static HRESULT WINAPI
1449 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7
*iface
,
1450 DDPIXELFORMAT
*PixelFormat
)
1452 /* What is DDERR_INVALIDSURFACETYPE for here? */
1453 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1454 TRACE("(%p)->(%p)\n",This
,PixelFormat
);
1457 return DDERR_INVALIDPARAMS
;
1459 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1465 /*****************************************************************************
1466 * IDirectDrawSurface7::GetSurfaceDesc
1468 * Returns the description of this surface
1471 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1476 * DDERR_INVALIDPARAMS if DDSD is NULL
1478 *****************************************************************************/
1479 static HRESULT WINAPI
1480 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7
*iface
,
1481 DDSURFACEDESC2
*DDSD
)
1483 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1485 TRACE("(%p)->(%p)\n",This
,DDSD
);
1488 return DDERR_INVALIDPARAMS
;
1490 if ((DDSD
->dwSize
< sizeof(DDSURFACEDESC
)) ||
1491 (DDSD
->dwSize
> sizeof(DDSURFACEDESC2
)))
1493 ERR("Impossible/Strange struct size %d.\n",DDSD
->dwSize
);
1494 return DDERR_GENERIC
;
1497 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1498 TRACE("Returning surface desc:\n");
1499 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1504 /*****************************************************************************
1505 * IDirectDrawSurface7::Initialize
1507 * Initializes the surface. This is a no-op in Wine
1510 * DD: Pointer to an DirectDraw interface
1511 * DDSD: Surface description for initialization
1514 * DDERR_ALREADYINITIALIZED
1516 *****************************************************************************/
1517 static HRESULT WINAPI
1518 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7
*iface
,
1520 DDSURFACEDESC2
*DDSD
)
1522 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1523 IDirectDrawImpl
*ddimpl
= ICOM_OBJECT(IDirectDrawImpl
, IDirectDraw
, DD
);
1524 TRACE("(%p)->(%p,%p)\n",This
,ddimpl
,DDSD
);
1526 return DDERR_ALREADYINITIALIZED
;
1529 /*****************************************************************************
1530 * IDirectDrawSurface7::IsLost
1532 * Checks if the surface is lost
1535 * DD_OK, if the surface is useable
1536 * DDERR_ISLOST if the surface is lost
1537 * See IWineD3DSurface::IsLost for more details
1539 *****************************************************************************/
1540 static HRESULT WINAPI
1541 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7
*iface
)
1543 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1545 TRACE("(%p)\n", This
);
1547 /* We lose the surface if the implementation was changed */
1548 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1550 /* But this shouldn't happen. When we change the implementation,
1551 * all surfaces are re-created automatically, and their content
1554 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
1555 return DDERR_SURFACELOST
;
1558 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
1561 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1562 * WineD3D uses the same error for surfaces
1564 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
1569 /*****************************************************************************
1570 * IDirectDrawSurface7::Restore
1572 * Restores a lost surface. This makes the surface usable again, but
1573 * doesn't reload its old contents
1577 * See IWineD3DSurface::Restore for more details
1579 *****************************************************************************/
1580 static HRESULT WINAPI
1581 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7
*iface
)
1583 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1584 TRACE("(%p)\n", This
);
1586 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1588 /* Call the recreation callback. Make sure to AddRef first */
1589 IDirectDrawSurface_AddRef(iface
);
1590 IDirectDrawImpl_RecreateSurfacesCallback(iface
,
1591 &This
->surface_desc
,
1592 NULL
/* Not needed */);
1594 return IWineD3DSurface_Restore(This
->WineD3DSurface
);
1597 /*****************************************************************************
1598 * IDirectDrawSurface7::SetOverlayPosition
1600 * Changes the display coordinates of an overlay surface
1607 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1608 *****************************************************************************/
1609 static HRESULT WINAPI
1610 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7
*iface
,
1614 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1615 TRACE("(%p)->(%d,%d): Relay\n", This
, X
, Y
);
1617 return IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
1622 /*****************************************************************************
1623 * IDirectDrawSurface7::UpdateOverlay
1625 * Modifies the attributes of an overlay surface.
1628 * SrcRect: The section of the source being used for the overlay
1629 * DstSurface: Address of the surface that is overlaid
1630 * DstRect: Place of the overlay
1631 * Flags: some DDOVER_* flags
1634 * DDERR_UNSUPPORTED, because we don't support overlays
1636 *****************************************************************************/
1637 static HRESULT WINAPI
1638 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7
*iface
,
1640 IDirectDrawSurface7
*DstSurface
,
1645 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1646 IDirectDrawSurfaceImpl
*Dst
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DstSurface
);
1647 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This
, SrcRect
, Dst
, DstRect
, Flags
, FX
);
1649 return IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
1651 Dst
? Dst
->WineD3DSurface
: NULL
,
1654 (WINEDDOVERLAYFX
*) FX
);
1657 /*****************************************************************************
1658 * IDirectDrawSurface7::UpdateOverlayDisplay
1660 * The DX7 sdk says that it's not implemented
1665 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1667 *****************************************************************************/
1668 static HRESULT WINAPI
1669 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
,
1672 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1673 TRACE("(%p)->(%x)\n", This
, Flags
);
1674 return DDERR_UNSUPPORTED
;
1677 /*****************************************************************************
1678 * IDirectDrawSurface7::UpdateOverlayZOrder
1680 * Sets an overlay's Z order
1683 * Flags: DDOVERZ_* flags
1684 * DDSRef: Defines the relative position in the overlay chain
1687 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1689 *****************************************************************************/
1690 static HRESULT WINAPI
1691 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
1693 IDirectDrawSurface7
*DDSRef
)
1695 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1696 IDirectDrawSurfaceImpl
*Ref
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DDSRef
);
1698 TRACE("(%p)->(%x,%p): Relay\n", This
, Flags
, Ref
);
1699 return IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
1701 Ref
? Ref
->WineD3DSurface
: NULL
);
1704 /*****************************************************************************
1705 * IDirectDrawSurface7::GetDDInterface
1707 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1708 * surface belongs to
1711 * DD: Address to write the interface pointer to
1715 * DDERR_INVALIDPARAMS if DD is NULL
1717 *****************************************************************************/
1718 static HRESULT WINAPI
1719 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7
*iface
,
1722 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1724 TRACE("(%p)->(%p)\n",This
,DD
);
1727 return DDERR_INVALIDPARAMS
;
1729 switch(This
->version
)
1732 *((IDirectDraw7
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw7
);
1733 IDirectDraw7_AddRef(*(IDirectDraw7
**) DD
);
1737 *((IDirectDraw4
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw4
);
1738 IDirectDraw4_AddRef(*(IDirectDraw4
**) DD
);
1742 *((IDirectDraw2
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw2
);
1743 IDirectDraw_AddRef( *(IDirectDraw2
**) DD
);
1747 *((IDirectDraw
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw
);
1748 IDirectDraw_AddRef( *(IDirectDraw
**) DD
);
1756 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1757 static HRESULT WINAPI
IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
1759 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1760 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
1762 TRACE("(%p)\n",This
);
1763 /* A uniqueness value of 0 is apparently special.
1764 * This needs to be checked. */
1766 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
1767 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
1769 if (old_uniqueness_value
== 0) break;
1770 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
1772 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
1773 old_uniqueness_value
,
1774 new_uniqueness_value
)
1775 == old_uniqueness_value
)
1782 static HRESULT WINAPI
IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7
*iface
, LPDWORD pValue
)
1784 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1786 TRACE("(%p)->(%p)\n",This
,pValue
);
1787 *pValue
= This
->uniqueness_value
;
1791 /*****************************************************************************
1792 * IDirectDrawSurface7::SetLOD
1794 * Sets the level of detail of a texture
1797 * MaxLOD: LOD to set
1801 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1803 *****************************************************************************/
1804 static HRESULT WINAPI
1805 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7
*iface
,
1808 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1809 TRACE("(%p)->(%d)\n", This
, MaxLOD
);
1811 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
1812 return DDERR_INVALIDOBJECT
;
1814 if(!This
->wineD3DTexture
)
1816 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
1817 return DDERR_INVALIDOBJECT
;
1820 return IWineD3DTexture_SetLOD(This
->wineD3DTexture
,
1824 /*****************************************************************************
1825 * IDirectDrawSurface7::GetLOD
1827 * Returns the level of detail of a Direct3D texture
1830 * MaxLOD: Address to write the LOD to
1834 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1835 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1837 *****************************************************************************/
1838 static HRESULT WINAPI
1839 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7
*iface
,
1842 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1843 TRACE("(%p)->(%p)\n", This
, MaxLOD
);
1846 return DDERR_INVALIDPARAMS
;
1848 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
1849 return DDERR_INVALIDOBJECT
;
1851 *MaxLOD
= IWineD3DTexture_GetLOD(This
->wineD3DTexture
);
1855 /*****************************************************************************
1856 * IDirectDrawSurface7::BltFast
1858 * Performs a fast Blit.
1861 * dstx: The x coordinate to blit to on the destination
1862 * dsty: The y coordinate to blit to on the destination
1863 * Source: The source surface
1864 * rsrc: The source rectangle
1865 * trans: Type of transfer. Some DDBLTFAST_* flags
1869 * For more details, see IWineD3DSurface::BltFast
1871 *****************************************************************************/
1872 static HRESULT WINAPI
1873 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7
*iface
,
1876 IDirectDrawSurface7
*Source
,
1880 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1882 IDirectDrawSurfaceImpl
*src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Source
);
1883 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This
, dstx
, dsty
, Source
, rsrc
, trans
);
1885 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
1887 src
? src
->WineD3DSurface
: NULL
,
1892 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1893 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1898 /*****************************************************************************
1899 * IDirectDrawSurface7::GetClipper
1901 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1905 * Clipper: Address to store the interface pointer at
1909 * DDERR_INVALIDPARAMS if Clipper is NULL
1910 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1912 *****************************************************************************/
1913 static HRESULT WINAPI
1914 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7
*iface
,
1915 IDirectDrawClipper
**Clipper
)
1917 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1918 TRACE("(%p)->(%p)\n", This
, Clipper
);
1921 return DDERR_INVALIDPARAMS
;
1923 if(This
->clipper
== NULL
)
1924 return DDERR_NOCLIPPERATTACHED
;
1926 *Clipper
= ICOM_INTERFACE(This
->clipper
, IDirectDrawClipper
);
1927 IDirectDrawClipper_AddRef(*Clipper
);
1931 /*****************************************************************************
1932 * IDirectDrawSurface7::SetClipper
1934 * Sets a clipper for the surface
1937 * Clipper: IDirectDrawClipper interface of the clipper to set
1942 *****************************************************************************/
1943 static HRESULT WINAPI
1944 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7
*iface
,
1945 IDirectDrawClipper
*Clipper
)
1947 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1948 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
1950 TRACE("(%p)->(%p)\n",This
,Clipper
);
1951 if (ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
) == This
->clipper
)
1954 This
->clipper
= ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
);
1956 if (Clipper
!= NULL
)
1957 IDirectDrawClipper_AddRef(Clipper
);
1959 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper
, IDirectDrawClipper
));
1964 /*****************************************************************************
1965 * IDirectDrawSurface7::SetSurfaceDesc
1967 * Sets the surface description. It can override the pixel format, the surface
1969 * It's not really tested.
1972 * DDSD: Pointer to the new surface description to set
1977 * DDERR_INVALIDPARAMS if DDSD is NULL
1979 *****************************************************************************/
1980 static HRESULT WINAPI
1981 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7
*iface
,
1982 DDSURFACEDESC2
*DDSD
,
1985 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1986 WINED3DFORMAT newFormat
= WINED3DFMT_UNKNOWN
;
1988 TRACE("(%p)->(%p,%x)\n", This
, DDSD
, Flags
);
1991 return DDERR_INVALIDPARAMS
;
1993 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
1995 ERR("Setting the surface memory isn't supported yet\n");
1996 return DDERR_INVALIDPARAMS
;
1999 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2001 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2003 if(newFormat
== WINED3DFMT_UNKNOWN
)
2005 ERR("Requested to set an unknown pixelformat\n");
2006 return DDERR_INVALIDPARAMS
;
2008 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2010 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2012 if(hr
!= DD_OK
) return hr
;
2015 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2017 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2019 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2021 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2023 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2025 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2027 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2029 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2031 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2033 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2035 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2037 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2039 if (DDSD
->dwFlags
& DDSD_LPSURFACE
)
2041 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2042 if(hr
!= WINED3D_OK
)
2044 /* No need for a trace here, wined3d does that for us */
2049 This
->surface_desc
= *DDSD
;
2054 /*****************************************************************************
2055 * IDirectDrawSurface7::GetPalette
2057 * Returns the IDirectDrawPalette interface of the palette currently assigned
2061 * Pal: Address to write the interface pointer to
2065 * DDERR_INVALIDPARAMS if Pal is NULL
2067 *****************************************************************************/
2068 static HRESULT WINAPI
2069 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7
*iface
,
2070 IDirectDrawPalette
**Pal
)
2072 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2073 IWineD3DPalette
*wPal
;
2075 TRACE("(%p)->(%p): Relay\n", This
, Pal
);
2078 return DDERR_INVALIDPARAMS
;
2080 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wPal
);
2081 if(hr
!= DD_OK
) return hr
;
2085 hr
= IWineD3DPalette_GetParent(wPal
, (IUnknown
**) Pal
);
2090 hr
= DDERR_NOPALETTEATTACHED
;
2096 /*****************************************************************************
2099 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2100 * recursively in the surface tree
2102 *****************************************************************************/
2106 WINEDDCOLORKEY
*CKey
;
2110 static HRESULT WINAPI
2111 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2112 DDSURFACEDESC2
*desc
,
2115 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2116 struct SCKContext
*ctx
= context
;
2119 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2124 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2128 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
2131 IDirectDrawSurface7_Release(surface
);
2132 return DDENUMRET_OK
;
2135 /*****************************************************************************
2136 * IDirectDrawSurface7::SetColorKey
2138 * Sets the color keying options for the surface. Observations showed that
2139 * in case of complex surfaces the color key has to be assigned to all
2144 * CKey: The new color key
2148 * See IWineD3DSurface::SetColorKey for details
2150 *****************************************************************************/
2151 static HRESULT WINAPI
2152 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7
*iface
,
2156 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2157 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) CKey
, Flags
};
2158 TRACE("(%p)->(%x,%p)\n", This
, Flags
, CKey
);
2162 switch (Flags
& ~DDCKEY_COLORSPACE
)
2164 case DDCKEY_DESTBLT
:
2165 This
->surface_desc
.ddckCKDestBlt
= *CKey
;
2166 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2169 case DDCKEY_DESTOVERLAY
:
2170 This
->surface_desc
.u3
.ddckCKDestOverlay
= *CKey
;
2171 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2174 case DDCKEY_SRCOVERLAY
:
2175 This
->surface_desc
.ddckCKSrcOverlay
= *CKey
;
2176 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2180 This
->surface_desc
.ddckCKSrcBlt
= *CKey
;
2181 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2185 return DDERR_INVALIDPARAMS
;
2190 switch (Flags
& ~DDCKEY_COLORSPACE
)
2192 case DDCKEY_DESTBLT
:
2193 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2196 case DDCKEY_DESTOVERLAY
:
2197 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2200 case DDCKEY_SRCOVERLAY
:
2201 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2205 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2209 return DDERR_INVALIDPARAMS
;
2212 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2215 IDirectDrawSurface7_EnumAttachedSurfaces(iface
,
2220 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2221 default: return ctx
.ret
;
2225 /*****************************************************************************
2226 * IDirectDrawSurface7::SetPalette
2228 * Assigns a DirectDrawPalette object to the surface
2231 * Pal: Interface to the palette to set
2236 *****************************************************************************/
2237 static HRESULT WINAPI
2238 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7
*iface
,
2239 IDirectDrawPalette
*Pal
)
2241 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2242 IDirectDrawPalette
*oldPal
;
2243 IDirectDrawSurfaceImpl
*surf
;
2244 IDirectDrawPaletteImpl
*PalImpl
= ICOM_OBJECT(IDirectDrawPaletteImpl
, IDirectDrawPalette
, Pal
);
2246 TRACE("(%p)->(%p)\n", This
, Pal
);
2248 /* Find the old palette */
2249 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2250 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
) return hr
;
2251 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2253 /* Set the new Palette */
2254 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2255 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2256 /* AddRef the Palette */
2257 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2259 /* Release the old palette */
2260 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2262 /* If this is a front buffer, also update the back buffers
2263 * TODO: How do things work for palettized cube textures?
2265 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2267 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2268 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2273 IDirectDrawSurface7
*attach
;
2275 hr
= IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
2282 TRACE("Setting palette on %p\n", attach
);
2283 IDirectDrawSurface7_SetPalette(attach
,
2285 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attach
);
2286 IDirectDrawSurface7_Release(attach
);
2293 /*****************************************************************************
2295 *****************************************************************************/
2297 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
=
2300 IDirectDrawSurfaceImpl_QueryInterface
,
2301 IDirectDrawSurfaceImpl_AddRef
,
2302 IDirectDrawSurfaceImpl_Release
,
2303 /*** IDirectDrawSurface ***/
2304 IDirectDrawSurfaceImpl_AddAttachedSurface
,
2305 IDirectDrawSurfaceImpl_AddOverlayDirtyRect
,
2306 IDirectDrawSurfaceImpl_Blt
,
2307 IDirectDrawSurfaceImpl_BltBatch
,
2308 IDirectDrawSurfaceImpl_BltFast
,
2309 IDirectDrawSurfaceImpl_DeleteAttachedSurface
,
2310 IDirectDrawSurfaceImpl_EnumAttachedSurfaces
,
2311 IDirectDrawSurfaceImpl_EnumOverlayZOrders
,
2312 IDirectDrawSurfaceImpl_Flip
,
2313 IDirectDrawSurfaceImpl_GetAttachedSurface
,
2314 IDirectDrawSurfaceImpl_GetBltStatus
,
2315 IDirectDrawSurfaceImpl_GetCaps
,
2316 IDirectDrawSurfaceImpl_GetClipper
,
2317 IDirectDrawSurfaceImpl_GetColorKey
,
2318 IDirectDrawSurfaceImpl_GetDC
,
2319 IDirectDrawSurfaceImpl_GetFlipStatus
,
2320 IDirectDrawSurfaceImpl_GetOverlayPosition
,
2321 IDirectDrawSurfaceImpl_GetPalette
,
2322 IDirectDrawSurfaceImpl_GetPixelFormat
,
2323 IDirectDrawSurfaceImpl_GetSurfaceDesc
,
2324 IDirectDrawSurfaceImpl_Initialize
,
2325 IDirectDrawSurfaceImpl_IsLost
,
2326 IDirectDrawSurfaceImpl_Lock
,
2327 IDirectDrawSurfaceImpl_ReleaseDC
,
2328 IDirectDrawSurfaceImpl_Restore
,
2329 IDirectDrawSurfaceImpl_SetClipper
,
2330 IDirectDrawSurfaceImpl_SetColorKey
,
2331 IDirectDrawSurfaceImpl_SetOverlayPosition
,
2332 IDirectDrawSurfaceImpl_SetPalette
,
2333 IDirectDrawSurfaceImpl_Unlock
,
2334 IDirectDrawSurfaceImpl_UpdateOverlay
,
2335 IDirectDrawSurfaceImpl_UpdateOverlayDisplay
,
2336 IDirectDrawSurfaceImpl_UpdateOverlayZOrder
,
2337 /*** IDirectDrawSurface2 ***/
2338 IDirectDrawSurfaceImpl_GetDDInterface
,
2339 IDirectDrawSurfaceImpl_PageLock
,
2340 IDirectDrawSurfaceImpl_PageUnlock
,
2341 /*** IDirectDrawSurface3 ***/
2342 IDirectDrawSurfaceImpl_SetSurfaceDesc
,
2343 /*** IDirectDrawSurface4 ***/
2344 IDirectDrawSurfaceImpl_SetPrivateData
,
2345 IDirectDrawSurfaceImpl_GetPrivateData
,
2346 IDirectDrawSurfaceImpl_FreePrivateData
,
2347 IDirectDrawSurfaceImpl_GetUniquenessValue
,
2348 IDirectDrawSurfaceImpl_ChangeUniquenessValue
,
2349 /*** IDirectDrawSurface7 ***/
2350 IDirectDrawSurfaceImpl_SetPriority
,
2351 IDirectDrawSurfaceImpl_GetPriority
,
2352 IDirectDrawSurfaceImpl_SetLOD
,
2353 IDirectDrawSurfaceImpl_GetLOD