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 (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
202 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
203 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
205 IDirect3DDevice7
*d3d
;
206 IDirect3DDeviceImpl
*device_impl
;
208 /* Call into IDirect3D7 for creation */
209 IDirect3D7_CreateDevice(&This
->ddraw
->IDirect3D7_iface
, riid
, &This
->IDirectDrawSurface7_iface
,
214 device_impl
= impl_from_IDirect3DDevice7(d3d
);
215 device_impl
->from_surface
= TRUE
;
216 *obj
= &device_impl
->IDirect3DDevice_iface
;
217 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
221 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
222 return E_NOINTERFACE
;
225 if (This
->version
!= 7)
227 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
229 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
230 *obj
= &This
->IDirect3DTexture2_iface
;
234 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
236 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
237 *obj
= &This
->IDirect3DTexture_iface
;
242 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
244 return E_NOINTERFACE
;
247 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
249 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
251 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
253 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
256 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
258 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
260 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
262 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
265 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
267 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
269 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
271 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
274 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
276 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
278 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
280 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
283 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
284 REFIID riid
, void **object
)
286 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
288 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
290 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
293 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
295 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
297 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
299 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
302 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
304 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
306 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
308 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
311 static void ddraw_surface_add_iface(struct ddraw_surface
*This
)
313 ULONG iface_count
= InterlockedIncrement(&This
->iface_count
);
314 TRACE("%p increasing iface count to %u.\n", This
, iface_count
);
316 if (iface_count
== 1)
318 wined3d_mutex_lock();
319 if (This
->wined3d_surface
)
320 wined3d_surface_incref(This
->wined3d_surface
);
321 if (This
->wined3d_texture
)
322 wined3d_texture_incref(This
->wined3d_texture
);
323 wined3d_mutex_unlock();
327 /*****************************************************************************
328 * IDirectDrawSurface7::AddRef
330 * A normal addref implementation
335 *****************************************************************************/
336 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
338 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
339 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
341 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
345 ddraw_surface_add_iface(This
);
351 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
353 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
354 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
356 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
360 ddraw_surface_add_iface(This
);
366 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
368 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
369 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
371 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
375 ddraw_surface_add_iface(This
);
381 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
383 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
384 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
386 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
390 ddraw_surface_add_iface(This
);
396 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
398 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
399 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
401 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
405 ddraw_surface_add_iface(This
);
411 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
413 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
414 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
416 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
420 ddraw_surface_add_iface(This
);
426 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
428 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
430 TRACE("iface %p.\n", iface
);
432 return IUnknown_AddRef(surface
->texture_outer
);
435 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
437 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
439 TRACE("iface %p.\n", iface
);
441 return IUnknown_AddRef(surface
->texture_outer
);
444 /*****************************************************************************
445 * ddraw_surface_destroy
447 * A helper function for IDirectDrawSurface7::Release
449 * Frees the surface, regardless of its refcount.
450 * See IDirectDrawSurface7::Release for more information
453 * This: Surface to free
455 *****************************************************************************/
456 static void ddraw_surface_destroy(struct ddraw_surface
*This
)
458 TRACE("surface %p.\n", This
);
460 /* Check the iface count and give a warning */
461 if(This
->iface_count
> 1)
463 /* This can happen when a complex surface is destroyed,
464 * because the 2nd surface was addref()ed when the app
465 * called GetAttachedSurface
467 WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n",
468 This
, This
->ref7
, This
->ref4
, This
->ref3
, This
->ref2
, This
->ref1
);
471 if (This
->wined3d_surface
)
472 wined3d_surface_decref(This
->wined3d_surface
);
475 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
477 struct ddraw_surface
*surf
;
478 IUnknown
*ifaceToRelease
;
481 TRACE("surface %p.\n", surface
);
483 /* The refcount test shows that the palette is detached when the surface
485 IDirectDrawSurface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, NULL
);
487 /* Loop through all complex attached surfaces and destroy them.
489 * Yet again, only the root can have more than one complexly attached
490 * surface, all the others have a total of one. */
491 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
493 if (!surface
->complex_array
[i
])
496 surf
= surface
->complex_array
[i
];
497 surface
->complex_array
[i
] = NULL
;
500 struct ddraw_surface
*destroy
= surf
;
501 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
502 ddraw_surface_destroy(destroy
); /* Destroy it */
506 ifaceToRelease
= surface
->ifaceToRelease
;
508 /* Destroy the root surface. */
509 ddraw_surface_destroy(surface
);
511 /* Reduce the ddraw refcount */
513 IUnknown_Release(ifaceToRelease
);
516 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
518 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
519 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
521 if (iface_count
== 0)
523 /* Complex attached surfaces are destroyed implicitly when the root is released */
524 wined3d_mutex_lock();
525 if(!This
->is_complex_root
)
527 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
528 wined3d_mutex_unlock();
531 if (This
->wined3d_texture
) /* If it's a texture, destroy the wined3d texture. */
532 wined3d_texture_decref(This
->wined3d_texture
);
534 ddraw_surface_cleanup(This
);
535 wined3d_mutex_unlock();
541 /*****************************************************************************
542 * IDirectDrawSurface7::Release
544 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
545 * surface is destroyed.
547 * Destroying the surface is a bit tricky. For the connection between
548 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
549 * It has a nice graph explaining the connection.
551 * What happens here is basically this:
552 * When a surface is destroyed, its WineD3DSurface is released,
553 * and the refcount of the DirectDraw interface is reduced by 1. If it has
554 * complex surfaces attached to it, then these surfaces are destroyed too,
555 * regardless of their refcount. If any surface being destroyed has another
556 * surface attached to it (with a "soft" attachment, not complex), then
557 * this surface is detached with DeleteAttachedSurface.
559 * When the surface is a texture, the WineD3DTexture is released.
560 * If the surface is the Direct3D render target, then the D3D
561 * capabilities of the WineD3DDevice are uninitialized, which causes the
562 * swapchain to be released.
564 * When a complex sublevel falls to ref zero, then this is ignored.
569 *****************************************************************************/
570 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
572 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
573 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
575 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
579 ddraw_surface_release_iface(This
);
585 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
587 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
588 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
590 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
594 ddraw_surface_release_iface(This
);
600 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
602 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
603 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
605 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
609 ddraw_surface_release_iface(This
);
615 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
617 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
618 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
620 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
624 ddraw_surface_release_iface(This
);
630 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
632 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
633 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
635 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
639 ddraw_surface_release_iface(This
);
645 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
647 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
648 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
650 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
654 ddraw_surface_release_iface(This
);
660 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
662 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
664 TRACE("iface %p.\n", iface
);
666 return IUnknown_Release(surface
->texture_outer
);
669 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
671 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
673 TRACE("iface %p.\n", iface
);
675 return IUnknown_Release(surface
->texture_outer
);
678 /*****************************************************************************
679 * IDirectDrawSurface7::GetAttachedSurface
681 * Returns an attached surface with the requested caps. Surface attachment
682 * and complex surfaces are not clearly described by the MSDN or sdk,
683 * so this method is tricky and likely to contain problems.
684 * This implementation searches the complex list first, then the
687 * The chains are searched from This down to the last surface in the chain,
688 * not from the first element in the chain. The first surface found is
689 * returned. The MSDN says that this method fails if more than one surface
690 * matches the caps, but it is not sure if that is right. The attachment
691 * structure may not even allow two matching surfaces.
693 * The found surface is AddRef-ed before it is returned.
696 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
697 * Surface: Address to store the found surface
701 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
702 * DDERR_NOTFOUND if no surface was found
704 *****************************************************************************/
705 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
706 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
708 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
709 struct ddraw_surface
*surf
;
713 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
715 wined3d_mutex_lock();
717 if(This
->version
< 7)
719 /* Earlier dx apps put garbage into these members, clear them */
720 our_caps
.dwCaps
= Caps
->dwCaps
;
721 our_caps
.dwCaps2
= 0;
722 our_caps
.dwCaps3
= 0;
723 our_caps
.dwCaps4
= 0;
730 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 */
732 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
734 surf
= This
->complex_array
[i
];
739 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
740 surf
->surface_desc
.ddsCaps
.dwCaps
,
741 surf
->surface_desc
.ddsCaps
.dwCaps2
,
742 surf
->surface_desc
.ddsCaps
.dwCaps3
,
743 surf
->surface_desc
.ddsCaps
.dwCaps4
);
746 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
747 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
749 /* MSDN: "This method fails if more than one surface is attached
750 * that matches the capabilities requested."
752 * Not sure how to test this.
755 TRACE("(%p): Returning surface %p\n", This
, surf
);
756 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
757 *Surface
= &surf
->IDirectDrawSurface7_iface
;
758 ddraw_surface7_AddRef(*Surface
);
759 wined3d_mutex_unlock();
765 /* Next, look at the attachment chain */
768 while( (surf
= surf
->next_attached
) )
772 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
773 surf
->surface_desc
.ddsCaps
.dwCaps
,
774 surf
->surface_desc
.ddsCaps
.dwCaps2
,
775 surf
->surface_desc
.ddsCaps
.dwCaps3
,
776 surf
->surface_desc
.ddsCaps
.dwCaps4
);
779 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
780 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
782 TRACE("(%p): Returning surface %p\n", This
, surf
);
783 *Surface
= &surf
->IDirectDrawSurface7_iface
;
784 ddraw_surface7_AddRef(*Surface
);
785 wined3d_mutex_unlock();
790 TRACE("(%p) Didn't find a valid surface\n", This
);
792 wined3d_mutex_unlock();
795 return DDERR_NOTFOUND
;
798 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
799 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
801 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
802 struct ddraw_surface
*attachment_impl
;
803 IDirectDrawSurface7
*attachment7
;
806 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
808 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
815 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
816 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
817 ddraw_surface4_AddRef(*attachment
);
818 ddraw_surface7_Release(attachment7
);
823 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
824 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
826 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
827 struct ddraw_surface
*attachment_impl
;
828 IDirectDrawSurface7
*attachment7
;
832 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
834 caps2
.dwCaps
= caps
->dwCaps
;
839 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
840 &caps2
, &attachment7
);
846 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
847 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
848 ddraw_surface3_AddRef(*attachment
);
849 ddraw_surface7_Release(attachment7
);
854 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
855 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
857 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
858 struct ddraw_surface
*attachment_impl
;
859 IDirectDrawSurface7
*attachment7
;
863 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
865 caps2
.dwCaps
= caps
->dwCaps
;
870 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
871 &caps2
, &attachment7
);
877 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
878 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
879 ddraw_surface2_AddRef(*attachment
);
880 ddraw_surface7_Release(attachment7
);
885 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
886 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
888 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
889 struct ddraw_surface
*attachment_impl
;
890 IDirectDrawSurface7
*attachment7
;
894 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
896 caps2
.dwCaps
= caps
->dwCaps
;
901 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
902 &caps2
, &attachment7
);
908 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
909 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
910 ddraw_surface1_AddRef(*attachment
);
911 ddraw_surface7_Release(attachment7
);
916 /*****************************************************************************
917 * IDirectDrawSurface7::Lock
919 * Locks the surface and returns a pointer to the surface's memory
922 * Rect: Rectangle to lock. If NULL, the whole surface is locked
923 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
924 * Flags: Locking flags, e.g Read only or write only
925 * h: An event handle that's not used and must be NULL
929 * DDERR_INVALIDPARAMS if DDSD is NULL
930 * For more details, see IWineD3DSurface::LockRect
932 *****************************************************************************/
933 static HRESULT
surface_lock(struct ddraw_surface
*This
,
934 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
936 struct wined3d_mapped_rect mapped_rect
;
939 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
940 This
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
942 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
943 wined3d_mutex_lock();
945 /* Should I check for the handle to be NULL?
947 * The DDLOCK flags and the D3DLOCK flags are equal
948 * for the supported values. The others are ignored by WineD3D
951 /* Windows zeroes this if the rect is invalid */
958 || (Rect
->left
> Rect
->right
)
959 || (Rect
->top
> Rect
->bottom
)
960 || (Rect
->right
> This
->surface_desc
.dwWidth
)
961 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
963 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
964 wined3d_mutex_unlock();
965 return DDERR_INVALIDPARAMS
;
969 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
970 hr
= ddraw_surface_update_frontbuffer(This
, Rect
, TRUE
);
972 hr
= wined3d_surface_map(This
->wined3d_surface
, &mapped_rect
, Rect
, Flags
);
975 wined3d_mutex_unlock();
978 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
979 * specific error. But since IWineD3DSurface::LockRect returns that error in this
980 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
981 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
982 * is much easier to do it in one place in ddraw
984 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
989 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
991 if (Flags
& DDLOCK_READONLY
)
992 memset(&This
->ddraw
->primary_lock
, 0, sizeof(This
->ddraw
->primary_lock
));
994 This
->ddraw
->primary_lock
= *Rect
;
996 SetRect(&This
->ddraw
->primary_lock
, 0, 0, This
->surface_desc
.dwWidth
, This
->surface_desc
.dwHeight
);
999 /* Override the memory area. The pitch should be set already. Strangely windows
1000 * does not set the LPSURFACE flag on locked surfaces !?!.
1001 * DDSD->dwFlags |= DDSD_LPSURFACE;
1003 This
->surface_desc
.lpSurface
= mapped_rect
.data
;
1004 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
1006 TRACE("locked surface returning description :\n");
1007 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1009 wined3d_mutex_unlock();
1014 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1015 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1017 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1019 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1020 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1022 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1023 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1024 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1026 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1027 return DDERR_INVALIDPARAMS
;
1029 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1032 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1033 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1035 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1037 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1038 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1040 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1041 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1042 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1044 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1045 return DDERR_INVALIDPARAMS
;
1047 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1050 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1051 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1053 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1054 DDSURFACEDESC2 surface_desc2
;
1057 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1058 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1060 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1061 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1062 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1064 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1065 return DDERR_INVALIDPARAMS
;
1068 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1069 surface_desc2
.dwFlags
= 0;
1070 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1071 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1072 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1076 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1077 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1079 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1080 DDSURFACEDESC2 surface_desc2
;
1083 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1084 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1086 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1087 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1088 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1090 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1091 return DDERR_INVALIDPARAMS
;
1094 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1095 surface_desc2
.dwFlags
= 0;
1096 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1097 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1098 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1102 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1103 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1105 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1106 DDSURFACEDESC2 surface_desc2
;
1108 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1109 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1111 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1112 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1113 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1115 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1116 return DDERR_INVALIDPARAMS
;
1119 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1120 surface_desc2
.dwFlags
= 0;
1121 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1122 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1123 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1127 /*****************************************************************************
1128 * IDirectDrawSurface7::Unlock
1130 * Unlocks an locked surface
1133 * Rect: Not used by this implementation
1137 * For more details, see IWineD3DSurface::UnlockRect
1139 *****************************************************************************/
1140 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1142 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1145 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1147 wined3d_mutex_lock();
1148 hr
= wined3d_surface_unmap(surface
->wined3d_surface
);
1151 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1152 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1153 surface
->surface_desc
.lpSurface
= NULL
;
1155 wined3d_mutex_unlock();
1160 static HRESULT WINAPI
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1162 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1164 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1166 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1169 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1171 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1173 TRACE("iface %p, data %p.\n", iface
, data
);
1175 /* data might not be the LPRECT of later versions, so drop it. */
1176 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1179 static HRESULT WINAPI
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1181 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1183 TRACE("iface %p, data %p.\n", iface
, data
);
1185 /* data might not be the LPRECT of later versions, so drop it. */
1186 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1189 static HRESULT WINAPI
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1191 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1193 TRACE("iface %p, data %p.\n", iface
, data
);
1195 /* data might not be the LPRECT of later versions, so drop it. */
1196 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1199 /*****************************************************************************
1200 * IDirectDrawSurface7::Flip
1202 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
1203 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
1204 * the flip target is passed to WineD3D, even if the app didn't specify one
1207 * DestOverride: Specifies the surface that will become the new front
1208 * buffer. If NULL, the current back buffer is used
1209 * Flags: some DirectDraw flags, see include/ddraw.h
1213 * DDERR_NOTFLIPPABLE if no flip target could be found
1214 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
1215 * For more details, see IWineD3DSurface::Flip
1217 *****************************************************************************/
1218 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
1220 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1221 struct ddraw_surface
*Override
= unsafe_impl_from_IDirectDrawSurface7(DestOverride
);
1222 IDirectDrawSurface7
*Override7
;
1225 TRACE("iface %p, dst %p, flags %#x.\n", iface
, DestOverride
, Flags
);
1227 /* Flip has to be called from a front buffer
1228 * What about overlay surfaces, AFAIK they can flip too? */
1229 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1230 return DDERR_INVALIDOBJECT
; /* Unchecked */
1232 wined3d_mutex_lock();
1234 /* WineD3D doesn't keep track of attached surface, so find the target */
1239 memset(&Caps
, 0, sizeof(Caps
));
1240 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
1241 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
1244 ERR("Can't find a flip target\n");
1245 wined3d_mutex_unlock();
1246 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1248 Override
= impl_from_IDirectDrawSurface7(Override7
);
1250 /* For the GetAttachedSurface */
1251 ddraw_surface7_Release(Override7
);
1254 hr
= wined3d_surface_flip(surface
->wined3d_surface
, Override
->wined3d_surface
, Flags
);
1255 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1256 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
1258 wined3d_mutex_unlock();
1263 static HRESULT WINAPI
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*dst
, DWORD flags
)
1265 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1266 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(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_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
1276 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1277 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(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 WINAPI
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*dst
, DWORD flags
)
1287 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1288 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1290 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1292 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1293 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1296 static HRESULT WINAPI
ddraw_surface1_Flip(IDirectDrawSurface
*iface
, IDirectDrawSurface
*dst
, DWORD flags
)
1298 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1299 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1301 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1303 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1304 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1307 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1308 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1309 const WINEDDBLTFX
*fx
, enum wined3d_texture_filter_type filter
)
1311 struct wined3d_surface
*wined3d_src_surface
= src_surface
? src_surface
->wined3d_surface
: NULL
;
1312 RECT src_rect
, dst_rect
;
1313 float scale_x
, scale_y
;
1314 const RECT
*clip_rect
;
1315 UINT clip_list_size
;
1320 if (!dst_surface
->clipper
)
1322 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1323 hr
= ddraw_surface_update_frontbuffer(src_surface
, src_rect_in
, TRUE
);
1325 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, dst_rect_in
,
1326 wined3d_src_surface
, src_rect_in
, flags
, fx
, filter
);
1327 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
1328 hr
= ddraw_surface_update_frontbuffer(dst_surface
, dst_rect_in
, FALSE
);
1337 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1338 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1342 dst_rect
= *dst_rect_in
;
1345 if (IsRectEmpty(&dst_rect
))
1346 return DDERR_INVALIDRECT
;
1354 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1355 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1359 src_rect
= *src_rect_in
;
1362 if (IsRectEmpty(&src_rect
))
1363 return DDERR_INVALIDRECT
;
1367 SetRect(&src_rect
, 0, 0, 0, 0);
1370 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1371 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1373 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1374 &dst_rect
, NULL
, &clip_list_size
)))
1376 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1380 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1382 WARN("Failed to allocate clip list.\n");
1383 return E_OUTOFMEMORY
;
1386 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1387 &dst_rect
, clip_list
, &clip_list_size
)))
1389 WARN("Failed to get clip list, hr %#x.\n", hr
);
1390 HeapFree(GetProcessHeap(), 0, clip_list
);
1394 clip_rect
= (RECT
*)clip_list
->Buffer
;
1395 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1397 RECT src_rect_clipped
= src_rect
;
1401 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1402 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1403 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1404 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1406 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1408 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1413 if (FAILED(hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, &clip_rect
[i
],
1414 wined3d_src_surface
, &src_rect_clipped
, flags
, fx
, filter
)))
1417 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1419 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1424 HeapFree(GetProcessHeap(), 0, clip_list
);
1428 /*****************************************************************************
1429 * IDirectDrawSurface7::Blt
1431 * Performs a blit on the surface
1434 * DestRect: Destination rectangle, can be NULL
1435 * SrcSurface: Source surface, can be NULL
1436 * SrcRect: Source rectangle, can be NULL
1438 * DDBltFx: Some extended blt parameters, connected to the flags
1442 * See IWineD3DSurface::Blt for more details
1444 *****************************************************************************/
1445 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1446 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1448 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1449 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1452 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1453 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1455 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1456 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1458 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1459 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1460 return DDERR_INVALIDPARAMS
;
1463 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1464 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1465 return DDERR_INVALIDPARAMS
;
1468 wined3d_mutex_lock();
1470 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1472 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1473 wined3d_mutex_unlock();
1474 return DDERR_INVALIDPARAMS
;
1477 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1478 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1479 * surfaces. So far no blitting operations using surfaces in the bltfx
1480 * struct are supported anyway. */
1481 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1482 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1484 wined3d_mutex_unlock();
1487 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1488 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1493 static HRESULT WINAPI
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1494 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1496 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1497 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1499 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1500 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1502 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1503 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1506 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1507 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1509 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1510 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1512 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1513 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1515 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1516 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1519 static HRESULT WINAPI
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1520 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1522 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1523 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1525 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1526 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1528 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1529 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1532 static HRESULT WINAPI
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1533 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1535 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1536 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1538 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1539 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1541 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1542 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1545 /*****************************************************************************
1546 * IDirectDrawSurface7::AddAttachedSurface
1548 * Attaches a surface to another surface. How the surface attachments work
1549 * is not totally understood yet, and this method is prone to problems.
1550 * The surface that is attached is AddRef-ed.
1552 * Tests with complex surfaces suggest that the surface attachments form a
1553 * tree, but no method to test this has been found yet.
1555 * The attachment list consists of a first surface (first_attached) and
1556 * for each surface a pointer to the next attached surface (next_attached).
1557 * For the first surface, and a surface that has no attachments
1558 * first_attached points to the surface itself. A surface that has
1559 * no successors in the chain has next_attached set to NULL.
1561 * Newly attached surfaces are attached right after the root surface.
1562 * If a surface is attached to a complex surface compound, it's attached to
1563 * the surface that the app requested, not the complex root. See
1564 * GetAttachedSurface for a description how surfaces are found.
1566 * This is how the current implementation works, and it was coded by looking
1567 * at the needs of the applications.
1569 * So far only Z-Buffer attachments are tested, and they are activated in
1570 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1571 * Back buffers should work in 2D mode, but they are not tested(They can be
1572 * attached in older iface versions). Rendering to the front buffer and
1573 * switching between that and double buffering is not yet implemented in
1574 * WineD3D, so for 3D it might have unexpected results.
1576 * ddraw_surface_attach_surface is the real thing,
1577 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1578 * performs additional checks. Version 7 of this interface is much more restrictive
1579 * than its predecessors.
1582 * Attach: Surface to attach to iface
1586 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1588 *****************************************************************************/
1589 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1591 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1594 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1596 wined3d_mutex_lock();
1598 /* Check if the surface is already attached somewhere */
1599 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1601 /* TODO: Test for the structure of the manual attachment. Is it a
1602 * chain or a list? What happens if one surface is attached to 2
1603 * different surfaces? */
1604 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1605 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1607 wined3d_mutex_unlock();
1608 return DDERR_SURFACEALREADYATTACHED
;
1611 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1612 Surf
->next_attached
= This
->next_attached
;
1613 Surf
->first_attached
= This
->first_attached
;
1614 This
->next_attached
= Surf
;
1616 /* Check if the WineD3D depth stencil needs updating */
1617 if(This
->ddraw
->d3ddevice
)
1619 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1622 wined3d_mutex_unlock();
1627 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1629 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1630 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1633 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1635 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1636 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1639 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1640 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1641 return DDERR_CANNOTATTACHSURFACE
;
1644 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1649 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1650 IUnknown_AddRef(attachment_impl
->attached_iface
);
1654 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1656 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
1657 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1660 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1662 hr
= ddraw_surface7_AddAttachedSurface(&This
->IDirectDrawSurface7_iface
,
1663 attachment_impl
? &attachment_impl
->IDirectDrawSurface7_iface
: NULL
);
1668 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1669 IUnknown_AddRef(attachment_impl
->attached_iface
);
1670 ddraw_surface7_Release(&attachment_impl
->IDirectDrawSurface7_iface
);
1673 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1675 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
1676 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1679 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1681 /* Tests suggest that
1682 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1683 * -> offscreen plain surfaces can be attached to primaries
1684 * -> primaries can be attached to offscreen plain surfaces
1685 * -> z buffers can be attached to primaries */
1686 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1687 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1689 /* Sizes have to match */
1690 if (attachment_impl
->surface_desc
.dwWidth
!= This
->surface_desc
.dwWidth
1691 || attachment_impl
->surface_desc
.dwHeight
!= This
->surface_desc
.dwHeight
)
1693 WARN("Surface sizes do not match.\n");
1694 return DDERR_CANNOTATTACHSURFACE
;
1698 else if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1699 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1705 WARN("Invalid attachment combination.\n");
1706 return DDERR_CANNOTATTACHSURFACE
;
1709 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1714 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1715 IUnknown_AddRef(attachment_impl
->attached_iface
);
1719 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1721 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
1722 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1725 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1727 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1728 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1733 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1734 IUnknown_AddRef(attachment_impl
->attached_iface
);
1735 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1739 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1741 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
1742 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1745 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1747 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1748 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1753 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1754 IUnknown_AddRef(attachment_impl
->attached_iface
);
1755 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1759 /*****************************************************************************
1760 * IDirectDrawSurface7::DeleteAttachedSurface
1762 * Removes a surface from the attachment chain. The surface's refcount
1763 * is decreased by one after it has been removed
1766 * Flags: Some flags, not used by this implementation
1767 * Attach: Surface to detach
1771 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1773 *****************************************************************************/
1774 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1775 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1777 struct ddraw_surface
*prev
= surface
;
1779 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1781 wined3d_mutex_lock();
1782 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1784 wined3d_mutex_unlock();
1785 return DDERR_CANNOTDETACHSURFACE
;
1788 if (attachment
->attached_iface
!= detach_iface
)
1790 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1791 wined3d_mutex_unlock();
1792 return DDERR_SURFACENOTATTACHED
;
1795 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1796 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1798 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1799 /* FIXME: we should probably also subtract from dwMipMapCount of this
1800 * and all parent surfaces */
1803 /* Find the predecessor of the detached surface */
1806 if (prev
->next_attached
== attachment
)
1808 prev
= prev
->next_attached
;
1811 /* There must be a surface, otherwise there's a bug */
1814 /* Unchain the surface */
1815 prev
->next_attached
= attachment
->next_attached
;
1816 attachment
->next_attached
= NULL
;
1817 attachment
->first_attached
= attachment
;
1819 /* Check if the wined3d depth stencil needs updating. */
1820 if (surface
->ddraw
->d3ddevice
)
1821 IDirect3DDeviceImpl_UpdateDepthStencil(surface
->ddraw
->d3ddevice
);
1822 wined3d_mutex_unlock();
1824 /* Set attached_iface to NULL before releasing it, the surface may go
1826 attachment
->attached_iface
= NULL
;
1827 IUnknown_Release(detach_iface
);
1832 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1833 DWORD flags
, IDirectDrawSurface7
*attachment
)
1835 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1836 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1838 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1840 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1843 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1844 DWORD flags
, IDirectDrawSurface4
*attachment
)
1846 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1847 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1849 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1851 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1854 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1855 DWORD flags
, IDirectDrawSurface3
*attachment
)
1857 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1858 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1860 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1862 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1865 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
1866 DWORD flags
, IDirectDrawSurface2
*attachment
)
1868 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1869 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1871 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1873 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1876 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
1877 DWORD flags
, IDirectDrawSurface
*attachment
)
1879 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1880 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1882 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1884 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1887 /*****************************************************************************
1888 * IDirectDrawSurface7::AddOverlayDirtyRect
1890 * "This method is not currently implemented"
1898 *****************************************************************************/
1899 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1901 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1903 return DDERR_UNSUPPORTED
; /* unchecked */
1906 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
1908 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1910 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1912 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1915 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1917 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1919 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1921 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1924 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
1926 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1928 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1930 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1933 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
1935 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1937 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1939 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1942 /*****************************************************************************
1943 * IDirectDrawSurface7::GetDC
1945 * Returns a GDI device context for the surface
1948 * hdc: Address of a HDC variable to store the dc to
1952 * DDERR_INVALIDPARAMS if hdc is NULL
1953 * For details, see IWineD3DSurface::GetDC
1955 *****************************************************************************/
1956 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1958 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1961 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1964 return DDERR_INVALIDPARAMS
;
1966 wined3d_mutex_lock();
1967 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1968 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
1970 hr
= wined3d_surface_getdc(surface
->wined3d_surface
, hdc
);
1971 wined3d_mutex_unlock();
1974 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1977 case WINED3DERR_INVALIDCALL
:
1978 if(hdc
) *hdc
= NULL
;
1979 return DDERR_INVALIDPARAMS
;
1985 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
1987 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1989 TRACE("iface %p, dc %p.\n", iface
, dc
);
1991 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1994 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1996 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1998 TRACE("iface %p, dc %p.\n", iface
, dc
);
2000 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2003 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2005 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2007 TRACE("iface %p, dc %p.\n", iface
, dc
);
2009 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2012 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2014 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2016 TRACE("iface %p, dc %p.\n", iface
, dc
);
2018 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2021 /*****************************************************************************
2022 * IDirectDrawSurface7::ReleaseDC
2024 * Releases the DC that was constructed with GetDC
2027 * hdc: HDC to release
2031 * For more details, see IWineD3DSurface::ReleaseDC
2033 *****************************************************************************/
2034 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2036 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2039 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2041 wined3d_mutex_lock();
2042 hr
= wined3d_surface_releasedc(surface
->wined3d_surface
, hdc
);
2043 if (SUCCEEDED(hr
) && (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
2044 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2045 wined3d_mutex_unlock();
2050 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2052 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2054 TRACE("iface %p, dc %p.\n", iface
, dc
);
2056 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2059 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2061 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2063 TRACE("iface %p, dc %p.\n", iface
, dc
);
2065 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2068 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2070 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2072 TRACE("iface %p, dc %p.\n", iface
, dc
);
2074 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2077 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2079 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2081 TRACE("iface %p, dc %p.\n", iface
, dc
);
2083 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2086 /*****************************************************************************
2087 * IDirectDrawSurface7::GetCaps
2089 * Returns the surface's caps
2092 * Caps: Address to write the caps to
2096 * DDERR_INVALIDPARAMS if Caps is NULL
2098 *****************************************************************************/
2099 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2101 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2103 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2106 return DDERR_INVALIDPARAMS
;
2108 *Caps
= surface
->surface_desc
.ddsCaps
;
2113 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2115 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2117 TRACE("iface %p, caps %p.\n", iface
, caps
);
2119 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2122 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2124 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2128 TRACE("iface %p, caps %p.\n", iface
, caps
);
2130 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2131 if (FAILED(hr
)) return hr
;
2133 caps
->dwCaps
= caps2
.dwCaps
;
2137 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2139 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2143 TRACE("iface %p, caps %p.\n", iface
, caps
);
2145 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2146 if (FAILED(hr
)) return hr
;
2148 caps
->dwCaps
= caps2
.dwCaps
;
2152 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2154 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2158 TRACE("iface %p, caps %p.\n", iface
, caps
);
2160 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2161 if (FAILED(hr
)) return hr
;
2163 caps
->dwCaps
= caps2
.dwCaps
;
2167 /*****************************************************************************
2168 * IDirectDrawSurface7::SetPriority
2170 * Sets a texture priority for managed textures.
2173 * Priority: The new priority
2177 * For more details, see IWineD3DSurface::SetPriority
2179 *****************************************************************************/
2180 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
2182 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2185 TRACE("iface %p, priority %u.\n", iface
, Priority
);
2187 wined3d_mutex_lock();
2188 hr
= wined3d_surface_set_priority(surface
->wined3d_surface
, Priority
);
2189 wined3d_mutex_unlock();
2194 /*****************************************************************************
2195 * IDirectDrawSurface7::GetPriority
2197 * Returns the surface's priority
2200 * Priority: Address of a variable to write the priority to
2204 * DDERR_INVALIDPARAMS if Priority == NULL
2205 * For more details, see IWineD3DSurface::GetPriority
2207 *****************************************************************************/
2208 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
2210 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2212 TRACE("iface %p, priority %p.\n", iface
, Priority
);
2216 return DDERR_INVALIDPARAMS
;
2219 wined3d_mutex_lock();
2220 *Priority
= wined3d_surface_get_priority(surface
->wined3d_surface
);
2221 wined3d_mutex_unlock();
2226 /*****************************************************************************
2227 * IDirectDrawSurface7::SetPrivateData
2229 * Stores some data in the surface that is intended for the application's
2233 * tag: GUID that identifies the data
2234 * Data: Pointer to the private data
2235 * Size: Size of the private data
2240 * For more details, see IWineD3DSurface::SetPrivateData
2242 *****************************************************************************/
2243 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2244 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
2246 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2247 struct wined3d_resource
*resource
;
2250 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2251 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
2253 wined3d_mutex_lock();
2254 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2255 hr
= wined3d_resource_set_private_data(resource
, tag
, Data
, Size
, Flags
);
2256 wined3d_mutex_unlock();
2260 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2265 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2266 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2268 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2270 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2271 iface
, debugstr_guid(tag
), data
, size
, flags
);
2273 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2276 /*****************************************************************************
2277 * IDirectDrawSurface7::GetPrivateData
2279 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2282 * tag: GUID of the data to return
2283 * Data: Address where to write the data to
2284 * Size: Size of the buffer at Data
2288 * DDERR_INVALIDPARAMS if Data is NULL
2289 * For more details, see IWineD3DSurface::GetPrivateData
2291 *****************************************************************************/
2292 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
2294 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2295 struct wined3d_resource
*resource
;
2298 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2299 iface
, debugstr_guid(tag
), Data
, Size
);
2302 return DDERR_INVALIDPARAMS
;
2304 wined3d_mutex_lock();
2305 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2306 hr
= wined3d_resource_get_private_data(resource
, tag
, Data
, Size
);
2307 wined3d_mutex_unlock();
2312 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2314 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2316 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2317 iface
, debugstr_guid(tag
), data
, size
);
2319 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2322 /*****************************************************************************
2323 * IDirectDrawSurface7::FreePrivateData
2325 * Frees private data stored in the surface
2328 * tag: Tag of the data to free
2332 * For more details, see IWineD3DSurface::FreePrivateData
2334 *****************************************************************************/
2335 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2337 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2338 struct wined3d_resource
*resource
;
2341 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2343 wined3d_mutex_lock();
2344 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2345 hr
= wined3d_resource_free_private_data(resource
, tag
);
2346 wined3d_mutex_unlock();
2351 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2353 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2355 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2357 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2360 /*****************************************************************************
2361 * IDirectDrawSurface7::PageLock
2363 * Prevents a sysmem surface from being paged out
2366 * Flags: Not used, must be 0(unchecked)
2369 * DD_OK, because it's a stub
2371 *****************************************************************************/
2372 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2374 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2376 /* This is Windows memory management related - we don't need this */
2380 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2382 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2384 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2386 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2389 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2391 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2393 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2395 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2398 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2400 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2402 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2404 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2407 /*****************************************************************************
2408 * IDirectDrawSurface7::PageUnlock
2410 * Allows a sysmem surface to be paged out
2413 * Flags: Not used, must be 0(unchecked)
2416 * DD_OK, because it's a stub
2418 *****************************************************************************/
2419 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2421 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2426 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2428 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2430 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2432 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2435 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2437 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2439 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2441 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2444 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2446 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2448 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2450 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2453 /*****************************************************************************
2454 * IDirectDrawSurface7::BltBatch
2456 * An unimplemented function
2464 *****************************************************************************/
2465 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2467 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2469 /* MSDN: "not currently implemented" */
2470 return DDERR_UNSUPPORTED
;
2473 static HRESULT WINAPI
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2475 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2477 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2479 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2482 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2484 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2486 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2488 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2491 static HRESULT WINAPI
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2493 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2495 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2497 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2500 static HRESULT WINAPI
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2502 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2504 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2506 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2509 /*****************************************************************************
2510 * IDirectDrawSurface7::EnumAttachedSurfaces
2512 * Enumerates all surfaces attached to this surface
2515 * context: Pointer to pass unmodified to the callback
2516 * cb: Callback function to call for each surface
2520 * DDERR_INVALIDPARAMS if cb is NULL
2522 *****************************************************************************/
2523 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2524 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2526 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2527 struct ddraw_surface
*surf
;
2528 DDSURFACEDESC2 desc
;
2531 /* Attached surfaces aren't handled in WineD3D */
2532 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2535 return DDERR_INVALIDPARAMS
;
2537 wined3d_mutex_lock();
2539 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2541 surf
= surface
->complex_array
[i
];
2544 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2545 desc
= surf
->surface_desc
;
2546 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2547 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2549 wined3d_mutex_unlock();
2554 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2556 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2557 desc
= surf
->surface_desc
;
2558 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2559 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2561 wined3d_mutex_unlock();
2566 TRACE(" end of enumeration.\n");
2568 wined3d_mutex_unlock();
2573 struct callback_info2
2575 LPDDENUMSURFACESCALLBACK2 callback
;
2579 struct callback_info
2581 LPDDENUMSURFACESCALLBACK callback
;
2585 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2587 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2588 const struct callback_info2
*info
= context
;
2590 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2591 ddraw_surface7_Release(surface
);
2593 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2596 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2598 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2599 const struct callback_info
*info
= context
;
2601 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2602 ddraw_surface7_Release(surface
);
2604 /* FIXME: Check surface_test.dwSize */
2605 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2606 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2609 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2610 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2612 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2613 struct callback_info2 info
;
2615 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2617 info
.callback
= callback
;
2618 info
.context
= context
;
2620 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2621 &info
, EnumCallback2
);
2624 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2625 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2627 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2628 struct callback_info info
;
2630 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2632 info
.callback
= callback
;
2633 info
.context
= context
;
2635 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2636 &info
, EnumCallback
);
2639 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2640 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2642 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2643 struct callback_info info
;
2645 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2647 info
.callback
= callback
;
2648 info
.context
= context
;
2650 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2651 &info
, EnumCallback
);
2654 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2655 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2657 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2658 struct callback_info info
;
2660 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2662 info
.callback
= callback
;
2663 info
.context
= context
;
2665 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2666 &info
, EnumCallback
);
2669 /*****************************************************************************
2670 * IDirectDrawSurface7::EnumOverlayZOrders
2672 * "Enumerates the overlay surfaces on the specified destination"
2675 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2676 * context: context to pass back to the callback
2677 * cb: callback function to call for each enumerated surface
2680 * DD_OK, because it's a stub
2682 *****************************************************************************/
2683 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2684 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2686 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2691 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2692 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2694 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2695 struct callback_info2 info
;
2697 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2699 info
.callback
= callback
;
2700 info
.context
= context
;
2702 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2703 flags
, &info
, EnumCallback2
);
2706 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2707 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2709 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2710 struct callback_info info
;
2712 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2714 info
.callback
= callback
;
2715 info
.context
= context
;
2717 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2718 flags
, &info
, EnumCallback
);
2721 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2722 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2724 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2725 struct callback_info info
;
2727 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2729 info
.callback
= callback
;
2730 info
.context
= context
;
2732 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2733 flags
, &info
, EnumCallback
);
2736 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2737 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2739 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2740 struct callback_info info
;
2742 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2744 info
.callback
= callback
;
2745 info
.context
= context
;
2747 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2748 flags
, &info
, EnumCallback
);
2751 /*****************************************************************************
2752 * IDirectDrawSurface7::GetBltStatus
2754 * Returns the blitting status
2757 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2760 * See IWineD3DSurface::Blt
2762 *****************************************************************************/
2763 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2765 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2768 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2770 wined3d_mutex_lock();
2771 hr
= wined3d_surface_get_blt_status(surface
->wined3d_surface
, Flags
);
2772 wined3d_mutex_unlock();
2775 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2780 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2782 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2784 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2786 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2789 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2791 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2793 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2795 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2798 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2800 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2802 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2804 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2807 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2809 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2811 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2813 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2816 /*****************************************************************************
2817 * IDirectDrawSurface7::GetColorKey
2819 * Returns the color key assigned to the surface
2823 * CKey: Address to store the key to
2827 * DDERR_INVALIDPARAMS if CKey is NULL
2829 *****************************************************************************/
2830 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2832 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
2834 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2837 return DDERR_INVALIDPARAMS
;
2839 wined3d_mutex_lock();
2843 case DDCKEY_DESTBLT
:
2844 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
2846 wined3d_mutex_unlock();
2847 return DDERR_NOCOLORKEY
;
2849 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
2852 case DDCKEY_DESTOVERLAY
:
2853 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
2855 wined3d_mutex_unlock();
2856 return DDERR_NOCOLORKEY
;
2858 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
2862 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
2864 wined3d_mutex_unlock();
2865 return DDERR_NOCOLORKEY
;
2867 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
2870 case DDCKEY_SRCOVERLAY
:
2871 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
2873 wined3d_mutex_unlock();
2874 return DDERR_NOCOLORKEY
;
2876 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
2880 wined3d_mutex_unlock();
2881 return DDERR_INVALIDPARAMS
;
2884 wined3d_mutex_unlock();
2889 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2891 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2893 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2895 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2898 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2900 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2902 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2904 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2907 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2909 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2911 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2913 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2916 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2918 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2920 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2922 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2925 /*****************************************************************************
2926 * IDirectDrawSurface7::GetFlipStatus
2928 * Returns the flipping status of the surface
2931 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2934 * See IWineD3DSurface::GetFlipStatus
2936 *****************************************************************************/
2937 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2939 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2942 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2944 wined3d_mutex_lock();
2945 hr
= wined3d_surface_get_flip_status(surface
->wined3d_surface
, Flags
);
2946 wined3d_mutex_unlock();
2950 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2955 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2957 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2959 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2961 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2964 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2966 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2968 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2970 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2973 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2975 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2977 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2979 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2982 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2984 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2986 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2988 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2991 /*****************************************************************************
2992 * IDirectDrawSurface7::GetOverlayPosition
2994 * Returns the display coordinates of a visible and active overlay surface
3001 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3002 *****************************************************************************/
3003 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
3005 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3008 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
3010 wined3d_mutex_lock();
3011 hr
= wined3d_surface_get_overlay_position(surface
->wined3d_surface
, X
, Y
);
3012 wined3d_mutex_unlock();
3017 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3019 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3021 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3023 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3026 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3028 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3030 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3032 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3035 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3037 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3039 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3041 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3044 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3046 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3048 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3050 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3053 /*****************************************************************************
3054 * IDirectDrawSurface7::GetPixelFormat
3056 * Returns the pixel format of the Surface
3059 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3060 * format should be written
3064 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3066 *****************************************************************************/
3067 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3069 /* What is DDERR_INVALIDSURFACETYPE for here? */
3070 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3072 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3075 return DDERR_INVALIDPARAMS
;
3077 wined3d_mutex_lock();
3078 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3079 wined3d_mutex_unlock();
3084 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3086 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3088 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3090 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3093 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3095 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3097 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3099 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3102 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3104 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3106 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3108 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3111 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3113 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3115 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3117 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3120 /*****************************************************************************
3121 * IDirectDrawSurface7::GetSurfaceDesc
3123 * Returns the description of this surface
3126 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3131 * DDERR_INVALIDPARAMS if DDSD is NULL
3133 *****************************************************************************/
3134 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3136 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3138 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3141 return DDERR_INVALIDPARAMS
;
3143 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3145 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3146 return DDERR_INVALIDPARAMS
;
3149 wined3d_mutex_lock();
3150 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3151 TRACE("Returning surface desc:\n");
3152 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3153 wined3d_mutex_unlock();
3158 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3160 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3162 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3164 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3167 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3169 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3171 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3173 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3175 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3177 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3178 return DDERR_INVALIDPARAMS
;
3181 wined3d_mutex_lock();
3182 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3183 TRACE("Returning surface desc:\n");
3184 if (TRACE_ON(ddraw
))
3186 /* DDRAW_dump_surface_desc handles the smaller size */
3187 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3189 wined3d_mutex_unlock();
3194 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3196 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3198 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3200 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3203 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3205 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3207 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3209 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3212 /*****************************************************************************
3213 * IDirectDrawSurface7::Initialize
3215 * Initializes the surface. This is a no-op in Wine
3218 * DD: Pointer to an DirectDraw interface
3219 * DDSD: Surface description for initialization
3222 * DDERR_ALREADYINITIALIZED
3224 *****************************************************************************/
3225 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3226 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3228 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3230 return DDERR_ALREADYINITIALIZED
;
3233 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3234 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3236 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3238 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3240 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3241 ddraw
, surface_desc
);
3244 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3245 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3247 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3248 DDSURFACEDESC2 surface_desc2
;
3250 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3252 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3253 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3254 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3257 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3258 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3261 DDSURFACEDESC2 surface_desc2
;
3263 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3265 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3266 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3267 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3270 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3271 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3273 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3274 DDSURFACEDESC2 surface_desc2
;
3276 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3278 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3279 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3280 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3283 /*****************************************************************************
3284 * IDirect3DTexture1::Initialize
3286 * The sdk says it's not implemented
3294 *****************************************************************************/
3295 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3296 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3298 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3300 return DDERR_UNSUPPORTED
; /* Unchecked */
3303 /*****************************************************************************
3304 * IDirectDrawSurface7::IsLost
3306 * Checks if the surface is lost
3309 * DD_OK, if the surface is usable
3310 * DDERR_ISLOST if the surface is lost
3311 * See IWineD3DSurface::IsLost for more details
3313 *****************************************************************************/
3314 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3316 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3319 TRACE("iface %p.\n", iface
);
3321 wined3d_mutex_lock();
3322 hr
= wined3d_surface_is_lost(surface
->wined3d_surface
);
3323 wined3d_mutex_unlock();
3327 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3328 * WineD3D uses the same error for surfaces
3330 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3335 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3337 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3339 TRACE("iface %p.\n", iface
);
3341 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3344 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3346 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3348 TRACE("iface %p.\n", iface
);
3350 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3353 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3355 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3357 TRACE("iface %p.\n", iface
);
3359 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3362 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3364 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3366 TRACE("iface %p.\n", iface
);
3368 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3371 /*****************************************************************************
3372 * IDirectDrawSurface7::Restore
3374 * Restores a lost surface. This makes the surface usable again, but
3375 * doesn't reload its old contents
3379 * See IWineD3DSurface::Restore for more details
3381 *****************************************************************************/
3382 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3384 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3387 TRACE("iface %p.\n", iface
);
3389 wined3d_mutex_lock();
3390 hr
= wined3d_surface_restore(surface
->wined3d_surface
);
3391 wined3d_mutex_unlock();
3396 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3398 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3400 TRACE("iface %p.\n", iface
);
3402 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3405 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3407 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3409 TRACE("iface %p.\n", iface
);
3411 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3414 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3416 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3418 TRACE("iface %p.\n", iface
);
3420 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3423 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3425 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3427 TRACE("iface %p.\n", iface
);
3429 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3432 /*****************************************************************************
3433 * IDirectDrawSurface7::SetOverlayPosition
3435 * Changes the display coordinates of an overlay surface
3442 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3443 *****************************************************************************/
3444 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3446 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3449 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3451 wined3d_mutex_lock();
3452 hr
= wined3d_surface_set_overlay_position(surface
->wined3d_surface
, X
, Y
);
3453 wined3d_mutex_unlock();
3458 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3460 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3462 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3464 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3467 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3469 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3471 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3473 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3476 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3478 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3480 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3482 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3485 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3487 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3489 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3491 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3494 /*****************************************************************************
3495 * IDirectDrawSurface7::UpdateOverlay
3497 * Modifies the attributes of an overlay surface.
3500 * SrcRect: The section of the source being used for the overlay
3501 * DstSurface: Address of the surface that is overlaid
3502 * DstRect: Place of the overlay
3503 * Flags: some DDOVER_* flags
3506 * DDERR_UNSUPPORTED, because we don't support overlays
3508 *****************************************************************************/
3509 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3510 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3512 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3513 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3516 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3517 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3519 wined3d_mutex_lock();
3520 hr
= wined3d_surface_update_overlay(src_impl
->wined3d_surface
, SrcRect
,
3521 dst_impl
? dst_impl
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3522 wined3d_mutex_unlock();
3525 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3526 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3527 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3533 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3534 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3536 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3537 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3539 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3540 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3542 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3543 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3546 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3547 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3549 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3550 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3552 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3553 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3555 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3556 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3559 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3560 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3562 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3563 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3565 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3566 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3568 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3569 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3572 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3573 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3575 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3576 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3578 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3579 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3581 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3582 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3585 /*****************************************************************************
3586 * IDirectDrawSurface7::UpdateOverlayDisplay
3588 * The DX7 sdk says that it's not implemented
3593 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3595 *****************************************************************************/
3596 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3598 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3600 return DDERR_UNSUPPORTED
;
3603 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3605 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3607 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3609 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3612 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3614 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3616 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3618 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3621 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3623 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3625 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3627 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3630 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3632 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3634 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3636 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3639 /*****************************************************************************
3640 * IDirectDrawSurface7::UpdateOverlayZOrder
3642 * Sets an overlay's Z order
3645 * Flags: DDOVERZ_* flags
3646 * DDSRef: Defines the relative position in the overlay chain
3649 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3651 *****************************************************************************/
3652 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3653 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3655 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3656 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3659 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3661 wined3d_mutex_lock();
3662 hr
= wined3d_surface_update_overlay_z_order(surface
->wined3d_surface
,
3663 Flags
, reference_impl
? reference_impl
->wined3d_surface
: NULL
);
3664 wined3d_mutex_unlock();
3669 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3670 DWORD flags
, IDirectDrawSurface4
*reference
)
3672 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3673 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(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_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3682 DWORD flags
, IDirectDrawSurface3
*reference
)
3684 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3685 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(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 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3694 DWORD flags
, IDirectDrawSurface2
*reference
)
3696 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3697 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3699 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3701 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3702 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3705 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3706 DWORD flags
, IDirectDrawSurface
*reference
)
3708 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3709 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3711 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3713 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3714 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3717 /*****************************************************************************
3718 * IDirectDrawSurface7::GetDDInterface
3720 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3721 * surface belongs to
3724 * DD: Address to write the interface pointer to
3728 * DDERR_INVALIDPARAMS if DD is NULL
3730 *****************************************************************************/
3731 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3733 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3735 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3738 return DDERR_INVALIDPARAMS
;
3740 switch(This
->version
)
3743 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3747 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3751 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3755 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3759 IUnknown_AddRef((IUnknown
*)*DD
);
3764 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3766 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3768 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3770 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3773 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3775 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3777 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3779 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3782 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3784 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3786 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3788 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3791 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3792 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3794 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3795 volatile struct ddraw_surface
* vThis
= This
;
3797 TRACE("iface %p.\n", iface
);
3799 wined3d_mutex_lock();
3800 /* A uniqueness value of 0 is apparently special.
3801 * This needs to be checked.
3802 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3805 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
3806 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
3808 if (old_uniqueness_value
== 0) break;
3809 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
3811 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
3812 old_uniqueness_value
,
3813 new_uniqueness_value
)
3814 == old_uniqueness_value
)
3818 wined3d_mutex_unlock();
3823 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3825 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3827 TRACE("iface %p.\n", iface
);
3829 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
3832 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3834 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3836 TRACE("iface %p, value %p.\n", iface
, pValue
);
3838 wined3d_mutex_lock();
3839 *pValue
= surface
->uniqueness_value
;
3840 wined3d_mutex_unlock();
3845 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3847 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3849 TRACE("iface %p, value %p.\n", iface
, pValue
);
3851 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
3854 /*****************************************************************************
3855 * IDirectDrawSurface7::SetLOD
3857 * Sets the level of detail of a texture
3860 * MaxLOD: LOD to set
3864 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3866 *****************************************************************************/
3867 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
3869 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3872 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
3874 wined3d_mutex_lock();
3875 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3877 wined3d_mutex_unlock();
3878 return DDERR_INVALIDOBJECT
;
3881 if (!surface
->wined3d_texture
)
3883 ERR("The ddraw surface has no wined3d texture.\n");
3884 wined3d_mutex_unlock();
3885 return DDERR_INVALIDOBJECT
;
3888 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
3889 wined3d_mutex_unlock();
3894 /*****************************************************************************
3895 * IDirectDrawSurface7::GetLOD
3897 * Returns the level of detail of a Direct3D texture
3900 * MaxLOD: Address to write the LOD to
3904 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3905 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3907 *****************************************************************************/
3908 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
3910 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3912 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
3915 return DDERR_INVALIDPARAMS
;
3917 wined3d_mutex_lock();
3918 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3920 wined3d_mutex_unlock();
3921 return DDERR_INVALIDOBJECT
;
3924 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
3925 wined3d_mutex_unlock();
3930 /*****************************************************************************
3931 * IDirectDrawSurface7::BltFast
3933 * Performs a fast Blit.
3936 * dstx: The x coordinate to blit to on the destination
3937 * dsty: The y coordinate to blit to on the destination
3938 * Source: The source surface
3939 * rsrc: The source rectangle
3940 * trans: Type of transfer. Some DDBLTFAST_* flags
3944 * For more details, see IWineD3DSurface::BltFast
3946 *****************************************************************************/
3947 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
3948 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
3950 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3951 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
3952 DWORD src_w
, src_h
, dst_w
, dst_h
;
3957 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3958 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
3960 dst_w
= This
->surface_desc
.dwWidth
;
3961 dst_h
= This
->surface_desc
.dwHeight
;
3963 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3968 src_w
= rsrc
->right
- rsrc
->left
;
3969 src_h
= rsrc
->bottom
- rsrc
->top
;
3973 src_w
= src
->surface_desc
.dwWidth
;
3974 src_h
= src
->surface_desc
.dwHeight
;
3977 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
3978 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
3980 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3981 return DDERR_INVALIDRECT
;
3984 SetRect(&dst_rect
, dstx
, dsty
, dstx
+ src_w
, dsty
+ src_h
);
3985 if (trans
& DDBLTFAST_SRCCOLORKEY
)
3986 flags
|= WINEDDBLT_KEYSRC
;
3987 if (trans
& DDBLTFAST_DESTCOLORKEY
)
3988 flags
|= WINEDDBLT_KEYDEST
;
3989 if (trans
& DDBLTFAST_WAIT
)
3990 flags
|= WINEDDBLT_WAIT
;
3991 if (trans
& DDBLTFAST_DONOTWAIT
)
3992 flags
|= WINEDDBLT_DONOTWAIT
;
3994 wined3d_mutex_lock();
3997 wined3d_mutex_unlock();
3998 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
3999 return DDERR_BLTFASTCANTCLIP
;
4002 if (src
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4003 hr
= ddraw_surface_update_frontbuffer(src
, rsrc
, TRUE
);
4005 hr
= wined3d_surface_blt(This
->wined3d_surface
, &dst_rect
,
4006 src
->wined3d_surface
, rsrc
, flags
, NULL
, WINED3D_TEXF_POINT
);
4007 if (SUCCEEDED(hr
) && (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
4008 hr
= ddraw_surface_update_frontbuffer(This
, &dst_rect
, FALSE
);
4009 wined3d_mutex_unlock();
4013 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4014 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
4019 static HRESULT WINAPI
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4020 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4022 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4023 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4025 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4026 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4028 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4029 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4032 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4033 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4035 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4036 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4038 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4039 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4041 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4042 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4045 static HRESULT WINAPI
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4046 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4048 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4049 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4051 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4052 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4054 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4055 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4058 static HRESULT WINAPI
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4059 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4061 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4062 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4064 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4065 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4067 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4068 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4071 /*****************************************************************************
4072 * IDirectDrawSurface7::GetClipper
4074 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4078 * Clipper: Address to store the interface pointer at
4082 * DDERR_INVALIDPARAMS if Clipper is NULL
4083 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4085 *****************************************************************************/
4086 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4088 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4090 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4093 return DDERR_INVALIDPARAMS
;
4095 wined3d_mutex_lock();
4096 if (!surface
->clipper
)
4098 wined3d_mutex_unlock();
4099 return DDERR_NOCLIPPERATTACHED
;
4102 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4103 IDirectDrawClipper_AddRef(*Clipper
);
4104 wined3d_mutex_unlock();
4109 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4111 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4113 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4115 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4118 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4120 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4122 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4124 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4127 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4129 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4131 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4133 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4136 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4138 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4140 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4142 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4145 /*****************************************************************************
4146 * IDirectDrawSurface7::SetClipper
4148 * Sets a clipper for the surface
4151 * Clipper: IDirectDrawClipper interface of the clipper to set
4156 *****************************************************************************/
4157 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4158 IDirectDrawClipper
*iclipper
)
4160 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4161 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4162 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4165 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4167 wined3d_mutex_lock();
4168 if (clipper
== This
->clipper
)
4170 wined3d_mutex_unlock();
4174 This
->clipper
= clipper
;
4176 if (clipper
!= NULL
)
4177 IDirectDrawClipper_AddRef(iclipper
);
4179 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4181 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4185 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4190 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4191 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4195 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4196 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4200 wined3d_mutex_unlock();
4205 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4207 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4209 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4211 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4214 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4216 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4218 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4220 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4223 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4225 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4227 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4229 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4232 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4234 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4236 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4238 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4241 /*****************************************************************************
4242 * IDirectDrawSurface7::SetSurfaceDesc
4244 * Sets the surface description. It can override the pixel format, the surface
4246 * It's not really tested.
4249 * DDSD: Pointer to the new surface description to set
4254 * DDERR_INVALIDPARAMS if DDSD is NULL
4256 *****************************************************************************/
4257 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4259 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4261 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4262 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4263 enum wined3d_format_id format_id
;
4264 BOOL update_wined3d
= FALSE
;
4267 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4271 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4272 return DDERR_INVALIDPARAMS
;
4276 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4277 return DDERR_INVALIDPARAMS
;
4279 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
))
4281 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4282 return DDERR_INVALIDSURFACETYPE
;
4285 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4286 * for PIXELFORMAT to work */
4287 if (DDSD
->dwFlags
& ~allowed_flags
)
4289 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4290 return DDERR_INVALIDPARAMS
;
4292 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
))
4294 WARN("DDSD_LPSURFACE is not set, returning DDERR_INVALIDPARAMS\n");
4295 return DDERR_INVALIDPARAMS
;
4297 if (DDSD
->dwFlags
& DDSD_CAPS
)
4299 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4300 return DDERR_INVALIDCAPS
;
4302 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4304 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4306 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4307 return DDERR_INVALIDPARAMS
;
4309 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4311 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4312 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4313 return DDERR_INVALIDPARAMS
;
4315 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4317 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4318 update_wined3d
= TRUE
;
4320 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4322 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4323 update_wined3d
= TRUE
;
4325 width
= DDSD
->dwWidth
;
4327 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4329 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4330 return DDERR_INVALIDPARAMS
;
4334 width
= This
->surface_desc
.dwWidth
;
4337 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4339 if (!DDSD
->dwHeight
)
4341 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4342 return DDERR_INVALIDPARAMS
;
4344 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4346 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4347 update_wined3d
= TRUE
;
4349 height
= DDSD
->dwHeight
;
4353 height
= This
->surface_desc
.dwHeight
;
4356 wined3d_mutex_lock();
4357 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4359 enum wined3d_format_id current_format_id
;
4360 format_id
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
4362 if (format_id
== WINED3DFMT_UNKNOWN
)
4364 ERR("Requested to set an unknown pixelformat\n");
4365 wined3d_mutex_unlock();
4366 return DDERR_INVALIDPARAMS
;
4368 current_format_id
= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4369 if (format_id
!= current_format_id
)
4371 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4372 update_wined3d
= TRUE
;
4377 format_id
= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4382 if (FAILED(hr
= wined3d_surface_update_desc(This
->wined3d_surface
, width
, height
,
4383 format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
4385 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4386 wined3d_mutex_unlock();
4390 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4391 This
->surface_desc
.dwWidth
= width
;
4392 if (DDSD
->dwFlags
& DDSD_PITCH
)
4393 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4394 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4395 This
->surface_desc
.dwHeight
= height
;
4396 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4397 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4400 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
4402 hr
= wined3d_surface_set_mem(This
->wined3d_surface
, DDSD
->lpSurface
);
4405 /* No need for a trace here, wined3d does that for us */
4408 case WINED3DERR_INVALIDCALL
:
4409 wined3d_mutex_unlock();
4410 return DDERR_INVALIDPARAMS
;
4415 /* DDSD->lpSurface is set by Lock() */
4418 wined3d_mutex_unlock();
4423 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4424 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4426 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4428 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4430 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4431 surface_desc
, flags
);
4434 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4435 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4437 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4438 DDSURFACEDESC2 surface_desc2
;
4440 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4442 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4443 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4444 surface_desc
? &surface_desc2
: NULL
, flags
);
4447 /*****************************************************************************
4448 * IDirectDrawSurface7::GetPalette
4450 * Returns the IDirectDrawPalette interface of the palette currently assigned
4454 * Pal: Address to write the interface pointer to
4458 * DDERR_INVALIDPARAMS if Pal is NULL
4460 *****************************************************************************/
4461 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
4463 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4464 struct wined3d_palette
*wined3d_palette
;
4467 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4470 return DDERR_INVALIDPARAMS
;
4472 wined3d_mutex_lock();
4473 wined3d_palette
= wined3d_surface_get_palette(surface
->wined3d_surface
);
4474 if (wined3d_palette
)
4476 *Pal
= wined3d_palette_get_parent(wined3d_palette
);
4477 IDirectDrawPalette_AddRef(*Pal
);
4482 hr
= DDERR_NOPALETTEATTACHED
;
4485 wined3d_mutex_unlock();
4490 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4492 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4494 TRACE("iface %p, palette %p.\n", iface
, palette
);
4496 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4499 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4501 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4503 TRACE("iface %p, palette %p.\n", iface
, palette
);
4505 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4508 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4510 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4512 TRACE("iface %p, palette %p.\n", iface
, palette
);
4514 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4517 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4519 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4521 TRACE("iface %p, palette %p.\n", iface
, palette
);
4523 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4526 /*****************************************************************************
4529 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4530 * recursively in the surface tree
4532 *****************************************************************************/
4536 struct wined3d_color_key
*color_key
;
4540 static HRESULT WINAPI
SetColorKeyEnum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
4542 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
4543 struct SCKContext
*ctx
= context
;
4546 hr
= wined3d_surface_set_color_key(surface_impl
->wined3d_surface
, ctx
->Flags
, ctx
->color_key
);
4549 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
4553 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
4554 ddraw_surface7_Release(surface
);
4556 return DDENUMRET_OK
;
4559 /*****************************************************************************
4560 * IDirectDrawSurface7::SetColorKey
4562 * Sets the color keying options for the surface. Observations showed that
4563 * in case of complex surfaces the color key has to be assigned to all
4568 * CKey: The new color key
4572 * See IWineD3DSurface::SetColorKey for details
4574 *****************************************************************************/
4575 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
4577 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4578 DDCOLORKEY FixedCKey
;
4579 struct SCKContext ctx
= { DD_OK
, (struct wined3d_color_key
*)(CKey
? &FixedCKey
: NULL
), Flags
};
4581 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
4583 wined3d_mutex_lock();
4587 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4588 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
4589 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
4591 switch (Flags
& ~DDCKEY_COLORSPACE
)
4593 case DDCKEY_DESTBLT
:
4594 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
4595 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4598 case DDCKEY_DESTOVERLAY
:
4599 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
4600 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4603 case DDCKEY_SRCOVERLAY
:
4604 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
4605 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4609 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
4610 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4614 wined3d_mutex_unlock();
4615 return DDERR_INVALIDPARAMS
;
4620 switch (Flags
& ~DDCKEY_COLORSPACE
)
4622 case DDCKEY_DESTBLT
:
4623 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4626 case DDCKEY_DESTOVERLAY
:
4627 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4630 case DDCKEY_SRCOVERLAY
:
4631 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4635 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4639 wined3d_mutex_unlock();
4640 return DDERR_INVALIDPARAMS
;
4643 ctx
.ret
= wined3d_surface_set_color_key(This
->wined3d_surface
, Flags
, ctx
.color_key
);
4644 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
4645 wined3d_mutex_unlock();
4649 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
4650 default: return ctx
.ret
;
4654 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4656 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4658 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4660 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4663 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4665 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4667 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4669 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4672 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4674 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4676 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4678 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4681 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4683 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4685 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4687 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4690 /*****************************************************************************
4691 * IDirectDrawSurface7::SetPalette
4693 * Assigns a DirectDrawPalette object to the surface
4696 * Pal: Interface to the palette to set
4701 *****************************************************************************/
4702 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
4704 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4705 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(Pal
);
4706 IDirectDrawPalette
*oldPal
;
4707 struct ddraw_surface
*surf
;
4710 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4712 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
4713 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
4714 return DDERR_INVALIDPIXELFORMAT
;
4717 if (This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4719 return DDERR_NOTONMIPMAPSUBLEVEL
;
4722 /* Find the old palette */
4723 wined3d_mutex_lock();
4724 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
4725 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
4727 wined3d_mutex_unlock();
4730 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
4732 /* Set the new Palette */
4733 wined3d_surface_set_palette(This
->wined3d_surface
, palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
4734 /* AddRef the Palette */
4735 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
4737 /* Release the old palette */
4738 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
4740 /* Update the wined3d frontbuffer if this is the frontbuffer. */
4741 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
) && This
->ddraw
->wined3d_frontbuffer
)
4743 hr
= wined3d_surface_set_palette(This
->ddraw
->wined3d_frontbuffer
, palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
4745 ERR("Failed to set frontbuffer palette, hr %#x.\n", hr
);
4748 /* If this is a front buffer, also update the back buffers
4749 * TODO: How do things work for palettized cube textures?
4751 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4753 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4754 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
4759 IDirectDrawSurface7
*attach
;
4761 hr
= ddraw_surface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &caps2
, &attach
);
4767 TRACE("Setting palette on %p\n", attach
);
4768 ddraw_surface7_SetPalette(attach
, Pal
);
4769 surf
= impl_from_IDirectDrawSurface7(attach
);
4770 ddraw_surface7_Release(attach
);
4774 wined3d_mutex_unlock();
4779 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4781 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4783 TRACE("iface %p, palette %p.\n", iface
, palette
);
4785 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4788 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4790 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4792 TRACE("iface %p, palette %p.\n", iface
, palette
);
4794 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4797 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4799 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4801 TRACE("iface %p, palette %p.\n", iface
, palette
);
4803 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4806 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4808 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4810 TRACE("iface %p, palette %p.\n", iface
, palette
);
4812 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4815 /**********************************************************
4816 * IDirectDrawGammaControl::GetGammaRamp
4818 * Returns the current gamma ramp for a surface
4822 * gamma_ramp: Address to write the ramp to
4826 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4828 **********************************************************/
4829 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4830 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4832 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4834 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4838 WARN("Invalid gamma_ramp passed.\n");
4839 return DDERR_INVALIDPARAMS
;
4842 wined3d_mutex_lock();
4843 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4845 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4846 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4850 ERR("Not implemented for non-primary surfaces.\n");
4852 wined3d_mutex_unlock();
4857 /**********************************************************
4858 * IDirectDrawGammaControl::SetGammaRamp
4860 * Sets the red, green and blue gamma ramps for
4863 * flags: Can be DDSGR_CALIBRATE to request calibration
4864 * gamma_ramp: Structure containing the new gamma ramp
4868 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4870 **********************************************************/
4871 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4872 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4874 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4876 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4880 WARN("Invalid gamma_ramp passed.\n");
4881 return DDERR_INVALIDPARAMS
;
4884 wined3d_mutex_lock();
4885 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4887 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4888 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4889 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4893 ERR("Not implemented for non-primary surfaces.\n");
4895 wined3d_mutex_unlock();
4900 /*****************************************************************************
4901 * IDirect3DTexture2::PaletteChanged
4903 * Informs the texture about a palette change
4906 * start: Start index of the change
4907 * count: The number of changed entries
4910 * D3D_OK, because it's a stub
4912 *****************************************************************************/
4913 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4915 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4920 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4922 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4924 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4926 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4929 /*****************************************************************************
4930 * IDirect3DTexture::Unload
4932 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4938 *****************************************************************************/
4939 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4941 WARN("iface %p. Not implemented.\n", iface
);
4943 return DDERR_UNSUPPORTED
;
4946 /*****************************************************************************
4947 * IDirect3DTexture2::GetHandle
4949 * Returns handle for the texture. At the moment, the interface
4950 * to the IWineD3DTexture is used.
4953 * device: Device this handle is assigned to
4954 * handle: Address to store the handle at.
4959 *****************************************************************************/
4960 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4961 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4963 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
4964 IDirect3DDeviceImpl
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
4966 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4968 wined3d_mutex_lock();
4970 if (!surface
->Handle
)
4972 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
4973 if (h
== DDRAW_INVALID_HANDLE
)
4975 ERR("Failed to allocate a texture handle.\n");
4976 wined3d_mutex_unlock();
4977 return DDERR_OUTOFMEMORY
;
4980 surface
->Handle
= h
+ 1;
4983 TRACE("Returning handle %08x.\n", surface
->Handle
);
4984 *handle
= surface
->Handle
;
4986 wined3d_mutex_unlock();
4991 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
4992 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
4994 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4995 IDirect3DDeviceImpl
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
4997 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4999 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5000 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5003 /*****************************************************************************
5004 * get_sub_mimaplevel
5006 * Helper function that returns the next mipmap level
5008 * tex_ptr: Surface of which to return the next level
5010 *****************************************************************************/
5011 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5013 /* Now go down the mipmap chain to the next surface */
5014 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
5015 IDirectDrawSurface7
*next_level
;
5018 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5019 if (FAILED(hr
)) return NULL
;
5021 ddraw_surface7_Release(next_level
);
5023 return impl_from_IDirectDrawSurface7(next_level
);
5026 /*****************************************************************************
5027 * IDirect3DTexture2::Load
5029 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5031 * This function isn't relayed to WineD3D because the whole interface is
5032 * implemented in DDraw only. For speed improvements a implementation which
5033 * takes OpenGL more into account could be placed into WineD3D.
5036 * src_texture: Address of the texture to load
5040 * D3DERR_TEXTURE_LOAD_FAILED.
5042 *****************************************************************************/
5043 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5045 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5046 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5049 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5051 if (src_surface
== dst_surface
)
5053 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5057 wined3d_mutex_lock();
5059 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5060 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5061 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5063 ERR("Trying to load surfaces with different mip-map counts.\n");
5068 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
5069 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
5070 DDSURFACEDESC
*src_desc
, *dst_desc
;
5072 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
5073 src_surface
, dst_surface
, src_surface
->mipmap_level
);
5075 /* Suppress the ALLOCONLOAD flag */
5076 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5078 /* Get the palettes */
5079 wined3d_dst_pal
= wined3d_surface_get_palette(dst_surface
->wined3d_surface
);
5080 if (wined3d_dst_pal
)
5081 dst_pal
= wined3d_palette_get_parent(wined3d_dst_pal
);
5083 wined3d_src_pal
= wined3d_surface_get_palette(src_surface
->wined3d_surface
);
5084 if (wined3d_src_pal
)
5085 src_pal
= wined3d_palette_get_parent(wined3d_src_pal
);
5089 PALETTEENTRY palent
[256];
5093 wined3d_mutex_unlock();
5094 return DDERR_NOPALETTEATTACHED
;
5096 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
5097 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
5100 /* Copy one surface on the other */
5101 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5102 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5104 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5106 /* Should also check for same pixel format, u1.lPitch, ... */
5107 ERR("Error in surface sizes.\n");
5108 wined3d_mutex_unlock();
5109 return D3DERR_TEXTURE_LOAD_FAILED
;
5113 struct wined3d_mapped_rect src_rect
, dst_rect
;
5115 /* Copy the src blit color key if the source has one, don't erase
5116 * the destination's ckey if the source has none */
5117 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5119 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5120 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5123 /* Copy the main memory texture into the surface that corresponds
5124 * to the OpenGL texture object. */
5126 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_rect
, NULL
, 0);
5129 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5130 wined3d_mutex_unlock();
5131 return D3DERR_TEXTURE_LOAD_FAILED
;
5134 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_rect
, NULL
, 0);
5137 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5138 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5139 wined3d_mutex_unlock();
5140 return D3DERR_TEXTURE_LOAD_FAILED
;
5143 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5144 memcpy(dst_rect
.data
, src_rect
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5146 memcpy(dst_rect
.data
, src_rect
.data
, src_rect
.row_pitch
* src_desc
->dwHeight
);
5148 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5149 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
5152 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5153 src_surface
= get_sub_mimaplevel(src_surface
);
5157 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5158 dst_surface
= get_sub_mimaplevel(dst_surface
);
5162 if (!src_surface
|| !dst_surface
)
5164 if (src_surface
!= dst_surface
)
5165 ERR("Loading surface with different mipmap structure.\n");
5170 wined3d_mutex_unlock();
5175 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5177 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5178 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5180 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5182 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5183 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5186 /*****************************************************************************
5188 *****************************************************************************/
5190 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5193 ddraw_surface7_QueryInterface
,
5194 ddraw_surface7_AddRef
,
5195 ddraw_surface7_Release
,
5196 /* IDirectDrawSurface */
5197 ddraw_surface7_AddAttachedSurface
,
5198 ddraw_surface7_AddOverlayDirtyRect
,
5200 ddraw_surface7_BltBatch
,
5201 ddraw_surface7_BltFast
,
5202 ddraw_surface7_DeleteAttachedSurface
,
5203 ddraw_surface7_EnumAttachedSurfaces
,
5204 ddraw_surface7_EnumOverlayZOrders
,
5205 ddraw_surface7_Flip
,
5206 ddraw_surface7_GetAttachedSurface
,
5207 ddraw_surface7_GetBltStatus
,
5208 ddraw_surface7_GetCaps
,
5209 ddraw_surface7_GetClipper
,
5210 ddraw_surface7_GetColorKey
,
5211 ddraw_surface7_GetDC
,
5212 ddraw_surface7_GetFlipStatus
,
5213 ddraw_surface7_GetOverlayPosition
,
5214 ddraw_surface7_GetPalette
,
5215 ddraw_surface7_GetPixelFormat
,
5216 ddraw_surface7_GetSurfaceDesc
,
5217 ddraw_surface7_Initialize
,
5218 ddraw_surface7_IsLost
,
5219 ddraw_surface7_Lock
,
5220 ddraw_surface7_ReleaseDC
,
5221 ddraw_surface7_Restore
,
5222 ddraw_surface7_SetClipper
,
5223 ddraw_surface7_SetColorKey
,
5224 ddraw_surface7_SetOverlayPosition
,
5225 ddraw_surface7_SetPalette
,
5226 ddraw_surface7_Unlock
,
5227 ddraw_surface7_UpdateOverlay
,
5228 ddraw_surface7_UpdateOverlayDisplay
,
5229 ddraw_surface7_UpdateOverlayZOrder
,
5230 /* IDirectDrawSurface2 */
5231 ddraw_surface7_GetDDInterface
,
5232 ddraw_surface7_PageLock
,
5233 ddraw_surface7_PageUnlock
,
5234 /* IDirectDrawSurface3 */
5235 ddraw_surface7_SetSurfaceDesc
,
5236 /* IDirectDrawSurface4 */
5237 ddraw_surface7_SetPrivateData
,
5238 ddraw_surface7_GetPrivateData
,
5239 ddraw_surface7_FreePrivateData
,
5240 ddraw_surface7_GetUniquenessValue
,
5241 ddraw_surface7_ChangeUniquenessValue
,
5242 /* IDirectDrawSurface7 */
5243 ddraw_surface7_SetPriority
,
5244 ddraw_surface7_GetPriority
,
5245 ddraw_surface7_SetLOD
,
5246 ddraw_surface7_GetLOD
,
5249 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5252 ddraw_surface4_QueryInterface
,
5253 ddraw_surface4_AddRef
,
5254 ddraw_surface4_Release
,
5255 /* IDirectDrawSurface */
5256 ddraw_surface4_AddAttachedSurface
,
5257 ddraw_surface4_AddOverlayDirtyRect
,
5259 ddraw_surface4_BltBatch
,
5260 ddraw_surface4_BltFast
,
5261 ddraw_surface4_DeleteAttachedSurface
,
5262 ddraw_surface4_EnumAttachedSurfaces
,
5263 ddraw_surface4_EnumOverlayZOrders
,
5264 ddraw_surface4_Flip
,
5265 ddraw_surface4_GetAttachedSurface
,
5266 ddraw_surface4_GetBltStatus
,
5267 ddraw_surface4_GetCaps
,
5268 ddraw_surface4_GetClipper
,
5269 ddraw_surface4_GetColorKey
,
5270 ddraw_surface4_GetDC
,
5271 ddraw_surface4_GetFlipStatus
,
5272 ddraw_surface4_GetOverlayPosition
,
5273 ddraw_surface4_GetPalette
,
5274 ddraw_surface4_GetPixelFormat
,
5275 ddraw_surface4_GetSurfaceDesc
,
5276 ddraw_surface4_Initialize
,
5277 ddraw_surface4_IsLost
,
5278 ddraw_surface4_Lock
,
5279 ddraw_surface4_ReleaseDC
,
5280 ddraw_surface4_Restore
,
5281 ddraw_surface4_SetClipper
,
5282 ddraw_surface4_SetColorKey
,
5283 ddraw_surface4_SetOverlayPosition
,
5284 ddraw_surface4_SetPalette
,
5285 ddraw_surface4_Unlock
,
5286 ddraw_surface4_UpdateOverlay
,
5287 ddraw_surface4_UpdateOverlayDisplay
,
5288 ddraw_surface4_UpdateOverlayZOrder
,
5289 /* IDirectDrawSurface2 */
5290 ddraw_surface4_GetDDInterface
,
5291 ddraw_surface4_PageLock
,
5292 ddraw_surface4_PageUnlock
,
5293 /* IDirectDrawSurface3 */
5294 ddraw_surface4_SetSurfaceDesc
,
5295 /* IDirectDrawSurface4 */
5296 ddraw_surface4_SetPrivateData
,
5297 ddraw_surface4_GetPrivateData
,
5298 ddraw_surface4_FreePrivateData
,
5299 ddraw_surface4_GetUniquenessValue
,
5300 ddraw_surface4_ChangeUniquenessValue
,
5303 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5306 ddraw_surface3_QueryInterface
,
5307 ddraw_surface3_AddRef
,
5308 ddraw_surface3_Release
,
5309 /* IDirectDrawSurface */
5310 ddraw_surface3_AddAttachedSurface
,
5311 ddraw_surface3_AddOverlayDirtyRect
,
5313 ddraw_surface3_BltBatch
,
5314 ddraw_surface3_BltFast
,
5315 ddraw_surface3_DeleteAttachedSurface
,
5316 ddraw_surface3_EnumAttachedSurfaces
,
5317 ddraw_surface3_EnumOverlayZOrders
,
5318 ddraw_surface3_Flip
,
5319 ddraw_surface3_GetAttachedSurface
,
5320 ddraw_surface3_GetBltStatus
,
5321 ddraw_surface3_GetCaps
,
5322 ddraw_surface3_GetClipper
,
5323 ddraw_surface3_GetColorKey
,
5324 ddraw_surface3_GetDC
,
5325 ddraw_surface3_GetFlipStatus
,
5326 ddraw_surface3_GetOverlayPosition
,
5327 ddraw_surface3_GetPalette
,
5328 ddraw_surface3_GetPixelFormat
,
5329 ddraw_surface3_GetSurfaceDesc
,
5330 ddraw_surface3_Initialize
,
5331 ddraw_surface3_IsLost
,
5332 ddraw_surface3_Lock
,
5333 ddraw_surface3_ReleaseDC
,
5334 ddraw_surface3_Restore
,
5335 ddraw_surface3_SetClipper
,
5336 ddraw_surface3_SetColorKey
,
5337 ddraw_surface3_SetOverlayPosition
,
5338 ddraw_surface3_SetPalette
,
5339 ddraw_surface3_Unlock
,
5340 ddraw_surface3_UpdateOverlay
,
5341 ddraw_surface3_UpdateOverlayDisplay
,
5342 ddraw_surface3_UpdateOverlayZOrder
,
5343 /* IDirectDrawSurface2 */
5344 ddraw_surface3_GetDDInterface
,
5345 ddraw_surface3_PageLock
,
5346 ddraw_surface3_PageUnlock
,
5347 /* IDirectDrawSurface3 */
5348 ddraw_surface3_SetSurfaceDesc
,
5351 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5354 ddraw_surface2_QueryInterface
,
5355 ddraw_surface2_AddRef
,
5356 ddraw_surface2_Release
,
5357 /* IDirectDrawSurface */
5358 ddraw_surface2_AddAttachedSurface
,
5359 ddraw_surface2_AddOverlayDirtyRect
,
5361 ddraw_surface2_BltBatch
,
5362 ddraw_surface2_BltFast
,
5363 ddraw_surface2_DeleteAttachedSurface
,
5364 ddraw_surface2_EnumAttachedSurfaces
,
5365 ddraw_surface2_EnumOverlayZOrders
,
5366 ddraw_surface2_Flip
,
5367 ddraw_surface2_GetAttachedSurface
,
5368 ddraw_surface2_GetBltStatus
,
5369 ddraw_surface2_GetCaps
,
5370 ddraw_surface2_GetClipper
,
5371 ddraw_surface2_GetColorKey
,
5372 ddraw_surface2_GetDC
,
5373 ddraw_surface2_GetFlipStatus
,
5374 ddraw_surface2_GetOverlayPosition
,
5375 ddraw_surface2_GetPalette
,
5376 ddraw_surface2_GetPixelFormat
,
5377 ddraw_surface2_GetSurfaceDesc
,
5378 ddraw_surface2_Initialize
,
5379 ddraw_surface2_IsLost
,
5380 ddraw_surface2_Lock
,
5381 ddraw_surface2_ReleaseDC
,
5382 ddraw_surface2_Restore
,
5383 ddraw_surface2_SetClipper
,
5384 ddraw_surface2_SetColorKey
,
5385 ddraw_surface2_SetOverlayPosition
,
5386 ddraw_surface2_SetPalette
,
5387 ddraw_surface2_Unlock
,
5388 ddraw_surface2_UpdateOverlay
,
5389 ddraw_surface2_UpdateOverlayDisplay
,
5390 ddraw_surface2_UpdateOverlayZOrder
,
5391 /* IDirectDrawSurface2 */
5392 ddraw_surface2_GetDDInterface
,
5393 ddraw_surface2_PageLock
,
5394 ddraw_surface2_PageUnlock
,
5397 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5400 ddraw_surface1_QueryInterface
,
5401 ddraw_surface1_AddRef
,
5402 ddraw_surface1_Release
,
5403 /* IDirectDrawSurface */
5404 ddraw_surface1_AddAttachedSurface
,
5405 ddraw_surface1_AddOverlayDirtyRect
,
5407 ddraw_surface1_BltBatch
,
5408 ddraw_surface1_BltFast
,
5409 ddraw_surface1_DeleteAttachedSurface
,
5410 ddraw_surface1_EnumAttachedSurfaces
,
5411 ddraw_surface1_EnumOverlayZOrders
,
5412 ddraw_surface1_Flip
,
5413 ddraw_surface1_GetAttachedSurface
,
5414 ddraw_surface1_GetBltStatus
,
5415 ddraw_surface1_GetCaps
,
5416 ddraw_surface1_GetClipper
,
5417 ddraw_surface1_GetColorKey
,
5418 ddraw_surface1_GetDC
,
5419 ddraw_surface1_GetFlipStatus
,
5420 ddraw_surface1_GetOverlayPosition
,
5421 ddraw_surface1_GetPalette
,
5422 ddraw_surface1_GetPixelFormat
,
5423 ddraw_surface1_GetSurfaceDesc
,
5424 ddraw_surface1_Initialize
,
5425 ddraw_surface1_IsLost
,
5426 ddraw_surface1_Lock
,
5427 ddraw_surface1_ReleaseDC
,
5428 ddraw_surface1_Restore
,
5429 ddraw_surface1_SetClipper
,
5430 ddraw_surface1_SetColorKey
,
5431 ddraw_surface1_SetOverlayPosition
,
5432 ddraw_surface1_SetPalette
,
5433 ddraw_surface1_Unlock
,
5434 ddraw_surface1_UpdateOverlay
,
5435 ddraw_surface1_UpdateOverlayDisplay
,
5436 ddraw_surface1_UpdateOverlayZOrder
,
5439 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5441 ddraw_gamma_control_QueryInterface
,
5442 ddraw_gamma_control_AddRef
,
5443 ddraw_gamma_control_Release
,
5444 ddraw_gamma_control_GetGammaRamp
,
5445 ddraw_gamma_control_SetGammaRamp
,
5448 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5450 d3d_texture2_QueryInterface
,
5451 d3d_texture2_AddRef
,
5452 d3d_texture2_Release
,
5453 d3d_texture2_GetHandle
,
5454 d3d_texture2_PaletteChanged
,
5458 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5460 d3d_texture1_QueryInterface
,
5461 d3d_texture1_AddRef
,
5462 d3d_texture1_Release
,
5463 d3d_texture1_Initialize
,
5464 d3d_texture1_GetHandle
,
5465 d3d_texture1_PaletteChanged
,
5467 d3d_texture1_Unload
,
5470 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5471 * IDirectDrawSurface interface to ddraw methods. */
5472 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5474 if (!iface
) return NULL
;
5475 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5477 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5480 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5483 IUnknown_Release(iface
);
5485 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5488 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5490 if (!iface
) return NULL
;
5491 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5493 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5496 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5499 IUnknown_Release(iface
);
5501 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5504 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5506 if (!iface
) return NULL
;
5507 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5509 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5512 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5515 IUnknown_Release(iface
);
5517 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5520 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5522 if (!iface
) return NULL
;
5523 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5525 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5528 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5531 IUnknown_Release(iface
);
5533 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5536 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5538 if (!iface
) return NULL
;
5539 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5541 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5544 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5547 IUnknown_Release(iface
);
5549 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5552 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5554 if (!iface
) return NULL
;
5555 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5556 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5559 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5561 if (!iface
) return NULL
;
5562 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5563 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5566 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5568 struct ddraw_surface
*surface
= parent
;
5570 TRACE("surface %p.\n", surface
);
5572 /* Check for attached surfaces and detach them. */
5573 if (surface
->first_attached
!= surface
)
5575 /* Well, this shouldn't happen: The surface being attached is
5576 * referenced in AddAttachedSurface(), so it shouldn't be released
5577 * until DeleteAttachedSurface() is called, because the refcount is
5578 * held. It looks like the application released it often enough to
5580 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5582 /* The refcount will drop to -1 here */
5583 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5584 ERR("DeleteAttachedSurface failed.\n");
5587 while (surface
->next_attached
)
5588 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5589 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5590 ERR("DeleteAttachedSurface failed.\n");
5592 /* Having a texture handle set implies that the device still exists. */
5593 if (surface
->Handle
)
5594 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5596 /* Reduce the ddraw surface count. */
5597 list_remove(&surface
->surface_list_entry
);
5599 if (surface
== surface
->ddraw
->primary
)
5600 surface
->ddraw
->primary
= NULL
;
5602 HeapFree(GetProcessHeap(), 0, surface
);
5605 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5607 ddraw_surface_wined3d_object_destroyed
,
5610 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5612 struct ddraw_surface
*surface
= parent
;
5614 TRACE("surface %p.\n", surface
);
5616 ddraw_surface_cleanup(surface
);
5619 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5621 ddraw_texture_wined3d_object_destroyed
,
5624 HRESULT
ddraw_surface_create_texture(struct ddraw_surface
*surface
)
5626 const DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
5627 enum wined3d_format_id format
;
5628 enum wined3d_pool pool
;
5631 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5632 levels
= desc
->u2
.dwMipMapCount
;
5636 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3D_POOL_SYSTEM_MEM.
5637 * Should I forward the MANAGED cap to the managed pool? */
5638 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5639 pool
= WINED3D_POOL_SYSTEM_MEM
;
5641 pool
= WINED3D_POOL_DEFAULT
;
5643 format
= PixelFormat_DD2WineD3D(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
5644 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5645 return wined3d_texture_create_cube(surface
->ddraw
->wined3d_device
, desc
->dwWidth
,
5646 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5648 return wined3d_texture_create_2d(surface
->ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
,
5649 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5652 HRESULT
ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
5653 DDSURFACEDESC2
*desc
, UINT mip_level
, UINT version
)
5655 enum wined3d_pool pool
= WINED3D_POOL_DEFAULT
;
5656 DWORD flags
= WINED3D_SURFACE_MAPPABLE
;
5657 enum wined3d_format_id format
;
5661 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5662 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5663 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)))
5665 /* Tests show surfaces without memory flags get these flags added
5666 * right after creation. */
5667 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5670 /* Some applications assume surfaces will always be mapped at the same
5671 * address. Some of those also assume that this address is valid even when
5672 * the surface isn't mapped, and that updates done this way will be
5673 * visible on the screen. The game Nox is such an application,
5674 * Commandos: Behind Enemy Lines is another. */
5675 flags
|= WINED3D_SURFACE_PIN_SYSMEM
;
5677 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5679 usage
|= WINED3DUSAGE_RENDERTARGET
;
5680 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5683 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5685 usage
|= WINED3DUSAGE_RENDERTARGET
;
5688 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
5690 usage
|= WINED3DUSAGE_OVERLAY
;
5693 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5694 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5696 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
5697 usage
|= WINED3DUSAGE_OWNDC
;
5699 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5701 pool
= WINED3D_POOL_SYSTEM_MEM
;
5703 else if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
5705 pool
= WINED3D_POOL_MANAGED
;
5706 /* Managed textures have the system memory flag set. */
5707 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5709 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5711 /* Videomemory adds localvidmem. This is mutually exclusive with
5712 * systemmemory and texturemanage. */
5713 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5716 format
= PixelFormat_DD2WineD3D(&desc
->u4
.ddpfPixelFormat
);
5717 if (format
== WINED3DFMT_UNKNOWN
)
5719 WARN("Unsupported / unknown pixelformat.\n");
5720 return DDERR_INVALIDPIXELFORMAT
;
5723 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
5724 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
5725 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
5726 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
5727 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
5728 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
5729 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
5730 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
5731 surface
->iface_count
= 1;
5732 surface
->version
= version
;
5733 surface
->ddraw
= ddraw
;
5738 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
5740 else if (version
== 4)
5743 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
5748 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
5751 copy_to_surfacedesc2(&surface
->surface_desc
, desc
);
5753 surface
->first_attached
= surface
;
5755 hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
, format
, mip_level
,
5756 usage
, pool
, WINED3D_MULTISAMPLE_NONE
, 0, DefaultSurfaceType
, flags
,
5757 surface
, &ddraw_surface_wined3d_parent_ops
, &surface
->wined3d_surface
);
5760 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
5764 /* Anno 1602 stores the pitch right after surface creation, so make sure
5765 * it's there. TODO: Test other fourcc formats. */
5766 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
5767 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
5769 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
5770 if (format
== WINED3DFMT_DXT1
)
5772 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
) / 2;
5776 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
);
5781 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
5782 surface
->surface_desc
.u1
.lPitch
= wined3d_surface_get_pitch(surface
->wined3d_surface
);
5785 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
5787 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
5788 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
5790 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
5792 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTBLT
,
5793 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
5795 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
5797 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
5798 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
5800 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
5802 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCBLT
,
5803 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
5805 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5807 hr
= wined3d_surface_set_mem(surface
->wined3d_surface
, desc
->lpSurface
);
5810 ERR("Failed to set surface memory, hr %#x.\n", hr
);
5811 wined3d_surface_decref(surface
->wined3d_surface
);