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 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)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
);
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
= &This
->IDirectDrawSurface3_vtbl
;
102 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
105 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
107 IUnknown_AddRef(iface
);
108 *obj
= &This
->IDirectDrawGammaControl_vtbl
;
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((IDirect3D7
*)&This
->ddraw
->IDirect3D7_vtbl
, riid
, (IDirectDrawSurface7
*)This
, &d3d
);
121 *obj
= d3d
? (IDirect3DDevice
*)&((IDirect3DDeviceImpl
*)d3d
)->IDirect3DDevice_vtbl
: NULL
;
122 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
126 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
127 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
129 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
131 *obj
= &This
->IDirect3DTexture_vtbl
;
132 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
136 *obj
= &This
->IDirect3DTexture2_vtbl
;
137 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
139 IUnknown_AddRef( (IUnknown
*) *obj
);
143 ERR("No interface\n");
144 return E_NOINTERFACE
;
147 /*****************************************************************************
148 * IDirectDrawSurface7::AddRef
150 * A normal addref implementation
155 *****************************************************************************/
157 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7
*iface
)
159 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
160 ULONG refCount
= InterlockedIncrement(&This
->ref
);
162 TRACE("(%p) : AddRef increasing from %d\n", This
, refCount
- 1);
166 /*****************************************************************************
167 * IDirectDrawSurfaceImpl_Destroy
169 * A helper function for IDirectDrawSurface7::Release
171 * Frees the surface, regardless of its refcount.
172 * See IDirectDrawSurface7::Release for more information
175 * This: Surface to free
177 *****************************************************************************/
178 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl
*This
)
180 TRACE("(%p)\n", This
);
182 /* Check the refcount and give a warning */
185 /* This can happen when a complex surface is destroyed,
186 * because the 2nd surface was addref()ed when the app
187 * called GetAttachedSurface
189 WARN("(%p): Destroying surface with refount %d\n", This
, This
->ref
);
192 /* Check for attached surfaces and detach them */
193 if(This
->first_attached
!= This
)
195 /* Well, this shouldn't happen: The surface being attached is addref()ed
196 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
197 * is called, because the refcount is held. It looks like the app released()
198 * it often enough to force this
200 IDirectDrawSurface7
*root
= (IDirectDrawSurface7
*)This
->first_attached
;
201 IDirectDrawSurface7
*detach
= (IDirectDrawSurface7
*)This
;
203 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This
, This
->first_attached
);
205 /* The refcount will drop to -1 here */
206 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
208 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
212 while(This
->next_attached
!= NULL
)
214 IDirectDrawSurface7
*root
= (IDirectDrawSurface7
*)This
;
215 IDirectDrawSurface7
*detach
= (IDirectDrawSurface7
*)This
->next_attached
;
217 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
219 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
224 /* Now destroy the surface. Wait: It could have been released if we are a texture */
225 if(This
->WineD3DSurface
)
226 IWineD3DSurface_Release(This
->WineD3DSurface
);
228 /* Having a texture handle set implies that the device still exists */
231 This
->ddraw
->d3ddevice
->Handles
[This
->Handle
- 1].ptr
= NULL
;
232 This
->ddraw
->d3ddevice
->Handles
[This
->Handle
- 1].type
= DDrawHandle_Unknown
;
235 /* Reduce the ddraw surface count */
236 InterlockedDecrement(&This
->ddraw
->surfaces
);
237 list_remove(&This
->surface_list_entry
);
239 HeapFree(GetProcessHeap(), 0, This
);
242 /*****************************************************************************
243 * IDirectDrawSurface7::Release
245 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
246 * surface is destroyed.
248 * Destroying the surface is a bit tricky. For the connection between
249 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
250 * It has a nice graph explaining the connection.
252 * What happens here is basically this:
253 * When a surface is destroyed, its WineD3DSurface is released,
254 * and the refcount of the DirectDraw interface is reduced by 1. If it has
255 * complex surfaces attached to it, then these surfaces are destroyed too,
256 * regardless of their refcount. If any surface being destroyed has another
257 * surface attached to it (with a "soft" attachment, not complex), then
258 * this surface is detached with DeleteAttachedSurface.
260 * When the surface is a texture, the WineD3DTexture is released.
261 * If the surface is the Direct3D render target, then the D3D
262 * capabilities of the WineD3DDevice are uninitialized, which causes the
263 * swapchain to be released.
265 * When a complex sublevel falls to ref zero, then this is ignored.
270 *****************************************************************************/
272 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7
*iface
)
274 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
276 TRACE("(%p) : Releasing from %d\n", This
, This
->ref
);
277 ref
= InterlockedDecrement(&This
->ref
);
282 IDirectDrawSurfaceImpl
*surf
;
283 IDirectDrawImpl
*ddraw
;
284 IUnknown
*ifaceToRelease
= This
->ifaceToRelease
;
287 /* Complex attached surfaces are destroyed implicitly when the root is released */
288 EnterCriticalSection(&ddraw_cs
);
289 if(!This
->is_complex_root
)
291 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
292 LeaveCriticalSection(&ddraw_cs
);
297 /* If it's a texture, destroy the WineD3DTexture.
298 * WineD3D will destroy the IParent interfaces
299 * of the sublevels, which destroys the WineD3DSurfaces.
300 * Set the surfaces to NULL to avoid destroying them again later
302 if(This
->wineD3DTexture
)
304 IWineD3DBaseTexture_Release(This
->wineD3DTexture
);
306 /* If it's the RenderTarget, destroy the d3ddevice */
307 else if(This
->wineD3DSwapChain
)
309 if((ddraw
->d3d_initialized
) && (This
== ddraw
->d3d_target
)) {
310 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This
);
312 /* Unset any index buffer, just to be sure */
313 IWineD3DDevice_SetIndices(ddraw
->wineD3DDevice
, NULL
);
314 IWineD3DDevice_SetDepthStencilSurface(ddraw
->wineD3DDevice
, NULL
);
315 IWineD3DDevice_SetVertexDeclaration(ddraw
->wineD3DDevice
, NULL
);
316 for(i
= 0; i
< ddraw
->numConvertedDecls
; i
++)
318 IWineD3DVertexDeclaration_Release(ddraw
->decls
[i
].decl
);
320 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
321 ddraw
->numConvertedDecls
= 0;
323 if(IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroyDepthStencilSurface
, D3D7CB_DestroySwapChain
) != D3D_OK
)
326 ERR("(%p) Failed to uninit 3D\n", This
);
330 /* Free the d3d window if one was created */
331 if(ddraw
->d3d_window
!= 0 && ddraw
->d3d_window
!= ddraw
->dest_window
)
333 TRACE(" (%p) Destroying the hidden render window %p\n", This
, ddraw
->d3d_window
);
334 DestroyWindow(ddraw
->d3d_window
);
335 ddraw
->d3d_window
= 0;
337 /* Unset the pointers */
340 This
->wineD3DSwapChain
= NULL
; /* Uninit3D releases the swapchain */
341 ddraw
->d3d_initialized
= FALSE
;
342 ddraw
->d3d_target
= NULL
;
344 IWineD3DDevice_UninitGDI(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
345 This
->wineD3DSwapChain
= NULL
;
348 /* Reset to the default surface implementation type. This is needed if apps use
349 * non render target surfaces and expect blits to work after destroying the render
352 * TODO: Recreate existing offscreen surfaces
354 ddraw
->ImplType
= DefaultSurfaceType
;
356 /* Write a trace because D3D unloading was the reason for many
357 * crashes during development.
359 TRACE("(%p) D3D unloaded\n", This
);
361 else if(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
365 /* It's a render target, but no swapchain was created.
366 * The IParent interfaces have to be released manually.
367 * The same applies for textures without an
368 * IWineD3DTexture object attached
372 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
374 if(This
->complex_array
[i
])
376 /* Only the topmost level can have more than 1 surfaces in the complex
377 * attachment array(Cube texture roots), for all others there is only
380 surf
= This
->complex_array
[i
];
383 IWineD3DSurface_GetParent(surf
->WineD3DSurface
,
384 (IUnknown
**) &Parent
);
385 IParent_Release(Parent
); /* For the getParent */
386 IParent_Release(Parent
); /* To release it */
387 surf
= surf
->complex_array
[0];
392 /* Now the top-level surface */
393 IWineD3DSurface_GetParent(This
->WineD3DSurface
,
394 (IUnknown
**) &Parent
);
395 IParent_Release(Parent
); /* For the getParent */
396 IParent_Release(Parent
); /* To release it */
399 /* The refcount test shows that the palette is detached when the surface is destroyed */
400 IDirectDrawSurface7_SetPalette((IDirectDrawSurface7
*)This
, NULL
);
402 /* Loop through all complex attached surfaces,
405 * Yet again, only the root can have more than one complexly attached surface, all the others
406 * have a total of one;
408 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
410 if(!This
->complex_array
[i
]) break;
412 surf
= This
->complex_array
[i
];
413 This
->complex_array
[i
] = NULL
;
416 IDirectDrawSurfaceImpl
*destroy
= surf
;
417 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
418 IDirectDrawSurfaceImpl_Destroy(destroy
); /* Destroy it */
422 /* Destroy the root surface.
424 IDirectDrawSurfaceImpl_Destroy(This
);
426 /* Reduce the ddraw refcount */
427 if(ifaceToRelease
) IUnknown_Release(ifaceToRelease
);
428 LeaveCriticalSection(&ddraw_cs
);
434 /*****************************************************************************
435 * IDirectDrawSurface7::GetAttachedSurface
437 * Returns an attached surface with the requested caps. Surface attachment
438 * and complex surfaces are not clearly described by the MSDN or sdk,
439 * so this method is tricky and likely to contain problems.
440 * This implementation searches the complex list first, then the
443 * The chains are searched from This down to the last surface in the chain,
444 * not from the first element in the chain. The first surface found is
445 * returned. The MSDN says that this method fails if more than one surface
446 * matches the caps, but it is not sure if that is right. The attachment
447 * structure may not even allow two matching surfaces.
449 * The found surface is AddRef-ed before it is returned.
452 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
453 * Surface: Address to store the found surface
457 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
458 * DDERR_NOTFOUND if no surface was found
460 *****************************************************************************/
461 static HRESULT WINAPI
462 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7
*iface
,
464 IDirectDrawSurface7
**Surface
)
466 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
467 IDirectDrawSurfaceImpl
*surf
;
471 TRACE("(%p)->(%p,%p)\n", This
, Caps
, Surface
);
472 EnterCriticalSection(&ddraw_cs
);
474 if(This
->version
< 7)
476 /* Earlier dx apps put garbage into these members, clear them */
477 our_caps
.dwCaps
= Caps
->dwCaps
;
478 our_caps
.dwCaps2
= 0;
479 our_caps
.dwCaps3
= 0;
480 our_caps
.dwCaps4
= 0;
487 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 */
489 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
491 surf
= This
->complex_array
[i
];
496 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
497 surf
->surface_desc
.ddsCaps
.dwCaps
,
498 surf
->surface_desc
.ddsCaps
.dwCaps2
,
499 surf
->surface_desc
.ddsCaps
.dwCaps3
,
500 surf
->surface_desc
.ddsCaps
.dwCaps4
);
503 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
504 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
506 /* MSDN: "This method fails if more than one surface is attached
507 * that matches the capabilities requested."
509 * Not sure how to test this.
512 TRACE("(%p): Returning surface %p\n", This
, surf
);
513 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
514 *Surface
= (IDirectDrawSurface7
*)surf
;
515 IDirectDrawSurface7_AddRef(*Surface
);
516 LeaveCriticalSection(&ddraw_cs
);
521 /* Next, look at the attachment chain */
524 while( (surf
= surf
->next_attached
) )
528 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
529 surf
->surface_desc
.ddsCaps
.dwCaps
,
530 surf
->surface_desc
.ddsCaps
.dwCaps2
,
531 surf
->surface_desc
.ddsCaps
.dwCaps3
,
532 surf
->surface_desc
.ddsCaps
.dwCaps4
);
535 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
536 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
538 TRACE("(%p): Returning surface %p\n", This
, surf
);
539 *Surface
= (IDirectDrawSurface7
*)surf
;
540 IDirectDrawSurface7_AddRef(*Surface
);
541 LeaveCriticalSection(&ddraw_cs
);
546 TRACE("(%p) Didn't find a valid surface\n", This
);
547 LeaveCriticalSection(&ddraw_cs
);
550 return DDERR_NOTFOUND
;
553 /*****************************************************************************
554 * IDirectDrawSurface7::Lock
556 * Locks the surface and returns a pointer to the surface's memory
559 * Rect: Rectangle to lock. If NULL, the whole surface is locked
560 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
561 * Flags: Locking flags, e.g Read only or write only
562 * h: An event handle that's not used and must be NULL
566 * DDERR_INVALIDPARAMS if DDSD is NULL
567 * For more details, see IWineD3DSurface::LockRect
569 *****************************************************************************/
570 static HRESULT WINAPI
571 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7
*iface
,
573 DDSURFACEDESC2
*DDSD
,
577 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
578 WINED3DLOCKED_RECT LockedRect
;
580 TRACE("(%p)->(%p,%p,%x,%p)\n", This
, Rect
, DDSD
, Flags
, h
);
583 return DDERR_INVALIDPARAMS
;
585 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
586 EnterCriticalSection(&ddraw_cs
);
588 /* Should I check for the handle to be NULL?
590 * The DDLOCK flags and the D3DLOCK flags are equal
591 * for the supported values. The others are ignored by WineD3D
594 if(DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) &&
595 DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
597 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS
);
598 LeaveCriticalSection(&ddraw_cs
);
599 return DDERR_INVALIDPARAMS
;
602 /* Windows zeroes this if the rect is invalid */
609 || (Rect
->left
> Rect
->right
)
610 || (Rect
->top
> Rect
->bottom
)
611 || (Rect
->right
> This
->surface_desc
.dwWidth
)
612 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
614 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
615 LeaveCriticalSection(&ddraw_cs
);
616 return DDERR_INVALIDPARAMS
;
620 hr
= IWineD3DSurface_LockRect(This
->WineD3DSurface
,
626 LeaveCriticalSection(&ddraw_cs
);
629 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
630 * specific error. But since IWineD3DSurface::LockRect returns that error in this
631 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
632 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
633 * is much easier to do it in one place in ddraw
635 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
640 /* Override the memory area. The pitch should be set already. Strangely windows
641 * does not set the LPSURFACE flag on locked surfaces !?!.
642 * DDSD->dwFlags |= DDSD_LPSURFACE;
644 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
645 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
647 TRACE("locked surface returning description :\n");
648 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
650 LeaveCriticalSection(&ddraw_cs
);
654 /*****************************************************************************
655 * IDirectDrawSurface7::Unlock
657 * Unlocks an locked surface
660 * Rect: Not used by this implementation
664 * For more details, see IWineD3DSurface::UnlockRect
666 *****************************************************************************/
667 static HRESULT WINAPI
668 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7
*iface
,
671 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
673 TRACE("(%p)->(%p)\n", This
, pRect
);
675 EnterCriticalSection(&ddraw_cs
);
676 hr
= IWineD3DSurface_UnlockRect(This
->WineD3DSurface
);
679 This
->surface_desc
.lpSurface
= NULL
;
681 LeaveCriticalSection(&ddraw_cs
);
685 /*****************************************************************************
686 * IDirectDrawSurface7::Flip
688 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
689 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
690 * the flip target is passed to WineD3D, even if the app didn't specify one
693 * DestOverride: Specifies the surface that will become the new front
694 * buffer. If NULL, the current back buffer is used
695 * Flags: some DirectDraw flags, see include/ddraw.h
699 * DDERR_NOTFLIPPABLE if no flip target could be found
700 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
701 * For more details, see IWineD3DSurface::Flip
703 *****************************************************************************/
704 static HRESULT WINAPI
705 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7
*iface
,
706 IDirectDrawSurface7
*DestOverride
,
709 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
710 IDirectDrawSurfaceImpl
*Override
= (IDirectDrawSurfaceImpl
*)DestOverride
;
711 IDirectDrawSurface7
*Override7
;
713 TRACE("(%p)->(%p,%x)\n", This
, DestOverride
, Flags
);
715 /* Flip has to be called from a front buffer
716 * What about overlay surfaces, AFAIK they can flip too?
718 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
719 return DDERR_INVALIDOBJECT
; /* Unchecked */
721 EnterCriticalSection(&ddraw_cs
);
723 /* WineD3D doesn't keep track of attached surface, so find the target */
728 memset(&Caps
, 0, sizeof(Caps
));
729 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
730 hr
= IDirectDrawSurface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
733 ERR("Can't find a flip target\n");
734 LeaveCriticalSection(&ddraw_cs
);
735 return DDERR_NOTFLIPPABLE
; /* Unchecked */
737 Override
= (IDirectDrawSurfaceImpl
*)Override7
;
739 /* For the GetAttachedSurface */
740 IDirectDrawSurface7_Release(Override7
);
743 hr
= IWineD3DSurface_Flip(This
->WineD3DSurface
,
744 Override
->WineD3DSurface
,
746 LeaveCriticalSection(&ddraw_cs
);
750 /*****************************************************************************
751 * IDirectDrawSurface7::Blt
753 * Performs a blit on the surface
756 * DestRect: Destination rectangle, can be NULL
757 * SrcSurface: Source surface, can be NULL
758 * SrcRect: Source rectangle, can be NULL
760 * DDBltFx: Some extended blt parameters, connected to the flags
764 * See IWineD3DSurface::Blt for more details
766 *****************************************************************************/
767 static HRESULT WINAPI
768 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7
*iface
,
770 IDirectDrawSurface7
*SrcSurface
,
775 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
776 IDirectDrawSurfaceImpl
*Src
= (IDirectDrawSurfaceImpl
*)SrcSurface
;
778 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This
, DestRect
, Src
, SrcRect
, Flags
, DDBltFx
);
780 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
781 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
783 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
784 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
785 return DDERR_INVALIDPARAMS
;
788 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
789 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
790 return DDERR_INVALIDPARAMS
;
793 /* Sizes can change, therefore hold the lock when testing the rectangles */
794 EnterCriticalSection(&ddraw_cs
);
797 if(DestRect
->top
>= DestRect
->bottom
|| DestRect
->left
>= DestRect
->right
||
798 DestRect
->right
> This
->surface_desc
.dwWidth
||
799 DestRect
->bottom
> This
->surface_desc
.dwHeight
)
801 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
802 LeaveCriticalSection(&ddraw_cs
);
803 return DDERR_INVALIDRECT
;
808 if(SrcRect
->top
>= SrcRect
->bottom
|| SrcRect
->left
>=SrcRect
->right
||
809 SrcRect
->right
> Src
->surface_desc
.dwWidth
||
810 SrcRect
->bottom
> Src
->surface_desc
.dwHeight
)
812 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
813 LeaveCriticalSection(&ddraw_cs
);
814 return DDERR_INVALIDRECT
;
818 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
819 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
820 LeaveCriticalSection(&ddraw_cs
);
821 return DDERR_INVALIDPARAMS
;
824 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
825 * and replace the ddraw surfaces with the wined3d surfaces
826 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
828 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
,
830 Src
? Src
->WineD3DSurface
: NULL
,
833 (WINEDDBLTFX
*) DDBltFx
,
836 LeaveCriticalSection(&ddraw_cs
);
839 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
840 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
845 /*****************************************************************************
846 * IDirectDrawSurface7::AddAttachedSurface
848 * Attaches a surface to another surface. How the surface attachments work
849 * is not totally understood yet, and this method is prone to problems.
850 * he surface that is attached is AddRef-ed.
852 * Tests with complex surfaces suggest that the surface attachments form a
853 * tree, but no method to test this has been found yet.
855 * The attachment list consists of a first surface (first_attached) and
856 * for each surface a pointer to the next attached surface (next_attached).
857 * For the first surface, and a surface that has no attachments
858 * first_attached points to the surface itself. A surface that has
859 * no successors in the chain has next_attached set to NULL.
861 * Newly attached surfaces are attached right after the root surface.
862 * If a surface is attached to a complex surface compound, it's attached to
863 * the surface that the app requested, not the complex root. See
864 * GetAttachedSurface for a description how surfaces are found.
866 * This is how the current implementation works, and it was coded by looking
867 * at the needs of the applications.
869 * So far only Z-Buffer attachments are tested, and they are activated in
870 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
871 * Back buffers should work in 2D mode, but they are not tested(They can be
872 * attached in older iface versions). Rendering to the front buffer and
873 * switching between that and double buffering is not yet implemented in
874 * WineD3D, so for 3D it might have unexpected results.
876 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
877 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
878 * performs additional checks. Version 7 of this interface is much more restrictive
879 * than its predecessors.
882 * Attach: Surface to attach to iface
886 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
888 *****************************************************************************/
890 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl
*This
,
891 IDirectDrawSurfaceImpl
*Surf
)
893 TRACE("(%p)->(%p)\n", This
, Surf
);
896 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
898 EnterCriticalSection(&ddraw_cs
);
900 /* Check if the surface is already attached somewhere */
901 if( (Surf
->next_attached
!= NULL
) ||
902 (Surf
->first_attached
!= Surf
) )
904 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
905 * What happens if one surface is attached to 2 different surfaces?
907 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
);
908 LeaveCriticalSection(&ddraw_cs
);
909 return DDERR_SURFACEALREADYATTACHED
;
912 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
913 Surf
->next_attached
= This
->next_attached
;
914 Surf
->first_attached
= This
->first_attached
;
915 This
->next_attached
= Surf
;
917 /* Check if the WineD3D depth stencil needs updating */
918 if(This
->ddraw
->d3ddevice
)
920 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
924 * "This method increments the reference count of the surface being attached."
926 IDirectDrawSurface7_AddRef((IDirectDrawSurface7
*)Surf
);
927 LeaveCriticalSection(&ddraw_cs
);
931 static HRESULT WINAPI
932 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7
*iface
,
933 IDirectDrawSurface7
*Attach
)
935 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
936 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Attach
;
938 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
939 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
942 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
943 Surf
->surface_desc
.ddsCaps
.dwCaps
);
944 return DDERR_CANNOTATTACHSURFACE
;
947 return IDirectDrawSurfaceImpl_AddAttachedSurface(This
,
950 /*****************************************************************************
951 * IDirectDrawSurface7::DeleteAttachedSurface
953 * Removes a surface from the attachment chain. The surface's refcount
954 * is decreased by one after it has been removed
957 * Flags: Some flags, not used by this implementation
958 * Attach: Surface to detach
962 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
964 *****************************************************************************/
965 static HRESULT WINAPI
966 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
968 IDirectDrawSurface7
*Attach
)
970 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
971 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Attach
;
972 IDirectDrawSurfaceImpl
*Prev
= This
;
973 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, Surf
);
975 EnterCriticalSection(&ddraw_cs
);
976 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
978 LeaveCriticalSection(&ddraw_cs
);
979 return DDERR_CANNOTDETACHSURFACE
;
982 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
983 if (This
->surface_desc
.ddsCaps
.dwCaps
&
984 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
986 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
987 /* FIXME: we should probably also subtract from dwMipMapCount of this
988 * and all parent surfaces */
991 /* Find the predecessor of the detached surface */
994 if(Prev
->next_attached
== Surf
) break;
995 Prev
= Prev
->next_attached
;
998 /* There must be a surface, otherwise there's a bug */
999 assert(Prev
!= NULL
);
1001 /* Unchain the surface */
1002 Prev
->next_attached
= Surf
->next_attached
;
1003 Surf
->next_attached
= NULL
;
1004 Surf
->first_attached
= Surf
;
1006 /* Check if the WineD3D depth stencil needs updating */
1007 if(This
->ddraw
->d3ddevice
)
1009 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1012 IDirectDrawSurface7_Release(Attach
);
1013 LeaveCriticalSection(&ddraw_cs
);
1017 /*****************************************************************************
1018 * IDirectDrawSurface7::AddOverlayDirtyRect
1020 * "This method is not currently implemented"
1028 *****************************************************************************/
1029 static HRESULT WINAPI
1030 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
,
1033 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1034 TRACE("(%p)->(%p)\n",This
,Rect
);
1036 /* MSDN says it's not implemented. I could forward it to WineD3D,
1037 * then we'd implement it, but I don't think that's a good idea
1038 * (Stefan Dösinger)
1041 return IWineD3DSurface_AddOverlayDirtyRect(This
->WineD3DSurface
, pRect
);
1043 return DDERR_UNSUPPORTED
; /* unchecked */
1046 /*****************************************************************************
1047 * IDirectDrawSurface7::GetDC
1049 * Returns a GDI device context for the surface
1052 * hdc: Address of a HDC variable to store the dc to
1056 * DDERR_INVALIDPARAMS if hdc is NULL
1057 * For details, see IWineD3DSurface::GetDC
1059 *****************************************************************************/
1060 static HRESULT WINAPI
1061 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7
*iface
,
1064 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1066 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1069 return DDERR_INVALIDPARAMS
;
1071 EnterCriticalSection(&ddraw_cs
);
1072 hr
= IWineD3DSurface_GetDC(This
->WineD3DSurface
,
1074 LeaveCriticalSection(&ddraw_cs
);
1078 /*****************************************************************************
1079 * IDirectDrawSurface7::ReleaseDC
1081 * Releases the DC that was constructed with GetDC
1084 * hdc: HDC to release
1088 * For more details, see IWineD3DSurface::ReleaseDC
1090 *****************************************************************************/
1091 static HRESULT WINAPI
1092 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7
*iface
,
1095 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1097 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1099 EnterCriticalSection(&ddraw_cs
);
1100 hr
= IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
1101 LeaveCriticalSection(&ddraw_cs
);
1105 /*****************************************************************************
1106 * IDirectDrawSurface7::GetCaps
1108 * Returns the surface's caps
1111 * Caps: Address to write the caps to
1115 * DDERR_INVALIDPARAMS if Caps is NULL
1117 *****************************************************************************/
1118 static HRESULT WINAPI
1119 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7
*iface
,
1122 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1123 TRACE("(%p)->(%p)\n",This
,Caps
);
1126 return DDERR_INVALIDPARAMS
;
1128 *Caps
= This
->surface_desc
.ddsCaps
;
1132 /*****************************************************************************
1133 * IDirectDrawSurface7::SetPriority
1135 * Sets a texture priority for managed textures.
1138 * Priority: The new priority
1142 * For more details, see IWineD3DSurface::SetPriority
1144 *****************************************************************************/
1145 static HRESULT WINAPI
1146 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1148 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1150 TRACE("(%p)->(%d): Relay!\n",This
,Priority
);
1152 EnterCriticalSection(&ddraw_cs
);
1153 hr
= IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1154 LeaveCriticalSection(&ddraw_cs
);
1158 /*****************************************************************************
1159 * IDirectDrawSurface7::GetPriority
1161 * Returns the surface's priority
1164 * Priority: Address of a variable to write the priority to
1168 * DDERR_INVALIDPARAMS if Priority == NULL
1169 * For more details, see IWineD3DSurface::GetPriority
1171 *****************************************************************************/
1172 static HRESULT WINAPI
1173 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7
*iface
,
1176 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1177 TRACE("(%p)->(%p): Relay\n",This
,Priority
);
1181 return DDERR_INVALIDPARAMS
;
1184 EnterCriticalSection(&ddraw_cs
);
1185 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1186 LeaveCriticalSection(&ddraw_cs
);
1190 /*****************************************************************************
1191 * IDirectDrawSurface7::SetPrivateData
1193 * Stores some data in the surface that is intended for the application's
1197 * tag: GUID that identifies the data
1198 * Data: Pointer to the private data
1199 * Size: Size of the private data
1204 * For more details, see IWineD3DSurface::SetPrivateData
1206 *****************************************************************************/
1207 static HRESULT WINAPI
1208 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7
*iface
,
1214 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1216 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This
, debugstr_guid(tag
), Data
, Size
, Flags
);
1218 EnterCriticalSection(&ddraw_cs
);
1219 hr
= IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1224 LeaveCriticalSection(&ddraw_cs
);
1227 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1232 /*****************************************************************************
1233 * IDirectDrawSurface7::GetPrivateData
1235 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1238 * tag: GUID of the data to return
1239 * Data: Address where to write the data to
1240 * Size: Size of the buffer at Data
1244 * DDERR_INVALIDPARAMS if Data is NULL
1245 * For more details, see IWineD3DSurface::GetPrivateData
1247 *****************************************************************************/
1248 static HRESULT WINAPI
1249 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7
*iface
,
1254 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1256 TRACE("(%p)->(%s,%p,%p): Relay\n", This
, debugstr_guid(tag
), Data
, Size
);
1259 return DDERR_INVALIDPARAMS
;
1261 EnterCriticalSection(&ddraw_cs
);
1262 hr
= IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1266 LeaveCriticalSection(&ddraw_cs
);
1270 /*****************************************************************************
1271 * IDirectDrawSurface7::FreePrivateData
1273 * Frees private data stored in the surface
1276 * tag: Tag of the data to free
1280 * For more details, see IWineD3DSurface::FreePrivateData
1282 *****************************************************************************/
1283 static HRESULT WINAPI
1284 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7
*iface
,
1287 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1289 TRACE("(%p)->(%s): Relay\n", This
, debugstr_guid(tag
));
1291 EnterCriticalSection(&ddraw_cs
);
1292 hr
= IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1293 LeaveCriticalSection(&ddraw_cs
);
1297 /*****************************************************************************
1298 * IDirectDrawSurface7::PageLock
1300 * Prevents a sysmem surface from being paged out
1303 * Flags: Not used, must be 0(unchecked)
1306 * DD_OK, because it's a stub
1308 *****************************************************************************/
1309 static HRESULT WINAPI
1310 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7
*iface
,
1313 TRACE("(%p)->(%x)\n", iface
, Flags
);
1315 /* This is Windows memory management related - we don't need this */
1319 /*****************************************************************************
1320 * IDirectDrawSurface7::PageUnlock
1322 * Allows a sysmem surface to be paged out
1325 * Flags: Not used, must be 0(unchecked)
1328 * DD_OK, because it's a stub
1330 *****************************************************************************/
1331 static HRESULT WINAPI
1332 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7
*iface
,
1335 TRACE("(%p)->(%x)\n", iface
, Flags
);
1340 /*****************************************************************************
1341 * IDirectDrawSurface7::BltBatch
1343 * An unimplemented function
1351 *****************************************************************************/
1352 static HRESULT WINAPI
IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1354 TRACE("(%p)->(%p,%d,%08x)\n",iface
,Batch
,Count
,Flags
);
1356 /* MSDN: "not currently implemented" */
1357 return DDERR_UNSUPPORTED
;
1360 /*****************************************************************************
1361 * IDirectDrawSurface7::EnumAttachedSurfaces
1363 * Enumerates all surfaces attached to this surface
1366 * context: Pointer to pass unmodified to the callback
1367 * cb: Callback function to call for each surface
1371 * DDERR_INVALIDPARAMS if cb is NULL
1373 *****************************************************************************/
1374 static HRESULT WINAPI
1375 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1377 LPDDENUMSURFACESCALLBACK7 cb
)
1379 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1380 IDirectDrawSurfaceImpl
*surf
;
1381 DDSURFACEDESC2 desc
;
1384 /* Attached surfaces aren't handled in WineD3D */
1385 TRACE("(%p)->(%p,%p)\n",This
,context
,cb
);
1388 return DDERR_INVALIDPARAMS
;
1390 EnterCriticalSection(&ddraw_cs
);
1391 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1393 surf
= This
->complex_array
[i
];
1396 IDirectDrawSurface7_AddRef((IDirectDrawSurface7
*)surf
);
1397 desc
= surf
->surface_desc
;
1398 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1399 if (cb((IDirectDrawSurface7
*)surf
, &desc
, context
) == DDENUMRET_CANCEL
)
1401 LeaveCriticalSection(&ddraw_cs
);
1406 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1408 IDirectDrawSurface7_AddRef((IDirectDrawSurface7
*)surf
);
1409 desc
= surf
->surface_desc
;
1410 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1411 if (cb((IDirectDrawSurface7
*)surf
, &desc
, context
) == DDENUMRET_CANCEL
)
1413 LeaveCriticalSection(&ddraw_cs
);
1418 TRACE(" end of enumeration.\n");
1420 LeaveCriticalSection(&ddraw_cs
);
1424 /*****************************************************************************
1425 * IDirectDrawSurface7::EnumOverlayZOrders
1427 * "Enumerates the overlay surfaces on the specified destination"
1430 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1431 * context: context to pass back to the callback
1432 * cb: callback function to call for each enumerated surface
1435 * DD_OK, because it's a stub
1437 *****************************************************************************/
1438 static HRESULT WINAPI
1439 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1442 LPDDENUMSURFACESCALLBACK7 cb
)
1444 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface
, Flags
, context
, cb
);
1449 /*****************************************************************************
1450 * IDirectDrawSurface7::GetBltStatus
1452 * Returns the blitting status
1455 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1458 * See IWineD3DSurface::Blt
1460 *****************************************************************************/
1461 static HRESULT WINAPI
1462 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7
*iface
,
1465 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1467 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1469 EnterCriticalSection(&ddraw_cs
);
1470 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1471 LeaveCriticalSection(&ddraw_cs
);
1474 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1479 /*****************************************************************************
1480 * IDirectDrawSurface7::GetColorKey
1482 * Returns the color key assigned to the surface
1486 * CKey: Address to store the key to
1490 * DDERR_INVALIDPARAMS if CKey is NULL
1492 *****************************************************************************/
1493 static HRESULT WINAPI
1494 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7
*iface
,
1498 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1499 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, CKey
);
1502 return DDERR_INVALIDPARAMS
;
1504 EnterCriticalSection(&ddraw_cs
);
1508 case DDCKEY_DESTBLT
:
1509 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1511 LeaveCriticalSection(&ddraw_cs
);
1512 return DDERR_NOCOLORKEY
;
1514 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1517 case DDCKEY_DESTOVERLAY
:
1518 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
1520 LeaveCriticalSection(&ddraw_cs
);
1521 return DDERR_NOCOLORKEY
;
1523 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1527 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
1529 LeaveCriticalSection(&ddraw_cs
);
1530 return DDERR_NOCOLORKEY
;
1532 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1535 case DDCKEY_SRCOVERLAY
:
1536 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
1538 LeaveCriticalSection(&ddraw_cs
);
1539 return DDERR_NOCOLORKEY
;
1541 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1545 LeaveCriticalSection(&ddraw_cs
);
1546 return DDERR_INVALIDPARAMS
;
1549 LeaveCriticalSection(&ddraw_cs
);
1553 /*****************************************************************************
1554 * IDirectDrawSurface7::GetFlipStatus
1556 * Returns the flipping status of the surface
1559 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1562 * See IWineD3DSurface::GetFlipStatus
1564 *****************************************************************************/
1565 static HRESULT WINAPI
1566 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7
*iface
,
1569 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1571 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1573 EnterCriticalSection(&ddraw_cs
);
1574 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1575 LeaveCriticalSection(&ddraw_cs
);
1578 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1583 /*****************************************************************************
1584 * IDirectDrawSurface7::GetOverlayPosition
1586 * Returns the display coordinates of a visible and active overlay surface
1593 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1594 *****************************************************************************/
1595 static HRESULT WINAPI
1596 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7
*iface
,
1599 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1601 TRACE("(%p)->(%p,%p): Relay\n", This
, X
, Y
);
1603 EnterCriticalSection(&ddraw_cs
);
1604 hr
= IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1607 LeaveCriticalSection(&ddraw_cs
);
1611 /*****************************************************************************
1612 * IDirectDrawSurface7::GetPixelFormat
1614 * Returns the pixel format of the Surface
1617 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1618 * format should be written
1622 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1624 *****************************************************************************/
1625 static HRESULT WINAPI
1626 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7
*iface
,
1627 DDPIXELFORMAT
*PixelFormat
)
1629 /* What is DDERR_INVALIDSURFACETYPE for here? */
1630 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1631 TRACE("(%p)->(%p)\n",This
,PixelFormat
);
1634 return DDERR_INVALIDPARAMS
;
1636 EnterCriticalSection(&ddraw_cs
);
1637 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1638 LeaveCriticalSection(&ddraw_cs
);
1644 /*****************************************************************************
1645 * IDirectDrawSurface7::GetSurfaceDesc
1647 * Returns the description of this surface
1650 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1655 * DDERR_INVALIDPARAMS if DDSD is NULL
1657 *****************************************************************************/
1658 static HRESULT WINAPI
1659 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7
*iface
,
1660 DDSURFACEDESC2
*DDSD
)
1662 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1664 TRACE("(%p)->(%p)\n",This
,DDSD
);
1667 return DDERR_INVALIDPARAMS
;
1669 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
1671 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
1672 return DDERR_INVALIDPARAMS
;
1675 EnterCriticalSection(&ddraw_cs
);
1676 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1677 TRACE("Returning surface desc:\n");
1678 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1680 LeaveCriticalSection(&ddraw_cs
);
1684 /*****************************************************************************
1685 * IDirectDrawSurface7::Initialize
1687 * Initializes the surface. This is a no-op in Wine
1690 * DD: Pointer to an DirectDraw interface
1691 * DDSD: Surface description for initialization
1694 * DDERR_ALREADYINITIALIZED
1696 *****************************************************************************/
1697 static HRESULT WINAPI
1698 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7
*iface
,
1700 DDSURFACEDESC2
*DDSD
)
1702 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1703 IDirectDrawImpl
*ddimpl
= DD
? ddraw_from_ddraw1(DD
) : NULL
;
1704 TRACE("(%p)->(%p,%p)\n",This
,ddimpl
,DDSD
);
1706 return DDERR_ALREADYINITIALIZED
;
1709 /*****************************************************************************
1710 * IDirectDrawSurface7::IsLost
1712 * Checks if the surface is lost
1715 * DD_OK, if the surface is usable
1716 * DDERR_ISLOST if the surface is lost
1717 * See IWineD3DSurface::IsLost for more details
1719 *****************************************************************************/
1720 static HRESULT WINAPI
1721 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7
*iface
)
1723 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1725 TRACE("(%p)\n", This
);
1727 EnterCriticalSection(&ddraw_cs
);
1728 /* We lose the surface if the implementation was changed */
1729 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1731 /* But this shouldn't happen. When we change the implementation,
1732 * all surfaces are re-created automatically, and their content
1735 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
1736 LeaveCriticalSection(&ddraw_cs
);
1737 return DDERR_SURFACELOST
;
1740 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
1741 LeaveCriticalSection(&ddraw_cs
);
1744 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1745 * WineD3D uses the same error for surfaces
1747 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
1752 /*****************************************************************************
1753 * IDirectDrawSurface7::Restore
1755 * Restores a lost surface. This makes the surface usable again, but
1756 * doesn't reload its old contents
1760 * See IWineD3DSurface::Restore for more details
1762 *****************************************************************************/
1763 static HRESULT WINAPI
1764 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7
*iface
)
1766 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1768 TRACE("(%p)\n", This
);
1770 EnterCriticalSection(&ddraw_cs
);
1771 if(This
->ImplType
!= This
->ddraw
->ImplType
)
1773 /* Call the recreation callback. Make sure to AddRef first */
1774 IDirectDrawSurface_AddRef(iface
);
1775 IDirectDrawImpl_RecreateSurfacesCallback(iface
,
1776 &This
->surface_desc
,
1777 NULL
/* Not needed */);
1779 hr
= IWineD3DSurface_Restore(This
->WineD3DSurface
);
1780 LeaveCriticalSection(&ddraw_cs
);
1784 /*****************************************************************************
1785 * IDirectDrawSurface7::SetOverlayPosition
1787 * Changes the display coordinates of an overlay surface
1794 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1795 *****************************************************************************/
1796 static HRESULT WINAPI
1797 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7
*iface
,
1801 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1803 TRACE("(%p)->(%d,%d): Relay\n", This
, X
, Y
);
1805 EnterCriticalSection(&ddraw_cs
);
1806 hr
= IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
1809 LeaveCriticalSection(&ddraw_cs
);
1813 /*****************************************************************************
1814 * IDirectDrawSurface7::UpdateOverlay
1816 * Modifies the attributes of an overlay surface.
1819 * SrcRect: The section of the source being used for the overlay
1820 * DstSurface: Address of the surface that is overlaid
1821 * DstRect: Place of the overlay
1822 * Flags: some DDOVER_* flags
1825 * DDERR_UNSUPPORTED, because we don't support overlays
1827 *****************************************************************************/
1828 static HRESULT WINAPI
1829 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7
*iface
,
1831 IDirectDrawSurface7
*DstSurface
,
1836 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1837 IDirectDrawSurfaceImpl
*Dst
= (IDirectDrawSurfaceImpl
*)DstSurface
;
1839 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This
, SrcRect
, Dst
, DstRect
, Flags
, FX
);
1841 EnterCriticalSection(&ddraw_cs
);
1842 hr
= IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
1844 Dst
? Dst
->WineD3DSurface
: NULL
,
1847 (WINEDDOVERLAYFX
*) FX
);
1848 LeaveCriticalSection(&ddraw_cs
);
1850 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1851 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
1852 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
1858 /*****************************************************************************
1859 * IDirectDrawSurface7::UpdateOverlayDisplay
1861 * The DX7 sdk says that it's not implemented
1866 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1868 *****************************************************************************/
1869 static HRESULT WINAPI
1870 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
,
1873 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1874 TRACE("(%p)->(%x)\n", This
, Flags
);
1875 return DDERR_UNSUPPORTED
;
1878 /*****************************************************************************
1879 * IDirectDrawSurface7::UpdateOverlayZOrder
1881 * Sets an overlay's Z order
1884 * Flags: DDOVERZ_* flags
1885 * DDSRef: Defines the relative position in the overlay chain
1888 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1890 *****************************************************************************/
1891 static HRESULT WINAPI
1892 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
1894 IDirectDrawSurface7
*DDSRef
)
1896 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1897 IDirectDrawSurfaceImpl
*Ref
= (IDirectDrawSurfaceImpl
*)DDSRef
;
1900 TRACE("(%p)->(%x,%p): Relay\n", This
, Flags
, Ref
);
1901 EnterCriticalSection(&ddraw_cs
);
1902 hr
= IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
1904 Ref
? Ref
->WineD3DSurface
: NULL
);
1905 LeaveCriticalSection(&ddraw_cs
);
1909 /*****************************************************************************
1910 * IDirectDrawSurface7::GetDDInterface
1912 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1913 * surface belongs to
1916 * DD: Address to write the interface pointer to
1920 * DDERR_INVALIDPARAMS if DD is NULL
1922 *****************************************************************************/
1923 static HRESULT WINAPI
1924 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7
*iface
,
1927 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1929 TRACE("(%p)->(%p)\n",This
,DD
);
1932 return DDERR_INVALIDPARAMS
;
1934 switch(This
->version
)
1941 *DD
= &This
->ddraw
->IDirectDraw4_vtbl
;
1945 *DD
= &This
->ddraw
->IDirectDraw2_vtbl
;
1949 *DD
= &This
->ddraw
->IDirectDraw_vtbl
;
1953 IUnknown_AddRef((IUnknown
*)*DD
);
1958 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1959 static HRESULT WINAPI
IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
1961 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1962 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
1964 TRACE("(%p)\n",This
);
1965 EnterCriticalSection(&ddraw_cs
);
1966 /* A uniqueness value of 0 is apparently special.
1967 * This needs to be checked.
1968 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1971 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
1972 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
1974 if (old_uniqueness_value
== 0) break;
1975 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
1977 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
1978 old_uniqueness_value
,
1979 new_uniqueness_value
)
1980 == old_uniqueness_value
)
1984 LeaveCriticalSection(&ddraw_cs
);
1988 static HRESULT WINAPI
IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7
*iface
, LPDWORD pValue
)
1990 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1992 TRACE("(%p)->(%p)\n",This
,pValue
);
1993 EnterCriticalSection(&ddraw_cs
);
1994 *pValue
= This
->uniqueness_value
;
1995 LeaveCriticalSection(&ddraw_cs
);
1999 /*****************************************************************************
2000 * IDirectDrawSurface7::SetLOD
2002 * Sets the level of detail of a texture
2005 * MaxLOD: LOD to set
2009 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2011 *****************************************************************************/
2012 static HRESULT WINAPI
2013 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7
*iface
,
2016 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2018 TRACE("(%p)->(%d)\n", This
, MaxLOD
);
2020 EnterCriticalSection(&ddraw_cs
);
2021 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2023 LeaveCriticalSection(&ddraw_cs
);
2024 return DDERR_INVALIDOBJECT
;
2027 if(!This
->wineD3DTexture
)
2029 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
2030 LeaveCriticalSection(&ddraw_cs
);
2031 return DDERR_INVALIDOBJECT
;
2034 hr
= IWineD3DBaseTexture_SetLOD(This
->wineD3DTexture
,
2036 LeaveCriticalSection(&ddraw_cs
);
2040 /*****************************************************************************
2041 * IDirectDrawSurface7::GetLOD
2043 * Returns the level of detail of a Direct3D texture
2046 * MaxLOD: Address to write the LOD to
2050 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2051 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2053 *****************************************************************************/
2054 static HRESULT WINAPI
2055 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7
*iface
,
2058 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2059 TRACE("(%p)->(%p)\n", This
, MaxLOD
);
2062 return DDERR_INVALIDPARAMS
;
2064 EnterCriticalSection(&ddraw_cs
);
2065 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2067 LeaveCriticalSection(&ddraw_cs
);
2068 return DDERR_INVALIDOBJECT
;
2071 *MaxLOD
= IWineD3DBaseTexture_GetLOD(This
->wineD3DTexture
);
2072 LeaveCriticalSection(&ddraw_cs
);
2076 /*****************************************************************************
2077 * IDirectDrawSurface7::BltFast
2079 * Performs a fast Blit.
2082 * dstx: The x coordinate to blit to on the destination
2083 * dsty: The y coordinate to blit to on the destination
2084 * Source: The source surface
2085 * rsrc: The source rectangle
2086 * trans: Type of transfer. Some DDBLTFAST_* flags
2090 * For more details, see IWineD3DSurface::BltFast
2092 *****************************************************************************/
2093 static HRESULT WINAPI
2094 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7
*iface
,
2097 IDirectDrawSurface7
*Source
,
2101 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2102 IDirectDrawSurfaceImpl
*src
= (IDirectDrawSurfaceImpl
*)Source
;
2104 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This
, dstx
, dsty
, Source
, rsrc
, trans
);
2106 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2111 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
2112 rsrc
->right
> src
->surface_desc
.dwWidth
||
2113 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
2115 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2116 return DDERR_INVALIDRECT
;
2118 if(dstx
+ rsrc
->right
- rsrc
->left
> This
->surface_desc
.dwWidth
||
2119 dsty
+ rsrc
->bottom
- rsrc
->top
> This
->surface_desc
.dwHeight
)
2121 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2122 return DDERR_INVALIDRECT
;
2127 if(dstx
+ src
->surface_desc
.dwWidth
> This
->surface_desc
.dwWidth
||
2128 dsty
+ src
->surface_desc
.dwHeight
> This
->surface_desc
.dwHeight
)
2130 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2131 return DDERR_INVALIDRECT
;
2135 EnterCriticalSection(&ddraw_cs
);
2136 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
2138 src
? src
->WineD3DSurface
: NULL
,
2141 LeaveCriticalSection(&ddraw_cs
);
2144 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
2145 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
2150 /*****************************************************************************
2151 * IDirectDrawSurface7::GetClipper
2153 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2157 * Clipper: Address to store the interface pointer at
2161 * DDERR_INVALIDPARAMS if Clipper is NULL
2162 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2164 *****************************************************************************/
2165 static HRESULT WINAPI
2166 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7
*iface
,
2167 IDirectDrawClipper
**Clipper
)
2169 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2170 TRACE("(%p)->(%p)\n", This
, Clipper
);
2174 LeaveCriticalSection(&ddraw_cs
);
2175 return DDERR_INVALIDPARAMS
;
2178 EnterCriticalSection(&ddraw_cs
);
2179 if(This
->clipper
== NULL
)
2181 LeaveCriticalSection(&ddraw_cs
);
2182 return DDERR_NOCLIPPERATTACHED
;
2185 *Clipper
= (IDirectDrawClipper
*)This
->clipper
;
2186 IDirectDrawClipper_AddRef(*Clipper
);
2187 LeaveCriticalSection(&ddraw_cs
);
2191 /*****************************************************************************
2192 * IDirectDrawSurface7::SetClipper
2194 * Sets a clipper for the surface
2197 * Clipper: IDirectDrawClipper interface of the clipper to set
2202 *****************************************************************************/
2203 static HRESULT WINAPI
2204 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7
*iface
,
2205 IDirectDrawClipper
*Clipper
)
2207 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2208 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
2211 TRACE("(%p)->(%p)\n",This
,Clipper
);
2213 EnterCriticalSection(&ddraw_cs
);
2214 if ((IDirectDrawClipperImpl
*)Clipper
== This
->clipper
)
2216 LeaveCriticalSection(&ddraw_cs
);
2220 This
->clipper
= (IDirectDrawClipperImpl
*)Clipper
;
2222 if (Clipper
!= NULL
)
2223 IDirectDrawClipper_AddRef(Clipper
);
2225 IDirectDrawClipper_Release((IDirectDrawClipper
*)oldClipper
);
2227 hr
= IWineD3DSurface_SetClipper(This
->WineD3DSurface
, This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
2229 if(This
->wineD3DSwapChain
) {
2232 IDirectDrawClipper_GetHWnd(Clipper
, &clipWindow
);
2236 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2239 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2240 This
->ddraw
->d3d_window
);
2244 LeaveCriticalSection(&ddraw_cs
);
2248 /*****************************************************************************
2249 * IDirectDrawSurface7::SetSurfaceDesc
2251 * Sets the surface description. It can override the pixel format, the surface
2253 * It's not really tested.
2256 * DDSD: Pointer to the new surface description to set
2261 * DDERR_INVALIDPARAMS if DDSD is NULL
2263 *****************************************************************************/
2264 static HRESULT WINAPI
2265 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7
*iface
,
2266 DDSURFACEDESC2
*DDSD
,
2269 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2270 WINED3DFORMAT newFormat
= WINED3DFMT_UNKNOWN
;
2272 TRACE("(%p)->(%p,%x)\n", This
, DDSD
, Flags
);
2275 return DDERR_INVALIDPARAMS
;
2277 EnterCriticalSection(&ddraw_cs
);
2278 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2280 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2282 if(newFormat
== WINED3DFMT_UNKNOWN
)
2284 ERR("Requested to set an unknown pixelformat\n");
2285 LeaveCriticalSection(&ddraw_cs
);
2286 return DDERR_INVALIDPARAMS
;
2288 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2290 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2294 LeaveCriticalSection(&ddraw_cs
);
2299 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2301 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2303 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2305 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2307 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2309 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2311 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2313 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2315 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2317 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2319 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2321 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2323 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
2325 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2326 if(hr
!= WINED3D_OK
)
2328 /* No need for a trace here, wined3d does that for us */
2331 case WINED3DERR_INVALIDCALL
:
2332 LeaveCriticalSection(&ddraw_cs
);
2333 return DDERR_INVALIDPARAMS
;
2340 This
->surface_desc
= *DDSD
;
2342 LeaveCriticalSection(&ddraw_cs
);
2346 /*****************************************************************************
2347 * IDirectDrawSurface7::GetPalette
2349 * Returns the IDirectDrawPalette interface of the palette currently assigned
2353 * Pal: Address to write the interface pointer to
2357 * DDERR_INVALIDPARAMS if Pal is NULL
2359 *****************************************************************************/
2360 static HRESULT WINAPI
2361 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7
*iface
,
2362 IDirectDrawPalette
**Pal
)
2364 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2365 IWineD3DPalette
*wPal
;
2367 TRACE("(%p)->(%p): Relay\n", This
, Pal
);
2370 return DDERR_INVALIDPARAMS
;
2372 EnterCriticalSection(&ddraw_cs
);
2373 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wPal
);
2376 LeaveCriticalSection(&ddraw_cs
);
2382 hr
= IWineD3DPalette_GetParent(wPal
, (IUnknown
**) Pal
);
2387 hr
= DDERR_NOPALETTEATTACHED
;
2390 LeaveCriticalSection(&ddraw_cs
);
2394 /*****************************************************************************
2397 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2398 * recursively in the surface tree
2400 *****************************************************************************/
2404 WINEDDCOLORKEY
*CKey
;
2408 static HRESULT WINAPI
2409 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2410 DDSURFACEDESC2
*desc
,
2413 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)surface
;
2414 struct SCKContext
*ctx
= context
;
2417 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2422 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2426 IDirectDrawSurface7_EnumAttachedSurfaces(surface
,
2429 IDirectDrawSurface7_Release(surface
);
2430 return DDENUMRET_OK
;
2433 /*****************************************************************************
2434 * IDirectDrawSurface7::SetColorKey
2436 * Sets the color keying options for the surface. Observations showed that
2437 * in case of complex surfaces the color key has to be assigned to all
2442 * CKey: The new color key
2446 * See IWineD3DSurface::SetColorKey for details
2448 *****************************************************************************/
2449 static HRESULT WINAPI
2450 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7
*iface
,
2454 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2455 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) CKey
, Flags
};
2456 TRACE("(%p)->(%x,%p)\n", This
, Flags
, CKey
);
2458 EnterCriticalSection(&ddraw_cs
);
2461 switch (Flags
& ~DDCKEY_COLORSPACE
)
2463 case DDCKEY_DESTBLT
:
2464 This
->surface_desc
.ddckCKDestBlt
= *CKey
;
2465 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2468 case DDCKEY_DESTOVERLAY
:
2469 This
->surface_desc
.u3
.ddckCKDestOverlay
= *CKey
;
2470 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2473 case DDCKEY_SRCOVERLAY
:
2474 This
->surface_desc
.ddckCKSrcOverlay
= *CKey
;
2475 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2479 This
->surface_desc
.ddckCKSrcBlt
= *CKey
;
2480 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2484 LeaveCriticalSection(&ddraw_cs
);
2485 return DDERR_INVALIDPARAMS
;
2490 switch (Flags
& ~DDCKEY_COLORSPACE
)
2492 case DDCKEY_DESTBLT
:
2493 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2496 case DDCKEY_DESTOVERLAY
:
2497 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2500 case DDCKEY_SRCOVERLAY
:
2501 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2505 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2509 LeaveCriticalSection(&ddraw_cs
);
2510 return DDERR_INVALIDPARAMS
;
2513 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2516 IDirectDrawSurface7_EnumAttachedSurfaces(iface
,
2519 LeaveCriticalSection(&ddraw_cs
);
2522 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2523 default: return ctx
.ret
;
2527 /*****************************************************************************
2528 * IDirectDrawSurface7::SetPalette
2530 * Assigns a DirectDrawPalette object to the surface
2533 * Pal: Interface to the palette to set
2538 *****************************************************************************/
2539 static HRESULT WINAPI
2540 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7
*iface
,
2541 IDirectDrawPalette
*Pal
)
2543 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2544 IDirectDrawPalette
*oldPal
;
2545 IDirectDrawSurfaceImpl
*surf
;
2546 IDirectDrawPaletteImpl
*PalImpl
= (IDirectDrawPaletteImpl
*)Pal
;
2548 TRACE("(%p)->(%p)\n", This
, Pal
);
2550 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
2551 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
2552 return DDERR_INVALIDPIXELFORMAT
;
2555 /* Find the old palette */
2556 EnterCriticalSection(&ddraw_cs
);
2557 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2558 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
2560 LeaveCriticalSection(&ddraw_cs
);
2563 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2565 /* Set the new Palette */
2566 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2567 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2568 /* AddRef the Palette */
2569 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2571 /* Release the old palette */
2572 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2574 /* If this is a front buffer, also update the back buffers
2575 * TODO: How do things work for palettized cube textures?
2577 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2579 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2580 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2585 IDirectDrawSurface7
*attach
;
2587 hr
= IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)surf
, &caps2
, &attach
);
2593 TRACE("Setting palette on %p\n", attach
);
2594 IDirectDrawSurface7_SetPalette(attach
,
2596 surf
= (IDirectDrawSurfaceImpl
*)attach
;
2597 IDirectDrawSurface7_Release(attach
);
2601 LeaveCriticalSection(&ddraw_cs
);
2605 /*****************************************************************************
2607 *****************************************************************************/
2609 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
=
2612 IDirectDrawSurfaceImpl_QueryInterface
,
2613 IDirectDrawSurfaceImpl_AddRef
,
2614 IDirectDrawSurfaceImpl_Release
,
2615 /*** IDirectDrawSurface ***/
2616 IDirectDrawSurface7Impl_AddAttachedSurface
,
2617 IDirectDrawSurfaceImpl_AddOverlayDirtyRect
,
2618 IDirectDrawSurfaceImpl_Blt
,
2619 IDirectDrawSurfaceImpl_BltBatch
,
2620 IDirectDrawSurfaceImpl_BltFast
,
2621 IDirectDrawSurfaceImpl_DeleteAttachedSurface
,
2622 IDirectDrawSurfaceImpl_EnumAttachedSurfaces
,
2623 IDirectDrawSurfaceImpl_EnumOverlayZOrders
,
2624 IDirectDrawSurfaceImpl_Flip
,
2625 IDirectDrawSurfaceImpl_GetAttachedSurface
,
2626 IDirectDrawSurfaceImpl_GetBltStatus
,
2627 IDirectDrawSurfaceImpl_GetCaps
,
2628 IDirectDrawSurfaceImpl_GetClipper
,
2629 IDirectDrawSurfaceImpl_GetColorKey
,
2630 IDirectDrawSurfaceImpl_GetDC
,
2631 IDirectDrawSurfaceImpl_GetFlipStatus
,
2632 IDirectDrawSurfaceImpl_GetOverlayPosition
,
2633 IDirectDrawSurfaceImpl_GetPalette
,
2634 IDirectDrawSurfaceImpl_GetPixelFormat
,
2635 IDirectDrawSurfaceImpl_GetSurfaceDesc
,
2636 IDirectDrawSurfaceImpl_Initialize
,
2637 IDirectDrawSurfaceImpl_IsLost
,
2638 IDirectDrawSurfaceImpl_Lock
,
2639 IDirectDrawSurfaceImpl_ReleaseDC
,
2640 IDirectDrawSurfaceImpl_Restore
,
2641 IDirectDrawSurfaceImpl_SetClipper
,
2642 IDirectDrawSurfaceImpl_SetColorKey
,
2643 IDirectDrawSurfaceImpl_SetOverlayPosition
,
2644 IDirectDrawSurfaceImpl_SetPalette
,
2645 IDirectDrawSurfaceImpl_Unlock
,
2646 IDirectDrawSurfaceImpl_UpdateOverlay
,
2647 IDirectDrawSurfaceImpl_UpdateOverlayDisplay
,
2648 IDirectDrawSurfaceImpl_UpdateOverlayZOrder
,
2649 /*** IDirectDrawSurface2 ***/
2650 IDirectDrawSurfaceImpl_GetDDInterface
,
2651 IDirectDrawSurfaceImpl_PageLock
,
2652 IDirectDrawSurfaceImpl_PageUnlock
,
2653 /*** IDirectDrawSurface3 ***/
2654 IDirectDrawSurfaceImpl_SetSurfaceDesc
,
2655 /*** IDirectDrawSurface4 ***/
2656 IDirectDrawSurfaceImpl_SetPrivateData
,
2657 IDirectDrawSurfaceImpl_GetPrivateData
,
2658 IDirectDrawSurfaceImpl_FreePrivateData
,
2659 IDirectDrawSurfaceImpl_GetUniquenessValue
,
2660 IDirectDrawSurfaceImpl_ChangeUniquenessValue
,
2661 /*** IDirectDrawSurface7 ***/
2662 IDirectDrawSurfaceImpl_SetPriority
,
2663 IDirectDrawSurfaceImpl_GetPriority
,
2664 IDirectDrawSurfaceImpl_SetLOD
,
2665 IDirectDrawSurfaceImpl_GetLOD