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_vtbl
;
145 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
149 *obj
= &This
->IDirect3DTexture2_vtbl
;
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
= surface_from_texture2(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
= surface_from_texture1(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
= surface_from_texture2(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
= surface_from_texture1(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
= surface_from_texture2(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
= surface_from_texture1(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 /* Sizes can change, therefore hold the lock when testing the rectangles */
1215 EnterCriticalSection(&ddraw_cs
);
1218 if(DestRect
->top
>= DestRect
->bottom
|| DestRect
->left
>= DestRect
->right
||
1219 DestRect
->right
> This
->surface_desc
.dwWidth
||
1220 DestRect
->bottom
> This
->surface_desc
.dwHeight
)
1222 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
1223 LeaveCriticalSection(&ddraw_cs
);
1224 return DDERR_INVALIDRECT
;
1229 if(SrcRect
->top
>= SrcRect
->bottom
|| SrcRect
->left
>=SrcRect
->right
||
1230 SrcRect
->right
> Src
->surface_desc
.dwWidth
||
1231 SrcRect
->bottom
> Src
->surface_desc
.dwHeight
)
1233 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
1234 LeaveCriticalSection(&ddraw_cs
);
1235 return DDERR_INVALIDRECT
;
1239 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
1240 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1241 LeaveCriticalSection(&ddraw_cs
);
1242 return DDERR_INVALIDPARAMS
;
1245 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1246 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1247 * surfaces. So far no blitting operations using surfaces in the bltfx
1248 * struct are supported anyway. */
1249 hr
= wined3d_surface_blt(This
->wined3d_surface
, DestRect
, Src
? Src
->wined3d_surface
: NULL
,
1250 SrcRect
, Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3DTEXF_LINEAR
);
1252 LeaveCriticalSection(&ddraw_cs
);
1255 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1256 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1261 static HRESULT WINAPI
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1262 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1264 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1265 IDirectDrawSurfaceImpl
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1266 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1267 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1269 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1270 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1273 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1274 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1276 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1277 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1278 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1279 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1281 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1282 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1285 static HRESULT WINAPI
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1286 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1288 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1289 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1290 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1291 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1293 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1294 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1297 static HRESULT WINAPI
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1298 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1300 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1301 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1302 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1303 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1305 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1306 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1309 /*****************************************************************************
1310 * IDirectDrawSurface7::AddAttachedSurface
1312 * Attaches a surface to another surface. How the surface attachments work
1313 * is not totally understood yet, and this method is prone to problems.
1314 * he surface that is attached is AddRef-ed.
1316 * Tests with complex surfaces suggest that the surface attachments form a
1317 * tree, but no method to test this has been found yet.
1319 * The attachment list consists of a first surface (first_attached) and
1320 * for each surface a pointer to the next attached surface (next_attached).
1321 * For the first surface, and a surface that has no attachments
1322 * first_attached points to the surface itself. A surface that has
1323 * no successors in the chain has next_attached set to NULL.
1325 * Newly attached surfaces are attached right after the root surface.
1326 * If a surface is attached to a complex surface compound, it's attached to
1327 * the surface that the app requested, not the complex root. See
1328 * GetAttachedSurface for a description how surfaces are found.
1330 * This is how the current implementation works, and it was coded by looking
1331 * at the needs of the applications.
1333 * So far only Z-Buffer attachments are tested, and they are activated in
1334 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1335 * Back buffers should work in 2D mode, but they are not tested(They can be
1336 * attached in older iface versions). Rendering to the front buffer and
1337 * switching between that and double buffering is not yet implemented in
1338 * WineD3D, so for 3D it might have unexpected results.
1340 * ddraw_surface_attach_surface is the real thing,
1341 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1342 * performs additional checks. Version 7 of this interface is much more restrictive
1343 * than its predecessors.
1346 * Attach: Surface to attach to iface
1350 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1352 *****************************************************************************/
1353 static HRESULT
ddraw_surface_attach_surface(IDirectDrawSurfaceImpl
*This
, IDirectDrawSurfaceImpl
*Surf
)
1355 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1358 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1360 EnterCriticalSection(&ddraw_cs
);
1362 /* Check if the surface is already attached somewhere */
1363 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1365 /* TODO: Test for the structure of the manual attachment. Is it a
1366 * chain or a list? What happens if one surface is attached to 2
1367 * different surfaces? */
1368 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1369 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1371 LeaveCriticalSection(&ddraw_cs
);
1372 return DDERR_SURFACEALREADYATTACHED
;
1375 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1376 Surf
->next_attached
= This
->next_attached
;
1377 Surf
->first_attached
= This
->first_attached
;
1378 This
->next_attached
= Surf
;
1380 /* Check if the WineD3D depth stencil needs updating */
1381 if(This
->ddraw
->d3ddevice
)
1383 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1386 LeaveCriticalSection(&ddraw_cs
);
1390 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*Attach
)
1392 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1393 IDirectDrawSurfaceImpl
*Surf
= unsafe_impl_from_IDirectDrawSurface7(Attach
);
1396 TRACE("iface %p, attachment %p.\n", iface
, Attach
);
1398 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1399 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1402 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1403 Surf
->surface_desc
.ddsCaps
.dwCaps
);
1404 return DDERR_CANNOTATTACHSURFACE
;
1407 hr
= ddraw_surface_attach_surface(This
, Surf
);
1412 ddraw_surface7_AddRef(Attach
);
1416 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1418 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1419 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1422 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1424 hr
= ddraw_surface7_AddAttachedSurface(&This
->IDirectDrawSurface7_iface
,
1425 attachment_impl
? &attachment_impl
->IDirectDrawSurface7_iface
: NULL
);
1430 ddraw_surface4_AddRef(attachment
);
1431 ddraw_surface7_Release(&attachment_impl
->IDirectDrawSurface7_iface
);
1434 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1436 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1437 IDirectDrawSurfaceImpl
*attach_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1440 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1442 /* Tests suggest that
1443 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1444 * -> offscreen plain surfaces can be attached to primaries
1445 * -> primaries can be attached to offscreen plain surfaces
1446 * -> z buffers can be attached to primaries */
1447 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1448 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1450 /* Sizes have to match */
1451 if (attach_impl
->surface_desc
.dwWidth
!= This
->surface_desc
.dwWidth
1452 || attach_impl
->surface_desc
.dwHeight
!= This
->surface_desc
.dwHeight
)
1454 WARN("Surface sizes do not match.\n");
1455 return DDERR_CANNOTATTACHSURFACE
;
1459 else if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1460 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1466 WARN("Invalid attachment combination.\n");
1467 return DDERR_CANNOTATTACHSURFACE
;
1470 hr
= ddraw_surface_attach_surface(This
, attach_impl
);
1475 ddraw_surface3_AddRef(attachment
);
1479 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1481 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1482 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1485 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1487 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1488 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1493 ddraw_surface2_AddRef(attachment
);
1494 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1498 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1500 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1501 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1504 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1506 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1507 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1512 ddraw_surface1_AddRef(attachment
);
1513 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1517 /*****************************************************************************
1518 * IDirectDrawSurface7::DeleteAttachedSurface
1520 * Removes a surface from the attachment chain. The surface's refcount
1521 * is decreased by one after it has been removed
1524 * Flags: Some flags, not used by this implementation
1525 * Attach: Surface to detach
1529 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1531 *****************************************************************************/
1532 static HRESULT
ddraw_surface_delete_attached_surface(IDirectDrawSurfaceImpl
*This
,
1533 IDirectDrawSurfaceImpl
*Surf
)
1535 IDirectDrawSurfaceImpl
*Prev
= This
;
1537 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1539 EnterCriticalSection(&ddraw_cs
);
1540 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
1542 LeaveCriticalSection(&ddraw_cs
);
1543 return DDERR_CANNOTDETACHSURFACE
;
1546 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1547 if (This
->surface_desc
.ddsCaps
.dwCaps
&
1548 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1550 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1551 /* FIXME: we should probably also subtract from dwMipMapCount of this
1552 * and all parent surfaces */
1555 /* Find the predecessor of the detached surface */
1558 if(Prev
->next_attached
== Surf
) break;
1559 Prev
= Prev
->next_attached
;
1562 /* There must be a surface, otherwise there's a bug */
1563 assert(Prev
!= NULL
);
1565 /* Unchain the surface */
1566 Prev
->next_attached
= Surf
->next_attached
;
1567 Surf
->next_attached
= NULL
;
1568 Surf
->first_attached
= Surf
;
1570 /* Check if the WineD3D depth stencil needs updating */
1571 if(This
->ddraw
->d3ddevice
)
1573 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1575 LeaveCriticalSection(&ddraw_cs
);
1579 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1580 DWORD flags
, IDirectDrawSurface7
*attachment
)
1582 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1583 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1586 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1588 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1593 ddraw_surface7_Release(attachment
);
1597 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1598 DWORD flags
, IDirectDrawSurface4
*attachment
)
1600 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1601 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1604 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1606 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1611 ddraw_surface4_Release(attachment
);
1615 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1616 DWORD flags
, IDirectDrawSurface3
*attachment
)
1618 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1619 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1621 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1623 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1628 ddraw_surface3_Release(attachment
);
1632 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
1633 DWORD flags
, IDirectDrawSurface2
*attachment
)
1635 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1636 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1638 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1640 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1645 ddraw_surface2_Release(attachment
);
1649 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
1650 DWORD flags
, IDirectDrawSurface
*attachment
)
1652 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1653 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1655 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1657 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1662 ddraw_surface1_Release(attachment
);
1666 /*****************************************************************************
1667 * IDirectDrawSurface7::AddOverlayDirtyRect
1669 * "This method is not currently implemented"
1677 *****************************************************************************/
1678 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1680 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1682 return DDERR_UNSUPPORTED
; /* unchecked */
1685 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
1687 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1688 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1690 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1693 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1695 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1696 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1698 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1701 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
1703 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1704 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1706 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1709 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
1711 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1712 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1714 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1717 /*****************************************************************************
1718 * IDirectDrawSurface7::GetDC
1720 * Returns a GDI device context for the surface
1723 * hdc: Address of a HDC variable to store the dc to
1727 * DDERR_INVALIDPARAMS if hdc is NULL
1728 * For details, see IWineD3DSurface::GetDC
1730 *****************************************************************************/
1731 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1733 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1736 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1739 return DDERR_INVALIDPARAMS
;
1741 EnterCriticalSection(&ddraw_cs
);
1742 hr
= wined3d_surface_getdc(This
->wined3d_surface
, hdc
);
1743 LeaveCriticalSection(&ddraw_cs
);
1746 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1749 case WINED3DERR_INVALIDCALL
:
1750 if(hdc
) *hdc
= NULL
;
1751 return DDERR_INVALIDPARAMS
;
1757 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
1759 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1760 TRACE("iface %p, dc %p.\n", iface
, dc
);
1762 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1765 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1767 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1768 TRACE("iface %p, dc %p.\n", iface
, dc
);
1770 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1773 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
1775 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1776 TRACE("iface %p, dc %p.\n", iface
, dc
);
1778 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1781 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
1783 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1784 TRACE("iface %p, dc %p.\n", iface
, dc
);
1786 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1789 /*****************************************************************************
1790 * IDirectDrawSurface7::ReleaseDC
1792 * Releases the DC that was constructed with GetDC
1795 * hdc: HDC to release
1799 * For more details, see IWineD3DSurface::ReleaseDC
1801 *****************************************************************************/
1802 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
1804 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1807 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1809 EnterCriticalSection(&ddraw_cs
);
1810 hr
= wined3d_surface_releasedc(This
->wined3d_surface
, hdc
);
1811 LeaveCriticalSection(&ddraw_cs
);
1815 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
1817 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1818 TRACE("iface %p, dc %p.\n", iface
, dc
);
1820 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1823 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
1825 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1826 TRACE("iface %p, dc %p.\n", iface
, dc
);
1828 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1831 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
1833 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1834 TRACE("iface %p, dc %p.\n", iface
, dc
);
1836 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1839 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
1841 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1842 TRACE("iface %p, dc %p.\n", iface
, dc
);
1844 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1847 /*****************************************************************************
1848 * IDirectDrawSurface7::GetCaps
1850 * Returns the surface's caps
1853 * Caps: Address to write the caps to
1857 * DDERR_INVALIDPARAMS if Caps is NULL
1859 *****************************************************************************/
1860 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
1862 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1864 TRACE("iface %p, caps %p.\n", iface
, Caps
);
1867 return DDERR_INVALIDPARAMS
;
1869 *Caps
= This
->surface_desc
.ddsCaps
;
1873 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
1875 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1876 TRACE("iface %p, caps %p.\n", iface
, caps
);
1878 return ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, caps
);
1881 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
1883 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1887 TRACE("iface %p, caps %p.\n", iface
, caps
);
1889 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1890 if (FAILED(hr
)) return hr
;
1892 caps
->dwCaps
= caps2
.dwCaps
;
1896 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
1898 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1902 TRACE("iface %p, caps %p.\n", iface
, caps
);
1904 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1905 if (FAILED(hr
)) return hr
;
1907 caps
->dwCaps
= caps2
.dwCaps
;
1911 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
1913 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1917 TRACE("iface %p, caps %p.\n", iface
, caps
);
1919 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1920 if (FAILED(hr
)) return hr
;
1922 caps
->dwCaps
= caps2
.dwCaps
;
1926 /*****************************************************************************
1927 * IDirectDrawSurface7::SetPriority
1929 * Sets a texture priority for managed textures.
1932 * Priority: The new priority
1936 * For more details, see IWineD3DSurface::SetPriority
1938 *****************************************************************************/
1939 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1941 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1944 TRACE("iface %p, priority %u.\n", iface
, Priority
);
1946 EnterCriticalSection(&ddraw_cs
);
1947 hr
= wined3d_surface_set_priority(This
->wined3d_surface
, Priority
);
1948 LeaveCriticalSection(&ddraw_cs
);
1952 /*****************************************************************************
1953 * IDirectDrawSurface7::GetPriority
1955 * Returns the surface's priority
1958 * Priority: Address of a variable to write the priority to
1962 * DDERR_INVALIDPARAMS if Priority == NULL
1963 * For more details, see IWineD3DSurface::GetPriority
1965 *****************************************************************************/
1966 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
1968 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1970 TRACE("iface %p, priority %p.\n", iface
, Priority
);
1974 return DDERR_INVALIDPARAMS
;
1977 EnterCriticalSection(&ddraw_cs
);
1978 *Priority
= wined3d_surface_get_priority(This
->wined3d_surface
);
1979 LeaveCriticalSection(&ddraw_cs
);
1983 /*****************************************************************************
1984 * IDirectDrawSurface7::SetPrivateData
1986 * Stores some data in the surface that is intended for the application's
1990 * tag: GUID that identifies the data
1991 * Data: Pointer to the private data
1992 * Size: Size of the private data
1997 * For more details, see IWineD3DSurface::SetPrivateData
1999 *****************************************************************************/
2000 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2001 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
2003 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2004 struct wined3d_resource
*resource
;
2007 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2008 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
2010 EnterCriticalSection(&ddraw_cs
);
2011 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2012 hr
= wined3d_resource_set_private_data(resource
, tag
, Data
, Size
, Flags
);
2013 LeaveCriticalSection(&ddraw_cs
);
2016 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2021 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2022 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2024 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2025 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2026 iface
, debugstr_guid(tag
), data
, size
, flags
);
2028 return ddraw_surface7_SetPrivateData(&This
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2031 /*****************************************************************************
2032 * IDirectDrawSurface7::GetPrivateData
2034 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2037 * tag: GUID of the data to return
2038 * Data: Address where to write the data to
2039 * Size: Size of the buffer at Data
2043 * DDERR_INVALIDPARAMS if Data is NULL
2044 * For more details, see IWineD3DSurface::GetPrivateData
2046 *****************************************************************************/
2047 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
2049 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2050 struct wined3d_resource
*resource
;
2053 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2054 iface
, debugstr_guid(tag
), Data
, Size
);
2057 return DDERR_INVALIDPARAMS
;
2059 EnterCriticalSection(&ddraw_cs
);
2060 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2061 hr
= wined3d_resource_get_private_data(resource
, tag
, Data
, Size
);
2062 LeaveCriticalSection(&ddraw_cs
);
2066 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2068 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2069 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2070 iface
, debugstr_guid(tag
), data
, size
);
2072 return ddraw_surface7_GetPrivateData(&This
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2075 /*****************************************************************************
2076 * IDirectDrawSurface7::FreePrivateData
2078 * Frees private data stored in the surface
2081 * tag: Tag of the data to free
2085 * For more details, see IWineD3DSurface::FreePrivateData
2087 *****************************************************************************/
2088 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2090 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2091 struct wined3d_resource
*resource
;
2094 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2096 EnterCriticalSection(&ddraw_cs
);
2097 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2098 hr
= wined3d_resource_free_private_data(resource
, tag
);
2099 LeaveCriticalSection(&ddraw_cs
);
2103 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2105 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2106 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2108 return ddraw_surface7_FreePrivateData(&This
->IDirectDrawSurface7_iface
, tag
);
2111 /*****************************************************************************
2112 * IDirectDrawSurface7::PageLock
2114 * Prevents a sysmem surface from being paged out
2117 * Flags: Not used, must be 0(unchecked)
2120 * DD_OK, because it's a stub
2122 *****************************************************************************/
2123 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2125 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2127 /* This is Windows memory management related - we don't need this */
2131 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2133 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2134 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2136 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2139 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2141 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2142 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2144 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2147 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2149 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2150 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2152 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2155 /*****************************************************************************
2156 * IDirectDrawSurface7::PageUnlock
2158 * Allows a sysmem surface to be paged out
2161 * Flags: Not used, must be 0(unchecked)
2164 * DD_OK, because it's a stub
2166 *****************************************************************************/
2167 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2169 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2174 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2176 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2177 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2179 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2182 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2184 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2185 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2187 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2190 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2192 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2193 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2195 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2198 /*****************************************************************************
2199 * IDirectDrawSurface7::BltBatch
2201 * An unimplemented function
2209 *****************************************************************************/
2210 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2212 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2214 /* MSDN: "not currently implemented" */
2215 return DDERR_UNSUPPORTED
;
2218 static HRESULT WINAPI
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2220 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2221 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2223 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2226 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2228 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2229 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2231 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2234 static HRESULT WINAPI
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2236 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2237 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2239 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2242 static HRESULT WINAPI
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2244 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2245 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2247 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2250 /*****************************************************************************
2251 * IDirectDrawSurface7::EnumAttachedSurfaces
2253 * Enumerates all surfaces attached to this surface
2256 * context: Pointer to pass unmodified to the callback
2257 * cb: Callback function to call for each surface
2261 * DDERR_INVALIDPARAMS if cb is NULL
2263 *****************************************************************************/
2264 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2265 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2267 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2268 IDirectDrawSurfaceImpl
*surf
;
2269 DDSURFACEDESC2 desc
;
2272 /* Attached surfaces aren't handled in WineD3D */
2273 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2276 return DDERR_INVALIDPARAMS
;
2278 EnterCriticalSection(&ddraw_cs
);
2279 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2281 surf
= This
->complex_array
[i
];
2284 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2285 desc
= surf
->surface_desc
;
2286 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2287 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2289 LeaveCriticalSection(&ddraw_cs
);
2294 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2296 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2297 desc
= surf
->surface_desc
;
2298 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2299 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2301 LeaveCriticalSection(&ddraw_cs
);
2306 TRACE(" end of enumeration.\n");
2308 LeaveCriticalSection(&ddraw_cs
);
2312 struct callback_info2
2314 LPDDENUMSURFACESCALLBACK2 callback
;
2318 struct callback_info
2320 LPDDENUMSURFACESCALLBACK callback
;
2324 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2326 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(surface
);
2327 const struct callback_info2
*info
= context
;
2329 ddraw_surface4_AddRef(&This
->IDirectDrawSurface4_iface
);
2330 ddraw_surface7_Release(surface
);
2332 return info
->callback(&This
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2335 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2337 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2338 const struct callback_info
*info
= context
;
2340 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2341 ddraw_surface7_Release(surface
);
2343 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2344 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2347 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2348 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2350 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2351 struct callback_info2 info
;
2353 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2355 info
.callback
= callback
;
2356 info
.context
= context
;
2358 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2359 &info
, EnumCallback2
);
2362 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2363 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2365 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2366 struct callback_info info
;
2368 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2370 info
.callback
= callback
;
2371 info
.context
= context
;
2373 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2374 &info
, EnumCallback
);
2377 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2378 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2380 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2381 struct callback_info info
;
2383 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2385 info
.callback
= callback
;
2386 info
.context
= context
;
2388 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2389 &info
, EnumCallback
);
2392 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2393 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2395 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2396 struct callback_info info
;
2398 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2400 info
.callback
= callback
;
2401 info
.context
= context
;
2403 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2404 &info
, EnumCallback
);
2407 /*****************************************************************************
2408 * IDirectDrawSurface7::EnumOverlayZOrders
2410 * "Enumerates the overlay surfaces on the specified destination"
2413 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2414 * context: context to pass back to the callback
2415 * cb: callback function to call for each enumerated surface
2418 * DD_OK, because it's a stub
2420 *****************************************************************************/
2421 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2422 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2424 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2429 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2430 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2432 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2433 struct callback_info2 info
;
2435 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2437 info
.callback
= callback
;
2438 info
.context
= context
;
2440 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2441 flags
, &info
, EnumCallback2
);
2444 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2445 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2447 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2448 struct callback_info info
;
2450 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2452 info
.callback
= callback
;
2453 info
.context
= context
;
2455 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2456 flags
, &info
, EnumCallback
);
2459 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2460 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2462 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2463 struct callback_info info
;
2465 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2467 info
.callback
= callback
;
2468 info
.context
= context
;
2470 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2471 flags
, &info
, EnumCallback
);
2474 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2475 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2477 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2478 struct callback_info info
;
2480 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2482 info
.callback
= callback
;
2483 info
.context
= context
;
2485 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2486 flags
, &info
, EnumCallback
);
2489 /*****************************************************************************
2490 * IDirectDrawSurface7::GetBltStatus
2492 * Returns the blitting status
2495 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2498 * See IWineD3DSurface::Blt
2500 *****************************************************************************/
2501 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2503 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2506 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2508 EnterCriticalSection(&ddraw_cs
);
2509 hr
= wined3d_surface_get_blt_status(This
->wined3d_surface
, Flags
);
2510 LeaveCriticalSection(&ddraw_cs
);
2513 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2518 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2520 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2521 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2523 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2526 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2528 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2529 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2531 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2534 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2536 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2537 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2539 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2542 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2544 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2545 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2547 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2550 /*****************************************************************************
2551 * IDirectDrawSurface7::GetColorKey
2553 * Returns the color key assigned to the surface
2557 * CKey: Address to store the key to
2561 * DDERR_INVALIDPARAMS if CKey is NULL
2563 *****************************************************************************/
2564 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2566 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2568 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2571 return DDERR_INVALIDPARAMS
;
2573 EnterCriticalSection(&ddraw_cs
);
2577 case DDCKEY_DESTBLT
:
2578 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
2580 LeaveCriticalSection(&ddraw_cs
);
2581 return DDERR_NOCOLORKEY
;
2583 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
2586 case DDCKEY_DESTOVERLAY
:
2587 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
2589 LeaveCriticalSection(&ddraw_cs
);
2590 return DDERR_NOCOLORKEY
;
2592 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
2596 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
2598 LeaveCriticalSection(&ddraw_cs
);
2599 return DDERR_NOCOLORKEY
;
2601 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
2604 case DDCKEY_SRCOVERLAY
:
2605 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
2607 LeaveCriticalSection(&ddraw_cs
);
2608 return DDERR_NOCOLORKEY
;
2610 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
2614 LeaveCriticalSection(&ddraw_cs
);
2615 return DDERR_INVALIDPARAMS
;
2618 LeaveCriticalSection(&ddraw_cs
);
2622 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2624 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2625 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2627 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2630 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2632 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2633 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2635 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2638 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2640 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2641 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2643 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2646 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2648 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2649 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2651 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2654 /*****************************************************************************
2655 * IDirectDrawSurface7::GetFlipStatus
2657 * Returns the flipping status of the surface
2660 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2663 * See IWineD3DSurface::GetFlipStatus
2665 *****************************************************************************/
2666 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2668 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2671 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2673 EnterCriticalSection(&ddraw_cs
);
2674 hr
= wined3d_surface_get_flip_status(This
->wined3d_surface
, Flags
);
2675 LeaveCriticalSection(&ddraw_cs
);
2678 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2683 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2685 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2686 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2688 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2691 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2693 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2694 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2696 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2699 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2701 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2702 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2704 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2707 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2709 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2710 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2712 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2715 /*****************************************************************************
2716 * IDirectDrawSurface7::GetOverlayPosition
2718 * Returns the display coordinates of a visible and active overlay surface
2725 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
2726 *****************************************************************************/
2727 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
2729 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2732 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
2734 EnterCriticalSection(&ddraw_cs
);
2735 hr
= wined3d_surface_get_overlay_position(This
->wined3d_surface
, X
, Y
);
2736 LeaveCriticalSection(&ddraw_cs
);
2740 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
2742 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2743 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2745 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2748 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
2750 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2751 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2753 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2756 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
2758 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2759 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2761 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2764 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
2766 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2767 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2769 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2772 /*****************************************************************************
2773 * IDirectDrawSurface7::GetPixelFormat
2775 * Returns the pixel format of the Surface
2778 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
2779 * format should be written
2783 * DDERR_INVALIDPARAMS if PixelFormat is NULL
2785 *****************************************************************************/
2786 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
2788 /* What is DDERR_INVALIDSURFACETYPE for here? */
2789 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2791 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
2794 return DDERR_INVALIDPARAMS
;
2796 EnterCriticalSection(&ddraw_cs
);
2797 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
2798 LeaveCriticalSection(&ddraw_cs
);
2803 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
2805 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2806 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2808 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2811 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
2813 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2814 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2816 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2819 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
2821 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2822 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2824 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2827 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
2829 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2830 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2832 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2835 /*****************************************************************************
2836 * IDirectDrawSurface7::GetSurfaceDesc
2838 * Returns the description of this surface
2841 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
2846 * DDERR_INVALIDPARAMS if DDSD is NULL
2848 *****************************************************************************/
2849 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
2851 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2853 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2856 return DDERR_INVALIDPARAMS
;
2858 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
2860 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
2861 return DDERR_INVALIDPARAMS
;
2864 EnterCriticalSection(&ddraw_cs
);
2865 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
2866 TRACE("Returning surface desc:\n");
2867 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
2869 LeaveCriticalSection(&ddraw_cs
);
2873 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
2875 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2876 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2878 return ddraw_surface7_GetSurfaceDesc(&This
->IDirectDrawSurface7_iface
, DDSD
);
2881 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
2883 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2885 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
2887 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
2889 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2891 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
2892 return DDERR_INVALIDPARAMS
;
2895 EnterCriticalSection(&ddraw_cs
);
2896 DD_STRUCT_COPY_BYSIZE(surface_desc
, (DDSURFACEDESC
*)&This
->surface_desc
);
2897 TRACE("Returning surface desc:\n");
2898 if (TRACE_ON(ddraw
))
2900 /* DDRAW_dump_surface_desc handles the smaller size */
2901 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2904 LeaveCriticalSection(&ddraw_cs
);
2908 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
2910 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2911 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2913 return ddraw_surface3_GetSurfaceDesc(&This
->IDirectDrawSurface3_iface
, DDSD
);
2916 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
2918 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2919 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2921 return ddraw_surface3_GetSurfaceDesc(&This
->IDirectDrawSurface3_iface
, DDSD
);
2924 /*****************************************************************************
2925 * IDirectDrawSurface7::Initialize
2927 * Initializes the surface. This is a no-op in Wine
2930 * DD: Pointer to an DirectDraw interface
2931 * DDSD: Surface description for initialization
2934 * DDERR_ALREADYINITIALIZED
2936 *****************************************************************************/
2937 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
2938 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
2940 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2942 return DDERR_ALREADYINITIALIZED
;
2945 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
2946 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
2948 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2949 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2951 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2952 ddraw
, surface_desc
);
2955 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
2956 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2958 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2959 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2961 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2962 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
2965 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
2966 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2968 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2969 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2971 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2972 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
2975 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
2976 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2978 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2979 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2981 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2982 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
2985 /*****************************************************************************
2986 * IDirect3DTexture1::Initialize
2988 * The sdk says it's not implemented
2996 *****************************************************************************/
2997 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
2998 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3000 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3002 return DDERR_UNSUPPORTED
; /* Unchecked */
3005 /*****************************************************************************
3006 * IDirectDrawSurface7::IsLost
3008 * Checks if the surface is lost
3011 * DD_OK, if the surface is usable
3012 * DDERR_ISLOST if the surface is lost
3013 * See IWineD3DSurface::IsLost for more details
3015 *****************************************************************************/
3016 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3018 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3021 TRACE("iface %p.\n", iface
);
3023 EnterCriticalSection(&ddraw_cs
);
3024 /* We lose the surface if the implementation was changed */
3025 if(This
->ImplType
!= This
->ddraw
->ImplType
)
3027 /* But this shouldn't happen. When we change the implementation,
3028 * all surfaces are re-created automatically, and their content
3031 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
3032 LeaveCriticalSection(&ddraw_cs
);
3033 return DDERR_SURFACELOST
;
3036 hr
= wined3d_surface_is_lost(This
->wined3d_surface
);
3037 LeaveCriticalSection(&ddraw_cs
);
3040 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3041 * WineD3D uses the same error for surfaces
3043 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3048 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3050 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3051 TRACE("iface %p.\n", iface
);
3053 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3056 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3058 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3059 TRACE("iface %p.\n", iface
);
3061 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3064 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3066 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3067 TRACE("iface %p.\n", iface
);
3069 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3072 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3074 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3075 TRACE("iface %p.\n", iface
);
3077 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3080 /*****************************************************************************
3081 * IDirectDrawSurface7::Restore
3083 * Restores a lost surface. This makes the surface usable again, but
3084 * doesn't reload its old contents
3088 * See IWineD3DSurface::Restore for more details
3090 *****************************************************************************/
3091 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3093 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3096 TRACE("iface %p.\n", iface
);
3098 EnterCriticalSection(&ddraw_cs
);
3099 if(This
->ImplType
!= This
->ddraw
->ImplType
)
3101 /* Call the recreation callback. Make sure to AddRef first */
3102 IDirectDrawSurface_AddRef(iface
);
3103 ddraw_recreate_surfaces_cb(iface
, &This
->surface_desc
, NULL
/* Not needed */);
3105 hr
= wined3d_surface_restore(This
->wined3d_surface
);
3106 LeaveCriticalSection(&ddraw_cs
);
3110 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3112 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3113 TRACE("iface %p.\n", iface
);
3115 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3118 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3120 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3121 TRACE("iface %p.\n", iface
);
3123 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3126 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3128 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3129 TRACE("iface %p.\n", iface
);
3131 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3134 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3136 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3137 TRACE("iface %p.\n", iface
);
3139 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3142 /*****************************************************************************
3143 * IDirectDrawSurface7::SetOverlayPosition
3145 * Changes the display coordinates of an overlay surface
3152 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3153 *****************************************************************************/
3154 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3156 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3159 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3161 EnterCriticalSection(&ddraw_cs
);
3162 hr
= wined3d_surface_set_overlay_position(This
->wined3d_surface
, X
, Y
);
3163 LeaveCriticalSection(&ddraw_cs
);
3167 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3169 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3170 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3172 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3175 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3177 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3178 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3180 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3183 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3185 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3186 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3188 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3191 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3193 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3194 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3196 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3199 /*****************************************************************************
3200 * IDirectDrawSurface7::UpdateOverlay
3202 * Modifies the attributes of an overlay surface.
3205 * SrcRect: The section of the source being used for the overlay
3206 * DstSurface: Address of the surface that is overlaid
3207 * DstRect: Place of the overlay
3208 * Flags: some DDOVER_* flags
3211 * DDERR_UNSUPPORTED, because we don't support overlays
3213 *****************************************************************************/
3214 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3215 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3217 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3218 IDirectDrawSurfaceImpl
*Dst
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3221 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3222 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3224 EnterCriticalSection(&ddraw_cs
);
3225 hr
= wined3d_surface_update_overlay(This
->wined3d_surface
, SrcRect
,
3226 Dst
? Dst
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3227 LeaveCriticalSection(&ddraw_cs
);
3229 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3230 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3231 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3237 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3238 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3240 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3241 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3242 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3243 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3245 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3246 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3249 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3250 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3252 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3253 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3254 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3255 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3257 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3258 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3261 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3262 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3264 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3265 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3266 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3267 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3269 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3270 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3273 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3274 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3276 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3277 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3278 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3279 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3281 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3282 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3285 /*****************************************************************************
3286 * IDirectDrawSurface7::UpdateOverlayDisplay
3288 * The DX7 sdk says that it's not implemented
3293 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3295 *****************************************************************************/
3296 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3298 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3300 return DDERR_UNSUPPORTED
;
3303 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3305 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3306 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3308 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3311 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3313 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3314 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3316 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3319 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3321 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3322 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3324 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3327 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3329 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3330 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3332 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3335 /*****************************************************************************
3336 * IDirectDrawSurface7::UpdateOverlayZOrder
3338 * Sets an overlay's Z order
3341 * Flags: DDOVERZ_* flags
3342 * DDSRef: Defines the relative position in the overlay chain
3345 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3347 *****************************************************************************/
3348 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3349 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3351 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3352 IDirectDrawSurfaceImpl
*Ref
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3355 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3357 EnterCriticalSection(&ddraw_cs
);
3358 hr
= wined3d_surface_update_overlay_z_order(This
->wined3d_surface
,
3359 Flags
, Ref
? Ref
->wined3d_surface
: NULL
);
3360 LeaveCriticalSection(&ddraw_cs
);
3364 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3365 DWORD flags
, IDirectDrawSurface4
*reference
)
3367 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3368 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3369 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3371 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3372 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3375 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3376 DWORD flags
, IDirectDrawSurface3
*reference
)
3378 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3379 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3380 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3382 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3383 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3386 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3387 DWORD flags
, IDirectDrawSurface2
*reference
)
3389 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3390 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3391 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3393 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3394 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3397 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3398 DWORD flags
, IDirectDrawSurface
*reference
)
3400 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3401 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3402 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3404 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3405 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3408 /*****************************************************************************
3409 * IDirectDrawSurface7::GetDDInterface
3411 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3412 * surface belongs to
3415 * DD: Address to write the interface pointer to
3419 * DDERR_INVALIDPARAMS if DD is NULL
3421 *****************************************************************************/
3422 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3424 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3426 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3429 return DDERR_INVALIDPARAMS
;
3431 switch(This
->version
)
3434 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3438 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3442 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3446 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3450 IUnknown_AddRef((IUnknown
*)*DD
);
3455 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3457 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3458 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3460 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3463 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3465 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3466 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3468 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3471 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3473 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3474 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3476 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3479 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3480 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3482 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3483 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
3485 TRACE("iface %p.\n", iface
);
3487 EnterCriticalSection(&ddraw_cs
);
3488 /* A uniqueness value of 0 is apparently special.
3489 * This needs to be checked.
3490 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3493 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
3494 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
3496 if (old_uniqueness_value
== 0) break;
3497 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
3499 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
3500 old_uniqueness_value
,
3501 new_uniqueness_value
)
3502 == old_uniqueness_value
)
3506 LeaveCriticalSection(&ddraw_cs
);
3510 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3512 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3513 TRACE("iface %p.\n", iface
);
3515 return ddraw_surface7_ChangeUniquenessValue(&This
->IDirectDrawSurface7_iface
);
3518 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3520 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3522 TRACE("iface %p, value %p.\n", iface
, pValue
);
3524 EnterCriticalSection(&ddraw_cs
);
3525 *pValue
= This
->uniqueness_value
;
3526 LeaveCriticalSection(&ddraw_cs
);
3530 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3532 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3533 TRACE("iface %p, value %p.\n", iface
, pValue
);
3535 return ddraw_surface7_GetUniquenessValue(&This
->IDirectDrawSurface7_iface
, pValue
);
3538 /*****************************************************************************
3539 * IDirectDrawSurface7::SetLOD
3541 * Sets the level of detail of a texture
3544 * MaxLOD: LOD to set
3548 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3550 *****************************************************************************/
3551 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
3553 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3556 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
3558 EnterCriticalSection(&ddraw_cs
);
3559 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3561 LeaveCriticalSection(&ddraw_cs
);
3562 return DDERR_INVALIDOBJECT
;
3565 if (!This
->wined3d_texture
)
3567 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
3568 LeaveCriticalSection(&ddraw_cs
);
3569 return DDERR_INVALIDOBJECT
;
3572 hr
= wined3d_texture_set_lod(This
->wined3d_texture
, MaxLOD
);
3573 LeaveCriticalSection(&ddraw_cs
);
3577 /*****************************************************************************
3578 * IDirectDrawSurface7::GetLOD
3580 * Returns the level of detail of a Direct3D texture
3583 * MaxLOD: Address to write the LOD to
3587 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3588 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3590 *****************************************************************************/
3591 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
3593 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3595 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
3598 return DDERR_INVALIDPARAMS
;
3600 EnterCriticalSection(&ddraw_cs
);
3601 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3603 LeaveCriticalSection(&ddraw_cs
);
3604 return DDERR_INVALIDOBJECT
;
3607 *MaxLOD
= wined3d_texture_get_lod(This
->wined3d_texture
);
3608 LeaveCriticalSection(&ddraw_cs
);
3612 /*****************************************************************************
3613 * IDirectDrawSurface7::BltFast
3615 * Performs a fast Blit.
3618 * dstx: The x coordinate to blit to on the destination
3619 * dsty: The y coordinate to blit to on the destination
3620 * Source: The source surface
3621 * rsrc: The source rectangle
3622 * trans: Type of transfer. Some DDBLTFAST_* flags
3626 * For more details, see IWineD3DSurface::BltFast
3628 *****************************************************************************/
3629 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
3630 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
3632 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3633 IDirectDrawSurfaceImpl
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
3634 DWORD src_w
, src_h
, dst_w
, dst_h
;
3637 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3638 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
3640 dst_w
= This
->surface_desc
.dwWidth
;
3641 dst_h
= This
->surface_desc
.dwHeight
;
3643 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3648 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
3649 rsrc
->right
> src
->surface_desc
.dwWidth
||
3650 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
3652 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
3653 return DDERR_INVALIDRECT
;
3656 src_w
= rsrc
->right
- rsrc
->left
;
3657 src_h
= rsrc
->bottom
- rsrc
->top
;
3661 src_w
= src
->surface_desc
.dwWidth
;
3662 src_h
= src
->surface_desc
.dwHeight
;
3665 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
3666 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
3668 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3669 return DDERR_INVALIDRECT
;
3672 EnterCriticalSection(&ddraw_cs
);
3673 hr
= wined3d_surface_bltfast(This
->wined3d_surface
, dstx
, dsty
,
3674 src
->wined3d_surface
, rsrc
, trans
);
3675 LeaveCriticalSection(&ddraw_cs
);
3678 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
3679 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
3684 static HRESULT WINAPI
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
3685 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
3687 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3688 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
3689 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3690 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3692 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3693 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3696 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
3697 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
3699 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3700 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
3701 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3702 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3704 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3705 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3708 static HRESULT WINAPI
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
3709 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
3711 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3712 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
3713 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3714 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3716 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3717 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3720 static HRESULT WINAPI
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
3721 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
3723 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3724 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
3725 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3726 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3728 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3729 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3732 /*****************************************************************************
3733 * IDirectDrawSurface7::GetClipper
3735 * Returns the IDirectDrawClipper interface of the clipper assigned to this
3739 * Clipper: Address to store the interface pointer at
3743 * DDERR_INVALIDPARAMS if Clipper is NULL
3744 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
3746 *****************************************************************************/
3747 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
3749 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3751 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
3755 LeaveCriticalSection(&ddraw_cs
);
3756 return DDERR_INVALIDPARAMS
;
3759 EnterCriticalSection(&ddraw_cs
);
3760 if(This
->clipper
== NULL
)
3762 LeaveCriticalSection(&ddraw_cs
);
3763 return DDERR_NOCLIPPERATTACHED
;
3766 *Clipper
= (IDirectDrawClipper
*)This
->clipper
;
3767 IDirectDrawClipper_AddRef(*Clipper
);
3768 LeaveCriticalSection(&ddraw_cs
);
3772 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
3774 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3775 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3777 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3780 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
3782 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3783 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3785 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3788 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
3790 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3791 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3793 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3796 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
3798 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3799 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3801 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3804 /*****************************************************************************
3805 * IDirectDrawSurface7::SetClipper
3807 * Sets a clipper for the surface
3810 * Clipper: IDirectDrawClipper interface of the clipper to set
3815 *****************************************************************************/
3816 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
3817 IDirectDrawClipper
*iclipper
)
3819 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3820 IDirectDrawClipperImpl
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
3821 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
3825 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
3827 EnterCriticalSection(&ddraw_cs
);
3828 if (clipper
== This
->clipper
)
3830 LeaveCriticalSection(&ddraw_cs
);
3834 This
->clipper
= clipper
;
3836 if (clipper
!= NULL
)
3837 IDirectDrawClipper_AddRef(iclipper
);
3839 IDirectDrawClipper_Release(&oldClipper
->IDirectDrawClipper_iface
);
3841 hr
= wined3d_surface_set_clipper(This
->wined3d_surface
,
3842 This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
3844 if (This
->wined3d_swapchain
)
3848 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
3852 wined3d_swapchain_set_window(This
->wined3d_swapchain
, clipWindow
);
3854 wined3d_swapchain_set_window(This
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
3857 LeaveCriticalSection(&ddraw_cs
);
3861 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
3863 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3864 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3866 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3869 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
3871 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3872 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3874 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3877 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
3879 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3880 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3882 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3885 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
3887 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3888 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3890 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3893 /*****************************************************************************
3894 * IDirectDrawSurface7::SetSurfaceDesc
3896 * Sets the surface description. It can override the pixel format, the surface
3898 * It's not really tested.
3901 * DDSD: Pointer to the new surface description to set
3906 * DDERR_INVALIDPARAMS if DDSD is NULL
3908 *****************************************************************************/
3909 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
3911 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3912 enum wined3d_format_id newFormat
= WINED3DFMT_UNKNOWN
;
3915 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
3918 return DDERR_INVALIDPARAMS
;
3920 EnterCriticalSection(&ddraw_cs
);
3921 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
3923 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
3925 if(newFormat
== WINED3DFMT_UNKNOWN
)
3927 ERR("Requested to set an unknown pixelformat\n");
3928 LeaveCriticalSection(&ddraw_cs
);
3929 return DDERR_INVALIDPARAMS
;
3931 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
3933 hr
= wined3d_surface_set_format(This
->wined3d_surface
, newFormat
);
3936 LeaveCriticalSection(&ddraw_cs
);
3941 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
3943 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
3944 (WINEDDCOLORKEY
*)&DDSD
->u3
.ddckCKDestOverlay
);
3946 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
3948 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_DESTBLT
,
3949 (WINEDDCOLORKEY
*)&DDSD
->ddckCKDestBlt
);
3951 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
3953 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
3954 (WINEDDCOLORKEY
*)&DDSD
->ddckCKSrcOverlay
);
3956 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
3958 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_SRCBLT
,
3959 (WINEDDCOLORKEY
*)&DDSD
->ddckCKSrcBlt
);
3961 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
3963 hr
= wined3d_surface_set_mem(This
->wined3d_surface
, DDSD
->lpSurface
);
3966 /* No need for a trace here, wined3d does that for us */
3969 case WINED3DERR_INVALIDCALL
:
3970 LeaveCriticalSection(&ddraw_cs
);
3971 return DDERR_INVALIDPARAMS
;
3978 This
->surface_desc
= *DDSD
;
3980 LeaveCriticalSection(&ddraw_cs
);
3984 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
3985 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
3987 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3988 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
3990 return ddraw_surface7_SetSurfaceDesc(&This
->IDirectDrawSurface7_iface
,
3991 surface_desc
, flags
);
3994 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
3995 DDSURFACEDESC
*surface_desc
, DWORD flags
)
3997 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3998 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4000 return ddraw_surface7_SetSurfaceDesc(&This
->IDirectDrawSurface7_iface
,
4001 (DDSURFACEDESC2
*)surface_desc
, flags
);
4004 /*****************************************************************************
4005 * IDirectDrawSurface7::GetPalette
4007 * Returns the IDirectDrawPalette interface of the palette currently assigned
4011 * Pal: Address to write the interface pointer to
4015 * DDERR_INVALIDPARAMS if Pal is NULL
4017 *****************************************************************************/
4018 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
4020 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4021 struct wined3d_palette
*wined3d_palette
;
4024 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4027 return DDERR_INVALIDPARAMS
;
4029 EnterCriticalSection(&ddraw_cs
);
4030 wined3d_palette
= wined3d_surface_get_palette(This
->wined3d_surface
);
4031 if (wined3d_palette
)
4033 *Pal
= wined3d_palette_get_parent(wined3d_palette
);
4034 IDirectDrawPalette_AddRef(*Pal
);
4039 hr
= DDERR_NOPALETTEATTACHED
;
4042 LeaveCriticalSection(&ddraw_cs
);
4046 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4048 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4049 TRACE("iface %p, palette %p.\n", iface
, palette
);
4051 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4054 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4056 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4057 TRACE("iface %p, palette %p.\n", iface
, palette
);
4059 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4062 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4064 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4065 TRACE("iface %p, palette %p.\n", iface
, palette
);
4067 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4070 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4072 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4073 TRACE("iface %p, palette %p.\n", iface
, palette
);
4075 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4078 /*****************************************************************************
4081 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4082 * recursively in the surface tree
4084 *****************************************************************************/
4088 WINEDDCOLORKEY
*CKey
;
4092 static HRESULT WINAPI
4093 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
4094 DDSURFACEDESC2
*desc
,
4097 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(surface
);
4098 struct SCKContext
*ctx
= context
;
4101 hr
= wined3d_surface_set_color_key(This
->wined3d_surface
, ctx
->Flags
, ctx
->CKey
);
4104 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
4108 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
4109 ddraw_surface7_Release(surface
);
4111 return DDENUMRET_OK
;
4114 /*****************************************************************************
4115 * IDirectDrawSurface7::SetColorKey
4117 * Sets the color keying options for the surface. Observations showed that
4118 * in case of complex surfaces the color key has to be assigned to all
4123 * CKey: The new color key
4127 * See IWineD3DSurface::SetColorKey for details
4129 *****************************************************************************/
4130 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
4132 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4133 DDCOLORKEY FixedCKey
;
4134 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) (CKey
? &FixedCKey
: NULL
), Flags
};
4136 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
4138 EnterCriticalSection(&ddraw_cs
);
4142 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4143 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
4144 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
4146 switch (Flags
& ~DDCKEY_COLORSPACE
)
4148 case DDCKEY_DESTBLT
:
4149 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
4150 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4153 case DDCKEY_DESTOVERLAY
:
4154 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
4155 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4158 case DDCKEY_SRCOVERLAY
:
4159 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
4160 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4164 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
4165 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4169 LeaveCriticalSection(&ddraw_cs
);
4170 return DDERR_INVALIDPARAMS
;
4175 switch (Flags
& ~DDCKEY_COLORSPACE
)
4177 case DDCKEY_DESTBLT
:
4178 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4181 case DDCKEY_DESTOVERLAY
:
4182 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4185 case DDCKEY_SRCOVERLAY
:
4186 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4190 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4194 LeaveCriticalSection(&ddraw_cs
);
4195 return DDERR_INVALIDPARAMS
;
4198 ctx
.ret
= wined3d_surface_set_color_key(This
->wined3d_surface
, Flags
, ctx
.CKey
);
4199 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
4200 LeaveCriticalSection(&ddraw_cs
);
4203 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
4204 default: return ctx
.ret
;
4208 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4210 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4211 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4213 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4216 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4218 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4219 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4221 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4224 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4226 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4227 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4229 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4232 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4234 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4235 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4237 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4240 /*****************************************************************************
4241 * IDirectDrawSurface7::SetPalette
4243 * Assigns a DirectDrawPalette object to the surface
4246 * Pal: Interface to the palette to set
4251 *****************************************************************************/
4252 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
4254 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4255 IDirectDrawPalette
*oldPal
;
4256 IDirectDrawSurfaceImpl
*surf
;
4257 IDirectDrawPaletteImpl
*PalImpl
= (IDirectDrawPaletteImpl
*)Pal
;
4260 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4262 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
4263 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
4264 return DDERR_INVALIDPIXELFORMAT
;
4267 /* Find the old palette */
4268 EnterCriticalSection(&ddraw_cs
);
4269 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
4270 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
4272 LeaveCriticalSection(&ddraw_cs
);
4275 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
4277 /* Set the new Palette */
4278 wined3d_surface_set_palette(This
->wined3d_surface
, PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
4279 /* AddRef the Palette */
4280 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
4282 /* Release the old palette */
4283 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
4285 /* If this is a front buffer, also update the back buffers
4286 * TODO: How do things work for palettized cube textures?
4288 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4290 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4291 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
4296 IDirectDrawSurface7
*attach
;
4298 hr
= ddraw_surface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &caps2
, &attach
);
4304 TRACE("Setting palette on %p\n", attach
);
4305 ddraw_surface7_SetPalette(attach
, Pal
);
4306 surf
= impl_from_IDirectDrawSurface7(attach
);
4307 ddraw_surface7_Release(attach
);
4311 LeaveCriticalSection(&ddraw_cs
);
4315 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4317 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4318 TRACE("iface %p, palette %p.\n", iface
, palette
);
4320 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4323 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4325 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4326 TRACE("iface %p, palette %p.\n", iface
, palette
);
4328 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4331 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4333 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4334 TRACE("iface %p, palette %p.\n", iface
, palette
);
4336 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4339 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4341 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4342 TRACE("iface %p, palette %p.\n", iface
, palette
);
4344 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4347 /**********************************************************
4348 * IDirectDrawGammaControl::GetGammaRamp
4350 * Returns the current gamma ramp for a surface
4354 * gamma_ramp: Address to write the ramp to
4358 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4360 **********************************************************/
4361 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4362 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4364 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4366 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4370 WARN("Invalid gamma_ramp passed.\n");
4371 return DDERR_INVALIDPARAMS
;
4374 EnterCriticalSection(&ddraw_cs
);
4375 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4377 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */
4378 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (WINED3DGAMMARAMP
*)gamma_ramp
);
4382 ERR("Not implemented for non-primary surfaces.\n");
4384 LeaveCriticalSection(&ddraw_cs
);
4389 /**********************************************************
4390 * IDirectDrawGammaControl::SetGammaRamp
4392 * Sets the red, green and blue gamma ramps for
4395 * flags: Can be DDSGR_CALIBRATE to request calibration
4396 * gamma_ramp: Structure containing the new gamma ramp
4400 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4402 **********************************************************/
4403 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4404 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4406 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4408 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4412 WARN("Invalid gamma_ramp passed.\n");
4413 return DDERR_INVALIDPARAMS
;
4416 EnterCriticalSection(&ddraw_cs
);
4417 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4419 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
4420 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, flags
, (WINED3DGAMMARAMP
*)gamma_ramp
);
4424 ERR("Not implemented for non-primary surfaces.\n");
4426 LeaveCriticalSection(&ddraw_cs
);
4431 /*****************************************************************************
4432 * IDirect3DTexture2::PaletteChanged
4434 * Informs the texture about a palette change
4437 * start: Start index of the change
4438 * count: The number of changed entries
4441 * D3D_OK, because it's a stub
4443 *****************************************************************************/
4444 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4446 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4451 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4453 IDirectDrawSurfaceImpl
*surface
= surface_from_texture1(iface
);
4455 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4457 return d3d_texture2_PaletteChanged((IDirect3DTexture2
*)&surface
->IDirect3DTexture2_vtbl
, start
, count
);
4460 /*****************************************************************************
4461 * IDirect3DTexture::Unload
4463 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4469 *****************************************************************************/
4470 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4472 WARN("iface %p. Not implemented.\n", iface
);
4474 return DDERR_UNSUPPORTED
;
4477 /*****************************************************************************
4478 * IDirect3DTexture2::GetHandle
4480 * Returns handle for the texture. At the moment, the interface
4481 * to the IWineD3DTexture is used.
4484 * device: Device this handle is assigned to
4485 * handle: Address to store the handle at.
4490 *****************************************************************************/
4491 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4492 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4494 IDirectDrawSurfaceImpl
*surface
= surface_from_texture2(iface
);
4496 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4498 EnterCriticalSection(&ddraw_cs
);
4500 if (!surface
->Handle
)
4502 DWORD h
= ddraw_allocate_handle(&device_from_device2(device
)->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
4503 if (h
== DDRAW_INVALID_HANDLE
)
4505 ERR("Failed to allocate a texture handle.\n");
4506 LeaveCriticalSection(&ddraw_cs
);
4507 return DDERR_OUTOFMEMORY
;
4510 surface
->Handle
= h
+ 1;
4513 TRACE("Returning handle %08x.\n", surface
->Handle
);
4514 *handle
= surface
->Handle
;
4516 LeaveCriticalSection(&ddraw_cs
);
4521 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
4522 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
4524 IDirect3DTexture2
*texture2
= (IDirect3DTexture2
*)&surface_from_texture1(iface
)->IDirect3DTexture2_vtbl
;
4525 IDirect3DDevice2
*device2
= (IDirect3DDevice2
*)&device_from_device1(device
)->IDirect3DDevice2_vtbl
;
4527 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4529 return d3d_texture2_GetHandle(texture2
, device2
, handle
);
4532 /*****************************************************************************
4533 * get_sub_mimaplevel
4535 * Helper function that returns the next mipmap level
4537 * tex_ptr: Surface of which to return the next level
4539 *****************************************************************************/
4540 static IDirectDrawSurfaceImpl
*get_sub_mimaplevel(IDirectDrawSurfaceImpl
*surface
)
4542 /* Now go down the mipmap chain to the next surface */
4543 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
4544 IDirectDrawSurface7
*next_level
;
4547 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
4548 if (FAILED(hr
)) return NULL
;
4550 ddraw_surface7_Release(next_level
);
4552 return impl_from_IDirectDrawSurface7(next_level
);
4555 /*****************************************************************************
4556 * IDirect3DTexture2::Load
4558 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
4560 * This function isn't relayed to WineD3D because the whole interface is
4561 * implemented in DDraw only. For speed improvements a implementation which
4562 * takes OpenGL more into account could be placed into WineD3D.
4565 * src_texture: Address of the texture to load
4569 * D3DERR_TEXTURE_LOAD_FAILED.
4571 *****************************************************************************/
4572 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
4574 IDirectDrawSurfaceImpl
*dst_surface
= surface_from_texture2(iface
);
4575 IDirectDrawSurfaceImpl
*src_surface
= surface_from_texture2(src_texture
);
4578 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
4580 if (src_surface
== dst_surface
)
4582 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
4586 EnterCriticalSection(&ddraw_cs
);
4588 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4589 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
4590 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
4592 ERR("Trying to load surfaces with different mip-map counts.\n");
4597 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
4598 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
4599 DDSURFACEDESC
*src_desc
, *dst_desc
;
4601 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
4602 src_surface
, dst_surface
, src_surface
->mipmap_level
);
4604 /* Suppress the ALLOCONLOAD flag */
4605 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
4607 /* Get the palettes */
4608 wined3d_dst_pal
= wined3d_surface_get_palette(dst_surface
->wined3d_surface
);
4609 if (wined3d_dst_pal
)
4610 dst_pal
= wined3d_palette_get_parent(wined3d_dst_pal
);
4612 wined3d_src_pal
= wined3d_surface_get_palette(src_surface
->wined3d_surface
);
4613 if (wined3d_src_pal
)
4614 src_pal
= wined3d_palette_get_parent(wined3d_src_pal
);
4618 PALETTEENTRY palent
[256];
4622 LeaveCriticalSection(&ddraw_cs
);
4623 return DDERR_NOPALETTEATTACHED
;
4625 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
4626 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
4629 /* Copy one surface on the other */
4630 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
4631 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
4633 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
4635 /* Should also check for same pixel format, u1.lPitch, ... */
4636 ERR("Error in surface sizes.\n");
4637 LeaveCriticalSection(&ddraw_cs
);
4638 return D3DERR_TEXTURE_LOAD_FAILED
;
4642 WINED3DLOCKED_RECT src_rect
, dst_rect
;
4644 /* Copy also the ColorKeying stuff */
4645 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
4647 dst_desc
->dwFlags
|= DDSD_CKSRCBLT
;
4648 dst_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
;
4649 dst_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
;
4652 /* Copy the main memory texture into the surface that corresponds
4653 * to the OpenGL texture object. */
4655 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_rect
, NULL
, 0);
4658 ERR("Failed to lock source surface, hr %#x.\n", hr
);
4659 LeaveCriticalSection(&ddraw_cs
);
4660 return D3DERR_TEXTURE_LOAD_FAILED
;
4663 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_rect
, NULL
, 0);
4666 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
4667 wined3d_surface_unmap(src_surface
->wined3d_surface
);
4668 LeaveCriticalSection(&ddraw_cs
);
4669 return D3DERR_TEXTURE_LOAD_FAILED
;
4672 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
4673 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_surface
->surface_desc
.u1
.dwLinearSize
);
4675 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_rect
.Pitch
* src_desc
->dwHeight
);
4677 wined3d_surface_unmap(src_surface
->wined3d_surface
);
4678 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
4681 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4682 src_surface
= get_sub_mimaplevel(src_surface
);
4686 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4687 dst_surface
= get_sub_mimaplevel(dst_surface
);
4691 if (!src_surface
|| !dst_surface
)
4693 if (src_surface
!= dst_surface
)
4694 ERR("Loading surface with different mipmap structure.\n");
4699 LeaveCriticalSection(&ddraw_cs
);
4704 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
4706 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
4708 return d3d_texture2_Load((IDirect3DTexture2
*)&surface_from_texture1(iface
)->IDirect3DTexture2_vtbl
,
4709 src_texture
? (IDirect3DTexture2
*)&surface_from_texture1(src_texture
)->IDirect3DTexture2_vtbl
: NULL
);
4712 /*****************************************************************************
4714 *****************************************************************************/
4716 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
4719 ddraw_surface7_QueryInterface
,
4720 ddraw_surface7_AddRef
,
4721 ddraw_surface7_Release
,
4722 /* IDirectDrawSurface */
4723 ddraw_surface7_AddAttachedSurface
,
4724 ddraw_surface7_AddOverlayDirtyRect
,
4726 ddraw_surface7_BltBatch
,
4727 ddraw_surface7_BltFast
,
4728 ddraw_surface7_DeleteAttachedSurface
,
4729 ddraw_surface7_EnumAttachedSurfaces
,
4730 ddraw_surface7_EnumOverlayZOrders
,
4731 ddraw_surface7_Flip
,
4732 ddraw_surface7_GetAttachedSurface
,
4733 ddraw_surface7_GetBltStatus
,
4734 ddraw_surface7_GetCaps
,
4735 ddraw_surface7_GetClipper
,
4736 ddraw_surface7_GetColorKey
,
4737 ddraw_surface7_GetDC
,
4738 ddraw_surface7_GetFlipStatus
,
4739 ddraw_surface7_GetOverlayPosition
,
4740 ddraw_surface7_GetPalette
,
4741 ddraw_surface7_GetPixelFormat
,
4742 ddraw_surface7_GetSurfaceDesc
,
4743 ddraw_surface7_Initialize
,
4744 ddraw_surface7_IsLost
,
4745 ddraw_surface7_Lock
,
4746 ddraw_surface7_ReleaseDC
,
4747 ddraw_surface7_Restore
,
4748 ddraw_surface7_SetClipper
,
4749 ddraw_surface7_SetColorKey
,
4750 ddraw_surface7_SetOverlayPosition
,
4751 ddraw_surface7_SetPalette
,
4752 ddraw_surface7_Unlock
,
4753 ddraw_surface7_UpdateOverlay
,
4754 ddraw_surface7_UpdateOverlayDisplay
,
4755 ddraw_surface7_UpdateOverlayZOrder
,
4756 /* IDirectDrawSurface2 */
4757 ddraw_surface7_GetDDInterface
,
4758 ddraw_surface7_PageLock
,
4759 ddraw_surface7_PageUnlock
,
4760 /* IDirectDrawSurface3 */
4761 ddraw_surface7_SetSurfaceDesc
,
4762 /* IDirectDrawSurface4 */
4763 ddraw_surface7_SetPrivateData
,
4764 ddraw_surface7_GetPrivateData
,
4765 ddraw_surface7_FreePrivateData
,
4766 ddraw_surface7_GetUniquenessValue
,
4767 ddraw_surface7_ChangeUniquenessValue
,
4768 /* IDirectDrawSurface7 */
4769 ddraw_surface7_SetPriority
,
4770 ddraw_surface7_GetPriority
,
4771 ddraw_surface7_SetLOD
,
4772 ddraw_surface7_GetLOD
,
4775 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
4778 ddraw_surface4_QueryInterface
,
4779 ddraw_surface4_AddRef
,
4780 ddraw_surface4_Release
,
4781 /* IDirectDrawSurface */
4782 ddraw_surface4_AddAttachedSurface
,
4783 ddraw_surface4_AddOverlayDirtyRect
,
4785 ddraw_surface4_BltBatch
,
4786 ddraw_surface4_BltFast
,
4787 ddraw_surface4_DeleteAttachedSurface
,
4788 ddraw_surface4_EnumAttachedSurfaces
,
4789 ddraw_surface4_EnumOverlayZOrders
,
4790 ddraw_surface4_Flip
,
4791 ddraw_surface4_GetAttachedSurface
,
4792 ddraw_surface4_GetBltStatus
,
4793 ddraw_surface4_GetCaps
,
4794 ddraw_surface4_GetClipper
,
4795 ddraw_surface4_GetColorKey
,
4796 ddraw_surface4_GetDC
,
4797 ddraw_surface4_GetFlipStatus
,
4798 ddraw_surface4_GetOverlayPosition
,
4799 ddraw_surface4_GetPalette
,
4800 ddraw_surface4_GetPixelFormat
,
4801 ddraw_surface4_GetSurfaceDesc
,
4802 ddraw_surface4_Initialize
,
4803 ddraw_surface4_IsLost
,
4804 ddraw_surface4_Lock
,
4805 ddraw_surface4_ReleaseDC
,
4806 ddraw_surface4_Restore
,
4807 ddraw_surface4_SetClipper
,
4808 ddraw_surface4_SetColorKey
,
4809 ddraw_surface4_SetOverlayPosition
,
4810 ddraw_surface4_SetPalette
,
4811 ddraw_surface4_Unlock
,
4812 ddraw_surface4_UpdateOverlay
,
4813 ddraw_surface4_UpdateOverlayDisplay
,
4814 ddraw_surface4_UpdateOverlayZOrder
,
4815 /* IDirectDrawSurface2 */
4816 ddraw_surface4_GetDDInterface
,
4817 ddraw_surface4_PageLock
,
4818 ddraw_surface4_PageUnlock
,
4819 /* IDirectDrawSurface3 */
4820 ddraw_surface4_SetSurfaceDesc
,
4821 /* IDirectDrawSurface4 */
4822 ddraw_surface4_SetPrivateData
,
4823 ddraw_surface4_GetPrivateData
,
4824 ddraw_surface4_FreePrivateData
,
4825 ddraw_surface4_GetUniquenessValue
,
4826 ddraw_surface4_ChangeUniquenessValue
,
4829 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
4832 ddraw_surface3_QueryInterface
,
4833 ddraw_surface3_AddRef
,
4834 ddraw_surface3_Release
,
4835 /* IDirectDrawSurface */
4836 ddraw_surface3_AddAttachedSurface
,
4837 ddraw_surface3_AddOverlayDirtyRect
,
4839 ddraw_surface3_BltBatch
,
4840 ddraw_surface3_BltFast
,
4841 ddraw_surface3_DeleteAttachedSurface
,
4842 ddraw_surface3_EnumAttachedSurfaces
,
4843 ddraw_surface3_EnumOverlayZOrders
,
4844 ddraw_surface3_Flip
,
4845 ddraw_surface3_GetAttachedSurface
,
4846 ddraw_surface3_GetBltStatus
,
4847 ddraw_surface3_GetCaps
,
4848 ddraw_surface3_GetClipper
,
4849 ddraw_surface3_GetColorKey
,
4850 ddraw_surface3_GetDC
,
4851 ddraw_surface3_GetFlipStatus
,
4852 ddraw_surface3_GetOverlayPosition
,
4853 ddraw_surface3_GetPalette
,
4854 ddraw_surface3_GetPixelFormat
,
4855 ddraw_surface3_GetSurfaceDesc
,
4856 ddraw_surface3_Initialize
,
4857 ddraw_surface3_IsLost
,
4858 ddraw_surface3_Lock
,
4859 ddraw_surface3_ReleaseDC
,
4860 ddraw_surface3_Restore
,
4861 ddraw_surface3_SetClipper
,
4862 ddraw_surface3_SetColorKey
,
4863 ddraw_surface3_SetOverlayPosition
,
4864 ddraw_surface3_SetPalette
,
4865 ddraw_surface3_Unlock
,
4866 ddraw_surface3_UpdateOverlay
,
4867 ddraw_surface3_UpdateOverlayDisplay
,
4868 ddraw_surface3_UpdateOverlayZOrder
,
4869 /* IDirectDrawSurface2 */
4870 ddraw_surface3_GetDDInterface
,
4871 ddraw_surface3_PageLock
,
4872 ddraw_surface3_PageUnlock
,
4873 /* IDirectDrawSurface3 */
4874 ddraw_surface3_SetSurfaceDesc
,
4877 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
4880 ddraw_surface2_QueryInterface
,
4881 ddraw_surface2_AddRef
,
4882 ddraw_surface2_Release
,
4883 /* IDirectDrawSurface */
4884 ddraw_surface2_AddAttachedSurface
,
4885 ddraw_surface2_AddOverlayDirtyRect
,
4887 ddraw_surface2_BltBatch
,
4888 ddraw_surface2_BltFast
,
4889 ddraw_surface2_DeleteAttachedSurface
,
4890 ddraw_surface2_EnumAttachedSurfaces
,
4891 ddraw_surface2_EnumOverlayZOrders
,
4892 ddraw_surface2_Flip
,
4893 ddraw_surface2_GetAttachedSurface
,
4894 ddraw_surface2_GetBltStatus
,
4895 ddraw_surface2_GetCaps
,
4896 ddraw_surface2_GetClipper
,
4897 ddraw_surface2_GetColorKey
,
4898 ddraw_surface2_GetDC
,
4899 ddraw_surface2_GetFlipStatus
,
4900 ddraw_surface2_GetOverlayPosition
,
4901 ddraw_surface2_GetPalette
,
4902 ddraw_surface2_GetPixelFormat
,
4903 ddraw_surface2_GetSurfaceDesc
,
4904 ddraw_surface2_Initialize
,
4905 ddraw_surface2_IsLost
,
4906 ddraw_surface2_Lock
,
4907 ddraw_surface2_ReleaseDC
,
4908 ddraw_surface2_Restore
,
4909 ddraw_surface2_SetClipper
,
4910 ddraw_surface2_SetColorKey
,
4911 ddraw_surface2_SetOverlayPosition
,
4912 ddraw_surface2_SetPalette
,
4913 ddraw_surface2_Unlock
,
4914 ddraw_surface2_UpdateOverlay
,
4915 ddraw_surface2_UpdateOverlayDisplay
,
4916 ddraw_surface2_UpdateOverlayZOrder
,
4917 /* IDirectDrawSurface2 */
4918 ddraw_surface2_GetDDInterface
,
4919 ddraw_surface2_PageLock
,
4920 ddraw_surface2_PageUnlock
,
4923 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
4926 ddraw_surface1_QueryInterface
,
4927 ddraw_surface1_AddRef
,
4928 ddraw_surface1_Release
,
4929 /* IDirectDrawSurface */
4930 ddraw_surface1_AddAttachedSurface
,
4931 ddraw_surface1_AddOverlayDirtyRect
,
4933 ddraw_surface1_BltBatch
,
4934 ddraw_surface1_BltFast
,
4935 ddraw_surface1_DeleteAttachedSurface
,
4936 ddraw_surface1_EnumAttachedSurfaces
,
4937 ddraw_surface1_EnumOverlayZOrders
,
4938 ddraw_surface1_Flip
,
4939 ddraw_surface1_GetAttachedSurface
,
4940 ddraw_surface1_GetBltStatus
,
4941 ddraw_surface1_GetCaps
,
4942 ddraw_surface1_GetClipper
,
4943 ddraw_surface1_GetColorKey
,
4944 ddraw_surface1_GetDC
,
4945 ddraw_surface1_GetFlipStatus
,
4946 ddraw_surface1_GetOverlayPosition
,
4947 ddraw_surface1_GetPalette
,
4948 ddraw_surface1_GetPixelFormat
,
4949 ddraw_surface1_GetSurfaceDesc
,
4950 ddraw_surface1_Initialize
,
4951 ddraw_surface1_IsLost
,
4952 ddraw_surface1_Lock
,
4953 ddraw_surface1_ReleaseDC
,
4954 ddraw_surface1_Restore
,
4955 ddraw_surface1_SetClipper
,
4956 ddraw_surface1_SetColorKey
,
4957 ddraw_surface1_SetOverlayPosition
,
4958 ddraw_surface1_SetPalette
,
4959 ddraw_surface1_Unlock
,
4960 ddraw_surface1_UpdateOverlay
,
4961 ddraw_surface1_UpdateOverlayDisplay
,
4962 ddraw_surface1_UpdateOverlayZOrder
,
4965 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
4967 ddraw_gamma_control_QueryInterface
,
4968 ddraw_gamma_control_AddRef
,
4969 ddraw_gamma_control_Release
,
4970 ddraw_gamma_control_GetGammaRamp
,
4971 ddraw_gamma_control_SetGammaRamp
,
4974 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
4976 d3d_texture2_QueryInterface
,
4977 d3d_texture2_AddRef
,
4978 d3d_texture2_Release
,
4979 d3d_texture2_GetHandle
,
4980 d3d_texture2_PaletteChanged
,
4984 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
4986 d3d_texture1_QueryInterface
,
4987 d3d_texture1_AddRef
,
4988 d3d_texture1_Release
,
4989 d3d_texture1_Initialize
,
4990 d3d_texture1_GetHandle
,
4991 d3d_texture1_PaletteChanged
,
4993 d3d_texture1_Unload
,
4996 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
4998 if (!iface
) return NULL
;
4999 assert(iface
->lpVtbl
== &ddraw_surface7_vtbl
);
5000 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface7_iface
);
5003 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5005 if (!iface
) return NULL
;
5006 assert(iface
->lpVtbl
== &ddraw_surface4_vtbl
);
5007 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface4_iface
);
5010 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5012 if (!iface
) return NULL
;
5013 assert(iface
->lpVtbl
== &ddraw_surface3_vtbl
);
5014 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface3_iface
);
5017 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5019 if (!iface
) return NULL
;
5020 assert(iface
->lpVtbl
== &ddraw_surface2_vtbl
);
5021 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface2_iface
);
5024 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5026 if (!iface
) return NULL
;
5027 assert(iface
->lpVtbl
== &ddraw_surface1_vtbl
);
5028 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface_iface
);
5031 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5033 IDirectDrawSurfaceImpl
*surface
= parent
;
5035 TRACE("surface %p.\n", surface
);
5037 /* Check for attached surfaces and detach them. */
5038 if (surface
->first_attached
!= surface
)
5040 IDirectDrawSurface7
*root
= &surface
->first_attached
->IDirectDrawSurface7_iface
;
5041 IDirectDrawSurface7
*detach
= &surface
->IDirectDrawSurface7_iface
;
5043 /* Well, this shouldn't happen: The surface being attached is
5044 * referenced in AddAttachedSurface(), so it shouldn't be released
5045 * until DeleteAttachedSurface() is called, because the refcount is
5046 * held. It looks like the application released it often enough to
5048 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5050 /* The refcount will drop to -1 here */
5051 if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
)))
5052 ERR("DeleteAttachedSurface failed.\n");
5055 while (surface
->next_attached
)
5057 IDirectDrawSurface7
*root
= &surface
->IDirectDrawSurface7_iface
;
5058 IDirectDrawSurface7
*detach
= &surface
->next_attached
->IDirectDrawSurface7_iface
;
5060 if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
)))
5061 ERR("DeleteAttachedSurface failed.\n");
5064 /* Having a texture handle set implies that the device still exists. */
5065 if (surface
->Handle
)
5066 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5068 /* Reduce the ddraw surface count. */
5069 InterlockedDecrement(&surface
->ddraw
->surfaces
);
5070 list_remove(&surface
->surface_list_entry
);
5072 HeapFree(GetProcessHeap(), 0, surface
);
5075 const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5077 ddraw_surface_wined3d_object_destroyed
,
5080 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5082 IDirectDrawSurfaceImpl
*surface
= parent
;
5084 TRACE("surface %p.\n", surface
);
5086 ddraw_surface_cleanup(surface
);
5089 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5091 ddraw_texture_wined3d_object_destroyed
,
5094 HRESULT
ddraw_surface_create_texture(IDirectDrawSurfaceImpl
*surface
)
5096 const DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
5097 enum wined3d_format_id format
;
5101 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5102 levels
= desc
->u2
.dwMipMapCount
;
5106 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM.
5107 * Should I forward the MANAGED cap to the managed pool? */
5108 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5109 pool
= WINED3DPOOL_SYSTEMMEM
;
5111 pool
= WINED3DPOOL_DEFAULT
;
5113 format
= PixelFormat_DD2WineD3D(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
5114 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5115 return wined3d_texture_create_cube(surface
->ddraw
->wined3d_device
, desc
->dwWidth
,
5116 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5118 return wined3d_texture_create_2d(surface
->ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
,
5119 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5122 HRESULT
ddraw_surface_init(IDirectDrawSurfaceImpl
*surface
, IDirectDrawImpl
*ddraw
,
5123 DDSURFACEDESC2
*desc
, UINT mip_level
, WINED3DSURFTYPE surface_type
, UINT version
)
5125 struct wined3d_resource_desc wined3d_desc
;
5126 struct wined3d_resource
*wined3d_resource
;
5127 WINED3DPOOL pool
= WINED3DPOOL_DEFAULT
;
5128 enum wined3d_format_id format
;
5132 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5133 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5134 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)))
5136 /* Tests show surfaces without memory flags get these flags added
5137 * right after creation. */
5138 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5141 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5143 usage
|= WINED3DUSAGE_RENDERTARGET
;
5144 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5147 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5149 usage
|= WINED3DUSAGE_RENDERTARGET
;
5152 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
5154 usage
|= WINED3DUSAGE_OVERLAY
;
5157 if (ddraw
->depthstencil
|| (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5159 /* The depth stencil creation callback sets this flag. Set the
5160 * wined3d usage to let it know it's a depth/stencil surface. */
5161 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5164 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5166 pool
= WINED3DPOOL_SYSTEMMEM
;
5168 else if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
5170 pool
= WINED3DPOOL_MANAGED
;
5171 /* Managed textures have the system memory flag set. */
5172 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5174 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5176 /* Videomemory adds localvidmem. This is mutually exclusive with
5177 * systemmemory and texturemanage. */
5178 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5181 format
= PixelFormat_DD2WineD3D(&desc
->u4
.ddpfPixelFormat
);
5182 if (format
== WINED3DFMT_UNKNOWN
)
5184 WARN("Unsupported / unknown pixelformat.\n");
5185 return DDERR_INVALIDPIXELFORMAT
;
5188 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
5189 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
5190 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
5191 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
5192 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
5193 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
5194 surface
->IDirect3DTexture2_vtbl
= &d3d_texture2_vtbl
;
5195 surface
->IDirect3DTexture_vtbl
= &d3d_texture1_vtbl
;
5196 surface
->iface_count
= 1;
5197 surface
->version
= version
;
5198 surface
->ddraw
= ddraw
;
5204 else if (version
== 4)
5213 copy_to_surfacedesc2(&surface
->surface_desc
, desc
);
5215 surface
->first_attached
= surface
;
5216 surface
->ImplType
= surface_type
;
5218 hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
, format
,
5219 TRUE
/* Lockable */, FALSE
/* Discard */, mip_level
, usage
, pool
,
5220 WINED3DMULTISAMPLE_NONE
, 0 /* MultiSampleQuality */, surface_type
, surface
,
5221 &ddraw_surface_wined3d_parent_ops
, &surface
->wined3d_surface
);
5224 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
5228 surface
->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5229 wined3d_resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
5230 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
5232 format
= wined3d_desc
.format
;
5233 if (format
== WINED3DFMT_UNKNOWN
)
5235 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN.\n");
5237 PixelFormat_WineD3DtoDD(&surface
->surface_desc
.u4
.ddpfPixelFormat
, format
);
5239 /* Anno 1602 stores the pitch right after surface creation, so make sure
5240 * it's there. TODO: Test other fourcc formats. */
5241 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
5242 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
5244 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
5245 if (format
== WINED3DFMT_DXT1
)
5247 surface
->surface_desc
.u1
.dwLinearSize
= max(4, wined3d_desc
.width
) * max(4, wined3d_desc
.height
) / 2;
5251 surface
->surface_desc
.u1
.dwLinearSize
= max(4, wined3d_desc
.width
) * max(4, wined3d_desc
.height
);
5256 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
5257 surface
->surface_desc
.u1
.lPitch
= wined3d_surface_get_pitch(surface
->wined3d_surface
);
5260 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
5262 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
5263 (WINEDDCOLORKEY
*)&desc
->u3
.ddckCKDestOverlay
);
5265 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
5267 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTBLT
,
5268 (WINEDDCOLORKEY
*)&desc
->ddckCKDestBlt
);
5270 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
5272 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
5273 (WINEDDCOLORKEY
*)&desc
->ddckCKSrcOverlay
);
5275 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
5277 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCBLT
,
5278 (WINEDDCOLORKEY
*)&desc
->ddckCKSrcBlt
);
5280 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5282 hr
= wined3d_surface_set_mem(surface
->wined3d_surface
, desc
->lpSurface
);
5285 ERR("Failed to set surface memory, hr %#x.\n", hr
);
5286 wined3d_surface_decref(surface
->wined3d_surface
);