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
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This file contains the (internal) driver registration functions,
10 * driver enumeration APIs and DirectDraw creation functions.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
30 #include "ddraw_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
34 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
35 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
37 static inline IDirectDrawSurfaceImpl
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
39 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawGammaControl_iface
);
42 /*****************************************************************************
43 * IUnknown parts follow
44 *****************************************************************************/
46 /*****************************************************************************
47 * IDirectDrawSurface7::QueryInterface
49 * A normal QueryInterface implementation. For QueryInterface rules
50 * see ddraw.c, IDirectDraw7::QueryInterface. This method
51 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
52 * in all versions, the IDirectDrawGammaControl interface and it can
53 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
56 * riid: The interface id queried for
57 * obj: Address to write the pointer to
61 * E_NOINTERFACE if the requested interface wasn't found
63 *****************************************************************************/
64 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
66 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
68 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
70 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
74 return DDERR_INVALIDPARAMS
;
76 if (IsEqualGUID(riid
, &IID_IUnknown
)
77 || IsEqualGUID(riid
, &IID_IDirectDrawSurface7
) )
79 IDirectDrawSurface7_AddRef(iface
);
81 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
84 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
86 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
87 *obj
= &This
->IDirectDrawSurface4_iface
;
88 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
91 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
93 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
94 *obj
= &This
->IDirectDrawSurface3_iface
;
95 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
98 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
100 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
101 *obj
= &This
->IDirectDrawSurface2_iface
;
102 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
105 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
))
107 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
108 *obj
= &This
->IDirectDrawSurface_iface
;
109 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
112 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
114 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
115 *obj
= &This
->IDirectDrawGammaControl_iface
;
116 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
119 else if( IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
) ||
120 IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)||
121 IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
) )
123 IDirect3DDevice7
*d3d
;
125 /* Call into IDirect3D7 for creation */
126 IDirect3D7_CreateDevice(&This
->ddraw
->IDirect3D7_iface
, riid
, &This
->IDirectDrawSurface7_iface
,
131 *obj
= (IDirect3DDevice
*)&((IDirect3DDeviceImpl
*)d3d
)->IDirect3DDevice_vtbl
;
132 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
136 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
137 return E_NOINTERFACE
;
139 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
140 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
142 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
144 *obj
= &This
->IDirect3DTexture_iface
;
145 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
149 *obj
= &This
->IDirect3DTexture2_iface
;
150 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
152 IUnknown_AddRef( (IUnknown
*) *obj
);
156 ERR("No interface\n");
157 return E_NOINTERFACE
;
160 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
162 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
163 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
165 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
168 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
170 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
171 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
173 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
176 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
178 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
179 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
181 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
184 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
186 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
187 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
189 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
192 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
193 REFIID riid
, void **object
)
195 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawGammaControl(iface
);
197 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
199 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
202 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
204 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture2(iface
);
205 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
207 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
210 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
212 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
213 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
215 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
218 static void ddraw_surface_add_iface(IDirectDrawSurfaceImpl
*This
)
220 ULONG iface_count
= InterlockedIncrement(&This
->iface_count
);
221 TRACE("%p increasing iface count to %u.\n", This
, iface_count
);
223 if (iface_count
== 1)
225 EnterCriticalSection(&ddraw_cs
);
226 if (This
->wined3d_surface
)
227 wined3d_surface_incref(This
->wined3d_surface
);
228 if (This
->wined3d_texture
)
229 wined3d_texture_incref(This
->wined3d_texture
);
230 LeaveCriticalSection(&ddraw_cs
);
234 /*****************************************************************************
235 * IDirectDrawSurface7::AddRef
237 * A normal addref implementation
242 *****************************************************************************/
243 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
245 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
246 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
248 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
252 ddraw_surface_add_iface(This
);
258 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
260 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
261 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
263 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
267 ddraw_surface_add_iface(This
);
273 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
275 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
276 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
278 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
282 ddraw_surface_add_iface(This
);
288 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
290 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
291 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
293 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
297 ddraw_surface_add_iface(This
);
303 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
305 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
306 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
308 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
312 ddraw_surface_add_iface(This
);
318 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
320 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawGammaControl(iface
);
321 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
323 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
327 ddraw_surface_add_iface(This
);
333 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
335 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture2(iface
);
336 TRACE("iface %p.\n", iface
);
338 return ddraw_surface1_AddRef(&This
->IDirectDrawSurface_iface
);
341 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
343 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
344 TRACE("iface %p.\n", iface
);
346 return ddraw_surface1_AddRef(&This
->IDirectDrawSurface_iface
);
349 /*****************************************************************************
350 * ddraw_surface_destroy
352 * A helper function for IDirectDrawSurface7::Release
354 * Frees the surface, regardless of its refcount.
355 * See IDirectDrawSurface7::Release for more information
358 * This: Surface to free
360 *****************************************************************************/
361 void ddraw_surface_destroy(IDirectDrawSurfaceImpl
*This
)
363 TRACE("surface %p.\n", This
);
365 /* Check the iface count and give a warning */
366 if(This
->iface_count
> 1)
368 /* This can happen when a complex surface is destroyed,
369 * because the 2nd surface was addref()ed when the app
370 * called GetAttachedSurface
372 WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n",
373 This
, This
->ref7
, This
->ref4
, This
->ref3
, This
->ref2
, This
->ref1
);
376 if (This
->wined3d_surface
)
377 wined3d_surface_decref(This
->wined3d_surface
);
380 static void ddraw_surface_cleanup(IDirectDrawSurfaceImpl
*surface
)
382 IDirectDrawSurfaceImpl
*surf
;
383 IUnknown
*ifaceToRelease
;
386 TRACE("surface %p.\n", surface
);
388 if (surface
->wined3d_swapchain
)
390 IDirectDrawImpl
*ddraw
= surface
->ddraw
;
392 /* If it's the render target, destroy the D3D device. */
393 if (ddraw
->d3d_initialized
&& surface
== ddraw
->d3d_target
)
395 TRACE("Destroying the render target, uninitializing D3D.\n");
397 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
399 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
401 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
402 ddraw
->numConvertedDecls
= 0;
404 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
406 ERR("Failed to uninit 3D.\n");
410 /* Free the d3d window if one was created. */
411 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
413 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
414 DestroyWindow(ddraw
->d3d_window
);
415 ddraw
->d3d_window
= 0;
419 ddraw
->d3d_initialized
= FALSE
;
420 ddraw
->d3d_target
= NULL
;
424 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
427 surface
->wined3d_swapchain
= NULL
;
429 /* Reset to the default surface implementation type. This is needed
430 * if applications use non render target surfaces and expect blits to
431 * work after destroying the render target.
433 * TODO: Recreate existing offscreen surfaces. */
434 ddraw
->ImplType
= DefaultSurfaceType
;
436 TRACE("D3D unloaded.\n");
439 /* The refcount test shows that the palette is detached when the surface
441 IDirectDrawSurface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, NULL
);
443 /* Loop through all complex attached surfaces and destroy them.
445 * Yet again, only the root can have more than one complexly attached
446 * surface, all the others have a total of one. */
447 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
449 if (!surface
->complex_array
[i
])
452 surf
= surface
->complex_array
[i
];
453 surface
->complex_array
[i
] = NULL
;
456 IDirectDrawSurfaceImpl
*destroy
= surf
;
457 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
458 ddraw_surface_destroy(destroy
); /* Destroy it */
462 ifaceToRelease
= surface
->ifaceToRelease
;
464 /* Destroy the root surface. */
465 ddraw_surface_destroy(surface
);
467 /* Reduce the ddraw refcount */
469 IUnknown_Release(ifaceToRelease
);
472 ULONG
ddraw_surface_release_iface(IDirectDrawSurfaceImpl
*This
)
474 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
475 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
477 if (iface_count
== 0)
479 /* Complex attached surfaces are destroyed implicitly when the root is released */
480 EnterCriticalSection(&ddraw_cs
);
481 if(!This
->is_complex_root
)
483 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
484 LeaveCriticalSection(&ddraw_cs
);
487 if (This
->wined3d_texture
) /* If it's a texture, destroy the wined3d texture. */
488 wined3d_texture_decref(This
->wined3d_texture
);
490 ddraw_surface_cleanup(This
);
491 LeaveCriticalSection(&ddraw_cs
);
497 /*****************************************************************************
498 * IDirectDrawSurface7::Release
500 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
501 * surface is destroyed.
503 * Destroying the surface is a bit tricky. For the connection between
504 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
505 * It has a nice graph explaining the connection.
507 * What happens here is basically this:
508 * When a surface is destroyed, its WineD3DSurface is released,
509 * and the refcount of the DirectDraw interface is reduced by 1. If it has
510 * complex surfaces attached to it, then these surfaces are destroyed too,
511 * regardless of their refcount. If any surface being destroyed has another
512 * surface attached to it (with a "soft" attachment, not complex), then
513 * this surface is detached with DeleteAttachedSurface.
515 * When the surface is a texture, the WineD3DTexture is released.
516 * If the surface is the Direct3D render target, then the D3D
517 * capabilities of the WineD3DDevice are uninitialized, which causes the
518 * swapchain to be released.
520 * When a complex sublevel falls to ref zero, then this is ignored.
525 *****************************************************************************/
526 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
528 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
529 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
531 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
535 ddraw_surface_release_iface(This
);
541 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
543 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
544 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
546 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
550 ddraw_surface_release_iface(This
);
556 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
558 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
559 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
561 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
565 ddraw_surface_release_iface(This
);
571 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
573 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
574 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
576 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
580 ddraw_surface_release_iface(This
);
586 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
588 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
589 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
591 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
595 ddraw_surface_release_iface(This
);
601 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
603 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawGammaControl(iface
);
604 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
606 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
610 ddraw_surface_release_iface(This
);
616 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
618 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture2(iface
);
619 TRACE("iface %p.\n", iface
);
621 return ddraw_surface1_Release(&This
->IDirectDrawSurface_iface
);
624 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
626 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
627 TRACE("iface %p.\n", iface
);
629 return ddraw_surface1_Release(&This
->IDirectDrawSurface_iface
);
632 /*****************************************************************************
633 * IDirectDrawSurface7::GetAttachedSurface
635 * Returns an attached surface with the requested caps. Surface attachment
636 * and complex surfaces are not clearly described by the MSDN or sdk,
637 * so this method is tricky and likely to contain problems.
638 * This implementation searches the complex list first, then the
641 * The chains are searched from This down to the last surface in the chain,
642 * not from the first element in the chain. The first surface found is
643 * returned. The MSDN says that this method fails if more than one surface
644 * matches the caps, but it is not sure if that is right. The attachment
645 * structure may not even allow two matching surfaces.
647 * The found surface is AddRef-ed before it is returned.
650 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
651 * Surface: Address to store the found surface
655 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
656 * DDERR_NOTFOUND if no surface was found
658 *****************************************************************************/
659 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
660 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
662 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
663 IDirectDrawSurfaceImpl
*surf
;
667 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
669 EnterCriticalSection(&ddraw_cs
);
671 if(This
->version
< 7)
673 /* Earlier dx apps put garbage into these members, clear them */
674 our_caps
.dwCaps
= Caps
->dwCaps
;
675 our_caps
.dwCaps2
= 0;
676 our_caps
.dwCaps3
= 0;
677 our_caps
.dwCaps4
= 0;
684 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 */
686 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
688 surf
= This
->complex_array
[i
];
693 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
694 surf
->surface_desc
.ddsCaps
.dwCaps
,
695 surf
->surface_desc
.ddsCaps
.dwCaps2
,
696 surf
->surface_desc
.ddsCaps
.dwCaps3
,
697 surf
->surface_desc
.ddsCaps
.dwCaps4
);
700 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
701 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
703 /* MSDN: "This method fails if more than one surface is attached
704 * that matches the capabilities requested."
706 * Not sure how to test this.
709 TRACE("(%p): Returning surface %p\n", This
, surf
);
710 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
711 *Surface
= &surf
->IDirectDrawSurface7_iface
;
712 ddraw_surface7_AddRef(*Surface
);
713 LeaveCriticalSection(&ddraw_cs
);
718 /* Next, look at the attachment chain */
721 while( (surf
= surf
->next_attached
) )
725 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
726 surf
->surface_desc
.ddsCaps
.dwCaps
,
727 surf
->surface_desc
.ddsCaps
.dwCaps2
,
728 surf
->surface_desc
.ddsCaps
.dwCaps3
,
729 surf
->surface_desc
.ddsCaps
.dwCaps4
);
732 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
733 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
735 TRACE("(%p): Returning surface %p\n", This
, surf
);
736 *Surface
= &surf
->IDirectDrawSurface7_iface
;
737 ddraw_surface7_AddRef(*Surface
);
738 LeaveCriticalSection(&ddraw_cs
);
743 TRACE("(%p) Didn't find a valid surface\n", This
);
744 LeaveCriticalSection(&ddraw_cs
);
747 return DDERR_NOTFOUND
;
750 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
751 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
753 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
754 IDirectDrawSurface7
*attachment7
;
755 IDirectDrawSurfaceImpl
*attachment_impl
;
758 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
760 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
767 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
768 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
769 ddraw_surface4_AddRef(*attachment
);
770 ddraw_surface7_Release(attachment7
);
775 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
776 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
778 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
779 IDirectDrawSurface7
*attachment7
;
780 IDirectDrawSurfaceImpl
*attachment_impl
;
784 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
786 caps2
.dwCaps
= caps
->dwCaps
;
791 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
792 &caps2
, &attachment7
);
798 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
799 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
800 ddraw_surface3_AddRef(*attachment
);
801 ddraw_surface7_Release(attachment7
);
806 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
807 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
809 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
810 IDirectDrawSurface7
*attachment7
;
811 IDirectDrawSurfaceImpl
*attachment_impl
;
815 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
817 caps2
.dwCaps
= caps
->dwCaps
;
822 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
823 &caps2
, &attachment7
);
829 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
830 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
831 ddraw_surface2_AddRef(*attachment
);
832 ddraw_surface7_Release(attachment7
);
837 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
838 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
840 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
841 IDirectDrawSurface7
*attachment7
;
842 IDirectDrawSurfaceImpl
*attachment_impl
;
846 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
848 caps2
.dwCaps
= caps
->dwCaps
;
853 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
854 &caps2
, &attachment7
);
860 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
861 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
862 ddraw_surface1_AddRef(*attachment
);
863 ddraw_surface7_Release(attachment7
);
868 /*****************************************************************************
869 * IDirectDrawSurface7::Lock
871 * Locks the surface and returns a pointer to the surface's memory
874 * Rect: Rectangle to lock. If NULL, the whole surface is locked
875 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
876 * Flags: Locking flags, e.g Read only or write only
877 * h: An event handle that's not used and must be NULL
881 * DDERR_INVALIDPARAMS if DDSD is NULL
882 * For more details, see IWineD3DSurface::LockRect
884 *****************************************************************************/
885 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
886 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
888 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
889 WINED3DLOCKED_RECT LockedRect
;
892 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
893 iface
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
896 return DDERR_INVALIDPARAMS
;
898 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
899 EnterCriticalSection(&ddraw_cs
);
901 /* Should I check for the handle to be NULL?
903 * The DDLOCK flags and the D3DLOCK flags are equal
904 * for the supported values. The others are ignored by WineD3D
907 if(DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) &&
908 DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
910 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDSD
->dwSize
);
911 LeaveCriticalSection(&ddraw_cs
);
912 return DDERR_INVALIDPARAMS
;
915 /* Windows zeroes this if the rect is invalid */
922 || (Rect
->left
> Rect
->right
)
923 || (Rect
->top
> Rect
->bottom
)
924 || (Rect
->right
> This
->surface_desc
.dwWidth
)
925 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
927 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
928 LeaveCriticalSection(&ddraw_cs
);
929 return DDERR_INVALIDPARAMS
;
933 hr
= wined3d_surface_map(This
->wined3d_surface
, &LockedRect
, Rect
, Flags
);
936 LeaveCriticalSection(&ddraw_cs
);
939 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
940 * specific error. But since IWineD3DSurface::LockRect returns that error in this
941 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
942 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
943 * is much easier to do it in one place in ddraw
945 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
950 /* Override the memory area. The pitch should be set already. Strangely windows
951 * does not set the LPSURFACE flag on locked surfaces !?!.
952 * DDSD->dwFlags |= DDSD_LPSURFACE;
954 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
955 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
957 TRACE("locked surface returning description :\n");
958 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
960 LeaveCriticalSection(&ddraw_cs
);
964 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
965 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
967 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
968 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
969 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
971 return ddraw_surface7_Lock(&This
->IDirectDrawSurface7_iface
,
972 rect
, surface_desc
, flags
, h
);
975 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
976 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
978 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
979 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
980 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
982 return ddraw_surface7_Lock(&This
->IDirectDrawSurface7_iface
,
983 rect
, (DDSURFACEDESC2
*)surface_desc
, flags
, h
);
986 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
987 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
989 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
990 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
991 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
993 return ddraw_surface7_Lock(&This
->IDirectDrawSurface7_iface
,
994 rect
, (DDSURFACEDESC2
*)surface_desc
, flags
, h
);
997 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
998 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1000 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1001 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1002 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1004 return ddraw_surface7_Lock(&This
->IDirectDrawSurface7_iface
,
1005 rect
, (DDSURFACEDESC2
*)surface_desc
, flags
, h
);
1008 /*****************************************************************************
1009 * IDirectDrawSurface7::Unlock
1011 * Unlocks an locked surface
1014 * Rect: Not used by this implementation
1018 * For more details, see IWineD3DSurface::UnlockRect
1020 *****************************************************************************/
1021 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1023 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1026 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1028 EnterCriticalSection(&ddraw_cs
);
1029 hr
= wined3d_surface_unmap(This
->wined3d_surface
);
1032 This
->surface_desc
.lpSurface
= NULL
;
1034 LeaveCriticalSection(&ddraw_cs
);
1038 static HRESULT WINAPI
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1040 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1041 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1043 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, pRect
);
1046 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1048 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1049 TRACE("iface %p, data %p.\n", iface
, data
);
1051 /* data might not be the LPRECT of later versions, so drop it. */
1052 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, NULL
);
1055 static HRESULT WINAPI
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1057 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1058 TRACE("iface %p, data %p.\n", iface
, data
);
1060 /* data might not be the LPRECT of later versions, so drop it. */
1061 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, NULL
);
1064 static HRESULT WINAPI
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1066 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1067 TRACE("iface %p, data %p.\n", iface
, data
);
1069 /* data might not be the LPRECT of later versions, so drop it. */
1070 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, NULL
);
1073 /*****************************************************************************
1074 * IDirectDrawSurface7::Flip
1076 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
1077 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
1078 * the flip target is passed to WineD3D, even if the app didn't specify one
1081 * DestOverride: Specifies the surface that will become the new front
1082 * buffer. If NULL, the current back buffer is used
1083 * Flags: some DirectDraw flags, see include/ddraw.h
1087 * DDERR_NOTFLIPPABLE if no flip target could be found
1088 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
1089 * For more details, see IWineD3DSurface::Flip
1091 *****************************************************************************/
1092 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
1094 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1095 IDirectDrawSurfaceImpl
*Override
= unsafe_impl_from_IDirectDrawSurface7(DestOverride
);
1096 IDirectDrawSurface7
*Override7
;
1099 TRACE("iface %p, dst %p, flags %#x.\n", iface
, DestOverride
, Flags
);
1101 /* Flip has to be called from a front buffer
1102 * What about overlay surfaces, AFAIK they can flip too?
1104 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
1105 return DDERR_INVALIDOBJECT
; /* Unchecked */
1107 EnterCriticalSection(&ddraw_cs
);
1109 /* WineD3D doesn't keep track of attached surface, so find the target */
1114 memset(&Caps
, 0, sizeof(Caps
));
1115 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
1116 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
1119 ERR("Can't find a flip target\n");
1120 LeaveCriticalSection(&ddraw_cs
);
1121 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1123 Override
= impl_from_IDirectDrawSurface7(Override7
);
1125 /* For the GetAttachedSurface */
1126 ddraw_surface7_Release(Override7
);
1129 hr
= wined3d_surface_flip(This
->wined3d_surface
, Override
->wined3d_surface
, Flags
);
1130 LeaveCriticalSection(&ddraw_cs
);
1134 static HRESULT WINAPI
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*dst
, DWORD flags
)
1136 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1137 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1138 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1140 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1141 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1144 static HRESULT WINAPI
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
1146 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1147 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1148 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1150 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1151 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1154 static HRESULT WINAPI
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*dst
, DWORD flags
)
1156 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1157 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1158 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1160 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1161 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1164 static HRESULT WINAPI
ddraw_surface1_Flip(IDirectDrawSurface
*iface
, IDirectDrawSurface
*dst
, DWORD flags
)
1166 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1167 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1168 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1170 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1171 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1174 /*****************************************************************************
1175 * IDirectDrawSurface7::Blt
1177 * Performs a blit on the surface
1180 * DestRect: Destination rectangle, can be NULL
1181 * SrcSurface: Source surface, can be NULL
1182 * SrcRect: Source rectangle, can be NULL
1184 * DDBltFx: Some extended blt parameters, connected to the flags
1188 * See IWineD3DSurface::Blt for more details
1190 *****************************************************************************/
1191 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1192 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1194 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1195 IDirectDrawSurfaceImpl
*Src
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1198 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1199 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1201 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1202 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1204 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1205 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1206 return DDERR_INVALIDPARAMS
;
1209 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1210 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1211 return DDERR_INVALIDPARAMS
;
1214 EnterCriticalSection(&ddraw_cs
);
1216 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
1217 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1218 LeaveCriticalSection(&ddraw_cs
);
1219 return DDERR_INVALIDPARAMS
;
1222 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1223 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1224 * surfaces. So far no blitting operations using surfaces in the bltfx
1225 * struct are supported anyway. */
1226 hr
= wined3d_surface_blt(This
->wined3d_surface
, DestRect
, Src
? Src
->wined3d_surface
: NULL
,
1227 SrcRect
, Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3DTEXF_LINEAR
);
1229 LeaveCriticalSection(&ddraw_cs
);
1232 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1233 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1238 static HRESULT WINAPI
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1239 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1241 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1242 IDirectDrawSurfaceImpl
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1243 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1244 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1246 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1247 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1250 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1251 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1253 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1254 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1255 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1256 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1258 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1259 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1262 static HRESULT WINAPI
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1263 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1265 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1266 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1267 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1268 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1270 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1271 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1274 static HRESULT WINAPI
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1275 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1277 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1278 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1279 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1280 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1282 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1283 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1286 /*****************************************************************************
1287 * IDirectDrawSurface7::AddAttachedSurface
1289 * Attaches a surface to another surface. How the surface attachments work
1290 * is not totally understood yet, and this method is prone to problems.
1291 * he surface that is attached is AddRef-ed.
1293 * Tests with complex surfaces suggest that the surface attachments form a
1294 * tree, but no method to test this has been found yet.
1296 * The attachment list consists of a first surface (first_attached) and
1297 * for each surface a pointer to the next attached surface (next_attached).
1298 * For the first surface, and a surface that has no attachments
1299 * first_attached points to the surface itself. A surface that has
1300 * no successors in the chain has next_attached set to NULL.
1302 * Newly attached surfaces are attached right after the root surface.
1303 * If a surface is attached to a complex surface compound, it's attached to
1304 * the surface that the app requested, not the complex root. See
1305 * GetAttachedSurface for a description how surfaces are found.
1307 * This is how the current implementation works, and it was coded by looking
1308 * at the needs of the applications.
1310 * So far only Z-Buffer attachments are tested, and they are activated in
1311 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1312 * Back buffers should work in 2D mode, but they are not tested(They can be
1313 * attached in older iface versions). Rendering to the front buffer and
1314 * switching between that and double buffering is not yet implemented in
1315 * WineD3D, so for 3D it might have unexpected results.
1317 * ddraw_surface_attach_surface is the real thing,
1318 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1319 * performs additional checks. Version 7 of this interface is much more restrictive
1320 * than its predecessors.
1323 * Attach: Surface to attach to iface
1327 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1329 *****************************************************************************/
1330 static HRESULT
ddraw_surface_attach_surface(IDirectDrawSurfaceImpl
*This
, IDirectDrawSurfaceImpl
*Surf
)
1332 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1335 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1337 EnterCriticalSection(&ddraw_cs
);
1339 /* Check if the surface is already attached somewhere */
1340 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1342 /* TODO: Test for the structure of the manual attachment. Is it a
1343 * chain or a list? What happens if one surface is attached to 2
1344 * different surfaces? */
1345 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1346 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1348 LeaveCriticalSection(&ddraw_cs
);
1349 return DDERR_SURFACEALREADYATTACHED
;
1352 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1353 Surf
->next_attached
= This
->next_attached
;
1354 Surf
->first_attached
= This
->first_attached
;
1355 This
->next_attached
= Surf
;
1357 /* Check if the WineD3D depth stencil needs updating */
1358 if(This
->ddraw
->d3ddevice
)
1360 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1363 LeaveCriticalSection(&ddraw_cs
);
1367 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*Attach
)
1369 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1370 IDirectDrawSurfaceImpl
*Surf
= unsafe_impl_from_IDirectDrawSurface7(Attach
);
1373 TRACE("iface %p, attachment %p.\n", iface
, Attach
);
1375 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1376 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1379 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1380 Surf
->surface_desc
.ddsCaps
.dwCaps
);
1381 return DDERR_CANNOTATTACHSURFACE
;
1384 hr
= ddraw_surface_attach_surface(This
, Surf
);
1389 ddraw_surface7_AddRef(Attach
);
1393 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1395 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1396 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1399 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1401 hr
= ddraw_surface7_AddAttachedSurface(&This
->IDirectDrawSurface7_iface
,
1402 attachment_impl
? &attachment_impl
->IDirectDrawSurface7_iface
: NULL
);
1407 ddraw_surface4_AddRef(attachment
);
1408 ddraw_surface7_Release(&attachment_impl
->IDirectDrawSurface7_iface
);
1411 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1413 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1414 IDirectDrawSurfaceImpl
*attach_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1417 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1419 /* Tests suggest that
1420 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1421 * -> offscreen plain surfaces can be attached to primaries
1422 * -> primaries can be attached to offscreen plain surfaces
1423 * -> z buffers can be attached to primaries */
1424 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1425 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1427 /* Sizes have to match */
1428 if (attach_impl
->surface_desc
.dwWidth
!= This
->surface_desc
.dwWidth
1429 || attach_impl
->surface_desc
.dwHeight
!= This
->surface_desc
.dwHeight
)
1431 WARN("Surface sizes do not match.\n");
1432 return DDERR_CANNOTATTACHSURFACE
;
1436 else if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1437 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1443 WARN("Invalid attachment combination.\n");
1444 return DDERR_CANNOTATTACHSURFACE
;
1447 hr
= ddraw_surface_attach_surface(This
, attach_impl
);
1452 ddraw_surface3_AddRef(attachment
);
1456 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1458 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1459 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1462 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1464 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1465 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1470 ddraw_surface2_AddRef(attachment
);
1471 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1475 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1477 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1478 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1481 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1483 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1484 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1489 ddraw_surface1_AddRef(attachment
);
1490 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1494 /*****************************************************************************
1495 * IDirectDrawSurface7::DeleteAttachedSurface
1497 * Removes a surface from the attachment chain. The surface's refcount
1498 * is decreased by one after it has been removed
1501 * Flags: Some flags, not used by this implementation
1502 * Attach: Surface to detach
1506 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1508 *****************************************************************************/
1509 static HRESULT
ddraw_surface_delete_attached_surface(IDirectDrawSurfaceImpl
*This
,
1510 IDirectDrawSurfaceImpl
*Surf
)
1512 IDirectDrawSurfaceImpl
*Prev
= This
;
1514 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1516 EnterCriticalSection(&ddraw_cs
);
1517 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
1519 LeaveCriticalSection(&ddraw_cs
);
1520 return DDERR_CANNOTDETACHSURFACE
;
1523 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1524 if (This
->surface_desc
.ddsCaps
.dwCaps
&
1525 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1527 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1528 /* FIXME: we should probably also subtract from dwMipMapCount of this
1529 * and all parent surfaces */
1532 /* Find the predecessor of the detached surface */
1535 if(Prev
->next_attached
== Surf
) break;
1536 Prev
= Prev
->next_attached
;
1539 /* There must be a surface, otherwise there's a bug */
1540 assert(Prev
!= NULL
);
1542 /* Unchain the surface */
1543 Prev
->next_attached
= Surf
->next_attached
;
1544 Surf
->next_attached
= NULL
;
1545 Surf
->first_attached
= Surf
;
1547 /* Check if the WineD3D depth stencil needs updating */
1548 if(This
->ddraw
->d3ddevice
)
1550 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1552 LeaveCriticalSection(&ddraw_cs
);
1556 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1557 DWORD flags
, IDirectDrawSurface7
*attachment
)
1559 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1560 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1563 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1565 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1570 ddraw_surface7_Release(attachment
);
1574 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1575 DWORD flags
, IDirectDrawSurface4
*attachment
)
1577 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1578 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1581 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1583 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1588 ddraw_surface4_Release(attachment
);
1592 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1593 DWORD flags
, IDirectDrawSurface3
*attachment
)
1595 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1596 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1598 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1600 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1605 ddraw_surface3_Release(attachment
);
1609 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
1610 DWORD flags
, IDirectDrawSurface2
*attachment
)
1612 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1613 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1615 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1617 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1622 ddraw_surface2_Release(attachment
);
1626 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
1627 DWORD flags
, IDirectDrawSurface
*attachment
)
1629 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1630 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1632 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1634 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1639 ddraw_surface1_Release(attachment
);
1643 /*****************************************************************************
1644 * IDirectDrawSurface7::AddOverlayDirtyRect
1646 * "This method is not currently implemented"
1654 *****************************************************************************/
1655 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1657 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1659 return DDERR_UNSUPPORTED
; /* unchecked */
1662 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
1664 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1665 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1667 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1670 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1672 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1673 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1675 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1678 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
1680 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1681 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1683 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1686 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
1688 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1689 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1691 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1694 /*****************************************************************************
1695 * IDirectDrawSurface7::GetDC
1697 * Returns a GDI device context for the surface
1700 * hdc: Address of a HDC variable to store the dc to
1704 * DDERR_INVALIDPARAMS if hdc is NULL
1705 * For details, see IWineD3DSurface::GetDC
1707 *****************************************************************************/
1708 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1710 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1713 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1716 return DDERR_INVALIDPARAMS
;
1718 EnterCriticalSection(&ddraw_cs
);
1719 hr
= wined3d_surface_getdc(This
->wined3d_surface
, hdc
);
1720 LeaveCriticalSection(&ddraw_cs
);
1723 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1726 case WINED3DERR_INVALIDCALL
:
1727 if(hdc
) *hdc
= NULL
;
1728 return DDERR_INVALIDPARAMS
;
1734 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
1736 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1737 TRACE("iface %p, dc %p.\n", iface
, dc
);
1739 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1742 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1744 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1745 TRACE("iface %p, dc %p.\n", iface
, dc
);
1747 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1750 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
1752 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1753 TRACE("iface %p, dc %p.\n", iface
, dc
);
1755 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1758 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
1760 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1761 TRACE("iface %p, dc %p.\n", iface
, dc
);
1763 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1766 /*****************************************************************************
1767 * IDirectDrawSurface7::ReleaseDC
1769 * Releases the DC that was constructed with GetDC
1772 * hdc: HDC to release
1776 * For more details, see IWineD3DSurface::ReleaseDC
1778 *****************************************************************************/
1779 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
1781 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1784 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1786 EnterCriticalSection(&ddraw_cs
);
1787 hr
= wined3d_surface_releasedc(This
->wined3d_surface
, hdc
);
1788 LeaveCriticalSection(&ddraw_cs
);
1792 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
1794 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1795 TRACE("iface %p, dc %p.\n", iface
, dc
);
1797 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1800 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
1802 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1803 TRACE("iface %p, dc %p.\n", iface
, dc
);
1805 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1808 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
1810 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1811 TRACE("iface %p, dc %p.\n", iface
, dc
);
1813 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1816 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
1818 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1819 TRACE("iface %p, dc %p.\n", iface
, dc
);
1821 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1824 /*****************************************************************************
1825 * IDirectDrawSurface7::GetCaps
1827 * Returns the surface's caps
1830 * Caps: Address to write the caps to
1834 * DDERR_INVALIDPARAMS if Caps is NULL
1836 *****************************************************************************/
1837 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
1839 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1841 TRACE("iface %p, caps %p.\n", iface
, Caps
);
1844 return DDERR_INVALIDPARAMS
;
1846 *Caps
= This
->surface_desc
.ddsCaps
;
1850 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
1852 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1853 TRACE("iface %p, caps %p.\n", iface
, caps
);
1855 return ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, caps
);
1858 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
1860 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1864 TRACE("iface %p, caps %p.\n", iface
, caps
);
1866 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1867 if (FAILED(hr
)) return hr
;
1869 caps
->dwCaps
= caps2
.dwCaps
;
1873 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
1875 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1879 TRACE("iface %p, caps %p.\n", iface
, caps
);
1881 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1882 if (FAILED(hr
)) return hr
;
1884 caps
->dwCaps
= caps2
.dwCaps
;
1888 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
1890 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1894 TRACE("iface %p, caps %p.\n", iface
, caps
);
1896 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1897 if (FAILED(hr
)) return hr
;
1899 caps
->dwCaps
= caps2
.dwCaps
;
1903 /*****************************************************************************
1904 * IDirectDrawSurface7::SetPriority
1906 * Sets a texture priority for managed textures.
1909 * Priority: The new priority
1913 * For more details, see IWineD3DSurface::SetPriority
1915 *****************************************************************************/
1916 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1918 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1921 TRACE("iface %p, priority %u.\n", iface
, Priority
);
1923 EnterCriticalSection(&ddraw_cs
);
1924 hr
= wined3d_surface_set_priority(This
->wined3d_surface
, Priority
);
1925 LeaveCriticalSection(&ddraw_cs
);
1929 /*****************************************************************************
1930 * IDirectDrawSurface7::GetPriority
1932 * Returns the surface's priority
1935 * Priority: Address of a variable to write the priority to
1939 * DDERR_INVALIDPARAMS if Priority == NULL
1940 * For more details, see IWineD3DSurface::GetPriority
1942 *****************************************************************************/
1943 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
1945 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1947 TRACE("iface %p, priority %p.\n", iface
, Priority
);
1951 return DDERR_INVALIDPARAMS
;
1954 EnterCriticalSection(&ddraw_cs
);
1955 *Priority
= wined3d_surface_get_priority(This
->wined3d_surface
);
1956 LeaveCriticalSection(&ddraw_cs
);
1960 /*****************************************************************************
1961 * IDirectDrawSurface7::SetPrivateData
1963 * Stores some data in the surface that is intended for the application's
1967 * tag: GUID that identifies the data
1968 * Data: Pointer to the private data
1969 * Size: Size of the private data
1974 * For more details, see IWineD3DSurface::SetPrivateData
1976 *****************************************************************************/
1977 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
1978 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
1980 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1981 struct wined3d_resource
*resource
;
1984 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
1985 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
1987 EnterCriticalSection(&ddraw_cs
);
1988 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
1989 hr
= wined3d_resource_set_private_data(resource
, tag
, Data
, Size
, Flags
);
1990 LeaveCriticalSection(&ddraw_cs
);
1993 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1998 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
1999 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2001 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2002 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2003 iface
, debugstr_guid(tag
), data
, size
, flags
);
2005 return ddraw_surface7_SetPrivateData(&This
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2008 /*****************************************************************************
2009 * IDirectDrawSurface7::GetPrivateData
2011 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2014 * tag: GUID of the data to return
2015 * Data: Address where to write the data to
2016 * Size: Size of the buffer at Data
2020 * DDERR_INVALIDPARAMS if Data is NULL
2021 * For more details, see IWineD3DSurface::GetPrivateData
2023 *****************************************************************************/
2024 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
2026 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2027 struct wined3d_resource
*resource
;
2030 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2031 iface
, debugstr_guid(tag
), Data
, Size
);
2034 return DDERR_INVALIDPARAMS
;
2036 EnterCriticalSection(&ddraw_cs
);
2037 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2038 hr
= wined3d_resource_get_private_data(resource
, tag
, Data
, Size
);
2039 LeaveCriticalSection(&ddraw_cs
);
2043 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2045 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2046 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2047 iface
, debugstr_guid(tag
), data
, size
);
2049 return ddraw_surface7_GetPrivateData(&This
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2052 /*****************************************************************************
2053 * IDirectDrawSurface7::FreePrivateData
2055 * Frees private data stored in the surface
2058 * tag: Tag of the data to free
2062 * For more details, see IWineD3DSurface::FreePrivateData
2064 *****************************************************************************/
2065 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2067 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2068 struct wined3d_resource
*resource
;
2071 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2073 EnterCriticalSection(&ddraw_cs
);
2074 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2075 hr
= wined3d_resource_free_private_data(resource
, tag
);
2076 LeaveCriticalSection(&ddraw_cs
);
2080 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2082 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2083 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2085 return ddraw_surface7_FreePrivateData(&This
->IDirectDrawSurface7_iface
, tag
);
2088 /*****************************************************************************
2089 * IDirectDrawSurface7::PageLock
2091 * Prevents a sysmem surface from being paged out
2094 * Flags: Not used, must be 0(unchecked)
2097 * DD_OK, because it's a stub
2099 *****************************************************************************/
2100 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2102 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2104 /* This is Windows memory management related - we don't need this */
2108 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2110 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2111 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2113 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2116 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2118 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2119 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2121 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2124 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2126 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2127 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2129 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2132 /*****************************************************************************
2133 * IDirectDrawSurface7::PageUnlock
2135 * Allows a sysmem surface to be paged out
2138 * Flags: Not used, must be 0(unchecked)
2141 * DD_OK, because it's a stub
2143 *****************************************************************************/
2144 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2146 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2151 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2153 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2154 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2156 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2159 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2161 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2162 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2164 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2167 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2169 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2170 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2172 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2175 /*****************************************************************************
2176 * IDirectDrawSurface7::BltBatch
2178 * An unimplemented function
2186 *****************************************************************************/
2187 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2189 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2191 /* MSDN: "not currently implemented" */
2192 return DDERR_UNSUPPORTED
;
2195 static HRESULT WINAPI
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2197 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2198 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2200 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2203 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2205 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2206 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2208 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2211 static HRESULT WINAPI
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2213 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2214 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2216 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2219 static HRESULT WINAPI
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2221 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2222 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2224 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2227 /*****************************************************************************
2228 * IDirectDrawSurface7::EnumAttachedSurfaces
2230 * Enumerates all surfaces attached to this surface
2233 * context: Pointer to pass unmodified to the callback
2234 * cb: Callback function to call for each surface
2238 * DDERR_INVALIDPARAMS if cb is NULL
2240 *****************************************************************************/
2241 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2242 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2244 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2245 IDirectDrawSurfaceImpl
*surf
;
2246 DDSURFACEDESC2 desc
;
2249 /* Attached surfaces aren't handled in WineD3D */
2250 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2253 return DDERR_INVALIDPARAMS
;
2255 EnterCriticalSection(&ddraw_cs
);
2256 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2258 surf
= This
->complex_array
[i
];
2261 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2262 desc
= surf
->surface_desc
;
2263 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2264 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2266 LeaveCriticalSection(&ddraw_cs
);
2271 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2273 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2274 desc
= surf
->surface_desc
;
2275 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2276 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2278 LeaveCriticalSection(&ddraw_cs
);
2283 TRACE(" end of enumeration.\n");
2285 LeaveCriticalSection(&ddraw_cs
);
2289 struct callback_info2
2291 LPDDENUMSURFACESCALLBACK2 callback
;
2295 struct callback_info
2297 LPDDENUMSURFACESCALLBACK callback
;
2301 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2303 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(surface
);
2304 const struct callback_info2
*info
= context
;
2306 ddraw_surface4_AddRef(&This
->IDirectDrawSurface4_iface
);
2307 ddraw_surface7_Release(surface
);
2309 return info
->callback(&This
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2312 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2314 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2315 const struct callback_info
*info
= context
;
2317 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2318 ddraw_surface7_Release(surface
);
2320 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2321 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2324 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2325 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2327 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2328 struct callback_info2 info
;
2330 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2332 info
.callback
= callback
;
2333 info
.context
= context
;
2335 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2336 &info
, EnumCallback2
);
2339 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2340 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2342 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2343 struct callback_info info
;
2345 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2347 info
.callback
= callback
;
2348 info
.context
= context
;
2350 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2351 &info
, EnumCallback
);
2354 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2355 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2357 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2358 struct callback_info info
;
2360 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2362 info
.callback
= callback
;
2363 info
.context
= context
;
2365 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2366 &info
, EnumCallback
);
2369 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2370 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2372 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2373 struct callback_info info
;
2375 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2377 info
.callback
= callback
;
2378 info
.context
= context
;
2380 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2381 &info
, EnumCallback
);
2384 /*****************************************************************************
2385 * IDirectDrawSurface7::EnumOverlayZOrders
2387 * "Enumerates the overlay surfaces on the specified destination"
2390 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2391 * context: context to pass back to the callback
2392 * cb: callback function to call for each enumerated surface
2395 * DD_OK, because it's a stub
2397 *****************************************************************************/
2398 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2399 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2401 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2406 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2407 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2409 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2410 struct callback_info2 info
;
2412 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2414 info
.callback
= callback
;
2415 info
.context
= context
;
2417 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2418 flags
, &info
, EnumCallback2
);
2421 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2422 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2424 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2425 struct callback_info info
;
2427 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2429 info
.callback
= callback
;
2430 info
.context
= context
;
2432 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2433 flags
, &info
, EnumCallback
);
2436 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2437 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2439 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2440 struct callback_info info
;
2442 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2444 info
.callback
= callback
;
2445 info
.context
= context
;
2447 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2448 flags
, &info
, EnumCallback
);
2451 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2452 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2454 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2455 struct callback_info info
;
2457 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2459 info
.callback
= callback
;
2460 info
.context
= context
;
2462 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2463 flags
, &info
, EnumCallback
);
2466 /*****************************************************************************
2467 * IDirectDrawSurface7::GetBltStatus
2469 * Returns the blitting status
2472 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2475 * See IWineD3DSurface::Blt
2477 *****************************************************************************/
2478 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2480 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2483 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2485 EnterCriticalSection(&ddraw_cs
);
2486 hr
= wined3d_surface_get_blt_status(This
->wined3d_surface
, Flags
);
2487 LeaveCriticalSection(&ddraw_cs
);
2490 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2495 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2497 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2498 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2500 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2503 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2505 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2506 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2508 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2511 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2513 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2514 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2516 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2519 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2521 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2522 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2524 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2527 /*****************************************************************************
2528 * IDirectDrawSurface7::GetColorKey
2530 * Returns the color key assigned to the surface
2534 * CKey: Address to store the key to
2538 * DDERR_INVALIDPARAMS if CKey is NULL
2540 *****************************************************************************/
2541 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2543 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2545 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2548 return DDERR_INVALIDPARAMS
;
2550 EnterCriticalSection(&ddraw_cs
);
2554 case DDCKEY_DESTBLT
:
2555 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
2557 LeaveCriticalSection(&ddraw_cs
);
2558 return DDERR_NOCOLORKEY
;
2560 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
2563 case DDCKEY_DESTOVERLAY
:
2564 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
2566 LeaveCriticalSection(&ddraw_cs
);
2567 return DDERR_NOCOLORKEY
;
2569 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
2573 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
2575 LeaveCriticalSection(&ddraw_cs
);
2576 return DDERR_NOCOLORKEY
;
2578 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
2581 case DDCKEY_SRCOVERLAY
:
2582 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
2584 LeaveCriticalSection(&ddraw_cs
);
2585 return DDERR_NOCOLORKEY
;
2587 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
2591 LeaveCriticalSection(&ddraw_cs
);
2592 return DDERR_INVALIDPARAMS
;
2595 LeaveCriticalSection(&ddraw_cs
);
2599 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2601 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2602 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2604 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2607 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2609 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2610 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2612 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2615 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2617 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2618 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2620 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2623 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2625 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2626 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2628 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2631 /*****************************************************************************
2632 * IDirectDrawSurface7::GetFlipStatus
2634 * Returns the flipping status of the surface
2637 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2640 * See IWineD3DSurface::GetFlipStatus
2642 *****************************************************************************/
2643 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2645 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2648 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2650 EnterCriticalSection(&ddraw_cs
);
2651 hr
= wined3d_surface_get_flip_status(This
->wined3d_surface
, Flags
);
2652 LeaveCriticalSection(&ddraw_cs
);
2655 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2660 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2662 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2663 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2665 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2668 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2670 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2671 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2673 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2676 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2678 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2679 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2681 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2684 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2686 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2687 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2689 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2692 /*****************************************************************************
2693 * IDirectDrawSurface7::GetOverlayPosition
2695 * Returns the display coordinates of a visible and active overlay surface
2702 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
2703 *****************************************************************************/
2704 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
2706 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2709 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
2711 EnterCriticalSection(&ddraw_cs
);
2712 hr
= wined3d_surface_get_overlay_position(This
->wined3d_surface
, X
, Y
);
2713 LeaveCriticalSection(&ddraw_cs
);
2717 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
2719 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2720 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2722 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2725 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
2727 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2728 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2730 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2733 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
2735 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2736 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2738 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2741 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
2743 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2744 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2746 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2749 /*****************************************************************************
2750 * IDirectDrawSurface7::GetPixelFormat
2752 * Returns the pixel format of the Surface
2755 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
2756 * format should be written
2760 * DDERR_INVALIDPARAMS if PixelFormat is NULL
2762 *****************************************************************************/
2763 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
2765 /* What is DDERR_INVALIDSURFACETYPE for here? */
2766 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2768 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
2771 return DDERR_INVALIDPARAMS
;
2773 EnterCriticalSection(&ddraw_cs
);
2774 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
2775 LeaveCriticalSection(&ddraw_cs
);
2780 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
2782 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2783 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2785 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2788 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
2790 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2791 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2793 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2796 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
2798 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2799 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2801 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2804 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
2806 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2807 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2809 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2812 /*****************************************************************************
2813 * IDirectDrawSurface7::GetSurfaceDesc
2815 * Returns the description of this surface
2818 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
2823 * DDERR_INVALIDPARAMS if DDSD is NULL
2825 *****************************************************************************/
2826 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
2828 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2830 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2833 return DDERR_INVALIDPARAMS
;
2835 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
2837 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
2838 return DDERR_INVALIDPARAMS
;
2841 EnterCriticalSection(&ddraw_cs
);
2842 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
2843 TRACE("Returning surface desc:\n");
2844 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
2846 LeaveCriticalSection(&ddraw_cs
);
2850 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
2852 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2853 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2855 return ddraw_surface7_GetSurfaceDesc(&This
->IDirectDrawSurface7_iface
, DDSD
);
2858 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
2860 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2862 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
2864 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
2866 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2868 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
2869 return DDERR_INVALIDPARAMS
;
2872 EnterCriticalSection(&ddraw_cs
);
2873 DD_STRUCT_COPY_BYSIZE(surface_desc
, (DDSURFACEDESC
*)&This
->surface_desc
);
2874 TRACE("Returning surface desc:\n");
2875 if (TRACE_ON(ddraw
))
2877 /* DDRAW_dump_surface_desc handles the smaller size */
2878 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2881 LeaveCriticalSection(&ddraw_cs
);
2885 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
2887 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2888 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2890 return ddraw_surface3_GetSurfaceDesc(&This
->IDirectDrawSurface3_iface
, DDSD
);
2893 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
2895 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2896 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2898 return ddraw_surface3_GetSurfaceDesc(&This
->IDirectDrawSurface3_iface
, DDSD
);
2901 /*****************************************************************************
2902 * IDirectDrawSurface7::Initialize
2904 * Initializes the surface. This is a no-op in Wine
2907 * DD: Pointer to an DirectDraw interface
2908 * DDSD: Surface description for initialization
2911 * DDERR_ALREADYINITIALIZED
2913 *****************************************************************************/
2914 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
2915 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
2917 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2919 return DDERR_ALREADYINITIALIZED
;
2922 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
2923 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
2925 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2926 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2928 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2929 ddraw
, surface_desc
);
2932 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
2933 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2935 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2936 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2938 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2939 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
2942 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
2943 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2945 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2946 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2948 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2949 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
2952 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
2953 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2955 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2956 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2958 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2959 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
2962 /*****************************************************************************
2963 * IDirect3DTexture1::Initialize
2965 * The sdk says it's not implemented
2973 *****************************************************************************/
2974 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
2975 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
2977 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
2979 return DDERR_UNSUPPORTED
; /* Unchecked */
2982 /*****************************************************************************
2983 * IDirectDrawSurface7::IsLost
2985 * Checks if the surface is lost
2988 * DD_OK, if the surface is usable
2989 * DDERR_ISLOST if the surface is lost
2990 * See IWineD3DSurface::IsLost for more details
2992 *****************************************************************************/
2993 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
2995 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2998 TRACE("iface %p.\n", iface
);
3000 EnterCriticalSection(&ddraw_cs
);
3001 /* We lose the surface if the implementation was changed */
3002 if(This
->ImplType
!= This
->ddraw
->ImplType
)
3004 /* But this shouldn't happen. When we change the implementation,
3005 * all surfaces are re-created automatically, and their content
3008 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
3009 LeaveCriticalSection(&ddraw_cs
);
3010 return DDERR_SURFACELOST
;
3013 hr
= wined3d_surface_is_lost(This
->wined3d_surface
);
3014 LeaveCriticalSection(&ddraw_cs
);
3017 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3018 * WineD3D uses the same error for surfaces
3020 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3025 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3027 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3028 TRACE("iface %p.\n", iface
);
3030 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3033 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3035 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3036 TRACE("iface %p.\n", iface
);
3038 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3041 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3043 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3044 TRACE("iface %p.\n", iface
);
3046 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3049 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3051 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3052 TRACE("iface %p.\n", iface
);
3054 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3057 /*****************************************************************************
3058 * IDirectDrawSurface7::Restore
3060 * Restores a lost surface. This makes the surface usable again, but
3061 * doesn't reload its old contents
3065 * See IWineD3DSurface::Restore for more details
3067 *****************************************************************************/
3068 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3070 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3073 TRACE("iface %p.\n", iface
);
3075 EnterCriticalSection(&ddraw_cs
);
3076 if(This
->ImplType
!= This
->ddraw
->ImplType
)
3078 /* Call the recreation callback. Make sure to AddRef first */
3079 IDirectDrawSurface_AddRef(iface
);
3080 ddraw_recreate_surfaces_cb(iface
, &This
->surface_desc
, NULL
/* Not needed */);
3082 hr
= wined3d_surface_restore(This
->wined3d_surface
);
3083 LeaveCriticalSection(&ddraw_cs
);
3087 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3089 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3090 TRACE("iface %p.\n", iface
);
3092 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3095 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3097 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3098 TRACE("iface %p.\n", iface
);
3100 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3103 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3105 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3106 TRACE("iface %p.\n", iface
);
3108 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3111 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3113 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3114 TRACE("iface %p.\n", iface
);
3116 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3119 /*****************************************************************************
3120 * IDirectDrawSurface7::SetOverlayPosition
3122 * Changes the display coordinates of an overlay surface
3129 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3130 *****************************************************************************/
3131 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3133 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3136 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3138 EnterCriticalSection(&ddraw_cs
);
3139 hr
= wined3d_surface_set_overlay_position(This
->wined3d_surface
, X
, Y
);
3140 LeaveCriticalSection(&ddraw_cs
);
3144 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3146 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3147 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3149 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3152 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3154 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3155 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3157 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3160 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3162 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3163 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3165 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3168 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3170 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3171 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3173 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3176 /*****************************************************************************
3177 * IDirectDrawSurface7::UpdateOverlay
3179 * Modifies the attributes of an overlay surface.
3182 * SrcRect: The section of the source being used for the overlay
3183 * DstSurface: Address of the surface that is overlaid
3184 * DstRect: Place of the overlay
3185 * Flags: some DDOVER_* flags
3188 * DDERR_UNSUPPORTED, because we don't support overlays
3190 *****************************************************************************/
3191 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3192 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3194 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3195 IDirectDrawSurfaceImpl
*Dst
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3198 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3199 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3201 EnterCriticalSection(&ddraw_cs
);
3202 hr
= wined3d_surface_update_overlay(This
->wined3d_surface
, SrcRect
,
3203 Dst
? Dst
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3204 LeaveCriticalSection(&ddraw_cs
);
3206 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3207 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3208 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3214 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3215 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3217 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3218 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3219 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3220 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3222 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3223 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3226 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3227 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3229 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3230 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3231 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3232 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3234 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3235 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3238 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3239 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3241 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3242 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3243 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3244 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3246 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3247 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3250 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3251 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3253 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3254 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3255 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3256 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3258 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3259 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3262 /*****************************************************************************
3263 * IDirectDrawSurface7::UpdateOverlayDisplay
3265 * The DX7 sdk says that it's not implemented
3270 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3272 *****************************************************************************/
3273 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3275 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3277 return DDERR_UNSUPPORTED
;
3280 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3282 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3283 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3285 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3288 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3290 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3291 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3293 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3296 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3298 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3299 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3301 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3304 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3306 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3307 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3309 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3312 /*****************************************************************************
3313 * IDirectDrawSurface7::UpdateOverlayZOrder
3315 * Sets an overlay's Z order
3318 * Flags: DDOVERZ_* flags
3319 * DDSRef: Defines the relative position in the overlay chain
3322 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3324 *****************************************************************************/
3325 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3326 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3328 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3329 IDirectDrawSurfaceImpl
*Ref
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3332 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3334 EnterCriticalSection(&ddraw_cs
);
3335 hr
= wined3d_surface_update_overlay_z_order(This
->wined3d_surface
,
3336 Flags
, Ref
? Ref
->wined3d_surface
: NULL
);
3337 LeaveCriticalSection(&ddraw_cs
);
3341 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3342 DWORD flags
, IDirectDrawSurface4
*reference
)
3344 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3345 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3346 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3348 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3349 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3352 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3353 DWORD flags
, IDirectDrawSurface3
*reference
)
3355 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3356 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3357 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3359 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3360 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3363 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3364 DWORD flags
, IDirectDrawSurface2
*reference
)
3366 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3367 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3368 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3370 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3371 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3374 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3375 DWORD flags
, IDirectDrawSurface
*reference
)
3377 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3378 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3379 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3381 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3382 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3385 /*****************************************************************************
3386 * IDirectDrawSurface7::GetDDInterface
3388 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3389 * surface belongs to
3392 * DD: Address to write the interface pointer to
3396 * DDERR_INVALIDPARAMS if DD is NULL
3398 *****************************************************************************/
3399 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3401 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3403 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3406 return DDERR_INVALIDPARAMS
;
3408 switch(This
->version
)
3411 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3415 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3419 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3423 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3427 IUnknown_AddRef((IUnknown
*)*DD
);
3432 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3434 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3435 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3437 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3440 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3442 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3443 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3445 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3448 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3450 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3451 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3453 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3456 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3457 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3459 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3460 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
3462 TRACE("iface %p.\n", iface
);
3464 EnterCriticalSection(&ddraw_cs
);
3465 /* A uniqueness value of 0 is apparently special.
3466 * This needs to be checked.
3467 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3470 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
3471 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
3473 if (old_uniqueness_value
== 0) break;
3474 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
3476 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
3477 old_uniqueness_value
,
3478 new_uniqueness_value
)
3479 == old_uniqueness_value
)
3483 LeaveCriticalSection(&ddraw_cs
);
3487 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3489 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3490 TRACE("iface %p.\n", iface
);
3492 return ddraw_surface7_ChangeUniquenessValue(&This
->IDirectDrawSurface7_iface
);
3495 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3497 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3499 TRACE("iface %p, value %p.\n", iface
, pValue
);
3501 EnterCriticalSection(&ddraw_cs
);
3502 *pValue
= This
->uniqueness_value
;
3503 LeaveCriticalSection(&ddraw_cs
);
3507 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3509 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3510 TRACE("iface %p, value %p.\n", iface
, pValue
);
3512 return ddraw_surface7_GetUniquenessValue(&This
->IDirectDrawSurface7_iface
, pValue
);
3515 /*****************************************************************************
3516 * IDirectDrawSurface7::SetLOD
3518 * Sets the level of detail of a texture
3521 * MaxLOD: LOD to set
3525 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3527 *****************************************************************************/
3528 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
3530 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3533 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
3535 EnterCriticalSection(&ddraw_cs
);
3536 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3538 LeaveCriticalSection(&ddraw_cs
);
3539 return DDERR_INVALIDOBJECT
;
3542 if (!This
->wined3d_texture
)
3544 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
3545 LeaveCriticalSection(&ddraw_cs
);
3546 return DDERR_INVALIDOBJECT
;
3549 hr
= wined3d_texture_set_lod(This
->wined3d_texture
, MaxLOD
);
3550 LeaveCriticalSection(&ddraw_cs
);
3554 /*****************************************************************************
3555 * IDirectDrawSurface7::GetLOD
3557 * Returns the level of detail of a Direct3D texture
3560 * MaxLOD: Address to write the LOD to
3564 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3565 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3567 *****************************************************************************/
3568 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
3570 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3572 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
3575 return DDERR_INVALIDPARAMS
;
3577 EnterCriticalSection(&ddraw_cs
);
3578 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3580 LeaveCriticalSection(&ddraw_cs
);
3581 return DDERR_INVALIDOBJECT
;
3584 *MaxLOD
= wined3d_texture_get_lod(This
->wined3d_texture
);
3585 LeaveCriticalSection(&ddraw_cs
);
3589 /*****************************************************************************
3590 * IDirectDrawSurface7::BltFast
3592 * Performs a fast Blit.
3595 * dstx: The x coordinate to blit to on the destination
3596 * dsty: The y coordinate to blit to on the destination
3597 * Source: The source surface
3598 * rsrc: The source rectangle
3599 * trans: Type of transfer. Some DDBLTFAST_* flags
3603 * For more details, see IWineD3DSurface::BltFast
3605 *****************************************************************************/
3606 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
3607 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
3609 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3610 IDirectDrawSurfaceImpl
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
3611 DWORD src_w
, src_h
, dst_w
, dst_h
;
3614 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3615 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
3617 dst_w
= This
->surface_desc
.dwWidth
;
3618 dst_h
= This
->surface_desc
.dwHeight
;
3620 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3625 src_w
= rsrc
->right
- rsrc
->left
;
3626 src_h
= rsrc
->bottom
- rsrc
->top
;
3630 src_w
= src
->surface_desc
.dwWidth
;
3631 src_h
= src
->surface_desc
.dwHeight
;
3634 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
3635 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
3637 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3638 return DDERR_INVALIDRECT
;
3641 EnterCriticalSection(&ddraw_cs
);
3642 hr
= wined3d_surface_bltfast(This
->wined3d_surface
, dstx
, dsty
,
3643 src
->wined3d_surface
, rsrc
, trans
);
3644 LeaveCriticalSection(&ddraw_cs
);
3647 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
3648 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
3653 static HRESULT WINAPI
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
3654 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
3656 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3657 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
3658 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3659 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3661 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3662 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3665 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
3666 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
3668 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3669 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
3670 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3671 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3673 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3674 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3677 static HRESULT WINAPI
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
3678 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
3680 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3681 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
3682 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3683 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3685 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3686 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3689 static HRESULT WINAPI
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
3690 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
3692 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3693 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
3694 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3695 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3697 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3698 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3701 /*****************************************************************************
3702 * IDirectDrawSurface7::GetClipper
3704 * Returns the IDirectDrawClipper interface of the clipper assigned to this
3708 * Clipper: Address to store the interface pointer at
3712 * DDERR_INVALIDPARAMS if Clipper is NULL
3713 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
3715 *****************************************************************************/
3716 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
3718 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3720 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
3724 LeaveCriticalSection(&ddraw_cs
);
3725 return DDERR_INVALIDPARAMS
;
3728 EnterCriticalSection(&ddraw_cs
);
3729 if(This
->clipper
== NULL
)
3731 LeaveCriticalSection(&ddraw_cs
);
3732 return DDERR_NOCLIPPERATTACHED
;
3735 *Clipper
= (IDirectDrawClipper
*)This
->clipper
;
3736 IDirectDrawClipper_AddRef(*Clipper
);
3737 LeaveCriticalSection(&ddraw_cs
);
3741 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
3743 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3744 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3746 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3749 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
3751 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3752 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3754 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3757 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
3759 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3760 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3762 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3765 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
3767 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3768 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3770 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3773 /*****************************************************************************
3774 * IDirectDrawSurface7::SetClipper
3776 * Sets a clipper for the surface
3779 * Clipper: IDirectDrawClipper interface of the clipper to set
3784 *****************************************************************************/
3785 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
3786 IDirectDrawClipper
*iclipper
)
3788 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3789 IDirectDrawClipperImpl
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
3790 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
3794 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
3796 EnterCriticalSection(&ddraw_cs
);
3797 if (clipper
== This
->clipper
)
3799 LeaveCriticalSection(&ddraw_cs
);
3803 This
->clipper
= clipper
;
3805 if (clipper
!= NULL
)
3806 IDirectDrawClipper_AddRef(iclipper
);
3808 IDirectDrawClipper_Release(&oldClipper
->IDirectDrawClipper_iface
);
3810 hr
= wined3d_surface_set_clipper(This
->wined3d_surface
,
3811 This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
3813 if (This
->wined3d_swapchain
)
3817 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
3821 wined3d_swapchain_set_window(This
->wined3d_swapchain
, clipWindow
);
3823 wined3d_swapchain_set_window(This
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
3826 LeaveCriticalSection(&ddraw_cs
);
3830 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
3832 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3833 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3835 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3838 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
3840 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3841 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3843 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3846 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
3848 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3849 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3851 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3854 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
3856 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3857 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3859 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3862 /*****************************************************************************
3863 * IDirectDrawSurface7::SetSurfaceDesc
3865 * Sets the surface description. It can override the pixel format, the surface
3867 * It's not really tested.
3870 * DDSD: Pointer to the new surface description to set
3875 * DDERR_INVALIDPARAMS if DDSD is NULL
3877 *****************************************************************************/
3878 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
3880 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3881 enum wined3d_format_id newFormat
= WINED3DFMT_UNKNOWN
;
3884 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
3887 return DDERR_INVALIDPARAMS
;
3889 EnterCriticalSection(&ddraw_cs
);
3890 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
3892 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
3894 if(newFormat
== WINED3DFMT_UNKNOWN
)
3896 ERR("Requested to set an unknown pixelformat\n");
3897 LeaveCriticalSection(&ddraw_cs
);
3898 return DDERR_INVALIDPARAMS
;
3900 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
3902 hr
= wined3d_surface_set_format(This
->wined3d_surface
, newFormat
);
3905 LeaveCriticalSection(&ddraw_cs
);
3910 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
3912 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
3913 (WINEDDCOLORKEY
*)&DDSD
->u3
.ddckCKDestOverlay
);
3915 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
3917 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_DESTBLT
,
3918 (WINEDDCOLORKEY
*)&DDSD
->ddckCKDestBlt
);
3920 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
3922 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
3923 (WINEDDCOLORKEY
*)&DDSD
->ddckCKSrcOverlay
);
3925 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
3927 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_SRCBLT
,
3928 (WINEDDCOLORKEY
*)&DDSD
->ddckCKSrcBlt
);
3930 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
3932 hr
= wined3d_surface_set_mem(This
->wined3d_surface
, DDSD
->lpSurface
);
3935 /* No need for a trace here, wined3d does that for us */
3938 case WINED3DERR_INVALIDCALL
:
3939 LeaveCriticalSection(&ddraw_cs
);
3940 return DDERR_INVALIDPARAMS
;
3947 This
->surface_desc
= *DDSD
;
3949 LeaveCriticalSection(&ddraw_cs
);
3953 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
3954 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
3956 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3957 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
3959 return ddraw_surface7_SetSurfaceDesc(&This
->IDirectDrawSurface7_iface
,
3960 surface_desc
, flags
);
3963 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
3964 DDSURFACEDESC
*surface_desc
, DWORD flags
)
3966 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3967 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
3969 return ddraw_surface7_SetSurfaceDesc(&This
->IDirectDrawSurface7_iface
,
3970 (DDSURFACEDESC2
*)surface_desc
, flags
);
3973 /*****************************************************************************
3974 * IDirectDrawSurface7::GetPalette
3976 * Returns the IDirectDrawPalette interface of the palette currently assigned
3980 * Pal: Address to write the interface pointer to
3984 * DDERR_INVALIDPARAMS if Pal is NULL
3986 *****************************************************************************/
3987 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
3989 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3990 struct wined3d_palette
*wined3d_palette
;
3993 TRACE("iface %p, palette %p.\n", iface
, Pal
);
3996 return DDERR_INVALIDPARAMS
;
3998 EnterCriticalSection(&ddraw_cs
);
3999 wined3d_palette
= wined3d_surface_get_palette(This
->wined3d_surface
);
4000 if (wined3d_palette
)
4002 *Pal
= wined3d_palette_get_parent(wined3d_palette
);
4003 IDirectDrawPalette_AddRef(*Pal
);
4008 hr
= DDERR_NOPALETTEATTACHED
;
4011 LeaveCriticalSection(&ddraw_cs
);
4015 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4017 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4018 TRACE("iface %p, palette %p.\n", iface
, palette
);
4020 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4023 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4025 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4026 TRACE("iface %p, palette %p.\n", iface
, palette
);
4028 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4031 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4033 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4034 TRACE("iface %p, palette %p.\n", iface
, palette
);
4036 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4039 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4041 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4042 TRACE("iface %p, palette %p.\n", iface
, palette
);
4044 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4047 /*****************************************************************************
4050 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4051 * recursively in the surface tree
4053 *****************************************************************************/
4057 WINEDDCOLORKEY
*CKey
;
4061 static HRESULT WINAPI
4062 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
4063 DDSURFACEDESC2
*desc
,
4066 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(surface
);
4067 struct SCKContext
*ctx
= context
;
4070 hr
= wined3d_surface_set_color_key(This
->wined3d_surface
, ctx
->Flags
, ctx
->CKey
);
4073 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
4077 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
4078 ddraw_surface7_Release(surface
);
4080 return DDENUMRET_OK
;
4083 /*****************************************************************************
4084 * IDirectDrawSurface7::SetColorKey
4086 * Sets the color keying options for the surface. Observations showed that
4087 * in case of complex surfaces the color key has to be assigned to all
4092 * CKey: The new color key
4096 * See IWineD3DSurface::SetColorKey for details
4098 *****************************************************************************/
4099 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
4101 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4102 DDCOLORKEY FixedCKey
;
4103 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) (CKey
? &FixedCKey
: NULL
), Flags
};
4105 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
4107 EnterCriticalSection(&ddraw_cs
);
4111 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4112 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
4113 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
4115 switch (Flags
& ~DDCKEY_COLORSPACE
)
4117 case DDCKEY_DESTBLT
:
4118 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
4119 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4122 case DDCKEY_DESTOVERLAY
:
4123 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
4124 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4127 case DDCKEY_SRCOVERLAY
:
4128 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
4129 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4133 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
4134 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4138 LeaveCriticalSection(&ddraw_cs
);
4139 return DDERR_INVALIDPARAMS
;
4144 switch (Flags
& ~DDCKEY_COLORSPACE
)
4146 case DDCKEY_DESTBLT
:
4147 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4150 case DDCKEY_DESTOVERLAY
:
4151 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4154 case DDCKEY_SRCOVERLAY
:
4155 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4159 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4163 LeaveCriticalSection(&ddraw_cs
);
4164 return DDERR_INVALIDPARAMS
;
4167 ctx
.ret
= wined3d_surface_set_color_key(This
->wined3d_surface
, Flags
, ctx
.CKey
);
4168 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
4169 LeaveCriticalSection(&ddraw_cs
);
4172 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
4173 default: return ctx
.ret
;
4177 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4179 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4180 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4182 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4185 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4187 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4188 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4190 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4193 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4195 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4196 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4198 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4201 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4203 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4204 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4206 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4209 /*****************************************************************************
4210 * IDirectDrawSurface7::SetPalette
4212 * Assigns a DirectDrawPalette object to the surface
4215 * Pal: Interface to the palette to set
4220 *****************************************************************************/
4221 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
4223 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4224 IDirectDrawPalette
*oldPal
;
4225 IDirectDrawSurfaceImpl
*surf
;
4226 IDirectDrawPaletteImpl
*PalImpl
= (IDirectDrawPaletteImpl
*)Pal
;
4229 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4231 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
4232 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
4233 return DDERR_INVALIDPIXELFORMAT
;
4236 if (!This
->is_complex_root
)
4238 return DDERR_NOTONMIPMAPSUBLEVEL
;
4241 /* Find the old palette */
4242 EnterCriticalSection(&ddraw_cs
);
4243 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
4244 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
4246 LeaveCriticalSection(&ddraw_cs
);
4249 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
4251 /* Set the new Palette */
4252 wined3d_surface_set_palette(This
->wined3d_surface
, PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
4253 /* AddRef the Palette */
4254 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
4256 /* Release the old palette */
4257 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
4259 /* If this is a front buffer, also update the back buffers
4260 * TODO: How do things work for palettized cube textures?
4262 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4264 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4265 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
4270 IDirectDrawSurface7
*attach
;
4272 hr
= ddraw_surface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &caps2
, &attach
);
4278 TRACE("Setting palette on %p\n", attach
);
4279 ddraw_surface7_SetPalette(attach
, Pal
);
4280 surf
= impl_from_IDirectDrawSurface7(attach
);
4281 ddraw_surface7_Release(attach
);
4285 LeaveCriticalSection(&ddraw_cs
);
4289 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4291 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4292 TRACE("iface %p, palette %p.\n", iface
, palette
);
4294 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4297 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4299 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4300 TRACE("iface %p, palette %p.\n", iface
, palette
);
4302 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4305 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4307 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4308 TRACE("iface %p, palette %p.\n", iface
, palette
);
4310 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4313 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4315 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4316 TRACE("iface %p, palette %p.\n", iface
, palette
);
4318 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4321 /**********************************************************
4322 * IDirectDrawGammaControl::GetGammaRamp
4324 * Returns the current gamma ramp for a surface
4328 * gamma_ramp: Address to write the ramp to
4332 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4334 **********************************************************/
4335 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4336 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4338 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4340 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4344 WARN("Invalid gamma_ramp passed.\n");
4345 return DDERR_INVALIDPARAMS
;
4348 EnterCriticalSection(&ddraw_cs
);
4349 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4351 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */
4352 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (WINED3DGAMMARAMP
*)gamma_ramp
);
4356 ERR("Not implemented for non-primary surfaces.\n");
4358 LeaveCriticalSection(&ddraw_cs
);
4363 /**********************************************************
4364 * IDirectDrawGammaControl::SetGammaRamp
4366 * Sets the red, green and blue gamma ramps for
4369 * flags: Can be DDSGR_CALIBRATE to request calibration
4370 * gamma_ramp: Structure containing the new gamma ramp
4374 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4376 **********************************************************/
4377 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4378 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4380 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4382 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4386 WARN("Invalid gamma_ramp passed.\n");
4387 return DDERR_INVALIDPARAMS
;
4390 EnterCriticalSection(&ddraw_cs
);
4391 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4393 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
4394 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, flags
, (WINED3DGAMMARAMP
*)gamma_ramp
);
4398 ERR("Not implemented for non-primary surfaces.\n");
4400 LeaveCriticalSection(&ddraw_cs
);
4405 /*****************************************************************************
4406 * IDirect3DTexture2::PaletteChanged
4408 * Informs the texture about a palette change
4411 * start: Start index of the change
4412 * count: The number of changed entries
4415 * D3D_OK, because it's a stub
4417 *****************************************************************************/
4418 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4420 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4425 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4427 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirect3DTexture(iface
);
4429 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4431 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4434 /*****************************************************************************
4435 * IDirect3DTexture::Unload
4437 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4443 *****************************************************************************/
4444 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4446 WARN("iface %p. Not implemented.\n", iface
);
4448 return DDERR_UNSUPPORTED
;
4451 /*****************************************************************************
4452 * IDirect3DTexture2::GetHandle
4454 * Returns handle for the texture. At the moment, the interface
4455 * to the IWineD3DTexture is used.
4458 * device: Device this handle is assigned to
4459 * handle: Address to store the handle at.
4464 *****************************************************************************/
4465 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4466 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4468 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirect3DTexture2(iface
);
4470 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4472 EnterCriticalSection(&ddraw_cs
);
4474 if (!surface
->Handle
)
4476 DWORD h
= ddraw_allocate_handle(&device_from_device2(device
)->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
4477 if (h
== DDRAW_INVALID_HANDLE
)
4479 ERR("Failed to allocate a texture handle.\n");
4480 LeaveCriticalSection(&ddraw_cs
);
4481 return DDERR_OUTOFMEMORY
;
4484 surface
->Handle
= h
+ 1;
4487 TRACE("Returning handle %08x.\n", surface
->Handle
);
4488 *handle
= surface
->Handle
;
4490 LeaveCriticalSection(&ddraw_cs
);
4495 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
4496 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
4498 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
4499 IDirect3DDevice2
*device2
= (IDirect3DDevice2
*)&device_from_device1(device
)->IDirect3DDevice2_vtbl
;
4501 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4503 return d3d_texture2_GetHandle(&This
->IDirect3DTexture2_iface
, device2
, handle
);
4506 /*****************************************************************************
4507 * get_sub_mimaplevel
4509 * Helper function that returns the next mipmap level
4511 * tex_ptr: Surface of which to return the next level
4513 *****************************************************************************/
4514 static IDirectDrawSurfaceImpl
*get_sub_mimaplevel(IDirectDrawSurfaceImpl
*surface
)
4516 /* Now go down the mipmap chain to the next surface */
4517 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
4518 IDirectDrawSurface7
*next_level
;
4521 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
4522 if (FAILED(hr
)) return NULL
;
4524 ddraw_surface7_Release(next_level
);
4526 return impl_from_IDirectDrawSurface7(next_level
);
4529 /*****************************************************************************
4530 * IDirect3DTexture2::Load
4532 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
4534 * This function isn't relayed to WineD3D because the whole interface is
4535 * implemented in DDraw only. For speed improvements a implementation which
4536 * takes OpenGL more into account could be placed into WineD3D.
4539 * src_texture: Address of the texture to load
4543 * D3DERR_TEXTURE_LOAD_FAILED.
4545 *****************************************************************************/
4546 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
4548 IDirectDrawSurfaceImpl
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
4549 IDirectDrawSurfaceImpl
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
4552 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
4554 if (src_surface
== dst_surface
)
4556 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
4560 EnterCriticalSection(&ddraw_cs
);
4562 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4563 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
4564 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
4566 ERR("Trying to load surfaces with different mip-map counts.\n");
4571 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
4572 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
4573 DDSURFACEDESC
*src_desc
, *dst_desc
;
4575 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
4576 src_surface
, dst_surface
, src_surface
->mipmap_level
);
4578 /* Suppress the ALLOCONLOAD flag */
4579 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
4581 /* Get the palettes */
4582 wined3d_dst_pal
= wined3d_surface_get_palette(dst_surface
->wined3d_surface
);
4583 if (wined3d_dst_pal
)
4584 dst_pal
= wined3d_palette_get_parent(wined3d_dst_pal
);
4586 wined3d_src_pal
= wined3d_surface_get_palette(src_surface
->wined3d_surface
);
4587 if (wined3d_src_pal
)
4588 src_pal
= wined3d_palette_get_parent(wined3d_src_pal
);
4592 PALETTEENTRY palent
[256];
4596 LeaveCriticalSection(&ddraw_cs
);
4597 return DDERR_NOPALETTEATTACHED
;
4599 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
4600 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
4603 /* Copy one surface on the other */
4604 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
4605 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
4607 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
4609 /* Should also check for same pixel format, u1.lPitch, ... */
4610 ERR("Error in surface sizes.\n");
4611 LeaveCriticalSection(&ddraw_cs
);
4612 return D3DERR_TEXTURE_LOAD_FAILED
;
4616 WINED3DLOCKED_RECT src_rect
, dst_rect
;
4618 /* Copy also the ColorKeying stuff */
4619 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
4621 dst_desc
->dwFlags
|= DDSD_CKSRCBLT
;
4622 dst_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
;
4623 dst_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
;
4626 /* Copy the main memory texture into the surface that corresponds
4627 * to the OpenGL texture object. */
4629 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_rect
, NULL
, 0);
4632 ERR("Failed to lock source surface, hr %#x.\n", hr
);
4633 LeaveCriticalSection(&ddraw_cs
);
4634 return D3DERR_TEXTURE_LOAD_FAILED
;
4637 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_rect
, NULL
, 0);
4640 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
4641 wined3d_surface_unmap(src_surface
->wined3d_surface
);
4642 LeaveCriticalSection(&ddraw_cs
);
4643 return D3DERR_TEXTURE_LOAD_FAILED
;
4646 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
4647 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_surface
->surface_desc
.u1
.dwLinearSize
);
4649 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_rect
.Pitch
* src_desc
->dwHeight
);
4651 wined3d_surface_unmap(src_surface
->wined3d_surface
);
4652 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
4655 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4656 src_surface
= get_sub_mimaplevel(src_surface
);
4660 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4661 dst_surface
= get_sub_mimaplevel(dst_surface
);
4665 if (!src_surface
|| !dst_surface
)
4667 if (src_surface
!= dst_surface
)
4668 ERR("Loading surface with different mipmap structure.\n");
4673 LeaveCriticalSection(&ddraw_cs
);
4678 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
4680 IDirectDrawSurfaceImpl
* This
= impl_from_IDirect3DTexture(iface
);
4681 IDirectDrawSurfaceImpl
* src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
4682 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
4684 return d3d_texture2_Load(&This
->IDirect3DTexture2_iface
,
4685 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
4688 /*****************************************************************************
4690 *****************************************************************************/
4692 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
4695 ddraw_surface7_QueryInterface
,
4696 ddraw_surface7_AddRef
,
4697 ddraw_surface7_Release
,
4698 /* IDirectDrawSurface */
4699 ddraw_surface7_AddAttachedSurface
,
4700 ddraw_surface7_AddOverlayDirtyRect
,
4702 ddraw_surface7_BltBatch
,
4703 ddraw_surface7_BltFast
,
4704 ddraw_surface7_DeleteAttachedSurface
,
4705 ddraw_surface7_EnumAttachedSurfaces
,
4706 ddraw_surface7_EnumOverlayZOrders
,
4707 ddraw_surface7_Flip
,
4708 ddraw_surface7_GetAttachedSurface
,
4709 ddraw_surface7_GetBltStatus
,
4710 ddraw_surface7_GetCaps
,
4711 ddraw_surface7_GetClipper
,
4712 ddraw_surface7_GetColorKey
,
4713 ddraw_surface7_GetDC
,
4714 ddraw_surface7_GetFlipStatus
,
4715 ddraw_surface7_GetOverlayPosition
,
4716 ddraw_surface7_GetPalette
,
4717 ddraw_surface7_GetPixelFormat
,
4718 ddraw_surface7_GetSurfaceDesc
,
4719 ddraw_surface7_Initialize
,
4720 ddraw_surface7_IsLost
,
4721 ddraw_surface7_Lock
,
4722 ddraw_surface7_ReleaseDC
,
4723 ddraw_surface7_Restore
,
4724 ddraw_surface7_SetClipper
,
4725 ddraw_surface7_SetColorKey
,
4726 ddraw_surface7_SetOverlayPosition
,
4727 ddraw_surface7_SetPalette
,
4728 ddraw_surface7_Unlock
,
4729 ddraw_surface7_UpdateOverlay
,
4730 ddraw_surface7_UpdateOverlayDisplay
,
4731 ddraw_surface7_UpdateOverlayZOrder
,
4732 /* IDirectDrawSurface2 */
4733 ddraw_surface7_GetDDInterface
,
4734 ddraw_surface7_PageLock
,
4735 ddraw_surface7_PageUnlock
,
4736 /* IDirectDrawSurface3 */
4737 ddraw_surface7_SetSurfaceDesc
,
4738 /* IDirectDrawSurface4 */
4739 ddraw_surface7_SetPrivateData
,
4740 ddraw_surface7_GetPrivateData
,
4741 ddraw_surface7_FreePrivateData
,
4742 ddraw_surface7_GetUniquenessValue
,
4743 ddraw_surface7_ChangeUniquenessValue
,
4744 /* IDirectDrawSurface7 */
4745 ddraw_surface7_SetPriority
,
4746 ddraw_surface7_GetPriority
,
4747 ddraw_surface7_SetLOD
,
4748 ddraw_surface7_GetLOD
,
4751 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
4754 ddraw_surface4_QueryInterface
,
4755 ddraw_surface4_AddRef
,
4756 ddraw_surface4_Release
,
4757 /* IDirectDrawSurface */
4758 ddraw_surface4_AddAttachedSurface
,
4759 ddraw_surface4_AddOverlayDirtyRect
,
4761 ddraw_surface4_BltBatch
,
4762 ddraw_surface4_BltFast
,
4763 ddraw_surface4_DeleteAttachedSurface
,
4764 ddraw_surface4_EnumAttachedSurfaces
,
4765 ddraw_surface4_EnumOverlayZOrders
,
4766 ddraw_surface4_Flip
,
4767 ddraw_surface4_GetAttachedSurface
,
4768 ddraw_surface4_GetBltStatus
,
4769 ddraw_surface4_GetCaps
,
4770 ddraw_surface4_GetClipper
,
4771 ddraw_surface4_GetColorKey
,
4772 ddraw_surface4_GetDC
,
4773 ddraw_surface4_GetFlipStatus
,
4774 ddraw_surface4_GetOverlayPosition
,
4775 ddraw_surface4_GetPalette
,
4776 ddraw_surface4_GetPixelFormat
,
4777 ddraw_surface4_GetSurfaceDesc
,
4778 ddraw_surface4_Initialize
,
4779 ddraw_surface4_IsLost
,
4780 ddraw_surface4_Lock
,
4781 ddraw_surface4_ReleaseDC
,
4782 ddraw_surface4_Restore
,
4783 ddraw_surface4_SetClipper
,
4784 ddraw_surface4_SetColorKey
,
4785 ddraw_surface4_SetOverlayPosition
,
4786 ddraw_surface4_SetPalette
,
4787 ddraw_surface4_Unlock
,
4788 ddraw_surface4_UpdateOverlay
,
4789 ddraw_surface4_UpdateOverlayDisplay
,
4790 ddraw_surface4_UpdateOverlayZOrder
,
4791 /* IDirectDrawSurface2 */
4792 ddraw_surface4_GetDDInterface
,
4793 ddraw_surface4_PageLock
,
4794 ddraw_surface4_PageUnlock
,
4795 /* IDirectDrawSurface3 */
4796 ddraw_surface4_SetSurfaceDesc
,
4797 /* IDirectDrawSurface4 */
4798 ddraw_surface4_SetPrivateData
,
4799 ddraw_surface4_GetPrivateData
,
4800 ddraw_surface4_FreePrivateData
,
4801 ddraw_surface4_GetUniquenessValue
,
4802 ddraw_surface4_ChangeUniquenessValue
,
4805 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
4808 ddraw_surface3_QueryInterface
,
4809 ddraw_surface3_AddRef
,
4810 ddraw_surface3_Release
,
4811 /* IDirectDrawSurface */
4812 ddraw_surface3_AddAttachedSurface
,
4813 ddraw_surface3_AddOverlayDirtyRect
,
4815 ddraw_surface3_BltBatch
,
4816 ddraw_surface3_BltFast
,
4817 ddraw_surface3_DeleteAttachedSurface
,
4818 ddraw_surface3_EnumAttachedSurfaces
,
4819 ddraw_surface3_EnumOverlayZOrders
,
4820 ddraw_surface3_Flip
,
4821 ddraw_surface3_GetAttachedSurface
,
4822 ddraw_surface3_GetBltStatus
,
4823 ddraw_surface3_GetCaps
,
4824 ddraw_surface3_GetClipper
,
4825 ddraw_surface3_GetColorKey
,
4826 ddraw_surface3_GetDC
,
4827 ddraw_surface3_GetFlipStatus
,
4828 ddraw_surface3_GetOverlayPosition
,
4829 ddraw_surface3_GetPalette
,
4830 ddraw_surface3_GetPixelFormat
,
4831 ddraw_surface3_GetSurfaceDesc
,
4832 ddraw_surface3_Initialize
,
4833 ddraw_surface3_IsLost
,
4834 ddraw_surface3_Lock
,
4835 ddraw_surface3_ReleaseDC
,
4836 ddraw_surface3_Restore
,
4837 ddraw_surface3_SetClipper
,
4838 ddraw_surface3_SetColorKey
,
4839 ddraw_surface3_SetOverlayPosition
,
4840 ddraw_surface3_SetPalette
,
4841 ddraw_surface3_Unlock
,
4842 ddraw_surface3_UpdateOverlay
,
4843 ddraw_surface3_UpdateOverlayDisplay
,
4844 ddraw_surface3_UpdateOverlayZOrder
,
4845 /* IDirectDrawSurface2 */
4846 ddraw_surface3_GetDDInterface
,
4847 ddraw_surface3_PageLock
,
4848 ddraw_surface3_PageUnlock
,
4849 /* IDirectDrawSurface3 */
4850 ddraw_surface3_SetSurfaceDesc
,
4853 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
4856 ddraw_surface2_QueryInterface
,
4857 ddraw_surface2_AddRef
,
4858 ddraw_surface2_Release
,
4859 /* IDirectDrawSurface */
4860 ddraw_surface2_AddAttachedSurface
,
4861 ddraw_surface2_AddOverlayDirtyRect
,
4863 ddraw_surface2_BltBatch
,
4864 ddraw_surface2_BltFast
,
4865 ddraw_surface2_DeleteAttachedSurface
,
4866 ddraw_surface2_EnumAttachedSurfaces
,
4867 ddraw_surface2_EnumOverlayZOrders
,
4868 ddraw_surface2_Flip
,
4869 ddraw_surface2_GetAttachedSurface
,
4870 ddraw_surface2_GetBltStatus
,
4871 ddraw_surface2_GetCaps
,
4872 ddraw_surface2_GetClipper
,
4873 ddraw_surface2_GetColorKey
,
4874 ddraw_surface2_GetDC
,
4875 ddraw_surface2_GetFlipStatus
,
4876 ddraw_surface2_GetOverlayPosition
,
4877 ddraw_surface2_GetPalette
,
4878 ddraw_surface2_GetPixelFormat
,
4879 ddraw_surface2_GetSurfaceDesc
,
4880 ddraw_surface2_Initialize
,
4881 ddraw_surface2_IsLost
,
4882 ddraw_surface2_Lock
,
4883 ddraw_surface2_ReleaseDC
,
4884 ddraw_surface2_Restore
,
4885 ddraw_surface2_SetClipper
,
4886 ddraw_surface2_SetColorKey
,
4887 ddraw_surface2_SetOverlayPosition
,
4888 ddraw_surface2_SetPalette
,
4889 ddraw_surface2_Unlock
,
4890 ddraw_surface2_UpdateOverlay
,
4891 ddraw_surface2_UpdateOverlayDisplay
,
4892 ddraw_surface2_UpdateOverlayZOrder
,
4893 /* IDirectDrawSurface2 */
4894 ddraw_surface2_GetDDInterface
,
4895 ddraw_surface2_PageLock
,
4896 ddraw_surface2_PageUnlock
,
4899 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
4902 ddraw_surface1_QueryInterface
,
4903 ddraw_surface1_AddRef
,
4904 ddraw_surface1_Release
,
4905 /* IDirectDrawSurface */
4906 ddraw_surface1_AddAttachedSurface
,
4907 ddraw_surface1_AddOverlayDirtyRect
,
4909 ddraw_surface1_BltBatch
,
4910 ddraw_surface1_BltFast
,
4911 ddraw_surface1_DeleteAttachedSurface
,
4912 ddraw_surface1_EnumAttachedSurfaces
,
4913 ddraw_surface1_EnumOverlayZOrders
,
4914 ddraw_surface1_Flip
,
4915 ddraw_surface1_GetAttachedSurface
,
4916 ddraw_surface1_GetBltStatus
,
4917 ddraw_surface1_GetCaps
,
4918 ddraw_surface1_GetClipper
,
4919 ddraw_surface1_GetColorKey
,
4920 ddraw_surface1_GetDC
,
4921 ddraw_surface1_GetFlipStatus
,
4922 ddraw_surface1_GetOverlayPosition
,
4923 ddraw_surface1_GetPalette
,
4924 ddraw_surface1_GetPixelFormat
,
4925 ddraw_surface1_GetSurfaceDesc
,
4926 ddraw_surface1_Initialize
,
4927 ddraw_surface1_IsLost
,
4928 ddraw_surface1_Lock
,
4929 ddraw_surface1_ReleaseDC
,
4930 ddraw_surface1_Restore
,
4931 ddraw_surface1_SetClipper
,
4932 ddraw_surface1_SetColorKey
,
4933 ddraw_surface1_SetOverlayPosition
,
4934 ddraw_surface1_SetPalette
,
4935 ddraw_surface1_Unlock
,
4936 ddraw_surface1_UpdateOverlay
,
4937 ddraw_surface1_UpdateOverlayDisplay
,
4938 ddraw_surface1_UpdateOverlayZOrder
,
4941 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
4943 ddraw_gamma_control_QueryInterface
,
4944 ddraw_gamma_control_AddRef
,
4945 ddraw_gamma_control_Release
,
4946 ddraw_gamma_control_GetGammaRamp
,
4947 ddraw_gamma_control_SetGammaRamp
,
4950 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
4952 d3d_texture2_QueryInterface
,
4953 d3d_texture2_AddRef
,
4954 d3d_texture2_Release
,
4955 d3d_texture2_GetHandle
,
4956 d3d_texture2_PaletteChanged
,
4960 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
4962 d3d_texture1_QueryInterface
,
4963 d3d_texture1_AddRef
,
4964 d3d_texture1_Release
,
4965 d3d_texture1_Initialize
,
4966 d3d_texture1_GetHandle
,
4967 d3d_texture1_PaletteChanged
,
4969 d3d_texture1_Unload
,
4972 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
4974 if (!iface
) return NULL
;
4975 assert(iface
->lpVtbl
== &ddraw_surface7_vtbl
);
4976 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface7_iface
);
4979 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
4981 if (!iface
) return NULL
;
4982 assert(iface
->lpVtbl
== &ddraw_surface4_vtbl
);
4983 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface4_iface
);
4986 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
4988 if (!iface
) return NULL
;
4989 assert(iface
->lpVtbl
== &ddraw_surface3_vtbl
);
4990 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface3_iface
);
4993 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
4995 if (!iface
) return NULL
;
4996 assert(iface
->lpVtbl
== &ddraw_surface2_vtbl
);
4997 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface2_iface
);
5000 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5002 if (!iface
) return NULL
;
5003 assert(iface
->lpVtbl
== &ddraw_surface1_vtbl
);
5004 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface_iface
);
5007 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5009 if (!iface
) return NULL
;
5010 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5011 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirect3DTexture2_iface
);
5014 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5016 if (!iface
) return NULL
;
5017 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5018 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirect3DTexture_iface
);
5021 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5023 IDirectDrawSurfaceImpl
*surface
= parent
;
5025 TRACE("surface %p.\n", surface
);
5027 /* Check for attached surfaces and detach them. */
5028 if (surface
->first_attached
!= surface
)
5030 IDirectDrawSurface7
*root
= &surface
->first_attached
->IDirectDrawSurface7_iface
;
5031 IDirectDrawSurface7
*detach
= &surface
->IDirectDrawSurface7_iface
;
5033 /* Well, this shouldn't happen: The surface being attached is
5034 * referenced in AddAttachedSurface(), so it shouldn't be released
5035 * until DeleteAttachedSurface() is called, because the refcount is
5036 * held. It looks like the application released it often enough to
5038 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5040 /* The refcount will drop to -1 here */
5041 if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
)))
5042 ERR("DeleteAttachedSurface failed.\n");
5045 while (surface
->next_attached
)
5047 IDirectDrawSurface7
*root
= &surface
->IDirectDrawSurface7_iface
;
5048 IDirectDrawSurface7
*detach
= &surface
->next_attached
->IDirectDrawSurface7_iface
;
5050 if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
)))
5051 ERR("DeleteAttachedSurface failed.\n");
5054 /* Having a texture handle set implies that the device still exists. */
5055 if (surface
->Handle
)
5056 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5058 /* Reduce the ddraw surface count. */
5059 InterlockedDecrement(&surface
->ddraw
->surfaces
);
5060 list_remove(&surface
->surface_list_entry
);
5062 HeapFree(GetProcessHeap(), 0, surface
);
5065 const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5067 ddraw_surface_wined3d_object_destroyed
,
5070 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5072 IDirectDrawSurfaceImpl
*surface
= parent
;
5074 TRACE("surface %p.\n", surface
);
5076 ddraw_surface_cleanup(surface
);
5079 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5081 ddraw_texture_wined3d_object_destroyed
,
5084 HRESULT
ddraw_surface_create_texture(IDirectDrawSurfaceImpl
*surface
)
5086 const DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
5087 enum wined3d_format_id format
;
5091 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5092 levels
= desc
->u2
.dwMipMapCount
;
5096 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM.
5097 * Should I forward the MANAGED cap to the managed pool? */
5098 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5099 pool
= WINED3DPOOL_SYSTEMMEM
;
5101 pool
= WINED3DPOOL_DEFAULT
;
5103 format
= PixelFormat_DD2WineD3D(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
5104 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5105 return wined3d_texture_create_cube(surface
->ddraw
->wined3d_device
, desc
->dwWidth
,
5106 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5108 return wined3d_texture_create_2d(surface
->ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
,
5109 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5112 HRESULT
ddraw_surface_init(IDirectDrawSurfaceImpl
*surface
, IDirectDrawImpl
*ddraw
,
5113 DDSURFACEDESC2
*desc
, UINT mip_level
, WINED3DSURFTYPE surface_type
, UINT version
)
5115 struct wined3d_resource_desc wined3d_desc
;
5116 struct wined3d_resource
*wined3d_resource
;
5117 WINED3DPOOL pool
= WINED3DPOOL_DEFAULT
;
5118 enum wined3d_format_id format
;
5122 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5123 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5124 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)))
5126 /* Tests show surfaces without memory flags get these flags added
5127 * right after creation. */
5128 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5131 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5133 usage
|= WINED3DUSAGE_RENDERTARGET
;
5134 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5137 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5139 usage
|= WINED3DUSAGE_RENDERTARGET
;
5142 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
5144 usage
|= WINED3DUSAGE_OVERLAY
;
5147 if (ddraw
->depthstencil
|| (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5149 /* The depth stencil creation callback sets this flag. Set the
5150 * wined3d usage to let it know it's a depth/stencil surface. */
5151 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5154 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5156 pool
= WINED3DPOOL_SYSTEMMEM
;
5158 else if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
5160 pool
= WINED3DPOOL_MANAGED
;
5161 /* Managed textures have the system memory flag set. */
5162 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5164 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5166 /* Videomemory adds localvidmem. This is mutually exclusive with
5167 * systemmemory and texturemanage. */
5168 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5171 format
= PixelFormat_DD2WineD3D(&desc
->u4
.ddpfPixelFormat
);
5172 if (format
== WINED3DFMT_UNKNOWN
)
5174 WARN("Unsupported / unknown pixelformat.\n");
5175 return DDERR_INVALIDPIXELFORMAT
;
5178 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
5179 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
5180 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
5181 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
5182 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
5183 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
5184 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
5185 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
5186 surface
->iface_count
= 1;
5187 surface
->version
= version
;
5188 surface
->ddraw
= ddraw
;
5194 else if (version
== 4)
5203 copy_to_surfacedesc2(&surface
->surface_desc
, desc
);
5205 surface
->first_attached
= surface
;
5206 surface
->ImplType
= surface_type
;
5208 hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
, format
,
5209 TRUE
/* Lockable */, FALSE
/* Discard */, mip_level
, usage
, pool
,
5210 WINED3DMULTISAMPLE_NONE
, 0 /* MultiSampleQuality */, surface_type
, surface
,
5211 &ddraw_surface_wined3d_parent_ops
, &surface
->wined3d_surface
);
5214 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
5218 surface
->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5219 wined3d_resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
5220 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
5222 format
= wined3d_desc
.format
;
5223 if (format
== WINED3DFMT_UNKNOWN
)
5225 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN.\n");
5227 PixelFormat_WineD3DtoDD(&surface
->surface_desc
.u4
.ddpfPixelFormat
, format
);
5229 /* Anno 1602 stores the pitch right after surface creation, so make sure
5230 * it's there. TODO: Test other fourcc formats. */
5231 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
5232 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
5234 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
5235 if (format
== WINED3DFMT_DXT1
)
5237 surface
->surface_desc
.u1
.dwLinearSize
= max(4, wined3d_desc
.width
) * max(4, wined3d_desc
.height
) / 2;
5241 surface
->surface_desc
.u1
.dwLinearSize
= max(4, wined3d_desc
.width
) * max(4, wined3d_desc
.height
);
5246 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
5247 surface
->surface_desc
.u1
.lPitch
= wined3d_surface_get_pitch(surface
->wined3d_surface
);
5250 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
5252 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
5253 (WINEDDCOLORKEY
*)&desc
->u3
.ddckCKDestOverlay
);
5255 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
5257 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTBLT
,
5258 (WINEDDCOLORKEY
*)&desc
->ddckCKDestBlt
);
5260 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
5262 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
5263 (WINEDDCOLORKEY
*)&desc
->ddckCKSrcOverlay
);
5265 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
5267 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCBLT
,
5268 (WINEDDCOLORKEY
*)&desc
->ddckCKSrcBlt
);
5270 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5272 hr
= wined3d_surface_set_mem(surface
->wined3d_surface
, desc
->lpSurface
);
5275 ERR("Failed to set surface memory, hr %#x.\n", hr
);
5276 wined3d_surface_decref(surface
->wined3d_surface
);