1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This file contains the (internal) driver registration functions,
10 * driver enumeration APIs and DirectDraw creation functions.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
30 #include "ddraw_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
34 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
35 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
37 static inline IDirectDrawSurfaceImpl
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
39 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawGammaControl_iface
);
42 /*****************************************************************************
43 * IUnknown parts follow
44 *****************************************************************************/
46 /*****************************************************************************
47 * IDirectDrawSurface7::QueryInterface
49 * A normal QueryInterface implementation. For QueryInterface rules
50 * see ddraw.c, IDirectDraw7::QueryInterface. This method
51 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
52 * in all versions, the IDirectDrawGammaControl interface and it can
53 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
56 * riid: The interface id queried for
57 * obj: Address to write the pointer to
61 * E_NOINTERFACE if the requested interface wasn't found
63 *****************************************************************************/
64 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
66 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
68 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
70 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
74 return DDERR_INVALIDPARAMS
;
76 if (IsEqualGUID(riid
, &IID_IUnknown
)
77 || IsEqualGUID(riid
, &IID_IDirectDrawSurface7
) )
79 IDirectDrawSurface7_AddRef(iface
);
81 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
84 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
86 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
87 *obj
= &This
->IDirectDrawSurface4_iface
;
88 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
91 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
93 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
94 *obj
= &This
->IDirectDrawSurface3_iface
;
95 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
98 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
100 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
101 *obj
= &This
->IDirectDrawSurface2_iface
;
102 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
105 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
))
107 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
108 *obj
= &This
->IDirectDrawSurface_iface
;
109 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
112 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
114 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
115 *obj
= &This
->IDirectDrawGammaControl_iface
;
116 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
119 else if( IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
) ||
120 IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)||
121 IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
) )
123 IDirect3DDevice7
*d3d
;
125 /* Call into IDirect3D7 for creation */
126 IDirect3D7_CreateDevice(&This
->ddraw
->IDirect3D7_iface
, riid
, &This
->IDirectDrawSurface7_iface
,
131 *obj
= (IDirect3DDevice
*)&((IDirect3DDeviceImpl
*)d3d
)->IDirect3DDevice_vtbl
;
132 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
136 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
137 return E_NOINTERFACE
;
139 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
140 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
142 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
144 *obj
= &This
->IDirect3DTexture_iface
;
145 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
149 *obj
= &This
->IDirect3DTexture2_iface
;
150 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
152 IUnknown_AddRef( (IUnknown
*) *obj
);
156 ERR("No interface\n");
157 return E_NOINTERFACE
;
160 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
162 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
163 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
165 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
168 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
170 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
171 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
173 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
176 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
178 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
179 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
181 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
184 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
186 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
187 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
189 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
192 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
193 REFIID riid
, void **object
)
195 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawGammaControl(iface
);
197 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
199 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
202 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
204 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture2(iface
);
205 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
207 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
210 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
212 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
213 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
215 return ddraw_surface7_QueryInterface(&This
->IDirectDrawSurface7_iface
, riid
, object
);
218 static void ddraw_surface_add_iface(IDirectDrawSurfaceImpl
*This
)
220 ULONG iface_count
= InterlockedIncrement(&This
->iface_count
);
221 TRACE("%p increasing iface count to %u.\n", This
, iface_count
);
223 if (iface_count
== 1)
225 EnterCriticalSection(&ddraw_cs
);
226 if (This
->wined3d_surface
)
227 wined3d_surface_incref(This
->wined3d_surface
);
228 if (This
->wined3d_texture
)
229 wined3d_texture_incref(This
->wined3d_texture
);
230 LeaveCriticalSection(&ddraw_cs
);
234 /*****************************************************************************
235 * IDirectDrawSurface7::AddRef
237 * A normal addref implementation
242 *****************************************************************************/
243 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
245 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
246 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
248 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
252 ddraw_surface_add_iface(This
);
258 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
260 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
261 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
263 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
267 ddraw_surface_add_iface(This
);
273 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
275 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
276 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
278 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
282 ddraw_surface_add_iface(This
);
288 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
290 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
291 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
293 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
297 ddraw_surface_add_iface(This
);
303 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
305 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
306 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
308 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
312 ddraw_surface_add_iface(This
);
318 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
320 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawGammaControl(iface
);
321 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
323 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
327 ddraw_surface_add_iface(This
);
333 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
335 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture2(iface
);
336 TRACE("iface %p.\n", iface
);
338 return ddraw_surface1_AddRef(&This
->IDirectDrawSurface_iface
);
341 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
343 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
344 TRACE("iface %p.\n", iface
);
346 return ddraw_surface1_AddRef(&This
->IDirectDrawSurface_iface
);
349 /*****************************************************************************
350 * ddraw_surface_destroy
352 * A helper function for IDirectDrawSurface7::Release
354 * Frees the surface, regardless of its refcount.
355 * See IDirectDrawSurface7::Release for more information
358 * This: Surface to free
360 *****************************************************************************/
361 void ddraw_surface_destroy(IDirectDrawSurfaceImpl
*This
)
363 TRACE("surface %p.\n", This
);
365 /* Check the iface count and give a warning */
366 if(This
->iface_count
> 1)
368 /* This can happen when a complex surface is destroyed,
369 * because the 2nd surface was addref()ed when the app
370 * called GetAttachedSurface
372 WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n",
373 This
, This
->ref7
, This
->ref4
, This
->ref3
, This
->ref2
, This
->ref1
);
376 if (This
->wined3d_surface
)
377 wined3d_surface_decref(This
->wined3d_surface
);
380 static void ddraw_surface_cleanup(IDirectDrawSurfaceImpl
*surface
)
382 IDirectDrawSurfaceImpl
*surf
;
383 IUnknown
*ifaceToRelease
;
386 TRACE("surface %p.\n", surface
);
388 if (surface
->wined3d_swapchain
)
390 IDirectDrawImpl
*ddraw
= surface
->ddraw
;
392 /* If it's the render target, destroy the D3D device. */
393 if (ddraw
->d3d_initialized
&& surface
== ddraw
->d3d_target
)
395 TRACE("Destroying the render target, uninitializing D3D.\n");
397 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
399 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
401 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
402 ddraw
->numConvertedDecls
= 0;
404 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
406 ERR("Failed to uninit 3D.\n");
410 /* Free the d3d window if one was created. */
411 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
413 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
414 DestroyWindow(ddraw
->d3d_window
);
415 ddraw
->d3d_window
= 0;
419 ddraw
->d3d_initialized
= FALSE
;
420 ddraw
->d3d_target
= NULL
;
424 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
427 surface
->wined3d_swapchain
= NULL
;
429 TRACE("D3D unloaded.\n");
432 /* The refcount test shows that the palette is detached when the surface
434 IDirectDrawSurface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, NULL
);
436 /* Loop through all complex attached surfaces and destroy them.
438 * Yet again, only the root can have more than one complexly attached
439 * surface, all the others have a total of one. */
440 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
442 if (!surface
->complex_array
[i
])
445 surf
= surface
->complex_array
[i
];
446 surface
->complex_array
[i
] = NULL
;
449 IDirectDrawSurfaceImpl
*destroy
= surf
;
450 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
451 ddraw_surface_destroy(destroy
); /* Destroy it */
455 ifaceToRelease
= surface
->ifaceToRelease
;
457 /* Destroy the root surface. */
458 ddraw_surface_destroy(surface
);
460 /* Reduce the ddraw refcount */
462 IUnknown_Release(ifaceToRelease
);
465 ULONG
ddraw_surface_release_iface(IDirectDrawSurfaceImpl
*This
)
467 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
468 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
470 if (iface_count
== 0)
472 /* Complex attached surfaces are destroyed implicitly when the root is released */
473 EnterCriticalSection(&ddraw_cs
);
474 if(!This
->is_complex_root
)
476 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
477 LeaveCriticalSection(&ddraw_cs
);
480 if (This
->wined3d_texture
) /* If it's a texture, destroy the wined3d texture. */
481 wined3d_texture_decref(This
->wined3d_texture
);
483 ddraw_surface_cleanup(This
);
484 LeaveCriticalSection(&ddraw_cs
);
490 /*****************************************************************************
491 * IDirectDrawSurface7::Release
493 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
494 * surface is destroyed.
496 * Destroying the surface is a bit tricky. For the connection between
497 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
498 * It has a nice graph explaining the connection.
500 * What happens here is basically this:
501 * When a surface is destroyed, its WineD3DSurface is released,
502 * and the refcount of the DirectDraw interface is reduced by 1. If it has
503 * complex surfaces attached to it, then these surfaces are destroyed too,
504 * regardless of their refcount. If any surface being destroyed has another
505 * surface attached to it (with a "soft" attachment, not complex), then
506 * this surface is detached with DeleteAttachedSurface.
508 * When the surface is a texture, the WineD3DTexture is released.
509 * If the surface is the Direct3D render target, then the D3D
510 * capabilities of the WineD3DDevice are uninitialized, which causes the
511 * swapchain to be released.
513 * When a complex sublevel falls to ref zero, then this is ignored.
518 *****************************************************************************/
519 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
521 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
522 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
524 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
528 ddraw_surface_release_iface(This
);
534 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
536 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
537 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
539 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
543 ddraw_surface_release_iface(This
);
549 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
551 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
552 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
554 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
558 ddraw_surface_release_iface(This
);
564 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
566 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
567 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
569 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
573 ddraw_surface_release_iface(This
);
579 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
581 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
582 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
584 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
588 ddraw_surface_release_iface(This
);
594 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
596 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawGammaControl(iface
);
597 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
599 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
603 ddraw_surface_release_iface(This
);
609 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
611 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture2(iface
);
612 TRACE("iface %p.\n", iface
);
614 return ddraw_surface1_Release(&This
->IDirectDrawSurface_iface
);
617 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
619 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
620 TRACE("iface %p.\n", iface
);
622 return ddraw_surface1_Release(&This
->IDirectDrawSurface_iface
);
625 /*****************************************************************************
626 * IDirectDrawSurface7::GetAttachedSurface
628 * Returns an attached surface with the requested caps. Surface attachment
629 * and complex surfaces are not clearly described by the MSDN or sdk,
630 * so this method is tricky and likely to contain problems.
631 * This implementation searches the complex list first, then the
634 * The chains are searched from This down to the last surface in the chain,
635 * not from the first element in the chain. The first surface found is
636 * returned. The MSDN says that this method fails if more than one surface
637 * matches the caps, but it is not sure if that is right. The attachment
638 * structure may not even allow two matching surfaces.
640 * The found surface is AddRef-ed before it is returned.
643 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
644 * Surface: Address to store the found surface
648 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
649 * DDERR_NOTFOUND if no surface was found
651 *****************************************************************************/
652 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
653 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
655 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
656 IDirectDrawSurfaceImpl
*surf
;
660 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
662 EnterCriticalSection(&ddraw_cs
);
664 if(This
->version
< 7)
666 /* Earlier dx apps put garbage into these members, clear them */
667 our_caps
.dwCaps
= Caps
->dwCaps
;
668 our_caps
.dwCaps2
= 0;
669 our_caps
.dwCaps3
= 0;
670 our_caps
.dwCaps4
= 0;
677 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 */
679 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
681 surf
= This
->complex_array
[i
];
686 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
687 surf
->surface_desc
.ddsCaps
.dwCaps
,
688 surf
->surface_desc
.ddsCaps
.dwCaps2
,
689 surf
->surface_desc
.ddsCaps
.dwCaps3
,
690 surf
->surface_desc
.ddsCaps
.dwCaps4
);
693 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
694 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
696 /* MSDN: "This method fails if more than one surface is attached
697 * that matches the capabilities requested."
699 * Not sure how to test this.
702 TRACE("(%p): Returning surface %p\n", This
, surf
);
703 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
704 *Surface
= &surf
->IDirectDrawSurface7_iface
;
705 ddraw_surface7_AddRef(*Surface
);
706 LeaveCriticalSection(&ddraw_cs
);
711 /* Next, look at the attachment chain */
714 while( (surf
= surf
->next_attached
) )
718 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
719 surf
->surface_desc
.ddsCaps
.dwCaps
,
720 surf
->surface_desc
.ddsCaps
.dwCaps2
,
721 surf
->surface_desc
.ddsCaps
.dwCaps3
,
722 surf
->surface_desc
.ddsCaps
.dwCaps4
);
725 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
726 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
728 TRACE("(%p): Returning surface %p\n", This
, surf
);
729 *Surface
= &surf
->IDirectDrawSurface7_iface
;
730 ddraw_surface7_AddRef(*Surface
);
731 LeaveCriticalSection(&ddraw_cs
);
736 TRACE("(%p) Didn't find a valid surface\n", This
);
737 LeaveCriticalSection(&ddraw_cs
);
740 return DDERR_NOTFOUND
;
743 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
744 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
746 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
747 IDirectDrawSurface7
*attachment7
;
748 IDirectDrawSurfaceImpl
*attachment_impl
;
751 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
753 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
760 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
761 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
762 ddraw_surface4_AddRef(*attachment
);
763 ddraw_surface7_Release(attachment7
);
768 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
769 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
771 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
772 IDirectDrawSurface7
*attachment7
;
773 IDirectDrawSurfaceImpl
*attachment_impl
;
777 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
779 caps2
.dwCaps
= caps
->dwCaps
;
784 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
785 &caps2
, &attachment7
);
791 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
792 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
793 ddraw_surface3_AddRef(*attachment
);
794 ddraw_surface7_Release(attachment7
);
799 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
800 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
802 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
803 IDirectDrawSurface7
*attachment7
;
804 IDirectDrawSurfaceImpl
*attachment_impl
;
808 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
810 caps2
.dwCaps
= caps
->dwCaps
;
815 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
816 &caps2
, &attachment7
);
822 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
823 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
824 ddraw_surface2_AddRef(*attachment
);
825 ddraw_surface7_Release(attachment7
);
830 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
831 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
833 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
834 IDirectDrawSurface7
*attachment7
;
835 IDirectDrawSurfaceImpl
*attachment_impl
;
839 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
841 caps2
.dwCaps
= caps
->dwCaps
;
846 hr
= ddraw_surface7_GetAttachedSurface(&This
->IDirectDrawSurface7_iface
,
847 &caps2
, &attachment7
);
853 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
854 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
855 ddraw_surface1_AddRef(*attachment
);
856 ddraw_surface7_Release(attachment7
);
861 /*****************************************************************************
862 * IDirectDrawSurface7::Lock
864 * Locks the surface and returns a pointer to the surface's memory
867 * Rect: Rectangle to lock. If NULL, the whole surface is locked
868 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
869 * Flags: Locking flags, e.g Read only or write only
870 * h: An event handle that's not used and must be NULL
874 * DDERR_INVALIDPARAMS if DDSD is NULL
875 * For more details, see IWineD3DSurface::LockRect
877 *****************************************************************************/
878 static HRESULT WINAPI
surface_lock(IDirectDrawSurfaceImpl
*This
,
879 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
881 WINED3DLOCKED_RECT LockedRect
;
884 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
885 This
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
887 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
888 EnterCriticalSection(&ddraw_cs
);
890 /* Should I check for the handle to be NULL?
892 * The DDLOCK flags and the D3DLOCK flags are equal
893 * for the supported values. The others are ignored by WineD3D
896 /* Windows zeroes this if the rect is invalid */
903 || (Rect
->left
> Rect
->right
)
904 || (Rect
->top
> Rect
->bottom
)
905 || (Rect
->right
> This
->surface_desc
.dwWidth
)
906 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
908 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
909 LeaveCriticalSection(&ddraw_cs
);
910 return DDERR_INVALIDPARAMS
;
914 hr
= wined3d_surface_map(This
->wined3d_surface
, &LockedRect
, Rect
, Flags
);
917 LeaveCriticalSection(&ddraw_cs
);
920 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
921 * specific error. But since IWineD3DSurface::LockRect returns that error in this
922 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
923 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
924 * is much easier to do it in one place in ddraw
926 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
931 /* Override the memory area. The pitch should be set already. Strangely windows
932 * does not set the LPSURFACE flag on locked surfaces !?!.
933 * DDSD->dwFlags |= DDSD_LPSURFACE;
935 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
936 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
938 TRACE("locked surface returning description :\n");
939 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
941 LeaveCriticalSection(&ddraw_cs
);
945 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
946 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
948 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
949 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
950 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
952 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
953 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
954 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
956 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
957 return DDERR_INVALIDPARAMS
;
959 return surface_lock(This
, rect
, surface_desc
, flags
, h
);
962 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
963 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
965 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
966 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
967 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
969 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
970 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
971 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
973 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
974 return DDERR_INVALIDPARAMS
;
976 return surface_lock(This
, rect
, surface_desc
, flags
, h
);
979 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
980 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
982 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
983 DDSURFACEDESC2 surface_desc2
;
985 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
986 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
988 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
989 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
990 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
992 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
993 return DDERR_INVALIDPARAMS
;
996 surface_desc2
.dwSize
= surface_desc
->dwSize
;
997 hr
= surface_lock(This
, rect
, &surface_desc2
, flags
, h
);
998 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
999 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1003 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1004 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1006 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1007 DDSURFACEDESC2 surface_desc2
;
1009 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1010 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1012 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1013 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1014 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1016 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1017 return DDERR_INVALIDPARAMS
;
1020 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1021 hr
= surface_lock(This
, rect
, &surface_desc2
, flags
, h
);
1022 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1023 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1027 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1028 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1030 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1031 DDSURFACEDESC2 surface_desc2
;
1033 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1034 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1036 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1037 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1038 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1040 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1041 return DDERR_INVALIDPARAMS
;
1044 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1045 hr
= surface_lock(This
, rect
, &surface_desc2
, flags
, h
);
1046 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1047 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1051 /*****************************************************************************
1052 * IDirectDrawSurface7::Unlock
1054 * Unlocks an locked surface
1057 * Rect: Not used by this implementation
1061 * For more details, see IWineD3DSurface::UnlockRect
1063 *****************************************************************************/
1064 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1066 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1069 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1071 EnterCriticalSection(&ddraw_cs
);
1072 hr
= wined3d_surface_unmap(This
->wined3d_surface
);
1075 This
->surface_desc
.lpSurface
= NULL
;
1077 LeaveCriticalSection(&ddraw_cs
);
1081 static HRESULT WINAPI
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1083 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1084 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1086 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, pRect
);
1089 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1091 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1092 TRACE("iface %p, data %p.\n", iface
, data
);
1094 /* data might not be the LPRECT of later versions, so drop it. */
1095 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, NULL
);
1098 static HRESULT WINAPI
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1100 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1101 TRACE("iface %p, data %p.\n", iface
, data
);
1103 /* data might not be the LPRECT of later versions, so drop it. */
1104 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, NULL
);
1107 static HRESULT WINAPI
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1109 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1110 TRACE("iface %p, data %p.\n", iface
, data
);
1112 /* data might not be the LPRECT of later versions, so drop it. */
1113 return ddraw_surface7_Unlock(&This
->IDirectDrawSurface7_iface
, NULL
);
1116 /*****************************************************************************
1117 * IDirectDrawSurface7::Flip
1119 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
1120 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
1121 * the flip target is passed to WineD3D, even if the app didn't specify one
1124 * DestOverride: Specifies the surface that will become the new front
1125 * buffer. If NULL, the current back buffer is used
1126 * Flags: some DirectDraw flags, see include/ddraw.h
1130 * DDERR_NOTFLIPPABLE if no flip target could be found
1131 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
1132 * For more details, see IWineD3DSurface::Flip
1134 *****************************************************************************/
1135 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
1137 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1138 IDirectDrawSurfaceImpl
*Override
= unsafe_impl_from_IDirectDrawSurface7(DestOverride
);
1139 IDirectDrawSurface7
*Override7
;
1142 TRACE("iface %p, dst %p, flags %#x.\n", iface
, DestOverride
, Flags
);
1144 /* Flip has to be called from a front buffer
1145 * What about overlay surfaces, AFAIK they can flip too?
1147 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
1148 return DDERR_INVALIDOBJECT
; /* Unchecked */
1150 EnterCriticalSection(&ddraw_cs
);
1152 /* WineD3D doesn't keep track of attached surface, so find the target */
1157 memset(&Caps
, 0, sizeof(Caps
));
1158 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
1159 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
1162 ERR("Can't find a flip target\n");
1163 LeaveCriticalSection(&ddraw_cs
);
1164 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1166 Override
= impl_from_IDirectDrawSurface7(Override7
);
1168 /* For the GetAttachedSurface */
1169 ddraw_surface7_Release(Override7
);
1172 hr
= wined3d_surface_flip(This
->wined3d_surface
, Override
->wined3d_surface
, Flags
);
1173 LeaveCriticalSection(&ddraw_cs
);
1177 static HRESULT WINAPI
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*dst
, DWORD flags
)
1179 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1180 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1181 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1183 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1184 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1187 static HRESULT WINAPI
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
1189 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1190 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1191 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1193 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1194 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1197 static HRESULT WINAPI
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*dst
, DWORD flags
)
1199 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1200 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1201 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1203 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1204 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1207 static HRESULT WINAPI
ddraw_surface1_Flip(IDirectDrawSurface
*iface
, IDirectDrawSurface
*dst
, DWORD flags
)
1209 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1210 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1211 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1213 return ddraw_surface7_Flip(&This
->IDirectDrawSurface7_iface
,
1214 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1217 /*****************************************************************************
1218 * IDirectDrawSurface7::Blt
1220 * Performs a blit on the surface
1223 * DestRect: Destination rectangle, can be NULL
1224 * SrcSurface: Source surface, can be NULL
1225 * SrcRect: Source rectangle, can be NULL
1227 * DDBltFx: Some extended blt parameters, connected to the flags
1231 * See IWineD3DSurface::Blt for more details
1233 *****************************************************************************/
1234 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1235 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1237 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1238 IDirectDrawSurfaceImpl
*Src
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1241 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1242 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1244 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1245 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1247 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1248 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1249 return DDERR_INVALIDPARAMS
;
1252 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1253 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1254 return DDERR_INVALIDPARAMS
;
1257 EnterCriticalSection(&ddraw_cs
);
1259 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
1260 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1261 LeaveCriticalSection(&ddraw_cs
);
1262 return DDERR_INVALIDPARAMS
;
1265 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1266 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1267 * surfaces. So far no blitting operations using surfaces in the bltfx
1268 * struct are supported anyway. */
1269 hr
= wined3d_surface_blt(This
->wined3d_surface
, DestRect
, Src
? Src
->wined3d_surface
: NULL
,
1270 SrcRect
, Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3DTEXF_LINEAR
);
1272 LeaveCriticalSection(&ddraw_cs
);
1275 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1276 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1281 static HRESULT WINAPI
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1282 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1284 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1285 IDirectDrawSurfaceImpl
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1286 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1287 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1289 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1290 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1293 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1294 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1296 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1297 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1298 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1299 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1301 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1302 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1305 static HRESULT WINAPI
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1306 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1308 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1309 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1310 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1311 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1313 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1314 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1317 static HRESULT WINAPI
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1318 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1320 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1321 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1322 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1323 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1325 return ddraw_surface7_Blt(&This
->IDirectDrawSurface7_iface
, dst_rect
,
1326 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1329 /*****************************************************************************
1330 * IDirectDrawSurface7::AddAttachedSurface
1332 * Attaches a surface to another surface. How the surface attachments work
1333 * is not totally understood yet, and this method is prone to problems.
1334 * he surface that is attached is AddRef-ed.
1336 * Tests with complex surfaces suggest that the surface attachments form a
1337 * tree, but no method to test this has been found yet.
1339 * The attachment list consists of a first surface (first_attached) and
1340 * for each surface a pointer to the next attached surface (next_attached).
1341 * For the first surface, and a surface that has no attachments
1342 * first_attached points to the surface itself. A surface that has
1343 * no successors in the chain has next_attached set to NULL.
1345 * Newly attached surfaces are attached right after the root surface.
1346 * If a surface is attached to a complex surface compound, it's attached to
1347 * the surface that the app requested, not the complex root. See
1348 * GetAttachedSurface for a description how surfaces are found.
1350 * This is how the current implementation works, and it was coded by looking
1351 * at the needs of the applications.
1353 * So far only Z-Buffer attachments are tested, and they are activated in
1354 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1355 * Back buffers should work in 2D mode, but they are not tested(They can be
1356 * attached in older iface versions). Rendering to the front buffer and
1357 * switching between that and double buffering is not yet implemented in
1358 * WineD3D, so for 3D it might have unexpected results.
1360 * ddraw_surface_attach_surface is the real thing,
1361 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1362 * performs additional checks. Version 7 of this interface is much more restrictive
1363 * than its predecessors.
1366 * Attach: Surface to attach to iface
1370 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1372 *****************************************************************************/
1373 static HRESULT
ddraw_surface_attach_surface(IDirectDrawSurfaceImpl
*This
, IDirectDrawSurfaceImpl
*Surf
)
1375 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1378 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1380 EnterCriticalSection(&ddraw_cs
);
1382 /* Check if the surface is already attached somewhere */
1383 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1385 /* TODO: Test for the structure of the manual attachment. Is it a
1386 * chain or a list? What happens if one surface is attached to 2
1387 * different surfaces? */
1388 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1389 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1391 LeaveCriticalSection(&ddraw_cs
);
1392 return DDERR_SURFACEALREADYATTACHED
;
1395 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1396 Surf
->next_attached
= This
->next_attached
;
1397 Surf
->first_attached
= This
->first_attached
;
1398 This
->next_attached
= Surf
;
1400 /* Check if the WineD3D depth stencil needs updating */
1401 if(This
->ddraw
->d3ddevice
)
1403 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1406 LeaveCriticalSection(&ddraw_cs
);
1410 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*Attach
)
1412 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1413 IDirectDrawSurfaceImpl
*Surf
= unsafe_impl_from_IDirectDrawSurface7(Attach
);
1416 TRACE("iface %p, attachment %p.\n", iface
, Attach
);
1418 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1419 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1422 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1423 Surf
->surface_desc
.ddsCaps
.dwCaps
);
1424 return DDERR_CANNOTATTACHSURFACE
;
1427 hr
= ddraw_surface_attach_surface(This
, Surf
);
1432 ddraw_surface7_AddRef(Attach
);
1436 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1438 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1439 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1442 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1444 hr
= ddraw_surface7_AddAttachedSurface(&This
->IDirectDrawSurface7_iface
,
1445 attachment_impl
? &attachment_impl
->IDirectDrawSurface7_iface
: NULL
);
1450 ddraw_surface4_AddRef(attachment
);
1451 ddraw_surface7_Release(&attachment_impl
->IDirectDrawSurface7_iface
);
1454 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1456 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1457 IDirectDrawSurfaceImpl
*attach_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1460 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1462 /* Tests suggest that
1463 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1464 * -> offscreen plain surfaces can be attached to primaries
1465 * -> primaries can be attached to offscreen plain surfaces
1466 * -> z buffers can be attached to primaries */
1467 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1468 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1470 /* Sizes have to match */
1471 if (attach_impl
->surface_desc
.dwWidth
!= This
->surface_desc
.dwWidth
1472 || attach_impl
->surface_desc
.dwHeight
!= This
->surface_desc
.dwHeight
)
1474 WARN("Surface sizes do not match.\n");
1475 return DDERR_CANNOTATTACHSURFACE
;
1479 else if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1480 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1486 WARN("Invalid attachment combination.\n");
1487 return DDERR_CANNOTATTACHSURFACE
;
1490 hr
= ddraw_surface_attach_surface(This
, attach_impl
);
1495 ddraw_surface3_AddRef(attachment
);
1499 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1501 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1502 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1505 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1507 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1508 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1513 ddraw_surface2_AddRef(attachment
);
1514 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1518 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1520 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1521 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1524 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1526 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1527 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1532 ddraw_surface1_AddRef(attachment
);
1533 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1537 /*****************************************************************************
1538 * IDirectDrawSurface7::DeleteAttachedSurface
1540 * Removes a surface from the attachment chain. The surface's refcount
1541 * is decreased by one after it has been removed
1544 * Flags: Some flags, not used by this implementation
1545 * Attach: Surface to detach
1549 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1551 *****************************************************************************/
1552 static HRESULT
ddraw_surface_delete_attached_surface(IDirectDrawSurfaceImpl
*This
,
1553 IDirectDrawSurfaceImpl
*Surf
)
1555 IDirectDrawSurfaceImpl
*Prev
= This
;
1557 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1559 EnterCriticalSection(&ddraw_cs
);
1560 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
1562 LeaveCriticalSection(&ddraw_cs
);
1563 return DDERR_CANNOTDETACHSURFACE
;
1566 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1567 if (This
->surface_desc
.ddsCaps
.dwCaps
&
1568 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1570 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1571 /* FIXME: we should probably also subtract from dwMipMapCount of this
1572 * and all parent surfaces */
1575 /* Find the predecessor of the detached surface */
1578 if(Prev
->next_attached
== Surf
) break;
1579 Prev
= Prev
->next_attached
;
1582 /* There must be a surface, otherwise there's a bug */
1583 assert(Prev
!= NULL
);
1585 /* Unchain the surface */
1586 Prev
->next_attached
= Surf
->next_attached
;
1587 Surf
->next_attached
= NULL
;
1588 Surf
->first_attached
= Surf
;
1590 /* Check if the WineD3D depth stencil needs updating */
1591 if(This
->ddraw
->d3ddevice
)
1593 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1595 LeaveCriticalSection(&ddraw_cs
);
1599 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1600 DWORD flags
, IDirectDrawSurface7
*attachment
)
1602 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1603 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1606 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1608 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1613 ddraw_surface7_Release(attachment
);
1617 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1618 DWORD flags
, IDirectDrawSurface4
*attachment
)
1620 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1621 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1624 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1626 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1631 ddraw_surface4_Release(attachment
);
1635 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1636 DWORD flags
, IDirectDrawSurface3
*attachment
)
1638 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1639 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1641 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1643 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1648 ddraw_surface3_Release(attachment
);
1652 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
1653 DWORD flags
, IDirectDrawSurface2
*attachment
)
1655 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1656 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1658 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1660 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1665 ddraw_surface2_Release(attachment
);
1669 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
1670 DWORD flags
, IDirectDrawSurface
*attachment
)
1672 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1673 IDirectDrawSurfaceImpl
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1675 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1677 hr
= ddraw_surface_delete_attached_surface(This
, attachment_impl
);
1682 ddraw_surface1_Release(attachment
);
1686 /*****************************************************************************
1687 * IDirectDrawSurface7::AddOverlayDirtyRect
1689 * "This method is not currently implemented"
1697 *****************************************************************************/
1698 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1700 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1702 return DDERR_UNSUPPORTED
; /* unchecked */
1705 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
1707 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1708 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1710 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1713 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1715 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1716 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1718 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1721 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
1723 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1724 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1726 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1729 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
1731 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1732 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1734 return ddraw_surface7_AddOverlayDirtyRect(&This
->IDirectDrawSurface7_iface
, rect
);
1737 /*****************************************************************************
1738 * IDirectDrawSurface7::GetDC
1740 * Returns a GDI device context for the surface
1743 * hdc: Address of a HDC variable to store the dc to
1747 * DDERR_INVALIDPARAMS if hdc is NULL
1748 * For details, see IWineD3DSurface::GetDC
1750 *****************************************************************************/
1751 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1753 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1756 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1759 return DDERR_INVALIDPARAMS
;
1761 EnterCriticalSection(&ddraw_cs
);
1762 hr
= wined3d_surface_getdc(This
->wined3d_surface
, hdc
);
1763 LeaveCriticalSection(&ddraw_cs
);
1766 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1769 case WINED3DERR_INVALIDCALL
:
1770 if(hdc
) *hdc
= NULL
;
1771 return DDERR_INVALIDPARAMS
;
1777 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
1779 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1780 TRACE("iface %p, dc %p.\n", iface
, dc
);
1782 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1785 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1787 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1788 TRACE("iface %p, dc %p.\n", iface
, dc
);
1790 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1793 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
1795 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1796 TRACE("iface %p, dc %p.\n", iface
, dc
);
1798 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1801 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
1803 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1804 TRACE("iface %p, dc %p.\n", iface
, dc
);
1806 return ddraw_surface7_GetDC(&This
->IDirectDrawSurface7_iface
, dc
);
1809 /*****************************************************************************
1810 * IDirectDrawSurface7::ReleaseDC
1812 * Releases the DC that was constructed with GetDC
1815 * hdc: HDC to release
1819 * For more details, see IWineD3DSurface::ReleaseDC
1821 *****************************************************************************/
1822 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
1824 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1827 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1829 EnterCriticalSection(&ddraw_cs
);
1830 hr
= wined3d_surface_releasedc(This
->wined3d_surface
, hdc
);
1831 LeaveCriticalSection(&ddraw_cs
);
1835 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
1837 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1838 TRACE("iface %p, dc %p.\n", iface
, dc
);
1840 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1843 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
1845 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1846 TRACE("iface %p, dc %p.\n", iface
, dc
);
1848 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1851 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
1853 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1854 TRACE("iface %p, dc %p.\n", iface
, dc
);
1856 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1859 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
1861 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1862 TRACE("iface %p, dc %p.\n", iface
, dc
);
1864 return ddraw_surface7_ReleaseDC(&This
->IDirectDrawSurface7_iface
, dc
);
1867 /*****************************************************************************
1868 * IDirectDrawSurface7::GetCaps
1870 * Returns the surface's caps
1873 * Caps: Address to write the caps to
1877 * DDERR_INVALIDPARAMS if Caps is NULL
1879 *****************************************************************************/
1880 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
1882 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1884 TRACE("iface %p, caps %p.\n", iface
, Caps
);
1887 return DDERR_INVALIDPARAMS
;
1889 *Caps
= This
->surface_desc
.ddsCaps
;
1893 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
1895 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
1896 TRACE("iface %p, caps %p.\n", iface
, caps
);
1898 return ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, caps
);
1901 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
1903 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
1907 TRACE("iface %p, caps %p.\n", iface
, caps
);
1909 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1910 if (FAILED(hr
)) return hr
;
1912 caps
->dwCaps
= caps2
.dwCaps
;
1916 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
1918 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
1922 TRACE("iface %p, caps %p.\n", iface
, caps
);
1924 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1925 if (FAILED(hr
)) return hr
;
1927 caps
->dwCaps
= caps2
.dwCaps
;
1931 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
1933 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
1937 TRACE("iface %p, caps %p.\n", iface
, caps
);
1939 hr
= ddraw_surface7_GetCaps(&This
->IDirectDrawSurface7_iface
, &caps2
);
1940 if (FAILED(hr
)) return hr
;
1942 caps
->dwCaps
= caps2
.dwCaps
;
1946 /*****************************************************************************
1947 * IDirectDrawSurface7::SetPriority
1949 * Sets a texture priority for managed textures.
1952 * Priority: The new priority
1956 * For more details, see IWineD3DSurface::SetPriority
1958 *****************************************************************************/
1959 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1961 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1964 TRACE("iface %p, priority %u.\n", iface
, Priority
);
1966 EnterCriticalSection(&ddraw_cs
);
1967 hr
= wined3d_surface_set_priority(This
->wined3d_surface
, Priority
);
1968 LeaveCriticalSection(&ddraw_cs
);
1972 /*****************************************************************************
1973 * IDirectDrawSurface7::GetPriority
1975 * Returns the surface's priority
1978 * Priority: Address of a variable to write the priority to
1982 * DDERR_INVALIDPARAMS if Priority == NULL
1983 * For more details, see IWineD3DSurface::GetPriority
1985 *****************************************************************************/
1986 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
1988 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
1990 TRACE("iface %p, priority %p.\n", iface
, Priority
);
1994 return DDERR_INVALIDPARAMS
;
1997 EnterCriticalSection(&ddraw_cs
);
1998 *Priority
= wined3d_surface_get_priority(This
->wined3d_surface
);
1999 LeaveCriticalSection(&ddraw_cs
);
2003 /*****************************************************************************
2004 * IDirectDrawSurface7::SetPrivateData
2006 * Stores some data in the surface that is intended for the application's
2010 * tag: GUID that identifies the data
2011 * Data: Pointer to the private data
2012 * Size: Size of the private data
2017 * For more details, see IWineD3DSurface::SetPrivateData
2019 *****************************************************************************/
2020 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2021 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
2023 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2024 struct wined3d_resource
*resource
;
2027 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2028 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
2030 EnterCriticalSection(&ddraw_cs
);
2031 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2032 hr
= wined3d_resource_set_private_data(resource
, tag
, Data
, Size
, Flags
);
2033 LeaveCriticalSection(&ddraw_cs
);
2036 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2041 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2042 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2044 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2045 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2046 iface
, debugstr_guid(tag
), data
, size
, flags
);
2048 return ddraw_surface7_SetPrivateData(&This
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2051 /*****************************************************************************
2052 * IDirectDrawSurface7::GetPrivateData
2054 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2057 * tag: GUID of the data to return
2058 * Data: Address where to write the data to
2059 * Size: Size of the buffer at Data
2063 * DDERR_INVALIDPARAMS if Data is NULL
2064 * For more details, see IWineD3DSurface::GetPrivateData
2066 *****************************************************************************/
2067 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
2069 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2070 struct wined3d_resource
*resource
;
2073 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2074 iface
, debugstr_guid(tag
), Data
, Size
);
2077 return DDERR_INVALIDPARAMS
;
2079 EnterCriticalSection(&ddraw_cs
);
2080 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2081 hr
= wined3d_resource_get_private_data(resource
, tag
, Data
, Size
);
2082 LeaveCriticalSection(&ddraw_cs
);
2086 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2088 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2089 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2090 iface
, debugstr_guid(tag
), data
, size
);
2092 return ddraw_surface7_GetPrivateData(&This
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2095 /*****************************************************************************
2096 * IDirectDrawSurface7::FreePrivateData
2098 * Frees private data stored in the surface
2101 * tag: Tag of the data to free
2105 * For more details, see IWineD3DSurface::FreePrivateData
2107 *****************************************************************************/
2108 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2110 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2111 struct wined3d_resource
*resource
;
2114 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2116 EnterCriticalSection(&ddraw_cs
);
2117 resource
= wined3d_surface_get_resource(This
->wined3d_surface
);
2118 hr
= wined3d_resource_free_private_data(resource
, tag
);
2119 LeaveCriticalSection(&ddraw_cs
);
2123 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2125 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2126 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2128 return ddraw_surface7_FreePrivateData(&This
->IDirectDrawSurface7_iface
, tag
);
2131 /*****************************************************************************
2132 * IDirectDrawSurface7::PageLock
2134 * Prevents a sysmem surface from being paged out
2137 * Flags: Not used, must be 0(unchecked)
2140 * DD_OK, because it's a stub
2142 *****************************************************************************/
2143 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2145 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2147 /* This is Windows memory management related - we don't need this */
2151 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2153 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2154 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2156 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2159 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2161 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2162 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2164 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2167 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2169 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2170 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2172 return ddraw_surface7_PageLock(&This
->IDirectDrawSurface7_iface
, flags
);
2175 /*****************************************************************************
2176 * IDirectDrawSurface7::PageUnlock
2178 * Allows a sysmem surface to be paged out
2181 * Flags: Not used, must be 0(unchecked)
2184 * DD_OK, because it's a stub
2186 *****************************************************************************/
2187 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2189 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2194 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2196 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2197 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2199 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2202 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2204 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2205 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2207 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2210 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2212 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2213 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2215 return ddraw_surface7_PageUnlock(&This
->IDirectDrawSurface7_iface
, flags
);
2218 /*****************************************************************************
2219 * IDirectDrawSurface7::BltBatch
2221 * An unimplemented function
2229 *****************************************************************************/
2230 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2232 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2234 /* MSDN: "not currently implemented" */
2235 return DDERR_UNSUPPORTED
;
2238 static HRESULT WINAPI
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2240 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2241 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2243 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2246 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2248 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2249 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2251 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2254 static HRESULT WINAPI
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2256 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2257 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2259 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2262 static HRESULT WINAPI
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2264 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2265 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2267 return ddraw_surface7_BltBatch(&This
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2270 /*****************************************************************************
2271 * IDirectDrawSurface7::EnumAttachedSurfaces
2273 * Enumerates all surfaces attached to this surface
2276 * context: Pointer to pass unmodified to the callback
2277 * cb: Callback function to call for each surface
2281 * DDERR_INVALIDPARAMS if cb is NULL
2283 *****************************************************************************/
2284 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2285 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2287 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2288 IDirectDrawSurfaceImpl
*surf
;
2289 DDSURFACEDESC2 desc
;
2292 /* Attached surfaces aren't handled in WineD3D */
2293 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2296 return DDERR_INVALIDPARAMS
;
2298 EnterCriticalSection(&ddraw_cs
);
2299 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2301 surf
= This
->complex_array
[i
];
2304 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2305 desc
= surf
->surface_desc
;
2306 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2307 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2309 LeaveCriticalSection(&ddraw_cs
);
2314 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2316 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2317 desc
= surf
->surface_desc
;
2318 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2319 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2321 LeaveCriticalSection(&ddraw_cs
);
2326 TRACE(" end of enumeration.\n");
2328 LeaveCriticalSection(&ddraw_cs
);
2332 struct callback_info2
2334 LPDDENUMSURFACESCALLBACK2 callback
;
2338 struct callback_info
2340 LPDDENUMSURFACESCALLBACK callback
;
2344 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2346 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(surface
);
2347 const struct callback_info2
*info
= context
;
2349 ddraw_surface4_AddRef(&This
->IDirectDrawSurface4_iface
);
2350 ddraw_surface7_Release(surface
);
2352 return info
->callback(&This
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2355 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2357 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2358 const struct callback_info
*info
= context
;
2360 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2361 ddraw_surface7_Release(surface
);
2363 /* FIXME: Check surface_test.dwSize */
2364 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2365 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2368 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2369 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2371 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2372 struct callback_info2 info
;
2374 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2376 info
.callback
= callback
;
2377 info
.context
= context
;
2379 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2380 &info
, EnumCallback2
);
2383 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2384 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2386 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2387 struct callback_info info
;
2389 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2391 info
.callback
= callback
;
2392 info
.context
= context
;
2394 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2395 &info
, EnumCallback
);
2398 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2399 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2401 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2402 struct callback_info info
;
2404 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2406 info
.callback
= callback
;
2407 info
.context
= context
;
2409 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2410 &info
, EnumCallback
);
2413 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2414 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2416 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2417 struct callback_info info
;
2419 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2421 info
.callback
= callback
;
2422 info
.context
= context
;
2424 return ddraw_surface7_EnumAttachedSurfaces(&This
->IDirectDrawSurface7_iface
,
2425 &info
, EnumCallback
);
2428 /*****************************************************************************
2429 * IDirectDrawSurface7::EnumOverlayZOrders
2431 * "Enumerates the overlay surfaces on the specified destination"
2434 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2435 * context: context to pass back to the callback
2436 * cb: callback function to call for each enumerated surface
2439 * DD_OK, because it's a stub
2441 *****************************************************************************/
2442 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2443 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2445 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2450 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2451 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2453 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2454 struct callback_info2 info
;
2456 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2458 info
.callback
= callback
;
2459 info
.context
= context
;
2461 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2462 flags
, &info
, EnumCallback2
);
2465 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2466 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2468 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2469 struct callback_info info
;
2471 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2473 info
.callback
= callback
;
2474 info
.context
= context
;
2476 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2477 flags
, &info
, EnumCallback
);
2480 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2481 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2483 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2484 struct callback_info info
;
2486 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2488 info
.callback
= callback
;
2489 info
.context
= context
;
2491 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2492 flags
, &info
, EnumCallback
);
2495 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2496 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2498 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2499 struct callback_info info
;
2501 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2503 info
.callback
= callback
;
2504 info
.context
= context
;
2506 return ddraw_surface7_EnumOverlayZOrders(&This
->IDirectDrawSurface7_iface
,
2507 flags
, &info
, EnumCallback
);
2510 /*****************************************************************************
2511 * IDirectDrawSurface7::GetBltStatus
2513 * Returns the blitting status
2516 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2519 * See IWineD3DSurface::Blt
2521 *****************************************************************************/
2522 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2524 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2527 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2529 EnterCriticalSection(&ddraw_cs
);
2530 hr
= wined3d_surface_get_blt_status(This
->wined3d_surface
, Flags
);
2531 LeaveCriticalSection(&ddraw_cs
);
2534 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2539 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2541 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2542 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2544 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2547 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2549 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2550 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2552 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2555 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2557 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2558 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2560 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2563 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2565 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2566 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2568 return ddraw_surface7_GetBltStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2571 /*****************************************************************************
2572 * IDirectDrawSurface7::GetColorKey
2574 * Returns the color key assigned to the surface
2578 * CKey: Address to store the key to
2582 * DDERR_INVALIDPARAMS if CKey is NULL
2584 *****************************************************************************/
2585 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2587 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2589 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2592 return DDERR_INVALIDPARAMS
;
2594 EnterCriticalSection(&ddraw_cs
);
2598 case DDCKEY_DESTBLT
:
2599 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
2601 LeaveCriticalSection(&ddraw_cs
);
2602 return DDERR_NOCOLORKEY
;
2604 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
2607 case DDCKEY_DESTOVERLAY
:
2608 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
2610 LeaveCriticalSection(&ddraw_cs
);
2611 return DDERR_NOCOLORKEY
;
2613 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
2617 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
2619 LeaveCriticalSection(&ddraw_cs
);
2620 return DDERR_NOCOLORKEY
;
2622 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
2625 case DDCKEY_SRCOVERLAY
:
2626 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
2628 LeaveCriticalSection(&ddraw_cs
);
2629 return DDERR_NOCOLORKEY
;
2631 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
2635 LeaveCriticalSection(&ddraw_cs
);
2636 return DDERR_INVALIDPARAMS
;
2639 LeaveCriticalSection(&ddraw_cs
);
2643 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2645 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2646 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2648 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2651 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2653 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2654 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2656 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2659 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2661 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2662 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2664 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2667 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2669 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2670 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2672 return ddraw_surface7_GetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
2675 /*****************************************************************************
2676 * IDirectDrawSurface7::GetFlipStatus
2678 * Returns the flipping status of the surface
2681 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2684 * See IWineD3DSurface::GetFlipStatus
2686 *****************************************************************************/
2687 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2689 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2692 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2694 EnterCriticalSection(&ddraw_cs
);
2695 hr
= wined3d_surface_get_flip_status(This
->wined3d_surface
, Flags
);
2696 LeaveCriticalSection(&ddraw_cs
);
2699 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2704 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2706 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2707 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2709 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2712 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2714 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2715 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2717 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2720 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2722 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2723 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2725 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2728 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2730 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2731 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2733 return ddraw_surface7_GetFlipStatus(&This
->IDirectDrawSurface7_iface
, flags
);
2736 /*****************************************************************************
2737 * IDirectDrawSurface7::GetOverlayPosition
2739 * Returns the display coordinates of a visible and active overlay surface
2746 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
2747 *****************************************************************************/
2748 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
2750 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2753 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
2755 EnterCriticalSection(&ddraw_cs
);
2756 hr
= wined3d_surface_get_overlay_position(This
->wined3d_surface
, X
, Y
);
2757 LeaveCriticalSection(&ddraw_cs
);
2761 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
2763 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2764 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2766 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2769 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
2771 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2772 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2774 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2777 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
2779 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2780 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2782 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2785 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
2787 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2788 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2790 return ddraw_surface7_GetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
2793 /*****************************************************************************
2794 * IDirectDrawSurface7::GetPixelFormat
2796 * Returns the pixel format of the Surface
2799 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
2800 * format should be written
2804 * DDERR_INVALIDPARAMS if PixelFormat is NULL
2806 *****************************************************************************/
2807 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
2809 /* What is DDERR_INVALIDSURFACETYPE for here? */
2810 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2812 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
2815 return DDERR_INVALIDPARAMS
;
2817 EnterCriticalSection(&ddraw_cs
);
2818 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
2819 LeaveCriticalSection(&ddraw_cs
);
2824 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
2826 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2827 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2829 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2832 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
2834 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2835 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2837 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2840 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
2842 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2843 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2845 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2848 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
2850 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2851 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
2853 return ddraw_surface7_GetPixelFormat(&This
->IDirectDrawSurface7_iface
, pixel_format
);
2856 /*****************************************************************************
2857 * IDirectDrawSurface7::GetSurfaceDesc
2859 * Returns the description of this surface
2862 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
2867 * DDERR_INVALIDPARAMS if DDSD is NULL
2869 *****************************************************************************/
2870 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
2872 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
2874 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2877 return DDERR_INVALIDPARAMS
;
2879 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
2881 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
2882 return DDERR_INVALIDPARAMS
;
2885 EnterCriticalSection(&ddraw_cs
);
2886 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
2887 TRACE("Returning surface desc:\n");
2888 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
2890 LeaveCriticalSection(&ddraw_cs
);
2894 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
2896 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2897 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2899 return ddraw_surface7_GetSurfaceDesc(&This
->IDirectDrawSurface7_iface
, DDSD
);
2902 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
2904 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2906 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
2908 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
2910 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2912 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
2913 return DDERR_INVALIDPARAMS
;
2916 EnterCriticalSection(&ddraw_cs
);
2917 DDSD2_to_DDSD(&This
->surface_desc
, surface_desc
);
2918 TRACE("Returning surface desc:\n");
2919 if (TRACE_ON(ddraw
))
2921 /* DDRAW_dump_surface_desc handles the smaller size */
2922 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2925 LeaveCriticalSection(&ddraw_cs
);
2929 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
2931 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2932 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2934 return ddraw_surface3_GetSurfaceDesc(&This
->IDirectDrawSurface3_iface
, DDSD
);
2937 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
2939 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
2940 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
2942 return ddraw_surface3_GetSurfaceDesc(&This
->IDirectDrawSurface3_iface
, DDSD
);
2945 /*****************************************************************************
2946 * IDirectDrawSurface7::Initialize
2948 * Initializes the surface. This is a no-op in Wine
2951 * DD: Pointer to an DirectDraw interface
2952 * DDSD: Surface description for initialization
2955 * DDERR_ALREADYINITIALIZED
2957 *****************************************************************************/
2958 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
2959 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
2961 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2963 return DDERR_ALREADYINITIALIZED
;
2966 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
2967 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
2969 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
2970 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2972 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2973 ddraw
, surface_desc
);
2976 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
2977 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2979 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
2980 DDSURFACEDESC2 surface_desc2
;
2981 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2983 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2984 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2985 ddraw
, surface_desc
? &surface_desc2
: NULL
);
2988 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
2989 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
2991 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
2992 DDSURFACEDESC2 surface_desc2
;
2993 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
2995 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2996 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
2997 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3000 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3001 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3003 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3004 DDSURFACEDESC2 surface_desc2
;
3005 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3007 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3008 return ddraw_surface7_Initialize(&This
->IDirectDrawSurface7_iface
,
3009 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3012 /*****************************************************************************
3013 * IDirect3DTexture1::Initialize
3015 * The sdk says it's not implemented
3023 *****************************************************************************/
3024 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3025 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3027 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3029 return DDERR_UNSUPPORTED
; /* Unchecked */
3032 /*****************************************************************************
3033 * IDirectDrawSurface7::IsLost
3035 * Checks if the surface is lost
3038 * DD_OK, if the surface is usable
3039 * DDERR_ISLOST if the surface is lost
3040 * See IWineD3DSurface::IsLost for more details
3042 *****************************************************************************/
3043 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3045 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3048 TRACE("iface %p.\n", iface
);
3050 EnterCriticalSection(&ddraw_cs
);
3051 hr
= wined3d_surface_is_lost(This
->wined3d_surface
);
3052 LeaveCriticalSection(&ddraw_cs
);
3055 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3056 * WineD3D uses the same error for surfaces
3058 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3063 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3065 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3066 TRACE("iface %p.\n", iface
);
3068 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3071 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3073 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3074 TRACE("iface %p.\n", iface
);
3076 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3079 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3081 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3082 TRACE("iface %p.\n", iface
);
3084 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3087 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3089 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3090 TRACE("iface %p.\n", iface
);
3092 return ddraw_surface7_IsLost(&This
->IDirectDrawSurface7_iface
);
3095 /*****************************************************************************
3096 * IDirectDrawSurface7::Restore
3098 * Restores a lost surface. This makes the surface usable again, but
3099 * doesn't reload its old contents
3103 * See IWineD3DSurface::Restore for more details
3105 *****************************************************************************/
3106 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3108 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3111 TRACE("iface %p.\n", iface
);
3113 EnterCriticalSection(&ddraw_cs
);
3114 hr
= wined3d_surface_restore(This
->wined3d_surface
);
3115 LeaveCriticalSection(&ddraw_cs
);
3119 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3121 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3122 TRACE("iface %p.\n", iface
);
3124 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3127 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3129 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3130 TRACE("iface %p.\n", iface
);
3132 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3135 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3137 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3138 TRACE("iface %p.\n", iface
);
3140 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3143 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3145 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3146 TRACE("iface %p.\n", iface
);
3148 return ddraw_surface7_Restore(&This
->IDirectDrawSurface7_iface
);
3151 /*****************************************************************************
3152 * IDirectDrawSurface7::SetOverlayPosition
3154 * Changes the display coordinates of an overlay surface
3161 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3162 *****************************************************************************/
3163 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3165 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3168 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3170 EnterCriticalSection(&ddraw_cs
);
3171 hr
= wined3d_surface_set_overlay_position(This
->wined3d_surface
, X
, Y
);
3172 LeaveCriticalSection(&ddraw_cs
);
3176 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3178 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3179 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3181 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3184 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3186 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3187 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3189 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3192 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3194 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3195 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3197 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3200 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3202 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3203 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3205 return ddraw_surface7_SetOverlayPosition(&This
->IDirectDrawSurface7_iface
, x
, y
);
3208 /*****************************************************************************
3209 * IDirectDrawSurface7::UpdateOverlay
3211 * Modifies the attributes of an overlay surface.
3214 * SrcRect: The section of the source being used for the overlay
3215 * DstSurface: Address of the surface that is overlaid
3216 * DstRect: Place of the overlay
3217 * Flags: some DDOVER_* flags
3220 * DDERR_UNSUPPORTED, because we don't support overlays
3222 *****************************************************************************/
3223 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3224 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3226 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3227 IDirectDrawSurfaceImpl
*Dst
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3230 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3231 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3233 EnterCriticalSection(&ddraw_cs
);
3234 hr
= wined3d_surface_update_overlay(This
->wined3d_surface
, SrcRect
,
3235 Dst
? Dst
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3236 LeaveCriticalSection(&ddraw_cs
);
3238 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3239 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3240 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3246 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3247 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3249 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3250 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3251 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3252 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3254 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3255 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3258 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3259 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3261 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3262 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3263 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3264 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3266 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3267 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3270 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3271 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3273 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3274 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3275 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3276 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3278 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3279 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3282 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3283 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3285 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3286 IDirectDrawSurfaceImpl
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3287 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3288 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3290 return ddraw_surface7_UpdateOverlay(&This
->IDirectDrawSurface7_iface
, src_rect
,
3291 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3294 /*****************************************************************************
3295 * IDirectDrawSurface7::UpdateOverlayDisplay
3297 * The DX7 sdk says that it's not implemented
3302 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3304 *****************************************************************************/
3305 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3307 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3309 return DDERR_UNSUPPORTED
;
3312 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3314 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3315 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3317 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3320 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3322 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3323 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3325 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3328 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3330 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3331 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3333 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3336 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3338 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3339 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3341 return ddraw_surface7_UpdateOverlayDisplay(&This
->IDirectDrawSurface7_iface
, flags
);
3344 /*****************************************************************************
3345 * IDirectDrawSurface7::UpdateOverlayZOrder
3347 * Sets an overlay's Z order
3350 * Flags: DDOVERZ_* flags
3351 * DDSRef: Defines the relative position in the overlay chain
3354 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3356 *****************************************************************************/
3357 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3358 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3360 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3361 IDirectDrawSurfaceImpl
*Ref
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3364 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3366 EnterCriticalSection(&ddraw_cs
);
3367 hr
= wined3d_surface_update_overlay_z_order(This
->wined3d_surface
,
3368 Flags
, Ref
? Ref
->wined3d_surface
: NULL
);
3369 LeaveCriticalSection(&ddraw_cs
);
3373 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3374 DWORD flags
, IDirectDrawSurface4
*reference
)
3376 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3377 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3378 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3380 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3381 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3384 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3385 DWORD flags
, IDirectDrawSurface3
*reference
)
3387 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3388 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3389 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3391 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3392 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3395 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3396 DWORD flags
, IDirectDrawSurface2
*reference
)
3398 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3399 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3400 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3402 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3403 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3406 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3407 DWORD flags
, IDirectDrawSurface
*reference
)
3409 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3410 IDirectDrawSurfaceImpl
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3411 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3413 return ddraw_surface7_UpdateOverlayZOrder(&This
->IDirectDrawSurface7_iface
, flags
,
3414 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3417 /*****************************************************************************
3418 * IDirectDrawSurface7::GetDDInterface
3420 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3421 * surface belongs to
3424 * DD: Address to write the interface pointer to
3428 * DDERR_INVALIDPARAMS if DD is NULL
3430 *****************************************************************************/
3431 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3433 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3435 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3438 return DDERR_INVALIDPARAMS
;
3440 switch(This
->version
)
3443 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3447 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3451 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3455 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3459 IUnknown_AddRef((IUnknown
*)*DD
);
3464 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3466 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3467 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3469 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3472 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3474 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3475 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3477 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3480 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3482 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3483 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3485 return ddraw_surface7_GetDDInterface(&This
->IDirectDrawSurface7_iface
, ddraw
);
3488 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3489 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3491 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3492 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
3494 TRACE("iface %p.\n", iface
);
3496 EnterCriticalSection(&ddraw_cs
);
3497 /* A uniqueness value of 0 is apparently special.
3498 * This needs to be checked.
3499 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3502 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
3503 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
3505 if (old_uniqueness_value
== 0) break;
3506 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
3508 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
3509 old_uniqueness_value
,
3510 new_uniqueness_value
)
3511 == old_uniqueness_value
)
3515 LeaveCriticalSection(&ddraw_cs
);
3519 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3521 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3522 TRACE("iface %p.\n", iface
);
3524 return ddraw_surface7_ChangeUniquenessValue(&This
->IDirectDrawSurface7_iface
);
3527 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3529 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3531 TRACE("iface %p, value %p.\n", iface
, pValue
);
3533 EnterCriticalSection(&ddraw_cs
);
3534 *pValue
= This
->uniqueness_value
;
3535 LeaveCriticalSection(&ddraw_cs
);
3539 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3541 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3542 TRACE("iface %p, value %p.\n", iface
, pValue
);
3544 return ddraw_surface7_GetUniquenessValue(&This
->IDirectDrawSurface7_iface
, pValue
);
3547 /*****************************************************************************
3548 * IDirectDrawSurface7::SetLOD
3550 * Sets the level of detail of a texture
3553 * MaxLOD: LOD to set
3557 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3559 *****************************************************************************/
3560 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
3562 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3565 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
3567 EnterCriticalSection(&ddraw_cs
);
3568 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3570 LeaveCriticalSection(&ddraw_cs
);
3571 return DDERR_INVALIDOBJECT
;
3574 if (!This
->wined3d_texture
)
3576 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
3577 LeaveCriticalSection(&ddraw_cs
);
3578 return DDERR_INVALIDOBJECT
;
3581 hr
= wined3d_texture_set_lod(This
->wined3d_texture
, MaxLOD
);
3582 LeaveCriticalSection(&ddraw_cs
);
3586 /*****************************************************************************
3587 * IDirectDrawSurface7::GetLOD
3589 * Returns the level of detail of a Direct3D texture
3592 * MaxLOD: Address to write the LOD to
3596 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3597 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3599 *****************************************************************************/
3600 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
3602 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3604 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
3607 return DDERR_INVALIDPARAMS
;
3609 EnterCriticalSection(&ddraw_cs
);
3610 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3612 LeaveCriticalSection(&ddraw_cs
);
3613 return DDERR_INVALIDOBJECT
;
3616 *MaxLOD
= wined3d_texture_get_lod(This
->wined3d_texture
);
3617 LeaveCriticalSection(&ddraw_cs
);
3621 /*****************************************************************************
3622 * IDirectDrawSurface7::BltFast
3624 * Performs a fast Blit.
3627 * dstx: The x coordinate to blit to on the destination
3628 * dsty: The y coordinate to blit to on the destination
3629 * Source: The source surface
3630 * rsrc: The source rectangle
3631 * trans: Type of transfer. Some DDBLTFAST_* flags
3635 * For more details, see IWineD3DSurface::BltFast
3637 *****************************************************************************/
3638 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
3639 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
3641 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3642 IDirectDrawSurfaceImpl
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
3643 DWORD src_w
, src_h
, dst_w
, dst_h
;
3646 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3647 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
3649 dst_w
= This
->surface_desc
.dwWidth
;
3650 dst_h
= This
->surface_desc
.dwHeight
;
3652 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3657 src_w
= rsrc
->right
- rsrc
->left
;
3658 src_h
= rsrc
->bottom
- rsrc
->top
;
3662 src_w
= src
->surface_desc
.dwWidth
;
3663 src_h
= src
->surface_desc
.dwHeight
;
3666 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
3667 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
3669 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3670 return DDERR_INVALIDRECT
;
3673 EnterCriticalSection(&ddraw_cs
);
3674 hr
= wined3d_surface_bltfast(This
->wined3d_surface
, dstx
, dsty
,
3675 src
->wined3d_surface
, rsrc
, trans
);
3676 LeaveCriticalSection(&ddraw_cs
);
3679 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
3680 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
3685 static HRESULT WINAPI
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
3686 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
3688 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3689 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
3690 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3691 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3693 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3694 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3697 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
3698 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
3700 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3701 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
3702 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3703 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3705 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3706 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3709 static HRESULT WINAPI
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
3710 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
3712 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3713 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
3714 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3715 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3717 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3718 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3721 static HRESULT WINAPI
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
3722 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
3724 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3725 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
3726 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3727 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
3729 return ddraw_surface7_BltFast(&This
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
3730 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
3733 /*****************************************************************************
3734 * IDirectDrawSurface7::GetClipper
3736 * Returns the IDirectDrawClipper interface of the clipper assigned to this
3740 * Clipper: Address to store the interface pointer at
3744 * DDERR_INVALIDPARAMS if Clipper is NULL
3745 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
3747 *****************************************************************************/
3748 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
3750 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3752 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
3756 LeaveCriticalSection(&ddraw_cs
);
3757 return DDERR_INVALIDPARAMS
;
3760 EnterCriticalSection(&ddraw_cs
);
3761 if(This
->clipper
== NULL
)
3763 LeaveCriticalSection(&ddraw_cs
);
3764 return DDERR_NOCLIPPERATTACHED
;
3767 *Clipper
= (IDirectDrawClipper
*)This
->clipper
;
3768 IDirectDrawClipper_AddRef(*Clipper
);
3769 LeaveCriticalSection(&ddraw_cs
);
3773 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
3775 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3776 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3778 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3781 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
3783 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3784 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3786 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3789 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
3791 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3792 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3794 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3797 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
3799 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3800 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3802 return ddraw_surface7_GetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3805 /*****************************************************************************
3806 * IDirectDrawSurface7::SetClipper
3808 * Sets a clipper for the surface
3811 * Clipper: IDirectDrawClipper interface of the clipper to set
3816 *****************************************************************************/
3817 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
3818 IDirectDrawClipper
*iclipper
)
3820 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3821 IDirectDrawClipperImpl
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
3822 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
3826 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
3828 EnterCriticalSection(&ddraw_cs
);
3829 if (clipper
== This
->clipper
)
3831 LeaveCriticalSection(&ddraw_cs
);
3835 This
->clipper
= clipper
;
3837 if (clipper
!= NULL
)
3838 IDirectDrawClipper_AddRef(iclipper
);
3840 IDirectDrawClipper_Release(&oldClipper
->IDirectDrawClipper_iface
);
3842 hr
= wined3d_surface_set_clipper(This
->wined3d_surface
,
3843 This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
3845 if (This
->wined3d_swapchain
)
3849 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
3853 wined3d_swapchain_set_window(This
->wined3d_swapchain
, clipWindow
);
3855 wined3d_swapchain_set_window(This
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
3858 LeaveCriticalSection(&ddraw_cs
);
3862 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
3864 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3865 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3867 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3870 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
3872 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
3873 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3875 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3878 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
3880 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
3881 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3883 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3886 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
3888 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
3889 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
3891 return ddraw_surface7_SetClipper(&This
->IDirectDrawSurface7_iface
, clipper
);
3894 /*****************************************************************************
3895 * IDirectDrawSurface7::SetSurfaceDesc
3897 * Sets the surface description. It can override the pixel format, the surface
3899 * It's not really tested.
3902 * DDSD: Pointer to the new surface description to set
3907 * DDERR_INVALIDPARAMS if DDSD is NULL
3909 *****************************************************************************/
3910 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
3912 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
3913 enum wined3d_format_id newFormat
= WINED3DFMT_UNKNOWN
;
3916 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
3920 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
3921 return DDERR_INVALIDPARAMS
;
3925 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
3926 return DDERR_INVALIDPARAMS
;
3929 EnterCriticalSection(&ddraw_cs
);
3930 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
3932 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
3934 if(newFormat
== WINED3DFMT_UNKNOWN
)
3936 ERR("Requested to set an unknown pixelformat\n");
3937 LeaveCriticalSection(&ddraw_cs
);
3938 return DDERR_INVALIDPARAMS
;
3940 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
3942 hr
= wined3d_surface_set_format(This
->wined3d_surface
, newFormat
);
3945 LeaveCriticalSection(&ddraw_cs
);
3950 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
3952 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
3953 (WINEDDCOLORKEY
*)&DDSD
->u3
.ddckCKDestOverlay
);
3955 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
3957 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_DESTBLT
,
3958 (WINEDDCOLORKEY
*)&DDSD
->ddckCKDestBlt
);
3960 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
3962 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
3963 (WINEDDCOLORKEY
*)&DDSD
->ddckCKSrcOverlay
);
3965 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
3967 wined3d_surface_set_color_key(This
->wined3d_surface
, DDCKEY_SRCBLT
,
3968 (WINEDDCOLORKEY
*)&DDSD
->ddckCKSrcBlt
);
3970 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
3972 hr
= wined3d_surface_set_mem(This
->wined3d_surface
, DDSD
->lpSurface
);
3975 /* No need for a trace here, wined3d does that for us */
3978 case WINED3DERR_INVALIDCALL
:
3979 LeaveCriticalSection(&ddraw_cs
);
3980 return DDERR_INVALIDPARAMS
;
3987 This
->surface_desc
= *DDSD
;
3989 LeaveCriticalSection(&ddraw_cs
);
3993 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
3994 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
3996 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
3997 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
3999 return ddraw_surface7_SetSurfaceDesc(&This
->IDirectDrawSurface7_iface
,
4000 surface_desc
, flags
);
4003 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4004 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4006 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4007 DDSURFACEDESC2 surface_desc2
;
4008 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4010 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4011 return ddraw_surface7_SetSurfaceDesc(&This
->IDirectDrawSurface7_iface
,
4012 surface_desc
? &surface_desc2
: NULL
, flags
);
4015 /*****************************************************************************
4016 * IDirectDrawSurface7::GetPalette
4018 * Returns the IDirectDrawPalette interface of the palette currently assigned
4022 * Pal: Address to write the interface pointer to
4026 * DDERR_INVALIDPARAMS if Pal is NULL
4028 *****************************************************************************/
4029 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
4031 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4032 struct wined3d_palette
*wined3d_palette
;
4035 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4038 return DDERR_INVALIDPARAMS
;
4040 EnterCriticalSection(&ddraw_cs
);
4041 wined3d_palette
= wined3d_surface_get_palette(This
->wined3d_surface
);
4042 if (wined3d_palette
)
4044 *Pal
= wined3d_palette_get_parent(wined3d_palette
);
4045 IDirectDrawPalette_AddRef(*Pal
);
4050 hr
= DDERR_NOPALETTEATTACHED
;
4053 LeaveCriticalSection(&ddraw_cs
);
4057 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4059 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4060 TRACE("iface %p, palette %p.\n", iface
, palette
);
4062 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4065 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4067 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4068 TRACE("iface %p, palette %p.\n", iface
, palette
);
4070 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4073 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4075 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4076 TRACE("iface %p, palette %p.\n", iface
, palette
);
4078 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4081 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4083 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4084 TRACE("iface %p, palette %p.\n", iface
, palette
);
4086 return ddraw_surface7_GetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4089 /*****************************************************************************
4092 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4093 * recursively in the surface tree
4095 *****************************************************************************/
4099 WINEDDCOLORKEY
*CKey
;
4103 static HRESULT WINAPI
4104 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
4105 DDSURFACEDESC2
*desc
,
4108 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(surface
);
4109 struct SCKContext
*ctx
= context
;
4112 hr
= wined3d_surface_set_color_key(This
->wined3d_surface
, ctx
->Flags
, ctx
->CKey
);
4115 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
4119 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
4120 ddraw_surface7_Release(surface
);
4122 return DDENUMRET_OK
;
4125 /*****************************************************************************
4126 * IDirectDrawSurface7::SetColorKey
4128 * Sets the color keying options for the surface. Observations showed that
4129 * in case of complex surfaces the color key has to be assigned to all
4134 * CKey: The new color key
4138 * See IWineD3DSurface::SetColorKey for details
4140 *****************************************************************************/
4141 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
4143 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4144 DDCOLORKEY FixedCKey
;
4145 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) (CKey
? &FixedCKey
: NULL
), Flags
};
4147 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
4149 EnterCriticalSection(&ddraw_cs
);
4153 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4154 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
4155 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
4157 switch (Flags
& ~DDCKEY_COLORSPACE
)
4159 case DDCKEY_DESTBLT
:
4160 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
4161 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4164 case DDCKEY_DESTOVERLAY
:
4165 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
4166 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4169 case DDCKEY_SRCOVERLAY
:
4170 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
4171 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4175 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
4176 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4180 LeaveCriticalSection(&ddraw_cs
);
4181 return DDERR_INVALIDPARAMS
;
4186 switch (Flags
& ~DDCKEY_COLORSPACE
)
4188 case DDCKEY_DESTBLT
:
4189 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4192 case DDCKEY_DESTOVERLAY
:
4193 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4196 case DDCKEY_SRCOVERLAY
:
4197 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4201 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4205 LeaveCriticalSection(&ddraw_cs
);
4206 return DDERR_INVALIDPARAMS
;
4209 ctx
.ret
= wined3d_surface_set_color_key(This
->wined3d_surface
, Flags
, ctx
.CKey
);
4210 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
4211 LeaveCriticalSection(&ddraw_cs
);
4214 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
4215 default: return ctx
.ret
;
4219 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4221 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4222 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4224 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4227 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4229 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4230 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4232 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4235 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4237 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4238 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4240 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4243 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4245 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4246 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4248 return ddraw_surface7_SetColorKey(&This
->IDirectDrawSurface7_iface
, flags
, color_key
);
4251 /*****************************************************************************
4252 * IDirectDrawSurface7::SetPalette
4254 * Assigns a DirectDrawPalette object to the surface
4257 * Pal: Interface to the palette to set
4262 *****************************************************************************/
4263 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
4265 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface7(iface
);
4266 IDirectDrawPalette
*oldPal
;
4267 IDirectDrawSurfaceImpl
*surf
;
4268 IDirectDrawPaletteImpl
*PalImpl
= (IDirectDrawPaletteImpl
*)Pal
;
4271 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4273 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
4274 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
4275 return DDERR_INVALIDPIXELFORMAT
;
4278 if (This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4280 return DDERR_NOTONMIPMAPSUBLEVEL
;
4283 /* Find the old palette */
4284 EnterCriticalSection(&ddraw_cs
);
4285 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
4286 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
4288 LeaveCriticalSection(&ddraw_cs
);
4291 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
4293 /* Set the new Palette */
4294 wined3d_surface_set_palette(This
->wined3d_surface
, PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
4295 /* AddRef the Palette */
4296 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
4298 /* Release the old palette */
4299 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
4301 /* If this is a front buffer, also update the back buffers
4302 * TODO: How do things work for palettized cube textures?
4304 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4306 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4307 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
4312 IDirectDrawSurface7
*attach
;
4314 hr
= ddraw_surface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &caps2
, &attach
);
4320 TRACE("Setting palette on %p\n", attach
);
4321 ddraw_surface7_SetPalette(attach
, Pal
);
4322 surf
= impl_from_IDirectDrawSurface7(attach
);
4323 ddraw_surface7_Release(attach
);
4327 LeaveCriticalSection(&ddraw_cs
);
4331 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4333 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface4(iface
);
4334 TRACE("iface %p, palette %p.\n", iface
, palette
);
4336 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4339 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4341 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface3(iface
);
4342 TRACE("iface %p, palette %p.\n", iface
, palette
);
4344 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4347 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4349 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface2(iface
);
4350 TRACE("iface %p, palette %p.\n", iface
, palette
);
4352 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4355 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4357 IDirectDrawSurfaceImpl
*This
= impl_from_IDirectDrawSurface(iface
);
4358 TRACE("iface %p, palette %p.\n", iface
, palette
);
4360 return ddraw_surface7_SetPalette(&This
->IDirectDrawSurface7_iface
, palette
);
4363 /**********************************************************
4364 * IDirectDrawGammaControl::GetGammaRamp
4366 * Returns the current gamma ramp for a surface
4370 * gamma_ramp: Address to write the ramp to
4374 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4376 **********************************************************/
4377 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4378 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4380 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4382 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4386 WARN("Invalid gamma_ramp passed.\n");
4387 return DDERR_INVALIDPARAMS
;
4390 EnterCriticalSection(&ddraw_cs
);
4391 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4393 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */
4394 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (WINED3DGAMMARAMP
*)gamma_ramp
);
4398 ERR("Not implemented for non-primary surfaces.\n");
4400 LeaveCriticalSection(&ddraw_cs
);
4405 /**********************************************************
4406 * IDirectDrawGammaControl::SetGammaRamp
4408 * Sets the red, green and blue gamma ramps for
4411 * flags: Can be DDSGR_CALIBRATE to request calibration
4412 * gamma_ramp: Structure containing the new gamma ramp
4416 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4418 **********************************************************/
4419 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4420 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4422 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4424 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4428 WARN("Invalid gamma_ramp passed.\n");
4429 return DDERR_INVALIDPARAMS
;
4432 EnterCriticalSection(&ddraw_cs
);
4433 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4435 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
4436 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, flags
, (WINED3DGAMMARAMP
*)gamma_ramp
);
4440 ERR("Not implemented for non-primary surfaces.\n");
4442 LeaveCriticalSection(&ddraw_cs
);
4447 /*****************************************************************************
4448 * IDirect3DTexture2::PaletteChanged
4450 * Informs the texture about a palette change
4453 * start: Start index of the change
4454 * count: The number of changed entries
4457 * D3D_OK, because it's a stub
4459 *****************************************************************************/
4460 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4462 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4467 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4469 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirect3DTexture(iface
);
4471 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4473 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4476 /*****************************************************************************
4477 * IDirect3DTexture::Unload
4479 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4485 *****************************************************************************/
4486 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4488 WARN("iface %p. Not implemented.\n", iface
);
4490 return DDERR_UNSUPPORTED
;
4493 /*****************************************************************************
4494 * IDirect3DTexture2::GetHandle
4496 * Returns handle for the texture. At the moment, the interface
4497 * to the IWineD3DTexture is used.
4500 * device: Device this handle is assigned to
4501 * handle: Address to store the handle at.
4506 *****************************************************************************/
4507 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4508 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4510 IDirectDrawSurfaceImpl
*surface
= impl_from_IDirect3DTexture2(iface
);
4512 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4514 EnterCriticalSection(&ddraw_cs
);
4516 if (!surface
->Handle
)
4518 DWORD h
= ddraw_allocate_handle(&device_from_device2(device
)->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
4519 if (h
== DDRAW_INVALID_HANDLE
)
4521 ERR("Failed to allocate a texture handle.\n");
4522 LeaveCriticalSection(&ddraw_cs
);
4523 return DDERR_OUTOFMEMORY
;
4526 surface
->Handle
= h
+ 1;
4529 TRACE("Returning handle %08x.\n", surface
->Handle
);
4530 *handle
= surface
->Handle
;
4532 LeaveCriticalSection(&ddraw_cs
);
4537 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
4538 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
4540 IDirectDrawSurfaceImpl
*This
= impl_from_IDirect3DTexture(iface
);
4541 IDirect3DDevice2
*device2
= (IDirect3DDevice2
*)&device_from_device1(device
)->IDirect3DDevice2_vtbl
;
4543 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4545 return d3d_texture2_GetHandle(&This
->IDirect3DTexture2_iface
, device2
, handle
);
4548 /*****************************************************************************
4549 * get_sub_mimaplevel
4551 * Helper function that returns the next mipmap level
4553 * tex_ptr: Surface of which to return the next level
4555 *****************************************************************************/
4556 static IDirectDrawSurfaceImpl
*get_sub_mimaplevel(IDirectDrawSurfaceImpl
*surface
)
4558 /* Now go down the mipmap chain to the next surface */
4559 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
4560 IDirectDrawSurface7
*next_level
;
4563 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
4564 if (FAILED(hr
)) return NULL
;
4566 ddraw_surface7_Release(next_level
);
4568 return impl_from_IDirectDrawSurface7(next_level
);
4571 /*****************************************************************************
4572 * IDirect3DTexture2::Load
4574 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
4576 * This function isn't relayed to WineD3D because the whole interface is
4577 * implemented in DDraw only. For speed improvements a implementation which
4578 * takes OpenGL more into account could be placed into WineD3D.
4581 * src_texture: Address of the texture to load
4585 * D3DERR_TEXTURE_LOAD_FAILED.
4587 *****************************************************************************/
4588 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
4590 IDirectDrawSurfaceImpl
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
4591 IDirectDrawSurfaceImpl
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
4594 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
4596 if (src_surface
== dst_surface
)
4598 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
4602 EnterCriticalSection(&ddraw_cs
);
4604 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4605 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
4606 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
4608 ERR("Trying to load surfaces with different mip-map counts.\n");
4613 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
4614 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
4615 DDSURFACEDESC
*src_desc
, *dst_desc
;
4617 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
4618 src_surface
, dst_surface
, src_surface
->mipmap_level
);
4620 /* Suppress the ALLOCONLOAD flag */
4621 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
4623 /* Get the palettes */
4624 wined3d_dst_pal
= wined3d_surface_get_palette(dst_surface
->wined3d_surface
);
4625 if (wined3d_dst_pal
)
4626 dst_pal
= wined3d_palette_get_parent(wined3d_dst_pal
);
4628 wined3d_src_pal
= wined3d_surface_get_palette(src_surface
->wined3d_surface
);
4629 if (wined3d_src_pal
)
4630 src_pal
= wined3d_palette_get_parent(wined3d_src_pal
);
4634 PALETTEENTRY palent
[256];
4638 LeaveCriticalSection(&ddraw_cs
);
4639 return DDERR_NOPALETTEATTACHED
;
4641 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
4642 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
4645 /* Copy one surface on the other */
4646 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
4647 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
4649 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
4651 /* Should also check for same pixel format, u1.lPitch, ... */
4652 ERR("Error in surface sizes.\n");
4653 LeaveCriticalSection(&ddraw_cs
);
4654 return D3DERR_TEXTURE_LOAD_FAILED
;
4658 WINED3DLOCKED_RECT src_rect
, dst_rect
;
4660 /* Copy also the ColorKeying stuff */
4661 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
4663 dst_desc
->dwFlags
|= DDSD_CKSRCBLT
;
4664 dst_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
;
4665 dst_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
;
4668 /* Copy the main memory texture into the surface that corresponds
4669 * to the OpenGL texture object. */
4671 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_rect
, NULL
, 0);
4674 ERR("Failed to lock source surface, hr %#x.\n", hr
);
4675 LeaveCriticalSection(&ddraw_cs
);
4676 return D3DERR_TEXTURE_LOAD_FAILED
;
4679 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_rect
, NULL
, 0);
4682 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
4683 wined3d_surface_unmap(src_surface
->wined3d_surface
);
4684 LeaveCriticalSection(&ddraw_cs
);
4685 return D3DERR_TEXTURE_LOAD_FAILED
;
4688 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
4689 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_surface
->surface_desc
.u1
.dwLinearSize
);
4691 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_rect
.Pitch
* src_desc
->dwHeight
);
4693 wined3d_surface_unmap(src_surface
->wined3d_surface
);
4694 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
4697 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4698 src_surface
= get_sub_mimaplevel(src_surface
);
4702 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
4703 dst_surface
= get_sub_mimaplevel(dst_surface
);
4707 if (!src_surface
|| !dst_surface
)
4709 if (src_surface
!= dst_surface
)
4710 ERR("Loading surface with different mipmap structure.\n");
4715 LeaveCriticalSection(&ddraw_cs
);
4720 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
4722 IDirectDrawSurfaceImpl
* This
= impl_from_IDirect3DTexture(iface
);
4723 IDirectDrawSurfaceImpl
* src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
4724 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
4726 return d3d_texture2_Load(&This
->IDirect3DTexture2_iface
,
4727 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
4730 /*****************************************************************************
4732 *****************************************************************************/
4734 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
4737 ddraw_surface7_QueryInterface
,
4738 ddraw_surface7_AddRef
,
4739 ddraw_surface7_Release
,
4740 /* IDirectDrawSurface */
4741 ddraw_surface7_AddAttachedSurface
,
4742 ddraw_surface7_AddOverlayDirtyRect
,
4744 ddraw_surface7_BltBatch
,
4745 ddraw_surface7_BltFast
,
4746 ddraw_surface7_DeleteAttachedSurface
,
4747 ddraw_surface7_EnumAttachedSurfaces
,
4748 ddraw_surface7_EnumOverlayZOrders
,
4749 ddraw_surface7_Flip
,
4750 ddraw_surface7_GetAttachedSurface
,
4751 ddraw_surface7_GetBltStatus
,
4752 ddraw_surface7_GetCaps
,
4753 ddraw_surface7_GetClipper
,
4754 ddraw_surface7_GetColorKey
,
4755 ddraw_surface7_GetDC
,
4756 ddraw_surface7_GetFlipStatus
,
4757 ddraw_surface7_GetOverlayPosition
,
4758 ddraw_surface7_GetPalette
,
4759 ddraw_surface7_GetPixelFormat
,
4760 ddraw_surface7_GetSurfaceDesc
,
4761 ddraw_surface7_Initialize
,
4762 ddraw_surface7_IsLost
,
4763 ddraw_surface7_Lock
,
4764 ddraw_surface7_ReleaseDC
,
4765 ddraw_surface7_Restore
,
4766 ddraw_surface7_SetClipper
,
4767 ddraw_surface7_SetColorKey
,
4768 ddraw_surface7_SetOverlayPosition
,
4769 ddraw_surface7_SetPalette
,
4770 ddraw_surface7_Unlock
,
4771 ddraw_surface7_UpdateOverlay
,
4772 ddraw_surface7_UpdateOverlayDisplay
,
4773 ddraw_surface7_UpdateOverlayZOrder
,
4774 /* IDirectDrawSurface2 */
4775 ddraw_surface7_GetDDInterface
,
4776 ddraw_surface7_PageLock
,
4777 ddraw_surface7_PageUnlock
,
4778 /* IDirectDrawSurface3 */
4779 ddraw_surface7_SetSurfaceDesc
,
4780 /* IDirectDrawSurface4 */
4781 ddraw_surface7_SetPrivateData
,
4782 ddraw_surface7_GetPrivateData
,
4783 ddraw_surface7_FreePrivateData
,
4784 ddraw_surface7_GetUniquenessValue
,
4785 ddraw_surface7_ChangeUniquenessValue
,
4786 /* IDirectDrawSurface7 */
4787 ddraw_surface7_SetPriority
,
4788 ddraw_surface7_GetPriority
,
4789 ddraw_surface7_SetLOD
,
4790 ddraw_surface7_GetLOD
,
4793 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
4796 ddraw_surface4_QueryInterface
,
4797 ddraw_surface4_AddRef
,
4798 ddraw_surface4_Release
,
4799 /* IDirectDrawSurface */
4800 ddraw_surface4_AddAttachedSurface
,
4801 ddraw_surface4_AddOverlayDirtyRect
,
4803 ddraw_surface4_BltBatch
,
4804 ddraw_surface4_BltFast
,
4805 ddraw_surface4_DeleteAttachedSurface
,
4806 ddraw_surface4_EnumAttachedSurfaces
,
4807 ddraw_surface4_EnumOverlayZOrders
,
4808 ddraw_surface4_Flip
,
4809 ddraw_surface4_GetAttachedSurface
,
4810 ddraw_surface4_GetBltStatus
,
4811 ddraw_surface4_GetCaps
,
4812 ddraw_surface4_GetClipper
,
4813 ddraw_surface4_GetColorKey
,
4814 ddraw_surface4_GetDC
,
4815 ddraw_surface4_GetFlipStatus
,
4816 ddraw_surface4_GetOverlayPosition
,
4817 ddraw_surface4_GetPalette
,
4818 ddraw_surface4_GetPixelFormat
,
4819 ddraw_surface4_GetSurfaceDesc
,
4820 ddraw_surface4_Initialize
,
4821 ddraw_surface4_IsLost
,
4822 ddraw_surface4_Lock
,
4823 ddraw_surface4_ReleaseDC
,
4824 ddraw_surface4_Restore
,
4825 ddraw_surface4_SetClipper
,
4826 ddraw_surface4_SetColorKey
,
4827 ddraw_surface4_SetOverlayPosition
,
4828 ddraw_surface4_SetPalette
,
4829 ddraw_surface4_Unlock
,
4830 ddraw_surface4_UpdateOverlay
,
4831 ddraw_surface4_UpdateOverlayDisplay
,
4832 ddraw_surface4_UpdateOverlayZOrder
,
4833 /* IDirectDrawSurface2 */
4834 ddraw_surface4_GetDDInterface
,
4835 ddraw_surface4_PageLock
,
4836 ddraw_surface4_PageUnlock
,
4837 /* IDirectDrawSurface3 */
4838 ddraw_surface4_SetSurfaceDesc
,
4839 /* IDirectDrawSurface4 */
4840 ddraw_surface4_SetPrivateData
,
4841 ddraw_surface4_GetPrivateData
,
4842 ddraw_surface4_FreePrivateData
,
4843 ddraw_surface4_GetUniquenessValue
,
4844 ddraw_surface4_ChangeUniquenessValue
,
4847 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
4850 ddraw_surface3_QueryInterface
,
4851 ddraw_surface3_AddRef
,
4852 ddraw_surface3_Release
,
4853 /* IDirectDrawSurface */
4854 ddraw_surface3_AddAttachedSurface
,
4855 ddraw_surface3_AddOverlayDirtyRect
,
4857 ddraw_surface3_BltBatch
,
4858 ddraw_surface3_BltFast
,
4859 ddraw_surface3_DeleteAttachedSurface
,
4860 ddraw_surface3_EnumAttachedSurfaces
,
4861 ddraw_surface3_EnumOverlayZOrders
,
4862 ddraw_surface3_Flip
,
4863 ddraw_surface3_GetAttachedSurface
,
4864 ddraw_surface3_GetBltStatus
,
4865 ddraw_surface3_GetCaps
,
4866 ddraw_surface3_GetClipper
,
4867 ddraw_surface3_GetColorKey
,
4868 ddraw_surface3_GetDC
,
4869 ddraw_surface3_GetFlipStatus
,
4870 ddraw_surface3_GetOverlayPosition
,
4871 ddraw_surface3_GetPalette
,
4872 ddraw_surface3_GetPixelFormat
,
4873 ddraw_surface3_GetSurfaceDesc
,
4874 ddraw_surface3_Initialize
,
4875 ddraw_surface3_IsLost
,
4876 ddraw_surface3_Lock
,
4877 ddraw_surface3_ReleaseDC
,
4878 ddraw_surface3_Restore
,
4879 ddraw_surface3_SetClipper
,
4880 ddraw_surface3_SetColorKey
,
4881 ddraw_surface3_SetOverlayPosition
,
4882 ddraw_surface3_SetPalette
,
4883 ddraw_surface3_Unlock
,
4884 ddraw_surface3_UpdateOverlay
,
4885 ddraw_surface3_UpdateOverlayDisplay
,
4886 ddraw_surface3_UpdateOverlayZOrder
,
4887 /* IDirectDrawSurface2 */
4888 ddraw_surface3_GetDDInterface
,
4889 ddraw_surface3_PageLock
,
4890 ddraw_surface3_PageUnlock
,
4891 /* IDirectDrawSurface3 */
4892 ddraw_surface3_SetSurfaceDesc
,
4895 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
4898 ddraw_surface2_QueryInterface
,
4899 ddraw_surface2_AddRef
,
4900 ddraw_surface2_Release
,
4901 /* IDirectDrawSurface */
4902 ddraw_surface2_AddAttachedSurface
,
4903 ddraw_surface2_AddOverlayDirtyRect
,
4905 ddraw_surface2_BltBatch
,
4906 ddraw_surface2_BltFast
,
4907 ddraw_surface2_DeleteAttachedSurface
,
4908 ddraw_surface2_EnumAttachedSurfaces
,
4909 ddraw_surface2_EnumOverlayZOrders
,
4910 ddraw_surface2_Flip
,
4911 ddraw_surface2_GetAttachedSurface
,
4912 ddraw_surface2_GetBltStatus
,
4913 ddraw_surface2_GetCaps
,
4914 ddraw_surface2_GetClipper
,
4915 ddraw_surface2_GetColorKey
,
4916 ddraw_surface2_GetDC
,
4917 ddraw_surface2_GetFlipStatus
,
4918 ddraw_surface2_GetOverlayPosition
,
4919 ddraw_surface2_GetPalette
,
4920 ddraw_surface2_GetPixelFormat
,
4921 ddraw_surface2_GetSurfaceDesc
,
4922 ddraw_surface2_Initialize
,
4923 ddraw_surface2_IsLost
,
4924 ddraw_surface2_Lock
,
4925 ddraw_surface2_ReleaseDC
,
4926 ddraw_surface2_Restore
,
4927 ddraw_surface2_SetClipper
,
4928 ddraw_surface2_SetColorKey
,
4929 ddraw_surface2_SetOverlayPosition
,
4930 ddraw_surface2_SetPalette
,
4931 ddraw_surface2_Unlock
,
4932 ddraw_surface2_UpdateOverlay
,
4933 ddraw_surface2_UpdateOverlayDisplay
,
4934 ddraw_surface2_UpdateOverlayZOrder
,
4935 /* IDirectDrawSurface2 */
4936 ddraw_surface2_GetDDInterface
,
4937 ddraw_surface2_PageLock
,
4938 ddraw_surface2_PageUnlock
,
4941 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
4944 ddraw_surface1_QueryInterface
,
4945 ddraw_surface1_AddRef
,
4946 ddraw_surface1_Release
,
4947 /* IDirectDrawSurface */
4948 ddraw_surface1_AddAttachedSurface
,
4949 ddraw_surface1_AddOverlayDirtyRect
,
4951 ddraw_surface1_BltBatch
,
4952 ddraw_surface1_BltFast
,
4953 ddraw_surface1_DeleteAttachedSurface
,
4954 ddraw_surface1_EnumAttachedSurfaces
,
4955 ddraw_surface1_EnumOverlayZOrders
,
4956 ddraw_surface1_Flip
,
4957 ddraw_surface1_GetAttachedSurface
,
4958 ddraw_surface1_GetBltStatus
,
4959 ddraw_surface1_GetCaps
,
4960 ddraw_surface1_GetClipper
,
4961 ddraw_surface1_GetColorKey
,
4962 ddraw_surface1_GetDC
,
4963 ddraw_surface1_GetFlipStatus
,
4964 ddraw_surface1_GetOverlayPosition
,
4965 ddraw_surface1_GetPalette
,
4966 ddraw_surface1_GetPixelFormat
,
4967 ddraw_surface1_GetSurfaceDesc
,
4968 ddraw_surface1_Initialize
,
4969 ddraw_surface1_IsLost
,
4970 ddraw_surface1_Lock
,
4971 ddraw_surface1_ReleaseDC
,
4972 ddraw_surface1_Restore
,
4973 ddraw_surface1_SetClipper
,
4974 ddraw_surface1_SetColorKey
,
4975 ddraw_surface1_SetOverlayPosition
,
4976 ddraw_surface1_SetPalette
,
4977 ddraw_surface1_Unlock
,
4978 ddraw_surface1_UpdateOverlay
,
4979 ddraw_surface1_UpdateOverlayDisplay
,
4980 ddraw_surface1_UpdateOverlayZOrder
,
4983 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
4985 ddraw_gamma_control_QueryInterface
,
4986 ddraw_gamma_control_AddRef
,
4987 ddraw_gamma_control_Release
,
4988 ddraw_gamma_control_GetGammaRamp
,
4989 ddraw_gamma_control_SetGammaRamp
,
4992 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
4994 d3d_texture2_QueryInterface
,
4995 d3d_texture2_AddRef
,
4996 d3d_texture2_Release
,
4997 d3d_texture2_GetHandle
,
4998 d3d_texture2_PaletteChanged
,
5002 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5004 d3d_texture1_QueryInterface
,
5005 d3d_texture1_AddRef
,
5006 d3d_texture1_Release
,
5007 d3d_texture1_Initialize
,
5008 d3d_texture1_GetHandle
,
5009 d3d_texture1_PaletteChanged
,
5011 d3d_texture1_Unload
,
5014 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5016 if (!iface
) return NULL
;
5017 assert(iface
->lpVtbl
== &ddraw_surface7_vtbl
);
5018 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface7_iface
);
5021 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5023 if (!iface
) return NULL
;
5024 assert(iface
->lpVtbl
== &ddraw_surface4_vtbl
);
5025 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface4_iface
);
5028 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5030 if (!iface
) return NULL
;
5031 assert(iface
->lpVtbl
== &ddraw_surface3_vtbl
);
5032 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface3_iface
);
5035 static IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5037 if (!iface
) return NULL
;
5038 assert(iface
->lpVtbl
== &ddraw_surface2_vtbl
);
5039 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface2_iface
);
5042 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5044 if (!iface
) return NULL
;
5045 assert(iface
->lpVtbl
== &ddraw_surface1_vtbl
);
5046 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirectDrawSurface_iface
);
5049 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5051 if (!iface
) return NULL
;
5052 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5053 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirect3DTexture2_iface
);
5056 IDirectDrawSurfaceImpl
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5058 if (!iface
) return NULL
;
5059 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5060 return CONTAINING_RECORD(iface
, IDirectDrawSurfaceImpl
, IDirect3DTexture_iface
);
5063 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5065 IDirectDrawSurfaceImpl
*surface
= parent
;
5067 TRACE("surface %p.\n", surface
);
5069 /* Check for attached surfaces and detach them. */
5070 if (surface
->first_attached
!= surface
)
5072 IDirectDrawSurface7
*root
= &surface
->first_attached
->IDirectDrawSurface7_iface
;
5073 IDirectDrawSurface7
*detach
= &surface
->IDirectDrawSurface7_iface
;
5075 /* Well, this shouldn't happen: The surface being attached is
5076 * referenced in AddAttachedSurface(), so it shouldn't be released
5077 * until DeleteAttachedSurface() is called, because the refcount is
5078 * held. It looks like the application released it often enough to
5080 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5082 /* The refcount will drop to -1 here */
5083 if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
)))
5084 ERR("DeleteAttachedSurface failed.\n");
5087 while (surface
->next_attached
)
5089 IDirectDrawSurface7
*root
= &surface
->IDirectDrawSurface7_iface
;
5090 IDirectDrawSurface7
*detach
= &surface
->next_attached
->IDirectDrawSurface7_iface
;
5092 if (FAILED(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
)))
5093 ERR("DeleteAttachedSurface failed.\n");
5096 /* Having a texture handle set implies that the device still exists. */
5097 if (surface
->Handle
)
5098 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5100 /* Reduce the ddraw surface count. */
5101 InterlockedDecrement(&surface
->ddraw
->surfaces
);
5102 list_remove(&surface
->surface_list_entry
);
5104 HeapFree(GetProcessHeap(), 0, surface
);
5107 const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5109 ddraw_surface_wined3d_object_destroyed
,
5112 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5114 IDirectDrawSurfaceImpl
*surface
= parent
;
5116 TRACE("surface %p.\n", surface
);
5118 ddraw_surface_cleanup(surface
);
5121 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5123 ddraw_texture_wined3d_object_destroyed
,
5126 HRESULT
ddraw_surface_create_texture(IDirectDrawSurfaceImpl
*surface
)
5128 const DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
5129 enum wined3d_format_id format
;
5133 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5134 levels
= desc
->u2
.dwMipMapCount
;
5138 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM.
5139 * Should I forward the MANAGED cap to the managed pool? */
5140 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5141 pool
= WINED3DPOOL_SYSTEMMEM
;
5143 pool
= WINED3DPOOL_DEFAULT
;
5145 format
= PixelFormat_DD2WineD3D(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
5146 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5147 return wined3d_texture_create_cube(surface
->ddraw
->wined3d_device
, desc
->dwWidth
,
5148 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5150 return wined3d_texture_create_2d(surface
->ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
,
5151 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5154 HRESULT
ddraw_surface_init(IDirectDrawSurfaceImpl
*surface
, IDirectDrawImpl
*ddraw
,
5155 DDSURFACEDESC2
*desc
, UINT mip_level
, UINT version
)
5157 WINED3DPOOL pool
= WINED3DPOOL_DEFAULT
;
5158 enum wined3d_format_id format
;
5162 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5163 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5164 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)))
5166 /* Tests show surfaces without memory flags get these flags added
5167 * right after creation. */
5168 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5171 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5173 usage
|= WINED3DUSAGE_RENDERTARGET
;
5174 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5177 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5179 usage
|= WINED3DUSAGE_RENDERTARGET
;
5182 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
5184 usage
|= WINED3DUSAGE_OVERLAY
;
5187 if (ddraw
->depthstencil
|| (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5189 /* The depth stencil creation callback sets this flag. Set the
5190 * wined3d usage to let it know it's a depth/stencil surface. */
5191 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5194 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5196 pool
= WINED3DPOOL_SYSTEMMEM
;
5198 else if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
5200 pool
= WINED3DPOOL_MANAGED
;
5201 /* Managed textures have the system memory flag set. */
5202 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5204 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5206 /* Videomemory adds localvidmem. This is mutually exclusive with
5207 * systemmemory and texturemanage. */
5208 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5211 format
= PixelFormat_DD2WineD3D(&desc
->u4
.ddpfPixelFormat
);
5212 if (format
== WINED3DFMT_UNKNOWN
)
5214 WARN("Unsupported / unknown pixelformat.\n");
5215 return DDERR_INVALIDPIXELFORMAT
;
5218 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
5219 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
5220 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
5221 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
5222 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
5223 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
5224 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
5225 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
5226 surface
->iface_count
= 1;
5227 surface
->version
= version
;
5228 surface
->ddraw
= ddraw
;
5234 else if (version
== 4)
5243 copy_to_surfacedesc2(&surface
->surface_desc
, desc
);
5245 surface
->first_attached
= surface
;
5247 hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
, format
,
5248 TRUE
/* Lockable */, FALSE
/* Discard */, mip_level
, usage
, pool
,
5249 WINED3DMULTISAMPLE_NONE
, 0 /* MultiSampleQuality */, DefaultSurfaceType
, surface
,
5250 &ddraw_surface_wined3d_parent_ops
, &surface
->wined3d_surface
);
5253 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
5257 /* Anno 1602 stores the pitch right after surface creation, so make sure
5258 * it's there. TODO: Test other fourcc formats. */
5259 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
5260 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
5262 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
5263 if (format
== WINED3DFMT_DXT1
)
5265 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
) / 2;
5269 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
);
5274 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
5275 surface
->surface_desc
.u1
.lPitch
= wined3d_surface_get_pitch(surface
->wined3d_surface
);
5278 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
5280 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
5281 (WINEDDCOLORKEY
*)&desc
->u3
.ddckCKDestOverlay
);
5283 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
5285 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTBLT
,
5286 (WINEDDCOLORKEY
*)&desc
->ddckCKDestBlt
);
5288 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
5290 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
5291 (WINEDDCOLORKEY
*)&desc
->ddckCKSrcOverlay
);
5293 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
5295 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCBLT
,
5296 (WINEDDCOLORKEY
*)&desc
->ddckCKSrcBlt
);
5298 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5300 hr
= wined3d_surface_set_mem(surface
->wined3d_surface
, desc
->lpSurface
);
5303 ERR("Failed to set surface memory, hr %#x.\n", hr
);
5304 wined3d_surface_decref(surface
->wined3d_surface
);