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"
29 #include "ddraw_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
33 static inline IDirectDrawSurfaceImpl
*surface_from_gamma_control(IDirectDrawGammaControl
*iface
)
35 return (IDirectDrawSurfaceImpl
*)((char*)iface
36 - FIELD_OFFSET(IDirectDrawSurfaceImpl
, IDirectDrawGammaControl_vtbl
));
39 /*****************************************************************************
40 * IUnknown parts follow
41 *****************************************************************************/
43 /*****************************************************************************
44 * IDirectDrawSurface7::QueryInterface
46 * A normal QueryInterface implementation. For QueryInterface rules
47 * see ddraw.c, IDirectDraw7::QueryInterface. This method
48 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
49 * in all versions, the IDirectDrawGammaControl interface and it can
50 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
53 * riid: The interface id queried for
54 * obj: Address to write the pointer to
58 * E_NOINTERFACE if the requested interface wasn't found
60 *****************************************************************************/
61 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
63 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
65 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
67 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
71 return DDERR_INVALIDPARAMS
;
73 if (IsEqualGUID(riid
, &IID_IUnknown
)
74 || IsEqualGUID(riid
, &IID_IDirectDrawSurface7
)
75 || IsEqualGUID(riid
, &IID_IDirectDrawSurface4
) )
77 IUnknown_AddRef(iface
);
79 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
82 else if( IsEqualGUID(riid
, &IID_IDirectDrawSurface3
)
83 || IsEqualGUID(riid
, &IID_IDirectDrawSurface2
)
84 || IsEqualGUID(riid
, &IID_IDirectDrawSurface
) )
86 IUnknown_AddRef(iface
);
87 *obj
= &This
->IDirectDrawSurface3_vtbl
;
88 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
91 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
93 IUnknown_AddRef(iface
);
94 *obj
= &This
->IDirectDrawGammaControl_vtbl
;
95 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
98 else if( IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
) ||
99 IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)||
100 IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
) )
102 IDirect3DDevice7
*d3d
;
104 /* Call into IDirect3D7 for creation */
105 IDirect3D7_CreateDevice(&This
->ddraw
->IDirect3D7_iface
, riid
, (IDirectDrawSurface7
*)This
,
110 *obj
= (IDirect3DDevice
*)&((IDirect3DDeviceImpl
*)d3d
)->IDirect3DDevice_vtbl
;
111 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
115 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
116 return E_NOINTERFACE
;
118 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
119 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
121 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
123 *obj
= &This
->IDirect3DTexture_vtbl
;
124 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
128 *obj
= &This
->IDirect3DTexture2_vtbl
;
129 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
131 IUnknown_AddRef( (IUnknown
*) *obj
);
135 ERR("No interface\n");
136 return E_NOINTERFACE
;
139 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
141 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
143 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_surface3(iface
), riid
, object
);
146 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
, REFIID riid
, void **object
)
148 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
150 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_gamma_control(iface
), riid
, object
);
153 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
155 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
157 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_texture2(iface
), riid
, object
);
160 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
162 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
164 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_texture1(iface
), riid
, object
);
167 /*****************************************************************************
168 * IDirectDrawSurface7::AddRef
170 * A normal addref implementation
175 *****************************************************************************/
176 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
178 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
179 ULONG refCount
= InterlockedIncrement(&This
->ref
);
181 TRACE("%p increasing refcount to %u.\n", This
, refCount
);
183 if (refCount
== 1 && This
->WineD3DSurface
)
185 EnterCriticalSection(&ddraw_cs
);
186 IWineD3DSurface_AddRef(This
->WineD3DSurface
);
187 LeaveCriticalSection(&ddraw_cs
);
193 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
195 TRACE("iface %p.\n", iface
);
197 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_surface3(iface
));
200 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
202 TRACE("iface %p.\n", iface
);
204 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_gamma_control(iface
));
207 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
209 TRACE("iface %p.\n", iface
);
211 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_texture2(iface
));
214 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
216 TRACE("iface %p.\n", iface
);
218 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_texture1(iface
));
221 /*****************************************************************************
222 * ddraw_surface_destroy
224 * A helper function for IDirectDrawSurface7::Release
226 * Frees the surface, regardless of its refcount.
227 * See IDirectDrawSurface7::Release for more information
230 * This: Surface to free
232 *****************************************************************************/
233 void ddraw_surface_destroy(IDirectDrawSurfaceImpl
*This
)
235 TRACE("surface %p.\n", This
);
237 /* Check the refcount and give a warning */
240 /* This can happen when a complex surface is destroyed,
241 * because the 2nd surface was addref()ed when the app
242 * called GetAttachedSurface
244 WARN("(%p): Destroying surface with refount %d\n", This
, This
->ref
);
247 /* Check for attached surfaces and detach them */
248 if(This
->first_attached
!= This
)
250 /* Well, this shouldn't happen: The surface being attached is addref()ed
251 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
252 * is called, because the refcount is held. It looks like the app released()
253 * it often enough to force this
255 IDirectDrawSurface7
*root
= (IDirectDrawSurface7
*)This
->first_attached
;
256 IDirectDrawSurface7
*detach
= (IDirectDrawSurface7
*)This
;
258 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This
, This
->first_attached
);
260 /* The refcount will drop to -1 here */
261 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
263 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
267 while(This
->next_attached
!= NULL
)
269 IDirectDrawSurface7
*root
= (IDirectDrawSurface7
*)This
;
270 IDirectDrawSurface7
*detach
= (IDirectDrawSurface7
*)This
->next_attached
;
272 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
274 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
279 /* Now destroy the surface. Wait: It could have been released if we are a texture */
280 if(This
->WineD3DSurface
)
281 IWineD3DSurface_Release(This
->WineD3DSurface
);
283 /* Having a texture handle set implies that the device still exists */
286 ddraw_free_handle(&This
->ddraw
->d3ddevice
->handle_table
, This
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
289 /* Reduce the ddraw surface count */
290 InterlockedDecrement(&This
->ddraw
->surfaces
);
291 list_remove(&This
->surface_list_entry
);
293 HeapFree(GetProcessHeap(), 0, This
);
296 /*****************************************************************************
297 * IDirectDrawSurface7::Release
299 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
300 * surface is destroyed.
302 * Destroying the surface is a bit tricky. For the connection between
303 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
304 * It has a nice graph explaining the connection.
306 * What happens here is basically this:
307 * When a surface is destroyed, its WineD3DSurface is released,
308 * and the refcount of the DirectDraw interface is reduced by 1. If it has
309 * complex surfaces attached to it, then these surfaces are destroyed too,
310 * regardless of their refcount. If any surface being destroyed has another
311 * surface attached to it (with a "soft" attachment, not complex), then
312 * this surface is detached with DeleteAttachedSurface.
314 * When the surface is a texture, the WineD3DTexture is released.
315 * If the surface is the Direct3D render target, then the D3D
316 * capabilities of the WineD3DDevice are uninitialized, which causes the
317 * swapchain to be released.
319 * When a complex sublevel falls to ref zero, then this is ignored.
324 *****************************************************************************/
325 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
327 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
328 ULONG ref
= InterlockedDecrement(&This
->ref
);
330 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
335 IDirectDrawSurfaceImpl
*surf
;
336 IDirectDrawImpl
*ddraw
;
337 IUnknown
*ifaceToRelease
= This
->ifaceToRelease
;
340 /* Complex attached surfaces are destroyed implicitly when the root is released */
341 EnterCriticalSection(&ddraw_cs
);
342 if(!This
->is_complex_root
)
344 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
345 LeaveCriticalSection(&ddraw_cs
);
350 /* If it's a texture, destroy the WineD3DTexture.
351 * WineD3D will destroy the IParent interfaces
352 * of the sublevels, which destroys the WineD3DSurfaces.
353 * Set the surfaces to NULL to avoid destroying them again later
355 if(This
->wineD3DTexture
)
357 IWineD3DBaseTexture_Release(This
->wineD3DTexture
);
359 /* If it's the RenderTarget, destroy the d3ddevice */
360 else if(This
->wineD3DSwapChain
)
362 if((ddraw
->d3d_initialized
) && (This
== ddraw
->d3d_target
)) {
363 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This
);
365 /* Unset any index buffer, just to be sure */
366 IWineD3DDevice_SetIndexBuffer(ddraw
->wineD3DDevice
, NULL
, WINED3DFMT_UNKNOWN
);
367 IWineD3DDevice_SetDepthStencilSurface(ddraw
->wineD3DDevice
, NULL
);
368 IWineD3DDevice_SetVertexDeclaration(ddraw
->wineD3DDevice
, NULL
);
369 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
371 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
373 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
374 ddraw
->numConvertedDecls
= 0;
376 if (FAILED(IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
)))
379 ERR("(%p) Failed to uninit 3D\n", This
);
383 /* Free the d3d window if one was created */
384 if(ddraw
->d3d_window
!= 0 && ddraw
->d3d_window
!= ddraw
->dest_window
)
386 TRACE(" (%p) Destroying the hidden render window %p\n", This
, ddraw
->d3d_window
);
387 DestroyWindow(ddraw
->d3d_window
);
388 ddraw
->d3d_window
= 0;
390 /* Unset the pointers */
393 This
->wineD3DSwapChain
= NULL
; /* Uninit3D releases the swapchain */
394 ddraw
->d3d_initialized
= FALSE
;
395 ddraw
->d3d_target
= NULL
;
397 IWineD3DDevice_UninitGDI(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
398 This
->wineD3DSwapChain
= NULL
;
401 /* Reset to the default surface implementation type. This is needed if apps use
402 * non render target surfaces and expect blits to work after destroying the render
405 * TODO: Recreate existing offscreen surfaces
407 ddraw
->ImplType
= DefaultSurfaceType
;
409 /* Write a trace because D3D unloading was the reason for many
410 * crashes during development.
412 TRACE("(%p) D3D unloaded\n", This
);
415 /* The refcount test shows that the palette is detached when the surface is destroyed */
416 IDirectDrawSurface7_SetPalette((IDirectDrawSurface7
*)This
, NULL
);
418 /* Loop through all complex attached surfaces,
421 * Yet again, only the root can have more than one complexly attached surface, all the others
422 * have a total of one;
424 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
426 if(!This
->complex_array
[i
]) break;
428 surf
= This
->complex_array
[i
];
429 This
->complex_array
[i
] = NULL
;
432 IDirectDrawSurfaceImpl
*destroy
= surf
;
433 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
434 ddraw_surface_destroy(destroy
); /* Destroy it */
438 /* Destroy the root surface. */
439 ddraw_surface_destroy(This
);
441 /* Reduce the ddraw refcount */
442 if(ifaceToRelease
) IUnknown_Release(ifaceToRelease
);
443 LeaveCriticalSection(&ddraw_cs
);
449 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
451 TRACE("iface %p.\n", iface
);
453 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_surface3(iface
));
456 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
458 TRACE("iface %p.\n", iface
);
460 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_gamma_control(iface
));
463 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
465 TRACE("iface %p.\n", iface
);
467 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_texture2(iface
));
470 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
472 TRACE("iface %p.\n", iface
);
474 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_texture1(iface
));
477 /*****************************************************************************
478 * IDirectDrawSurface7::GetAttachedSurface
480 * Returns an attached surface with the requested caps. Surface attachment
481 * and complex surfaces are not clearly described by the MSDN or sdk,
482 * so this method is tricky and likely to contain problems.
483 * This implementation searches the complex list first, then the
486 * The chains are searched from This down to the last surface in the chain,
487 * not from the first element in the chain. The first surface found is
488 * returned. The MSDN says that this method fails if more than one surface
489 * matches the caps, but it is not sure if that is right. The attachment
490 * structure may not even allow two matching surfaces.
492 * The found surface is AddRef-ed before it is returned.
495 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
496 * Surface: Address to store the found surface
500 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
501 * DDERR_NOTFOUND if no surface was found
503 *****************************************************************************/
504 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
505 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
507 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
508 IDirectDrawSurfaceImpl
*surf
;
512 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
514 EnterCriticalSection(&ddraw_cs
);
516 if(This
->version
< 7)
518 /* Earlier dx apps put garbage into these members, clear them */
519 our_caps
.dwCaps
= Caps
->dwCaps
;
520 our_caps
.dwCaps2
= 0;
521 our_caps
.dwCaps3
= 0;
522 our_caps
.dwCaps4
= 0;
529 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 */
531 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
533 surf
= This
->complex_array
[i
];
538 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
539 surf
->surface_desc
.ddsCaps
.dwCaps
,
540 surf
->surface_desc
.ddsCaps
.dwCaps2
,
541 surf
->surface_desc
.ddsCaps
.dwCaps3
,
542 surf
->surface_desc
.ddsCaps
.dwCaps4
);
545 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
546 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
548 /* MSDN: "This method fails if more than one surface is attached
549 * that matches the capabilities requested."
551 * Not sure how to test this.
554 TRACE("(%p): Returning surface %p\n", This
, surf
);
555 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
556 *Surface
= (IDirectDrawSurface7
*)surf
;
557 ddraw_surface7_AddRef(*Surface
);
558 LeaveCriticalSection(&ddraw_cs
);
563 /* Next, look at the attachment chain */
566 while( (surf
= surf
->next_attached
) )
570 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
571 surf
->surface_desc
.ddsCaps
.dwCaps
,
572 surf
->surface_desc
.ddsCaps
.dwCaps2
,
573 surf
->surface_desc
.ddsCaps
.dwCaps3
,
574 surf
->surface_desc
.ddsCaps
.dwCaps4
);
577 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
578 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
580 TRACE("(%p): Returning surface %p\n", This
, surf
);
581 *Surface
= (IDirectDrawSurface7
*)surf
;
582 ddraw_surface7_AddRef(*Surface
);
583 LeaveCriticalSection(&ddraw_cs
);
588 TRACE("(%p) Didn't find a valid surface\n", This
);
589 LeaveCriticalSection(&ddraw_cs
);
592 return DDERR_NOTFOUND
;
595 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
596 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
598 IDirectDrawSurface7
*attachment7
;
602 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
604 caps2
.dwCaps
= caps
->dwCaps
;
609 hr
= ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7
*)surface_from_surface3(iface
),
610 &caps2
, &attachment7
);
611 if (FAILED(hr
)) *attachment
= NULL
;
612 else *attachment
= attachment7
?
613 (IDirectDrawSurface3
*)&((IDirectDrawSurfaceImpl
*)attachment7
)->IDirectDrawSurface3_vtbl
: NULL
;
618 /*****************************************************************************
619 * IDirectDrawSurface7::Lock
621 * Locks the surface and returns a pointer to the surface's memory
624 * Rect: Rectangle to lock. If NULL, the whole surface is locked
625 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
626 * Flags: Locking flags, e.g Read only or write only
627 * h: An event handle that's not used and must be NULL
631 * DDERR_INVALIDPARAMS if DDSD is NULL
632 * For more details, see IWineD3DSurface::LockRect
634 *****************************************************************************/
635 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
636 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
638 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
639 WINED3DLOCKED_RECT LockedRect
;
642 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
643 iface
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
646 return DDERR_INVALIDPARAMS
;
648 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
649 EnterCriticalSection(&ddraw_cs
);
651 /* Should I check for the handle to be NULL?
653 * The DDLOCK flags and the D3DLOCK flags are equal
654 * for the supported values. The others are ignored by WineD3D
657 if(DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) &&
658 DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
660 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS
);
661 LeaveCriticalSection(&ddraw_cs
);
662 return DDERR_INVALIDPARAMS
;
665 /* Windows zeroes this if the rect is invalid */
672 || (Rect
->left
> Rect
->right
)
673 || (Rect
->top
> Rect
->bottom
)
674 || (Rect
->right
> This
->surface_desc
.dwWidth
)
675 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
677 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
678 LeaveCriticalSection(&ddraw_cs
);
679 return DDERR_INVALIDPARAMS
;
683 hr
= IWineD3DSurface_Map(This
->WineD3DSurface
, &LockedRect
, Rect
, Flags
);
686 LeaveCriticalSection(&ddraw_cs
);
689 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
690 * specific error. But since IWineD3DSurface::LockRect returns that error in this
691 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
692 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
693 * is much easier to do it in one place in ddraw
695 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
700 /* Override the memory area. The pitch should be set already. Strangely windows
701 * does not set the LPSURFACE flag on locked surfaces !?!.
702 * DDSD->dwFlags |= DDSD_LPSURFACE;
704 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
705 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
707 TRACE("locked surface returning description :\n");
708 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
710 LeaveCriticalSection(&ddraw_cs
);
714 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
715 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
717 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
718 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
720 return ddraw_surface7_Lock((IDirectDrawSurface7
*)surface_from_surface3(iface
),
721 rect
, (DDSURFACEDESC2
*)surface_desc
, flags
, h
);
724 /*****************************************************************************
725 * IDirectDrawSurface7::Unlock
727 * Unlocks an locked surface
730 * Rect: Not used by this implementation
734 * For more details, see IWineD3DSurface::UnlockRect
736 *****************************************************************************/
737 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
739 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
742 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
744 EnterCriticalSection(&ddraw_cs
);
745 hr
= IWineD3DSurface_Unmap(This
->WineD3DSurface
);
748 This
->surface_desc
.lpSurface
= NULL
;
750 LeaveCriticalSection(&ddraw_cs
);
754 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
756 TRACE("iface %p, data %p.\n", iface
, data
);
758 /* data might not be the LPRECT of later versions, so drop it. */
759 return ddraw_surface7_Unlock((IDirectDrawSurface7
*)surface_from_surface3(iface
), NULL
);
762 /*****************************************************************************
763 * IDirectDrawSurface7::Flip
765 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
766 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
767 * the flip target is passed to WineD3D, even if the app didn't specify one
770 * DestOverride: Specifies the surface that will become the new front
771 * buffer. If NULL, the current back buffer is used
772 * Flags: some DirectDraw flags, see include/ddraw.h
776 * DDERR_NOTFLIPPABLE if no flip target could be found
777 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
778 * For more details, see IWineD3DSurface::Flip
780 *****************************************************************************/
781 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
783 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
784 IDirectDrawSurfaceImpl
*Override
= (IDirectDrawSurfaceImpl
*)DestOverride
;
785 IDirectDrawSurface7
*Override7
;
788 TRACE("iface %p, dst %p, flags %#x.\n", iface
, DestOverride
, Flags
);
790 /* Flip has to be called from a front buffer
791 * What about overlay surfaces, AFAIK they can flip too?
793 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
794 return DDERR_INVALIDOBJECT
; /* Unchecked */
796 EnterCriticalSection(&ddraw_cs
);
798 /* WineD3D doesn't keep track of attached surface, so find the target */
803 memset(&Caps
, 0, sizeof(Caps
));
804 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
805 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
808 ERR("Can't find a flip target\n");
809 LeaveCriticalSection(&ddraw_cs
);
810 return DDERR_NOTFLIPPABLE
; /* Unchecked */
812 Override
= (IDirectDrawSurfaceImpl
*)Override7
;
814 /* For the GetAttachedSurface */
815 ddraw_surface7_Release(Override7
);
818 hr
= IWineD3DSurface_Flip(This
->WineD3DSurface
,
819 Override
->WineD3DSurface
,
821 LeaveCriticalSection(&ddraw_cs
);
825 static HRESULT WINAPI
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
827 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
829 return ddraw_surface7_Flip((IDirectDrawSurface7
*)surface_from_surface3(iface
),
830 dst
? (IDirectDrawSurface7
*)surface_from_surface3(dst
) : NULL
, flags
);
833 /*****************************************************************************
834 * IDirectDrawSurface7::Blt
836 * Performs a blit on the surface
839 * DestRect: Destination rectangle, can be NULL
840 * SrcSurface: Source surface, can be NULL
841 * SrcRect: Source rectangle, can be NULL
843 * DDBltFx: Some extended blt parameters, connected to the flags
847 * See IWineD3DSurface::Blt for more details
849 *****************************************************************************/
850 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
851 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
853 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
854 IDirectDrawSurfaceImpl
*Src
= (IDirectDrawSurfaceImpl
*)SrcSurface
;
857 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
858 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
860 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
861 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
863 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
864 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
865 return DDERR_INVALIDPARAMS
;
868 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
869 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
870 return DDERR_INVALIDPARAMS
;
873 /* Sizes can change, therefore hold the lock when testing the rectangles */
874 EnterCriticalSection(&ddraw_cs
);
877 if(DestRect
->top
>= DestRect
->bottom
|| DestRect
->left
>= DestRect
->right
||
878 DestRect
->right
> This
->surface_desc
.dwWidth
||
879 DestRect
->bottom
> This
->surface_desc
.dwHeight
)
881 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
882 LeaveCriticalSection(&ddraw_cs
);
883 return DDERR_INVALIDRECT
;
888 if(SrcRect
->top
>= SrcRect
->bottom
|| SrcRect
->left
>=SrcRect
->right
||
889 SrcRect
->right
> Src
->surface_desc
.dwWidth
||
890 SrcRect
->bottom
> Src
->surface_desc
.dwHeight
)
892 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
893 LeaveCriticalSection(&ddraw_cs
);
894 return DDERR_INVALIDRECT
;
898 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
899 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
900 LeaveCriticalSection(&ddraw_cs
);
901 return DDERR_INVALIDPARAMS
;
904 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
905 * and replace the ddraw surfaces with the wined3d surfaces
906 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
908 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
, DestRect
, Src
? Src
->WineD3DSurface
: NULL
,
909 SrcRect
, Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3DTEXF_LINEAR
);
911 LeaveCriticalSection(&ddraw_cs
);
914 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
915 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
920 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
921 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
923 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
924 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
926 return ddraw_surface7_Blt((IDirectDrawSurface7
*)surface_from_surface3(iface
), dst_rect
,
927 src_surface
? (IDirectDrawSurface7
*)surface_from_surface3(src_surface
) : NULL
, src_rect
, flags
, fx
);
930 /*****************************************************************************
931 * IDirectDrawSurface7::AddAttachedSurface
933 * Attaches a surface to another surface. How the surface attachments work
934 * is not totally understood yet, and this method is prone to problems.
935 * he surface that is attached is AddRef-ed.
937 * Tests with complex surfaces suggest that the surface attachments form a
938 * tree, but no method to test this has been found yet.
940 * The attachment list consists of a first surface (first_attached) and
941 * for each surface a pointer to the next attached surface (next_attached).
942 * For the first surface, and a surface that has no attachments
943 * first_attached points to the surface itself. A surface that has
944 * no successors in the chain has next_attached set to NULL.
946 * Newly attached surfaces are attached right after the root surface.
947 * If a surface is attached to a complex surface compound, it's attached to
948 * the surface that the app requested, not the complex root. See
949 * GetAttachedSurface for a description how surfaces are found.
951 * This is how the current implementation works, and it was coded by looking
952 * at the needs of the applications.
954 * So far only Z-Buffer attachments are tested, and they are activated in
955 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
956 * Back buffers should work in 2D mode, but they are not tested(They can be
957 * attached in older iface versions). Rendering to the front buffer and
958 * switching between that and double buffering is not yet implemented in
959 * WineD3D, so for 3D it might have unexpected results.
961 * ddraw_surface_attach_surface is the real thing,
962 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
963 * performs additional checks. Version 7 of this interface is much more restrictive
964 * than its predecessors.
967 * Attach: Surface to attach to iface
971 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
973 *****************************************************************************/
974 static HRESULT
ddraw_surface_attach_surface(IDirectDrawSurfaceImpl
*This
, IDirectDrawSurfaceImpl
*Surf
)
976 TRACE("surface %p, attachment %p.\n", This
, Surf
);
979 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
981 EnterCriticalSection(&ddraw_cs
);
983 /* Check if the surface is already attached somewhere */
984 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
986 /* TODO: Test for the structure of the manual attachment. Is it a
987 * chain or a list? What happens if one surface is attached to 2
988 * different surfaces? */
989 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
990 Surf
, Surf
->next_attached
, Surf
->first_attached
);
992 LeaveCriticalSection(&ddraw_cs
);
993 return DDERR_SURFACEALREADYATTACHED
;
996 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
997 Surf
->next_attached
= This
->next_attached
;
998 Surf
->first_attached
= This
->first_attached
;
999 This
->next_attached
= Surf
;
1001 /* Check if the WineD3D depth stencil needs updating */
1002 if(This
->ddraw
->d3ddevice
)
1004 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1007 ddraw_surface7_AddRef((IDirectDrawSurface7
*)Surf
);
1008 LeaveCriticalSection(&ddraw_cs
);
1012 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*Attach
)
1014 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1015 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Attach
;
1017 TRACE("iface %p, attachment %p.\n", iface
, Attach
);
1019 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1020 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1023 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1024 Surf
->surface_desc
.ddsCaps
.dwCaps
);
1025 return DDERR_CANNOTATTACHSURFACE
;
1028 return ddraw_surface_attach_surface(This
, Surf
);
1031 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1033 IDirectDrawSurfaceImpl
*surface
= surface_from_surface3(iface
);
1034 IDirectDrawSurfaceImpl
*attach_impl
= surface_from_surface3(attachment
);
1036 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1038 /* Tests suggest that
1039 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1040 * -> offscreen plain surfaces can be attached to primaries
1041 * -> primaries can be attached to offscreen plain surfaces
1042 * -> z buffers can be attached to primaries */
1043 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1044 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1046 /* Sizes have to match */
1047 if (attach_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1048 || attach_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1050 WARN("Surface sizes do not match.\n");
1051 return DDERR_CANNOTATTACHSURFACE
;
1055 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1056 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1062 WARN("Invalid attachment combination.\n");
1063 return DDERR_CANNOTATTACHSURFACE
;
1066 return ddraw_surface_attach_surface(surface
, attach_impl
);
1069 /*****************************************************************************
1070 * IDirectDrawSurface7::DeleteAttachedSurface
1072 * Removes a surface from the attachment chain. The surface's refcount
1073 * is decreased by one after it has been removed
1076 * Flags: Some flags, not used by this implementation
1077 * Attach: Surface to detach
1081 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1083 *****************************************************************************/
1084 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1085 DWORD Flags
, IDirectDrawSurface7
*Attach
)
1087 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1088 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Attach
;
1089 IDirectDrawSurfaceImpl
*Prev
= This
;
1091 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, Flags
, Attach
);
1093 EnterCriticalSection(&ddraw_cs
);
1094 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
1096 LeaveCriticalSection(&ddraw_cs
);
1097 return DDERR_CANNOTDETACHSURFACE
;
1100 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1101 if (This
->surface_desc
.ddsCaps
.dwCaps
&
1102 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1104 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1105 /* FIXME: we should probably also subtract from dwMipMapCount of this
1106 * and all parent surfaces */
1109 /* Find the predecessor of the detached surface */
1112 if(Prev
->next_attached
== Surf
) break;
1113 Prev
= Prev
->next_attached
;
1116 /* There must be a surface, otherwise there's a bug */
1117 assert(Prev
!= NULL
);
1119 /* Unchain the surface */
1120 Prev
->next_attached
= Surf
->next_attached
;
1121 Surf
->next_attached
= NULL
;
1122 Surf
->first_attached
= Surf
;
1124 /* Check if the WineD3D depth stencil needs updating */
1125 if(This
->ddraw
->d3ddevice
)
1127 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1130 ddraw_surface7_Release(Attach
);
1131 LeaveCriticalSection(&ddraw_cs
);
1135 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1136 DWORD flags
, IDirectDrawSurface3
*attachment
)
1138 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1140 return ddraw_surface7_DeleteAttachedSurface((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
,
1141 attachment
? (IDirectDrawSurface7
*)surface_from_surface3(attachment
) : NULL
);
1144 /*****************************************************************************
1145 * IDirectDrawSurface7::AddOverlayDirtyRect
1147 * "This method is not currently implemented"
1155 *****************************************************************************/
1156 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1158 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1160 return DDERR_UNSUPPORTED
; /* unchecked */
1163 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1165 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1167 return ddraw_surface7_AddOverlayDirtyRect((IDirectDrawSurface7
*)surface_from_surface3(iface
), rect
);
1170 /*****************************************************************************
1171 * IDirectDrawSurface7::GetDC
1173 * Returns a GDI device context for the surface
1176 * hdc: Address of a HDC variable to store the dc to
1180 * DDERR_INVALIDPARAMS if hdc is NULL
1181 * For details, see IWineD3DSurface::GetDC
1183 *****************************************************************************/
1184 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1186 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1189 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1192 return DDERR_INVALIDPARAMS
;
1194 EnterCriticalSection(&ddraw_cs
);
1195 hr
= IWineD3DSurface_GetDC(This
->WineD3DSurface
,
1197 LeaveCriticalSection(&ddraw_cs
);
1200 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1203 case WINED3DERR_INVALIDCALL
:
1204 if(hdc
) *hdc
= NULL
;
1205 return DDERR_INVALIDPARAMS
;
1211 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1213 TRACE("iface %p, dc %p.\n", iface
, dc
);
1215 return ddraw_surface7_GetDC((IDirectDrawSurface7
*)surface_from_surface3(iface
), dc
);
1218 /*****************************************************************************
1219 * IDirectDrawSurface7::ReleaseDC
1221 * Releases the DC that was constructed with GetDC
1224 * hdc: HDC to release
1228 * For more details, see IWineD3DSurface::ReleaseDC
1230 *****************************************************************************/
1231 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
1233 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1236 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1238 EnterCriticalSection(&ddraw_cs
);
1239 hr
= IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
1240 LeaveCriticalSection(&ddraw_cs
);
1244 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
1246 TRACE("iface %p, dc %p.\n", iface
, dc
);
1248 return ddraw_surface7_ReleaseDC((IDirectDrawSurface7
*)surface_from_surface3(iface
), dc
);
1251 /*****************************************************************************
1252 * IDirectDrawSurface7::GetCaps
1254 * Returns the surface's caps
1257 * Caps: Address to write the caps to
1261 * DDERR_INVALIDPARAMS if Caps is NULL
1263 *****************************************************************************/
1264 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
1266 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1268 TRACE("iface %p, caps %p.\n", iface
, Caps
);
1271 return DDERR_INVALIDPARAMS
;
1273 *Caps
= This
->surface_desc
.ddsCaps
;
1277 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
1282 TRACE("iface %p, caps %p.\n", iface
, caps
);
1284 hr
= ddraw_surface7_GetCaps((IDirectDrawSurface7
*)surface_from_surface3(iface
), &caps2
);
1285 if (FAILED(hr
)) return hr
;
1287 caps
->dwCaps
= caps2
.dwCaps
;
1291 /*****************************************************************************
1292 * IDirectDrawSurface7::SetPriority
1294 * Sets a texture priority for managed textures.
1297 * Priority: The new priority
1301 * For more details, see IWineD3DSurface::SetPriority
1303 *****************************************************************************/
1304 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1306 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1309 TRACE("iface %p, priority %u.\n", iface
, Priority
);
1311 EnterCriticalSection(&ddraw_cs
);
1312 hr
= IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1313 LeaveCriticalSection(&ddraw_cs
);
1317 /*****************************************************************************
1318 * IDirectDrawSurface7::GetPriority
1320 * Returns the surface's priority
1323 * Priority: Address of a variable to write the priority to
1327 * DDERR_INVALIDPARAMS if Priority == NULL
1328 * For more details, see IWineD3DSurface::GetPriority
1330 *****************************************************************************/
1331 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
1333 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1335 TRACE("iface %p, priority %p.\n", iface
, Priority
);
1339 return DDERR_INVALIDPARAMS
;
1342 EnterCriticalSection(&ddraw_cs
);
1343 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1344 LeaveCriticalSection(&ddraw_cs
);
1348 /*****************************************************************************
1349 * IDirectDrawSurface7::SetPrivateData
1351 * Stores some data in the surface that is intended for the application's
1355 * tag: GUID that identifies the data
1356 * Data: Pointer to the private data
1357 * Size: Size of the private data
1362 * For more details, see IWineD3DSurface::SetPrivateData
1364 *****************************************************************************/
1365 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
1366 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
1368 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1371 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
1372 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
1374 EnterCriticalSection(&ddraw_cs
);
1375 hr
= IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1380 LeaveCriticalSection(&ddraw_cs
);
1383 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1388 /*****************************************************************************
1389 * IDirectDrawSurface7::GetPrivateData
1391 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1394 * tag: GUID of the data to return
1395 * Data: Address where to write the data to
1396 * Size: Size of the buffer at Data
1400 * DDERR_INVALIDPARAMS if Data is NULL
1401 * For more details, see IWineD3DSurface::GetPrivateData
1403 *****************************************************************************/
1404 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
1406 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1409 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
1410 iface
, debugstr_guid(tag
), Data
, Size
);
1413 return DDERR_INVALIDPARAMS
;
1415 EnterCriticalSection(&ddraw_cs
);
1416 hr
= IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1420 LeaveCriticalSection(&ddraw_cs
);
1424 /*****************************************************************************
1425 * IDirectDrawSurface7::FreePrivateData
1427 * Frees private data stored in the surface
1430 * tag: Tag of the data to free
1434 * For more details, see IWineD3DSurface::FreePrivateData
1436 *****************************************************************************/
1437 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
1439 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1442 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
1444 EnterCriticalSection(&ddraw_cs
);
1445 hr
= IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1446 LeaveCriticalSection(&ddraw_cs
);
1450 /*****************************************************************************
1451 * IDirectDrawSurface7::PageLock
1453 * Prevents a sysmem surface from being paged out
1456 * Flags: Not used, must be 0(unchecked)
1459 * DD_OK, because it's a stub
1461 *****************************************************************************/
1462 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
1464 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
1466 /* This is Windows memory management related - we don't need this */
1470 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
1472 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1474 return ddraw_surface7_PageLock((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1477 /*****************************************************************************
1478 * IDirectDrawSurface7::PageUnlock
1480 * Allows a sysmem surface to be paged out
1483 * Flags: Not used, must be 0(unchecked)
1486 * DD_OK, because it's a stub
1488 *****************************************************************************/
1489 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
1491 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
1496 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
1498 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1500 return ddraw_surface7_PageUnlock((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1503 /*****************************************************************************
1504 * IDirectDrawSurface7::BltBatch
1506 * An unimplemented function
1514 *****************************************************************************/
1515 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1517 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
1519 /* MSDN: "not currently implemented" */
1520 return DDERR_UNSUPPORTED
;
1523 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
1525 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
1527 return ddraw_surface7_BltBatch((IDirectDrawSurface7
*)surface_from_surface3(iface
), batch
, count
, flags
);
1530 /*****************************************************************************
1531 * IDirectDrawSurface7::EnumAttachedSurfaces
1533 * Enumerates all surfaces attached to this surface
1536 * context: Pointer to pass unmodified to the callback
1537 * cb: Callback function to call for each surface
1541 * DDERR_INVALIDPARAMS if cb is NULL
1543 *****************************************************************************/
1544 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1545 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
1547 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1548 IDirectDrawSurfaceImpl
*surf
;
1549 DDSURFACEDESC2 desc
;
1552 /* Attached surfaces aren't handled in WineD3D */
1553 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
1556 return DDERR_INVALIDPARAMS
;
1558 EnterCriticalSection(&ddraw_cs
);
1559 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1561 surf
= This
->complex_array
[i
];
1564 ddraw_surface7_AddRef((IDirectDrawSurface7
*)surf
);
1565 desc
= surf
->surface_desc
;
1566 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1567 if (cb((IDirectDrawSurface7
*)surf
, &desc
, context
) == DDENUMRET_CANCEL
)
1569 LeaveCriticalSection(&ddraw_cs
);
1574 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1576 ddraw_surface7_AddRef((IDirectDrawSurface7
*)surf
);
1577 desc
= surf
->surface_desc
;
1578 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1579 if (cb((IDirectDrawSurface7
*)surf
, &desc
, context
) == DDENUMRET_CANCEL
)
1581 LeaveCriticalSection(&ddraw_cs
);
1586 TRACE(" end of enumeration.\n");
1588 LeaveCriticalSection(&ddraw_cs
);
1592 struct callback_info
1594 LPDDENUMSURFACESCALLBACK callback
;
1598 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
1600 const struct callback_info
*info
= context
;
1602 return info
->callback((IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface
)->IDirectDrawSurface3_vtbl
,
1603 (DDSURFACEDESC
*)surface_desc
, info
->context
);
1606 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
1607 void *context
, LPDDENUMSURFACESCALLBACK callback
)
1609 struct callback_info info
;
1611 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
1613 info
.callback
= callback
;
1614 info
.context
= context
;
1616 return ddraw_surface7_EnumAttachedSurfaces((IDirectDrawSurface7
*)surface_from_surface3(iface
),
1617 &info
, EnumCallback
);
1620 /*****************************************************************************
1621 * IDirectDrawSurface7::EnumOverlayZOrders
1623 * "Enumerates the overlay surfaces on the specified destination"
1626 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1627 * context: context to pass back to the callback
1628 * cb: callback function to call for each enumerated surface
1631 * DD_OK, because it's a stub
1633 *****************************************************************************/
1634 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1635 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
1637 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
1642 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
1643 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
1645 struct callback_info info
;
1647 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
1649 info
.callback
= callback
;
1650 info
.context
= context
;
1652 return ddraw_surface7_EnumOverlayZOrders((IDirectDrawSurface7
*)surface_from_surface3(iface
),
1653 flags
, &info
, EnumCallback
);
1656 /*****************************************************************************
1657 * IDirectDrawSurface7::GetBltStatus
1659 * Returns the blitting status
1662 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1665 * See IWineD3DSurface::Blt
1667 *****************************************************************************/
1668 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
1670 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1673 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
1675 EnterCriticalSection(&ddraw_cs
);
1676 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1677 LeaveCriticalSection(&ddraw_cs
);
1680 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1685 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
1687 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1689 return ddraw_surface7_GetBltStatus((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1692 /*****************************************************************************
1693 * IDirectDrawSurface7::GetColorKey
1695 * Returns the color key assigned to the surface
1699 * CKey: Address to store the key to
1703 * DDERR_INVALIDPARAMS if CKey is NULL
1705 *****************************************************************************/
1706 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
1708 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1710 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
1713 return DDERR_INVALIDPARAMS
;
1715 EnterCriticalSection(&ddraw_cs
);
1719 case DDCKEY_DESTBLT
:
1720 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1722 LeaveCriticalSection(&ddraw_cs
);
1723 return DDERR_NOCOLORKEY
;
1725 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1728 case DDCKEY_DESTOVERLAY
:
1729 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
1731 LeaveCriticalSection(&ddraw_cs
);
1732 return DDERR_NOCOLORKEY
;
1734 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1738 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
1740 LeaveCriticalSection(&ddraw_cs
);
1741 return DDERR_NOCOLORKEY
;
1743 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1746 case DDCKEY_SRCOVERLAY
:
1747 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
1749 LeaveCriticalSection(&ddraw_cs
);
1750 return DDERR_NOCOLORKEY
;
1752 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1756 LeaveCriticalSection(&ddraw_cs
);
1757 return DDERR_INVALIDPARAMS
;
1760 LeaveCriticalSection(&ddraw_cs
);
1764 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
1766 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
1768 return ddraw_surface7_GetColorKey((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
, color_key
);
1771 /*****************************************************************************
1772 * IDirectDrawSurface7::GetFlipStatus
1774 * Returns the flipping status of the surface
1777 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1780 * See IWineD3DSurface::GetFlipStatus
1782 *****************************************************************************/
1783 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
1785 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1788 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
1790 EnterCriticalSection(&ddraw_cs
);
1791 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1792 LeaveCriticalSection(&ddraw_cs
);
1795 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1800 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
1802 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1804 return ddraw_surface7_GetFlipStatus((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1807 /*****************************************************************************
1808 * IDirectDrawSurface7::GetOverlayPosition
1810 * Returns the display coordinates of a visible and active overlay surface
1817 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1818 *****************************************************************************/
1819 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
1821 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1824 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
1826 EnterCriticalSection(&ddraw_cs
);
1827 hr
= IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1830 LeaveCriticalSection(&ddraw_cs
);
1834 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
1836 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
1838 return ddraw_surface7_GetOverlayPosition((IDirectDrawSurface7
*)surface_from_surface3(iface
), x
, y
);
1841 /*****************************************************************************
1842 * IDirectDrawSurface7::GetPixelFormat
1844 * Returns the pixel format of the Surface
1847 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1848 * format should be written
1852 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1854 *****************************************************************************/
1855 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
1857 /* What is DDERR_INVALIDSURFACETYPE for here? */
1858 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1860 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
1863 return DDERR_INVALIDPARAMS
;
1865 EnterCriticalSection(&ddraw_cs
);
1866 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1867 LeaveCriticalSection(&ddraw_cs
);
1872 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
1874 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
1876 return ddraw_surface7_GetPixelFormat((IDirectDrawSurface7
*)surface_from_surface3(iface
), pixel_format
);
1879 /*****************************************************************************
1880 * IDirectDrawSurface7::GetSurfaceDesc
1882 * Returns the description of this surface
1885 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1890 * DDERR_INVALIDPARAMS if DDSD is NULL
1892 *****************************************************************************/
1893 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
1895 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1897 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1900 return DDERR_INVALIDPARAMS
;
1902 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
1904 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
1905 return DDERR_INVALIDPARAMS
;
1908 EnterCriticalSection(&ddraw_cs
);
1909 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1910 TRACE("Returning surface desc:\n");
1911 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1913 LeaveCriticalSection(&ddraw_cs
);
1917 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
1919 IDirectDrawSurfaceImpl
*surface
= surface_from_surface3(iface
);
1921 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1923 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1925 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
1927 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
1928 return DDERR_INVALIDPARAMS
;
1931 EnterCriticalSection(&ddraw_cs
);
1932 DD_STRUCT_COPY_BYSIZE(surface_desc
, (DDSURFACEDESC
*)&surface
->surface_desc
);
1933 TRACE("Returning surface desc:\n");
1934 if (TRACE_ON(ddraw
))
1936 /* DDRAW_dump_surface_desc handles the smaller size */
1937 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
1940 LeaveCriticalSection(&ddraw_cs
);
1944 /*****************************************************************************
1945 * IDirectDrawSurface7::Initialize
1947 * Initializes the surface. This is a no-op in Wine
1950 * DD: Pointer to an DirectDraw interface
1951 * DDSD: Surface description for initialization
1954 * DDERR_ALREADYINITIALIZED
1956 *****************************************************************************/
1957 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
1958 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
1960 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
1962 return DDERR_ALREADYINITIALIZED
;
1965 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
1966 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
1968 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
1970 return ddraw_surface7_Initialize((IDirectDrawSurface7
*)surface_from_surface3(iface
),
1971 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
1974 /*****************************************************************************
1975 * IDirect3DTexture1::Initialize
1977 * The sdk says it's not implemented
1985 *****************************************************************************/
1986 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
1987 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
1989 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
1991 return DDERR_UNSUPPORTED
; /* Unchecked */
1994 /*****************************************************************************
1995 * IDirectDrawSurface7::IsLost
1997 * Checks if the surface is lost
2000 * DD_OK, if the surface is usable
2001 * DDERR_ISLOST if the surface is lost
2002 * See IWineD3DSurface::IsLost for more details
2004 *****************************************************************************/
2005 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
2007 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2010 TRACE("iface %p.\n", iface
);
2012 EnterCriticalSection(&ddraw_cs
);
2013 /* We lose the surface if the implementation was changed */
2014 if(This
->ImplType
!= This
->ddraw
->ImplType
)
2016 /* But this shouldn't happen. When we change the implementation,
2017 * all surfaces are re-created automatically, and their content
2020 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
2021 LeaveCriticalSection(&ddraw_cs
);
2022 return DDERR_SURFACELOST
;
2025 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
2026 LeaveCriticalSection(&ddraw_cs
);
2029 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
2030 * WineD3D uses the same error for surfaces
2032 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
2037 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
2039 TRACE("iface %p.\n", iface
);
2041 return ddraw_surface7_IsLost((IDirectDrawSurface7
*)surface_from_surface3(iface
));
2044 /*****************************************************************************
2045 * IDirectDrawSurface7::Restore
2047 * Restores a lost surface. This makes the surface usable again, but
2048 * doesn't reload its old contents
2052 * See IWineD3DSurface::Restore for more details
2054 *****************************************************************************/
2055 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
2057 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2060 TRACE("iface %p.\n", iface
);
2062 EnterCriticalSection(&ddraw_cs
);
2063 if(This
->ImplType
!= This
->ddraw
->ImplType
)
2065 /* Call the recreation callback. Make sure to AddRef first */
2066 IDirectDrawSurface_AddRef(iface
);
2067 ddraw_recreate_surfaces_cb(iface
, &This
->surface_desc
, NULL
/* Not needed */);
2069 hr
= IWineD3DSurface_Restore(This
->WineD3DSurface
);
2070 LeaveCriticalSection(&ddraw_cs
);
2074 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
2076 TRACE("iface %p.\n", iface
);
2078 return ddraw_surface7_Restore((IDirectDrawSurface7
*)surface_from_surface3(iface
));
2081 /*****************************************************************************
2082 * IDirectDrawSurface7::SetOverlayPosition
2084 * Changes the display coordinates of an overlay surface
2091 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
2092 *****************************************************************************/
2093 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
2095 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2098 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
2100 EnterCriticalSection(&ddraw_cs
);
2101 hr
= IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
2104 LeaveCriticalSection(&ddraw_cs
);
2108 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
2110 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
2112 return ddraw_surface7_SetOverlayPosition((IDirectDrawSurface7
*)surface_from_surface3(iface
), x
, y
);
2115 /*****************************************************************************
2116 * IDirectDrawSurface7::UpdateOverlay
2118 * Modifies the attributes of an overlay surface.
2121 * SrcRect: The section of the source being used for the overlay
2122 * DstSurface: Address of the surface that is overlaid
2123 * DstRect: Place of the overlay
2124 * Flags: some DDOVER_* flags
2127 * DDERR_UNSUPPORTED, because we don't support overlays
2129 *****************************************************************************/
2130 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
2131 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
2133 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2134 IDirectDrawSurfaceImpl
*Dst
= (IDirectDrawSurfaceImpl
*)DstSurface
;
2137 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
2138 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
2140 EnterCriticalSection(&ddraw_cs
);
2141 hr
= IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
2143 Dst
? Dst
->WineD3DSurface
: NULL
,
2146 (WINEDDOVERLAYFX
*) FX
);
2147 LeaveCriticalSection(&ddraw_cs
);
2149 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2150 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
2151 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
2157 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
2158 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
2160 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
2161 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
2163 return ddraw_surface7_UpdateOverlay((IDirectDrawSurface7
*)surface_from_surface3(iface
), src_rect
,
2164 dst_surface
? (IDirectDrawSurface7
*)surface_from_surface3(dst_surface
) : NULL
, dst_rect
, flags
, fx
);
2167 /*****************************************************************************
2168 * IDirectDrawSurface7::UpdateOverlayDisplay
2170 * The DX7 sdk says that it's not implemented
2175 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
2177 *****************************************************************************/
2178 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
2180 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2182 return DDERR_UNSUPPORTED
;
2185 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
2187 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2189 return ddraw_surface7_UpdateOverlayDisplay((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
2192 /*****************************************************************************
2193 * IDirectDrawSurface7::UpdateOverlayZOrder
2195 * Sets an overlay's Z order
2198 * Flags: DDOVERZ_* flags
2199 * DDSRef: Defines the relative position in the overlay chain
2202 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
2204 *****************************************************************************/
2205 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
2206 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
2208 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2209 IDirectDrawSurfaceImpl
*Ref
= (IDirectDrawSurfaceImpl
*)DDSRef
;
2212 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
2214 EnterCriticalSection(&ddraw_cs
);
2215 hr
= IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
2217 Ref
? Ref
->WineD3DSurface
: NULL
);
2218 LeaveCriticalSection(&ddraw_cs
);
2222 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
2223 DWORD flags
, IDirectDrawSurface3
*reference
)
2225 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
2227 return ddraw_surface7_UpdateOverlayZOrder((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
,
2228 reference
? (IDirectDrawSurface7
*)surface_from_surface3(reference
) : NULL
);
2231 /*****************************************************************************
2232 * IDirectDrawSurface7::GetDDInterface
2234 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
2235 * surface belongs to
2238 * DD: Address to write the interface pointer to
2242 * DDERR_INVALIDPARAMS if DD is NULL
2244 *****************************************************************************/
2245 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
2247 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2249 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
2252 return DDERR_INVALIDPARAMS
;
2254 switch(This
->version
)
2257 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
2261 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
2265 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
2269 *DD
= &This
->ddraw
->IDirectDraw_iface
;
2273 IUnknown_AddRef((IUnknown
*)*DD
);
2278 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
2280 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
2282 return ddraw_surface7_GetDDInterface((IDirectDrawSurface7
*)surface_from_surface3(iface
), ddraw
);
2285 /* This seems also windows implementation specific - I don't think WineD3D needs this */
2286 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
2288 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2289 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
2291 TRACE("iface %p.\n", iface
);
2293 EnterCriticalSection(&ddraw_cs
);
2294 /* A uniqueness value of 0 is apparently special.
2295 * This needs to be checked.
2296 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
2299 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
2300 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
2302 if (old_uniqueness_value
== 0) break;
2303 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
2305 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
2306 old_uniqueness_value
,
2307 new_uniqueness_value
)
2308 == old_uniqueness_value
)
2312 LeaveCriticalSection(&ddraw_cs
);
2316 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
2318 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2320 TRACE("iface %p, value %p.\n", iface
, pValue
);
2322 EnterCriticalSection(&ddraw_cs
);
2323 *pValue
= This
->uniqueness_value
;
2324 LeaveCriticalSection(&ddraw_cs
);
2328 /*****************************************************************************
2329 * IDirectDrawSurface7::SetLOD
2331 * Sets the level of detail of a texture
2334 * MaxLOD: LOD to set
2338 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2340 *****************************************************************************/
2341 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
2343 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2346 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
2348 EnterCriticalSection(&ddraw_cs
);
2349 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2351 LeaveCriticalSection(&ddraw_cs
);
2352 return DDERR_INVALIDOBJECT
;
2355 if(!This
->wineD3DTexture
)
2357 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
2358 LeaveCriticalSection(&ddraw_cs
);
2359 return DDERR_INVALIDOBJECT
;
2362 hr
= IWineD3DBaseTexture_SetLOD(This
->wineD3DTexture
,
2364 LeaveCriticalSection(&ddraw_cs
);
2368 /*****************************************************************************
2369 * IDirectDrawSurface7::GetLOD
2371 * Returns the level of detail of a Direct3D texture
2374 * MaxLOD: Address to write the LOD to
2378 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2379 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2381 *****************************************************************************/
2382 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
2384 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2386 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
2389 return DDERR_INVALIDPARAMS
;
2391 EnterCriticalSection(&ddraw_cs
);
2392 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2394 LeaveCriticalSection(&ddraw_cs
);
2395 return DDERR_INVALIDOBJECT
;
2398 *MaxLOD
= IWineD3DBaseTexture_GetLOD(This
->wineD3DTexture
);
2399 LeaveCriticalSection(&ddraw_cs
);
2403 /*****************************************************************************
2404 * IDirectDrawSurface7::BltFast
2406 * Performs a fast Blit.
2409 * dstx: The x coordinate to blit to on the destination
2410 * dsty: The y coordinate to blit to on the destination
2411 * Source: The source surface
2412 * rsrc: The source rectangle
2413 * trans: Type of transfer. Some DDBLTFAST_* flags
2417 * For more details, see IWineD3DSurface::BltFast
2419 *****************************************************************************/
2420 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
2421 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
2423 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2424 IDirectDrawSurfaceImpl
*src
= (IDirectDrawSurfaceImpl
*)Source
;
2425 DWORD src_w
, src_h
, dst_w
, dst_h
;
2428 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
2429 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
2431 dst_w
= This
->surface_desc
.dwWidth
;
2432 dst_h
= This
->surface_desc
.dwHeight
;
2434 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2439 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
2440 rsrc
->right
> src
->surface_desc
.dwWidth
||
2441 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
2443 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2444 return DDERR_INVALIDRECT
;
2447 src_w
= rsrc
->right
- rsrc
->left
;
2448 src_h
= rsrc
->bottom
- rsrc
->top
;
2452 src_w
= src
->surface_desc
.dwWidth
;
2453 src_h
= src
->surface_desc
.dwHeight
;
2456 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
2457 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
2459 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
2460 return DDERR_INVALIDRECT
;
2463 EnterCriticalSection(&ddraw_cs
);
2464 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
2466 src
? src
->WineD3DSurface
: NULL
,
2469 LeaveCriticalSection(&ddraw_cs
);
2472 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
2473 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
2478 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
2479 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
2481 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
2482 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
2484 return ddraw_surface7_BltFast((IDirectDrawSurface7
*)surface_from_surface3(iface
), dst_x
, dst_y
,
2485 src_surface
? (IDirectDrawSurface7
*)surface_from_surface3(src_surface
) : NULL
, src_rect
, flags
);
2488 /*****************************************************************************
2489 * IDirectDrawSurface7::GetClipper
2491 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2495 * Clipper: Address to store the interface pointer at
2499 * DDERR_INVALIDPARAMS if Clipper is NULL
2500 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2502 *****************************************************************************/
2503 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
2505 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2507 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
2511 LeaveCriticalSection(&ddraw_cs
);
2512 return DDERR_INVALIDPARAMS
;
2515 EnterCriticalSection(&ddraw_cs
);
2516 if(This
->clipper
== NULL
)
2518 LeaveCriticalSection(&ddraw_cs
);
2519 return DDERR_NOCLIPPERATTACHED
;
2522 *Clipper
= (IDirectDrawClipper
*)This
->clipper
;
2523 IDirectDrawClipper_AddRef(*Clipper
);
2524 LeaveCriticalSection(&ddraw_cs
);
2528 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
2530 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
2532 return ddraw_surface7_GetClipper((IDirectDrawSurface7
*)surface_from_surface3(iface
), clipper
);
2535 /*****************************************************************************
2536 * IDirectDrawSurface7::SetClipper
2538 * Sets a clipper for the surface
2541 * Clipper: IDirectDrawClipper interface of the clipper to set
2546 *****************************************************************************/
2547 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
*Clipper
)
2549 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2550 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
2554 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
2556 EnterCriticalSection(&ddraw_cs
);
2557 if ((IDirectDrawClipperImpl
*)Clipper
== This
->clipper
)
2559 LeaveCriticalSection(&ddraw_cs
);
2563 This
->clipper
= (IDirectDrawClipperImpl
*)Clipper
;
2565 if (Clipper
!= NULL
)
2566 IDirectDrawClipper_AddRef(Clipper
);
2568 IDirectDrawClipper_Release((IDirectDrawClipper
*)oldClipper
);
2570 hr
= IWineD3DSurface_SetClipper(This
->WineD3DSurface
, This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
2572 if(This
->wineD3DSwapChain
) {
2575 IDirectDrawClipper_GetHWnd(Clipper
, &clipWindow
);
2579 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2582 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2583 This
->ddraw
->d3d_window
);
2587 LeaveCriticalSection(&ddraw_cs
);
2591 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
2593 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
2595 return ddraw_surface7_SetClipper((IDirectDrawSurface7
*)surface_from_surface3(iface
), clipper
);
2598 /*****************************************************************************
2599 * IDirectDrawSurface7::SetSurfaceDesc
2601 * Sets the surface description. It can override the pixel format, the surface
2603 * It's not really tested.
2606 * DDSD: Pointer to the new surface description to set
2611 * DDERR_INVALIDPARAMS if DDSD is NULL
2613 *****************************************************************************/
2614 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
2616 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2617 enum wined3d_format_id newFormat
= WINED3DFMT_UNKNOWN
;
2620 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
2623 return DDERR_INVALIDPARAMS
;
2625 EnterCriticalSection(&ddraw_cs
);
2626 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2628 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2630 if(newFormat
== WINED3DFMT_UNKNOWN
)
2632 ERR("Requested to set an unknown pixelformat\n");
2633 LeaveCriticalSection(&ddraw_cs
);
2634 return DDERR_INVALIDPARAMS
;
2636 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2638 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2642 LeaveCriticalSection(&ddraw_cs
);
2647 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2649 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2651 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2653 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2655 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2657 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2659 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2661 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2663 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2665 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2667 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2669 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2671 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
2673 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2674 if(hr
!= WINED3D_OK
)
2676 /* No need for a trace here, wined3d does that for us */
2679 case WINED3DERR_INVALIDCALL
:
2680 LeaveCriticalSection(&ddraw_cs
);
2681 return DDERR_INVALIDPARAMS
;
2688 This
->surface_desc
= *DDSD
;
2690 LeaveCriticalSection(&ddraw_cs
);
2694 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
2695 DDSURFACEDESC
*surface_desc
, DWORD flags
)
2697 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
2699 return ddraw_surface7_SetSurfaceDesc((IDirectDrawSurface7
*)surface_from_surface3(iface
),
2700 (DDSURFACEDESC2
*)surface_desc
, flags
);
2703 /*****************************************************************************
2704 * IDirectDrawSurface7::GetPalette
2706 * Returns the IDirectDrawPalette interface of the palette currently assigned
2710 * Pal: Address to write the interface pointer to
2714 * DDERR_INVALIDPARAMS if Pal is NULL
2716 *****************************************************************************/
2717 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
2719 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2720 struct wined3d_palette
*wined3d_palette
;
2723 TRACE("iface %p, palette %p.\n", iface
, Pal
);
2726 return DDERR_INVALIDPARAMS
;
2728 EnterCriticalSection(&ddraw_cs
);
2729 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wined3d_palette
);
2732 LeaveCriticalSection(&ddraw_cs
);
2736 if (wined3d_palette
)
2738 *Pal
= wined3d_palette_get_parent(wined3d_palette
);
2739 IDirectDrawPalette_AddRef(*Pal
);
2744 hr
= DDERR_NOPALETTEATTACHED
;
2747 LeaveCriticalSection(&ddraw_cs
);
2751 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
2753 TRACE("iface %p, palette %p.\n", iface
, palette
);
2755 return ddraw_surface7_GetPalette((IDirectDrawSurface7
*)surface_from_surface3(iface
), palette
);
2758 /*****************************************************************************
2761 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2762 * recursively in the surface tree
2764 *****************************************************************************/
2768 WINEDDCOLORKEY
*CKey
;
2772 static HRESULT WINAPI
2773 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2774 DDSURFACEDESC2
*desc
,
2777 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)surface
;
2778 struct SCKContext
*ctx
= context
;
2781 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2786 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2790 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
2791 ddraw_surface7_Release(surface
);
2793 return DDENUMRET_OK
;
2796 /*****************************************************************************
2797 * IDirectDrawSurface7::SetColorKey
2799 * Sets the color keying options for the surface. Observations showed that
2800 * in case of complex surfaces the color key has to be assigned to all
2805 * CKey: The new color key
2809 * See IWineD3DSurface::SetColorKey for details
2811 *****************************************************************************/
2812 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2814 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2815 DDCOLORKEY FixedCKey
;
2816 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) (CKey
? &FixedCKey
: NULL
), Flags
};
2818 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2820 EnterCriticalSection(&ddraw_cs
);
2824 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
2825 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
2826 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
2828 switch (Flags
& ~DDCKEY_COLORSPACE
)
2830 case DDCKEY_DESTBLT
:
2831 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
2832 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2835 case DDCKEY_DESTOVERLAY
:
2836 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
2837 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2840 case DDCKEY_SRCOVERLAY
:
2841 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
2842 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2846 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
2847 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2851 LeaveCriticalSection(&ddraw_cs
);
2852 return DDERR_INVALIDPARAMS
;
2857 switch (Flags
& ~DDCKEY_COLORSPACE
)
2859 case DDCKEY_DESTBLT
:
2860 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2863 case DDCKEY_DESTOVERLAY
:
2864 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2867 case DDCKEY_SRCOVERLAY
:
2868 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2872 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2876 LeaveCriticalSection(&ddraw_cs
);
2877 return DDERR_INVALIDPARAMS
;
2880 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
, Flags
, ctx
.CKey
);
2881 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
2882 LeaveCriticalSection(&ddraw_cs
);
2885 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2886 default: return ctx
.ret
;
2890 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2892 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2894 return ddraw_surface7_SetColorKey((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
, color_key
);
2897 /*****************************************************************************
2898 * IDirectDrawSurface7::SetPalette
2900 * Assigns a DirectDrawPalette object to the surface
2903 * Pal: Interface to the palette to set
2908 *****************************************************************************/
2909 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
2911 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2912 IDirectDrawPalette
*oldPal
;
2913 IDirectDrawSurfaceImpl
*surf
;
2914 IDirectDrawPaletteImpl
*PalImpl
= (IDirectDrawPaletteImpl
*)Pal
;
2917 TRACE("iface %p, palette %p.\n", iface
, Pal
);
2919 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
2920 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
2921 return DDERR_INVALIDPIXELFORMAT
;
2924 /* Find the old palette */
2925 EnterCriticalSection(&ddraw_cs
);
2926 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2927 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
2929 LeaveCriticalSection(&ddraw_cs
);
2932 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2934 /* Set the new Palette */
2935 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2936 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2937 /* AddRef the Palette */
2938 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2940 /* Release the old palette */
2941 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2943 /* If this is a front buffer, also update the back buffers
2944 * TODO: How do things work for palettized cube textures?
2946 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2948 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2949 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2954 IDirectDrawSurface7
*attach
;
2956 hr
= ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7
*)surf
, &caps2
, &attach
);
2962 TRACE("Setting palette on %p\n", attach
);
2963 ddraw_surface7_SetPalette(attach
, Pal
);
2964 surf
= (IDirectDrawSurfaceImpl
*)attach
;
2965 ddraw_surface7_Release(attach
);
2969 LeaveCriticalSection(&ddraw_cs
);
2973 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
2975 TRACE("iface %p, palette %p.\n", iface
, palette
);
2977 return ddraw_surface7_SetPalette((IDirectDrawSurface7
*)surface_from_surface3(iface
), palette
);
2980 /**********************************************************
2981 * IDirectDrawGammaControl::GetGammaRamp
2983 * Returns the current gamma ramp for a surface
2987 * gamma_ramp: Address to write the ramp to
2991 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
2993 **********************************************************/
2994 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
2995 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
2997 IDirectDrawSurfaceImpl
*surface
= surface_from_gamma_control(iface
);
2999 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
3003 WARN("Invalid gamma_ramp passed.\n");
3004 return DDERR_INVALIDPARAMS
;
3007 EnterCriticalSection(&ddraw_cs
);
3008 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3010 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */
3011 IWineD3DDevice_GetGammaRamp(surface
->ddraw
->wineD3DDevice
, 0, (WINED3DGAMMARAMP
*)gamma_ramp
);
3015 ERR("Not implemented for non-primary surfaces.\n");
3017 LeaveCriticalSection(&ddraw_cs
);
3022 /**********************************************************
3023 * IDirectDrawGammaControl::SetGammaRamp
3025 * Sets the red, green and blue gamma ramps for
3028 * flags: Can be DDSGR_CALIBRATE to request calibration
3029 * gamma_ramp: Structure containing the new gamma ramp
3033 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
3035 **********************************************************/
3036 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
3037 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
3039 IDirectDrawSurfaceImpl
*surface
= surface_from_gamma_control(iface
);
3041 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
3045 WARN("Invalid gamma_ramp passed.\n");
3046 return DDERR_INVALIDPARAMS
;
3049 EnterCriticalSection(&ddraw_cs
);
3050 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3052 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
3053 IWineD3DDevice_SetGammaRamp(surface
->ddraw
->wineD3DDevice
, 0, flags
, (WINED3DGAMMARAMP
*)gamma_ramp
);
3057 ERR("Not implemented for non-primary surfaces.\n");
3059 LeaveCriticalSection(&ddraw_cs
);
3064 /*****************************************************************************
3065 * IDirect3DTexture2::PaletteChanged
3067 * Informs the texture about a palette change
3070 * start: Start index of the change
3071 * count: The number of changed entries
3074 * D3D_OK, because it's a stub
3076 *****************************************************************************/
3077 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
3079 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
3084 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
3086 IDirectDrawSurfaceImpl
*surface
= surface_from_texture1(iface
);
3088 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
3090 return d3d_texture2_PaletteChanged((IDirect3DTexture2
*)&surface
->IDirect3DTexture2_vtbl
, start
, count
);
3093 /*****************************************************************************
3094 * IDirect3DTexture::Unload
3096 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
3102 *****************************************************************************/
3103 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
3105 WARN("iface %p. Not implemented.\n", iface
);
3107 return DDERR_UNSUPPORTED
;
3110 /*****************************************************************************
3111 * IDirect3DTexture2::GetHandle
3113 * Returns handle for the texture. At the moment, the interface
3114 * to the IWineD3DTexture is used.
3117 * device: Device this handle is assigned to
3118 * handle: Address to store the handle at.
3123 *****************************************************************************/
3124 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
3125 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
3127 IDirectDrawSurfaceImpl
*surface
= surface_from_texture2(iface
);
3129 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
3131 EnterCriticalSection(&ddraw_cs
);
3133 if (!surface
->Handle
)
3135 DWORD h
= ddraw_allocate_handle(&device_from_device2(device
)->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
3136 if (h
== DDRAW_INVALID_HANDLE
)
3138 ERR("Failed to allocate a texture handle.\n");
3139 LeaveCriticalSection(&ddraw_cs
);
3140 return DDERR_OUTOFMEMORY
;
3143 surface
->Handle
= h
+ 1;
3146 TRACE("Returning handle %08x.\n", surface
->Handle
);
3147 *handle
= surface
->Handle
;
3149 LeaveCriticalSection(&ddraw_cs
);
3154 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
3155 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
3157 IDirect3DTexture2
*texture2
= (IDirect3DTexture2
*)&surface_from_texture1(iface
)->IDirect3DTexture2_vtbl
;
3158 IDirect3DDevice2
*device2
= (IDirect3DDevice2
*)&device_from_device1(device
)->IDirect3DDevice2_vtbl
;
3160 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
3162 return d3d_texture2_GetHandle(texture2
, device2
, handle
);
3165 /*****************************************************************************
3166 * get_sub_mimaplevel
3168 * Helper function that returns the next mipmap level
3170 * tex_ptr: Surface of which to return the next level
3172 *****************************************************************************/
3173 static IDirectDrawSurfaceImpl
*get_sub_mimaplevel(IDirectDrawSurfaceImpl
*surface
)
3175 /* Now go down the mipmap chain to the next surface */
3176 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
3177 IDirectDrawSurface7
*next_level
;
3180 hr
= ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7
*)surface
, &mipmap_caps
, &next_level
);
3181 if (FAILED(hr
)) return NULL
;
3183 ddraw_surface7_Release(next_level
);
3185 return (IDirectDrawSurfaceImpl
*)next_level
;
3188 /*****************************************************************************
3189 * IDirect3DTexture2::Load
3191 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
3193 * This function isn't relayed to WineD3D because the whole interface is
3194 * implemented in DDraw only. For speed improvements a implementation which
3195 * takes OpenGL more into account could be placed into WineD3D.
3198 * src_texture: Address of the texture to load
3202 * D3DERR_TEXTURE_LOAD_FAILED.
3204 *****************************************************************************/
3205 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
3207 IDirectDrawSurfaceImpl
*dst_surface
= surface_from_texture2(iface
);
3208 IDirectDrawSurfaceImpl
*src_surface
= surface_from_texture2(src_texture
);
3211 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
3213 if (src_surface
== dst_surface
)
3215 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
3219 EnterCriticalSection(&ddraw_cs
);
3221 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3222 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
3223 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
3225 ERR("Trying to load surfaces with different mip-map counts.\n");
3230 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
3231 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
3232 DDSURFACEDESC
*src_desc
, *dst_desc
;
3234 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
3235 src_surface
, dst_surface
, src_surface
->mipmap_level
);
3237 /* Suppress the ALLOCONLOAD flag */
3238 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
3240 /* Get the palettes */
3241 hr
= IWineD3DSurface_GetPalette(dst_surface
->WineD3DSurface
, &wined3d_dst_pal
);
3244 ERR("Failed to get destination palette, hr %#x.\n", hr
);
3245 LeaveCriticalSection(&ddraw_cs
);
3246 return D3DERR_TEXTURE_LOAD_FAILED
;
3248 if (wined3d_dst_pal
)
3249 dst_pal
= wined3d_palette_get_parent(wined3d_dst_pal
);
3251 hr
= IWineD3DSurface_GetPalette(src_surface
->WineD3DSurface
, &wined3d_src_pal
);
3254 ERR("Failed to get source palette, hr %#x.\n", hr
);
3255 LeaveCriticalSection(&ddraw_cs
);
3256 return D3DERR_TEXTURE_LOAD_FAILED
;
3258 if (wined3d_src_pal
)
3259 src_pal
= wined3d_palette_get_parent(wined3d_src_pal
);
3263 PALETTEENTRY palent
[256];
3267 LeaveCriticalSection(&ddraw_cs
);
3268 return DDERR_NOPALETTEATTACHED
;
3270 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
3271 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
3274 /* Copy one surface on the other */
3275 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
3276 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
3278 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
3280 /* Should also check for same pixel format, u1.lPitch, ... */
3281 ERR("Error in surface sizes.\n");
3282 LeaveCriticalSection(&ddraw_cs
);
3283 return D3DERR_TEXTURE_LOAD_FAILED
;
3287 WINED3DLOCKED_RECT src_rect
, dst_rect
;
3289 /* Copy also the ColorKeying stuff */
3290 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
3292 dst_desc
->dwFlags
|= DDSD_CKSRCBLT
;
3293 dst_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
;
3294 dst_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
;
3297 /* Copy the main memory texture into the surface that corresponds
3298 * to the OpenGL texture object. */
3300 hr
= IWineD3DSurface_Map(src_surface
->WineD3DSurface
, &src_rect
, NULL
, 0);
3303 ERR("Failed to lock source surface, hr %#x.\n", hr
);
3304 LeaveCriticalSection(&ddraw_cs
);
3305 return D3DERR_TEXTURE_LOAD_FAILED
;
3308 hr
= IWineD3DSurface_Map(dst_surface
->WineD3DSurface
, &dst_rect
, NULL
, 0);
3311 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
3312 IWineD3DSurface_Unmap(src_surface
->WineD3DSurface
);
3313 LeaveCriticalSection(&ddraw_cs
);
3314 return D3DERR_TEXTURE_LOAD_FAILED
;
3317 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
3318 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_surface
->surface_desc
.u1
.dwLinearSize
);
3320 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_rect
.Pitch
* src_desc
->dwHeight
);
3322 IWineD3DSurface_Unmap(src_surface
->WineD3DSurface
);
3323 IWineD3DSurface_Unmap(dst_surface
->WineD3DSurface
);
3326 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3327 src_surface
= get_sub_mimaplevel(src_surface
);
3331 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3332 dst_surface
= get_sub_mimaplevel(dst_surface
);
3336 if (!src_surface
|| !dst_surface
)
3338 if (src_surface
!= dst_surface
)
3339 ERR("Loading surface with different mipmap structure.\n");
3344 LeaveCriticalSection(&ddraw_cs
);
3349 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
3351 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
3353 return d3d_texture2_Load((IDirect3DTexture2
*)&surface_from_texture1(iface
)->IDirect3DTexture2_vtbl
,
3354 src_texture
? (IDirect3DTexture2
*)&surface_from_texture1(src_texture
)->IDirect3DTexture2_vtbl
: NULL
);
3357 /*****************************************************************************
3359 *****************************************************************************/
3361 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
3364 ddraw_surface7_QueryInterface
,
3365 ddraw_surface7_AddRef
,
3366 ddraw_surface7_Release
,
3367 /* IDirectDrawSurface */
3368 ddraw_surface7_AddAttachedSurface
,
3369 ddraw_surface7_AddOverlayDirtyRect
,
3371 ddraw_surface7_BltBatch
,
3372 ddraw_surface7_BltFast
,
3373 ddraw_surface7_DeleteAttachedSurface
,
3374 ddraw_surface7_EnumAttachedSurfaces
,
3375 ddraw_surface7_EnumOverlayZOrders
,
3376 ddraw_surface7_Flip
,
3377 ddraw_surface7_GetAttachedSurface
,
3378 ddraw_surface7_GetBltStatus
,
3379 ddraw_surface7_GetCaps
,
3380 ddraw_surface7_GetClipper
,
3381 ddraw_surface7_GetColorKey
,
3382 ddraw_surface7_GetDC
,
3383 ddraw_surface7_GetFlipStatus
,
3384 ddraw_surface7_GetOverlayPosition
,
3385 ddraw_surface7_GetPalette
,
3386 ddraw_surface7_GetPixelFormat
,
3387 ddraw_surface7_GetSurfaceDesc
,
3388 ddraw_surface7_Initialize
,
3389 ddraw_surface7_IsLost
,
3390 ddraw_surface7_Lock
,
3391 ddraw_surface7_ReleaseDC
,
3392 ddraw_surface7_Restore
,
3393 ddraw_surface7_SetClipper
,
3394 ddraw_surface7_SetColorKey
,
3395 ddraw_surface7_SetOverlayPosition
,
3396 ddraw_surface7_SetPalette
,
3397 ddraw_surface7_Unlock
,
3398 ddraw_surface7_UpdateOverlay
,
3399 ddraw_surface7_UpdateOverlayDisplay
,
3400 ddraw_surface7_UpdateOverlayZOrder
,
3401 /* IDirectDrawSurface2 */
3402 ddraw_surface7_GetDDInterface
,
3403 ddraw_surface7_PageLock
,
3404 ddraw_surface7_PageUnlock
,
3405 /* IDirectDrawSurface3 */
3406 ddraw_surface7_SetSurfaceDesc
,
3407 /* IDirectDrawSurface4 */
3408 ddraw_surface7_SetPrivateData
,
3409 ddraw_surface7_GetPrivateData
,
3410 ddraw_surface7_FreePrivateData
,
3411 ddraw_surface7_GetUniquenessValue
,
3412 ddraw_surface7_ChangeUniquenessValue
,
3413 /* IDirectDrawSurface7 */
3414 ddraw_surface7_SetPriority
,
3415 ddraw_surface7_GetPriority
,
3416 ddraw_surface7_SetLOD
,
3417 ddraw_surface7_GetLOD
,
3420 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
3423 ddraw_surface3_QueryInterface
,
3424 ddraw_surface3_AddRef
,
3425 ddraw_surface3_Release
,
3426 /* IDirectDrawSurface */
3427 ddraw_surface3_AddAttachedSurface
,
3428 ddraw_surface3_AddOverlayDirtyRect
,
3430 ddraw_surface3_BltBatch
,
3431 ddraw_surface3_BltFast
,
3432 ddraw_surface3_DeleteAttachedSurface
,
3433 ddraw_surface3_EnumAttachedSurfaces
,
3434 ddraw_surface3_EnumOverlayZOrders
,
3435 ddraw_surface3_Flip
,
3436 ddraw_surface3_GetAttachedSurface
,
3437 ddraw_surface3_GetBltStatus
,
3438 ddraw_surface3_GetCaps
,
3439 ddraw_surface3_GetClipper
,
3440 ddraw_surface3_GetColorKey
,
3441 ddraw_surface3_GetDC
,
3442 ddraw_surface3_GetFlipStatus
,
3443 ddraw_surface3_GetOverlayPosition
,
3444 ddraw_surface3_GetPalette
,
3445 ddraw_surface3_GetPixelFormat
,
3446 ddraw_surface3_GetSurfaceDesc
,
3447 ddraw_surface3_Initialize
,
3448 ddraw_surface3_IsLost
,
3449 ddraw_surface3_Lock
,
3450 ddraw_surface3_ReleaseDC
,
3451 ddraw_surface3_Restore
,
3452 ddraw_surface3_SetClipper
,
3453 ddraw_surface3_SetColorKey
,
3454 ddraw_surface3_SetOverlayPosition
,
3455 ddraw_surface3_SetPalette
,
3456 ddraw_surface3_Unlock
,
3457 ddraw_surface3_UpdateOverlay
,
3458 ddraw_surface3_UpdateOverlayDisplay
,
3459 ddraw_surface3_UpdateOverlayZOrder
,
3460 /* IDirectDrawSurface2 */
3461 ddraw_surface3_GetDDInterface
,
3462 ddraw_surface3_PageLock
,
3463 ddraw_surface3_PageUnlock
,
3464 /* IDirectDrawSurface3 */
3465 ddraw_surface3_SetSurfaceDesc
,
3468 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
3470 ddraw_gamma_control_QueryInterface
,
3471 ddraw_gamma_control_AddRef
,
3472 ddraw_gamma_control_Release
,
3473 ddraw_gamma_control_GetGammaRamp
,
3474 ddraw_gamma_control_SetGammaRamp
,
3477 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
3479 d3d_texture2_QueryInterface
,
3480 d3d_texture2_AddRef
,
3481 d3d_texture2_Release
,
3482 d3d_texture2_GetHandle
,
3483 d3d_texture2_PaletteChanged
,
3487 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
3489 d3d_texture1_QueryInterface
,
3490 d3d_texture1_AddRef
,
3491 d3d_texture1_Release
,
3492 d3d_texture1_Initialize
,
3493 d3d_texture1_GetHandle
,
3494 d3d_texture1_PaletteChanged
,
3496 d3d_texture1_Unload
,
3499 HRESULT
ddraw_surface_init(IDirectDrawSurfaceImpl
*surface
, IDirectDrawImpl
*ddraw
,
3500 DDSURFACEDESC2
*desc
, UINT mip_level
, WINED3DSURFTYPE surface_type
)
3502 struct wined3d_resource_desc wined3d_desc
;
3503 struct wined3d_resource
*wined3d_resource
;
3504 WINED3DPOOL pool
= WINED3DPOOL_DEFAULT
;
3505 enum wined3d_format_id format
;
3509 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
3510 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3511 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)))
3513 /* Tests show surfaces without memory flags get these flags added
3514 * right after creation. */
3515 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
3518 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3520 usage
|= WINED3DUSAGE_RENDERTARGET
;
3521 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
3524 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
3526 usage
|= WINED3DUSAGE_RENDERTARGET
;
3529 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
3531 usage
|= WINED3DUSAGE_OVERLAY
;
3534 if (ddraw
->depthstencil
|| (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
3536 /* The depth stencil creation callback sets this flag. Set the
3537 * wined3d usage to let it know it's a depth/stencil surface. */
3538 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
3541 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
3543 pool
= WINED3DPOOL_SYSTEMMEM
;
3545 else if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
3547 pool
= WINED3DPOOL_MANAGED
;
3548 /* Managed textures have the system memory flag set. */
3549 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
3551 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
3553 /* Videomemory adds localvidmem. This is mutually exclusive with
3554 * systemmemory and texturemanage. */
3555 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
3558 format
= PixelFormat_DD2WineD3D(&desc
->u4
.ddpfPixelFormat
);
3559 if (format
== WINED3DFMT_UNKNOWN
)
3561 WARN("Unsupported / unknown pixelformat.\n");
3562 return DDERR_INVALIDPIXELFORMAT
;
3565 surface
->lpVtbl
= &ddraw_surface7_vtbl
;
3566 surface
->IDirectDrawSurface3_vtbl
= &ddraw_surface3_vtbl
;
3567 surface
->IDirectDrawGammaControl_vtbl
= &ddraw_gamma_control_vtbl
;
3568 surface
->IDirect3DTexture2_vtbl
= &d3d_texture2_vtbl
;
3569 surface
->IDirect3DTexture_vtbl
= &d3d_texture1_vtbl
;
3571 surface
->version
= 7;
3572 surface
->ddraw
= ddraw
;
3574 surface
->surface_desc
.dwSize
= sizeof(DDSURFACEDESC2
);
3575 surface
->surface_desc
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
3576 DD_STRUCT_COPY_BYSIZE(&surface
->surface_desc
, desc
);
3578 surface
->first_attached
= surface
;
3579 surface
->ImplType
= surface_type
;
3581 hr
= IWineD3DDevice_CreateSurface(ddraw
->wineD3DDevice
, desc
->dwWidth
, desc
->dwHeight
, format
,
3582 TRUE
/* Lockable */, FALSE
/* Discard */, mip_level
, usage
, pool
,
3583 WINED3DMULTISAMPLE_NONE
, 0 /* MultiSampleQuality */, surface_type
, surface
,
3584 &ddraw_null_wined3d_parent_ops
, &surface
->WineD3DSurface
);
3587 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
3591 surface
->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
3592 wined3d_resource
= IWineD3DSurface_GetResource(surface
->WineD3DSurface
);
3593 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
3595 format
= wined3d_desc
.format
;
3596 if (format
== WINED3DFMT_UNKNOWN
)
3598 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN.\n");
3600 PixelFormat_WineD3DtoDD(&surface
->surface_desc
.u4
.ddpfPixelFormat
, format
);
3602 /* Anno 1602 stores the pitch right after surface creation, so make sure
3603 * it's there. TODO: Test other fourcc formats. */
3604 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
3605 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
3607 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
3608 if (format
== WINED3DFMT_DXT1
)
3610 surface
->surface_desc
.u1
.dwLinearSize
= max(4, wined3d_desc
.width
) * max(4, wined3d_desc
.height
) / 2;
3614 surface
->surface_desc
.u1
.dwLinearSize
= max(4, wined3d_desc
.width
) * max(4, wined3d_desc
.height
);
3619 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
3620 surface
->surface_desc
.u1
.lPitch
= IWineD3DSurface_GetPitch(surface
->WineD3DSurface
);
3623 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
3625 IWineD3DSurface_SetColorKey(surface
->WineD3DSurface
,
3626 DDCKEY_DESTOVERLAY
, (WINEDDCOLORKEY
*)&desc
->u3
.ddckCKDestOverlay
);
3628 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
3630 IWineD3DSurface_SetColorKey(surface
->WineD3DSurface
,
3631 DDCKEY_DESTBLT
, (WINEDDCOLORKEY
*)&desc
->ddckCKDestBlt
);
3633 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
3635 IWineD3DSurface_SetColorKey(surface
->WineD3DSurface
,
3636 DDCKEY_SRCOVERLAY
, (WINEDDCOLORKEY
*)&desc
->ddckCKSrcOverlay
);
3638 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
3640 IWineD3DSurface_SetColorKey(surface
->WineD3DSurface
,
3641 DDCKEY_SRCBLT
, (WINEDDCOLORKEY
*)&desc
->ddckCKSrcBlt
);
3643 if (desc
->dwFlags
& DDSD_LPSURFACE
)
3645 hr
= IWineD3DSurface_SetMem(surface
->WineD3DSurface
, desc
->lpSurface
);
3648 ERR("Failed to set surface memory, hr %#x.\n", hr
);
3649 IWineD3DSurface_Release(surface
->WineD3DSurface
);