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 library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
32 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
34 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
36 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
39 /* This is slow, of course. Also, in case of locks, we can't prevent other
40 * applications from drawing to the screen while we've locked the frontbuffer.
41 * We'd like to do this in wined3d instead, but for that to work wined3d needs
42 * to support windowless rendering first. */
43 static HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
, const RECT
*rect
, BOOL read
)
45 HDC surface_dc
, screen_dc
;
54 w
= surface
->surface_desc
.dwWidth
;
55 h
= surface
->surface_desc
.dwHeight
;
61 w
= rect
->right
- rect
->left
;
62 h
= rect
->bottom
- rect
->top
;
68 if (surface
->ddraw
->swapchain_window
)
70 /* Nothing to do, we control the frontbuffer, or at least the parts we
75 return wined3d_surface_blt(surface
->ddraw
->wined3d_frontbuffer
, rect
,
76 surface
->wined3d_surface
, rect
, 0, NULL
, WINED3D_TEXF_POINT
);
79 if (FAILED(hr
= wined3d_surface_getdc(surface
->wined3d_surface
, &surface_dc
)))
81 ERR("Failed to get surface DC, hr %#x.\n", hr
);
85 if (!(screen_dc
= GetDC(NULL
)))
87 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
88 ERR("Failed to get screen DC.\n");
93 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
94 screen_dc
, x
, y
, SRCCOPY
);
96 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
97 surface_dc
, x
, y
, SRCCOPY
);
99 ReleaseDC(NULL
, screen_dc
);
100 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
104 ERR("Failed to blit to/from screen.\n");
111 /*****************************************************************************
112 * IUnknown parts follow
113 *****************************************************************************/
115 /*****************************************************************************
116 * IDirectDrawSurface7::QueryInterface
118 * A normal QueryInterface implementation. For QueryInterface rules
119 * see ddraw.c, IDirectDraw7::QueryInterface. This method
120 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
121 * in all versions, the IDirectDrawGammaControl interface and it can
122 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
125 * riid: The interface id queried for
126 * obj: Address to write the pointer to
130 * E_NOINTERFACE if the requested interface wasn't found
132 *****************************************************************************/
133 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
135 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
137 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
139 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
143 return DDERR_INVALIDPARAMS
;
145 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
147 IDirectDrawSurface7_AddRef(iface
);
149 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
153 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
155 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
156 *obj
= &This
->IDirectDrawSurface4_iface
;
157 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
161 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
163 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
164 *obj
= &This
->IDirectDrawSurface3_iface
;
165 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
169 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
171 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
172 *obj
= &This
->IDirectDrawSurface2_iface
;
173 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
177 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
178 || IsEqualGUID(riid
, &IID_IUnknown
))
180 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
181 *obj
= &This
->IDirectDrawSurface_iface
;
182 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
186 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
188 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
189 *obj
= &This
->IDirectDrawGammaControl_iface
;
190 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
194 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
196 WARN("Color control not implemented.\n");
198 return E_NOINTERFACE
;
201 if (This
->version
!= 7)
203 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
204 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
205 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
207 wined3d_mutex_lock();
212 if (FAILED(hr
= d3d_device_create(This
->ddraw
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
213 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
215 This
->device1
= NULL
;
216 wined3d_mutex_unlock();
217 WARN("Failed to create device, hr %#x.\n", hr
);
221 wined3d_mutex_unlock();
223 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
224 *obj
= &This
->device1
->IDirect3DDevice_iface
;
228 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
230 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
231 *obj
= &This
->IDirect3DTexture2_iface
;
235 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
237 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
238 *obj
= &This
->IDirect3DTexture_iface
;
243 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
245 if (This
->version
!= 7)
248 return E_NOINTERFACE
;
251 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
253 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
255 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
257 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
260 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
262 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
264 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
266 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
269 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
271 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
273 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
275 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
278 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
280 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
282 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
284 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
287 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
288 REFIID riid
, void **object
)
290 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
292 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
294 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
297 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
299 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
301 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
303 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
306 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
308 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
310 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
312 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
315 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
317 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
318 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
320 if (iface_count
== 1)
322 if (surface
->ifaceToRelease
)
323 IUnknown_AddRef(surface
->ifaceToRelease
);
324 wined3d_mutex_lock();
325 if (surface
->wined3d_surface
)
326 wined3d_surface_incref(surface
->wined3d_surface
);
327 if (surface
->wined3d_texture
)
328 wined3d_texture_incref(surface
->wined3d_texture
);
329 wined3d_mutex_unlock();
333 /*****************************************************************************
334 * IDirectDrawSurface7::AddRef
336 * A normal addref implementation
341 *****************************************************************************/
342 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
344 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
345 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
347 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
351 ddraw_surface_add_iface(This
);
357 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
359 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
360 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
362 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
366 ddraw_surface_add_iface(This
);
372 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
374 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
375 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
377 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
381 ddraw_surface_add_iface(This
);
387 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
389 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
390 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
392 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
396 ddraw_surface_add_iface(This
);
402 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
404 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
405 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
407 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
411 ddraw_surface_add_iface(This
);
417 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
419 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
420 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
422 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
426 ddraw_surface_add_iface(This
);
432 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
434 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
436 TRACE("iface %p.\n", iface
);
438 return IUnknown_AddRef(surface
->texture_outer
);
441 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
443 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
445 TRACE("iface %p.\n", iface
);
447 return IUnknown_AddRef(surface
->texture_outer
);
450 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
452 struct ddraw_surface
*surf
;
455 TRACE("surface %p.\n", surface
);
457 /* The refcount test shows that the palette is detached when the surface
459 IDirectDrawSurface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, NULL
);
461 /* Loop through all complex attached surfaces and destroy them.
463 * Yet again, only the root can have more than one complexly attached
464 * surface, all the others have a total of one. */
465 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
467 if (!surface
->complex_array
[i
])
470 surf
= surface
->complex_array
[i
];
471 surface
->complex_array
[i
] = NULL
;
472 ddraw_surface_cleanup(surf
);
475 if (surface
->device1
)
476 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
478 if (surface
->iface_count
> 1)
480 /* This can happen when a complex surface is destroyed, because the
481 * 2nd surface was addref()ed when the app called
482 * GetAttachedSurface(). */
483 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
484 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
487 if (surface
->wined3d_texture
488 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
489 wined3d_texture_decref(surface
->wined3d_texture
);
490 if (surface
->wined3d_surface
)
491 wined3d_surface_decref(surface
->wined3d_surface
);
494 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
496 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
497 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
499 if (iface_count
== 0)
501 IUnknown
*release_iface
= This
->ifaceToRelease
;
503 /* Complex attached surfaces are destroyed implicitly when the root is released */
504 wined3d_mutex_lock();
505 if(!This
->is_complex_root
)
507 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
508 wined3d_mutex_unlock();
511 /* If it's a texture, destroy the wined3d texture. */
512 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
513 wined3d_texture_decref(This
->wined3d_texture
);
515 ddraw_surface_cleanup(This
);
516 wined3d_mutex_unlock();
519 IUnknown_Release(release_iface
);
525 /*****************************************************************************
526 * IDirectDrawSurface7::Release
528 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
529 * surface is destroyed.
531 * Destroying the surface is a bit tricky. For the connection between
532 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
533 * It has a nice graph explaining the connection.
535 * What happens here is basically this:
536 * When a surface is destroyed, its WineD3DSurface is released,
537 * and the refcount of the DirectDraw interface is reduced by 1. If it has
538 * complex surfaces attached to it, then these surfaces are destroyed too,
539 * regardless of their refcount. If any surface being destroyed has another
540 * surface attached to it (with a "soft" attachment, not complex), then
541 * this surface is detached with DeleteAttachedSurface.
543 * When the surface is a texture, the WineD3DTexture is released.
544 * If the surface is the Direct3D render target, then the D3D
545 * capabilities of the WineD3DDevice are uninitialized, which causes the
546 * swapchain to be released.
548 * When a complex sublevel falls to ref zero, then this is ignored.
553 *****************************************************************************/
554 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
556 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
557 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
559 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
563 ddraw_surface_release_iface(This
);
569 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
571 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
572 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
574 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
578 ddraw_surface_release_iface(This
);
584 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
586 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
587 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
589 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
593 ddraw_surface_release_iface(This
);
599 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
601 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
602 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
604 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
608 ddraw_surface_release_iface(This
);
614 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
616 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
617 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
619 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
623 ddraw_surface_release_iface(This
);
629 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
631 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
632 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
634 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
638 ddraw_surface_release_iface(This
);
644 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
646 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
648 TRACE("iface %p.\n", iface
);
650 return IUnknown_Release(surface
->texture_outer
);
653 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
655 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
657 TRACE("iface %p.\n", iface
);
659 return IUnknown_Release(surface
->texture_outer
);
662 /*****************************************************************************
663 * IDirectDrawSurface7::GetAttachedSurface
665 * Returns an attached surface with the requested caps. Surface attachment
666 * and complex surfaces are not clearly described by the MSDN or sdk,
667 * so this method is tricky and likely to contain problems.
668 * This implementation searches the complex list first, then the
671 * The chains are searched from This down to the last surface in the chain,
672 * not from the first element in the chain. The first surface found is
673 * returned. The MSDN says that this method fails if more than one surface
674 * matches the caps, but it is not sure if that is right. The attachment
675 * structure may not even allow two matching surfaces.
677 * The found surface is AddRef-ed before it is returned.
680 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
681 * Surface: Address to store the found surface
685 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
686 * DDERR_NOTFOUND if no surface was found
688 *****************************************************************************/
689 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
690 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
692 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
693 struct ddraw_surface
*surf
;
697 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
699 wined3d_mutex_lock();
701 if(This
->version
< 7)
703 /* Earlier dx apps put garbage into these members, clear them */
704 our_caps
.dwCaps
= Caps
->dwCaps
;
705 our_caps
.dwCaps2
= 0;
706 our_caps
.dwCaps3
= 0;
707 our_caps
.dwCaps4
= 0;
714 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 */
716 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
718 surf
= This
->complex_array
[i
];
721 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
722 surf
->surface_desc
.ddsCaps
.dwCaps
,
723 surf
->surface_desc
.ddsCaps
.dwCaps2
,
724 surf
->surface_desc
.ddsCaps
.dwCaps3
,
725 surf
->surface_desc
.ddsCaps
.dwCaps4
);
727 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
728 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
730 /* MSDN: "This method fails if more than one surface is attached
731 * that matches the capabilities requested."
733 * Not sure how to test this.
736 TRACE("(%p): Returning surface %p\n", This
, surf
);
737 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
738 *Surface
= &surf
->IDirectDrawSurface7_iface
;
739 ddraw_surface7_AddRef(*Surface
);
740 wined3d_mutex_unlock();
746 /* Next, look at the attachment chain */
749 while( (surf
= surf
->next_attached
) )
751 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
752 surf
->surface_desc
.ddsCaps
.dwCaps
,
753 surf
->surface_desc
.ddsCaps
.dwCaps2
,
754 surf
->surface_desc
.ddsCaps
.dwCaps3
,
755 surf
->surface_desc
.ddsCaps
.dwCaps4
);
757 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
758 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
760 TRACE("(%p): Returning surface %p\n", This
, surf
);
761 *Surface
= &surf
->IDirectDrawSurface7_iface
;
762 ddraw_surface7_AddRef(*Surface
);
763 wined3d_mutex_unlock();
768 TRACE("(%p) Didn't find a valid surface\n", This
);
770 wined3d_mutex_unlock();
773 return DDERR_NOTFOUND
;
776 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
777 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
779 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
780 struct ddraw_surface
*attachment_impl
;
781 IDirectDrawSurface7
*attachment7
;
784 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
786 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
793 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
794 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
795 ddraw_surface4_AddRef(*attachment
);
796 ddraw_surface7_Release(attachment7
);
801 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
802 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
804 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
805 struct ddraw_surface
*attachment_impl
;
806 IDirectDrawSurface7
*attachment7
;
810 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
812 caps2
.dwCaps
= caps
->dwCaps
;
817 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
818 &caps2
, &attachment7
);
824 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
825 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
826 ddraw_surface3_AddRef(*attachment
);
827 ddraw_surface7_Release(attachment7
);
832 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
833 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
835 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
836 struct ddraw_surface
*attachment_impl
;
837 IDirectDrawSurface7
*attachment7
;
841 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
843 caps2
.dwCaps
= caps
->dwCaps
;
848 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
849 &caps2
, &attachment7
);
855 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
856 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
857 ddraw_surface2_AddRef(*attachment
);
858 ddraw_surface7_Release(attachment7
);
863 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
864 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
866 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
867 struct ddraw_surface
*attachment_impl
;
868 IDirectDrawSurface7
*attachment7
;
872 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
874 caps2
.dwCaps
= caps
->dwCaps
;
879 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
880 &caps2
, &attachment7
);
886 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
887 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
888 ddraw_surface1_AddRef(*attachment
);
889 ddraw_surface7_Release(attachment7
);
894 /*****************************************************************************
895 * IDirectDrawSurface7::Lock
897 * Locks the surface and returns a pointer to the surface's memory
900 * Rect: Rectangle to lock. If NULL, the whole surface is locked
901 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
902 * Flags: Locking flags, e.g Read only or write only
903 * h: An event handle that's not used and must be NULL
907 * DDERR_INVALIDPARAMS if DDSD is NULL
908 * For more details, see IWineD3DSurface::LockRect
910 *****************************************************************************/
911 static HRESULT
surface_lock(struct ddraw_surface
*This
,
912 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
914 struct wined3d_map_desc map_desc
;
917 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
918 This
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
920 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
921 wined3d_mutex_lock();
923 /* Should I check for the handle to be NULL?
925 * The DDLOCK flags and the D3DLOCK flags are equal
926 * for the supported values. The others are ignored by WineD3D
929 /* Windows zeroes this if the rect is invalid */
936 || (Rect
->left
> Rect
->right
)
937 || (Rect
->top
> Rect
->bottom
)
938 || (Rect
->right
> This
->surface_desc
.dwWidth
)
939 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
941 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
942 wined3d_mutex_unlock();
943 return DDERR_INVALIDPARAMS
;
947 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
948 hr
= ddraw_surface_update_frontbuffer(This
, Rect
, TRUE
);
950 hr
= wined3d_surface_map(This
->wined3d_surface
, &map_desc
, Rect
, Flags
);
953 wined3d_mutex_unlock();
956 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
957 * specific error. But since IWineD3DSurface::LockRect returns that error in this
958 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
959 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
960 * is much easier to do it in one place in ddraw
962 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
967 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
969 if (Flags
& DDLOCK_READONLY
)
970 memset(&This
->ddraw
->primary_lock
, 0, sizeof(This
->ddraw
->primary_lock
));
972 This
->ddraw
->primary_lock
= *Rect
;
974 SetRect(&This
->ddraw
->primary_lock
, 0, 0, This
->surface_desc
.dwWidth
, This
->surface_desc
.dwHeight
);
977 /* Override the memory area. The pitch should be set already. Strangely windows
978 * does not set the LPSURFACE flag on locked surfaces !?!.
979 * DDSD->dwFlags |= DDSD_LPSURFACE;
981 This
->surface_desc
.lpSurface
= map_desc
.data
;
982 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
984 TRACE("locked surface returning description :\n");
985 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
987 wined3d_mutex_unlock();
992 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
993 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
995 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
997 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
998 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1000 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1001 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1002 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1004 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1005 return DDERR_INVALIDPARAMS
;
1007 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1010 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1011 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1013 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1015 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1016 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1018 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1019 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1020 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1022 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1023 return DDERR_INVALIDPARAMS
;
1025 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1028 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1029 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1031 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1032 DDSURFACEDESC2 surface_desc2
;
1035 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1036 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1038 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1039 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1040 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1042 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1043 return DDERR_INVALIDPARAMS
;
1046 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1047 surface_desc2
.dwFlags
= 0;
1048 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1049 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1050 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1054 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1055 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1057 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1058 DDSURFACEDESC2 surface_desc2
;
1061 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1062 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1064 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1065 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1066 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1068 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1069 return DDERR_INVALIDPARAMS
;
1072 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1073 surface_desc2
.dwFlags
= 0;
1074 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1075 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1076 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1080 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1081 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1083 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1084 DDSURFACEDESC2 surface_desc2
;
1086 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1087 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1089 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1090 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1091 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1093 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1094 return DDERR_INVALIDPARAMS
;
1097 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1098 surface_desc2
.dwFlags
= 0;
1099 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1100 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1101 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1105 /*****************************************************************************
1106 * IDirectDrawSurface7::Unlock
1108 * Unlocks an locked surface
1111 * Rect: Not used by this implementation
1115 * For more details, see IWineD3DSurface::UnlockRect
1117 *****************************************************************************/
1118 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1120 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1123 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1125 wined3d_mutex_lock();
1126 hr
= wined3d_surface_unmap(surface
->wined3d_surface
);
1129 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1130 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1131 surface
->surface_desc
.lpSurface
= NULL
;
1133 wined3d_mutex_unlock();
1138 static HRESULT WINAPI
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1140 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1142 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1144 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1147 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1149 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1151 TRACE("iface %p, data %p.\n", iface
, data
);
1153 /* data might not be the LPRECT of later versions, so drop it. */
1154 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1157 static HRESULT WINAPI
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1159 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1161 TRACE("iface %p, data %p.\n", iface
, data
);
1163 /* data might not be the LPRECT of later versions, so drop it. */
1164 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1167 static HRESULT WINAPI
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1169 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1171 TRACE("iface %p, data %p.\n", iface
, data
);
1173 /* data might not be the LPRECT of later versions, so drop it. */
1174 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1177 /*****************************************************************************
1178 * IDirectDrawSurface7::Flip
1180 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
1181 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
1182 * the flip target is passed to WineD3D, even if the app didn't specify one
1185 * DestOverride: Specifies the surface that will become the new front
1186 * buffer. If NULL, the current back buffer is used
1187 * Flags: some DirectDraw flags, see include/ddraw.h
1191 * DDERR_NOTFLIPPABLE if no flip target could be found
1192 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
1193 * For more details, see IWineD3DSurface::Flip
1195 *****************************************************************************/
1196 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
1198 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1199 struct ddraw_surface
*Override
= unsafe_impl_from_IDirectDrawSurface7(DestOverride
);
1200 IDirectDrawSurface7
*Override7
;
1203 TRACE("iface %p, dst %p, flags %#x.\n", iface
, DestOverride
, Flags
);
1205 /* Flip has to be called from a front buffer
1206 * What about overlay surfaces, AFAIK they can flip too? */
1207 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1208 return DDERR_INVALIDOBJECT
; /* Unchecked */
1210 wined3d_mutex_lock();
1212 /* WineD3D doesn't keep track of attached surface, so find the target */
1217 memset(&Caps
, 0, sizeof(Caps
));
1218 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
1219 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
1222 ERR("Can't find a flip target\n");
1223 wined3d_mutex_unlock();
1224 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1226 Override
= impl_from_IDirectDrawSurface7(Override7
);
1228 /* For the GetAttachedSurface */
1229 ddraw_surface7_Release(Override7
);
1232 hr
= wined3d_surface_flip(surface
->wined3d_surface
, Override
->wined3d_surface
, Flags
);
1233 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1234 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
1236 wined3d_mutex_unlock();
1241 static HRESULT WINAPI
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*dst
, DWORD flags
)
1243 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1244 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1246 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1248 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1249 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1252 static HRESULT WINAPI
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
1254 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1255 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1257 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1259 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1260 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1263 static HRESULT WINAPI
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*dst
, DWORD flags
)
1265 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1266 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1268 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1270 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1271 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1274 static HRESULT WINAPI
ddraw_surface1_Flip(IDirectDrawSurface
*iface
, IDirectDrawSurface
*dst
, DWORD flags
)
1276 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1277 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1279 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1281 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1282 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1285 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1286 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1287 const WINEDDBLTFX
*fx
, enum wined3d_texture_filter_type filter
)
1289 struct wined3d_surface
*wined3d_src_surface
= src_surface
? src_surface
->wined3d_surface
: NULL
;
1290 RECT src_rect
, dst_rect
;
1291 float scale_x
, scale_y
;
1292 const RECT
*clip_rect
;
1293 UINT clip_list_size
;
1298 if (!dst_surface
->clipper
)
1300 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1301 hr
= ddraw_surface_update_frontbuffer(src_surface
, src_rect_in
, TRUE
);
1303 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, dst_rect_in
,
1304 wined3d_src_surface
, src_rect_in
, flags
, fx
, filter
);
1305 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
1306 hr
= ddraw_surface_update_frontbuffer(dst_surface
, dst_rect_in
, FALSE
);
1315 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1316 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1320 dst_rect
= *dst_rect_in
;
1323 if (IsRectEmpty(&dst_rect
))
1324 return DDERR_INVALIDRECT
;
1332 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1333 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1337 src_rect
= *src_rect_in
;
1340 if (IsRectEmpty(&src_rect
))
1341 return DDERR_INVALIDRECT
;
1345 SetRect(&src_rect
, 0, 0, 0, 0);
1348 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1349 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1351 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1352 &dst_rect
, NULL
, &clip_list_size
)))
1354 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1358 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1360 WARN("Failed to allocate clip list.\n");
1361 return E_OUTOFMEMORY
;
1364 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1365 &dst_rect
, clip_list
, &clip_list_size
)))
1367 WARN("Failed to get clip list, hr %#x.\n", hr
);
1368 HeapFree(GetProcessHeap(), 0, clip_list
);
1372 clip_rect
= (RECT
*)clip_list
->Buffer
;
1373 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1375 RECT src_rect_clipped
= src_rect
;
1379 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1380 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1381 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1382 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1384 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1386 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1391 if (FAILED(hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, &clip_rect
[i
],
1392 wined3d_src_surface
, &src_rect_clipped
, flags
, fx
, filter
)))
1395 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1397 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1402 HeapFree(GetProcessHeap(), 0, clip_list
);
1406 /*****************************************************************************
1407 * IDirectDrawSurface7::Blt
1409 * Performs a blit on the surface
1412 * DestRect: Destination rectangle, can be NULL
1413 * SrcSurface: Source surface, can be NULL
1414 * SrcRect: Source rectangle, can be NULL
1416 * DDBltFx: Some extended blt parameters, connected to the flags
1420 * See IWineD3DSurface::Blt for more details
1422 *****************************************************************************/
1423 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1424 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1426 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1427 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1430 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1431 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1433 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1434 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1436 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1437 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1438 return DDERR_INVALIDPARAMS
;
1441 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1442 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1443 return DDERR_INVALIDPARAMS
;
1446 wined3d_mutex_lock();
1448 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1450 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1451 wined3d_mutex_unlock();
1452 return DDERR_INVALIDPARAMS
;
1455 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1456 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1457 * surfaces. So far no blitting operations using surfaces in the bltfx
1458 * struct are supported anyway. */
1459 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1460 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1462 wined3d_mutex_unlock();
1465 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1466 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1471 static HRESULT WINAPI
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1472 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1474 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1475 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1477 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1478 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1480 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1481 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1484 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1485 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1487 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1488 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1490 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1491 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1493 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1494 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1497 static HRESULT WINAPI
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1498 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1500 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1501 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1503 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1504 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1506 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1507 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1510 static HRESULT WINAPI
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1511 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1513 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1514 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1516 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1517 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1519 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1520 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1523 /*****************************************************************************
1524 * IDirectDrawSurface7::AddAttachedSurface
1526 * Attaches a surface to another surface. How the surface attachments work
1527 * is not totally understood yet, and this method is prone to problems.
1528 * The surface that is attached is AddRef-ed.
1530 * Tests with complex surfaces suggest that the surface attachments form a
1531 * tree, but no method to test this has been found yet.
1533 * The attachment list consists of a first surface (first_attached) and
1534 * for each surface a pointer to the next attached surface (next_attached).
1535 * For the first surface, and a surface that has no attachments
1536 * first_attached points to the surface itself. A surface that has
1537 * no successors in the chain has next_attached set to NULL.
1539 * Newly attached surfaces are attached right after the root surface.
1540 * If a surface is attached to a complex surface compound, it's attached to
1541 * the surface that the app requested, not the complex root. See
1542 * GetAttachedSurface for a description how surfaces are found.
1544 * This is how the current implementation works, and it was coded by looking
1545 * at the needs of the applications.
1547 * So far only Z-Buffer attachments are tested, and they are activated in
1548 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1549 * Back buffers should work in 2D mode, but they are not tested(They can be
1550 * attached in older iface versions). Rendering to the front buffer and
1551 * switching between that and double buffering is not yet implemented in
1552 * WineD3D, so for 3D it might have unexpected results.
1554 * ddraw_surface_attach_surface is the real thing,
1555 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1556 * performs additional checks. Version 7 of this interface is much more restrictive
1557 * than its predecessors.
1560 * Attach: Surface to attach to iface
1564 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1566 *****************************************************************************/
1567 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1569 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1572 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1574 wined3d_mutex_lock();
1576 /* Check if the surface is already attached somewhere */
1577 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1579 /* TODO: Test for the structure of the manual attachment. Is it a
1580 * chain or a list? What happens if one surface is attached to 2
1581 * different surfaces? */
1582 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1583 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1585 wined3d_mutex_unlock();
1586 return DDERR_SURFACEALREADYATTACHED
;
1589 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1590 Surf
->next_attached
= This
->next_attached
;
1591 Surf
->first_attached
= This
->first_attached
;
1592 This
->next_attached
= Surf
;
1594 /* Check if the WineD3D depth stencil needs updating */
1595 if (This
->ddraw
->d3ddevice
)
1596 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1598 wined3d_mutex_unlock();
1603 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1605 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1606 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1609 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1611 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1612 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1615 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1616 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1617 return DDERR_CANNOTATTACHSURFACE
;
1620 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1625 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1626 IUnknown_AddRef(attachment_impl
->attached_iface
);
1630 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1632 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
1633 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1636 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1638 hr
= ddraw_surface7_AddAttachedSurface(&This
->IDirectDrawSurface7_iface
,
1639 attachment_impl
? &attachment_impl
->IDirectDrawSurface7_iface
: NULL
);
1644 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1645 IUnknown_AddRef(attachment_impl
->attached_iface
);
1646 ddraw_surface7_Release(&attachment_impl
->IDirectDrawSurface7_iface
);
1649 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1651 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
1652 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1655 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1657 /* Tests suggest that
1658 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1659 * -> offscreen plain surfaces can be attached to primaries
1660 * -> primaries can be attached to offscreen plain surfaces
1661 * -> z buffers can be attached to primaries */
1662 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1663 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1665 /* Sizes have to match */
1666 if (attachment_impl
->surface_desc
.dwWidth
!= This
->surface_desc
.dwWidth
1667 || attachment_impl
->surface_desc
.dwHeight
!= This
->surface_desc
.dwHeight
)
1669 WARN("Surface sizes do not match.\n");
1670 return DDERR_CANNOTATTACHSURFACE
;
1674 else if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1675 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1681 WARN("Invalid attachment combination.\n");
1682 return DDERR_CANNOTATTACHSURFACE
;
1685 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1690 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1691 IUnknown_AddRef(attachment_impl
->attached_iface
);
1695 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1697 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
1698 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1701 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1703 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1704 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1709 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1710 IUnknown_AddRef(attachment_impl
->attached_iface
);
1711 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1715 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1717 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
1718 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1721 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1723 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1724 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1729 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1730 IUnknown_AddRef(attachment_impl
->attached_iface
);
1731 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1735 /*****************************************************************************
1736 * IDirectDrawSurface7::DeleteAttachedSurface
1738 * Removes a surface from the attachment chain. The surface's refcount
1739 * is decreased by one after it has been removed
1742 * Flags: Some flags, not used by this implementation
1743 * Attach: Surface to detach
1747 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1749 *****************************************************************************/
1750 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1751 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1753 struct ddraw_surface
*prev
= surface
;
1755 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1757 wined3d_mutex_lock();
1758 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1760 wined3d_mutex_unlock();
1761 return DDERR_CANNOTDETACHSURFACE
;
1764 if (attachment
->attached_iface
!= detach_iface
)
1766 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1767 wined3d_mutex_unlock();
1768 return DDERR_SURFACENOTATTACHED
;
1771 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1772 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1774 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1775 /* FIXME: we should probably also subtract from dwMipMapCount of this
1776 * and all parent surfaces */
1779 /* Find the predecessor of the detached surface */
1782 if (prev
->next_attached
== attachment
)
1784 prev
= prev
->next_attached
;
1787 /* There must be a surface, otherwise there's a bug */
1790 /* Unchain the surface */
1791 prev
->next_attached
= attachment
->next_attached
;
1792 attachment
->next_attached
= NULL
;
1793 attachment
->first_attached
= attachment
;
1795 /* Check if the wined3d depth stencil needs updating. */
1796 if (surface
->ddraw
->d3ddevice
)
1797 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1798 wined3d_mutex_unlock();
1800 /* Set attached_iface to NULL before releasing it, the surface may go
1802 attachment
->attached_iface
= NULL
;
1803 IUnknown_Release(detach_iface
);
1808 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1809 DWORD flags
, IDirectDrawSurface7
*attachment
)
1811 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1812 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1814 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1816 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1819 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1820 DWORD flags
, IDirectDrawSurface4
*attachment
)
1822 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1823 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1825 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1827 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1830 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1831 DWORD flags
, IDirectDrawSurface3
*attachment
)
1833 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1834 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1836 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1838 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1841 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
1842 DWORD flags
, IDirectDrawSurface2
*attachment
)
1844 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1845 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1847 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1849 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1852 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
1853 DWORD flags
, IDirectDrawSurface
*attachment
)
1855 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1856 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1858 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1860 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1863 /*****************************************************************************
1864 * IDirectDrawSurface7::AddOverlayDirtyRect
1866 * "This method is not currently implemented"
1874 *****************************************************************************/
1875 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1877 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1879 return DDERR_UNSUPPORTED
; /* unchecked */
1882 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
1884 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1886 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1888 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1891 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1893 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1895 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1897 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1900 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
1902 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1904 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1906 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1909 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
1911 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1913 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1915 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1918 /*****************************************************************************
1919 * IDirectDrawSurface7::GetDC
1921 * Returns a GDI device context for the surface
1924 * hdc: Address of a HDC variable to store the dc to
1928 * DDERR_INVALIDPARAMS if hdc is NULL
1929 * For details, see IWineD3DSurface::GetDC
1931 *****************************************************************************/
1932 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1934 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1937 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1940 return DDERR_INVALIDPARAMS
;
1942 wined3d_mutex_lock();
1943 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1944 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
1946 hr
= wined3d_surface_getdc(surface
->wined3d_surface
, hdc
);
1947 wined3d_mutex_unlock();
1950 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1953 case WINED3DERR_INVALIDCALL
:
1954 if(hdc
) *hdc
= NULL
;
1955 return DDERR_INVALIDPARAMS
;
1961 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
1963 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1965 TRACE("iface %p, dc %p.\n", iface
, dc
);
1967 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1970 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1972 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1974 TRACE("iface %p, dc %p.\n", iface
, dc
);
1976 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1979 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
1981 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1983 TRACE("iface %p, dc %p.\n", iface
, dc
);
1985 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1988 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
1990 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1992 TRACE("iface %p, dc %p.\n", iface
, dc
);
1994 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1997 /*****************************************************************************
1998 * IDirectDrawSurface7::ReleaseDC
2000 * Releases the DC that was constructed with GetDC
2003 * hdc: HDC to release
2007 * For more details, see IWineD3DSurface::ReleaseDC
2009 *****************************************************************************/
2010 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2012 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2015 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2017 wined3d_mutex_lock();
2018 hr
= wined3d_surface_releasedc(surface
->wined3d_surface
, hdc
);
2019 if (SUCCEEDED(hr
) && (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
2020 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2021 wined3d_mutex_unlock();
2026 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2028 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2030 TRACE("iface %p, dc %p.\n", iface
, dc
);
2032 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2035 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2037 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2039 TRACE("iface %p, dc %p.\n", iface
, dc
);
2041 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2044 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2046 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2048 TRACE("iface %p, dc %p.\n", iface
, dc
);
2050 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2053 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2055 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2057 TRACE("iface %p, dc %p.\n", iface
, dc
);
2059 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2062 /*****************************************************************************
2063 * IDirectDrawSurface7::GetCaps
2065 * Returns the surface's caps
2068 * Caps: Address to write the caps to
2072 * DDERR_INVALIDPARAMS if Caps is NULL
2074 *****************************************************************************/
2075 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2077 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2079 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2082 return DDERR_INVALIDPARAMS
;
2084 *Caps
= surface
->surface_desc
.ddsCaps
;
2089 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2091 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2093 TRACE("iface %p, caps %p.\n", iface
, caps
);
2095 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2098 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2104 TRACE("iface %p, caps %p.\n", iface
, caps
);
2106 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2107 if (FAILED(hr
)) return hr
;
2109 caps
->dwCaps
= caps2
.dwCaps
;
2113 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2115 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2119 TRACE("iface %p, caps %p.\n", iface
, caps
);
2121 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2122 if (FAILED(hr
)) return hr
;
2124 caps
->dwCaps
= caps2
.dwCaps
;
2128 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2130 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2134 TRACE("iface %p, caps %p.\n", iface
, caps
);
2136 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2137 if (FAILED(hr
)) return hr
;
2139 caps
->dwCaps
= caps2
.dwCaps
;
2143 /*****************************************************************************
2144 * IDirectDrawSurface7::SetPriority
2146 * Sets a texture priority for managed textures.
2149 * Priority: The new priority
2153 * For more details, see IWineD3DSurface::SetPriority
2155 *****************************************************************************/
2156 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
2158 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2161 TRACE("iface %p, priority %u.\n", iface
, Priority
);
2163 wined3d_mutex_lock();
2164 hr
= wined3d_surface_set_priority(surface
->wined3d_surface
, Priority
);
2165 wined3d_mutex_unlock();
2170 /*****************************************************************************
2171 * IDirectDrawSurface7::GetPriority
2173 * Returns the surface's priority
2176 * Priority: Address of a variable to write the priority to
2180 * DDERR_INVALIDPARAMS if Priority == NULL
2181 * For more details, see IWineD3DSurface::GetPriority
2183 *****************************************************************************/
2184 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
2186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2188 TRACE("iface %p, priority %p.\n", iface
, Priority
);
2192 return DDERR_INVALIDPARAMS
;
2195 wined3d_mutex_lock();
2196 *Priority
= wined3d_surface_get_priority(surface
->wined3d_surface
);
2197 wined3d_mutex_unlock();
2202 /*****************************************************************************
2203 * IDirectDrawSurface7::SetPrivateData
2205 * Stores some data in the surface that is intended for the application's
2209 * tag: GUID that identifies the data
2210 * Data: Pointer to the private data
2211 * Size: Size of the private data
2216 * For more details, see IWineD3DSurface::SetPrivateData
2218 *****************************************************************************/
2219 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2220 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
2222 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2223 struct wined3d_resource
*resource
;
2226 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2227 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
2229 wined3d_mutex_lock();
2230 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2231 hr
= wined3d_resource_set_private_data(resource
, tag
, Data
, Size
, Flags
);
2232 wined3d_mutex_unlock();
2236 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2241 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2242 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2244 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2246 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2247 iface
, debugstr_guid(tag
), data
, size
, flags
);
2249 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2252 /*****************************************************************************
2253 * IDirectDrawSurface7::GetPrivateData
2255 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2258 * tag: GUID of the data to return
2259 * Data: Address where to write the data to
2260 * Size: Size of the buffer at Data
2264 * DDERR_INVALIDPARAMS if Data is NULL
2265 * For more details, see IWineD3DSurface::GetPrivateData
2267 *****************************************************************************/
2268 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
2270 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2271 struct wined3d_resource
*resource
;
2274 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2275 iface
, debugstr_guid(tag
), Data
, Size
);
2278 return DDERR_INVALIDPARAMS
;
2280 wined3d_mutex_lock();
2281 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2282 hr
= wined3d_resource_get_private_data(resource
, tag
, Data
, Size
);
2283 wined3d_mutex_unlock();
2288 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2290 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2292 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2293 iface
, debugstr_guid(tag
), data
, size
);
2295 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2298 /*****************************************************************************
2299 * IDirectDrawSurface7::FreePrivateData
2301 * Frees private data stored in the surface
2304 * tag: Tag of the data to free
2308 * For more details, see IWineD3DSurface::FreePrivateData
2310 *****************************************************************************/
2311 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2313 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2314 struct wined3d_resource
*resource
;
2317 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2319 wined3d_mutex_lock();
2320 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2321 hr
= wined3d_resource_free_private_data(resource
, tag
);
2322 wined3d_mutex_unlock();
2327 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2329 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2331 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2333 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2336 /*****************************************************************************
2337 * IDirectDrawSurface7::PageLock
2339 * Prevents a sysmem surface from being paged out
2342 * Flags: Not used, must be 0(unchecked)
2345 * DD_OK, because it's a stub
2347 *****************************************************************************/
2348 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2350 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2352 /* This is Windows memory management related - we don't need this */
2356 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2358 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2360 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2362 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2365 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2367 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2369 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2371 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2374 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2376 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2378 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2380 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2383 /*****************************************************************************
2384 * IDirectDrawSurface7::PageUnlock
2386 * Allows a sysmem surface to be paged out
2389 * Flags: Not used, must be 0(unchecked)
2392 * DD_OK, because it's a stub
2394 *****************************************************************************/
2395 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2397 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2402 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2404 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2406 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2408 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2411 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2413 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2415 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2417 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2420 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2422 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2424 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2426 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2429 /*****************************************************************************
2430 * IDirectDrawSurface7::BltBatch
2432 * An unimplemented function
2440 *****************************************************************************/
2441 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2443 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2445 /* MSDN: "not currently implemented" */
2446 return DDERR_UNSUPPORTED
;
2449 static HRESULT WINAPI
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2451 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2453 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2455 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2458 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2460 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2462 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2464 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2467 static HRESULT WINAPI
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2469 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2471 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2473 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2476 static HRESULT WINAPI
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2478 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2480 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2482 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2485 /*****************************************************************************
2486 * IDirectDrawSurface7::EnumAttachedSurfaces
2488 * Enumerates all surfaces attached to this surface
2491 * context: Pointer to pass unmodified to the callback
2492 * cb: Callback function to call for each surface
2496 * DDERR_INVALIDPARAMS if cb is NULL
2498 *****************************************************************************/
2499 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2500 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2502 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2503 struct ddraw_surface
*surf
;
2504 DDSURFACEDESC2 desc
;
2507 /* Attached surfaces aren't handled in WineD3D */
2508 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2511 return DDERR_INVALIDPARAMS
;
2513 wined3d_mutex_lock();
2515 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2517 surf
= surface
->complex_array
[i
];
2520 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2521 desc
= surf
->surface_desc
;
2522 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2523 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2525 wined3d_mutex_unlock();
2530 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2532 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2533 desc
= surf
->surface_desc
;
2534 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2535 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2537 wined3d_mutex_unlock();
2542 TRACE(" end of enumeration.\n");
2544 wined3d_mutex_unlock();
2549 struct callback_info2
2551 LPDDENUMSURFACESCALLBACK2 callback
;
2555 struct callback_info
2557 LPDDENUMSURFACESCALLBACK callback
;
2561 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2563 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2564 const struct callback_info2
*info
= context
;
2566 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2567 ddraw_surface7_Release(surface
);
2569 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2572 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2574 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2575 const struct callback_info
*info
= context
;
2577 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2578 ddraw_surface7_Release(surface
);
2580 /* FIXME: Check surface_test.dwSize */
2581 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2582 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2585 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2586 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2588 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2589 struct callback_info2 info
;
2591 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2593 info
.callback
= callback
;
2594 info
.context
= context
;
2596 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2597 &info
, EnumCallback2
);
2600 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2601 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2603 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2604 struct callback_info info
;
2606 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2608 info
.callback
= callback
;
2609 info
.context
= context
;
2611 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2612 &info
, EnumCallback
);
2615 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2616 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2618 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2619 struct callback_info info
;
2621 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2623 info
.callback
= callback
;
2624 info
.context
= context
;
2626 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2627 &info
, EnumCallback
);
2630 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2631 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2633 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2634 struct callback_info info
;
2636 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2638 info
.callback
= callback
;
2639 info
.context
= context
;
2641 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2642 &info
, EnumCallback
);
2645 /*****************************************************************************
2646 * IDirectDrawSurface7::EnumOverlayZOrders
2648 * "Enumerates the overlay surfaces on the specified destination"
2651 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2652 * context: context to pass back to the callback
2653 * cb: callback function to call for each enumerated surface
2656 * DD_OK, because it's a stub
2658 *****************************************************************************/
2659 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2660 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2662 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2667 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2668 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2670 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2671 struct callback_info2 info
;
2673 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2675 info
.callback
= callback
;
2676 info
.context
= context
;
2678 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2679 flags
, &info
, EnumCallback2
);
2682 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2683 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2685 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2686 struct callback_info info
;
2688 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2690 info
.callback
= callback
;
2691 info
.context
= context
;
2693 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2694 flags
, &info
, EnumCallback
);
2697 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2698 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2700 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2701 struct callback_info info
;
2703 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2705 info
.callback
= callback
;
2706 info
.context
= context
;
2708 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2709 flags
, &info
, EnumCallback
);
2712 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2713 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2715 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2716 struct callback_info info
;
2718 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2720 info
.callback
= callback
;
2721 info
.context
= context
;
2723 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2724 flags
, &info
, EnumCallback
);
2727 /*****************************************************************************
2728 * IDirectDrawSurface7::GetBltStatus
2730 * Returns the blitting status
2733 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2736 * See IWineD3DSurface::Blt
2738 *****************************************************************************/
2739 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2741 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2744 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2746 wined3d_mutex_lock();
2747 hr
= wined3d_surface_get_blt_status(surface
->wined3d_surface
, Flags
);
2748 wined3d_mutex_unlock();
2751 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2756 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2758 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2760 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2762 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2765 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2767 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2769 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2771 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2774 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2776 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2778 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2780 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2783 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2785 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2787 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2789 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2792 /*****************************************************************************
2793 * IDirectDrawSurface7::GetColorKey
2795 * Returns the color key assigned to the surface
2799 * CKey: Address to store the key to
2803 * DDERR_INVALIDPARAMS if CKey is NULL
2805 *****************************************************************************/
2806 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2808 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
2810 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2813 return DDERR_INVALIDPARAMS
;
2815 wined3d_mutex_lock();
2819 case DDCKEY_DESTBLT
:
2820 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
2822 wined3d_mutex_unlock();
2823 return DDERR_NOCOLORKEY
;
2825 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
2828 case DDCKEY_DESTOVERLAY
:
2829 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
2831 wined3d_mutex_unlock();
2832 return DDERR_NOCOLORKEY
;
2834 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
2838 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
2840 wined3d_mutex_unlock();
2841 return DDERR_NOCOLORKEY
;
2843 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
2846 case DDCKEY_SRCOVERLAY
:
2847 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
2849 wined3d_mutex_unlock();
2850 return DDERR_NOCOLORKEY
;
2852 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
2856 wined3d_mutex_unlock();
2857 return DDERR_INVALIDPARAMS
;
2860 wined3d_mutex_unlock();
2865 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2867 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2869 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2871 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2874 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2876 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2878 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2880 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2883 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2885 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2887 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2889 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2892 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2896 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2898 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2901 /*****************************************************************************
2902 * IDirectDrawSurface7::GetFlipStatus
2904 * Returns the flipping status of the surface
2907 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2910 * See IWineD3DSurface::GetFlipStatus
2912 *****************************************************************************/
2913 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2915 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2918 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2920 wined3d_mutex_lock();
2921 hr
= wined3d_surface_get_flip_status(surface
->wined3d_surface
, Flags
);
2922 wined3d_mutex_unlock();
2926 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2931 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2933 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2935 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2937 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2940 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2942 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2944 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2946 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2949 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2951 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2953 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2955 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2958 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2960 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2962 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2964 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2967 /*****************************************************************************
2968 * IDirectDrawSurface7::GetOverlayPosition
2970 * Returns the display coordinates of a visible and active overlay surface
2977 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
2978 *****************************************************************************/
2979 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
2981 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2984 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
2986 wined3d_mutex_lock();
2987 hr
= wined3d_surface_get_overlay_position(surface
->wined3d_surface
, X
, Y
);
2988 wined3d_mutex_unlock();
2993 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
2995 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2997 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
2999 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3002 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3004 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3006 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3008 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3011 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3013 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3015 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3017 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3020 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3022 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3024 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3026 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3029 /*****************************************************************************
3030 * IDirectDrawSurface7::GetPixelFormat
3032 * Returns the pixel format of the Surface
3035 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3036 * format should be written
3040 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3042 *****************************************************************************/
3043 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3045 /* What is DDERR_INVALIDSURFACETYPE for here? */
3046 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3048 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3051 return DDERR_INVALIDPARAMS
;
3053 wined3d_mutex_lock();
3054 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3055 wined3d_mutex_unlock();
3060 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3064 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3066 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3069 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3071 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3073 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3075 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3078 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3080 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3082 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3084 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3087 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3089 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3091 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3093 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3096 /*****************************************************************************
3097 * IDirectDrawSurface7::GetSurfaceDesc
3099 * Returns the description of this surface
3102 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3107 * DDERR_INVALIDPARAMS if DDSD is NULL
3109 *****************************************************************************/
3110 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3112 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3114 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3117 return DDERR_INVALIDPARAMS
;
3119 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3121 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3122 return DDERR_INVALIDPARAMS
;
3125 wined3d_mutex_lock();
3126 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3127 TRACE("Returning surface desc:\n");
3128 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3129 wined3d_mutex_unlock();
3134 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3136 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3138 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3140 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3143 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3145 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3147 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3149 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3151 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3153 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3154 return DDERR_INVALIDPARAMS
;
3157 wined3d_mutex_lock();
3158 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3159 TRACE("Returning surface desc:\n");
3160 if (TRACE_ON(ddraw
))
3162 /* DDRAW_dump_surface_desc handles the smaller size */
3163 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3165 wined3d_mutex_unlock();
3170 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3172 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3174 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3176 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3179 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3181 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3183 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3185 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3188 /*****************************************************************************
3189 * IDirectDrawSurface7::Initialize
3191 * Initializes the surface. This is a no-op in Wine
3194 * DD: Pointer to an DirectDraw interface
3195 * DDSD: Surface description for initialization
3198 * DDERR_ALREADYINITIALIZED
3200 *****************************************************************************/
3201 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3202 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3204 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3206 return DDERR_ALREADYINITIALIZED
;
3209 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3210 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3212 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3214 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3216 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3217 ddraw
, surface_desc
);
3220 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3221 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3223 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3224 DDSURFACEDESC2 surface_desc2
;
3226 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3228 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3229 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3230 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3233 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3234 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3236 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3237 DDSURFACEDESC2 surface_desc2
;
3239 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3241 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3242 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3243 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3246 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3247 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3249 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3250 DDSURFACEDESC2 surface_desc2
;
3252 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3254 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3255 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3256 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3259 /*****************************************************************************
3260 * IDirect3DTexture1::Initialize
3262 * The sdk says it's not implemented
3270 *****************************************************************************/
3271 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3272 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3274 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3276 return DDERR_UNSUPPORTED
; /* Unchecked */
3279 /*****************************************************************************
3280 * IDirectDrawSurface7::IsLost
3282 * Checks if the surface is lost
3285 * DD_OK, if the surface is usable
3286 * DDERR_ISLOST if the surface is lost
3287 * See IWineD3DSurface::IsLost for more details
3289 *****************************************************************************/
3290 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3292 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3295 TRACE("iface %p.\n", iface
);
3297 wined3d_mutex_lock();
3298 hr
= wined3d_surface_is_lost(surface
->wined3d_surface
);
3299 wined3d_mutex_unlock();
3303 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3304 * WineD3D uses the same error for surfaces
3306 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3311 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3313 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3315 TRACE("iface %p.\n", iface
);
3317 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3320 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3322 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3324 TRACE("iface %p.\n", iface
);
3326 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3329 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3331 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3333 TRACE("iface %p.\n", iface
);
3335 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3338 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3340 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3342 TRACE("iface %p.\n", iface
);
3344 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3347 /*****************************************************************************
3348 * IDirectDrawSurface7::Restore
3350 * Restores a lost surface. This makes the surface usable again, but
3351 * doesn't reload its old contents
3355 * See IWineD3DSurface::Restore for more details
3357 *****************************************************************************/
3358 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3360 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3363 TRACE("iface %p.\n", iface
);
3365 wined3d_mutex_lock();
3366 hr
= wined3d_surface_restore(surface
->wined3d_surface
);
3367 wined3d_mutex_unlock();
3372 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3376 TRACE("iface %p.\n", iface
);
3378 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3381 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3383 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3385 TRACE("iface %p.\n", iface
);
3387 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3390 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3392 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3394 TRACE("iface %p.\n", iface
);
3396 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3399 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3401 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3403 TRACE("iface %p.\n", iface
);
3405 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3408 /*****************************************************************************
3409 * IDirectDrawSurface7::SetOverlayPosition
3411 * Changes the display coordinates of an overlay surface
3418 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3419 *****************************************************************************/
3420 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3422 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3425 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3427 wined3d_mutex_lock();
3428 hr
= wined3d_surface_set_overlay_position(surface
->wined3d_surface
, X
, Y
);
3429 wined3d_mutex_unlock();
3434 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3436 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3438 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3440 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3443 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3445 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3447 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3449 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3452 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3454 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3456 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3458 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3461 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3463 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3465 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3467 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3470 /*****************************************************************************
3471 * IDirectDrawSurface7::UpdateOverlay
3473 * Modifies the attributes of an overlay surface.
3476 * SrcRect: The section of the source being used for the overlay
3477 * DstSurface: Address of the surface that is overlaid
3478 * DstRect: Place of the overlay
3479 * Flags: some DDOVER_* flags
3482 * DDERR_UNSUPPORTED, because we don't support overlays
3484 *****************************************************************************/
3485 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3486 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3488 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3489 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3492 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3493 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3495 wined3d_mutex_lock();
3496 hr
= wined3d_surface_update_overlay(src_impl
->wined3d_surface
, SrcRect
,
3497 dst_impl
? dst_impl
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3498 wined3d_mutex_unlock();
3501 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3502 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3503 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3509 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3510 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3512 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3513 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3515 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3516 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3518 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3519 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3522 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3523 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3525 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3526 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3528 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3529 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3531 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3532 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3535 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3536 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3538 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3539 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3541 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3542 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3544 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3545 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3548 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3549 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3551 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3552 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3554 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3555 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3557 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3558 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3561 /*****************************************************************************
3562 * IDirectDrawSurface7::UpdateOverlayDisplay
3564 * The DX7 sdk says that it's not implemented
3569 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3571 *****************************************************************************/
3572 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3574 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3576 return DDERR_UNSUPPORTED
;
3579 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3581 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3583 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3585 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3588 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3590 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3592 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3594 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3597 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3599 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3601 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3603 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3606 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3608 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3610 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3612 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3615 /*****************************************************************************
3616 * IDirectDrawSurface7::UpdateOverlayZOrder
3618 * Sets an overlay's Z order
3621 * Flags: DDOVERZ_* flags
3622 * DDSRef: Defines the relative position in the overlay chain
3625 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3627 *****************************************************************************/
3628 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3629 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3631 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3632 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3635 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3637 wined3d_mutex_lock();
3638 hr
= wined3d_surface_update_overlay_z_order(surface
->wined3d_surface
,
3639 Flags
, reference_impl
? reference_impl
->wined3d_surface
: NULL
);
3640 wined3d_mutex_unlock();
3645 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3646 DWORD flags
, IDirectDrawSurface4
*reference
)
3648 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3649 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3651 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3653 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3654 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3657 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3658 DWORD flags
, IDirectDrawSurface3
*reference
)
3660 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3661 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3663 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3665 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3666 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3669 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3670 DWORD flags
, IDirectDrawSurface2
*reference
)
3672 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3673 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3675 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3677 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3678 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3681 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3682 DWORD flags
, IDirectDrawSurface
*reference
)
3684 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3685 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3687 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3689 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3690 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3693 /*****************************************************************************
3694 * IDirectDrawSurface7::GetDDInterface
3696 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3697 * surface belongs to
3700 * DD: Address to write the interface pointer to
3704 * DDERR_INVALIDPARAMS if DD is NULL
3706 *****************************************************************************/
3707 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3709 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3711 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3714 return DDERR_INVALIDPARAMS
;
3716 switch(This
->version
)
3719 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3723 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3727 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3731 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3735 IUnknown_AddRef((IUnknown
*)*DD
);
3740 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3742 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3744 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3746 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3749 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3751 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3753 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3755 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3758 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3760 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3762 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3764 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3767 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3768 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3770 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3771 volatile struct ddraw_surface
* vThis
= This
;
3773 TRACE("iface %p.\n", iface
);
3775 wined3d_mutex_lock();
3776 /* A uniqueness value of 0 is apparently special.
3777 * This needs to be checked.
3778 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3781 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
3782 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
3784 if (old_uniqueness_value
== 0) break;
3785 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
3787 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
3788 old_uniqueness_value
,
3789 new_uniqueness_value
)
3790 == old_uniqueness_value
)
3794 wined3d_mutex_unlock();
3799 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3801 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3803 TRACE("iface %p.\n", iface
);
3805 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
3808 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3810 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3812 TRACE("iface %p, value %p.\n", iface
, pValue
);
3814 wined3d_mutex_lock();
3815 *pValue
= surface
->uniqueness_value
;
3816 wined3d_mutex_unlock();
3821 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3823 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3825 TRACE("iface %p, value %p.\n", iface
, pValue
);
3827 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
3830 /*****************************************************************************
3831 * IDirectDrawSurface7::SetLOD
3833 * Sets the level of detail of a texture
3836 * MaxLOD: LOD to set
3840 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3842 *****************************************************************************/
3843 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
3845 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3848 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
3850 wined3d_mutex_lock();
3851 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3853 wined3d_mutex_unlock();
3854 return DDERR_INVALIDOBJECT
;
3857 if (!surface
->wined3d_texture
)
3859 ERR("The ddraw surface has no wined3d texture.\n");
3860 wined3d_mutex_unlock();
3861 return DDERR_INVALIDOBJECT
;
3864 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
3865 wined3d_mutex_unlock();
3870 /*****************************************************************************
3871 * IDirectDrawSurface7::GetLOD
3873 * Returns the level of detail of a Direct3D texture
3876 * MaxLOD: Address to write the LOD to
3880 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3881 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3883 *****************************************************************************/
3884 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
3886 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3888 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
3891 return DDERR_INVALIDPARAMS
;
3893 wined3d_mutex_lock();
3894 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3896 wined3d_mutex_unlock();
3897 return DDERR_INVALIDOBJECT
;
3900 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
3901 wined3d_mutex_unlock();
3906 /*****************************************************************************
3907 * IDirectDrawSurface7::BltFast
3909 * Performs a fast Blit.
3912 * dstx: The x coordinate to blit to on the destination
3913 * dsty: The y coordinate to blit to on the destination
3914 * Source: The source surface
3915 * rsrc: The source rectangle
3916 * trans: Type of transfer. Some DDBLTFAST_* flags
3920 * For more details, see IWineD3DSurface::BltFast
3922 *****************************************************************************/
3923 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
3924 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
3926 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3927 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
3928 DWORD src_w
, src_h
, dst_w
, dst_h
;
3933 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3934 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
3936 dst_w
= This
->surface_desc
.dwWidth
;
3937 dst_h
= This
->surface_desc
.dwHeight
;
3939 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3944 src_w
= rsrc
->right
- rsrc
->left
;
3945 src_h
= rsrc
->bottom
- rsrc
->top
;
3949 src_w
= src
->surface_desc
.dwWidth
;
3950 src_h
= src
->surface_desc
.dwHeight
;
3953 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
3954 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
3956 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3957 return DDERR_INVALIDRECT
;
3960 SetRect(&dst_rect
, dstx
, dsty
, dstx
+ src_w
, dsty
+ src_h
);
3961 if (trans
& DDBLTFAST_SRCCOLORKEY
)
3962 flags
|= WINEDDBLT_KEYSRC
;
3963 if (trans
& DDBLTFAST_DESTCOLORKEY
)
3964 flags
|= WINEDDBLT_KEYDEST
;
3965 if (trans
& DDBLTFAST_WAIT
)
3966 flags
|= WINEDDBLT_WAIT
;
3967 if (trans
& DDBLTFAST_DONOTWAIT
)
3968 flags
|= WINEDDBLT_DONOTWAIT
;
3970 wined3d_mutex_lock();
3973 wined3d_mutex_unlock();
3974 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
3975 return DDERR_BLTFASTCANTCLIP
;
3978 if (src
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
3979 hr
= ddraw_surface_update_frontbuffer(src
, rsrc
, TRUE
);
3981 hr
= wined3d_surface_blt(This
->wined3d_surface
, &dst_rect
,
3982 src
->wined3d_surface
, rsrc
, flags
, NULL
, WINED3D_TEXF_POINT
);
3983 if (SUCCEEDED(hr
) && (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
3984 hr
= ddraw_surface_update_frontbuffer(This
, &dst_rect
, FALSE
);
3985 wined3d_mutex_unlock();
3989 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
3990 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
3995 static HRESULT WINAPI
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
3996 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
3998 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
3999 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4001 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4002 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4004 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4005 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4008 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4009 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4011 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4012 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4014 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4015 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4017 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4018 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4021 static HRESULT WINAPI
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4022 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4024 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4025 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4027 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4028 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4030 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4031 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4034 static HRESULT WINAPI
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4035 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4037 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4038 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4040 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4041 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4043 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4044 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4047 /*****************************************************************************
4048 * IDirectDrawSurface7::GetClipper
4050 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4054 * Clipper: Address to store the interface pointer at
4058 * DDERR_INVALIDPARAMS if Clipper is NULL
4059 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4061 *****************************************************************************/
4062 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4064 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4066 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4069 return DDERR_INVALIDPARAMS
;
4071 wined3d_mutex_lock();
4072 if (!surface
->clipper
)
4074 wined3d_mutex_unlock();
4075 return DDERR_NOCLIPPERATTACHED
;
4078 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4079 IDirectDrawClipper_AddRef(*Clipper
);
4080 wined3d_mutex_unlock();
4085 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4087 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4089 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4091 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4094 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4096 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4098 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4100 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4103 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4105 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4107 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4109 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4112 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4114 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4116 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4118 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4121 /*****************************************************************************
4122 * IDirectDrawSurface7::SetClipper
4124 * Sets a clipper for the surface
4127 * Clipper: IDirectDrawClipper interface of the clipper to set
4132 *****************************************************************************/
4133 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4134 IDirectDrawClipper
*iclipper
)
4136 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4137 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4138 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4141 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4143 wined3d_mutex_lock();
4144 if (clipper
== This
->clipper
)
4146 wined3d_mutex_unlock();
4150 This
->clipper
= clipper
;
4152 if (clipper
!= NULL
)
4153 IDirectDrawClipper_AddRef(iclipper
);
4155 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4157 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4161 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4166 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4167 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4171 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4172 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4176 wined3d_mutex_unlock();
4181 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4183 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4185 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4187 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4190 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4192 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4194 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4196 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4199 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4201 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4203 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4205 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4208 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4210 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4212 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4214 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4217 /*****************************************************************************
4218 * IDirectDrawSurface7::SetSurfaceDesc
4220 * Sets the surface description. It can override the pixel format, the surface
4222 * It's not really tested.
4225 * DDSD: Pointer to the new surface description to set
4230 * DDERR_INVALIDPARAMS if DDSD is NULL
4232 *****************************************************************************/
4233 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4235 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4237 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4238 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4239 enum wined3d_format_id format_id
;
4240 BOOL update_wined3d
= FALSE
;
4241 UINT pitch
, width
, height
;
4243 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4247 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4248 return DDERR_INVALIDPARAMS
;
4252 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4253 return DDERR_INVALIDPARAMS
;
4255 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
))
4257 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4258 return DDERR_INVALIDSURFACETYPE
;
4261 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4262 * for PIXELFORMAT to work */
4263 if (DDSD
->dwFlags
& ~allowed_flags
)
4265 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4266 return DDERR_INVALIDPARAMS
;
4268 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
))
4270 WARN("DDSD_LPSURFACE is not set, returning DDERR_INVALIDPARAMS\n");
4271 return DDERR_INVALIDPARAMS
;
4273 if (DDSD
->dwFlags
& DDSD_CAPS
)
4275 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4276 return DDERR_INVALIDCAPS
;
4278 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4280 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4282 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4283 return DDERR_INVALIDPARAMS
;
4285 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4287 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4288 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4289 return DDERR_INVALIDPARAMS
;
4291 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4293 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4294 update_wined3d
= TRUE
;
4296 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4298 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4299 update_wined3d
= TRUE
;
4301 pitch
= DDSD
->u1
.lPitch
;
4302 width
= DDSD
->dwWidth
;
4304 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4306 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4307 return DDERR_INVALIDPARAMS
;
4311 pitch
= This
->surface_desc
.u1
.lPitch
;
4312 width
= This
->surface_desc
.dwWidth
;
4315 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4317 if (!DDSD
->dwHeight
)
4319 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4320 return DDERR_INVALIDPARAMS
;
4322 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4324 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4325 update_wined3d
= TRUE
;
4327 height
= DDSD
->dwHeight
;
4331 height
= This
->surface_desc
.dwHeight
;
4334 wined3d_mutex_lock();
4335 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4337 enum wined3d_format_id current_format_id
;
4338 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4340 if (format_id
== WINED3DFMT_UNKNOWN
)
4342 ERR("Requested to set an unknown pixelformat\n");
4343 wined3d_mutex_unlock();
4344 return DDERR_INVALIDPARAMS
;
4346 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4347 if (format_id
!= current_format_id
)
4349 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4350 update_wined3d
= TRUE
;
4355 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4360 if (FAILED(hr
= wined3d_surface_update_desc(This
->wined3d_surface
, width
, height
,
4361 format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
4363 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4364 wined3d_mutex_unlock();
4368 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4369 This
->surface_desc
.dwWidth
= width
;
4370 if (DDSD
->dwFlags
& DDSD_PITCH
)
4371 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4372 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4373 This
->surface_desc
.dwHeight
= height
;
4374 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4375 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4378 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
4380 if (FAILED(hr
= wined3d_surface_set_mem(This
->wined3d_surface
, DDSD
->lpSurface
, pitch
)))
4382 /* No need for a trace here, wined3d does that for us */
4385 case WINED3DERR_INVALIDCALL
:
4386 wined3d_mutex_unlock();
4387 return DDERR_INVALIDPARAMS
;
4392 /* DDSD->lpSurface is set by Lock() */
4395 wined3d_mutex_unlock();
4400 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4401 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4403 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4405 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4407 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4408 surface_desc
, flags
);
4411 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4412 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4414 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4415 DDSURFACEDESC2 surface_desc2
;
4417 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4419 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4420 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4421 surface_desc
? &surface_desc2
: NULL
, flags
);
4424 /*****************************************************************************
4425 * IDirectDrawSurface7::GetPalette
4427 * Returns the IDirectDrawPalette interface of the palette currently assigned
4431 * Pal: Address to write the interface pointer to
4435 * DDERR_INVALIDPARAMS if Pal is NULL
4437 *****************************************************************************/
4438 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
4440 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4441 struct wined3d_palette
*wined3d_palette
;
4442 struct ddraw_palette
*palette_impl
;
4445 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4448 return DDERR_INVALIDPARAMS
;
4450 wined3d_mutex_lock();
4451 wined3d_palette
= wined3d_surface_get_palette(surface
->wined3d_surface
);
4452 if (wined3d_palette
)
4454 palette_impl
= wined3d_palette_get_parent(wined3d_palette
);
4455 *Pal
= &palette_impl
->IDirectDrawPalette_iface
;
4456 IDirectDrawPalette_AddRef(*Pal
);
4461 hr
= DDERR_NOPALETTEATTACHED
;
4464 wined3d_mutex_unlock();
4469 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4471 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4473 TRACE("iface %p, palette %p.\n", iface
, palette
);
4475 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4478 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4480 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4482 TRACE("iface %p, palette %p.\n", iface
, palette
);
4484 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4487 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4489 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4491 TRACE("iface %p, palette %p.\n", iface
, palette
);
4493 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4496 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4498 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4500 TRACE("iface %p, palette %p.\n", iface
, palette
);
4502 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4505 /*****************************************************************************
4508 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4509 * recursively in the surface tree
4511 *****************************************************************************/
4515 struct wined3d_color_key
*color_key
;
4519 static HRESULT WINAPI
SetColorKeyEnum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
4521 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
4522 struct SCKContext
*ctx
= context
;
4525 hr
= wined3d_surface_set_color_key(surface_impl
->wined3d_surface
, ctx
->Flags
, ctx
->color_key
);
4528 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
4532 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
4533 ddraw_surface7_Release(surface
);
4535 return DDENUMRET_OK
;
4538 /*****************************************************************************
4539 * IDirectDrawSurface7::SetColorKey
4541 * Sets the color keying options for the surface. Observations showed that
4542 * in case of complex surfaces the color key has to be assigned to all
4547 * CKey: The new color key
4551 * See IWineD3DSurface::SetColorKey for details
4553 *****************************************************************************/
4554 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
4556 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4557 DDCOLORKEY FixedCKey
;
4558 struct SCKContext ctx
= { DD_OK
, (struct wined3d_color_key
*)(CKey
? &FixedCKey
: NULL
), Flags
};
4560 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
4562 wined3d_mutex_lock();
4566 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4567 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
4568 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
4570 switch (Flags
& ~DDCKEY_COLORSPACE
)
4572 case DDCKEY_DESTBLT
:
4573 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
4574 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4577 case DDCKEY_DESTOVERLAY
:
4578 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
4579 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4582 case DDCKEY_SRCOVERLAY
:
4583 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
4584 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4588 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
4589 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4593 wined3d_mutex_unlock();
4594 return DDERR_INVALIDPARAMS
;
4599 switch (Flags
& ~DDCKEY_COLORSPACE
)
4601 case DDCKEY_DESTBLT
:
4602 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4605 case DDCKEY_DESTOVERLAY
:
4606 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4609 case DDCKEY_SRCOVERLAY
:
4610 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4614 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4618 wined3d_mutex_unlock();
4619 return DDERR_INVALIDPARAMS
;
4622 ctx
.ret
= wined3d_surface_set_color_key(This
->wined3d_surface
, Flags
, ctx
.color_key
);
4623 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
4624 wined3d_mutex_unlock();
4628 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
4629 default: return ctx
.ret
;
4633 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4635 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4637 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4639 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4642 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4644 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4646 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4648 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4651 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4653 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4655 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4657 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4660 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4662 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4664 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4666 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4669 /*****************************************************************************
4670 * IDirectDrawSurface7::SetPalette
4672 * Assigns a DirectDrawPalette object to the surface
4675 * Pal: Interface to the palette to set
4680 *****************************************************************************/
4681 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
4683 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4684 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(Pal
);
4685 IDirectDrawPalette
*oldPal
;
4686 struct ddraw_surface
*surf
;
4689 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4691 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
4692 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
4693 return DDERR_INVALIDPIXELFORMAT
;
4696 if (This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4698 return DDERR_NOTONMIPMAPSUBLEVEL
;
4701 /* Find the old palette */
4702 wined3d_mutex_lock();
4703 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
4704 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
4706 wined3d_mutex_unlock();
4709 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
4711 /* Set the new Palette */
4712 wined3d_surface_set_palette(This
->wined3d_surface
, palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
4713 /* AddRef the Palette */
4714 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
4716 /* Release the old palette */
4717 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
4719 /* Update the wined3d frontbuffer if this is the frontbuffer. */
4720 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
) && This
->ddraw
->wined3d_frontbuffer
)
4721 wined3d_surface_set_palette(This
->ddraw
->wined3d_frontbuffer
,
4722 palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
4724 /* If this is a front buffer, also update the back buffers
4725 * TODO: How do things work for palettized cube textures?
4727 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4729 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4730 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
4735 IDirectDrawSurface7
*attach
;
4737 hr
= ddraw_surface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &caps2
, &attach
);
4743 TRACE("Setting palette on %p\n", attach
);
4744 ddraw_surface7_SetPalette(attach
, Pal
);
4745 surf
= impl_from_IDirectDrawSurface7(attach
);
4746 ddraw_surface7_Release(attach
);
4750 wined3d_mutex_unlock();
4755 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4757 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4759 TRACE("iface %p, palette %p.\n", iface
, palette
);
4761 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4764 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4766 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4768 TRACE("iface %p, palette %p.\n", iface
, palette
);
4770 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4773 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4775 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4777 TRACE("iface %p, palette %p.\n", iface
, palette
);
4779 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4782 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4784 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4786 TRACE("iface %p, palette %p.\n", iface
, palette
);
4788 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4791 /**********************************************************
4792 * IDirectDrawGammaControl::GetGammaRamp
4794 * Returns the current gamma ramp for a surface
4798 * gamma_ramp: Address to write the ramp to
4802 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4804 **********************************************************/
4805 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4806 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4808 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4810 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4814 WARN("Invalid gamma_ramp passed.\n");
4815 return DDERR_INVALIDPARAMS
;
4818 wined3d_mutex_lock();
4819 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4821 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4822 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4826 ERR("Not implemented for non-primary surfaces.\n");
4828 wined3d_mutex_unlock();
4833 /**********************************************************
4834 * IDirectDrawGammaControl::SetGammaRamp
4836 * Sets the red, green and blue gamma ramps for
4839 * flags: Can be DDSGR_CALIBRATE to request calibration
4840 * gamma_ramp: Structure containing the new gamma ramp
4844 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4846 **********************************************************/
4847 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4848 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4850 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4852 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4856 WARN("Invalid gamma_ramp passed.\n");
4857 return DDERR_INVALIDPARAMS
;
4860 wined3d_mutex_lock();
4861 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4863 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4864 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4865 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4869 ERR("Not implemented for non-primary surfaces.\n");
4871 wined3d_mutex_unlock();
4876 /*****************************************************************************
4877 * IDirect3DTexture2::PaletteChanged
4879 * Informs the texture about a palette change
4882 * start: Start index of the change
4883 * count: The number of changed entries
4886 * D3D_OK, because it's a stub
4888 *****************************************************************************/
4889 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4891 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4896 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4898 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4900 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4902 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4905 /*****************************************************************************
4906 * IDirect3DTexture::Unload
4908 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4914 *****************************************************************************/
4915 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4917 WARN("iface %p. Not implemented.\n", iface
);
4919 return DDERR_UNSUPPORTED
;
4922 /*****************************************************************************
4923 * IDirect3DTexture2::GetHandle
4925 * Returns handle for the texture. At the moment, the interface
4926 * to the IWineD3DTexture is used.
4929 * device: Device this handle is assigned to
4930 * handle: Address to store the handle at.
4935 *****************************************************************************/
4936 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4937 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4939 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
4940 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
4942 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4944 wined3d_mutex_lock();
4946 if (!surface
->Handle
)
4948 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
4949 if (h
== DDRAW_INVALID_HANDLE
)
4951 ERR("Failed to allocate a texture handle.\n");
4952 wined3d_mutex_unlock();
4953 return DDERR_OUTOFMEMORY
;
4956 surface
->Handle
= h
+ 1;
4959 TRACE("Returning handle %08x.\n", surface
->Handle
);
4960 *handle
= surface
->Handle
;
4962 wined3d_mutex_unlock();
4967 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
4968 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
4970 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4971 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
4973 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4975 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
4976 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
4979 /*****************************************************************************
4980 * get_sub_mimaplevel
4982 * Helper function that returns the next mipmap level
4984 * tex_ptr: Surface of which to return the next level
4986 *****************************************************************************/
4987 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
4989 /* Now go down the mipmap chain to the next surface */
4990 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
4991 IDirectDrawSurface7
*next_level
;
4994 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
4995 if (FAILED(hr
)) return NULL
;
4997 ddraw_surface7_Release(next_level
);
4999 return impl_from_IDirectDrawSurface7(next_level
);
5002 /*****************************************************************************
5003 * IDirect3DTexture2::Load
5005 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5007 * This function isn't relayed to WineD3D because the whole interface is
5008 * implemented in DDraw only. For speed improvements a implementation which
5009 * takes OpenGL more into account could be placed into WineD3D.
5012 * src_texture: Address of the texture to load
5016 * D3DERR_TEXTURE_LOAD_FAILED.
5018 *****************************************************************************/
5019 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5021 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5022 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5025 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5027 if (src_surface
== dst_surface
)
5029 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5033 wined3d_mutex_lock();
5035 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5036 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5037 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5039 ERR("Trying to load surfaces with different mip-map counts.\n");
5044 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
5045 DDSURFACEDESC
*src_desc
, *dst_desc
;
5047 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
5048 src_surface
, dst_surface
, src_surface
->mipmap_level
);
5050 /* Suppress the ALLOCONLOAD flag */
5051 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5053 /* Get the palettes */
5054 wined3d_dst_pal
= wined3d_surface_get_palette(dst_surface
->wined3d_surface
);
5055 wined3d_src_pal
= wined3d_surface_get_palette(src_surface
->wined3d_surface
);
5057 if (wined3d_src_pal
)
5059 PALETTEENTRY palent
[256];
5061 if (!wined3d_dst_pal
)
5063 wined3d_mutex_unlock();
5064 return DDERR_NOPALETTEATTACHED
;
5066 wined3d_palette_get_entries(wined3d_src_pal
, 0, 0, 256, palent
);
5067 wined3d_palette_set_entries(wined3d_dst_pal
, 0, 0, 256, palent
);
5070 /* Copy one surface on the other */
5071 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5072 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5074 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5076 /* Should also check for same pixel format, u1.lPitch, ... */
5077 ERR("Error in surface sizes.\n");
5078 wined3d_mutex_unlock();
5079 return D3DERR_TEXTURE_LOAD_FAILED
;
5083 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5085 /* Copy the src blit color key if the source has one, don't erase
5086 * the destination's ckey if the source has none */
5087 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5089 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5090 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5093 /* Copy the main memory texture into the surface that corresponds
5094 * to the OpenGL texture object. */
5096 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_map_desc
, NULL
, 0);
5099 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5100 wined3d_mutex_unlock();
5101 return D3DERR_TEXTURE_LOAD_FAILED
;
5104 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_map_desc
, NULL
, 0);
5107 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5108 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5109 wined3d_mutex_unlock();
5110 return D3DERR_TEXTURE_LOAD_FAILED
;
5113 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5114 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5116 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5118 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5119 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
5122 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5123 src_surface
= get_sub_mimaplevel(src_surface
);
5127 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5128 dst_surface
= get_sub_mimaplevel(dst_surface
);
5132 if (!src_surface
|| !dst_surface
)
5134 if (src_surface
!= dst_surface
)
5135 ERR("Loading surface with different mipmap structure.\n");
5140 wined3d_mutex_unlock();
5145 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5147 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5148 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5150 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5152 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5153 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5156 /*****************************************************************************
5158 *****************************************************************************/
5160 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5163 ddraw_surface7_QueryInterface
,
5164 ddraw_surface7_AddRef
,
5165 ddraw_surface7_Release
,
5166 /* IDirectDrawSurface */
5167 ddraw_surface7_AddAttachedSurface
,
5168 ddraw_surface7_AddOverlayDirtyRect
,
5170 ddraw_surface7_BltBatch
,
5171 ddraw_surface7_BltFast
,
5172 ddraw_surface7_DeleteAttachedSurface
,
5173 ddraw_surface7_EnumAttachedSurfaces
,
5174 ddraw_surface7_EnumOverlayZOrders
,
5175 ddraw_surface7_Flip
,
5176 ddraw_surface7_GetAttachedSurface
,
5177 ddraw_surface7_GetBltStatus
,
5178 ddraw_surface7_GetCaps
,
5179 ddraw_surface7_GetClipper
,
5180 ddraw_surface7_GetColorKey
,
5181 ddraw_surface7_GetDC
,
5182 ddraw_surface7_GetFlipStatus
,
5183 ddraw_surface7_GetOverlayPosition
,
5184 ddraw_surface7_GetPalette
,
5185 ddraw_surface7_GetPixelFormat
,
5186 ddraw_surface7_GetSurfaceDesc
,
5187 ddraw_surface7_Initialize
,
5188 ddraw_surface7_IsLost
,
5189 ddraw_surface7_Lock
,
5190 ddraw_surface7_ReleaseDC
,
5191 ddraw_surface7_Restore
,
5192 ddraw_surface7_SetClipper
,
5193 ddraw_surface7_SetColorKey
,
5194 ddraw_surface7_SetOverlayPosition
,
5195 ddraw_surface7_SetPalette
,
5196 ddraw_surface7_Unlock
,
5197 ddraw_surface7_UpdateOverlay
,
5198 ddraw_surface7_UpdateOverlayDisplay
,
5199 ddraw_surface7_UpdateOverlayZOrder
,
5200 /* IDirectDrawSurface2 */
5201 ddraw_surface7_GetDDInterface
,
5202 ddraw_surface7_PageLock
,
5203 ddraw_surface7_PageUnlock
,
5204 /* IDirectDrawSurface3 */
5205 ddraw_surface7_SetSurfaceDesc
,
5206 /* IDirectDrawSurface4 */
5207 ddraw_surface7_SetPrivateData
,
5208 ddraw_surface7_GetPrivateData
,
5209 ddraw_surface7_FreePrivateData
,
5210 ddraw_surface7_GetUniquenessValue
,
5211 ddraw_surface7_ChangeUniquenessValue
,
5212 /* IDirectDrawSurface7 */
5213 ddraw_surface7_SetPriority
,
5214 ddraw_surface7_GetPriority
,
5215 ddraw_surface7_SetLOD
,
5216 ddraw_surface7_GetLOD
,
5219 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5222 ddraw_surface4_QueryInterface
,
5223 ddraw_surface4_AddRef
,
5224 ddraw_surface4_Release
,
5225 /* IDirectDrawSurface */
5226 ddraw_surface4_AddAttachedSurface
,
5227 ddraw_surface4_AddOverlayDirtyRect
,
5229 ddraw_surface4_BltBatch
,
5230 ddraw_surface4_BltFast
,
5231 ddraw_surface4_DeleteAttachedSurface
,
5232 ddraw_surface4_EnumAttachedSurfaces
,
5233 ddraw_surface4_EnumOverlayZOrders
,
5234 ddraw_surface4_Flip
,
5235 ddraw_surface4_GetAttachedSurface
,
5236 ddraw_surface4_GetBltStatus
,
5237 ddraw_surface4_GetCaps
,
5238 ddraw_surface4_GetClipper
,
5239 ddraw_surface4_GetColorKey
,
5240 ddraw_surface4_GetDC
,
5241 ddraw_surface4_GetFlipStatus
,
5242 ddraw_surface4_GetOverlayPosition
,
5243 ddraw_surface4_GetPalette
,
5244 ddraw_surface4_GetPixelFormat
,
5245 ddraw_surface4_GetSurfaceDesc
,
5246 ddraw_surface4_Initialize
,
5247 ddraw_surface4_IsLost
,
5248 ddraw_surface4_Lock
,
5249 ddraw_surface4_ReleaseDC
,
5250 ddraw_surface4_Restore
,
5251 ddraw_surface4_SetClipper
,
5252 ddraw_surface4_SetColorKey
,
5253 ddraw_surface4_SetOverlayPosition
,
5254 ddraw_surface4_SetPalette
,
5255 ddraw_surface4_Unlock
,
5256 ddraw_surface4_UpdateOverlay
,
5257 ddraw_surface4_UpdateOverlayDisplay
,
5258 ddraw_surface4_UpdateOverlayZOrder
,
5259 /* IDirectDrawSurface2 */
5260 ddraw_surface4_GetDDInterface
,
5261 ddraw_surface4_PageLock
,
5262 ddraw_surface4_PageUnlock
,
5263 /* IDirectDrawSurface3 */
5264 ddraw_surface4_SetSurfaceDesc
,
5265 /* IDirectDrawSurface4 */
5266 ddraw_surface4_SetPrivateData
,
5267 ddraw_surface4_GetPrivateData
,
5268 ddraw_surface4_FreePrivateData
,
5269 ddraw_surface4_GetUniquenessValue
,
5270 ddraw_surface4_ChangeUniquenessValue
,
5273 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5276 ddraw_surface3_QueryInterface
,
5277 ddraw_surface3_AddRef
,
5278 ddraw_surface3_Release
,
5279 /* IDirectDrawSurface */
5280 ddraw_surface3_AddAttachedSurface
,
5281 ddraw_surface3_AddOverlayDirtyRect
,
5283 ddraw_surface3_BltBatch
,
5284 ddraw_surface3_BltFast
,
5285 ddraw_surface3_DeleteAttachedSurface
,
5286 ddraw_surface3_EnumAttachedSurfaces
,
5287 ddraw_surface3_EnumOverlayZOrders
,
5288 ddraw_surface3_Flip
,
5289 ddraw_surface3_GetAttachedSurface
,
5290 ddraw_surface3_GetBltStatus
,
5291 ddraw_surface3_GetCaps
,
5292 ddraw_surface3_GetClipper
,
5293 ddraw_surface3_GetColorKey
,
5294 ddraw_surface3_GetDC
,
5295 ddraw_surface3_GetFlipStatus
,
5296 ddraw_surface3_GetOverlayPosition
,
5297 ddraw_surface3_GetPalette
,
5298 ddraw_surface3_GetPixelFormat
,
5299 ddraw_surface3_GetSurfaceDesc
,
5300 ddraw_surface3_Initialize
,
5301 ddraw_surface3_IsLost
,
5302 ddraw_surface3_Lock
,
5303 ddraw_surface3_ReleaseDC
,
5304 ddraw_surface3_Restore
,
5305 ddraw_surface3_SetClipper
,
5306 ddraw_surface3_SetColorKey
,
5307 ddraw_surface3_SetOverlayPosition
,
5308 ddraw_surface3_SetPalette
,
5309 ddraw_surface3_Unlock
,
5310 ddraw_surface3_UpdateOverlay
,
5311 ddraw_surface3_UpdateOverlayDisplay
,
5312 ddraw_surface3_UpdateOverlayZOrder
,
5313 /* IDirectDrawSurface2 */
5314 ddraw_surface3_GetDDInterface
,
5315 ddraw_surface3_PageLock
,
5316 ddraw_surface3_PageUnlock
,
5317 /* IDirectDrawSurface3 */
5318 ddraw_surface3_SetSurfaceDesc
,
5321 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5324 ddraw_surface2_QueryInterface
,
5325 ddraw_surface2_AddRef
,
5326 ddraw_surface2_Release
,
5327 /* IDirectDrawSurface */
5328 ddraw_surface2_AddAttachedSurface
,
5329 ddraw_surface2_AddOverlayDirtyRect
,
5331 ddraw_surface2_BltBatch
,
5332 ddraw_surface2_BltFast
,
5333 ddraw_surface2_DeleteAttachedSurface
,
5334 ddraw_surface2_EnumAttachedSurfaces
,
5335 ddraw_surface2_EnumOverlayZOrders
,
5336 ddraw_surface2_Flip
,
5337 ddraw_surface2_GetAttachedSurface
,
5338 ddraw_surface2_GetBltStatus
,
5339 ddraw_surface2_GetCaps
,
5340 ddraw_surface2_GetClipper
,
5341 ddraw_surface2_GetColorKey
,
5342 ddraw_surface2_GetDC
,
5343 ddraw_surface2_GetFlipStatus
,
5344 ddraw_surface2_GetOverlayPosition
,
5345 ddraw_surface2_GetPalette
,
5346 ddraw_surface2_GetPixelFormat
,
5347 ddraw_surface2_GetSurfaceDesc
,
5348 ddraw_surface2_Initialize
,
5349 ddraw_surface2_IsLost
,
5350 ddraw_surface2_Lock
,
5351 ddraw_surface2_ReleaseDC
,
5352 ddraw_surface2_Restore
,
5353 ddraw_surface2_SetClipper
,
5354 ddraw_surface2_SetColorKey
,
5355 ddraw_surface2_SetOverlayPosition
,
5356 ddraw_surface2_SetPalette
,
5357 ddraw_surface2_Unlock
,
5358 ddraw_surface2_UpdateOverlay
,
5359 ddraw_surface2_UpdateOverlayDisplay
,
5360 ddraw_surface2_UpdateOverlayZOrder
,
5361 /* IDirectDrawSurface2 */
5362 ddraw_surface2_GetDDInterface
,
5363 ddraw_surface2_PageLock
,
5364 ddraw_surface2_PageUnlock
,
5367 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5370 ddraw_surface1_QueryInterface
,
5371 ddraw_surface1_AddRef
,
5372 ddraw_surface1_Release
,
5373 /* IDirectDrawSurface */
5374 ddraw_surface1_AddAttachedSurface
,
5375 ddraw_surface1_AddOverlayDirtyRect
,
5377 ddraw_surface1_BltBatch
,
5378 ddraw_surface1_BltFast
,
5379 ddraw_surface1_DeleteAttachedSurface
,
5380 ddraw_surface1_EnumAttachedSurfaces
,
5381 ddraw_surface1_EnumOverlayZOrders
,
5382 ddraw_surface1_Flip
,
5383 ddraw_surface1_GetAttachedSurface
,
5384 ddraw_surface1_GetBltStatus
,
5385 ddraw_surface1_GetCaps
,
5386 ddraw_surface1_GetClipper
,
5387 ddraw_surface1_GetColorKey
,
5388 ddraw_surface1_GetDC
,
5389 ddraw_surface1_GetFlipStatus
,
5390 ddraw_surface1_GetOverlayPosition
,
5391 ddraw_surface1_GetPalette
,
5392 ddraw_surface1_GetPixelFormat
,
5393 ddraw_surface1_GetSurfaceDesc
,
5394 ddraw_surface1_Initialize
,
5395 ddraw_surface1_IsLost
,
5396 ddraw_surface1_Lock
,
5397 ddraw_surface1_ReleaseDC
,
5398 ddraw_surface1_Restore
,
5399 ddraw_surface1_SetClipper
,
5400 ddraw_surface1_SetColorKey
,
5401 ddraw_surface1_SetOverlayPosition
,
5402 ddraw_surface1_SetPalette
,
5403 ddraw_surface1_Unlock
,
5404 ddraw_surface1_UpdateOverlay
,
5405 ddraw_surface1_UpdateOverlayDisplay
,
5406 ddraw_surface1_UpdateOverlayZOrder
,
5409 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5411 ddraw_gamma_control_QueryInterface
,
5412 ddraw_gamma_control_AddRef
,
5413 ddraw_gamma_control_Release
,
5414 ddraw_gamma_control_GetGammaRamp
,
5415 ddraw_gamma_control_SetGammaRamp
,
5418 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5420 d3d_texture2_QueryInterface
,
5421 d3d_texture2_AddRef
,
5422 d3d_texture2_Release
,
5423 d3d_texture2_GetHandle
,
5424 d3d_texture2_PaletteChanged
,
5428 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5430 d3d_texture1_QueryInterface
,
5431 d3d_texture1_AddRef
,
5432 d3d_texture1_Release
,
5433 d3d_texture1_Initialize
,
5434 d3d_texture1_GetHandle
,
5435 d3d_texture1_PaletteChanged
,
5437 d3d_texture1_Unload
,
5440 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5441 * IDirectDrawSurface interface to ddraw methods. */
5442 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5444 if (!iface
) return NULL
;
5445 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5447 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5450 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5453 IDirectDrawSurface7_Release(iface
);
5455 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5458 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5460 if (!iface
) return NULL
;
5461 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5463 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5466 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5469 IDirectDrawSurface4_Release(iface
);
5471 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5474 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5476 if (!iface
) return NULL
;
5477 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5479 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5482 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5485 IDirectDrawSurface3_Release(iface
);
5487 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5490 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5492 if (!iface
) return NULL
;
5493 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5495 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5498 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5501 IDirectDrawSurface2_Release(iface
);
5503 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5506 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5508 if (!iface
) return NULL
;
5509 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5511 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5514 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5517 IDirectDrawSurface_Release(iface
);
5519 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5522 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5524 if (!iface
) return NULL
;
5525 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5526 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5529 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5531 if (!iface
) return NULL
;
5532 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5533 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5536 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5538 struct ddraw_surface
*surface
= parent
;
5540 TRACE("surface %p.\n", surface
);
5542 /* Check for attached surfaces and detach them. */
5543 if (surface
->first_attached
!= surface
)
5545 /* Well, this shouldn't happen: The surface being attached is
5546 * referenced in AddAttachedSurface(), so it shouldn't be released
5547 * until DeleteAttachedSurface() is called, because the refcount is
5548 * held. It looks like the application released it often enough to
5550 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5552 /* The refcount will drop to -1 here */
5553 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5554 ERR("DeleteAttachedSurface failed.\n");
5557 while (surface
->next_attached
)
5558 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5559 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5560 ERR("DeleteAttachedSurface failed.\n");
5562 /* Having a texture handle set implies that the device still exists. */
5563 if (surface
->Handle
)
5564 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5566 /* Reduce the ddraw surface count. */
5567 list_remove(&surface
->surface_list_entry
);
5569 if (surface
== surface
->ddraw
->primary
)
5570 surface
->ddraw
->primary
= NULL
;
5572 HeapFree(GetProcessHeap(), 0, surface
);
5575 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5577 ddraw_surface_wined3d_object_destroyed
,
5580 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5582 struct ddraw_texture
*texture
= parent
;
5584 TRACE("texture %p.\n", texture
);
5586 if (texture
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5587 ddraw_surface_cleanup(texture
->root
);
5588 HeapFree(GetProcessHeap(), 0, parent
);
5591 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5593 ddraw_texture_wined3d_object_destroyed
,
5596 HRESULT
ddraw_surface_create_texture(struct ddraw
*ddraw
, const DDSURFACEDESC2
*desc
,
5597 unsigned int version
, DWORD surface_flags
, struct ddraw_surface
**surface
)
5599 struct ddraw_surface
*root
, *mip
, **attach
;
5600 struct wined3d_resource_desc wined3d_desc
;
5601 struct wined3d_texture
*wined3d_texture
;
5602 struct wined3d_resource
*resource
;
5603 struct ddraw_texture
*texture
;
5604 UINT layers
, levels
, i
, j
;
5605 DDSURFACEDESC2
*mip_desc
;
5606 enum wined3d_pool pool
;
5609 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5610 return E_OUTOFMEMORY
;
5612 texture
->version
= version
;
5613 texture
->surface_desc
= *desc
;
5615 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5616 levels
= desc
->u2
.dwMipMapCount
;
5620 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5625 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5627 wined3d_desc
.usage
= WINED3DUSAGE_TEXTURE
;
5628 pool
= WINED3D_POOL_MANAGED
;
5630 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5632 /* ddraw does not enforce format support restrictions on system memory
5633 * textures. Don't set the texture flag, the texture can't be used for
5634 * texturing anyway. */
5635 wined3d_desc
.usage
= 0;
5636 pool
= WINED3D_POOL_SYSTEM_MEM
;
5640 wined3d_desc
.usage
= WINED3DUSAGE_DYNAMIC
;
5641 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5642 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
5643 pool
= WINED3D_POOL_DEFAULT
;
5646 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5647 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5649 WARN("Unsupported / unknown pixelformat.\n");
5650 return DDERR_INVALIDPIXELFORMAT
;
5653 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5654 wined3d_desc
.multisample_quality
= 0;
5655 wined3d_desc
.pool
= pool
;
5656 wined3d_desc
.width
= desc
->dwWidth
;
5657 wined3d_desc
.height
= desc
->dwHeight
;
5658 wined3d_desc
.depth
= 1;
5659 wined3d_desc
.size
= 0;
5661 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5663 wined3d_desc
.resource_type
= WINED3D_RTYPE_CUBE_TEXTURE
;
5664 hr
= wined3d_texture_create_cube(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
5665 surface_flags
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
);
5669 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
5670 hr
= wined3d_texture_create_2d(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
5671 surface_flags
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
);
5676 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
5679 case WINED3DERR_INVALIDCALL
:
5680 hr
= DDERR_INVALIDPARAMS
;
5684 FIXME("Unexpected wined3d error %#x.\n", hr
);
5687 HeapFree(GetProcessHeap(), 0, texture
);
5691 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
5692 root
= wined3d_resource_get_parent(resource
);
5693 root
->wined3d_texture
= wined3d_texture
;
5694 texture
->root
= root
;
5696 for (i
= 0; i
< layers
; ++i
)
5698 attach
= &root
->complex_array
[layers
- 1 - i
];
5700 for (j
= 0; j
< levels
; ++j
)
5702 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
5703 mip
= wined3d_resource_get_parent(resource
);
5708 mip_desc
= &mip
->surface_desc
;
5711 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
5713 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
5715 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5717 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5721 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
5722 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5724 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
5725 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
5727 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
5728 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
5730 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
5731 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
5733 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
5734 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
5736 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
5737 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
5744 attach
= &mip
->complex_array
[0];
5753 HRESULT
ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
5754 DDSURFACEDESC2
*desc
, DWORD flags
, UINT version
)
5756 enum wined3d_pool pool
= WINED3D_POOL_DEFAULT
;
5757 enum wined3d_format_id format
;
5761 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5762 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5763 && (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))))
5765 /* Tests show surfaces without memory flags get these flags added
5766 * right after creation. */
5767 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5770 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5771 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5773 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
))
5775 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5776 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5777 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5778 usage
|= WINED3DUSAGE_RENDERTARGET
;
5781 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
5783 usage
|= WINED3DUSAGE_OVERLAY
;
5786 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
5787 usage
|= WINED3DUSAGE_OWNDC
;
5789 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5791 pool
= WINED3D_POOL_SYSTEM_MEM
;
5793 else if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5795 pool
= WINED3D_POOL_MANAGED
;
5796 /* Managed textures have the system memory flag set. */
5797 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5799 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5801 /* Videomemory adds localvidmem. This is mutually exclusive with
5802 * systemmemory and texturemanage. */
5803 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5804 usage
|= WINED3DUSAGE_DYNAMIC
;
5807 format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5808 if (format
== WINED3DFMT_UNKNOWN
)
5810 WARN("Unsupported / unknown pixelformat.\n");
5811 return DDERR_INVALIDPIXELFORMAT
;
5814 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
5815 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
5816 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
5817 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
5818 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
5819 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
5820 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
5821 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
5822 surface
->iface_count
= 1;
5823 surface
->version
= version
;
5824 surface
->ddraw
= ddraw
;
5829 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
5831 else if (version
== 4)
5834 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
5839 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
5842 copy_to_surfacedesc2(&surface
->surface_desc
, desc
);
5844 surface
->first_attached
= surface
;
5846 if (FAILED(hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
, format
,
5847 usage
, pool
, WINED3D_MULTISAMPLE_NONE
, 0, flags
, surface
,
5848 &ddraw_surface_wined3d_parent_ops
, &surface
->wined3d_surface
)))
5850 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
5854 /* Anno 1602 stores the pitch right after surface creation, so make sure
5855 * it's there. TODO: Test other fourcc formats. */
5856 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
5857 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
5859 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
5860 if (format
== WINED3DFMT_DXT1
)
5862 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
) / 2;
5866 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
);
5871 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
5872 surface
->surface_desc
.u1
.lPitch
= wined3d_surface_get_pitch(surface
->wined3d_surface
);
5875 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
5877 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
5878 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
5880 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
5882 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTBLT
,
5883 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
5885 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
5887 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
5888 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
5890 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
5892 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCBLT
,
5893 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
5895 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5899 if (desc
->dwFlags
& DDSD_PITCH
)
5901 pitch
= desc
->u1
.lPitch
;
5902 surface
->surface_desc
.u1
.lPitch
= pitch
;
5905 if (FAILED(hr
= wined3d_surface_set_mem(surface
->wined3d_surface
, desc
->lpSurface
, pitch
)))
5907 ERR("Failed to set surface memory, hr %#x.\n", hr
);
5908 wined3d_surface_decref(surface
->wined3d_surface
);