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
);
478 if(This
->version
< 7)
480 /* Earlier dx apps put garbage into these members, clear them */
481 our_caps
.dwCaps
= Caps
->dwCaps
;
482 our_caps
.dwCaps2
= 0;
483 our_caps
.dwCaps3
= 0;
484 our_caps
.dwCaps4
= 0;
491 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 */
493 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
495 surf
= This
->complex_array
[i
];
500 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
501 surf
->surface_desc
.ddsCaps
.dwCaps
,
502 surf
->surface_desc
.ddsCaps
.dwCaps2
,
503 surf
->surface_desc
.ddsCaps
.dwCaps3
,
504 surf
->surface_desc
.ddsCaps
.dwCaps4
);
507 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
508 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
510 /* MSDN: "This method fails if more than one surface is attached
511 * that matches the capabilities requested."
513 * Not sure how to test this.
516 TRACE("(%p): Returning surface %p\n", This
, surf
);
517 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
518 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
519 IDirectDrawSurface7_AddRef(*Surface
);
520 LeaveCriticalSection(&ddraw_cs
);
525 /* Next, look at the attachment chain */
528 while( (surf
= surf
->next_attached
) )
532 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
533 surf
->surface_desc
.ddsCaps
.dwCaps
,
534 surf
->surface_desc
.ddsCaps
.dwCaps2
,
535 surf
->surface_desc
.ddsCaps
.dwCaps3
,
536 surf
->surface_desc
.ddsCaps
.dwCaps4
);
539 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
540 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
542 TRACE("(%p): Returning surface %p\n", This
, surf
);
543 *Surface
= ICOM_INTERFACE(surf
, IDirectDrawSurface7
);
544 IDirectDrawSurface7_AddRef(*Surface
);
545 LeaveCriticalSection(&ddraw_cs
);
550 TRACE("(%p) Didn't find a valid surface\n", This
);
551 LeaveCriticalSection(&ddraw_cs
);
554 return DDERR_NOTFOUND
;
557 /*****************************************************************************
558 * IDirectDrawSurface7::Lock
560 * Locks the surface and returns a pointer to the surface's memory
563 * Rect: Rectangle to lock. If NULL, the whole surface is locked
564 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
565 * Flags: Locking flags, e.g Read only or write only
566 * h: An event handle that's not used and must be NULL
570 * DDERR_INVALIDPARAMS if DDSD is NULL
571 * For more details, see IWineD3DSurface::LockRect
573 *****************************************************************************/
574 static HRESULT WINAPI
575 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7
*iface
,
577 DDSURFACEDESC2
*DDSD
,
581 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
582 WINED3DLOCKED_RECT LockedRect
;
584 TRACE("(%p)->(%p,%p,%x,%p)\n", This
, Rect
, DDSD
, Flags
, h
);
587 return DDERR_INVALIDPARAMS
;
589 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
590 EnterCriticalSection(&ddraw_cs
);
592 /* Should I check for the handle to be NULL?
594 * The DDLOCK flags and the D3DLOCK flags are equal
595 * for the supported values. The others are ignored by WineD3D
598 if(DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) &&
599 DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
601 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS
);
602 LeaveCriticalSection(&ddraw_cs
);
603 return DDERR_INVALIDPARAMS
;
606 /* Windows zeroes this if the rect is invalid */
613 || (Rect
->left
> Rect
->right
)
614 || (Rect
->top
> Rect
->bottom
)
615 || (Rect
->right
> This
->surface_desc
.dwWidth
)
616 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
618 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
619 LeaveCriticalSection(&ddraw_cs
);
620 return DDERR_INVALIDPARAMS
;
624 hr
= IWineD3DSurface_LockRect(This
->WineD3DSurface
,
630 LeaveCriticalSection(&ddraw_cs
);
633 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
634 * specific error. But since IWineD3DSurface::LockRect returns that error in this
635 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
636 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
637 * is much easier to do it in one place in ddraw
639 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
644 /* Override the memory area. The pitch should be set already. Strangely windows
645 * does not set the LPSURFACE flag on locked surfaces !?!.
646 * DDSD->dwFlags |= DDSD_LPSURFACE;
648 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
649 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
651 TRACE("locked surface returning description :\n");
652 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
654 LeaveCriticalSection(&ddraw_cs
);
658 /*****************************************************************************
659 * IDirectDrawSurface7::Unlock
661 * Unlocks an locked surface
664 * Rect: Not used by this implementation
668 * For more details, see IWineD3DSurface::UnlockRect
670 *****************************************************************************/
671 static HRESULT WINAPI
672 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7
*iface
,
675 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
677 TRACE("(%p)->(%p)\n", This
, pRect
);
679 EnterCriticalSection(&ddraw_cs
);
680 hr
= IWineD3DSurface_UnlockRect(This
->WineD3DSurface
);
683 This
->surface_desc
.lpSurface
= NULL
;
685 LeaveCriticalSection(&ddraw_cs
);
689 /*****************************************************************************
690 * IDirectDrawSurface7::Flip
692 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
693 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
694 * the flip target is passed to WineD3D, even if the app didn't specify one
697 * DestOverride: Specifies the surface that will become the new front
698 * buffer. If NULL, the current back buffer is used
699 * Flags: some DirectDraw flags, see include/ddraw.h
703 * DDERR_NOTFLIPPABLE if no flip target could be found
704 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
705 * For more details, see IWineD3DSurface::Flip
707 *****************************************************************************/
708 static HRESULT WINAPI
709 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7
*iface
,
710 IDirectDrawSurface7
*DestOverride
,
713 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
714 IDirectDrawSurfaceImpl
*Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DestOverride
);
715 IDirectDrawSurface7
*Override7
;
717 TRACE("(%p)->(%p,%x)\n", This
, DestOverride
, Flags
);
719 /* Flip has to be called from a front buffer
720 * What about overlay surfaces, AFAIK they can flip too?
722 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
723 return DDERR_INVALIDOBJECT
; /* Unchecked */
725 EnterCriticalSection(&ddraw_cs
);
727 /* WineD3D doesn't keep track of attached surface, so find the target */
732 memset(&Caps
, 0, sizeof(Caps
));
733 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
734 hr
= IDirectDrawSurface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
737 ERR("Can't find a flip target\n");
738 LeaveCriticalSection(&ddraw_cs
);
739 return DDERR_NOTFLIPPABLE
; /* Unchecked */
741 Override
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Override7
);
743 /* For the GetAttachedSurface */
744 IDirectDrawSurface7_Release(Override7
);
747 hr
= IWineD3DSurface_Flip(This
->WineD3DSurface
,
748 Override
->WineD3DSurface
,
750 LeaveCriticalSection(&ddraw_cs
);
754 /*****************************************************************************
755 * IDirectDrawSurface7::Blt
757 * Performs a blit on the surface
760 * DestRect: Destination rectangle, can be NULL
761 * SrcSurface: Source surface, can be NULL
762 * SrcRect: Source rectangle, can be NULL
764 * DDBltFx: Some extended blt parameters, connected to the flags
768 * See IWineD3DSurface::Blt for more details
770 *****************************************************************************/
771 static HRESULT WINAPI
772 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7
*iface
,
774 IDirectDrawSurface7
*SrcSurface
,
779 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
781 IDirectDrawSurfaceImpl
*Src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, SrcSurface
);
782 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This
, DestRect
, Src
, SrcRect
, Flags
, DDBltFx
);
784 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
785 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
787 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
788 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
789 return DDERR_INVALIDPARAMS
;
792 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
793 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
794 return DDERR_INVALIDPARAMS
;
797 /* Sizes can change, therefore hold the lock when testing the rectangles */
798 EnterCriticalSection(&ddraw_cs
);
801 if(DestRect
->top
>= DestRect
->bottom
|| DestRect
->left
>= DestRect
->right
||
802 DestRect
->right
> This
->surface_desc
.dwWidth
||
803 DestRect
->bottom
> This
->surface_desc
.dwHeight
)
805 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
806 LeaveCriticalSection(&ddraw_cs
);
807 return DDERR_INVALIDRECT
;
812 if(SrcRect
->top
>= SrcRect
->bottom
|| SrcRect
->left
>=SrcRect
->right
||
813 SrcRect
->right
> Src
->surface_desc
.dwWidth
||
814 SrcRect
->bottom
> Src
->surface_desc
.dwHeight
)
816 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
817 LeaveCriticalSection(&ddraw_cs
);
818 return DDERR_INVALIDRECT
;
822 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
823 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
824 LeaveCriticalSection(&ddraw_cs
);
825 return DDERR_INVALIDPARAMS
;
828 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
829 * and replace the ddraw surfaces with the wined3d surfaces
830 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
832 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
,
834 Src
? Src
->WineD3DSurface
: NULL
,
837 (WINEDDBLTFX
*) DDBltFx
,
840 LeaveCriticalSection(&ddraw_cs
);
843 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
844 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
849 /*****************************************************************************
850 * IDirectDrawSurface7::AddAttachedSurface
852 * Attaches a surface to another surface. How the surface attachments work
853 * is not totally understood yet, and this method is prone to problems.
854 * he surface that is attached is AddRef-ed.
856 * Tests with complex surfaces suggest that the surface attachments form a
857 * tree, but no method to test this has been found yet.
859 * The attachment list consists of a first surface (first_attached) and
860 * for each surface a pointer to the next attached surface (next_attached).
861 * For the first surface, and a surface that has no attachments
862 * first_attached points to the surface itself. A surface that has
863 * no successors in the chain has next_attached set to NULL.
865 * Newly attached surfaces are attached right after the root surface.
866 * If a surface is attached to a complex surface compound, it's attached to
867 * the surface that the app requested, not the complex root. See
868 * GetAttachedSurface for a description how surfaces are found.
870 * This is how the current implementation works, and it was coded by looking
871 * at the needs of the applications.
873 * So far only Z-Buffer attachments are tested, and they are activated in
874 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
875 * Back buffers should work in 2D mode, but they are not tested(They can be
876 * attached in older iface versions). Rendering to the front buffer and
877 * switching between that and double buffering is not yet implemented in
878 * WineD3D, so for 3D it might have unexpected results.
880 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
881 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
882 * performs additional checks. Version 7 of this interface is much more restrictive
883 * than its predecessors.
886 * Attach: Surface to attach to iface
890 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
892 *****************************************************************************/
894 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl
*This
,
895 IDirectDrawSurfaceImpl
*Surf
)
897 TRACE("(%p)->(%p)\n", This
, Surf
);
900 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
902 EnterCriticalSection(&ddraw_cs
);
904 /* Check if the surface is already attached somewhere */
905 if( (Surf
->next_attached
!= NULL
) ||
906 (Surf
->first_attached
!= Surf
) )
908 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
909 * What happens if one surface is attached to 2 different surfaces?
911 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
);
912 LeaveCriticalSection(&ddraw_cs
);
913 return DDERR_SURFACEALREADYATTACHED
;
916 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
917 Surf
->next_attached
= This
->next_attached
;
918 Surf
->first_attached
= This
->first_attached
;
919 This
->next_attached
= Surf
;
921 /* Check if the WineD3D depth stencil needs updating */
922 if(This
->ddraw
->d3ddevice
)
924 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
928 * "This method increments the reference count of the surface being attached."
930 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(Surf
, IDirectDrawSurface7
));
931 LeaveCriticalSection(&ddraw_cs
);
935 static HRESULT WINAPI
936 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7
*iface
,
937 IDirectDrawSurface7
*Attach
)
939 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
940 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
942 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
943 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
946 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
947 Surf
->surface_desc
.ddsCaps
.dwCaps
);
948 return DDERR_CANNOTATTACHSURFACE
;
951 return IDirectDrawSurfaceImpl_AddAttachedSurface(This
,
954 /*****************************************************************************
955 * IDirectDrawSurface7::DeleteAttachedSurface
957 * Removes a surface from the attachment chain. The surface's refcount
958 * is decreased by one after it has been removed
961 * Flags: Some flags, not used by this implementation
962 * Attach: Surface to detach
966 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
968 *****************************************************************************/
969 static HRESULT WINAPI
970 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
972 IDirectDrawSurface7
*Attach
)
974 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
975 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Attach
);
976 IDirectDrawSurfaceImpl
*Prev
= This
;
977 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, Surf
);
979 EnterCriticalSection(&ddraw_cs
);
980 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
982 LeaveCriticalSection(&ddraw_cs
);
983 return DDERR_CANNOTDETACHSURFACE
;
986 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
987 if (This
->surface_desc
.ddsCaps
.dwCaps
&
988 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
990 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
991 /* FIXME: we should probably also subtract from dwMipMapCount of this
992 * and all parent surfaces */
995 /* Find the predecessor of the detached surface */
998 if(Prev
->next_attached
== Surf
) break;
999 Prev
= Prev
->next_attached
;
1002 /* There must be a surface, otherwise there's a bug */
1003 assert(Prev
!= NULL
);
1005 /* Unchain the surface */
1006 Prev
->next_attached
= Surf
->next_attached
;
1007 Surf
->next_attached
= NULL
;
1008 Surf
->first_attached
= Surf
;
1010 /* Check if the WineD3D depth stencil needs updating */
1011 if(This
->ddraw
->d3ddevice
)
1013 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1016 IDirectDrawSurface7_Release(Attach
);
1017 LeaveCriticalSection(&ddraw_cs
);
1021 /*****************************************************************************
1022 * IDirectDrawSurface7::AddOverlayDirtyRect
1024 * "This method is not currently implemented"
1032 *****************************************************************************/
1033 static HRESULT WINAPI
1034 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
,
1037 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1038 TRACE("(%p)->(%p)\n",This
,Rect
);
1040 /* MSDN says it's not implemented. I could forward it to WineD3D,
1041 * then we'd implement it, but I don't think that's a good idea
1042 * (Stefan Dösinger)
1045 return IWineD3DSurface_AddOverlayDirtyRect(This
->WineD3DSurface
, pRect
);
1047 return DDERR_UNSUPPORTED
; /* unchecked */
1050 /*****************************************************************************
1051 * IDirectDrawSurface7::GetDC
1053 * Returns a GDI device context for the surface
1056 * hdc: Address of a HDC variable to store the dc to
1060 * DDERR_INVALIDPARAMS if hdc is NULL
1061 * For details, see IWineD3DSurface::GetDC
1063 *****************************************************************************/
1064 static HRESULT WINAPI
1065 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7
*iface
,
1068 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1070 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1073 return DDERR_INVALIDPARAMS
;
1075 EnterCriticalSection(&ddraw_cs
);
1076 hr
= IWineD3DSurface_GetDC(This
->WineD3DSurface
,
1078 LeaveCriticalSection(&ddraw_cs
);
1082 /*****************************************************************************
1083 * IDirectDrawSurface7::ReleaseDC
1085 * Releases the DC that was constructed with GetDC
1088 * hdc: HDC to release
1092 * For more details, see IWineD3DSurface::ReleaseDC
1094 *****************************************************************************/
1095 static HRESULT WINAPI
1096 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7
*iface
,
1099 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1101 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1103 EnterCriticalSection(&ddraw_cs
);
1104 hr
= IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
1105 LeaveCriticalSection(&ddraw_cs
);
1109 /*****************************************************************************
1110 * IDirectDrawSurface7::GetCaps
1112 * Returns the surface's caps
1115 * Caps: Address to write the caps to
1119 * DDERR_INVALIDPARAMS if Caps is NULL
1121 *****************************************************************************/
1122 static HRESULT WINAPI
1123 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7
*iface
,
1126 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1127 TRACE("(%p)->(%p)\n",This
,Caps
);
1130 return DDERR_INVALIDPARAMS
;
1132 *Caps
= This
->surface_desc
.ddsCaps
;
1136 /*****************************************************************************
1137 * IDirectDrawSurface7::SetPriority
1139 * Sets a texture priority for managed textures.
1142 * Priority: The new priority
1146 * For more details, see IWineD3DSurface::SetPriority
1148 *****************************************************************************/
1149 static HRESULT WINAPI
1150 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1152 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1154 TRACE("(%p)->(%d): Relay!\n",This
,Priority
);
1156 EnterCriticalSection(&ddraw_cs
);
1157 hr
= IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1158 LeaveCriticalSection(&ddraw_cs
);
1162 /*****************************************************************************
1163 * IDirectDrawSurface7::GetPriority
1165 * Returns the surface's priority
1168 * Priority: Address of a variable to write the priority to
1172 * DDERR_INVALIDPARAMS if Priority == NULL
1173 * For more details, see IWineD3DSurface::GetPriority
1175 *****************************************************************************/
1176 static HRESULT WINAPI
1177 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7
*iface
,
1180 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1181 TRACE("(%p)->(%p): Relay\n",This
,Priority
);
1185 return DDERR_INVALIDPARAMS
;
1188 EnterCriticalSection(&ddraw_cs
);
1189 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1190 LeaveCriticalSection(&ddraw_cs
);
1194 /*****************************************************************************
1195 * IDirectDrawSurface7::SetPrivateData
1197 * Stores some data in the surface that is intended for the application's
1201 * tag: GUID that identifies the data
1202 * Data: Pointer to the private data
1203 * Size: Size of the private data
1208 * For more details, see IWineD3DSurface::SetPrivateData
1210 *****************************************************************************/
1211 static HRESULT WINAPI
1212 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7
*iface
,
1218 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1220 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This
, debugstr_guid(tag
), Data
, Size
, Flags
);
1222 EnterCriticalSection(&ddraw_cs
);
1223 hr
= IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1228 LeaveCriticalSection(&ddraw_cs
);
1231 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1236 /*****************************************************************************
1237 * IDirectDrawSurface7::GetPrivateData
1239 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1242 * tag: GUID of the data to return
1243 * Data: Address where to write the data to
1244 * Size: Size of the buffer at Data
1248 * DDERR_INVALIDPARAMS if Data is NULL
1249 * For more details, see IWineD3DSurface::GetPrivateData
1251 *****************************************************************************/
1252 static HRESULT WINAPI
1253 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7
*iface
,
1258 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1260 TRACE("(%p)->(%s,%p,%p): Relay\n", This
, debugstr_guid(tag
), Data
, Size
);
1263 return DDERR_INVALIDPARAMS
;
1265 EnterCriticalSection(&ddraw_cs
);
1266 hr
= IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1270 LeaveCriticalSection(&ddraw_cs
);
1274 /*****************************************************************************
1275 * IDirectDrawSurface7::FreePrivateData
1277 * Frees private data stored in the surface
1280 * tag: Tag of the data to free
1284 * For more details, see IWineD3DSurface::FreePrivateData
1286 *****************************************************************************/
1287 static HRESULT WINAPI
1288 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7
*iface
,
1291 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1293 TRACE("(%p)->(%s): Relay\n", This
, debugstr_guid(tag
));
1295 EnterCriticalSection(&ddraw_cs
);
1296 hr
= IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1297 LeaveCriticalSection(&ddraw_cs
);
1301 /*****************************************************************************
1302 * IDirectDrawSurface7::PageLock
1304 * Prevents a sysmem surface from being paged out
1307 * Flags: Not used, must be 0(unchecked)
1310 * DD_OK, because it's a stub
1312 *****************************************************************************/
1313 static HRESULT WINAPI
1314 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7
*iface
,
1317 TRACE("(%p)->(%x)\n", iface
, Flags
);
1319 /* This is Windows memory management related - we don't need this */
1323 /*****************************************************************************
1324 * IDirectDrawSurface7::PageUnlock
1326 * Allows a sysmem surface to be paged out
1329 * Flags: Not used, must be 0(unchecked)
1332 * DD_OK, because it's a stub
1334 *****************************************************************************/
1335 static HRESULT WINAPI
1336 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7
*iface
,
1339 TRACE("(%p)->(%x)\n", iface
, Flags
);
1344 /*****************************************************************************
1345 * IDirectDrawSurface7::BltBatch
1347 * An unimplemented function
1355 *****************************************************************************/
1356 static HRESULT WINAPI
IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1358 TRACE("(%p)->(%p,%d,%08x)\n",iface
,Batch
,Count
,Flags
);
1360 /* MSDN: "not currently implemented" */
1361 return DDERR_UNSUPPORTED
;
1364 /*****************************************************************************
1365 * IDirectDrawSurface7::EnumAttachedSurfaces
1367 * Enumerates all surfaces attached to this surface
1370 * context: Pointer to pass unmodified to the callback
1371 * cb: Callback function to call for each surface
1375 * DDERR_INVALIDPARAMS if cb is NULL
1377 *****************************************************************************/
1378 static HRESULT WINAPI
1379 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1381 LPDDENUMSURFACESCALLBACK7 cb
)
1383 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1384 IDirectDrawSurfaceImpl
*surf
;
1385 DDSURFACEDESC2 desc
;
1388 /* Attached surfaces aren't handled in WineD3D */
1389 TRACE("(%p)->(%p,%p)\n",This
,context
,cb
);
1392 return DDERR_INVALIDPARAMS
;
1394 EnterCriticalSection(&ddraw_cs
);
1395 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1397 surf
= This
->complex_array
[i
];
1400 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1401 desc
= surf
->surface_desc
;
1402 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1403 if (cb(ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1405 LeaveCriticalSection(&ddraw_cs
);
1410 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1412 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
1413 desc
= surf
->surface_desc
;
1414 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1415 if (cb( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, context
) == DDENUMRET_CANCEL
)
1417 LeaveCriticalSection(&ddraw_cs
);
1422 TRACE(" end of enumeration.\n");
1424 LeaveCriticalSection(&ddraw_cs
);
1428 /*****************************************************************************
1429 * IDirectDrawSurface7::EnumOverlayZOrders
1431 * "Enumerates the overlay surfaces on the specified destination"
1434 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1435 * context: context to pass back to the callback
1436 * cb: callback function to call for each enumerated surface
1439 * DD_OK, because it's a stub
1441 *****************************************************************************/
1442 static HRESULT WINAPI
1443 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1446 LPDDENUMSURFACESCALLBACK7 cb
)
1448 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface
, Flags
, context
, cb
);
1453 /*****************************************************************************
1454 * IDirectDrawSurface7::GetBltStatus
1456 * Returns the blitting status
1459 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1462 * See IWineD3DSurface::Blt
1464 *****************************************************************************/
1465 static HRESULT WINAPI
1466 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7
*iface
,
1469 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1471 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1473 EnterCriticalSection(&ddraw_cs
);
1474 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1475 LeaveCriticalSection(&ddraw_cs
);
1478 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1483 /*****************************************************************************
1484 * IDirectDrawSurface7::GetColorKey
1486 * Returns the color key assigned to the surface
1490 * CKey: Address to store the key to
1494 * DDERR_INVALIDPARAMS if CKey is NULL
1496 *****************************************************************************/
1497 static HRESULT WINAPI
1498 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7
*iface
,
1502 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1503 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, CKey
);
1506 return DDERR_INVALIDPARAMS
;
1508 EnterCriticalSection(&ddraw_cs
);
1512 case DDCKEY_DESTBLT
:
1513 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1515 LeaveCriticalSection(&ddraw_cs
);
1516 return DDERR_NOCOLORKEY
;
1518 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1521 case DDCKEY_DESTOVERLAY
:
1522 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
1524 LeaveCriticalSection(&ddraw_cs
);
1525 return DDERR_NOCOLORKEY
;
1527 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1531 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
1533 LeaveCriticalSection(&ddraw_cs
);
1534 return DDERR_NOCOLORKEY
;
1536 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1539 case DDCKEY_SRCOVERLAY
:
1540 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
1542 LeaveCriticalSection(&ddraw_cs
);
1543 return DDERR_NOCOLORKEY
;
1545 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1549 LeaveCriticalSection(&ddraw_cs
);
1550 return DDERR_INVALIDPARAMS
;
1553 LeaveCriticalSection(&ddraw_cs
);
1557 /*****************************************************************************
1558 * IDirectDrawSurface7::GetFlipStatus
1560 * Returns the flipping status of the surface
1563 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1566 * See IWineD3DSurface::GetFlipStatus
1568 *****************************************************************************/
1569 static HRESULT WINAPI
1570 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7
*iface
,
1573 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1575 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1577 EnterCriticalSection(&ddraw_cs
);
1578 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1579 LeaveCriticalSection(&ddraw_cs
);
1582 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1587 /*****************************************************************************
1588 * IDirectDrawSurface7::GetOverlayPosition
1590 * Returns the display coordinates of a visible and active overlay surface
1597 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1598 *****************************************************************************/
1599 static HRESULT WINAPI
1600 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7
*iface
,
1603 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1605 TRACE("(%p)->(%p,%p): Relay\n", This
, X
, Y
);
1607 EnterCriticalSection(&ddraw_cs
);
1608 hr
= IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1611 LeaveCriticalSection(&ddraw_cs
);
1615 /*****************************************************************************
1616 * IDirectDrawSurface7::GetPixelFormat
1618 * Returns the pixel format of the Surface
1621 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1622 * format should be written
1626 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1628 *****************************************************************************/
1629 static HRESULT WINAPI
1630 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7
*iface
,
1631 DDPIXELFORMAT
*PixelFormat
)
1633 /* What is DDERR_INVALIDSURFACETYPE for here? */
1634 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1635 TRACE("(%p)->(%p)\n",This
,PixelFormat
);
1638 return DDERR_INVALIDPARAMS
;
1640 EnterCriticalSection(&ddraw_cs
);
1641 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1642 LeaveCriticalSection(&ddraw_cs
);
1648 /*****************************************************************************
1649 * IDirectDrawSurface7::GetSurfaceDesc
1651 * Returns the description of this surface
1654 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1659 * DDERR_INVALIDPARAMS if DDSD is NULL
1661 *****************************************************************************/
1662 static HRESULT WINAPI
1663 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7
*iface
,
1664 DDSURFACEDESC2
*DDSD
)
1666 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1668 TRACE("(%p)->(%p)\n",This
,DDSD
);
1671 return DDERR_INVALIDPARAMS
;
1673 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
1675 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
1676 return DDERR_INVALIDPARAMS
;
1679 EnterCriticalSection(&ddraw_cs
);
1680 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1681 TRACE("Returning surface desc:\n");
1682 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1684 LeaveCriticalSection(&ddraw_cs
);
1688 /*****************************************************************************
1689 * IDirectDrawSurface7::Initialize
1691 * Initializes the surface. This is a no-op in Wine
1694 * DD: Pointer to an DirectDraw interface
1695 * DDSD: Surface description for initialization
1698 * DDERR_ALREADYINITIALIZED
1700 *****************************************************************************/
1701 static HRESULT WINAPI
1702 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7
*iface
,
1704 DDSURFACEDESC2
*DDSD
)
1706 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1707 IDirectDrawImpl
*ddimpl
= ICOM_OBJECT(IDirectDrawImpl
, IDirectDraw
, DD
);
1708 TRACE("(%p)->(%p,%p)\n",This
,ddimpl
,DDSD
);
1710 return DDERR_ALREADYINITIALIZED
;
1713 /*****************************************************************************
1714 * IDirectDrawSurface7::IsLost
1716 * Checks if the surface is lost
1719 * DD_OK, if the surface is usable
1720 * DDERR_ISLOST if the surface is lost
1721 * See IWineD3DSurface::IsLost for more details
1723 *****************************************************************************/
1724 static HRESULT WINAPI
1725 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7
*iface
)
1727 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1729 TRACE("(%p)\n", This
);
1731 EnterCriticalSection(&ddraw_cs
);
1732 /* We lose the surface if the implementation was changed */
1733 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1735 /* But this shouldn't happen. When we change the implementation,
1736 * all surfaces are re-created automatically, and their content
1739 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
1740 LeaveCriticalSection(&ddraw_cs
);
1741 return DDERR_SURFACELOST
;
1744 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
1745 LeaveCriticalSection(&ddraw_cs
);
1748 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1749 * WineD3D uses the same error for surfaces
1751 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
1756 /*****************************************************************************
1757 * IDirectDrawSurface7::Restore
1759 * Restores a lost surface. This makes the surface usable again, but
1760 * doesn't reload its old contents
1764 * See IWineD3DSurface::Restore for more details
1766 *****************************************************************************/
1767 static HRESULT WINAPI
1768 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7
*iface
)
1770 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1772 TRACE("(%p)\n", This
);
1774 EnterCriticalSection(&ddraw_cs
);
1775 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1777 /* Call the recreation callback. Make sure to AddRef first */
1778 IDirectDrawSurface_AddRef(iface
);
1779 IDirectDrawImpl_RecreateSurfacesCallback(iface
,
1780 &This
->surface_desc
,
1781 NULL
/* Not needed */);
1783 hr
= IWineD3DSurface_Restore(This
->WineD3DSurface
);
1784 LeaveCriticalSection(&ddraw_cs
);
1788 /*****************************************************************************
1789 * IDirectDrawSurface7::SetOverlayPosition
1791 * Changes the display coordinates of an overlay surface
1798 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1799 *****************************************************************************/
1800 static HRESULT WINAPI
1801 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7
*iface
,
1805 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1807 TRACE("(%p)->(%d,%d): Relay\n", This
, X
, Y
);
1809 EnterCriticalSection(&ddraw_cs
);
1810 hr
= IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
1813 LeaveCriticalSection(&ddraw_cs
);
1817 /*****************************************************************************
1818 * IDirectDrawSurface7::UpdateOverlay
1820 * Modifies the attributes of an overlay surface.
1823 * SrcRect: The section of the source being used for the overlay
1824 * DstSurface: Address of the surface that is overlaid
1825 * DstRect: Place of the overlay
1826 * Flags: some DDOVER_* flags
1829 * DDERR_UNSUPPORTED, because we don't support overlays
1831 *****************************************************************************/
1832 static HRESULT WINAPI
1833 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7
*iface
,
1835 IDirectDrawSurface7
*DstSurface
,
1840 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1841 IDirectDrawSurfaceImpl
*Dst
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DstSurface
);
1843 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This
, SrcRect
, Dst
, DstRect
, Flags
, FX
);
1845 EnterCriticalSection(&ddraw_cs
);
1846 hr
= IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
1848 Dst
? Dst
->WineD3DSurface
: NULL
,
1851 (WINEDDOVERLAYFX
*) FX
);
1852 LeaveCriticalSection(&ddraw_cs
);
1854 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1855 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
1856 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
1862 /*****************************************************************************
1863 * IDirectDrawSurface7::UpdateOverlayDisplay
1865 * The DX7 sdk says that it's not implemented
1870 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1872 *****************************************************************************/
1873 static HRESULT WINAPI
1874 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
,
1877 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1878 TRACE("(%p)->(%x)\n", This
, Flags
);
1879 return DDERR_UNSUPPORTED
;
1882 /*****************************************************************************
1883 * IDirectDrawSurface7::UpdateOverlayZOrder
1885 * Sets an overlay's Z order
1888 * Flags: DDOVERZ_* flags
1889 * DDSRef: Defines the relative position in the overlay chain
1892 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1894 *****************************************************************************/
1895 static HRESULT WINAPI
1896 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
1898 IDirectDrawSurface7
*DDSRef
)
1900 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1902 IDirectDrawSurfaceImpl
*Ref
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, DDSRef
);
1904 TRACE("(%p)->(%x,%p): Relay\n", This
, Flags
, Ref
);
1905 EnterCriticalSection(&ddraw_cs
);
1906 hr
= IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
1908 Ref
? Ref
->WineD3DSurface
: NULL
);
1909 LeaveCriticalSection(&ddraw_cs
);
1913 /*****************************************************************************
1914 * IDirectDrawSurface7::GetDDInterface
1916 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1917 * surface belongs to
1920 * DD: Address to write the interface pointer to
1924 * DDERR_INVALIDPARAMS if DD is NULL
1926 *****************************************************************************/
1927 static HRESULT WINAPI
1928 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7
*iface
,
1931 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1933 TRACE("(%p)->(%p)\n",This
,DD
);
1936 return DDERR_INVALIDPARAMS
;
1938 switch(This
->version
)
1941 *((IDirectDraw7
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw7
);
1942 IDirectDraw7_AddRef(*(IDirectDraw7
**) DD
);
1946 *((IDirectDraw4
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw4
);
1947 IDirectDraw4_AddRef(*(IDirectDraw4
**) DD
);
1951 *((IDirectDraw2
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw2
);
1952 IDirectDraw_AddRef( *(IDirectDraw2
**) DD
);
1956 *((IDirectDraw
**) DD
) = ICOM_INTERFACE(This
->ddraw
, IDirectDraw
);
1957 IDirectDraw_AddRef( *(IDirectDraw
**) DD
);
1965 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1966 static HRESULT WINAPI
IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
1968 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1969 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
1971 TRACE("(%p)\n",This
);
1972 EnterCriticalSection(&ddraw_cs
);
1973 /* A uniqueness value of 0 is apparently special.
1974 * This needs to be checked.
1975 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1978 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
1979 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
1981 if (old_uniqueness_value
== 0) break;
1982 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
1984 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
1985 old_uniqueness_value
,
1986 new_uniqueness_value
)
1987 == old_uniqueness_value
)
1991 LeaveCriticalSection(&ddraw_cs
);
1995 static HRESULT WINAPI
IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7
*iface
, LPDWORD pValue
)
1997 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
1999 TRACE("(%p)->(%p)\n",This
,pValue
);
2000 EnterCriticalSection(&ddraw_cs
);
2001 *pValue
= This
->uniqueness_value
;
2002 LeaveCriticalSection(&ddraw_cs
);
2006 /*****************************************************************************
2007 * IDirectDrawSurface7::SetLOD
2009 * Sets the level of detail of a texture
2012 * MaxLOD: LOD to set
2016 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2018 *****************************************************************************/
2019 static HRESULT WINAPI
2020 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7
*iface
,
2023 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2025 TRACE("(%p)->(%d)\n", This
, MaxLOD
);
2027 EnterCriticalSection(&ddraw_cs
);
2028 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2030 LeaveCriticalSection(&ddraw_cs
);
2031 return DDERR_INVALIDOBJECT
;
2034 if(!This
->wineD3DTexture
)
2036 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
2037 LeaveCriticalSection(&ddraw_cs
);
2038 return DDERR_INVALIDOBJECT
;
2041 hr
= IWineD3DBaseTexture_SetLOD(This
->wineD3DTexture
,
2043 LeaveCriticalSection(&ddraw_cs
);
2047 /*****************************************************************************
2048 * IDirectDrawSurface7::GetLOD
2050 * Returns the level of detail of a Direct3D texture
2053 * MaxLOD: Address to write the LOD to
2057 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2058 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2060 *****************************************************************************/
2061 static HRESULT WINAPI
2062 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7
*iface
,
2065 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2066 TRACE("(%p)->(%p)\n", This
, MaxLOD
);
2069 return DDERR_INVALIDPARAMS
;
2071 EnterCriticalSection(&ddraw_cs
);
2072 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2074 LeaveCriticalSection(&ddraw_cs
);
2075 return DDERR_INVALIDOBJECT
;
2078 *MaxLOD
= IWineD3DBaseTexture_GetLOD(This
->wineD3DTexture
);
2079 LeaveCriticalSection(&ddraw_cs
);
2083 /*****************************************************************************
2084 * IDirectDrawSurface7::BltFast
2086 * Performs a fast Blit.
2089 * dstx: The x coordinate to blit to on the destination
2090 * dsty: The y coordinate to blit to on the destination
2091 * Source: The source surface
2092 * rsrc: The source rectangle
2093 * trans: Type of transfer. Some DDBLTFAST_* flags
2097 * For more details, see IWineD3DSurface::BltFast
2099 *****************************************************************************/
2100 static HRESULT WINAPI
2101 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7
*iface
,
2104 IDirectDrawSurface7
*Source
,
2108 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2110 IDirectDrawSurfaceImpl
*src
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Source
);
2111 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This
, dstx
, dsty
, Source
, rsrc
, trans
);
2113 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2118 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
2119 rsrc
->right
> src
->surface_desc
.dwWidth
||
2120 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
2122 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2123 return DDERR_INVALIDRECT
;
2125 if(dstx
+ rsrc
->right
- rsrc
->left
> This
->surface_desc
.dwWidth
||
2126 dsty
+ rsrc
->bottom
- rsrc
->top
> This
->surface_desc
.dwHeight
)
2128 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2129 return DDERR_INVALIDRECT
;
2134 if(dstx
+ src
->surface_desc
.dwWidth
> This
->surface_desc
.dwWidth
||
2135 dsty
+ src
->surface_desc
.dwHeight
> This
->surface_desc
.dwHeight
)
2137 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2138 return DDERR_INVALIDRECT
;
2142 EnterCriticalSection(&ddraw_cs
);
2143 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
2145 src
? src
->WineD3DSurface
: NULL
,
2148 LeaveCriticalSection(&ddraw_cs
);
2151 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
2152 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
2157 /*****************************************************************************
2158 * IDirectDrawSurface7::GetClipper
2160 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2164 * Clipper: Address to store the interface pointer at
2168 * DDERR_INVALIDPARAMS if Clipper is NULL
2169 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2171 *****************************************************************************/
2172 static HRESULT WINAPI
2173 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7
*iface
,
2174 IDirectDrawClipper
**Clipper
)
2176 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2177 TRACE("(%p)->(%p)\n", This
, Clipper
);
2181 LeaveCriticalSection(&ddraw_cs
);
2182 return DDERR_INVALIDPARAMS
;
2185 EnterCriticalSection(&ddraw_cs
);
2186 if(This
->clipper
== NULL
)
2188 LeaveCriticalSection(&ddraw_cs
);
2189 return DDERR_NOCLIPPERATTACHED
;
2192 *Clipper
= ICOM_INTERFACE(This
->clipper
, IDirectDrawClipper
);
2193 IDirectDrawClipper_AddRef(*Clipper
);
2194 LeaveCriticalSection(&ddraw_cs
);
2198 /*****************************************************************************
2199 * IDirectDrawSurface7::SetClipper
2201 * Sets a clipper for the surface
2204 * Clipper: IDirectDrawClipper interface of the clipper to set
2209 *****************************************************************************/
2210 static HRESULT WINAPI
2211 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7
*iface
,
2212 IDirectDrawClipper
*Clipper
)
2214 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2215 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
2218 TRACE("(%p)->(%p)\n",This
,Clipper
);
2220 EnterCriticalSection(&ddraw_cs
);
2221 if (ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
) == This
->clipper
)
2223 LeaveCriticalSection(&ddraw_cs
);
2227 This
->clipper
= ICOM_OBJECT(IDirectDrawClipperImpl
, IDirectDrawClipper
, Clipper
);
2229 if (Clipper
!= NULL
)
2230 IDirectDrawClipper_AddRef(Clipper
);
2232 IDirectDrawClipper_Release(ICOM_INTERFACE(oldClipper
, IDirectDrawClipper
));
2234 hr
= IWineD3DSurface_SetClipper(This
->WineD3DSurface
, This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
2236 if(This
->wineD3DSwapChain
) {
2239 IDirectDrawClipper_GetHWnd(Clipper
, &clipWindow
);
2243 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2246 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2247 This
->ddraw
->d3d_window
);
2251 LeaveCriticalSection(&ddraw_cs
);
2255 /*****************************************************************************
2256 * IDirectDrawSurface7::SetSurfaceDesc
2258 * Sets the surface description. It can override the pixel format, the surface
2260 * It's not really tested.
2263 * DDSD: Pointer to the new surface description to set
2268 * DDERR_INVALIDPARAMS if DDSD is NULL
2270 *****************************************************************************/
2271 static HRESULT WINAPI
2272 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7
*iface
,
2273 DDSURFACEDESC2
*DDSD
,
2276 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2277 WINED3DFORMAT newFormat
= WINED3DFMT_UNKNOWN
;
2279 TRACE("(%p)->(%p,%x)\n", This
, DDSD
, Flags
);
2282 return DDERR_INVALIDPARAMS
;
2284 EnterCriticalSection(&ddraw_cs
);
2285 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2287 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2289 if(newFormat
== WINED3DFMT_UNKNOWN
)
2291 ERR("Requested to set an unknown pixelformat\n");
2292 LeaveCriticalSection(&ddraw_cs
);
2293 return DDERR_INVALIDPARAMS
;
2295 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2297 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2301 LeaveCriticalSection(&ddraw_cs
);
2306 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2308 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2310 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2312 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2314 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2316 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2318 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2320 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2322 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2324 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2326 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2328 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2330 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
2332 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2333 if(hr
!= WINED3D_OK
)
2335 /* No need for a trace here, wined3d does that for us */
2336 LeaveCriticalSection(&ddraw_cs
);
2339 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2340 default: break; /* Go on */
2346 This
->surface_desc
= *DDSD
;
2348 LeaveCriticalSection(&ddraw_cs
);
2352 /*****************************************************************************
2353 * IDirectDrawSurface7::GetPalette
2355 * Returns the IDirectDrawPalette interface of the palette currently assigned
2359 * Pal: Address to write the interface pointer to
2363 * DDERR_INVALIDPARAMS if Pal is NULL
2365 *****************************************************************************/
2366 static HRESULT WINAPI
2367 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7
*iface
,
2368 IDirectDrawPalette
**Pal
)
2370 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2371 IWineD3DPalette
*wPal
;
2373 TRACE("(%p)->(%p): Relay\n", This
, Pal
);
2376 return DDERR_INVALIDPARAMS
;
2378 EnterCriticalSection(&ddraw_cs
);
2379 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wPal
);
2382 LeaveCriticalSection(&ddraw_cs
);
2388 hr
= IWineD3DPalette_GetParent(wPal
, (IUnknown
**) Pal
);
2393 hr
= DDERR_NOPALETTEATTACHED
;
2396 LeaveCriticalSection(&ddraw_cs
);
2400 /*****************************************************************************
2403 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2404 * recursively in the surface tree
2406 *****************************************************************************/
2410 WINEDDCOLORKEY
*CKey
;
2414 static HRESULT WINAPI
2415 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2416 DDSURFACEDESC2
*desc
,
2419 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2420 struct SCKContext
*ctx
= context
;
2423 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2428 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2432 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
2435 IDirectDrawSurface7_Release(surface
);
2436 return DDENUMRET_OK
;
2439 /*****************************************************************************
2440 * IDirectDrawSurface7::SetColorKey
2442 * Sets the color keying options for the surface. Observations showed that
2443 * in case of complex surfaces the color key has to be assigned to all
2448 * CKey: The new color key
2452 * See IWineD3DSurface::SetColorKey for details
2454 *****************************************************************************/
2455 static HRESULT WINAPI
2456 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7
*iface
,
2460 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2461 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) CKey
, Flags
};
2462 TRACE("(%p)->(%x,%p)\n", This
, Flags
, CKey
);
2464 EnterCriticalSection(&ddraw_cs
);
2467 switch (Flags
& ~DDCKEY_COLORSPACE
)
2469 case DDCKEY_DESTBLT
:
2470 This
->surface_desc
.ddckCKDestBlt
= *CKey
;
2471 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2474 case DDCKEY_DESTOVERLAY
:
2475 This
->surface_desc
.u3
.ddckCKDestOverlay
= *CKey
;
2476 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2479 case DDCKEY_SRCOVERLAY
:
2480 This
->surface_desc
.ddckCKSrcOverlay
= *CKey
;
2481 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2485 This
->surface_desc
.ddckCKSrcBlt
= *CKey
;
2486 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2490 LeaveCriticalSection(&ddraw_cs
);
2491 return DDERR_INVALIDPARAMS
;
2496 switch (Flags
& ~DDCKEY_COLORSPACE
)
2498 case DDCKEY_DESTBLT
:
2499 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2502 case DDCKEY_DESTOVERLAY
:
2503 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2506 case DDCKEY_SRCOVERLAY
:
2507 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2511 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2515 LeaveCriticalSection(&ddraw_cs
);
2516 return DDERR_INVALIDPARAMS
;
2519 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2522 IDirectDrawSurface7_EnumAttachedSurfaces(iface
,
2525 LeaveCriticalSection(&ddraw_cs
);
2528 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2529 default: return ctx
.ret
;
2533 /*****************************************************************************
2534 * IDirectDrawSurface7::SetPalette
2536 * Assigns a DirectDrawPalette object to the surface
2539 * Pal: Interface to the palette to set
2544 *****************************************************************************/
2545 static HRESULT WINAPI
2546 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7
*iface
,
2547 IDirectDrawPalette
*Pal
)
2549 ICOM_THIS_FROM(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, iface
);
2550 IDirectDrawPalette
*oldPal
;
2551 IDirectDrawSurfaceImpl
*surf
;
2552 IDirectDrawPaletteImpl
*PalImpl
= ICOM_OBJECT(IDirectDrawPaletteImpl
, IDirectDrawPalette
, Pal
);
2554 TRACE("(%p)->(%p)\n", This
, Pal
);
2556 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
2557 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
2558 return DDERR_INVALIDPIXELFORMAT
;
2561 /* Find the old palette */
2562 EnterCriticalSection(&ddraw_cs
);
2563 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2564 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
2566 LeaveCriticalSection(&ddraw_cs
);
2569 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2571 /* Set the new Palette */
2572 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2573 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2574 /* AddRef the Palette */
2575 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2577 /* Release the old palette */
2578 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2580 /* If this is a front buffer, also update the back buffers
2581 * TODO: How do things work for palettized cube textures?
2583 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2585 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2586 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2591 IDirectDrawSurface7
*attach
;
2593 hr
= IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
2600 TRACE("Setting palette on %p\n", attach
);
2601 IDirectDrawSurface7_SetPalette(attach
,
2603 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attach
);
2604 IDirectDrawSurface7_Release(attach
);
2608 LeaveCriticalSection(&ddraw_cs
);
2612 /*****************************************************************************
2614 *****************************************************************************/
2616 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
=
2619 IDirectDrawSurfaceImpl_QueryInterface
,
2620 IDirectDrawSurfaceImpl_AddRef
,
2621 IDirectDrawSurfaceImpl_Release
,
2622 /*** IDirectDrawSurface ***/
2623 IDirectDrawSurface7Impl_AddAttachedSurface
,
2624 IDirectDrawSurfaceImpl_AddOverlayDirtyRect
,
2625 IDirectDrawSurfaceImpl_Blt
,
2626 IDirectDrawSurfaceImpl_BltBatch
,
2627 IDirectDrawSurfaceImpl_BltFast
,
2628 IDirectDrawSurfaceImpl_DeleteAttachedSurface
,
2629 IDirectDrawSurfaceImpl_EnumAttachedSurfaces
,
2630 IDirectDrawSurfaceImpl_EnumOverlayZOrders
,
2631 IDirectDrawSurfaceImpl_Flip
,
2632 IDirectDrawSurfaceImpl_GetAttachedSurface
,
2633 IDirectDrawSurfaceImpl_GetBltStatus
,
2634 IDirectDrawSurfaceImpl_GetCaps
,
2635 IDirectDrawSurfaceImpl_GetClipper
,
2636 IDirectDrawSurfaceImpl_GetColorKey
,
2637 IDirectDrawSurfaceImpl_GetDC
,
2638 IDirectDrawSurfaceImpl_GetFlipStatus
,
2639 IDirectDrawSurfaceImpl_GetOverlayPosition
,
2640 IDirectDrawSurfaceImpl_GetPalette
,
2641 IDirectDrawSurfaceImpl_GetPixelFormat
,
2642 IDirectDrawSurfaceImpl_GetSurfaceDesc
,
2643 IDirectDrawSurfaceImpl_Initialize
,
2644 IDirectDrawSurfaceImpl_IsLost
,
2645 IDirectDrawSurfaceImpl_Lock
,
2646 IDirectDrawSurfaceImpl_ReleaseDC
,
2647 IDirectDrawSurfaceImpl_Restore
,
2648 IDirectDrawSurfaceImpl_SetClipper
,
2649 IDirectDrawSurfaceImpl_SetColorKey
,
2650 IDirectDrawSurfaceImpl_SetOverlayPosition
,
2651 IDirectDrawSurfaceImpl_SetPalette
,
2652 IDirectDrawSurfaceImpl_Unlock
,
2653 IDirectDrawSurfaceImpl_UpdateOverlay
,
2654 IDirectDrawSurfaceImpl_UpdateOverlayDisplay
,
2655 IDirectDrawSurfaceImpl_UpdateOverlayZOrder
,
2656 /*** IDirectDrawSurface2 ***/
2657 IDirectDrawSurfaceImpl_GetDDInterface
,
2658 IDirectDrawSurfaceImpl_PageLock
,
2659 IDirectDrawSurfaceImpl_PageUnlock
,
2660 /*** IDirectDrawSurface3 ***/
2661 IDirectDrawSurfaceImpl_SetSurfaceDesc
,
2662 /*** IDirectDrawSurface4 ***/
2663 IDirectDrawSurfaceImpl_SetPrivateData
,
2664 IDirectDrawSurfaceImpl_GetPrivateData
,
2665 IDirectDrawSurfaceImpl_FreePrivateData
,
2666 IDirectDrawSurfaceImpl_GetUniquenessValue
,
2667 IDirectDrawSurfaceImpl_ChangeUniquenessValue
,
2668 /*** IDirectDrawSurface7 ***/
2669 IDirectDrawSurfaceImpl_SetPriority
,
2670 IDirectDrawSurfaceImpl_GetPriority
,
2671 IDirectDrawSurfaceImpl_SetLOD
,
2672 IDirectDrawSurfaceImpl_GetLOD