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
)||
114 IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
) )
116 IDirect3DDevice7
*d3d
;
118 /* Call into IDirect3D7 for creation */
119 IDirect3D7_CreateDevice(ICOM_INTERFACE(This
->ddraw
, IDirect3D7
),
121 ICOM_INTERFACE(This
, IDirectDrawSurface7
),
124 *obj
= COM_INTERFACE_CAST(IDirect3DDeviceImpl
, IDirect3DDevice7
, IDirect3DDevice
, d3d
);
125 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
129 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
130 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
132 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
134 *obj
= ICOM_INTERFACE(This
, IDirect3DTexture
);
135 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
139 *obj
= ICOM_INTERFACE(This
, IDirect3DTexture2
);
140 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
142 IUnknown_AddRef( (IUnknown
*) *obj
);
146 ERR("No interface\n");
147 return E_NOINTERFACE
;
150 /*****************************************************************************
151 * IDirectDrawSurface7::AddRef
153 * A normal addref implementation
158 *****************************************************************************/
160 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7
*iface
)
162 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
163 ULONG refCount
= InterlockedIncrement(&This
->ref
);
165 TRACE("(%p) : AddRef increasing from %d\n", This
, refCount
- 1);
169 /*****************************************************************************
170 * IDirectDrawSurfaceImpl_Destroy
172 * A helper function for IDirectDrawSurface7::Release
174 * Frees the surface, regardless of its refcount.
175 * See IDirectDrawSurface7::Release for more information
178 * This: Surface to free
180 *****************************************************************************/
181 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl
*This
)
183 TRACE("(%p)\n", This
);
185 /* Check the refcount and give a warning */
188 /* This can happen when a complex surface is destroyed,
189 * because the 2nd surface was addref()ed when the app
190 * called GetAttachedSurface
192 WARN("(%p): Destroying surface with refount %d\n", This
, This
->ref
);
195 /* Check for attached surfaces and detach them */
196 if(This
->first_attached
!= This
)
198 /* Well, this shouldn't happen: The surface being attached is addref()ed
199 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
200 * is called, because the refcount is held. It looks like the app released()
201 * it often enough to force this
203 IDirectDrawSurface7
*root
= ICOM_INTERFACE(This
->first_attached
, IDirectDrawSurface7
);
204 IDirectDrawSurface7
*detach
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
206 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This
, This
->first_attached
);
208 /* The refcount will drop to -1 here */
209 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
211 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
215 while(This
->next_attached
!= NULL
)
217 IDirectDrawSurface7
*root
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
218 IDirectDrawSurface7
*detach
= ICOM_INTERFACE(This
->next_attached
, IDirectDrawSurface7
);
220 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
222 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
227 /* Now destroy the surface. Wait: It could have been released if we are a texture */
228 if(This
->WineD3DSurface
)
229 IWineD3DSurface_Release(This
->WineD3DSurface
);
231 /* Having a texture handle set implies that the device still exists */
234 This
->ddraw
->d3ddevice
->Handles
[This
->Handle
- 1].ptr
= NULL
;
235 This
->ddraw
->d3ddevice
->Handles
[This
->Handle
- 1].type
= DDrawHandle_Unknown
;
238 /* Reduce the ddraw surface count */
239 InterlockedDecrement(&This
->ddraw
->surfaces
);
240 list_remove(&This
->surface_list_entry
);
242 HeapFree(GetProcessHeap(), 0, This
);
245 /*****************************************************************************
246 * IDirectDrawSurface7::Release
248 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
249 * surface is destroyed.
251 * Destroying the surface is a bit tricky. For the connection between
252 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
253 * It has a nice graph explaining the connection.
255 * What happens here is basically this:
256 * When a surface is destroyed, its WineD3DSurface is released,
257 * and the refcount of the DirectDraw interface is reduced by 1. If it has
258 * complex surfaces attached to it, then these surfaces are destroyed too,
259 * regardless of their refcount. If any surface being destroyed has another
260 * surface attached to it (with a "soft" attachment, not complex), then
261 * this surface is detached with DeleteAttachedSurface.
263 * When the surface is a texture, the WineD3DTexture is released.
264 * If the surface is the Direct3D render target, then the D3D
265 * capabilities of the WineD3DDevice are uninitialized, which causes the
266 * swapchain to be released.
268 * When a complex sublevel falls to ref zero, then this is ignored.
273 *****************************************************************************/
275 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7
*iface
)
277 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
279 TRACE("(%p) : Releasing from %d\n", This
, This
->ref
);
280 ref
= InterlockedDecrement(&This
->ref
);
285 IDirectDrawSurfaceImpl
*surf
;
286 IDirectDrawImpl
*ddraw
;
287 IUnknown
*ifaceToRelease
= This
->ifaceToRelease
;
290 /* Complex attached surfaces are destroyed implicitly when the root is released */
291 EnterCriticalSection(&ddraw_cs
);
292 if(!This
->is_complex_root
)
294 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
295 LeaveCriticalSection(&ddraw_cs
);
300 /* If it's a texture, destroy the WineD3DTexture.
301 * WineD3D will destroy the IParent interfaces
302 * of the sublevels, which destroys the WineD3DSurfaces.
303 * Set the surfaces to NULL to avoid destroying them again later
305 if(This
->wineD3DTexture
)
307 IWineD3DBaseTexture_Release(This
->wineD3DTexture
);
309 /* If it's the RenderTarget, destroy the d3ddevice */
310 else if(This
->wineD3DSwapChain
)
312 if((ddraw
->d3d_initialized
) && (This
== ddraw
->d3d_target
)) {
313 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This
);
315 /* Unset any index buffer, just to be sure */
316 IWineD3DDevice_SetIndices(ddraw
->wineD3DDevice
, NULL
);
317 IWineD3DDevice_SetDepthStencilSurface(ddraw
->wineD3DDevice
, NULL
);
318 IWineD3DDevice_SetVertexDeclaration(ddraw
->wineD3DDevice
, NULL
);
319 for(i
= 0; i
< ddraw
->numConvertedDecls
; i
++)
321 IWineD3DVertexDeclaration_Release(ddraw
->decls
[i
].decl
);
323 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
324 ddraw
->numConvertedDecls
= 0;
326 if(IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroyDepthStencilSurface
, D3D7CB_DestroySwapChain
) != D3D_OK
)
329 ERR("(%p) Failed to uninit 3D\n", This
);
333 /* Free the d3d window if one was created */
334 if(ddraw
->d3d_window
!= 0 && ddraw
->d3d_window
!= ddraw
->dest_window
)
336 TRACE(" (%p) Destroying the hidden render window %p\n", This
, ddraw
->d3d_window
);
337 DestroyWindow(ddraw
->d3d_window
);
338 ddraw
->d3d_window
= 0;
340 /* Unset the pointers */
343 This
->wineD3DSwapChain
= NULL
; /* Uninit3D releases the swapchain */
344 ddraw
->d3d_initialized
= FALSE
;
345 ddraw
->d3d_target
= NULL
;
347 IWineD3DDevice_UninitGDI(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
348 This
->wineD3DSwapChain
= NULL
;
351 /* Reset to the default surface implementation type. This is needed if apps use
352 * non render target surfaces and expect blits to work after destroying the render
355 * TODO: Recreate existing offscreen surfaces
357 ddraw
->ImplType
= DefaultSurfaceType
;
359 /* Write a trace because D3D unloading was the reason for many
360 * crashes during development.
362 TRACE("(%p) D3D unloaded\n", This
);
364 else if(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
368 /* It's a render target, but no swapchain was created.
369 * The IParent interfaces have to be released manually.
370 * The same applies for textures without an
371 * IWineD3DTexture object attached
375 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
377 if(This
->complex_array
[i
])
379 /* Only the topmost level can have more than 1 surfaces in the complex
380 * attachment array(Cube texture roots), for all others there is only
383 surf
= This
->complex_array
[i
];
386 IWineD3DSurface_GetParent(surf
->WineD3DSurface
,
387 (IUnknown
**) &Parent
);
388 IParent_Release(Parent
); /* For the getParent */
389 IParent_Release(Parent
); /* To release it */
390 surf
= surf
->complex_array
[0];
395 /* Now the top-level surface */
396 IWineD3DSurface_GetParent(This
->WineD3DSurface
,
397 (IUnknown
**) &Parent
);
398 IParent_Release(Parent
); /* For the getParent */
399 IParent_Release(Parent
); /* To release it */
402 /* The refcount test shows that the palette is detached when the surface is destroyed */
403 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This
, IDirectDrawSurface7
),
406 /* Loop through all complex attached surfaces,
409 * Yet again, only the root can have more than one complexly attached surface, all the others
410 * have a total of one;
412 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
414 if(!This
->complex_array
[i
]) break;
416 surf
= This
->complex_array
[i
];
417 This
->complex_array
[i
] = NULL
;
420 IDirectDrawSurfaceImpl
*destroy
= surf
;
421 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
422 IDirectDrawSurfaceImpl_Destroy(destroy
); /* Destroy it */
426 /* Destroy the root surface.
428 IDirectDrawSurfaceImpl_Destroy(This
);
430 /* Reduce the ddraw refcount */
431 if(ifaceToRelease
) IUnknown_Release(ifaceToRelease
);
432 LeaveCriticalSection(&ddraw_cs
);
438 /*****************************************************************************
439 * IDirectDrawSurface7::GetAttachedSurface
441 * Returns an attached surface with the requested caps. Surface attachment
442 * and complex surfaces are not clearly described by the MSDN or sdk,
443 * so this method is tricky and likely to contain problems.
444 * This implementation searches the complex list first, then the
447 * The chains are searched from This down to the last surface in the chain,
448 * not from the first element in the chain. The first surface found is
449 * returned. The MSDN says that this method fails if more than one surface
450 * matches the caps, but it is not sure if that is right. The attachment
451 * structure may not even allow two matching surfaces.
453 * The found surface is AddRef-ed before it is returned.
456 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
457 * Surface: Address to store the found surface
461 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
462 * DDERR_NOTFOUND if no surface was found
464 *****************************************************************************/
465 static HRESULT WINAPI
466 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7
*iface
,
468 IDirectDrawSurface7
**Surface
)
470 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
471 IDirectDrawSurfaceImpl
*surf
;
475 TRACE("(%p)->(%p,%p)\n", This
, Caps
, Surface
);
476 EnterCriticalSection(&ddraw_cs
);
480 if(This
->version
< 7)
482 /* Earlier dx apps put garbage into these members, clear them */
483 our_caps
.dwCaps2
= 0;
484 our_caps
.dwCaps3
= 0;
485 our_caps
.dwCaps4
= 0;
488 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 */
490 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
492 surf
= This
->complex_array
[i
];
497 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
498 surf
->surface_desc
.ddsCaps
.dwCaps
,
499 surf
->surface_desc
.ddsCaps
.dwCaps2
,
500 surf
->surface_desc
.ddsCaps
.dwCaps3
,
501 surf
->surface_desc
.ddsCaps
.dwCaps4
);
504 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
505 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
507 /* MSDN: "This method fails if more than one surface is attached
508 * that matches the capabilities requested."
510 * Not sure how to test this.
513 TRACE("(%p): Returning surface %p\n", This
, surf
);
514 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
515 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
516 IDirectDrawSurface7_AddRef(*Surface
);
517 LeaveCriticalSection(&ddraw_cs
);
522 /* Next, look at the attachment chain */
525 while( (surf
= surf
->next_attached
) )
529 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
530 surf
->surface_desc
.ddsCaps
.dwCaps
,
531 surf
->surface_desc
.ddsCaps
.dwCaps2
,
532 surf
->surface_desc
.ddsCaps
.dwCaps3
,
533 surf
->surface_desc
.ddsCaps
.dwCaps4
);
536 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
537 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
539 TRACE("(%p): Returning surface %p\n", This
, surf
);
540 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
541 IDirectDrawSurface7_AddRef(*Surface
);
542 LeaveCriticalSection(&ddraw_cs
);
547 TRACE("(%p) Didn't find a valid surface\n", This
);
548 LeaveCriticalSection(&ddraw_cs
);
551 return DDERR_NOTFOUND
;
554 /*****************************************************************************
555 * IDirectDrawSurface7::Lock
557 * Locks the surface and returns a pointer to the surface's memory
560 * Rect: Rectangle to lock. If NULL, the whole surface is locked
561 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
562 * Flags: Locking flags, e.g Read only or write only
563 * h: An event handle that's not used and must be NULL
567 * DDERR_INVALIDPARAMS if DDSD is NULL
568 * For more details, see IWineD3DSurface::LockRect
570 *****************************************************************************/
571 static HRESULT WINAPI
572 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7
*iface
,
574 DDSURFACEDESC2
*DDSD
,
578 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
579 WINED3DLOCKED_RECT LockedRect
;
581 TRACE("(%p)->(%p,%p,%x,%p)\n", This
, Rect
, DDSD
, Flags
, h
);
584 return DDERR_INVALIDPARAMS
;
586 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
587 EnterCriticalSection(&ddraw_cs
);
589 /* Should I check for the handle to be NULL?
591 * The DDLOCK flags and the D3DLOCK flags are equal
592 * for the supported values. The others are ignored by WineD3D
595 if(DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) &&
596 DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
598 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS
);
599 LeaveCriticalSection(&ddraw_cs
);
600 return DDERR_INVALIDPARAMS
;
603 /* Windows zeroes this if the rect is invalid */
610 || (Rect
->left
> Rect
->right
)
611 || (Rect
->top
> Rect
->bottom
)
612 || (Rect
->right
> This
->surface_desc
.dwWidth
)
613 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
615 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
616 LeaveCriticalSection(&ddraw_cs
);
617 return DDERR_INVALIDPARAMS
;
621 hr
= IWineD3DSurface_LockRect(This
->WineD3DSurface
,
627 LeaveCriticalSection(&ddraw_cs
);
630 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
631 * specific error. But since IWineD3DSurface::LockRect returns that error in this
632 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
633 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
634 * is much easier to do it in one place in ddraw
636 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
641 /* Override the memory area. The pitch should be set already. Strangely windows
642 * does not set the LPSURFACE flag on locked surfaces !?!.
643 * DDSD->dwFlags |= DDSD_LPSURFACE;
645 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
646 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
648 TRACE("locked surface returning description :\n");
649 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
651 LeaveCriticalSection(&ddraw_cs
);
655 /*****************************************************************************
656 * IDirectDrawSurface7::Unlock
658 * Unlocks an locked surface
661 * Rect: Not used by this implementation
665 * For more details, see IWineD3DSurface::UnlockRect
667 *****************************************************************************/
668 static HRESULT WINAPI
669 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7
*iface
,
672 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
674 TRACE("(%p)->(%p)\n", This
, pRect
);
676 EnterCriticalSection(&ddraw_cs
);
677 hr
= IWineD3DSurface_UnlockRect(This
->WineD3DSurface
);
680 This
->surface_desc
.lpSurface
= NULL
;
682 LeaveCriticalSection(&ddraw_cs
);
686 /*****************************************************************************
687 * IDirectDrawSurface7::Flip
689 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
690 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
691 * the flip target is passed to WineD3D, even if the app didn't specify one
694 * DestOverride: Specifies the surface that will become the new front
695 * buffer. If NULL, the current back buffer is used
696 * Flags: some DirectDraw flags, see include/ddraw.h
700 * DDERR_NOTFLIPPABLE if no flip target could be found
701 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
702 * For more details, see IWineD3DSurface::Flip
704 *****************************************************************************/
705 static HRESULT WINAPI
706 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7
*iface
,
707 IDirectDrawSurface7
*DestOverride
,
710 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
711 IDirectDrawSurfaceImpl
*Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DestOverride
);
712 IDirectDrawSurface7
*Override7
;
714 TRACE("(%p)->(%p,%x)\n", This
, DestOverride
, Flags
);
716 /* Flip has to be called from a front buffer
717 * What about overlay surfaces, AFAIK they can flip too?
719 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
720 return DDERR_INVALIDOBJECT
; /* Unchecked */
722 EnterCriticalSection(&ddraw_cs
);
724 /* WineD3D doesn't keep track of attached surface, so find the target */
729 memset(&Caps
, 0, sizeof(Caps
));
730 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
731 hr
= IDirectDrawSurface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
734 ERR("Can't find a flip target\n");
735 LeaveCriticalSection(&ddraw_cs
);
736 return DDERR_NOTFLIPPABLE
; /* Unchecked */
738 Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Override7
);
740 /* For the GetAttachedSurface */
741 IDirectDrawSurface7_Release(Override7
);
744 hr
= IWineD3DSurface_Flip(This
->WineD3DSurface
,
745 Override
->WineD3DSurface
,
747 LeaveCriticalSection(&ddraw_cs
);
751 /*****************************************************************************
752 * IDirectDrawSurface7::Blt
754 * Performs a blit on the surface
757 * DestRect: Destination rectangle, can be NULL
758 * SrcSurface: Source surface, can be NULL
759 * SrcRect: Source rectangle, can be NULL
761 * DDBltFx: Some extended blt parameters, connected to the flags
765 * See IWineD3DSurface::Blt for more details
767 *****************************************************************************/
768 static HRESULT WINAPI
769 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7
*iface
,
771 IDirectDrawSurface7
*SrcSurface
,
776 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
778 IDirectDrawSurfaceImpl
*Src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, SrcSurface
);
779 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This
, DestRect
, Src
, SrcRect
, Flags
, DDBltFx
);
781 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
782 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
784 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
785 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
786 return DDERR_INVALIDPARAMS
;
789 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
790 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
791 return DDERR_INVALIDPARAMS
;
794 /* Sizes can change, therefore hold the lock when testing the rectangles */
795 EnterCriticalSection(&ddraw_cs
);
798 if(DestRect
->top
>= DestRect
->bottom
|| DestRect
->left
>= DestRect
->right
||
799 DestRect
->right
> This
->surface_desc
.dwWidth
||
800 DestRect
->bottom
> This
->surface_desc
.dwHeight
)
802 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
803 LeaveCriticalSection(&ddraw_cs
);
804 return DDERR_INVALIDRECT
;
809 if(SrcRect
->top
>= SrcRect
->bottom
|| SrcRect
->left
>=SrcRect
->right
||
810 SrcRect
->right
> Src
->surface_desc
.dwWidth
||
811 SrcRect
->bottom
> Src
->surface_desc
.dwHeight
)
813 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
814 LeaveCriticalSection(&ddraw_cs
);
815 return DDERR_INVALIDRECT
;
819 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
820 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
821 LeaveCriticalSection(&ddraw_cs
);
822 return DDERR_INVALIDPARAMS
;
825 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
826 * and replace the ddraw surfaces with the wined3d surfaces
827 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
829 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
,
831 Src
? Src
->WineD3DSurface
: NULL
,
834 (WINEDDBLTFX
*) DDBltFx
,
837 LeaveCriticalSection(&ddraw_cs
);
840 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
841 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
846 /*****************************************************************************
847 * IDirectDrawSurface7::AddAttachedSurface
849 * Attaches a surface to another surface. How the surface attachments work
850 * is not totally understood yet, and this method is prone to problems.
851 * he surface that is attached is AddRef-ed.
853 * Tests with complex surfaces suggest that the surface attachments form a
854 * tree, but no method to test this has been found yet.
856 * The attachment list consists of a first surface (first_attached) and
857 * for each surface a pointer to the next attached surface (next_attached).
858 * For the first surface, and a surface that has no attachments
859 * first_attached points to the surface itself. A surface that has
860 * no successors in the chain has next_attached set to NULL.
862 * Newly attached surfaces are attached right after the root surface.
863 * If a surface is attached to a complex surface compound, it's attached to
864 * the surface that the app requested, not the complex root. See
865 * GetAttachedSurface for a description how surfaces are found.
867 * This is how the current implementation works, and it was coded by looking
868 * at the needs of the applications.
870 * So far only Z-Buffer attachments are tested, and they are activated in
871 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
872 * Back buffers should work in 2D mode, but they are not tested(They can be
873 * attached in older iface versions). Rendering to the front buffer and
874 * switching between that and double buffering is not yet implemented in
875 * WineD3D, so for 3D it might have unexpected results.
877 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
878 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
879 * performs additional checks. Version 7 of this interface is much more restrictive
880 * than its predecessors.
883 * Attach: Surface to attach to iface
887 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
889 *****************************************************************************/
891 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl
*This
,
892 IDirectDrawSurfaceImpl
*Surf
)
894 TRACE("(%p)->(%p)\n", This
, Surf
);
897 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
899 EnterCriticalSection(&ddraw_cs
);
901 /* Check if the surface is already attached somewhere */
902 if( (Surf
->next_attached
!= NULL
) ||
903 (Surf
->first_attached
!= Surf
) )
905 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
906 * What happens if one surface is attached to 2 different surfaces?
908 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
);
909 LeaveCriticalSection(&ddraw_cs
);
910 return DDERR_SURFACEALREADYATTACHED
;
913 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
914 Surf
->next_attached
= This
->next_attached
;
915 Surf
->first_attached
= This
->first_attached
;
916 This
->next_attached
= Surf
;
918 /* Check if the WineD3D depth stencil needs updating */
919 if(This
->ddraw
->d3ddevice
)
921 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
925 * "This method increments the reference count of the surface being attached."
927 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(Surf
, IDirectDrawSurface7
));
928 LeaveCriticalSection(&ddraw_cs
);
932 static HRESULT WINAPI
933 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7
*iface
,
934 IDirectDrawSurface7
*Attach
)
936 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
937 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
939 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
940 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
943 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
944 Surf
->surface_desc
.ddsCaps
.dwCaps
);
945 return DDERR_CANNOTATTACHSURFACE
;
948 return IDirectDrawSurfaceImpl_AddAttachedSurface(This
,
951 /*****************************************************************************
952 * IDirectDrawSurface7::DeleteAttachedSurface
954 * Removes a surface from the attachment chain. The surface's refcount
955 * is decreased by one after it has been removed
958 * Flags: Some flags, not used by this implementation
959 * Attach: Surface to detach
963 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
965 *****************************************************************************/
966 static HRESULT WINAPI
967 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
969 IDirectDrawSurface7
*Attach
)
971 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
972 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
973 IDirectDrawSurfaceImpl
*Prev
= This
;
974 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, Surf
);
976 EnterCriticalSection(&ddraw_cs
);
977 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
979 LeaveCriticalSection(&ddraw_cs
);
980 return DDERR_CANNOTDETACHSURFACE
;
983 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
984 if (This
->surface_desc
.ddsCaps
.dwCaps
&
985 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
987 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
988 /* FIXME: we should probably also subtract from dwMipMapCount of this
989 * and all parent surfaces */
992 /* Find the predecessor of the detached surface */
995 if(Prev
->next_attached
== Surf
) break;
996 Prev
= Prev
->next_attached
;
999 /* There must be a surface, otherwise there's a bug */
1000 assert(Prev
!= NULL
);
1002 /* Unchain the surface */
1003 Prev
->next_attached
= Surf
->next_attached
;
1004 Surf
->next_attached
= NULL
;
1005 Surf
->first_attached
= Surf
;
1007 /* Check if the WineD3D depth stencil needs updating */
1008 if(This
->ddraw
->d3ddevice
)
1010 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1013 IDirectDrawSurface7_Release(Attach
);
1014 LeaveCriticalSection(&ddraw_cs
);
1018 /*****************************************************************************
1019 * IDirectDrawSurface7::AddOverlayDirtyRect
1021 * "This method is not currently implemented"
1029 *****************************************************************************/
1030 static HRESULT WINAPI
1031 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
,
1034 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1035 TRACE("(%p)->(%p)\n",This
,Rect
);
1037 /* MSDN says it's not implemented. I could forward it to WineD3D,
1038 * then we'd implement it, but I don't think that's a good idea
1039 * (Stefan Dösinger)
1042 return IWineD3DSurface_AddOverlayDirtyRect(This
->WineD3DSurface
, pRect
);
1044 return DDERR_UNSUPPORTED
; /* unchecked */
1047 /*****************************************************************************
1048 * IDirectDrawSurface7::GetDC
1050 * Returns a GDI device context for the surface
1053 * hdc: Address of a HDC variable to store the dc to
1057 * DDERR_INVALIDPARAMS if hdc is NULL
1058 * For details, see IWineD3DSurface::GetDC
1060 *****************************************************************************/
1061 static HRESULT WINAPI
1062 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7
*iface
,
1065 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1067 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1070 return DDERR_INVALIDPARAMS
;
1072 EnterCriticalSection(&ddraw_cs
);
1073 hr
= IWineD3DSurface_GetDC(This
->WineD3DSurface
,
1075 LeaveCriticalSection(&ddraw_cs
);
1079 /*****************************************************************************
1080 * IDirectDrawSurface7::ReleaseDC
1082 * Releases the DC that was constructed with GetDC
1085 * hdc: HDC to release
1089 * For more details, see IWineD3DSurface::ReleaseDC
1091 *****************************************************************************/
1092 static HRESULT WINAPI
1093 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7
*iface
,
1096 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1098 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1100 EnterCriticalSection(&ddraw_cs
);
1101 hr
= IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
1102 LeaveCriticalSection(&ddraw_cs
);
1106 /*****************************************************************************
1107 * IDirectDrawSurface7::GetCaps
1109 * Returns the surface's caps
1112 * Caps: Address to write the caps to
1116 * DDERR_INVALIDPARAMS if Caps is NULL
1118 *****************************************************************************/
1119 static HRESULT WINAPI
1120 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7
*iface
,
1123 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1124 TRACE("(%p)->(%p)\n",This
,Caps
);
1127 return DDERR_INVALIDPARAMS
;
1129 *Caps
= This
->surface_desc
.ddsCaps
;
1133 /*****************************************************************************
1134 * IDirectDrawSurface7::SetPriority
1136 * Sets a texture priority for managed textures.
1139 * Priority: The new priority
1143 * For more details, see IWineD3DSurface::SetPriority
1145 *****************************************************************************/
1146 static HRESULT WINAPI
1147 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1149 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1151 TRACE("(%p)->(%d): Relay!\n",This
,Priority
);
1153 EnterCriticalSection(&ddraw_cs
);
1154 hr
= IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1155 LeaveCriticalSection(&ddraw_cs
);
1159 /*****************************************************************************
1160 * IDirectDrawSurface7::GetPriority
1162 * Returns the surface's priority
1165 * Priority: Address of a variable to write the priority to
1169 * DDERR_INVALIDPARAMS if Priority == NULL
1170 * For more details, see IWineD3DSurface::GetPriority
1172 *****************************************************************************/
1173 static HRESULT WINAPI
1174 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7
*iface
,
1177 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1178 TRACE("(%p)->(%p): Relay\n",This
,Priority
);
1182 return DDERR_INVALIDPARAMS
;
1185 EnterCriticalSection(&ddraw_cs
);
1186 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1187 LeaveCriticalSection(&ddraw_cs
);
1191 /*****************************************************************************
1192 * IDirectDrawSurface7::SetPrivateData
1194 * Stores some data in the surface that is intended for the application's
1198 * tag: GUID that identifies the data
1199 * Data: Pointer to the private data
1200 * Size: Size of the private data
1205 * For more details, see IWineD3DSurface::SetPrivateData
1207 *****************************************************************************/
1208 static HRESULT WINAPI
1209 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7
*iface
,
1215 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1217 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This
, debugstr_guid(tag
), Data
, Size
, Flags
);
1219 EnterCriticalSection(&ddraw_cs
);
1220 hr
= IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1225 LeaveCriticalSection(&ddraw_cs
);
1228 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1233 /*****************************************************************************
1234 * IDirectDrawSurface7::GetPrivateData
1236 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1239 * tag: GUID of the data to return
1240 * Data: Address where to write the data to
1241 * Size: Size of the buffer at Data
1245 * DDERR_INVALIDPARAMS if Data is NULL
1246 * For more details, see IWineD3DSurface::GetPrivateData
1248 *****************************************************************************/
1249 static HRESULT WINAPI
1250 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7
*iface
,
1255 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1257 TRACE("(%p)->(%s,%p,%p): Relay\n", This
, debugstr_guid(tag
), Data
, Size
);
1260 return DDERR_INVALIDPARAMS
;
1262 EnterCriticalSection(&ddraw_cs
);
1263 hr
= IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1267 LeaveCriticalSection(&ddraw_cs
);
1271 /*****************************************************************************
1272 * IDirectDrawSurface7::FreePrivateData
1274 * Frees private data stored in the surface
1277 * tag: Tag of the data to free
1281 * For more details, see IWineD3DSurface::FreePrivateData
1283 *****************************************************************************/
1284 static HRESULT WINAPI
1285 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7
*iface
,
1288 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1290 TRACE("(%p)->(%s): Relay\n", This
, debugstr_guid(tag
));
1292 EnterCriticalSection(&ddraw_cs
);
1293 hr
= IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1294 LeaveCriticalSection(&ddraw_cs
);
1298 /*****************************************************************************
1299 * IDirectDrawSurface7::PageLock
1301 * Prevents a sysmem surface from being paged out
1304 * Flags: Not used, must be 0(unchecked)
1307 * DD_OK, because it's a stub
1309 *****************************************************************************/
1310 static HRESULT WINAPI
1311 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7
*iface
,
1314 TRACE("(%p)->(%x)\n", iface
, Flags
);
1316 /* This is Windows memory management related - we don't need this */
1320 /*****************************************************************************
1321 * IDirectDrawSurface7::PageUnlock
1323 * Allows a sysmem surface to be paged out
1326 * Flags: Not used, must be 0(unchecked)
1329 * DD_OK, because it's a stub
1331 *****************************************************************************/
1332 static HRESULT WINAPI
1333 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7
*iface
,
1336 TRACE("(%p)->(%x)\n", iface
, Flags
);
1341 /*****************************************************************************
1342 * IDirectDrawSurface7::BltBatch
1344 * An unimplemented function
1352 *****************************************************************************/
1353 static HRESULT WINAPI
IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1355 TRACE("(%p)->(%p,%d,%08x)\n",iface
,Batch
,Count
,Flags
);
1357 /* MSDN: "not currently implemented" */
1358 return DDERR_UNSUPPORTED
;
1361 /*****************************************************************************
1362 * IDirectDrawSurface7::EnumAttachedSurfaces
1364 * Enumerates all surfaces attached to this surface
1367 * context: Pointer to pass unmodified to the callback
1368 * cb: Callback function to call for each surface
1372 * DDERR_INVALIDPARAMS if cb is NULL
1374 *****************************************************************************/
1375 static HRESULT WINAPI
1376 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1378 LPDDENUMSURFACESCALLBACK7 cb
)
1380 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1381 IDirectDrawSurfaceImpl
*surf
;
1382 DDSURFACEDESC2 desc
;
1385 /* Attached surfaces aren't handled in WineD3D */
1386 TRACE("(%p)->(%p,%p)\n",This
,context
,cb
);
1389 return DDERR_INVALIDPARAMS
;
1391 EnterCriticalSection(&ddraw_cs
);
1392 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1394 surf
= This
->complex_array
[i
];
1397 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1398 desc
= surf
->surface_desc
;
1399 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1400 if (cb(ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1402 LeaveCriticalSection(&ddraw_cs
);
1407 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1409 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1410 desc
= surf
->surface_desc
;
1411 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1412 if (cb( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1414 LeaveCriticalSection(&ddraw_cs
);
1419 TRACE(" end of enumeration.\n");
1421 LeaveCriticalSection(&ddraw_cs
);
1425 /*****************************************************************************
1426 * IDirectDrawSurface7::EnumOverlayZOrders
1428 * "Enumerates the overlay surfaces on the specified destination"
1431 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1432 * context: context to pass back to the callback
1433 * cb: callback function to call for each enumerated surface
1436 * DD_OK, because it's a stub
1438 *****************************************************************************/
1439 static HRESULT WINAPI
1440 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1443 LPDDENUMSURFACESCALLBACK7 cb
)
1445 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface
, Flags
, context
, cb
);
1450 /*****************************************************************************
1451 * IDirectDrawSurface7::GetBltStatus
1453 * Returns the blitting status
1456 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1459 * See IWineD3DSurface::Blt
1461 *****************************************************************************/
1462 static HRESULT WINAPI
1463 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7
*iface
,
1466 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1468 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1470 EnterCriticalSection(&ddraw_cs
);
1471 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1472 LeaveCriticalSection(&ddraw_cs
);
1475 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1480 /*****************************************************************************
1481 * IDirectDrawSurface7::GetColorKey
1483 * Returns the color key assigned to the surface
1487 * CKey: Address to store the key to
1491 * DDERR_INVALIDPARAMS if CKey is NULL
1493 *****************************************************************************/
1494 static HRESULT WINAPI
1495 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7
*iface
,
1499 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1500 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, CKey
);
1503 return DDERR_INVALIDPARAMS
;
1505 EnterCriticalSection(&ddraw_cs
);
1509 case DDCKEY_DESTBLT
:
1510 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1512 LeaveCriticalSection(&ddraw_cs
);
1513 return DDERR_NOCOLORKEY
;
1515 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1518 case DDCKEY_DESTOVERLAY
:
1519 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
1521 LeaveCriticalSection(&ddraw_cs
);
1522 return DDERR_NOCOLORKEY
;
1524 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1528 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
1530 LeaveCriticalSection(&ddraw_cs
);
1531 return DDERR_NOCOLORKEY
;
1533 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1536 case DDCKEY_SRCOVERLAY
:
1537 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
1539 LeaveCriticalSection(&ddraw_cs
);
1540 return DDERR_NOCOLORKEY
;
1542 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1546 LeaveCriticalSection(&ddraw_cs
);
1547 return DDERR_INVALIDPARAMS
;
1550 LeaveCriticalSection(&ddraw_cs
);
1554 /*****************************************************************************
1555 * IDirectDrawSurface7::GetFlipStatus
1557 * Returns the flipping status of the surface
1560 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1563 * See IWineD3DSurface::GetFlipStatus
1565 *****************************************************************************/
1566 static HRESULT WINAPI
1567 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7
*iface
,
1570 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1572 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1574 EnterCriticalSection(&ddraw_cs
);
1575 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1576 LeaveCriticalSection(&ddraw_cs
);
1579 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1584 /*****************************************************************************
1585 * IDirectDrawSurface7::GetOverlayPosition
1587 * Returns the display coordinates of a visible and active overlay surface
1594 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1595 *****************************************************************************/
1596 static HRESULT WINAPI
1597 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7
*iface
,
1600 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1602 TRACE("(%p)->(%p,%p): Relay\n", This
, X
, Y
);
1604 EnterCriticalSection(&ddraw_cs
);
1605 hr
= IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1608 LeaveCriticalSection(&ddraw_cs
);
1612 /*****************************************************************************
1613 * IDirectDrawSurface7::GetPixelFormat
1615 * Returns the pixel format of the Surface
1618 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1619 * format should be written
1623 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1625 *****************************************************************************/
1626 static HRESULT WINAPI
1627 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7
*iface
,
1628 DDPIXELFORMAT
*PixelFormat
)
1630 /* What is DDERR_INVALIDSURFACETYPE for here? */
1631 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1632 TRACE("(%p)->(%p)\n",This
,PixelFormat
);
1635 return DDERR_INVALIDPARAMS
;
1637 EnterCriticalSection(&ddraw_cs
);
1638 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1639 LeaveCriticalSection(&ddraw_cs
);
1645 /*****************************************************************************
1646 * IDirectDrawSurface7::GetSurfaceDesc
1648 * Returns the description of this surface
1651 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1656 * DDERR_INVALIDPARAMS if DDSD is NULL
1658 *****************************************************************************/
1659 static HRESULT WINAPI
1660 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7
*iface
,
1661 DDSURFACEDESC2
*DDSD
)
1663 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1665 TRACE("(%p)->(%p)\n",This
,DDSD
);
1668 return DDERR_INVALIDPARAMS
;
1670 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
1672 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
1673 return DDERR_INVALIDPARAMS
;
1676 EnterCriticalSection(&ddraw_cs
);
1677 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1678 TRACE("Returning surface desc:\n");
1679 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1681 LeaveCriticalSection(&ddraw_cs
);
1685 /*****************************************************************************
1686 * IDirectDrawSurface7::Initialize
1688 * Initializes the surface. This is a no-op in Wine
1691 * DD: Pointer to an DirectDraw interface
1692 * DDSD: Surface description for initialization
1695 * DDERR_ALREADYINITIALIZED
1697 *****************************************************************************/
1698 static HRESULT WINAPI
1699 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7
*iface
,
1701 DDSURFACEDESC2
*DDSD
)
1703 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1704 IDirectDrawImpl
*ddimpl
= ICOM_OBJECT(IDirectDrawImpl
, IDirectDraw
, DD
);
1705 TRACE("(%p)->(%p,%p)\n",This
,ddimpl
,DDSD
);
1707 return DDERR_ALREADYINITIALIZED
;
1710 /*****************************************************************************
1711 * IDirectDrawSurface7::IsLost
1713 * Checks if the surface is lost
1716 * DD_OK, if the surface is usable
1717 * DDERR_ISLOST if the surface is lost
1718 * See IWineD3DSurface::IsLost for more details
1720 *****************************************************************************/
1721 static HRESULT WINAPI
1722 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7
*iface
)
1724 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1726 TRACE("(%p)\n", This
);
1728 EnterCriticalSection(&ddraw_cs
);
1729 /* We lose the surface if the implementation was changed */
1730 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1732 /* But this shouldn't happen. When we change the implementation,
1733 * all surfaces are re-created automatically, and their content
1736 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
1737 LeaveCriticalSection(&ddraw_cs
);
1738 return DDERR_SURFACELOST
;
1741 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
1742 LeaveCriticalSection(&ddraw_cs
);
1745 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1746 * WineD3D uses the same error for surfaces
1748 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
1753 /*****************************************************************************
1754 * IDirectDrawSurface7::Restore
1756 * Restores a lost surface. This makes the surface usable again, but
1757 * doesn't reload its old contents
1761 * See IWineD3DSurface::Restore for more details
1763 *****************************************************************************/
1764 static HRESULT WINAPI
1765 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7
*iface
)
1767 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1769 TRACE("(%p)\n", This
);
1771 EnterCriticalSection(&ddraw_cs
);
1772 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1774 /* Call the recreation callback. Make sure to AddRef first */
1775 IDirectDrawSurface_AddRef(iface
);
1776 IDirectDrawImpl_RecreateSurfacesCallback(iface
,
1777 &This
->surface_desc
,
1778 NULL
/* Not needed */);
1780 hr
= IWineD3DSurface_Restore(This
->WineD3DSurface
);
1781 LeaveCriticalSection(&ddraw_cs
);
1785 /*****************************************************************************
1786 * IDirectDrawSurface7::SetOverlayPosition
1788 * Changes the display coordinates of an overlay surface
1795 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1796 *****************************************************************************/
1797 static HRESULT WINAPI
1798 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7
*iface
,
1802 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1804 TRACE("(%p)->(%d,%d): Relay\n", This
, X
, Y
);
1806 EnterCriticalSection(&ddraw_cs
);
1807 hr
= IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
1810 LeaveCriticalSection(&ddraw_cs
);
1814 /*****************************************************************************
1815 * IDirectDrawSurface7::UpdateOverlay
1817 * Modifies the attributes of an overlay surface.
1820 * SrcRect: The section of the source being used for the overlay
1821 * DstSurface: Address of the surface that is overlaid
1822 * DstRect: Place of the overlay
1823 * Flags: some DDOVER_* flags
1826 * DDERR_UNSUPPORTED, because we don't support overlays
1828 *****************************************************************************/
1829 static HRESULT WINAPI
1830 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7
*iface
,
1832 IDirectDrawSurface7
*DstSurface
,
1837 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1838 IDirectDrawSurfaceImpl
*Dst
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DstSurface
);
1840 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This
, SrcRect
, Dst
, DstRect
, Flags
, FX
);
1842 EnterCriticalSection(&ddraw_cs
);
1843 hr
= IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
1845 Dst
? Dst
->WineD3DSurface
: NULL
,
1848 (WINEDDOVERLAYFX
*) FX
);
1849 LeaveCriticalSection(&ddraw_cs
);
1851 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1852 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
1853 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
1859 /*****************************************************************************
1860 * IDirectDrawSurface7::UpdateOverlayDisplay
1862 * The DX7 sdk says that it's not implemented
1867 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1869 *****************************************************************************/
1870 static HRESULT WINAPI
1871 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
,
1874 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1875 TRACE("(%p)->(%x)\n", This
, Flags
);
1876 return DDERR_UNSUPPORTED
;
1879 /*****************************************************************************
1880 * IDirectDrawSurface7::UpdateOverlayZOrder
1882 * Sets an overlay's Z order
1885 * Flags: DDOVERZ_* flags
1886 * DDSRef: Defines the relative position in the overlay chain
1889 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1891 *****************************************************************************/
1892 static HRESULT WINAPI
1893 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
1895 IDirectDrawSurface7
*DDSRef
)
1897 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1899 IDirectDrawSurfaceImpl
*Ref
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DDSRef
);
1901 TRACE("(%p)->(%x,%p): Relay\n", This
, Flags
, Ref
);
1902 EnterCriticalSection(&ddraw_cs
);
1903 hr
= IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
1905 Ref
? Ref
->WineD3DSurface
: NULL
);
1906 LeaveCriticalSection(&ddraw_cs
);
1910 /*****************************************************************************
1911 * IDirectDrawSurface7::GetDDInterface
1913 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1914 * surface belongs to
1917 * DD: Address to write the interface pointer to
1921 * DDERR_INVALIDPARAMS if DD is NULL
1923 *****************************************************************************/
1924 static HRESULT WINAPI
1925 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7
*iface
,
1928 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1930 TRACE("(%p)->(%p)\n",This
,DD
);
1933 return DDERR_INVALIDPARAMS
;
1935 switch(This
->version
)
1938 *((IDirectDraw7
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw7
);
1939 IDirectDraw7_AddRef(*(IDirectDraw7
**) DD
);
1943 *((IDirectDraw4
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw4
);
1944 IDirectDraw4_AddRef(*(IDirectDraw4
**) DD
);
1948 *((IDirectDraw2
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw2
);
1949 IDirectDraw_AddRef( *(IDirectDraw2
**) DD
);
1953 *((IDirectDraw
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw
);
1954 IDirectDraw_AddRef( *(IDirectDraw
**) DD
);
1962 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1963 static HRESULT WINAPI
IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
1965 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1966 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
1968 TRACE("(%p)\n",This
);
1969 EnterCriticalSection(&ddraw_cs
);
1970 /* A uniqueness value of 0 is apparently special.
1971 * This needs to be checked.
1972 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1975 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
1976 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
1978 if (old_uniqueness_value
== 0) break;
1979 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
1981 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
1982 old_uniqueness_value
,
1983 new_uniqueness_value
)
1984 == old_uniqueness_value
)
1988 LeaveCriticalSection(&ddraw_cs
);
1992 static HRESULT WINAPI
IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7
*iface
, LPDWORD pValue
)
1994 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1996 TRACE("(%p)->(%p)\n",This
,pValue
);
1997 EnterCriticalSection(&ddraw_cs
);
1998 *pValue
= This
->uniqueness_value
;
1999 LeaveCriticalSection(&ddraw_cs
);
2003 /*****************************************************************************
2004 * IDirectDrawSurface7::SetLOD
2006 * Sets the level of detail of a texture
2009 * MaxLOD: LOD to set
2013 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2015 *****************************************************************************/
2016 static HRESULT WINAPI
2017 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7
*iface
,
2020 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2022 TRACE("(%p)->(%d)\n", This
, MaxLOD
);
2024 EnterCriticalSection(&ddraw_cs
);
2025 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2027 LeaveCriticalSection(&ddraw_cs
);
2028 return DDERR_INVALIDOBJECT
;
2031 if(!This
->wineD3DTexture
)
2033 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
2034 LeaveCriticalSection(&ddraw_cs
);
2035 return DDERR_INVALIDOBJECT
;
2038 hr
= IWineD3DBaseTexture_SetLOD(This
->wineD3DTexture
,
2040 LeaveCriticalSection(&ddraw_cs
);
2044 /*****************************************************************************
2045 * IDirectDrawSurface7::GetLOD
2047 * Returns the level of detail of a Direct3D texture
2050 * MaxLOD: Address to write the LOD to
2054 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2055 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2057 *****************************************************************************/
2058 static HRESULT WINAPI
2059 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7
*iface
,
2062 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2063 TRACE("(%p)->(%p)\n", This
, MaxLOD
);
2066 return DDERR_INVALIDPARAMS
;
2068 EnterCriticalSection(&ddraw_cs
);
2069 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2071 LeaveCriticalSection(&ddraw_cs
);
2072 return DDERR_INVALIDOBJECT
;
2075 *MaxLOD
= IWineD3DBaseTexture_GetLOD(This
->wineD3DTexture
);
2076 LeaveCriticalSection(&ddraw_cs
);
2080 /*****************************************************************************
2081 * IDirectDrawSurface7::BltFast
2083 * Performs a fast Blit.
2086 * dstx: The x coordinate to blit to on the destination
2087 * dsty: The y coordinate to blit to on the destination
2088 * Source: The source surface
2089 * rsrc: The source rectangle
2090 * trans: Type of transfer. Some DDBLTFAST_* flags
2094 * For more details, see IWineD3DSurface::BltFast
2096 *****************************************************************************/
2097 static HRESULT WINAPI
2098 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7
*iface
,
2101 IDirectDrawSurface7
*Source
,
2105 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2107 IDirectDrawSurfaceImpl
*src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Source
);
2108 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This
, dstx
, dsty
, Source
, rsrc
, trans
);
2110 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2115 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
2116 rsrc
->right
> src
->surface_desc
.dwWidth
||
2117 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
2119 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2120 return DDERR_INVALIDRECT
;
2122 if(dstx
+ rsrc
->right
- rsrc
->left
> This
->surface_desc
.dwWidth
||
2123 dsty
+ rsrc
->bottom
- rsrc
->top
> This
->surface_desc
.dwHeight
)
2125 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2126 return DDERR_INVALIDRECT
;
2131 if(dstx
+ src
->surface_desc
.dwWidth
> This
->surface_desc
.dwWidth
||
2132 dsty
+ src
->surface_desc
.dwHeight
> This
->surface_desc
.dwHeight
)
2134 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2135 return DDERR_INVALIDRECT
;
2139 EnterCriticalSection(&ddraw_cs
);
2140 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
2142 src
? src
->WineD3DSurface
: NULL
,
2145 LeaveCriticalSection(&ddraw_cs
);
2148 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
2149 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
2154 /*****************************************************************************
2155 * IDirectDrawSurface7::GetClipper
2157 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2161 * Clipper: Address to store the interface pointer at
2165 * DDERR_INVALIDPARAMS if Clipper is NULL
2166 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2168 *****************************************************************************/
2169 static HRESULT WINAPI
2170 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7
*iface
,
2171 IDirectDrawClipper
**Clipper
)
2173 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2174 TRACE("(%p)->(%p)\n", This
, Clipper
);
2178 LeaveCriticalSection(&ddraw_cs
);
2179 return DDERR_INVALIDPARAMS
;
2182 EnterCriticalSection(&ddraw_cs
);
2183 if(This
->clipper
== NULL
)
2185 LeaveCriticalSection(&ddraw_cs
);
2186 return DDERR_NOCLIPPERATTACHED
;
2189 *Clipper
= ICOM_INTERFACE(This
->clipper
, IDirectDrawClipper
);
2190 IDirectDrawClipper_AddRef(*Clipper
);
2191 LeaveCriticalSection(&ddraw_cs
);
2195 /*****************************************************************************
2196 * IDirectDrawSurface7::SetClipper
2198 * Sets a clipper for the surface
2201 * Clipper: IDirectDrawClipper interface of the clipper to set
2206 *****************************************************************************/
2207 static HRESULT WINAPI
2208 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7
*iface
,
2209 IDirectDrawClipper
*Clipper
)
2211 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2212 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
2215 TRACE("(%p)->(%p)\n",This
,Clipper
);
2217 EnterCriticalSection(&ddraw_cs
);
2218 if (ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
) == This
->clipper
)
2220 LeaveCriticalSection(&ddraw_cs
);
2224 This
->clipper
= ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
);
2226 if (Clipper
!= NULL
)
2227 IDirectDrawClipper_AddRef(Clipper
);
2229 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper
, IDirectDrawClipper
));
2231 hr
= IWineD3DSurface_SetClipper(This
->WineD3DSurface
, This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
2233 if(This
->wineD3DSwapChain
) {
2236 IDirectDrawClipper_GetHWnd(Clipper
, &clipWindow
);
2240 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2243 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2244 This
->ddraw
->d3d_window
);
2248 LeaveCriticalSection(&ddraw_cs
);
2252 /*****************************************************************************
2253 * IDirectDrawSurface7::SetSurfaceDesc
2255 * Sets the surface description. It can override the pixel format, the surface
2257 * It's not really tested.
2260 * DDSD: Pointer to the new surface description to set
2265 * DDERR_INVALIDPARAMS if DDSD is NULL
2267 *****************************************************************************/
2268 static HRESULT WINAPI
2269 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7
*iface
,
2270 DDSURFACEDESC2
*DDSD
,
2273 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2274 WINED3DFORMAT newFormat
= WINED3DFMT_UNKNOWN
;
2276 TRACE("(%p)->(%p,%x)\n", This
, DDSD
, Flags
);
2279 return DDERR_INVALIDPARAMS
;
2281 EnterCriticalSection(&ddraw_cs
);
2282 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2284 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2286 if(newFormat
== WINED3DFMT_UNKNOWN
)
2288 ERR("Requested to set an unknown pixelformat\n");
2289 LeaveCriticalSection(&ddraw_cs
);
2290 return DDERR_INVALIDPARAMS
;
2292 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2294 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2298 LeaveCriticalSection(&ddraw_cs
);
2303 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2305 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2307 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2309 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2311 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2313 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2315 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2317 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2319 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2321 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2323 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2325 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2327 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
2329 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2330 if(hr
!= WINED3D_OK
)
2332 /* No need for a trace here, wined3d does that for us */
2333 LeaveCriticalSection(&ddraw_cs
);
2336 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2337 default: break; /* Go on */
2343 This
->surface_desc
= *DDSD
;
2345 LeaveCriticalSection(&ddraw_cs
);
2349 /*****************************************************************************
2350 * IDirectDrawSurface7::GetPalette
2352 * Returns the IDirectDrawPalette interface of the palette currently assigned
2356 * Pal: Address to write the interface pointer to
2360 * DDERR_INVALIDPARAMS if Pal is NULL
2362 *****************************************************************************/
2363 static HRESULT WINAPI
2364 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7
*iface
,
2365 IDirectDrawPalette
**Pal
)
2367 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2368 IWineD3DPalette
*wPal
;
2370 TRACE("(%p)->(%p): Relay\n", This
, Pal
);
2373 return DDERR_INVALIDPARAMS
;
2375 EnterCriticalSection(&ddraw_cs
);
2376 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wPal
);
2379 LeaveCriticalSection(&ddraw_cs
);
2385 hr
= IWineD3DPalette_GetParent(wPal
, (IUnknown
**) Pal
);
2390 hr
= DDERR_NOPALETTEATTACHED
;
2393 LeaveCriticalSection(&ddraw_cs
);
2397 /*****************************************************************************
2400 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2401 * recursively in the surface tree
2403 *****************************************************************************/
2407 WINEDDCOLORKEY
*CKey
;
2411 static HRESULT WINAPI
2412 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2413 DDSURFACEDESC2
*desc
,
2416 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2417 struct SCKContext
*ctx
= context
;
2420 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2425 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2429 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
2432 IDirectDrawSurface7_Release(surface
);
2433 return DDENUMRET_OK
;
2436 /*****************************************************************************
2437 * IDirectDrawSurface7::SetColorKey
2439 * Sets the color keying options for the surface. Observations showed that
2440 * in case of complex surfaces the color key has to be assigned to all
2445 * CKey: The new color key
2449 * See IWineD3DSurface::SetColorKey for details
2451 *****************************************************************************/
2452 static HRESULT WINAPI
2453 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7
*iface
,
2457 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2458 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) CKey
, Flags
};
2459 TRACE("(%p)->(%x,%p)\n", This
, Flags
, CKey
);
2461 EnterCriticalSection(&ddraw_cs
);
2464 switch (Flags
& ~DDCKEY_COLORSPACE
)
2466 case DDCKEY_DESTBLT
:
2467 This
->surface_desc
.ddckCKDestBlt
= *CKey
;
2468 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2471 case DDCKEY_DESTOVERLAY
:
2472 This
->surface_desc
.u3
.ddckCKDestOverlay
= *CKey
;
2473 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2476 case DDCKEY_SRCOVERLAY
:
2477 This
->surface_desc
.ddckCKSrcOverlay
= *CKey
;
2478 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2482 This
->surface_desc
.ddckCKSrcBlt
= *CKey
;
2483 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2487 LeaveCriticalSection(&ddraw_cs
);
2488 return DDERR_INVALIDPARAMS
;
2493 switch (Flags
& ~DDCKEY_COLORSPACE
)
2495 case DDCKEY_DESTBLT
:
2496 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2499 case DDCKEY_DESTOVERLAY
:
2500 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2503 case DDCKEY_SRCOVERLAY
:
2504 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2508 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2512 LeaveCriticalSection(&ddraw_cs
);
2513 return DDERR_INVALIDPARAMS
;
2516 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2519 IDirectDrawSurface7_EnumAttachedSurfaces(iface
,
2522 LeaveCriticalSection(&ddraw_cs
);
2525 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2526 default: return ctx
.ret
;
2530 /*****************************************************************************
2531 * IDirectDrawSurface7::SetPalette
2533 * Assigns a DirectDrawPalette object to the surface
2536 * Pal: Interface to the palette to set
2541 *****************************************************************************/
2542 static HRESULT WINAPI
2543 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7
*iface
,
2544 IDirectDrawPalette
*Pal
)
2546 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2547 IDirectDrawPalette
*oldPal
;
2548 IDirectDrawSurfaceImpl
*surf
;
2549 IDirectDrawPaletteImpl
*PalImpl
= ICOM_OBJECT(IDirectDrawPaletteImpl
, IDirectDrawPalette
, Pal
);
2551 TRACE("(%p)->(%p)\n", This
, Pal
);
2553 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
2554 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
2555 return DDERR_INVALIDPIXELFORMAT
;
2558 /* Find the old palette */
2559 EnterCriticalSection(&ddraw_cs
);
2560 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2561 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
2563 LeaveCriticalSection(&ddraw_cs
);
2566 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2568 /* Set the new Palette */
2569 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2570 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2571 /* AddRef the Palette */
2572 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2574 /* Release the old palette */
2575 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2577 /* If this is a front buffer, also update the back buffers
2578 * TODO: How do things work for palettized cube textures?
2580 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2582 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2583 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2588 IDirectDrawSurface7
*attach
;
2590 hr
= IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
2597 TRACE("Setting palette on %p\n", attach
);
2598 IDirectDrawSurface7_SetPalette(attach
,
2600 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attach
);
2601 IDirectDrawSurface7_Release(attach
);
2605 LeaveCriticalSection(&ddraw_cs
);
2609 /*****************************************************************************
2611 *****************************************************************************/
2613 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
=
2616 IDirectDrawSurfaceImpl_QueryInterface
,
2617 IDirectDrawSurfaceImpl_AddRef
,
2618 IDirectDrawSurfaceImpl_Release
,
2619 /*** IDirectDrawSurface ***/
2620 IDirectDrawSurface7Impl_AddAttachedSurface
,
2621 IDirectDrawSurfaceImpl_AddOverlayDirtyRect
,
2622 IDirectDrawSurfaceImpl_Blt
,
2623 IDirectDrawSurfaceImpl_BltBatch
,
2624 IDirectDrawSurfaceImpl_BltFast
,
2625 IDirectDrawSurfaceImpl_DeleteAttachedSurface
,
2626 IDirectDrawSurfaceImpl_EnumAttachedSurfaces
,
2627 IDirectDrawSurfaceImpl_EnumOverlayZOrders
,
2628 IDirectDrawSurfaceImpl_Flip
,
2629 IDirectDrawSurfaceImpl_GetAttachedSurface
,
2630 IDirectDrawSurfaceImpl_GetBltStatus
,
2631 IDirectDrawSurfaceImpl_GetCaps
,
2632 IDirectDrawSurfaceImpl_GetClipper
,
2633 IDirectDrawSurfaceImpl_GetColorKey
,
2634 IDirectDrawSurfaceImpl_GetDC
,
2635 IDirectDrawSurfaceImpl_GetFlipStatus
,
2636 IDirectDrawSurfaceImpl_GetOverlayPosition
,
2637 IDirectDrawSurfaceImpl_GetPalette
,
2638 IDirectDrawSurfaceImpl_GetPixelFormat
,
2639 IDirectDrawSurfaceImpl_GetSurfaceDesc
,
2640 IDirectDrawSurfaceImpl_Initialize
,
2641 IDirectDrawSurfaceImpl_IsLost
,
2642 IDirectDrawSurfaceImpl_Lock
,
2643 IDirectDrawSurfaceImpl_ReleaseDC
,
2644 IDirectDrawSurfaceImpl_Restore
,
2645 IDirectDrawSurfaceImpl_SetClipper
,
2646 IDirectDrawSurfaceImpl_SetColorKey
,
2647 IDirectDrawSurfaceImpl_SetOverlayPosition
,
2648 IDirectDrawSurfaceImpl_SetPalette
,
2649 IDirectDrawSurfaceImpl_Unlock
,
2650 IDirectDrawSurfaceImpl_UpdateOverlay
,
2651 IDirectDrawSurfaceImpl_UpdateOverlayDisplay
,
2652 IDirectDrawSurfaceImpl_UpdateOverlayZOrder
,
2653 /*** IDirectDrawSurface2 ***/
2654 IDirectDrawSurfaceImpl_GetDDInterface
,
2655 IDirectDrawSurfaceImpl_PageLock
,
2656 IDirectDrawSurfaceImpl_PageUnlock
,
2657 /*** IDirectDrawSurface3 ***/
2658 IDirectDrawSurfaceImpl_SetSurfaceDesc
,
2659 /*** IDirectDrawSurface4 ***/
2660 IDirectDrawSurfaceImpl_SetPrivateData
,
2661 IDirectDrawSurfaceImpl_GetPrivateData
,
2662 IDirectDrawSurfaceImpl_FreePrivateData
,
2663 IDirectDrawSurfaceImpl_GetUniquenessValue
,
2664 IDirectDrawSurfaceImpl_ChangeUniquenessValue
,
2665 /*** IDirectDrawSurface7 ***/
2666 IDirectDrawSurfaceImpl_SetPriority
,
2667 IDirectDrawSurfaceImpl_GetPriority
,
2668 IDirectDrawSurfaceImpl_SetLOD
,
2669 IDirectDrawSurfaceImpl_GetLOD