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
41 #include "wine/exception.h"
46 #include "ddraw_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
51 /*****************************************************************************
52 * IUnknown parts follow
53 *****************************************************************************/
55 /*****************************************************************************
56 * IDirectDrawSurface7::QueryInterface
58 * A normal QueryInterface implementation. For QueryInterface rules
59 * see ddraw.c, IDirectDraw7::QueryInterface. This method
60 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
61 * in all versions, the IDirectDrawGammaControl interface and it can
62 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
65 * riid: The interface id queried for
66 * obj: Address to write the pointer to
70 * E_NOINTERFACE if the requested interface wasn't found
72 *****************************************************************************/
74 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7
*iface
,
78 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
80 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
84 return DDERR_INVALIDPARAMS
;
86 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),obj
);
87 if (IsEqualGUID(riid
, &IID_IUnknown
)
88 || IsEqualGUID(riid
, &IID_IDirectDrawSurface7
)
89 || IsEqualGUID(riid
, &IID_IDirectDrawSurface4
) )
91 IUnknown_AddRef(iface
);
92 *obj
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
93 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
96 else if( IsEqualGUID(riid
, &IID_IDirectDrawSurface3
)
97 || IsEqualGUID(riid
, &IID_IDirectDrawSurface2
)
98 || IsEqualGUID(riid
, &IID_IDirectDrawSurface
) )
100 IUnknown_AddRef(iface
);
101 *obj
= ICOM_INTERFACE(This
, IDirectDrawSurface3
);
102 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
105 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
107 IUnknown_AddRef(iface
);
108 *obj
= ICOM_INTERFACE(This
, IDirectDrawGammaControl
);
109 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
112 else if( IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
) ||
113 IsEqualGUID(riid
, &IID_IDirect3DHALDevice
) )
115 IDirect3DDevice7
*d3d
;
117 /* Call into IDirect3D7 for creation */
118 IDirect3D7_CreateDevice(ICOM_INTERFACE(This
->ddraw
, IDirect3D7
),
120 ICOM_INTERFACE(This
, IDirectDrawSurface7
),
123 *obj
= COM_INTERFACE_CAST(IDirect3DDeviceImpl
, IDirect3DDevice7
, IDirect3DDevice
, d3d
);
124 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
128 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
129 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
131 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
133 *obj
= ICOM_INTERFACE(This
, IDirect3DTexture
);
134 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
138 *obj
= ICOM_INTERFACE(This
, IDirect3DTexture2
);
139 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
141 IUnknown_AddRef( (IUnknown
*) *obj
);
145 ERR("No interface\n");
146 return E_NOINTERFACE
;
149 /*****************************************************************************
150 * IDirectDrawSurface7::AddRef
152 * A normal addref implementation
157 *****************************************************************************/
159 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7
*iface
)
161 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
162 ULONG refCount
= InterlockedIncrement(&This
->ref
);
164 TRACE("(%p) : AddRef increasing from %d\n", This
, refCount
- 1);
168 /*****************************************************************************
169 * IDirectDrawSurfaceImpl_Destroy
171 * A helper function for IDirectDrawSurface7::Release
173 * Frees the surface, regardless of its refcount.
174 * See IDirectDrawSurface7::Release for more information
177 * This: Surface to free
179 *****************************************************************************/
180 static void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl
*This
)
182 TRACE("(%p)\n", This
);
184 /* Check the refcount and give a warning */
187 /* This can happen when a complex surface is destroyed,
188 * because the 2nd surface was addref()ed when the app
189 * called GetAttachedSurface
191 WARN("(%p): Destroying surface with refount %d\n", This
, This
->ref
);
194 /* Check for attached surfaces and detach them */
195 if(This
->first_attached
!= This
)
197 /* Well, this shouldn't happen: The surface being attached is addref()ed
198 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
199 * is called, because the refcount is held. It looks like the app released()
200 * it often enough to force this
202 IDirectDrawSurface7
*root
= ICOM_INTERFACE(This
->first_attached
, IDirectDrawSurface7
);
203 IDirectDrawSurface7
*detach
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
205 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This
, This
->first_attached
);
207 /* The refcount will drop to -1 here */
208 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
210 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
214 while(This
->next_attached
!= NULL
)
216 IDirectDrawSurface7
*root
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
217 IDirectDrawSurface7
*detach
= ICOM_INTERFACE(This
->next_attached
, IDirectDrawSurface7
);
219 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
221 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
226 /* Now destroy the surface. Wait: It could have been released if we are a texture */
227 if(This
->WineD3DSurface
)
228 IWineD3DSurface_Release(This
->WineD3DSurface
);
230 /* Having a texture handle set implies that the device still exists */
233 This
->ddraw
->d3ddevice
->Handles
[This
->Handle
- 1].ptr
= NULL
;
234 This
->ddraw
->d3ddevice
->Handles
[This
->Handle
- 1].type
= DDrawHandle_Unknown
;
237 /* Reduce the ddraw surface count */
238 InterlockedDecrement(&This
->ddraw
->surfaces
);
239 list_remove(&This
->surface_list_entry
);
241 HeapFree(GetProcessHeap(), 0, This
);
244 /*****************************************************************************
245 * IDirectDrawSurface7::Release
247 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
248 * surface is destroyed.
250 * Destroying the surface is a bit tricky. For the connection between
251 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
252 * It has a nice graph explaining the connection.
254 * What happens here is basically this:
255 * When a surface is destroyed, its WineD3DSurface is released,
256 * and the refcount of the DirectDraw interface is reduced by 1. If it has
257 * complex surfaces attached to it, then these surfaces are destroyed too,
258 * regardless of their refcount. If any surface being destroyed has another
259 * surface attached to it (with a "soft" attachment, not complex), then
260 * this surface is detached with DeleteAttachedSurface.
262 * When the surface is a texture, the WineD3DTexture is released.
263 * If the surface is the Direct3D render target, then the D3D
264 * capabilities of the WineD3DDevice are uninitialized, which causes the
265 * swapchain to be released.
267 * When a complex sublevel falls to ref zero, then this is ignored.
272 *****************************************************************************/
274 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7
*iface
)
276 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
278 TRACE("(%p) : Releasing from %d\n", This
, This
->ref
);
279 ref
= InterlockedDecrement(&This
->ref
);
284 IDirectDrawSurfaceImpl
*surf
;
285 IDirectDrawImpl
*ddraw
;
286 IUnknown
*ifaceToRelease
= This
->ifaceToRelease
;
289 /* Complex attached surfaces are destroyed implicitely when the root is released */
290 EnterCriticalSection(&ddraw_cs
);
291 if(!This
->is_complex_root
)
293 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
294 LeaveCriticalSection(&ddraw_cs
);
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 IWineD3DBaseTexture_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
);
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
);
410 LeaveCriticalSection(&ddraw_cs
);
416 /*****************************************************************************
417 * IDirectDrawSurface7::GetAttachedSurface
419 * Returns an attached surface with the requested caps. Surface attachment
420 * and complex surfaces are not clearly described by the MSDN or sdk,
421 * so this method is tricky and likely to contain problems.
422 * This implementation searches the complex list first, then the
425 * The chains are searched from This down to the last surface in the chain,
426 * not from the first element in the chain. The first surface found is
427 * returned. The MSDN says that this method fails if more than one surface
428 * matches the caps, but it is not sure if that is right. The attachment
429 * structure may not even allow two matching surfaces.
431 * The found surface is AddRef-ed before it is returned.
434 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
435 * Surface: Address to store the found surface
439 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
440 * DDERR_NOTFOUND if no surface was found
442 *****************************************************************************/
443 static HRESULT WINAPI
444 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7
*iface
,
446 IDirectDrawSurface7
**Surface
)
448 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
449 IDirectDrawSurfaceImpl
*surf
;
453 TRACE("(%p)->(%p,%p)\n", This
, Caps
, Surface
);
454 EnterCriticalSection(&ddraw_cs
);
458 if(This
->version
< 7)
460 /* Earlier dx apps put garbage into these members, clear them */
461 our_caps
.dwCaps2
= 0;
462 our_caps
.dwCaps3
= 0;
463 our_caps
.dwCaps4
= 0;
466 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 */
468 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
470 surf
= This
->complex_array
[i
];
475 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
476 surf
->surface_desc
.ddsCaps
.dwCaps
,
477 surf
->surface_desc
.ddsCaps
.dwCaps2
,
478 surf
->surface_desc
.ddsCaps
.dwCaps3
,
479 surf
->surface_desc
.ddsCaps
.dwCaps4
);
482 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
483 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
485 /* MSDN: "This method fails if more than one surface is attached
486 * that matches the capabilities requested."
488 * Not sure how to test this.
491 TRACE("(%p): Returning surface %p\n", This
, surf
);
492 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
493 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
494 IDirectDrawSurface7_AddRef(*Surface
);
495 LeaveCriticalSection(&ddraw_cs
);
500 /* Next, look at the attachment chain */
503 while( (surf
= surf
->next_attached
) )
507 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
508 surf
->surface_desc
.ddsCaps
.dwCaps
,
509 surf
->surface_desc
.ddsCaps
.dwCaps2
,
510 surf
->surface_desc
.ddsCaps
.dwCaps3
,
511 surf
->surface_desc
.ddsCaps
.dwCaps4
);
514 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
515 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
517 TRACE("(%p): Returning surface %p\n", This
, surf
);
518 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
519 IDirectDrawSurface7_AddRef(*Surface
);
520 LeaveCriticalSection(&ddraw_cs
);
525 TRACE("(%p) Didn't find a valid surface\n", This
);
526 LeaveCriticalSection(&ddraw_cs
);
527 return DDERR_NOTFOUND
;
530 /*****************************************************************************
531 * IDirectDrawSurface7::Lock
533 * Locks the surface and returns a pointer to the surface's memory
536 * Rect: Rectangle to lock. If NULL, the whole surface is locked
537 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
538 * Flags: Locking flags, e.g Read only or write only
539 * h: An event handle that's not used and must be NULL
543 * DDERR_INVALIDPARAMS if DDSD is NULL
544 * For more details, see IWineD3DSurface::LockRect
546 *****************************************************************************/
547 static HRESULT WINAPI
548 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7
*iface
,
550 DDSURFACEDESC2
*DDSD
,
554 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
555 WINED3DLOCKED_RECT LockedRect
;
557 TRACE("(%p)->(%p,%p,%x,%p)\n", This
, Rect
, DDSD
, Flags
, h
);
560 return DDERR_INVALIDPARAMS
;
562 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
563 EnterCriticalSection(&ddraw_cs
);
568 || (Rect
->left
> Rect
->right
)
569 || (Rect
->top
> Rect
->bottom
)
570 || (Rect
->right
> This
->surface_desc
.dwWidth
)
571 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
573 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
574 LeaveCriticalSection(&ddraw_cs
);
575 return DDERR_INVALIDPARAMS
;
579 /* Should I check for the handle to be NULL?
581 * The DDLOCK flags and the D3DLOCK flags are equal
582 * for the supported values. The others are ignored by WineD3D
585 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
586 * that means it doesn't have dwSize set. Init it to some sane
589 if(DDSD
->dwSize
<= sizeof(DDSURFACEDESC
))
591 DDSD
->dwSize
= sizeof(DDSURFACEDESC
);
595 DDSD
->dwSize
= sizeof(DDSURFACEDESC2
);
598 hr
= IWineD3DSurface_LockRect(This
->WineD3DSurface
,
604 LeaveCriticalSection(&ddraw_cs
);
608 /* Override the memory area. The pitch should be set already. Strangely windows
609 * does not set the LPSURFACE flag on locked surfaces !?!.
610 * DDSD->dwFlags |= DDSD_LPSURFACE;
612 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
613 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
615 TRACE("locked surface returning description :\n");
616 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
618 LeaveCriticalSection(&ddraw_cs
);
622 /*****************************************************************************
623 * IDirectDrawSurface7::Unlock
625 * Unlocks an locked surface
628 * Rect: Not used by this implementation
632 * For more details, see IWineD3DSurface::UnlockRect
634 *****************************************************************************/
635 static HRESULT WINAPI
636 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7
*iface
,
639 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
641 TRACE("(%p)->(%p)\n", This
, pRect
);
643 EnterCriticalSection(&ddraw_cs
);
644 hr
= IWineD3DSurface_UnlockRect(This
->WineD3DSurface
);
647 This
->surface_desc
.lpSurface
= NULL
;
649 LeaveCriticalSection(&ddraw_cs
);
653 /*****************************************************************************
654 * IDirectDrawSurface7::Flip
656 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
657 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
658 * the flip target is passed to WineD3D, even if the app didn't specify one
661 * DestOverride: Specifies the surface that will become the new front
662 * buffer. If NULL, the current back buffer is used
663 * Flags: some DirectDraw flags, see include/ddraw.h
667 * DDERR_NOTFLIPPABLE if no flip target could be found
668 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
669 * For more details, see IWineD3DSurface::Flip
671 *****************************************************************************/
672 static HRESULT WINAPI
673 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7
*iface
,
674 IDirectDrawSurface7
*DestOverride
,
677 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
678 IDirectDrawSurfaceImpl
*Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DestOverride
);
679 IDirectDrawSurface7
*Override7
;
681 TRACE("(%p)->(%p,%x)\n", This
, DestOverride
, Flags
);
683 /* Flip has to be called from a front buffer
684 * What about overlay surfaces, AFAIK they can flip too?
686 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
) )
687 return DDERR_INVALIDOBJECT
; /* Unckecked */
689 EnterCriticalSection(&ddraw_cs
);
691 /* WineD3D doesn't keep track of attached surface, so find the target */
696 memset(&Caps
, 0, sizeof(Caps
));
697 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
698 hr
= IDirectDrawSurface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
701 ERR("Can't find a flip target\n");
702 LeaveCriticalSection(&ddraw_cs
);
703 return DDERR_NOTFLIPPABLE
; /* Unchecked */
705 Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Override7
);
707 /* For the GetAttachedSurface */
708 IDirectDrawSurface7_Release(Override7
);
711 hr
= IWineD3DSurface_Flip(This
->WineD3DSurface
,
712 Override
->WineD3DSurface
,
714 LeaveCriticalSection(&ddraw_cs
);
718 /*****************************************************************************
719 * IDirectDrawSurface7::Blt
721 * Performs a blit on the surface
724 * DestRect: Destination rectangle, can be NULL
725 * SrcSurface: Source surface, can be NULL
726 * SrcRect: Source rectange, can be NULL
728 * DDBltFx: Some extended blt parameters, connected to the flags
732 * See IWineD3DSurface::Blt for more details
734 *****************************************************************************/
735 static HRESULT WINAPI
736 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7
*iface
,
738 IDirectDrawSurface7
*SrcSurface
,
743 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
745 IDirectDrawSurfaceImpl
*Src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, SrcSurface
);
746 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This
, DestRect
, Src
, SrcRect
, Flags
, DDBltFx
);
748 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
749 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
751 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
752 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
753 return DDERR_INVALIDPARAMS
;
756 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
757 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
758 return DDERR_INVALIDPARAMS
;
761 EnterCriticalSection(&ddraw_cs
);
762 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
763 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
764 LeaveCriticalSection(&ddraw_cs
);
765 return DDERR_INVALIDPARAMS
;
768 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
769 * and replace the ddraw surfaces with the wined3d surfaces
770 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
772 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
,
774 Src
? Src
->WineD3DSurface
: NULL
,
777 (WINEDDBLTFX
*) DDBltFx
,
780 LeaveCriticalSection(&ddraw_cs
);
783 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
784 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
789 /*****************************************************************************
790 * IDirectDrawSurface7::AddAttachedSurface
792 * Attaches a surface to another surface. How the surface attachments work
793 * is not totally understood yet, and this method is prone to problems.
794 * he surface that is attached is AddRef-ed.
796 * Tests with complex surfaces suggest that the surface attachments form a
797 * tree, but no method to test this has been found yet.
799 * The attachment list consists of a first surface (first_attached) and
800 * for each surface a pointer to the next attached surface (next_attached).
801 * For the first surface, and a surface that has no attachments
802 * first_attached points to the surface itself. A surface that has
803 * no successors in the chain has next_attached set to NULL.
805 * Newly attached surfaces are attached right after the root surface.
806 * If a surface is attached to a complex surface compound, it's attached to
807 * the surface that the app requested, not the complex root. See
808 * GetAttachedSurface for a description how surfaces are found.
810 * This is how the current implementation works, and it was coded by looking
811 * at the needs of the applications.
813 * So far only Z-Buffer attachments are tested, and they are activated in
814 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
815 * Back buffers should work in 2D mode, but they are not tested(They can be
816 * attached in older iface versions). Rendering to the front buffer and
817 * switching between that and double buffering is not yet implemented in
818 * WineD3D, so for 3D it might have unexpected results.
820 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
821 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
822 * performs additional checks. Version 7 of this interface is much more restrictive
823 * than its predecessors.
826 * Attach: Surface to attach to iface
830 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
832 *****************************************************************************/
834 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl
*This
,
835 IDirectDrawSurfaceImpl
*Surf
)
837 TRACE("(%p)->(%p)\n", This
, Surf
);
840 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
842 EnterCriticalSection(&ddraw_cs
);
844 /* Check if the surface is already attached somewhere */
845 if( (Surf
->next_attached
!= NULL
) ||
846 (Surf
->first_attached
!= Surf
) )
848 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
849 * What happens if one surface is attached to 2 different surfaces?
851 FIXME("(%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
);
852 LeaveCriticalSection(&ddraw_cs
);
853 return DDERR_SURFACEALREADYATTACHED
;
856 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
857 Surf
->next_attached
= This
->next_attached
;
858 Surf
->first_attached
= This
->first_attached
;
859 This
->next_attached
= Surf
;
861 /* Check if the WineD3D depth stencil needs updating */
862 if(This
->ddraw
->d3ddevice
)
864 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
868 * "This method increments the reference count of the surface being attached."
870 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(Surf
, IDirectDrawSurface7
));
871 LeaveCriticalSection(&ddraw_cs
);
875 static HRESULT WINAPI
876 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7
*iface
,
877 IDirectDrawSurface7
*Attach
)
879 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
880 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
882 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
883 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
886 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
887 Surf
->surface_desc
.ddsCaps
.dwCaps
);
888 return DDERR_CANNOTATTACHSURFACE
;
891 return IDirectDrawSurfaceImpl_AddAttachedSurface(This
,
894 /*****************************************************************************
895 * IDirectDrawSurface7::DeleteAttachedSurface
897 * Removes a surface from the attachment chain. The surface's refcount
898 * is decreased by one after it has been removed
901 * Flags: Some flags, not used by this implementation
902 * Attach: Surface to detach
906 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
908 *****************************************************************************/
909 static HRESULT WINAPI
910 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
912 IDirectDrawSurface7
*Attach
)
914 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
915 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
916 IDirectDrawSurfaceImpl
*Prev
= This
;
917 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, Surf
);
919 EnterCriticalSection(&ddraw_cs
);
920 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
922 LeaveCriticalSection(&ddraw_cs
);
923 return DDERR_CANNOTDETACHSURFACE
;
926 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
927 if (This
->surface_desc
.ddsCaps
.dwCaps
&
928 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
930 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
931 /* FIXME: we should probably also subtract from dwMipMapCount of this
932 * and all parent surfaces */
935 /* Find the predecessor of the detached surface */
938 if(Prev
->next_attached
== Surf
) break;
939 Prev
= Prev
->next_attached
;
942 /* There must be a surface, otherwise there's a bug */
943 assert(Prev
!= NULL
);
945 /* Unchain the surface */
946 Prev
->next_attached
= Surf
->next_attached
;
947 Surf
->next_attached
= NULL
;
948 Surf
->first_attached
= Surf
;
950 /* Check if the WineD3D depth stencil needs updating */
951 if(This
->ddraw
->d3ddevice
)
953 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
956 IDirectDrawSurface7_Release(Attach
);
957 LeaveCriticalSection(&ddraw_cs
);
961 /*****************************************************************************
962 * IDirectDrawSurface7::AddOverlayDirtyRect
964 * "This method is not currently implemented"
972 *****************************************************************************/
973 static HRESULT WINAPI
974 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
,
977 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
978 TRACE("(%p)->(%p)\n",This
,Rect
);
980 /* MSDN says it's not implemented. I could forward it to WineD3D,
981 * then we'd implement it, but I don't think that's a good idea
985 return IWineD3DSurface_AddOverlayDirtyRect(This
->WineD3DSurface
, pRect
);
987 return DDERR_UNSUPPORTED
; /* unchecked */
990 /*****************************************************************************
991 * IDirectDrawSurface7::GetDC
993 * Returns a GDI device context for the surface
996 * hdc: Address of a HDC variable to store the dc to
1000 * DDERR_INVALIDPARAMS if hdc is NULL
1001 * For details, see IWineD3DSurface::GetDC
1003 *****************************************************************************/
1004 static HRESULT WINAPI
1005 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7
*iface
,
1008 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1010 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1013 return DDERR_INVALIDPARAMS
;
1015 EnterCriticalSection(&ddraw_cs
);
1016 hr
= IWineD3DSurface_GetDC(This
->WineD3DSurface
,
1018 LeaveCriticalSection(&ddraw_cs
);
1022 /*****************************************************************************
1023 * IDirectDrawSurface7::ReleaseDC
1025 * Releases the DC that was constructed with GetDC
1028 * hdc: HDC to release
1032 * For more details, see IWineD3DSurface::ReleaseDC
1034 *****************************************************************************/
1035 static HRESULT WINAPI
1036 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7
*iface
,
1039 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1041 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1043 EnterCriticalSection(&ddraw_cs
);
1044 hr
= IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
1045 LeaveCriticalSection(&ddraw_cs
);
1049 /*****************************************************************************
1050 * IDirectDrawSurface7::GetCaps
1052 * Returns the surface's caps
1055 * Caps: Address to write the caps to
1059 * DDERR_INVALIDPARAMS if Caps is NULL
1061 *****************************************************************************/
1062 static HRESULT WINAPI
1063 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7
*iface
,
1066 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1067 TRACE("(%p)->(%p)\n",This
,Caps
);
1070 return DDERR_INVALIDPARAMS
;
1072 *Caps
= This
->surface_desc
.ddsCaps
;
1076 /*****************************************************************************
1077 * IDirectDrawSurface7::SetPriority
1079 * Sets a texture priority for managed textures.
1082 * Priority: The new priority
1086 * For more details, see IWineD3DSurface::SetPriority
1088 *****************************************************************************/
1089 static HRESULT WINAPI
1090 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1092 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1094 TRACE("(%p)->(%d): Relay!\n",This
,Priority
);
1096 EnterCriticalSection(&ddraw_cs
);
1097 hr
= IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1098 LeaveCriticalSection(&ddraw_cs
);
1102 /*****************************************************************************
1103 * IDirectDrawSurface7::GetPriority
1105 * Returns the surface's priority
1108 * Priority: Address of a variable to write the priority to
1112 * DDERR_INVALIDPARAMS if Priority == NULL
1113 * For more details, see IWineD3DSurface::GetPriority
1115 *****************************************************************************/
1116 static HRESULT WINAPI
1117 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7
*iface
,
1120 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1121 TRACE("(%p)->(%p): Relay\n",This
,Priority
);
1125 return DDERR_INVALIDPARAMS
;
1128 EnterCriticalSection(&ddraw_cs
);
1129 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1130 LeaveCriticalSection(&ddraw_cs
);
1134 /*****************************************************************************
1135 * IDirectDrawSurface7::SetPrivateData
1137 * Stores some data in the surface that is intended for the application's
1141 * tag: GUID that identifies the data
1142 * Data: Pointer to the private data
1143 * Size: Size of the private data
1148 * For more details, see IWineD3DSurface::SetPrivateData
1150 *****************************************************************************/
1151 static HRESULT WINAPI
1152 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7
*iface
,
1158 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1160 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This
, debugstr_guid(tag
), Data
, Size
, Flags
);
1162 EnterCriticalSection(&ddraw_cs
);
1163 hr
= IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1168 LeaveCriticalSection(&ddraw_cs
);
1171 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1176 /*****************************************************************************
1177 * IDirectDrawSurface7::GetPrivateData
1179 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1182 * tag: GUID of the data to return
1183 * Data: Address where to write the data to
1184 * Size: Size of the buffer at Data
1188 * DDERR_INVALIDPARAMS if Data is NULL
1189 * For more details, see IWineD3DSurface::GetPrivateData
1191 *****************************************************************************/
1192 static HRESULT WINAPI
1193 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7
*iface
,
1198 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1200 TRACE("(%p)->(%s,%p,%p): Relay\n", This
, debugstr_guid(tag
), Data
, Size
);
1203 return DDERR_INVALIDPARAMS
;
1205 EnterCriticalSection(&ddraw_cs
);
1206 hr
= IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1210 LeaveCriticalSection(&ddraw_cs
);
1214 /*****************************************************************************
1215 * IDirectDrawSurface7::FreePrivateData
1217 * Frees private data stored in the surface
1220 * tag: Tag of the data to free
1224 * For more details, see IWineD3DSurface::FreePrivateData
1226 *****************************************************************************/
1227 static HRESULT WINAPI
1228 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7
*iface
,
1231 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1233 TRACE("(%p)->(%s): Relay\n", This
, debugstr_guid(tag
));
1235 EnterCriticalSection(&ddraw_cs
);
1236 hr
= IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1237 LeaveCriticalSection(&ddraw_cs
);
1241 /*****************************************************************************
1242 * IDirectDrawSurface7::PageLock
1244 * Prevents a sysmem surface from being paged out
1247 * Flags: Not used, must be 0(unchecked)
1250 * DD_OK, because it's a stub
1252 *****************************************************************************/
1253 static HRESULT WINAPI
1254 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7
*iface
,
1257 TRACE("(%p)->(%x)\n", iface
, Flags
);
1259 /* This is Windows memory management related - we don't need this */
1263 /*****************************************************************************
1264 * IDirectDrawSurface7::PageUnlock
1266 * Allows a sysmem surface to be paged out
1269 * Flags: Not used, must be 0(unckeched)
1272 * DD_OK, because it's a stub
1274 *****************************************************************************/
1275 static HRESULT WINAPI
1276 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7
*iface
,
1279 TRACE("(%p)->(%x)\n", iface
, Flags
);
1284 /*****************************************************************************
1285 * IDirectDrawSurface7::BltBatch
1287 * An unimplemented function
1295 *****************************************************************************/
1296 static HRESULT WINAPI
IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1298 TRACE("(%p)->(%p,%d,%08x)\n",iface
,Batch
,Count
,Flags
);
1300 /* MSDN: "not currently implemented" */
1301 return DDERR_UNSUPPORTED
;
1304 /*****************************************************************************
1305 * IDirectDrawSurface7::EnumAttachedSurfaces
1307 * Enumerates all surfaces attached to this surface
1310 * context: Pointer to pass unmodified to the callback
1311 * cb: Callback function to call for each surface
1315 * DDERR_INVALIDPARAMS if cb is NULL
1317 *****************************************************************************/
1318 static HRESULT WINAPI
1319 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1321 LPDDENUMSURFACESCALLBACK7 cb
)
1323 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1324 IDirectDrawSurfaceImpl
*surf
;
1325 DDSURFACEDESC2 desc
;
1328 /* Attached surfaces aren't handled in WineD3D */
1329 TRACE("(%p)->(%p,%p)\n",This
,context
,cb
);
1332 return DDERR_INVALIDPARAMS
;
1334 EnterCriticalSection(&ddraw_cs
);
1335 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1337 surf
= This
->complex_array
[i
];
1340 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1341 desc
= surf
->surface_desc
;
1342 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1343 if (cb(ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1345 LeaveCriticalSection(&ddraw_cs
);
1350 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1352 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1353 desc
= surf
->surface_desc
;
1354 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1355 if (cb( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1357 LeaveCriticalSection(&ddraw_cs
);
1362 TRACE(" end of enumeration.\n");
1364 LeaveCriticalSection(&ddraw_cs
);
1368 /*****************************************************************************
1369 * IDirectDrawSurface7::EnumOverlayZOrders
1371 * "Enumerates the overlay surfaces on the specified destination"
1374 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1375 * context: context to pass back to the callback
1376 * cb: callback function to call for each enumerated surface
1379 * DD_OK, because it's a stub
1381 *****************************************************************************/
1382 static HRESULT WINAPI
1383 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1386 LPDDENUMSURFACESCALLBACK7 cb
)
1388 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface
, Flags
, context
, cb
);
1393 /*****************************************************************************
1394 * IDirectDrawSurface7::GetBltStatus
1396 * Returns the blitting status
1399 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1402 * See IWineD3DSurface::Blt
1404 *****************************************************************************/
1405 static HRESULT WINAPI
1406 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7
*iface
,
1409 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1411 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1413 EnterCriticalSection(&ddraw_cs
);
1414 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1415 LeaveCriticalSection(&ddraw_cs
);
1418 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1423 /*****************************************************************************
1424 * IDirectDrawSurface7::GetColorKey
1426 * Returns the color key assigned to the surface
1430 * CKey: Address to store the key to
1434 * DDERR_INVALIDPARAMS if CKey is NULL
1436 *****************************************************************************/
1437 static HRESULT WINAPI
1438 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7
*iface
,
1442 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1443 * isn't there? That's like saying that an int isn't there. (Which MS
1444 * has done in other docs.) */
1445 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1446 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, CKey
);
1449 return DDERR_INVALIDPARAMS
;
1451 EnterCriticalSection(&ddraw_cs
);
1454 case DDCKEY_DESTBLT
:
1455 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1458 case DDCKEY_DESTOVERLAY
:
1459 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1463 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1466 case DDCKEY_SRCOVERLAY
:
1467 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1471 LeaveCriticalSection(&ddraw_cs
);
1472 return DDERR_INVALIDPARAMS
;
1475 LeaveCriticalSection(&ddraw_cs
);
1479 /*****************************************************************************
1480 * IDirectDrawSurface7::GetFlipStatus
1482 * Returns the flipping status of the surface
1485 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1488 * See IWineD3DSurface::GetFlipStatus
1490 *****************************************************************************/
1491 static HRESULT WINAPI
1492 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7
*iface
,
1495 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1497 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1499 EnterCriticalSection(&ddraw_cs
);
1500 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1501 LeaveCriticalSection(&ddraw_cs
);
1504 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1509 /*****************************************************************************
1510 * IDirectDrawSurface7::GetOverlayPosition
1512 * Returns the display coordinates of a visible and active overlay surface
1519 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1520 *****************************************************************************/
1521 static HRESULT WINAPI
1522 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7
*iface
,
1525 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1527 TRACE("(%p)->(%p,%p): Relay\n", This
, X
, Y
);
1529 EnterCriticalSection(&ddraw_cs
);
1530 hr
= IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1533 LeaveCriticalSection(&ddraw_cs
);
1537 /*****************************************************************************
1538 * IDirectDrawSurface7::GetPixelFormat
1540 * Returns the pixel format of the Surface
1543 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1544 * format should be written
1548 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1550 *****************************************************************************/
1551 static HRESULT WINAPI
1552 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7
*iface
,
1553 DDPIXELFORMAT
*PixelFormat
)
1555 /* What is DDERR_INVALIDSURFACETYPE for here? */
1556 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1557 TRACE("(%p)->(%p)\n",This
,PixelFormat
);
1560 return DDERR_INVALIDPARAMS
;
1562 EnterCriticalSection(&ddraw_cs
);
1563 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1564 LeaveCriticalSection(&ddraw_cs
);
1570 /*****************************************************************************
1571 * IDirectDrawSurface7::GetSurfaceDesc
1573 * Returns the description of this surface
1576 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1581 * DDERR_INVALIDPARAMS if DDSD is NULL
1583 *****************************************************************************/
1584 static HRESULT WINAPI
1585 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7
*iface
,
1586 DDSURFACEDESC2
*DDSD
)
1588 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1590 TRACE("(%p)->(%p)\n",This
,DDSD
);
1593 return DDERR_INVALIDPARAMS
;
1595 if ((DDSD
->dwSize
< sizeof(DDSURFACEDESC
)) ||
1596 (DDSD
->dwSize
> sizeof(DDSURFACEDESC2
)))
1598 ERR("Impossible/Strange struct size %d.\n",DDSD
->dwSize
);
1599 return DDERR_GENERIC
;
1602 EnterCriticalSection(&ddraw_cs
);
1603 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1604 TRACE("Returning surface desc:\n");
1605 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1607 LeaveCriticalSection(&ddraw_cs
);
1611 /*****************************************************************************
1612 * IDirectDrawSurface7::Initialize
1614 * Initializes the surface. This is a no-op in Wine
1617 * DD: Pointer to an DirectDraw interface
1618 * DDSD: Surface description for initialization
1621 * DDERR_ALREADYINITIALIZED
1623 *****************************************************************************/
1624 static HRESULT WINAPI
1625 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7
*iface
,
1627 DDSURFACEDESC2
*DDSD
)
1629 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1630 IDirectDrawImpl
*ddimpl
= ICOM_OBJECT(IDirectDrawImpl
, IDirectDraw
, DD
);
1631 TRACE("(%p)->(%p,%p)\n",This
,ddimpl
,DDSD
);
1633 return DDERR_ALREADYINITIALIZED
;
1636 /*****************************************************************************
1637 * IDirectDrawSurface7::IsLost
1639 * Checks if the surface is lost
1642 * DD_OK, if the surface is useable
1643 * DDERR_ISLOST if the surface is lost
1644 * See IWineD3DSurface::IsLost for more details
1646 *****************************************************************************/
1647 static HRESULT WINAPI
1648 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7
*iface
)
1650 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1652 TRACE("(%p)\n", This
);
1654 EnterCriticalSection(&ddraw_cs
);
1655 /* We lose the surface if the implementation was changed */
1656 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1658 /* But this shouldn't happen. When we change the implementation,
1659 * all surfaces are re-created automatically, and their content
1662 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
1663 LeaveCriticalSection(&ddraw_cs
);
1664 return DDERR_SURFACELOST
;
1667 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
1668 LeaveCriticalSection(&ddraw_cs
);
1671 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1672 * WineD3D uses the same error for surfaces
1674 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
1679 /*****************************************************************************
1680 * IDirectDrawSurface7::Restore
1682 * Restores a lost surface. This makes the surface usable again, but
1683 * doesn't reload its old contents
1687 * See IWineD3DSurface::Restore for more details
1689 *****************************************************************************/
1690 static HRESULT WINAPI
1691 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7
*iface
)
1693 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1695 TRACE("(%p)\n", This
);
1697 EnterCriticalSection(&ddraw_cs
);
1698 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1700 /* Call the recreation callback. Make sure to AddRef first */
1701 IDirectDrawSurface_AddRef(iface
);
1702 IDirectDrawImpl_RecreateSurfacesCallback(iface
,
1703 &This
->surface_desc
,
1704 NULL
/* Not needed */);
1706 hr
= IWineD3DSurface_Restore(This
->WineD3DSurface
);
1707 LeaveCriticalSection(&ddraw_cs
);
1711 /*****************************************************************************
1712 * IDirectDrawSurface7::SetOverlayPosition
1714 * Changes the display coordinates of an overlay surface
1721 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1722 *****************************************************************************/
1723 static HRESULT WINAPI
1724 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7
*iface
,
1728 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1730 TRACE("(%p)->(%d,%d): Relay\n", This
, X
, Y
);
1732 EnterCriticalSection(&ddraw_cs
);
1733 hr
= IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
1736 LeaveCriticalSection(&ddraw_cs
);
1740 /*****************************************************************************
1741 * IDirectDrawSurface7::UpdateOverlay
1743 * Modifies the attributes of an overlay surface.
1746 * SrcRect: The section of the source being used for the overlay
1747 * DstSurface: Address of the surface that is overlaid
1748 * DstRect: Place of the overlay
1749 * Flags: some DDOVER_* flags
1752 * DDERR_UNSUPPORTED, because we don't support overlays
1754 *****************************************************************************/
1755 static HRESULT WINAPI
1756 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7
*iface
,
1758 IDirectDrawSurface7
*DstSurface
,
1763 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1764 IDirectDrawSurfaceImpl
*Dst
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DstSurface
);
1766 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This
, SrcRect
, Dst
, DstRect
, Flags
, FX
);
1768 EnterCriticalSection(&ddraw_cs
);
1769 hr
= IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
1771 Dst
? Dst
->WineD3DSurface
: NULL
,
1774 (WINEDDOVERLAYFX
*) FX
);
1775 LeaveCriticalSection(&ddraw_cs
);
1779 /*****************************************************************************
1780 * IDirectDrawSurface7::UpdateOverlayDisplay
1782 * The DX7 sdk says that it's not implemented
1787 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1789 *****************************************************************************/
1790 static HRESULT WINAPI
1791 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
,
1794 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1795 TRACE("(%p)->(%x)\n", This
, Flags
);
1796 return DDERR_UNSUPPORTED
;
1799 /*****************************************************************************
1800 * IDirectDrawSurface7::UpdateOverlayZOrder
1802 * Sets an overlay's Z order
1805 * Flags: DDOVERZ_* flags
1806 * DDSRef: Defines the relative position in the overlay chain
1809 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1811 *****************************************************************************/
1812 static HRESULT WINAPI
1813 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
1815 IDirectDrawSurface7
*DDSRef
)
1817 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1819 IDirectDrawSurfaceImpl
*Ref
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DDSRef
);
1821 TRACE("(%p)->(%x,%p): Relay\n", This
, Flags
, Ref
);
1822 EnterCriticalSection(&ddraw_cs
);
1823 hr
= IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
1825 Ref
? Ref
->WineD3DSurface
: NULL
);
1826 LeaveCriticalSection(&ddraw_cs
);
1830 /*****************************************************************************
1831 * IDirectDrawSurface7::GetDDInterface
1833 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1834 * surface belongs to
1837 * DD: Address to write the interface pointer to
1841 * DDERR_INVALIDPARAMS if DD is NULL
1843 *****************************************************************************/
1844 static HRESULT WINAPI
1845 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7
*iface
,
1848 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1850 TRACE("(%p)->(%p)\n",This
,DD
);
1853 return DDERR_INVALIDPARAMS
;
1855 switch(This
->version
)
1858 *((IDirectDraw7
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw7
);
1859 IDirectDraw7_AddRef(*(IDirectDraw7
**) DD
);
1863 *((IDirectDraw4
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw4
);
1864 IDirectDraw4_AddRef(*(IDirectDraw4
**) DD
);
1868 *((IDirectDraw2
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw2
);
1869 IDirectDraw_AddRef( *(IDirectDraw2
**) DD
);
1873 *((IDirectDraw
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw
);
1874 IDirectDraw_AddRef( *(IDirectDraw
**) DD
);
1882 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1883 static HRESULT WINAPI
IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
1885 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1886 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
1888 TRACE("(%p)\n",This
);
1889 EnterCriticalSection(&ddraw_cs
);
1890 /* A uniqueness value of 0 is apparently special.
1891 * This needs to be checked.
1892 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1895 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
1896 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
1898 if (old_uniqueness_value
== 0) break;
1899 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
1901 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
1902 old_uniqueness_value
,
1903 new_uniqueness_value
)
1904 == old_uniqueness_value
)
1908 LeaveCriticalSection(&ddraw_cs
);
1912 static HRESULT WINAPI
IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7
*iface
, LPDWORD pValue
)
1914 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1916 TRACE("(%p)->(%p)\n",This
,pValue
);
1917 EnterCriticalSection(&ddraw_cs
);
1918 *pValue
= This
->uniqueness_value
;
1919 LeaveCriticalSection(&ddraw_cs
);
1923 /*****************************************************************************
1924 * IDirectDrawSurface7::SetLOD
1926 * Sets the level of detail of a texture
1929 * MaxLOD: LOD to set
1933 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1935 *****************************************************************************/
1936 static HRESULT WINAPI
1937 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7
*iface
,
1940 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1942 TRACE("(%p)->(%d)\n", This
, MaxLOD
);
1944 EnterCriticalSection(&ddraw_cs
);
1945 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
1947 LeaveCriticalSection(&ddraw_cs
);
1948 return DDERR_INVALIDOBJECT
;
1951 if(!This
->wineD3DTexture
)
1953 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
1954 LeaveCriticalSection(&ddraw_cs
);
1955 return DDERR_INVALIDOBJECT
;
1958 hr
= IWineD3DBaseTexture_SetLOD(This
->wineD3DTexture
,
1960 LeaveCriticalSection(&ddraw_cs
);
1964 /*****************************************************************************
1965 * IDirectDrawSurface7::GetLOD
1967 * Returns the level of detail of a Direct3D texture
1970 * MaxLOD: Address to write the LOD to
1974 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1975 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1977 *****************************************************************************/
1978 static HRESULT WINAPI
1979 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7
*iface
,
1982 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1983 TRACE("(%p)->(%p)\n", This
, MaxLOD
);
1986 return DDERR_INVALIDPARAMS
;
1988 EnterCriticalSection(&ddraw_cs
);
1989 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
1991 LeaveCriticalSection(&ddraw_cs
);
1992 return DDERR_INVALIDOBJECT
;
1995 *MaxLOD
= IWineD3DBaseTexture_GetLOD(This
->wineD3DTexture
);
1996 LeaveCriticalSection(&ddraw_cs
);
2000 /*****************************************************************************
2001 * IDirectDrawSurface7::BltFast
2003 * Performs a fast Blit.
2006 * dstx: The x coordinate to blit to on the destination
2007 * dsty: The y coordinate to blit to on the destination
2008 * Source: The source surface
2009 * rsrc: The source rectangle
2010 * trans: Type of transfer. Some DDBLTFAST_* flags
2014 * For more details, see IWineD3DSurface::BltFast
2016 *****************************************************************************/
2017 static HRESULT WINAPI
2018 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7
*iface
,
2021 IDirectDrawSurface7
*Source
,
2025 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2027 IDirectDrawSurfaceImpl
*src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Source
);
2028 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This
, dstx
, dsty
, Source
, rsrc
, trans
);
2030 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2035 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
2036 rsrc
->right
> src
->surface_desc
.dwWidth
||
2037 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
2039 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2040 return DDERR_INVALIDRECT
;
2042 if(dstx
+ rsrc
->right
- rsrc
->left
> This
->surface_desc
.dwWidth
||
2043 dsty
+ rsrc
->bottom
- rsrc
->top
> This
->surface_desc
.dwHeight
)
2045 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2046 return DDERR_INVALIDRECT
;
2051 if(dstx
+ src
->surface_desc
.dwWidth
> This
->surface_desc
.dwWidth
||
2052 dsty
+ src
->surface_desc
.dwHeight
> This
->surface_desc
.dwHeight
)
2054 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2055 return DDERR_INVALIDRECT
;
2059 EnterCriticalSection(&ddraw_cs
);
2060 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
2062 src
? src
->WineD3DSurface
: NULL
,
2065 LeaveCriticalSection(&ddraw_cs
);
2068 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
2069 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
2074 /*****************************************************************************
2075 * IDirectDrawSurface7::GetClipper
2077 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2081 * Clipper: Address to store the interface pointer at
2085 * DDERR_INVALIDPARAMS if Clipper is NULL
2086 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2088 *****************************************************************************/
2089 static HRESULT WINAPI
2090 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7
*iface
,
2091 IDirectDrawClipper
**Clipper
)
2093 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2094 TRACE("(%p)->(%p)\n", This
, Clipper
);
2098 LeaveCriticalSection(&ddraw_cs
);
2099 return DDERR_INVALIDPARAMS
;
2102 EnterCriticalSection(&ddraw_cs
);
2103 if(This
->clipper
== NULL
)
2105 LeaveCriticalSection(&ddraw_cs
);
2106 return DDERR_NOCLIPPERATTACHED
;
2109 *Clipper
= ICOM_INTERFACE(This
->clipper
, IDirectDrawClipper
);
2110 IDirectDrawClipper_AddRef(*Clipper
);
2111 LeaveCriticalSection(&ddraw_cs
);
2115 /*****************************************************************************
2116 * IDirectDrawSurface7::SetClipper
2118 * Sets a clipper for the surface
2121 * Clipper: IDirectDrawClipper interface of the clipper to set
2126 *****************************************************************************/
2127 static HRESULT WINAPI
2128 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7
*iface
,
2129 IDirectDrawClipper
*Clipper
)
2131 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2132 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
2134 TRACE("(%p)->(%p)\n",This
,Clipper
);
2136 EnterCriticalSection(&ddraw_cs
);
2137 if (ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
) == This
->clipper
)
2139 LeaveCriticalSection(&ddraw_cs
);
2143 This
->clipper
= ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
);
2145 if (Clipper
!= NULL
)
2146 IDirectDrawClipper_AddRef(Clipper
);
2148 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper
, IDirectDrawClipper
));
2150 hr
= IWineD3DSurface_SetClipper(This
->WineD3DSurface
, This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
2151 LeaveCriticalSection(&ddraw_cs
);
2155 /*****************************************************************************
2156 * IDirectDrawSurface7::SetSurfaceDesc
2158 * Sets the surface description. It can override the pixel format, the surface
2160 * It's not really tested.
2163 * DDSD: Pointer to the new surface description to set
2168 * DDERR_INVALIDPARAMS if DDSD is NULL
2170 *****************************************************************************/
2171 static HRESULT WINAPI
2172 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7
*iface
,
2173 DDSURFACEDESC2
*DDSD
,
2176 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2177 WINED3DFORMAT newFormat
= WINED3DFMT_UNKNOWN
;
2179 TRACE("(%p)->(%p,%x)\n", This
, DDSD
, Flags
);
2182 return DDERR_INVALIDPARAMS
;
2184 EnterCriticalSection(&ddraw_cs
);
2185 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2187 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2189 if(newFormat
== WINED3DFMT_UNKNOWN
)
2191 ERR("Requested to set an unknown pixelformat\n");
2192 LeaveCriticalSection(&ddraw_cs
);
2193 return DDERR_INVALIDPARAMS
;
2195 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2197 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2201 LeaveCriticalSection(&ddraw_cs
);
2206 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2208 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2210 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2212 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2214 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2216 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2218 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2220 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2222 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2224 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2226 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2228 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2230 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
2232 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2233 if(hr
!= WINED3D_OK
)
2235 /* No need for a trace here, wined3d does that for us */
2236 LeaveCriticalSection(&ddraw_cs
);
2239 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2240 default: break; /* Go on */
2246 This
->surface_desc
= *DDSD
;
2248 LeaveCriticalSection(&ddraw_cs
);
2252 /*****************************************************************************
2253 * IDirectDrawSurface7::GetPalette
2255 * Returns the IDirectDrawPalette interface of the palette currently assigned
2259 * Pal: Address to write the interface pointer to
2263 * DDERR_INVALIDPARAMS if Pal is NULL
2265 *****************************************************************************/
2266 static HRESULT WINAPI
2267 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7
*iface
,
2268 IDirectDrawPalette
**Pal
)
2270 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2271 IWineD3DPalette
*wPal
;
2273 TRACE("(%p)->(%p): Relay\n", This
, Pal
);
2276 return DDERR_INVALIDPARAMS
;
2278 EnterCriticalSection(&ddraw_cs
);
2279 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wPal
);
2282 LeaveCriticalSection(&ddraw_cs
);
2288 hr
= IWineD3DPalette_GetParent(wPal
, (IUnknown
**) Pal
);
2293 hr
= DDERR_NOPALETTEATTACHED
;
2296 LeaveCriticalSection(&ddraw_cs
);
2300 /*****************************************************************************
2303 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2304 * recursively in the surface tree
2306 *****************************************************************************/
2310 WINEDDCOLORKEY
*CKey
;
2314 static HRESULT WINAPI
2315 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2316 DDSURFACEDESC2
*desc
,
2319 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2320 struct SCKContext
*ctx
= context
;
2323 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2328 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2332 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
2335 IDirectDrawSurface7_Release(surface
);
2336 return DDENUMRET_OK
;
2339 /*****************************************************************************
2340 * IDirectDrawSurface7::SetColorKey
2342 * Sets the color keying options for the surface. Observations showed that
2343 * in case of complex surfaces the color key has to be assigned to all
2348 * CKey: The new color key
2352 * See IWineD3DSurface::SetColorKey for details
2354 *****************************************************************************/
2355 static HRESULT WINAPI
2356 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7
*iface
,
2360 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2361 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) CKey
, Flags
};
2362 TRACE("(%p)->(%x,%p)\n", This
, Flags
, CKey
);
2364 EnterCriticalSection(&ddraw_cs
);
2367 switch (Flags
& ~DDCKEY_COLORSPACE
)
2369 case DDCKEY_DESTBLT
:
2370 This
->surface_desc
.ddckCKDestBlt
= *CKey
;
2371 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2374 case DDCKEY_DESTOVERLAY
:
2375 This
->surface_desc
.u3
.ddckCKDestOverlay
= *CKey
;
2376 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2379 case DDCKEY_SRCOVERLAY
:
2380 This
->surface_desc
.ddckCKSrcOverlay
= *CKey
;
2381 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2385 This
->surface_desc
.ddckCKSrcBlt
= *CKey
;
2386 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2390 LeaveCriticalSection(&ddraw_cs
);
2391 return DDERR_INVALIDPARAMS
;
2396 switch (Flags
& ~DDCKEY_COLORSPACE
)
2398 case DDCKEY_DESTBLT
:
2399 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2402 case DDCKEY_DESTOVERLAY
:
2403 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2406 case DDCKEY_SRCOVERLAY
:
2407 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2411 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2415 LeaveCriticalSection(&ddraw_cs
);
2416 return DDERR_INVALIDPARAMS
;
2419 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2422 IDirectDrawSurface7_EnumAttachedSurfaces(iface
,
2425 LeaveCriticalSection(&ddraw_cs
);
2428 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2429 default: return ctx
.ret
;
2433 /*****************************************************************************
2434 * IDirectDrawSurface7::SetPalette
2436 * Assigns a DirectDrawPalette object to the surface
2439 * Pal: Interface to the palette to set
2444 *****************************************************************************/
2445 static HRESULT WINAPI
2446 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7
*iface
,
2447 IDirectDrawPalette
*Pal
)
2449 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2450 IDirectDrawPalette
*oldPal
;
2451 IDirectDrawSurfaceImpl
*surf
;
2452 IDirectDrawPaletteImpl
*PalImpl
= ICOM_OBJECT(IDirectDrawPaletteImpl
, IDirectDrawPalette
, Pal
);
2454 TRACE("(%p)->(%p)\n", This
, Pal
);
2456 /* Find the old palette */
2457 EnterCriticalSection(&ddraw_cs
);
2458 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2459 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
2461 LeaveCriticalSection(&ddraw_cs
);
2464 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2466 /* Set the new Palette */
2467 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2468 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2469 /* AddRef the Palette */
2470 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2472 /* Release the old palette */
2473 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2475 /* If this is a front buffer, also update the back buffers
2476 * TODO: How do things work for palettized cube textures?
2478 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2480 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2481 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2486 IDirectDrawSurface7
*attach
;
2488 hr
= IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
2495 TRACE("Setting palette on %p\n", attach
);
2496 IDirectDrawSurface7_SetPalette(attach
,
2498 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attach
);
2499 IDirectDrawSurface7_Release(attach
);
2503 LeaveCriticalSection(&ddraw_cs
);
2507 /*****************************************************************************
2509 *****************************************************************************/
2511 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
=
2514 IDirectDrawSurfaceImpl_QueryInterface
,
2515 IDirectDrawSurfaceImpl_AddRef
,
2516 IDirectDrawSurfaceImpl_Release
,
2517 /*** IDirectDrawSurface ***/
2518 IDirectDrawSurface7Impl_AddAttachedSurface
,
2519 IDirectDrawSurfaceImpl_AddOverlayDirtyRect
,
2520 IDirectDrawSurfaceImpl_Blt
,
2521 IDirectDrawSurfaceImpl_BltBatch
,
2522 IDirectDrawSurfaceImpl_BltFast
,
2523 IDirectDrawSurfaceImpl_DeleteAttachedSurface
,
2524 IDirectDrawSurfaceImpl_EnumAttachedSurfaces
,
2525 IDirectDrawSurfaceImpl_EnumOverlayZOrders
,
2526 IDirectDrawSurfaceImpl_Flip
,
2527 IDirectDrawSurfaceImpl_GetAttachedSurface
,
2528 IDirectDrawSurfaceImpl_GetBltStatus
,
2529 IDirectDrawSurfaceImpl_GetCaps
,
2530 IDirectDrawSurfaceImpl_GetClipper
,
2531 IDirectDrawSurfaceImpl_GetColorKey
,
2532 IDirectDrawSurfaceImpl_GetDC
,
2533 IDirectDrawSurfaceImpl_GetFlipStatus
,
2534 IDirectDrawSurfaceImpl_GetOverlayPosition
,
2535 IDirectDrawSurfaceImpl_GetPalette
,
2536 IDirectDrawSurfaceImpl_GetPixelFormat
,
2537 IDirectDrawSurfaceImpl_GetSurfaceDesc
,
2538 IDirectDrawSurfaceImpl_Initialize
,
2539 IDirectDrawSurfaceImpl_IsLost
,
2540 IDirectDrawSurfaceImpl_Lock
,
2541 IDirectDrawSurfaceImpl_ReleaseDC
,
2542 IDirectDrawSurfaceImpl_Restore
,
2543 IDirectDrawSurfaceImpl_SetClipper
,
2544 IDirectDrawSurfaceImpl_SetColorKey
,
2545 IDirectDrawSurfaceImpl_SetOverlayPosition
,
2546 IDirectDrawSurfaceImpl_SetPalette
,
2547 IDirectDrawSurfaceImpl_Unlock
,
2548 IDirectDrawSurfaceImpl_UpdateOverlay
,
2549 IDirectDrawSurfaceImpl_UpdateOverlayDisplay
,
2550 IDirectDrawSurfaceImpl_UpdateOverlayZOrder
,
2551 /*** IDirectDrawSurface2 ***/
2552 IDirectDrawSurfaceImpl_GetDDInterface
,
2553 IDirectDrawSurfaceImpl_PageLock
,
2554 IDirectDrawSurfaceImpl_PageUnlock
,
2555 /*** IDirectDrawSurface3 ***/
2556 IDirectDrawSurfaceImpl_SetSurfaceDesc
,
2557 /*** IDirectDrawSurface4 ***/
2558 IDirectDrawSurfaceImpl_SetPrivateData
,
2559 IDirectDrawSurfaceImpl_GetPrivateData
,
2560 IDirectDrawSurfaceImpl_FreePrivateData
,
2561 IDirectDrawSurfaceImpl_GetUniquenessValue
,
2562 IDirectDrawSurfaceImpl_ChangeUniquenessValue
,
2563 /*** IDirectDrawSurface7 ***/
2564 IDirectDrawSurfaceImpl_SetPriority
,
2565 IDirectDrawSurfaceImpl_GetPriority
,
2566 IDirectDrawSurfaceImpl_SetLOD
,
2567 IDirectDrawSurfaceImpl_GetLOD