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 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 wined3d_palette_apply_to_dc(surface
->palette
->wineD3DPalette
, surface_dc
);
87 if (!(screen_dc
= GetDC(NULL
)))
89 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
90 ERR("Failed to get screen DC.\n");
95 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
96 screen_dc
, x
, y
, SRCCOPY
);
98 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
99 surface_dc
, x
, y
, SRCCOPY
);
101 ReleaseDC(NULL
, screen_dc
);
102 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
106 ERR("Failed to blit to/from screen.\n");
113 /*****************************************************************************
114 * IUnknown parts follow
115 *****************************************************************************/
117 /*****************************************************************************
118 * IDirectDrawSurface7::QueryInterface
120 * A normal QueryInterface implementation. For QueryInterface rules
121 * see ddraw.c, IDirectDraw7::QueryInterface. This method
122 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
123 * in all versions, the IDirectDrawGammaControl interface and it can
124 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
127 * riid: The interface id queried for
128 * obj: Address to write the pointer to
132 * E_NOINTERFACE if the requested interface wasn't found
134 *****************************************************************************/
135 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
137 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
139 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
141 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
145 return DDERR_INVALIDPARAMS
;
147 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
149 IDirectDrawSurface7_AddRef(iface
);
151 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
155 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
157 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
158 *obj
= &This
->IDirectDrawSurface4_iface
;
159 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
163 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
165 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
166 *obj
= &This
->IDirectDrawSurface3_iface
;
167 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
171 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
173 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
174 *obj
= &This
->IDirectDrawSurface2_iface
;
175 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
179 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
180 || IsEqualGUID(riid
, &IID_IUnknown
))
182 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
183 *obj
= &This
->IDirectDrawSurface_iface
;
184 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
188 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
190 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
191 *obj
= &This
->IDirectDrawGammaControl_iface
;
192 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
196 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
198 WARN("Color control not implemented.\n");
200 return E_NOINTERFACE
;
203 if (This
->version
!= 7)
205 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
206 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
207 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
209 wined3d_mutex_lock();
214 if (FAILED(hr
= d3d_device_create(This
->ddraw
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
215 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
217 This
->device1
= NULL
;
218 wined3d_mutex_unlock();
219 WARN("Failed to create device, hr %#x.\n", hr
);
223 wined3d_mutex_unlock();
225 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
226 *obj
= &This
->device1
->IDirect3DDevice_iface
;
230 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
232 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
233 *obj
= &This
->IDirect3DTexture2_iface
;
237 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
239 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
240 *obj
= &This
->IDirect3DTexture_iface
;
245 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
247 if (This
->version
!= 7)
250 return E_NOINTERFACE
;
253 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
255 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
257 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
259 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
262 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
264 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
266 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
268 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
271 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
273 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
275 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
277 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
280 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
282 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
284 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
286 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
289 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
290 REFIID riid
, void **object
)
292 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
294 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
296 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
299 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
301 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
303 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
305 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
308 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
310 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
312 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
314 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
317 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
319 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
320 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
322 if (iface_count
== 1)
324 if (surface
->ifaceToRelease
)
325 IUnknown_AddRef(surface
->ifaceToRelease
);
326 wined3d_mutex_lock();
327 if (surface
->wined3d_rtv
)
328 wined3d_rendertarget_view_incref(surface
->wined3d_rtv
);
329 if (surface
->wined3d_surface
)
330 wined3d_surface_incref(surface
->wined3d_surface
);
331 if (surface
->wined3d_texture
)
332 wined3d_texture_incref(surface
->wined3d_texture
);
333 wined3d_mutex_unlock();
337 /*****************************************************************************
338 * IDirectDrawSurface7::AddRef
340 * A normal addref implementation
345 *****************************************************************************/
346 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
348 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
349 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
351 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
355 ddraw_surface_add_iface(This
);
361 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
363 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
364 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
366 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
370 ddraw_surface_add_iface(This
);
376 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
378 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
379 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
381 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
385 ddraw_surface_add_iface(This
);
391 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
393 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
394 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
396 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
400 ddraw_surface_add_iface(This
);
406 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
408 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
409 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
411 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
415 ddraw_surface_add_iface(This
);
421 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
423 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
424 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
426 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
430 ddraw_surface_add_iface(This
);
436 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
438 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
440 TRACE("iface %p.\n", iface
);
442 return IUnknown_AddRef(surface
->texture_outer
);
445 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
447 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
449 TRACE("iface %p.\n", iface
);
451 return IUnknown_AddRef(surface
->texture_outer
);
454 static HRESULT
ddraw_surface_set_palette(struct ddraw_surface
*surface
, IDirectDrawPalette
*palette
)
456 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(palette
);
457 struct ddraw_palette
*prev
;
459 TRACE("iface %p, palette %p.\n", surface
, palette
);
461 if (palette_impl
&& palette_impl
->flags
& DDPCAPS_ALPHA
462 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
464 WARN("Alpha palette set on non-texture surface, returning DDERR_INVALIDSURFACETYPE.\n");
465 return DDERR_INVALIDSURFACETYPE
;
468 if (!format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
469 return DDERR_INVALIDPIXELFORMAT
;
471 wined3d_mutex_lock();
473 prev
= surface
->palette
;
474 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
477 prev
->flags
&= ~DDPCAPS_PRIMARYSURFACE
;
479 palette_impl
->flags
|= DDPCAPS_PRIMARYSURFACE
;
480 wined3d_swapchain_set_palette(surface
->ddraw
->wined3d_swapchain
,
481 palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
482 ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
485 IDirectDrawPalette_AddRef(&palette_impl
->IDirectDrawPalette_iface
);
487 IDirectDrawPalette_Release(&prev
->IDirectDrawPalette_iface
);
488 surface
->palette
= palette_impl
;
490 wined3d_mutex_unlock();
495 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
497 struct ddraw_surface
*surf
;
500 TRACE("surface %p.\n", surface
);
502 /* The refcount test shows that the palette is detached when the surface
504 ddraw_surface_set_palette(surface
, NULL
);
506 /* Loop through all complex attached surfaces and destroy them.
508 * Yet again, only the root can have more than one complexly attached
509 * surface, all the others have a total of one. */
510 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
512 if (!surface
->complex_array
[i
])
515 surf
= surface
->complex_array
[i
];
516 surface
->complex_array
[i
] = NULL
;
517 if (!surf
->is_complex_root
)
518 ddraw_surface_cleanup(surf
);
521 if (surface
->device1
)
522 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
524 if (surface
->iface_count
> 1)
526 /* This can happen when a complex surface is destroyed, because the
527 * 2nd surface was addref()ed when the app called
528 * GetAttachedSurface(). */
529 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
530 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
533 if (surface
->wined3d_rtv
)
534 wined3d_rendertarget_view_decref(surface
->wined3d_rtv
);
535 if (surface
->wined3d_texture
)
536 wined3d_texture_decref(surface
->wined3d_texture
);
537 if (surface
->wined3d_surface
)
538 wined3d_surface_decref(surface
->wined3d_surface
);
541 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
543 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
544 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
546 if (iface_count
== 0)
548 IUnknown
*release_iface
= This
->ifaceToRelease
;
550 /* Complex attached surfaces are destroyed implicitly when the root is released */
551 wined3d_mutex_lock();
552 if(!This
->is_complex_root
)
554 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
555 wined3d_mutex_unlock();
558 ddraw_surface_cleanup(This
);
559 wined3d_mutex_unlock();
562 IUnknown_Release(release_iface
);
568 /*****************************************************************************
569 * IDirectDrawSurface7::Release
571 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
572 * surface is destroyed.
574 * Destroying the surface is a bit tricky. For the connection between
575 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
576 * It has a nice graph explaining the connection.
578 * What happens here is basically this:
579 * When a surface is destroyed, its WineD3DSurface is released,
580 * and the refcount of the DirectDraw interface is reduced by 1. If it has
581 * complex surfaces attached to it, then these surfaces are destroyed too,
582 * regardless of their refcount. If any surface being destroyed has another
583 * surface attached to it (with a "soft" attachment, not complex), then
584 * this surface is detached with DeleteAttachedSurface.
586 * When the surface is a texture, the WineD3DTexture is released.
587 * If the surface is the Direct3D render target, then the D3D
588 * capabilities of the WineD3DDevice are uninitialized, which causes the
589 * swapchain to be released.
591 * When a complex sublevel falls to ref zero, then this is ignored.
596 *****************************************************************************/
597 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
599 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
600 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
602 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
606 ddraw_surface_release_iface(This
);
612 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
614 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
615 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
617 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
621 ddraw_surface_release_iface(This
);
627 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
629 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
630 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
632 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
636 ddraw_surface_release_iface(This
);
642 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
644 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
645 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
647 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
651 ddraw_surface_release_iface(This
);
657 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
659 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
660 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
662 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
666 ddraw_surface_release_iface(This
);
672 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
674 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
675 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
677 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
681 ddraw_surface_release_iface(This
);
687 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
689 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
691 TRACE("iface %p.\n", iface
);
693 return IUnknown_Release(surface
->texture_outer
);
696 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
698 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
700 TRACE("iface %p.\n", iface
);
702 return IUnknown_Release(surface
->texture_outer
);
705 /*****************************************************************************
706 * IDirectDrawSurface7::GetAttachedSurface
708 * Returns an attached surface with the requested caps. Surface attachment
709 * and complex surfaces are not clearly described by the MSDN or sdk,
710 * so this method is tricky and likely to contain problems.
711 * This implementation searches the complex list first, then the
714 * The chains are searched from This down to the last surface in the chain,
715 * not from the first element in the chain. The first surface found is
716 * returned. The MSDN says that this method fails if more than one surface
717 * matches the caps, but it is not sure if that is right. The attachment
718 * structure may not even allow two matching surfaces.
720 * The found surface is AddRef-ed before it is returned.
723 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
724 * Surface: Address to store the found surface
728 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
729 * DDERR_NOTFOUND if no surface was found
731 *****************************************************************************/
732 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
733 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
735 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
736 struct ddraw_surface
*surf
;
740 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
742 wined3d_mutex_lock();
744 if(This
->version
< 7)
746 /* Earlier dx apps put garbage into these members, clear them */
747 our_caps
.dwCaps
= Caps
->dwCaps
;
748 our_caps
.dwCaps2
= 0;
749 our_caps
.dwCaps3
= 0;
750 our_caps
.u1
.dwCaps4
= 0;
757 TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This
, our_caps
.dwCaps
, our_caps
.dwCaps2
, our_caps
.dwCaps3
, our_caps
.u1
.dwCaps4
); /* FIXME: Better debugging */
759 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
761 surf
= This
->complex_array
[i
];
764 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
765 surf
->surface_desc
.ddsCaps
.dwCaps
,
766 surf
->surface_desc
.ddsCaps
.dwCaps2
,
767 surf
->surface_desc
.ddsCaps
.dwCaps3
,
768 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
770 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
771 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
773 /* MSDN: "This method fails if more than one surface is attached
774 * that matches the capabilities requested."
776 * Not sure how to test this.
779 TRACE("(%p): Returning surface %p\n", This
, surf
);
780 *Surface
= &surf
->IDirectDrawSurface7_iface
;
781 ddraw_surface7_AddRef(*Surface
);
782 wined3d_mutex_unlock();
788 /* Next, look at the attachment chain */
791 while( (surf
= surf
->next_attached
) )
793 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
794 surf
->surface_desc
.ddsCaps
.dwCaps
,
795 surf
->surface_desc
.ddsCaps
.dwCaps2
,
796 surf
->surface_desc
.ddsCaps
.dwCaps3
,
797 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
799 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
800 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
802 TRACE("(%p): Returning surface %p\n", This
, surf
);
803 *Surface
= &surf
->IDirectDrawSurface7_iface
;
804 ddraw_surface7_AddRef(*Surface
);
805 wined3d_mutex_unlock();
810 TRACE("(%p) Didn't find a valid surface\n", This
);
812 wined3d_mutex_unlock();
815 return DDERR_NOTFOUND
;
818 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
819 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
821 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
822 struct ddraw_surface
*attachment_impl
;
823 IDirectDrawSurface7
*attachment7
;
826 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
828 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
835 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
836 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
837 ddraw_surface4_AddRef(*attachment
);
838 ddraw_surface7_Release(attachment7
);
843 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
844 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
846 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
847 struct ddraw_surface
*attachment_impl
;
848 IDirectDrawSurface7
*attachment7
;
852 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
854 caps2
.dwCaps
= caps
->dwCaps
;
857 caps2
.u1
.dwCaps4
= 0;
859 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
860 &caps2
, &attachment7
);
866 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
867 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
868 ddraw_surface3_AddRef(*attachment
);
869 ddraw_surface7_Release(attachment7
);
874 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
875 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
877 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
878 struct ddraw_surface
*attachment_impl
;
879 IDirectDrawSurface7
*attachment7
;
883 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
885 caps2
.dwCaps
= caps
->dwCaps
;
888 caps2
.u1
.dwCaps4
= 0;
890 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
891 &caps2
, &attachment7
);
897 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
898 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
899 ddraw_surface2_AddRef(*attachment
);
900 ddraw_surface7_Release(attachment7
);
905 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
906 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
908 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
909 struct ddraw_surface
*attachment_impl
;
910 IDirectDrawSurface7
*attachment7
;
914 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
916 caps2
.dwCaps
= caps
->dwCaps
;
919 caps2
.u1
.dwCaps4
= 0;
921 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
922 &caps2
, &attachment7
);
928 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
929 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
930 ddraw_surface1_AddRef(*attachment
);
931 ddraw_surface7_Release(attachment7
);
936 /*****************************************************************************
937 * IDirectDrawSurface7::Lock
939 * Locks the surface and returns a pointer to the surface's memory
942 * Rect: Rectangle to lock. If NULL, the whole surface is locked
943 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
944 * Flags: Locking flags, e.g Read only or write only
945 * h: An event handle that's not used and must be NULL
949 * DDERR_INVALIDPARAMS if DDSD is NULL
950 * For more details, see IWineD3DSurface::LockRect
952 *****************************************************************************/
953 static HRESULT
surface_lock(struct ddraw_surface
*This
,
954 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
956 struct wined3d_box box
;
957 struct wined3d_map_desc map_desc
;
960 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
961 This
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
963 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
964 wined3d_mutex_lock();
966 /* Should I check for the handle to be NULL?
968 * The DDLOCK flags and the D3DLOCK flags are equal
969 * for the supported values. The others are ignored by WineD3D
972 /* Windows zeroes this if the rect is invalid */
979 || (Rect
->left
> Rect
->right
)
980 || (Rect
->top
> Rect
->bottom
)
981 || (Rect
->right
> This
->surface_desc
.dwWidth
)
982 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
984 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
985 wined3d_mutex_unlock();
986 return DDERR_INVALIDPARAMS
;
988 box
.left
= Rect
->left
;
990 box
.right
= Rect
->right
;
991 box
.bottom
= Rect
->bottom
;
996 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
997 hr
= ddraw_surface_update_frontbuffer(This
, Rect
, TRUE
);
999 hr
= wined3d_surface_map(This
->wined3d_surface
, &map_desc
, Rect
? &box
: NULL
, Flags
);
1002 wined3d_mutex_unlock();
1005 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
1006 * specific error. But since IWineD3DSurface::LockRect returns that error in this
1007 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
1008 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
1009 * is much easier to do it in one place in ddraw
1011 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1016 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1018 if (Flags
& DDLOCK_READONLY
)
1019 memset(&This
->ddraw
->primary_lock
, 0, sizeof(This
->ddraw
->primary_lock
));
1021 This
->ddraw
->primary_lock
= *Rect
;
1023 SetRect(&This
->ddraw
->primary_lock
, 0, 0, This
->surface_desc
.dwWidth
, This
->surface_desc
.dwHeight
);
1026 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1027 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
1028 DDSD
->lpSurface
= map_desc
.data
;
1030 TRACE("locked surface returning description :\n");
1031 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1033 wined3d_mutex_unlock();
1038 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1039 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1041 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1043 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1044 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1046 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1047 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1048 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1050 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1051 return DDERR_INVALIDPARAMS
;
1053 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1056 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1057 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1059 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1061 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1062 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1064 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1065 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1066 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1068 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1069 return DDERR_INVALIDPARAMS
;
1071 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1074 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1075 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1077 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1078 DDSURFACEDESC2 surface_desc2
;
1081 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1082 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1084 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1085 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1086 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1088 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1089 return DDERR_INVALIDPARAMS
;
1092 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1093 surface_desc2
.dwFlags
= 0;
1094 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1095 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1096 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1100 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1101 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1103 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1104 DDSURFACEDESC2 surface_desc2
;
1107 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1108 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1110 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1111 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1112 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1114 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1115 return DDERR_INVALIDPARAMS
;
1118 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1119 surface_desc2
.dwFlags
= 0;
1120 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1121 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1122 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1126 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1127 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1129 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1130 DDSURFACEDESC2 surface_desc2
;
1132 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1133 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1135 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1136 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1137 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1139 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1140 return DDERR_INVALIDPARAMS
;
1143 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1144 surface_desc2
.dwFlags
= 0;
1145 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1146 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1147 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1151 /*****************************************************************************
1152 * IDirectDrawSurface7::Unlock
1154 * Unlocks an locked surface
1157 * Rect: Not used by this implementation
1161 * For more details, see IWineD3DSurface::UnlockRect
1163 *****************************************************************************/
1164 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1166 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1169 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1171 wined3d_mutex_lock();
1172 hr
= wined3d_surface_unmap(surface
->wined3d_surface
);
1173 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1174 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1175 wined3d_mutex_unlock();
1180 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1182 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1184 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1186 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1189 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1191 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1201 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1203 TRACE("iface %p, data %p.\n", iface
, data
);
1205 /* data might not be the LPRECT of later versions, so drop it. */
1206 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1209 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1211 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1213 TRACE("iface %p, data %p.\n", iface
, data
);
1215 /* data might not be the LPRECT of later versions, so drop it. */
1216 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1219 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1220 IDirectDrawSurface7
*src
, DWORD flags
)
1222 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1223 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1224 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1225 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1226 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1227 struct wined3d_texture
*texture
;
1228 IDirectDrawSurface7
*current
;
1229 struct wined3d_surface
*tmp
;
1232 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1234 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1235 return DDERR_NOTFLIPPABLE
;
1237 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1238 return DDERR_SURFACELOST
;
1240 wined3d_mutex_lock();
1242 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1243 tmp
= dst_impl
->wined3d_surface
;
1244 texture
= dst_impl
->wined3d_texture
;
1245 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1246 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1250 for (current
= iface
; current
!= src
;)
1252 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1254 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1255 wined3d_mutex_unlock();
1256 return DDERR_NOTFLIPPABLE
;
1258 ddraw_surface7_Release(current
);
1259 if (current
== iface
)
1261 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1262 wined3d_mutex_unlock();
1263 return DDERR_NOTFLIPPABLE
;
1267 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1268 if (rtv
== dst_impl
->wined3d_rtv
)
1269 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1270 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1271 dst_impl
->wined3d_rtv
= src_rtv
;
1272 wined3d_resource_set_parent(wined3d_surface_get_resource(src_impl
->wined3d_surface
), dst_impl
);
1273 dst_impl
->wined3d_surface
= src_impl
->wined3d_surface
;
1274 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1275 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1276 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1277 ddraw_texture
= prev_ddraw_texture
;
1281 for (current
= iface
;;)
1283 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1285 ERR("Can't find a flip target\n");
1286 wined3d_mutex_unlock();
1287 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1289 ddraw_surface7_Release(current
);
1290 if (current
== iface
)
1292 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1296 src_impl
= impl_from_IDirectDrawSurface7(current
);
1297 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1298 if (rtv
== dst_impl
->wined3d_rtv
)
1299 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1300 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1301 dst_impl
->wined3d_rtv
= src_rtv
;
1302 wined3d_resource_set_parent(wined3d_surface_get_resource(src_impl
->wined3d_surface
), dst_impl
);
1303 dst_impl
->wined3d_surface
= src_impl
->wined3d_surface
;
1304 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1305 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1306 ddraw_texture
= prev_ddraw_texture
;
1307 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1308 dst_impl
= src_impl
;
1312 /* We don't have to worry about potential texture bindings, since
1313 * flippable surfaces can never be textures. */
1314 if (rtv
== src_impl
->wined3d_rtv
)
1315 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1316 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1317 src_impl
->wined3d_rtv
= tmp_rtv
;
1318 wined3d_resource_set_parent(wined3d_surface_get_resource(tmp
), src_impl
);
1319 src_impl
->wined3d_surface
= tmp
;
1320 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1321 src_impl
->wined3d_texture
= texture
;
1327 FIXME("Ignoring flags %#x.\n", flags
);
1329 WARN("Ignoring flags %#x.\n", flags
);
1332 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1333 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1337 wined3d_mutex_unlock();
1342 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1343 IDirectDrawSurface4
*dst
, DWORD flags
)
1345 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1346 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1348 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1350 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1351 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1354 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1355 IDirectDrawSurface3
*dst
, DWORD flags
)
1357 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1358 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1360 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1362 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1363 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1366 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1367 IDirectDrawSurface2
*dst
, DWORD flags
)
1369 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1370 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1372 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1374 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1375 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1378 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1379 IDirectDrawSurface
*dst
, DWORD flags
)
1381 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1382 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1384 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1386 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1387 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1390 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1391 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1392 const WINEDDBLTFX
*fx
, enum wined3d_texture_filter_type filter
)
1394 struct wined3d_surface
*wined3d_src_surface
= src_surface
? src_surface
->wined3d_surface
: NULL
;
1395 RECT src_rect
, dst_rect
;
1396 float scale_x
, scale_y
;
1397 const RECT
*clip_rect
;
1398 UINT clip_list_size
;
1403 if (!dst_surface
->clipper
)
1405 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1406 hr
= ddraw_surface_update_frontbuffer(src_surface
, src_rect_in
, TRUE
);
1408 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, dst_rect_in
,
1409 wined3d_src_surface
, src_rect_in
, flags
, fx
, filter
);
1410 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1411 hr
= ddraw_surface_update_frontbuffer(dst_surface
, dst_rect_in
, FALSE
);
1420 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1421 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1425 dst_rect
= *dst_rect_in
;
1428 if (IsRectEmpty(&dst_rect
))
1429 return DDERR_INVALIDRECT
;
1437 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1438 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1442 src_rect
= *src_rect_in
;
1445 if (IsRectEmpty(&src_rect
))
1446 return DDERR_INVALIDRECT
;
1450 SetRect(&src_rect
, 0, 0, 0, 0);
1453 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1454 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1456 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1457 &dst_rect
, NULL
, &clip_list_size
)))
1459 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1463 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1465 WARN("Failed to allocate clip list.\n");
1466 return E_OUTOFMEMORY
;
1469 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1470 &dst_rect
, clip_list
, &clip_list_size
)))
1472 WARN("Failed to get clip list, hr %#x.\n", hr
);
1473 HeapFree(GetProcessHeap(), 0, clip_list
);
1477 clip_rect
= (RECT
*)clip_list
->Buffer
;
1478 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1480 RECT src_rect_clipped
= src_rect
;
1484 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1485 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1486 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1487 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1489 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1491 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1496 if (FAILED(hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, &clip_rect
[i
],
1497 wined3d_src_surface
, &src_rect_clipped
, flags
, fx
, filter
)))
1500 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1502 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1507 HeapFree(GetProcessHeap(), 0, clip_list
);
1511 /*****************************************************************************
1512 * IDirectDrawSurface7::Blt
1514 * Performs a blit on the surface
1517 * DestRect: Destination rectangle, can be NULL
1518 * SrcSurface: Source surface, can be NULL
1519 * SrcRect: Source rectangle, can be NULL
1521 * DDBltFx: Some extended blt parameters, connected to the flags
1525 * See IWineD3DSurface::Blt for more details
1527 *****************************************************************************/
1528 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1529 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1531 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1532 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1536 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1537 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1539 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1540 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1542 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1543 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1544 return DDERR_INVALIDPARAMS
;
1547 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1548 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1549 return DDERR_INVALIDPARAMS
;
1552 wined3d_mutex_lock();
1554 if (Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1556 if (Flags
& DDBLT_ROP
)
1558 wined3d_mutex_unlock();
1559 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1560 return DDERR_INVALIDPARAMS
;
1564 wined3d_mutex_unlock();
1565 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1566 return DDERR_INVALIDPARAMS
;
1570 wined3d_mutex_unlock();
1571 WARN("Depth or colorfill used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1572 return DDERR_INVALIDPARAMS
;
1575 if ((Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1576 Flags
&= ~DDBLT_DEPTHFILL
;
1578 if ((dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_COLORFILL
))
1580 wined3d_mutex_unlock();
1581 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1582 return DDERR_INVALIDPARAMS
;
1584 if (!(dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_DEPTHFILL
))
1586 wined3d_mutex_unlock();
1587 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1588 return DDERR_INVALIDPARAMS
;
1592 if (Flags
& DDBLT_ROP
)
1596 wined3d_mutex_unlock();
1597 WARN("DDBLT_ROP used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1598 return DDERR_INVALIDPARAMS
;
1601 Flags
&= ~DDBLT_ROP
;
1602 switch (DDBltFx
->dwROP
)
1611 if (DDBltFx
->dwROP
== WHITENESS
)
1612 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1614 rop_fx
.u5
.dwFillColor
= 0;
1616 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1617 Flags
|= DDBLT_DEPTHFILL
;
1619 Flags
|= DDBLT_COLORFILL
;
1625 wined3d_mutex_unlock();
1626 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", DDBltFx
->dwROP
);
1627 return DDERR_NORASTEROPHW
;
1631 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1633 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1634 wined3d_mutex_unlock();
1635 return DDERR_INVALIDPARAMS
;
1638 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1639 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1640 * surfaces. So far no blitting operations using surfaces in the bltfx
1641 * struct are supported anyway. */
1642 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1643 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1645 wined3d_mutex_unlock();
1648 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1649 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1654 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1655 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1657 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1658 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1660 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1661 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1663 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1664 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1667 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1668 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1670 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1671 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1673 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1674 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1676 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1677 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1680 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1681 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1683 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1684 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1686 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1687 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1689 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1690 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1693 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1694 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1696 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1697 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1699 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1700 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1702 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1703 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1706 /*****************************************************************************
1707 * IDirectDrawSurface7::AddAttachedSurface
1709 * Attaches a surface to another surface. How the surface attachments work
1710 * is not totally understood yet, and this method is prone to problems.
1711 * The surface that is attached is AddRef-ed.
1713 * Tests with complex surfaces suggest that the surface attachments form a
1714 * tree, but no method to test this has been found yet.
1716 * The attachment list consists of a first surface (first_attached) and
1717 * for each surface a pointer to the next attached surface (next_attached).
1718 * For the first surface, and a surface that has no attachments
1719 * first_attached points to the surface itself. A surface that has
1720 * no successors in the chain has next_attached set to NULL.
1722 * Newly attached surfaces are attached right after the root surface.
1723 * If a surface is attached to a complex surface compound, it's attached to
1724 * the surface that the app requested, not the complex root. See
1725 * GetAttachedSurface for a description how surfaces are found.
1727 * This is how the current implementation works, and it was coded by looking
1728 * at the needs of the applications.
1730 * So far only Z-Buffer attachments are tested, and they are activated in
1731 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1732 * Back buffers should work in 2D mode, but they are not tested(They can be
1733 * attached in older iface versions). Rendering to the front buffer and
1734 * switching between that and double buffering is not yet implemented in
1735 * WineD3D, so for 3D it might have unexpected results.
1737 * ddraw_surface_attach_surface is the real thing,
1738 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1739 * performs additional checks. Version 7 of this interface is much more restrictive
1740 * than its predecessors.
1743 * Attach: Surface to attach to iface
1747 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1749 *****************************************************************************/
1750 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1752 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1755 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1757 wined3d_mutex_lock();
1759 /* Check if the surface is already attached somewhere */
1760 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1762 /* TODO: Test for the structure of the manual attachment. Is it a
1763 * chain or a list? What happens if one surface is attached to 2
1764 * different surfaces? */
1765 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1766 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1768 wined3d_mutex_unlock();
1769 return DDERR_SURFACEALREADYATTACHED
;
1772 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1773 Surf
->next_attached
= This
->next_attached
;
1774 Surf
->first_attached
= This
->first_attached
;
1775 This
->next_attached
= Surf
;
1777 /* Check if the WineD3D depth stencil needs updating */
1778 if (This
->ddraw
->d3ddevice
)
1779 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1781 wined3d_mutex_unlock();
1786 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1788 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1789 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1792 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1794 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1795 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1798 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1799 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1800 return DDERR_CANNOTATTACHSURFACE
;
1803 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1808 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1809 IUnknown_AddRef(attachment_impl
->attached_iface
);
1813 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1815 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1816 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1819 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1821 /* Tests suggest that
1822 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1823 * -> offscreen plain surfaces can be attached to primaries
1824 * -> primaries can be attached to offscreen plain surfaces
1825 * -> z buffers can be attached to primaries */
1826 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1827 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1829 /* Sizes have to match */
1830 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1831 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1833 WARN("Surface sizes do not match.\n");
1834 return DDERR_CANNOTATTACHSURFACE
;
1837 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1838 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1840 WARN("Invalid attachment combination.\n");
1841 return DDERR_CANNOTATTACHSURFACE
;
1844 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1847 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1848 IUnknown_AddRef(attachment_impl
->attached_iface
);
1852 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1854 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1855 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1858 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1860 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1861 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1864 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1865 IUnknown_AddRef(attachment_impl
->attached_iface
);
1866 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1870 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1872 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1873 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1876 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1878 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1879 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1882 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1883 IUnknown_AddRef(attachment_impl
->attached_iface
);
1884 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1888 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1890 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1891 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1894 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1896 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1897 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1900 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1901 IUnknown_AddRef(attachment_impl
->attached_iface
);
1902 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1906 /*****************************************************************************
1907 * IDirectDrawSurface7::DeleteAttachedSurface
1909 * Removes a surface from the attachment chain. The surface's refcount
1910 * is decreased by one after it has been removed
1913 * Flags: Some flags, not used by this implementation
1914 * Attach: Surface to detach
1918 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1920 *****************************************************************************/
1921 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1922 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1924 struct ddraw_surface
*prev
= surface
;
1926 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1928 wined3d_mutex_lock();
1929 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1931 wined3d_mutex_unlock();
1932 return DDERR_CANNOTDETACHSURFACE
;
1935 if (attachment
->attached_iface
!= detach_iface
)
1937 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1938 wined3d_mutex_unlock();
1939 return DDERR_SURFACENOTATTACHED
;
1942 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1943 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1945 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1946 /* FIXME: we should probably also subtract from dwMipMapCount of this
1947 * and all parent surfaces */
1950 /* Find the predecessor of the detached surface */
1953 if (prev
->next_attached
== attachment
)
1955 prev
= prev
->next_attached
;
1958 /* There must be a surface, otherwise there's a bug */
1961 /* Unchain the surface */
1962 prev
->next_attached
= attachment
->next_attached
;
1963 attachment
->next_attached
= NULL
;
1964 attachment
->first_attached
= attachment
;
1966 /* Check if the wined3d depth stencil needs updating. */
1967 if (surface
->ddraw
->d3ddevice
)
1968 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1969 wined3d_mutex_unlock();
1971 /* Set attached_iface to NULL before releasing it, the surface may go
1973 attachment
->attached_iface
= NULL
;
1974 IUnknown_Release(detach_iface
);
1979 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1980 DWORD flags
, IDirectDrawSurface7
*attachment
)
1982 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1983 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1985 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1987 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1990 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1991 DWORD flags
, IDirectDrawSurface4
*attachment
)
1993 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1994 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1996 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1998 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2001 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2002 DWORD flags
, IDirectDrawSurface3
*attachment
)
2004 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2005 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2007 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2009 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2012 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2013 DWORD flags
, IDirectDrawSurface2
*attachment
)
2015 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2016 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2018 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2020 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2023 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2024 DWORD flags
, IDirectDrawSurface
*attachment
)
2026 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2027 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2029 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2031 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2034 /*****************************************************************************
2035 * IDirectDrawSurface7::AddOverlayDirtyRect
2037 * "This method is not currently implemented"
2045 *****************************************************************************/
2046 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2048 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2050 return DDERR_UNSUPPORTED
; /* unchecked */
2053 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2055 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2057 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2059 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2062 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2064 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2066 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2068 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2071 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2073 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2075 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2077 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2080 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2082 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2084 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2086 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2089 /*****************************************************************************
2090 * IDirectDrawSurface7::GetDC
2092 * Returns a GDI device context for the surface
2095 * hdc: Address of a HDC variable to store the dc to
2099 * DDERR_INVALIDPARAMS if hdc is NULL
2100 * For details, see IWineD3DSurface::GetDC
2102 *****************************************************************************/
2103 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
2105 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2108 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2111 return DDERR_INVALIDPARAMS
;
2113 wined3d_mutex_lock();
2114 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2115 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2117 hr
= wined3d_surface_getdc(surface
->wined3d_surface
, hdc
);
2119 if (SUCCEEDED(hr
) && format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2121 const struct ddraw_palette
*palette
;
2123 if (surface
->palette
)
2124 palette
= surface
->palette
;
2125 else if (surface
->ddraw
->primary
)
2126 palette
= surface
->ddraw
->primary
->palette
;
2131 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *hdc
);
2134 wined3d_mutex_unlock();
2137 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
2140 case WINED3DERR_INVALIDCALL
:
2141 if(hdc
) *hdc
= NULL
;
2142 return DDERR_INVALIDPARAMS
;
2148 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2150 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2152 TRACE("iface %p, dc %p.\n", iface
, dc
);
2154 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2157 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2159 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2161 TRACE("iface %p, dc %p.\n", iface
, dc
);
2163 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2166 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2168 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2170 TRACE("iface %p, dc %p.\n", iface
, dc
);
2172 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2175 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2177 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2179 TRACE("iface %p, dc %p.\n", iface
, dc
);
2181 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2184 /*****************************************************************************
2185 * IDirectDrawSurface7::ReleaseDC
2187 * Releases the DC that was constructed with GetDC
2190 * hdc: HDC to release
2194 * For more details, see IWineD3DSurface::ReleaseDC
2196 *****************************************************************************/
2197 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2199 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2202 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2204 wined3d_mutex_lock();
2205 hr
= wined3d_surface_releasedc(surface
->wined3d_surface
, hdc
);
2206 if (SUCCEEDED(hr
) && (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2207 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2208 wined3d_mutex_unlock();
2213 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2215 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2217 TRACE("iface %p, dc %p.\n", iface
, dc
);
2219 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2222 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2224 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2226 TRACE("iface %p, dc %p.\n", iface
, dc
);
2228 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2231 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2233 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2235 TRACE("iface %p, dc %p.\n", iface
, dc
);
2237 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2240 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2242 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2244 TRACE("iface %p, dc %p.\n", iface
, dc
);
2246 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2249 /*****************************************************************************
2250 * IDirectDrawSurface7::GetCaps
2252 * Returns the surface's caps
2255 * Caps: Address to write the caps to
2259 * DDERR_INVALIDPARAMS if Caps is NULL
2261 *****************************************************************************/
2262 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2264 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2266 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2269 return DDERR_INVALIDPARAMS
;
2271 *Caps
= surface
->surface_desc
.ddsCaps
;
2276 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2278 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2280 TRACE("iface %p, caps %p.\n", iface
, caps
);
2282 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2285 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2287 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2291 TRACE("iface %p, caps %p.\n", iface
, caps
);
2293 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2294 if (FAILED(hr
)) return hr
;
2296 caps
->dwCaps
= caps2
.dwCaps
;
2300 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2302 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2306 TRACE("iface %p, caps %p.\n", iface
, caps
);
2308 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2309 if (FAILED(hr
)) return hr
;
2311 caps
->dwCaps
= caps2
.dwCaps
;
2315 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2317 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2321 TRACE("iface %p, caps %p.\n", iface
, caps
);
2323 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2324 if (FAILED(hr
)) return hr
;
2326 caps
->dwCaps
= caps2
.dwCaps
;
2330 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2332 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2333 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2335 struct wined3d_resource
*resource
;
2337 TRACE("iface %p, priority %u.\n", iface
, priority
);
2339 wined3d_mutex_lock();
2340 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2341 * calls on such surfaces segfault on Windows. */
2342 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2344 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2345 hr
= DDERR_INVALIDPARAMS
;
2349 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2350 wined3d_resource_set_priority(resource
, priority
);
2353 wined3d_mutex_unlock();
2358 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2360 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2361 const struct wined3d_resource
*resource
;
2362 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2365 TRACE("iface %p, priority %p.\n", iface
, priority
);
2367 wined3d_mutex_lock();
2368 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2370 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2371 hr
= DDERR_INVALIDOBJECT
;
2373 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->wined3d_texture
)
2375 WARN("Called on non-managed texture or mipmap sublevel, returning DDERR_INVALIDPARAMS.\n");
2376 hr
= DDERR_INVALIDPARAMS
;
2380 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2381 *priority
= wined3d_resource_get_priority(resource
);
2384 wined3d_mutex_unlock();
2389 /*****************************************************************************
2390 * IDirectDrawSurface7::SetPrivateData
2392 * Stores some data in the surface that is intended for the application's
2396 * tag: GUID that identifies the data
2397 * Data: Pointer to the private data
2398 * Size: Size of the private data
2403 * For more details, see IWineD3DSurface::SetPrivateData
2405 *****************************************************************************/
2406 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2407 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2409 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2412 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2413 iface
, debugstr_guid(tag
), data
, size
, flags
);
2417 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2418 return DDERR_INVALIDPARAMS
;
2421 wined3d_mutex_lock();
2422 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2423 wined3d_mutex_unlock();
2424 return hr_ddraw_from_wined3d(hr
);
2427 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2428 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2430 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2432 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2433 iface
, debugstr_guid(tag
), data
, size
, flags
);
2435 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2438 /*****************************************************************************
2439 * IDirectDrawSurface7::GetPrivateData
2441 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2444 * tag: GUID of the data to return
2445 * Data: Address where to write the data to
2446 * Size: Size of the buffer at Data
2450 * DDERR_INVALIDPARAMS if Data is NULL
2451 * For more details, see IWineD3DSurface::GetPrivateData
2453 *****************************************************************************/
2454 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2456 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2457 const struct wined3d_private_data
*stored_data
;
2460 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2461 iface
, debugstr_guid(tag
), data
, size
);
2463 wined3d_mutex_lock();
2464 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2467 hr
= DDERR_NOTFOUND
;
2472 hr
= DDERR_INVALIDPARAMS
;
2475 if (*size
< stored_data
->size
)
2477 *size
= stored_data
->size
;
2478 hr
= DDERR_MOREDATA
;
2483 hr
= DDERR_INVALIDPARAMS
;
2487 *size
= stored_data
->size
;
2488 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2492 wined3d_mutex_unlock();
2496 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2498 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2500 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2501 iface
, debugstr_guid(tag
), data
, size
);
2503 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2506 /*****************************************************************************
2507 * IDirectDrawSurface7::FreePrivateData
2509 * Frees private data stored in the surface
2512 * tag: Tag of the data to free
2516 * For more details, see IWineD3DSurface::FreePrivateData
2518 *****************************************************************************/
2519 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2521 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2522 struct wined3d_private_data
*entry
;
2524 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2526 wined3d_mutex_lock();
2527 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2530 wined3d_mutex_unlock();
2531 return DDERR_NOTFOUND
;
2534 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2535 wined3d_mutex_unlock();
2540 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2542 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2544 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2546 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2549 /*****************************************************************************
2550 * IDirectDrawSurface7::PageLock
2552 * Prevents a sysmem surface from being paged out
2555 * Flags: Not used, must be 0(unchecked)
2558 * DD_OK, because it's a stub
2560 *****************************************************************************/
2561 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2563 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2565 /* This is Windows memory management related - we don't need this */
2569 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2571 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2573 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2575 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2578 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2580 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2582 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2584 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2587 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2589 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2591 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2593 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2596 /*****************************************************************************
2597 * IDirectDrawSurface7::PageUnlock
2599 * Allows a sysmem surface to be paged out
2602 * Flags: Not used, must be 0(unchecked)
2605 * DD_OK, because it's a stub
2607 *****************************************************************************/
2608 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2610 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2615 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2617 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2619 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2621 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2624 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2626 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2628 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2630 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2633 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2635 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2637 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2639 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2642 /*****************************************************************************
2643 * IDirectDrawSurface7::BltBatch
2645 * An unimplemented function
2653 *****************************************************************************/
2654 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2656 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2658 /* MSDN: "not currently implemented" */
2659 return DDERR_UNSUPPORTED
;
2662 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2664 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2666 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2668 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2671 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2673 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2675 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2677 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2680 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2682 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2684 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2686 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2689 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2691 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2693 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2695 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2698 /*****************************************************************************
2699 * IDirectDrawSurface7::EnumAttachedSurfaces
2701 * Enumerates all surfaces attached to this surface
2704 * context: Pointer to pass unmodified to the callback
2705 * cb: Callback function to call for each surface
2709 * DDERR_INVALIDPARAMS if cb is NULL
2711 *****************************************************************************/
2712 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2713 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2715 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2716 struct ddraw_surface
*surf
;
2717 DDSURFACEDESC2 desc
;
2720 /* Attached surfaces aren't handled in WineD3D */
2721 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2724 return DDERR_INVALIDPARAMS
;
2726 wined3d_mutex_lock();
2728 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2730 surf
= surface
->complex_array
[i
];
2733 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2734 desc
= surf
->surface_desc
;
2735 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2736 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2738 wined3d_mutex_unlock();
2743 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2745 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2746 desc
= surf
->surface_desc
;
2747 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2748 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2750 wined3d_mutex_unlock();
2755 TRACE(" end of enumeration.\n");
2757 wined3d_mutex_unlock();
2762 struct callback_info2
2764 LPDDENUMSURFACESCALLBACK2 callback
;
2768 struct callback_info
2770 LPDDENUMSURFACESCALLBACK callback
;
2774 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2776 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2777 const struct callback_info2
*info
= context
;
2779 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2780 ddraw_surface7_Release(surface
);
2782 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2785 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2787 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2788 const struct callback_info
*info
= context
;
2790 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2791 ddraw_surface7_Release(surface
);
2793 /* FIXME: Check surface_test.dwSize */
2794 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2795 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2798 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2799 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2801 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2802 struct callback_info2 info
;
2804 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2806 info
.callback
= callback
;
2807 info
.context
= context
;
2809 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2810 &info
, EnumCallback2
);
2813 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2814 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2816 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2817 struct callback_info info
;
2819 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2821 info
.callback
= callback
;
2822 info
.context
= context
;
2824 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2825 &info
, EnumCallback
);
2828 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2829 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2831 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2832 struct callback_info info
;
2834 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2836 info
.callback
= callback
;
2837 info
.context
= context
;
2839 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2840 &info
, EnumCallback
);
2843 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2844 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2846 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2847 struct callback_info info
;
2849 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2851 info
.callback
= callback
;
2852 info
.context
= context
;
2854 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2855 &info
, EnumCallback
);
2858 /*****************************************************************************
2859 * IDirectDrawSurface7::EnumOverlayZOrders
2861 * "Enumerates the overlay surfaces on the specified destination"
2864 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2865 * context: context to pass back to the callback
2866 * cb: callback function to call for each enumerated surface
2869 * DD_OK, because it's a stub
2871 *****************************************************************************/
2872 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2873 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2875 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2880 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2881 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2883 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2884 struct callback_info2 info
;
2886 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2888 info
.callback
= callback
;
2889 info
.context
= context
;
2891 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2892 flags
, &info
, EnumCallback2
);
2895 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2896 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2898 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2899 struct callback_info info
;
2901 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2903 info
.callback
= callback
;
2904 info
.context
= context
;
2906 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2907 flags
, &info
, EnumCallback
);
2910 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2911 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2913 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2914 struct callback_info info
;
2916 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2918 info
.callback
= callback
;
2919 info
.context
= context
;
2921 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2922 flags
, &info
, EnumCallback
);
2925 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2926 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2928 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2929 struct callback_info info
;
2931 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2933 info
.callback
= callback
;
2934 info
.context
= context
;
2936 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2937 flags
, &info
, EnumCallback
);
2940 /*****************************************************************************
2941 * IDirectDrawSurface7::GetBltStatus
2943 * Returns the blitting status
2946 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2949 * See IWineD3DSurface::Blt
2951 *****************************************************************************/
2952 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2954 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2958 case WINEDDGBS_CANBLT
:
2959 case WINEDDGBS_ISBLTDONE
:
2963 return DDERR_INVALIDPARAMS
;
2967 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2969 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2971 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2973 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2976 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2978 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2980 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2982 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2985 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2987 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2989 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2991 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2994 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2996 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2998 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3000 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3003 /*****************************************************************************
3004 * IDirectDrawSurface7::GetColorKey
3006 * Returns the color key assigned to the surface
3010 * CKey: Address to store the key to
3014 * DDERR_INVALIDPARAMS if CKey is NULL
3016 *****************************************************************************/
3017 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3019 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3021 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3024 return DDERR_INVALIDPARAMS
;
3026 wined3d_mutex_lock();
3030 case DDCKEY_DESTBLT
:
3031 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3033 wined3d_mutex_unlock();
3034 return DDERR_NOCOLORKEY
;
3036 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3039 case DDCKEY_DESTOVERLAY
:
3040 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3042 wined3d_mutex_unlock();
3043 return DDERR_NOCOLORKEY
;
3045 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3049 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3051 wined3d_mutex_unlock();
3052 return DDERR_NOCOLORKEY
;
3054 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3057 case DDCKEY_SRCOVERLAY
:
3058 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3060 wined3d_mutex_unlock();
3061 return DDERR_NOCOLORKEY
;
3063 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3067 wined3d_mutex_unlock();
3068 return DDERR_INVALIDPARAMS
;
3071 wined3d_mutex_unlock();
3076 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3078 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3080 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3082 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3085 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3087 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3089 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3091 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3094 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3096 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3098 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3100 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3103 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3105 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3107 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3109 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3112 /*****************************************************************************
3113 * IDirectDrawSurface7::GetFlipStatus
3115 * Returns the flipping status of the surface
3118 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3121 * See IWineD3DSurface::GetFlipStatus
3123 *****************************************************************************/
3124 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3126 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3128 /* XXX: DDERR_INVALIDSURFACETYPE */
3132 case WINEDDGFS_CANFLIP
:
3133 case WINEDDGFS_ISFLIPDONE
:
3137 return DDERR_INVALIDPARAMS
;
3141 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3143 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3145 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3147 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3150 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3152 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3154 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3156 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3159 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3161 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3163 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3165 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3168 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3170 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3172 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3174 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3177 /*****************************************************************************
3178 * IDirectDrawSurface7::GetOverlayPosition
3180 * Returns the display coordinates of a visible and active overlay surface
3187 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3188 *****************************************************************************/
3189 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
3191 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3194 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
3196 wined3d_mutex_lock();
3197 hr
= wined3d_surface_get_overlay_position(surface
->wined3d_surface
, X
, Y
);
3198 wined3d_mutex_unlock();
3203 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3205 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3207 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3209 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3212 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3214 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3216 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3218 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3221 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3223 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3225 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3227 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3230 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3232 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3234 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3236 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3239 /*****************************************************************************
3240 * IDirectDrawSurface7::GetPixelFormat
3242 * Returns the pixel format of the Surface
3245 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3246 * format should be written
3250 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3252 *****************************************************************************/
3253 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3255 /* What is DDERR_INVALIDSURFACETYPE for here? */
3256 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3258 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3261 return DDERR_INVALIDPARAMS
;
3263 wined3d_mutex_lock();
3264 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3265 wined3d_mutex_unlock();
3270 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3272 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3274 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3276 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3279 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3281 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3283 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3285 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3288 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3290 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3292 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3294 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3297 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3299 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3301 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3303 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3306 /*****************************************************************************
3307 * IDirectDrawSurface7::GetSurfaceDesc
3309 * Returns the description of this surface
3312 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3317 * DDERR_INVALIDPARAMS if DDSD is NULL
3319 *****************************************************************************/
3320 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3322 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3324 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3327 return DDERR_INVALIDPARAMS
;
3329 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3331 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3332 return DDERR_INVALIDPARAMS
;
3335 wined3d_mutex_lock();
3336 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3337 TRACE("Returning surface desc:\n");
3338 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3339 wined3d_mutex_unlock();
3344 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3346 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3348 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3350 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3353 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3355 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3357 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3359 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3361 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3363 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3364 return DDERR_INVALIDPARAMS
;
3367 wined3d_mutex_lock();
3368 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3369 TRACE("Returning surface desc:\n");
3370 if (TRACE_ON(ddraw
))
3372 /* DDRAW_dump_surface_desc handles the smaller size */
3373 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3375 wined3d_mutex_unlock();
3380 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3382 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3384 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3386 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3389 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3391 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3393 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3395 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3398 /*****************************************************************************
3399 * IDirectDrawSurface7::Initialize
3401 * Initializes the surface. This is a no-op in Wine
3404 * DD: Pointer to an DirectDraw interface
3405 * DDSD: Surface description for initialization
3408 * DDERR_ALREADYINITIALIZED
3410 *****************************************************************************/
3411 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3412 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3414 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3416 return DDERR_ALREADYINITIALIZED
;
3419 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3420 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3422 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3424 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3426 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3427 ddraw
, surface_desc
);
3430 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3431 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3433 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3434 DDSURFACEDESC2 surface_desc2
;
3436 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3438 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3439 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3440 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3443 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3444 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3446 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3447 DDSURFACEDESC2 surface_desc2
;
3449 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3451 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3452 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3453 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3456 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3457 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3459 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3460 DDSURFACEDESC2 surface_desc2
;
3462 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3464 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3465 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3466 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3469 /*****************************************************************************
3470 * IDirect3DTexture1::Initialize
3472 * The sdk says it's not implemented
3480 *****************************************************************************/
3481 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3482 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3484 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3486 return DDERR_UNSUPPORTED
; /* Unchecked */
3489 /*****************************************************************************
3490 * IDirectDrawSurface7::IsLost
3492 * Checks if the surface is lost
3495 * DD_OK, if the surface is usable
3496 * DDERR_ISLOST if the surface is lost
3497 * See IWineD3DSurface::IsLost for more details
3499 *****************************************************************************/
3500 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3502 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3505 TRACE("iface %p.\n", iface
);
3507 wined3d_mutex_lock();
3508 hr
= wined3d_surface_is_lost(surface
->wined3d_surface
);
3509 wined3d_mutex_unlock();
3513 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3514 * WineD3D uses the same error for surfaces
3516 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3521 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3523 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3525 TRACE("iface %p.\n", iface
);
3527 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3530 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3532 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3534 TRACE("iface %p.\n", iface
);
3536 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3539 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3541 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3543 TRACE("iface %p.\n", iface
);
3545 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3548 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3550 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3552 TRACE("iface %p.\n", iface
);
3554 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3557 /*****************************************************************************
3558 * IDirectDrawSurface7::Restore
3560 * Restores a lost surface. This makes the surface usable again, but
3561 * doesn't reload its old contents
3565 * See IWineD3DSurface::Restore for more details
3567 *****************************************************************************/
3568 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3570 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3573 TRACE("iface %p.\n", iface
);
3575 wined3d_mutex_lock();
3576 hr
= wined3d_surface_restore(surface
->wined3d_surface
);
3577 wined3d_mutex_unlock();
3582 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3584 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3586 TRACE("iface %p.\n", iface
);
3588 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3591 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3593 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3595 TRACE("iface %p.\n", iface
);
3597 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3600 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3602 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3604 TRACE("iface %p.\n", iface
);
3606 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3609 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3611 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3613 TRACE("iface %p.\n", iface
);
3615 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3618 /*****************************************************************************
3619 * IDirectDrawSurface7::SetOverlayPosition
3621 * Changes the display coordinates of an overlay surface
3628 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3629 *****************************************************************************/
3630 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3632 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3635 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3637 wined3d_mutex_lock();
3638 hr
= wined3d_surface_set_overlay_position(surface
->wined3d_surface
, X
, Y
);
3639 wined3d_mutex_unlock();
3644 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3646 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3648 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3650 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3653 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3655 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3657 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3659 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3662 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3664 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3666 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3668 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3671 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3673 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3675 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3677 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3680 /*****************************************************************************
3681 * IDirectDrawSurface7::UpdateOverlay
3683 * Modifies the attributes of an overlay surface.
3686 * SrcRect: The section of the source being used for the overlay
3687 * DstSurface: Address of the surface that is overlaid
3688 * DstRect: Place of the overlay
3689 * Flags: some DDOVER_* flags
3692 * DDERR_UNSUPPORTED, because we don't support overlays
3694 *****************************************************************************/
3695 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3696 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3698 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3699 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3702 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3703 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3705 wined3d_mutex_lock();
3706 hr
= wined3d_surface_update_overlay(src_impl
->wined3d_surface
, SrcRect
,
3707 dst_impl
? dst_impl
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3708 wined3d_mutex_unlock();
3711 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3712 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3713 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3719 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3720 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3722 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3723 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3725 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3726 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3728 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3729 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3732 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3733 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3735 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3736 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3738 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3739 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3741 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3742 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3745 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3746 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3748 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3749 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3751 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3752 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3754 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3755 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3758 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3759 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3761 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3762 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3764 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3765 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3767 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3768 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3771 /*****************************************************************************
3772 * IDirectDrawSurface7::UpdateOverlayDisplay
3774 * The DX7 sdk says that it's not implemented
3779 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3781 *****************************************************************************/
3782 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3784 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3786 return DDERR_UNSUPPORTED
;
3789 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3791 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3793 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3795 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3798 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3800 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3802 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3804 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3807 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3809 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3811 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3813 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3816 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3818 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3820 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3822 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3825 /*****************************************************************************
3826 * IDirectDrawSurface7::UpdateOverlayZOrder
3828 * Sets an overlay's Z order
3831 * Flags: DDOVERZ_* flags
3832 * DDSRef: Defines the relative position in the overlay chain
3835 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3837 *****************************************************************************/
3838 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3839 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3841 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3842 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3845 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3847 wined3d_mutex_lock();
3848 hr
= wined3d_surface_update_overlay_z_order(surface
->wined3d_surface
,
3849 Flags
, reference_impl
? reference_impl
->wined3d_surface
: NULL
);
3850 wined3d_mutex_unlock();
3855 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3856 DWORD flags
, IDirectDrawSurface4
*reference
)
3858 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3859 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3861 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3863 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3864 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3867 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3868 DWORD flags
, IDirectDrawSurface3
*reference
)
3870 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3871 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3873 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3875 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3876 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3879 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3880 DWORD flags
, IDirectDrawSurface2
*reference
)
3882 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3883 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3885 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3887 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3888 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3891 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3892 DWORD flags
, IDirectDrawSurface
*reference
)
3894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3895 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3897 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3899 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3900 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3903 /*****************************************************************************
3904 * IDirectDrawSurface7::GetDDInterface
3906 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3907 * surface belongs to
3910 * DD: Address to write the interface pointer to
3914 * DDERR_INVALIDPARAMS if DD is NULL
3916 *****************************************************************************/
3917 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3919 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3921 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3924 return DDERR_INVALIDPARAMS
;
3926 switch(This
->version
)
3929 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3933 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3937 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3941 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3945 IUnknown_AddRef((IUnknown
*)*DD
);
3950 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3952 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3954 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3956 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3959 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3961 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3963 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3965 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3968 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3970 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3972 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3974 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3977 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3979 TRACE("iface %p.\n", iface
);
3984 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3986 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3988 TRACE("iface %p.\n", iface
);
3990 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
3993 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3995 TRACE("iface %p, value %p.\n", iface
, pValue
);
4002 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4004 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4006 TRACE("iface %p, value %p.\n", iface
, pValue
);
4008 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4011 /*****************************************************************************
4012 * IDirectDrawSurface7::SetLOD
4014 * Sets the level of detail of a texture
4017 * MaxLOD: LOD to set
4021 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4023 *****************************************************************************/
4024 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4026 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4029 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4031 wined3d_mutex_lock();
4032 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4034 wined3d_mutex_unlock();
4035 return DDERR_INVALIDOBJECT
;
4038 if (!surface
->wined3d_texture
)
4040 ERR("The ddraw surface has no wined3d texture.\n");
4041 wined3d_mutex_unlock();
4042 return DDERR_INVALIDOBJECT
;
4045 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4046 wined3d_mutex_unlock();
4051 /*****************************************************************************
4052 * IDirectDrawSurface7::GetLOD
4054 * Returns the level of detail of a Direct3D texture
4057 * MaxLOD: Address to write the LOD to
4061 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4062 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4064 *****************************************************************************/
4065 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4067 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4069 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4072 return DDERR_INVALIDPARAMS
;
4074 wined3d_mutex_lock();
4075 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4077 wined3d_mutex_unlock();
4078 return DDERR_INVALIDOBJECT
;
4081 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4082 wined3d_mutex_unlock();
4087 /*****************************************************************************
4088 * IDirectDrawSurface7::BltFast
4090 * Performs a fast Blit.
4093 * dstx: The x coordinate to blit to on the destination
4094 * dsty: The y coordinate to blit to on the destination
4095 * Source: The source surface
4096 * rsrc: The source rectangle
4097 * trans: Type of transfer. Some DDBLTFAST_* flags
4101 * For more details, see IWineD3DSurface::BltFast
4103 *****************************************************************************/
4104 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
4105 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
4107 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4108 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
4109 DWORD src_w
, src_h
, dst_w
, dst_h
;
4114 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4115 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
4117 dst_w
= This
->surface_desc
.dwWidth
;
4118 dst_h
= This
->surface_desc
.dwHeight
;
4120 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
4125 src_w
= rsrc
->right
- rsrc
->left
;
4126 src_h
= rsrc
->bottom
- rsrc
->top
;
4130 src_w
= src
->surface_desc
.dwWidth
;
4131 src_h
= src
->surface_desc
.dwHeight
;
4134 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
4135 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
4137 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4138 return DDERR_INVALIDRECT
;
4141 SetRect(&dst_rect
, dstx
, dsty
, dstx
+ src_w
, dsty
+ src_h
);
4142 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4143 flags
|= WINEDDBLT_KEYSRC
;
4144 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4145 flags
|= WINEDDBLT_KEYDEST
;
4146 if (trans
& DDBLTFAST_WAIT
)
4147 flags
|= WINEDDBLT_WAIT
;
4148 if (trans
& DDBLTFAST_DONOTWAIT
)
4149 flags
|= WINEDDBLT_DONOTWAIT
;
4151 wined3d_mutex_lock();
4154 wined3d_mutex_unlock();
4155 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4156 return DDERR_BLTFASTCANTCLIP
;
4159 if (src
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4160 hr
= ddraw_surface_update_frontbuffer(src
, rsrc
, TRUE
);
4162 hr
= wined3d_surface_blt(This
->wined3d_surface
, &dst_rect
,
4163 src
->wined3d_surface
, rsrc
, flags
, NULL
, WINED3D_TEXF_POINT
);
4164 if (SUCCEEDED(hr
) && (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4165 hr
= ddraw_surface_update_frontbuffer(This
, &dst_rect
, FALSE
);
4166 wined3d_mutex_unlock();
4170 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4171 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
4176 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4177 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4179 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4180 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4182 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4183 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4185 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4186 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4189 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4190 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4192 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4193 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4195 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4196 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4198 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4199 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4202 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4203 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4205 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4206 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4208 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4209 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4211 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4212 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4215 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4216 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4218 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4219 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4221 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4222 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4224 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4225 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4228 /*****************************************************************************
4229 * IDirectDrawSurface7::GetClipper
4231 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4235 * Clipper: Address to store the interface pointer at
4239 * DDERR_INVALIDPARAMS if Clipper is NULL
4240 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4242 *****************************************************************************/
4243 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4245 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4247 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4250 return DDERR_INVALIDPARAMS
;
4252 wined3d_mutex_lock();
4253 if (!surface
->clipper
)
4255 wined3d_mutex_unlock();
4256 return DDERR_NOCLIPPERATTACHED
;
4259 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4260 IDirectDrawClipper_AddRef(*Clipper
);
4261 wined3d_mutex_unlock();
4266 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4268 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4270 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4272 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4275 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4277 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4279 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4281 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4284 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4286 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4288 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4290 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4293 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4295 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4297 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4299 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4302 /*****************************************************************************
4303 * IDirectDrawSurface7::SetClipper
4305 * Sets a clipper for the surface
4308 * Clipper: IDirectDrawClipper interface of the clipper to set
4313 *****************************************************************************/
4314 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4315 IDirectDrawClipper
*iclipper
)
4317 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4318 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4319 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4322 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4324 wined3d_mutex_lock();
4325 if (clipper
== This
->clipper
)
4327 wined3d_mutex_unlock();
4331 This
->clipper
= clipper
;
4333 if (clipper
!= NULL
)
4334 IDirectDrawClipper_AddRef(iclipper
);
4336 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4338 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4342 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4347 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4348 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4352 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4353 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4357 wined3d_mutex_unlock();
4362 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4364 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4366 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4368 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4371 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4373 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4375 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4377 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4380 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4382 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4384 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4386 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4389 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4391 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4393 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4395 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4398 /*****************************************************************************
4399 * IDirectDrawSurface7::SetSurfaceDesc
4401 * Sets the surface description. It can override the pixel format, the surface
4403 * It's not really tested.
4406 * DDSD: Pointer to the new surface description to set
4411 * DDERR_INVALIDPARAMS if DDSD is NULL
4413 *****************************************************************************/
4414 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4416 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4418 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4419 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4420 enum wined3d_format_id format_id
;
4421 UINT pitch
, width
, height
;
4423 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4427 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4428 return DDERR_INVALIDPARAMS
;
4432 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4433 return DDERR_INVALIDPARAMS
;
4435 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4436 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4437 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4439 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4440 return DDERR_INVALIDSURFACETYPE
;
4443 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4444 * for PIXELFORMAT to work */
4445 if (DDSD
->dwFlags
& ~allowed_flags
)
4447 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4448 return DDERR_INVALIDPARAMS
;
4450 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4452 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4453 return DDERR_INVALIDPARAMS
;
4455 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4457 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4458 return DDERR_INVALIDCAPS
;
4460 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4462 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4464 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4465 return DDERR_INVALIDPARAMS
;
4467 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4469 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4470 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4471 return DDERR_INVALIDPARAMS
;
4473 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4474 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4475 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4476 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4477 pitch
= DDSD
->u1
.lPitch
;
4478 width
= DDSD
->dwWidth
;
4480 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4482 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4483 return DDERR_INVALIDPARAMS
;
4487 pitch
= This
->surface_desc
.u1
.lPitch
;
4488 width
= This
->surface_desc
.dwWidth
;
4491 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4493 if (!DDSD
->dwHeight
)
4495 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4496 return DDERR_INVALIDPARAMS
;
4498 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4499 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4500 height
= DDSD
->dwHeight
;
4504 height
= This
->surface_desc
.dwHeight
;
4507 wined3d_mutex_lock();
4508 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4510 enum wined3d_format_id current_format_id
;
4511 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4513 if (format_id
== WINED3DFMT_UNKNOWN
)
4515 ERR("Requested to set an unknown pixelformat\n");
4516 wined3d_mutex_unlock();
4517 return DDERR_INVALIDPARAMS
;
4519 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4520 if (format_id
!= current_format_id
)
4521 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4525 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4528 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4529 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4531 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4532 wined3d_mutex_unlock();
4533 return hr_ddraw_from_wined3d(hr
);
4536 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4537 This
->surface_desc
.dwWidth
= width
;
4538 if (DDSD
->dwFlags
& DDSD_PITCH
)
4539 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4540 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4541 This
->surface_desc
.dwHeight
= height
;
4542 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4543 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4545 wined3d_mutex_unlock();
4550 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4551 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4553 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4555 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4557 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4558 surface_desc
, flags
);
4561 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4562 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4564 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4565 DDSURFACEDESC2 surface_desc2
;
4567 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4569 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4570 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4571 surface_desc
? &surface_desc2
: NULL
, flags
);
4574 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4576 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4577 struct ddraw_palette
*palette_impl
;
4580 TRACE("iface %p, palette %p.\n", iface
, palette
);
4583 return DDERR_INVALIDPARAMS
;
4584 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4586 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4587 return DDERR_SURFACELOST
;
4590 wined3d_mutex_lock();
4591 if ((palette_impl
= surface
->palette
))
4593 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4594 IDirectDrawPalette_AddRef(*palette
);
4599 hr
= DDERR_NOPALETTEATTACHED
;
4601 wined3d_mutex_unlock();
4606 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4608 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4610 TRACE("iface %p, palette %p.\n", iface
, palette
);
4612 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4615 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4617 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4619 TRACE("iface %p, palette %p.\n", iface
, palette
);
4621 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4624 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4626 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4628 TRACE("iface %p, palette %p.\n", iface
, palette
);
4630 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4633 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4635 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4637 TRACE("iface %p, palette %p.\n", iface
, palette
);
4639 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4642 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4644 DDCOLORKEY fixed_color_key
;
4645 HRESULT hr
= WINED3D_OK
;
4647 if (flags
& DDCKEY_COLORSPACE
)
4649 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4651 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4652 return DDERR_NOCOLORKEYHW
;
4654 flags
&= ~DDCKEY_COLORSPACE
;
4657 wined3d_mutex_lock();
4661 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4662 switch (flags
& ~DDCKEY_COLORSPACE
)
4664 case DDCKEY_DESTBLT
:
4665 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4666 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4669 case DDCKEY_DESTOVERLAY
:
4670 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4671 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4674 case DDCKEY_SRCOVERLAY
:
4675 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4676 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4680 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4681 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4685 wined3d_mutex_unlock();
4686 return DDERR_INVALIDPARAMS
;
4691 switch (flags
& ~DDCKEY_COLORSPACE
)
4693 case DDCKEY_DESTBLT
:
4694 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4697 case DDCKEY_DESTOVERLAY
:
4698 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4701 case DDCKEY_SRCOVERLAY
:
4702 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4706 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4710 wined3d_mutex_unlock();
4711 return DDERR_INVALIDPARAMS
;
4715 if (surface
->wined3d_texture
)
4716 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4717 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4719 wined3d_mutex_unlock();
4721 return hr_ddraw_from_wined3d(hr
);
4724 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4726 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4728 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4730 wined3d_mutex_lock();
4731 if (!surface
->wined3d_texture
)
4733 wined3d_mutex_unlock();
4734 return DDERR_NOTONMIPMAPSUBLEVEL
;
4736 wined3d_mutex_unlock();
4738 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4741 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4743 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4745 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4747 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4750 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4752 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4754 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4756 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4759 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4761 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4763 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4765 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4768 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4770 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4772 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4774 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4777 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4779 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4781 TRACE("iface %p, palette %p.\n", iface
, palette
);
4783 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4784 return DDERR_NOTONMIPMAPSUBLEVEL
;
4785 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4787 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4788 return DDERR_SURFACELOST
;
4791 return ddraw_surface_set_palette(surface
, palette
);
4794 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4796 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4798 TRACE("iface %p, palette %p.\n", iface
, palette
);
4800 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4802 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4803 return DDERR_SURFACELOST
;
4806 return ddraw_surface_set_palette(surface
, palette
);
4809 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4811 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4813 TRACE("iface %p, palette %p.\n", iface
, palette
);
4815 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4817 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4818 return DDERR_SURFACELOST
;
4821 return ddraw_surface_set_palette(surface
, palette
);
4824 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4826 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4828 TRACE("iface %p, palette %p.\n", iface
, palette
);
4830 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4832 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4833 return DDERR_SURFACELOST
;
4836 return ddraw_surface_set_palette(surface
, palette
);
4839 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4841 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4843 TRACE("iface %p, palette %p.\n", iface
, palette
);
4845 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4847 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4848 return DDERR_SURFACELOST
;
4851 return ddraw_surface_set_palette(surface
, palette
);
4854 /**********************************************************
4855 * IDirectDrawGammaControl::GetGammaRamp
4857 * Returns the current gamma ramp for a surface
4861 * gamma_ramp: Address to write the ramp to
4865 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4867 **********************************************************/
4868 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4869 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4871 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4873 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4877 WARN("Invalid gamma_ramp passed.\n");
4878 return DDERR_INVALIDPARAMS
;
4881 wined3d_mutex_lock();
4882 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4884 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4885 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4889 ERR("Not implemented for non-primary surfaces.\n");
4891 wined3d_mutex_unlock();
4896 /**********************************************************
4897 * IDirectDrawGammaControl::SetGammaRamp
4899 * Sets the red, green and blue gamma ramps for
4902 * flags: Can be DDSGR_CALIBRATE to request calibration
4903 * gamma_ramp: Structure containing the new gamma ramp
4907 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4909 **********************************************************/
4910 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4911 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4913 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4915 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4919 WARN("Invalid gamma_ramp passed.\n");
4920 return DDERR_INVALIDPARAMS
;
4923 wined3d_mutex_lock();
4924 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4926 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4927 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4928 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4932 ERR("Not implemented for non-primary surfaces.\n");
4934 wined3d_mutex_unlock();
4939 /*****************************************************************************
4940 * IDirect3DTexture2::PaletteChanged
4942 * Informs the texture about a palette change
4945 * start: Start index of the change
4946 * count: The number of changed entries
4949 * D3D_OK, because it's a stub
4951 *****************************************************************************/
4952 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4954 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4959 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4961 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4963 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4965 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4968 /*****************************************************************************
4969 * IDirect3DTexture::Unload
4971 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4977 *****************************************************************************/
4978 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4980 WARN("iface %p. Not implemented.\n", iface
);
4982 return DDERR_UNSUPPORTED
;
4985 /*****************************************************************************
4986 * IDirect3DTexture2::GetHandle
4988 * Returns handle for the texture. At the moment, the interface
4989 * to the IWineD3DTexture is used.
4992 * device: Device this handle is assigned to
4993 * handle: Address to store the handle at.
4998 *****************************************************************************/
4999 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5000 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5002 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5003 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5005 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5007 wined3d_mutex_lock();
5009 if (!surface
->Handle
)
5011 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5012 if (h
== DDRAW_INVALID_HANDLE
)
5014 ERR("Failed to allocate a texture handle.\n");
5015 wined3d_mutex_unlock();
5016 return DDERR_OUTOFMEMORY
;
5019 surface
->Handle
= h
+ 1;
5022 TRACE("Returning handle %08x.\n", surface
->Handle
);
5023 *handle
= surface
->Handle
;
5025 wined3d_mutex_unlock();
5030 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5031 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5033 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5034 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5036 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5038 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5039 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5042 /*****************************************************************************
5043 * get_sub_mimaplevel
5045 * Helper function that returns the next mipmap level
5047 * tex_ptr: Surface of which to return the next level
5049 *****************************************************************************/
5050 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5052 /* Now go down the mipmap chain to the next surface */
5053 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5054 IDirectDrawSurface7
*next_level
;
5057 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5058 if (FAILED(hr
)) return NULL
;
5060 ddraw_surface7_Release(next_level
);
5062 return impl_from_IDirectDrawSurface7(next_level
);
5065 /*****************************************************************************
5066 * IDirect3DTexture2::Load
5068 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5070 * This function isn't relayed to WineD3D because the whole interface is
5071 * implemented in DDraw only. For speed improvements an implementation which
5072 * takes OpenGL more into account could be placed into WineD3D.
5075 * src_texture: Address of the texture to load
5079 * D3DERR_TEXTURE_LOAD_FAILED.
5081 *****************************************************************************/
5082 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5084 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5085 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5088 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5090 if (src_surface
== dst_surface
)
5092 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5096 wined3d_mutex_lock();
5098 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5099 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5100 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5102 ERR("Trying to load surfaces with different mip-map counts.\n");
5107 struct ddraw_palette
*dst_pal
, *src_pal
;
5108 DDSURFACEDESC
*src_desc
, *dst_desc
;
5110 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5112 /* Suppress the ALLOCONLOAD flag */
5113 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5115 /* Get the palettes */
5116 dst_pal
= dst_surface
->palette
;
5117 src_pal
= src_surface
->palette
;
5121 PALETTEENTRY palent
[256];
5125 wined3d_mutex_unlock();
5126 return DDERR_NOPALETTEATTACHED
;
5128 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5129 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5132 /* Copy one surface on the other */
5133 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5134 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5136 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5138 /* Should also check for same pixel format, u1.lPitch, ... */
5139 ERR("Error in surface sizes.\n");
5140 wined3d_mutex_unlock();
5141 return D3DERR_TEXTURE_LOAD_FAILED
;
5145 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5147 /* Copy the src blit color key if the source has one, don't erase
5148 * the destination's ckey if the source has none */
5149 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5151 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5152 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5155 /* Copy the main memory texture into the surface that corresponds
5156 * to the OpenGL texture object. */
5158 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_map_desc
, NULL
, 0);
5161 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5162 wined3d_mutex_unlock();
5163 return D3DERR_TEXTURE_LOAD_FAILED
;
5166 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_map_desc
, NULL
, 0);
5169 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5170 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5171 wined3d_mutex_unlock();
5172 return D3DERR_TEXTURE_LOAD_FAILED
;
5175 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5176 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5178 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5180 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5181 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
5184 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5185 src_surface
= get_sub_mimaplevel(src_surface
);
5189 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5190 dst_surface
= get_sub_mimaplevel(dst_surface
);
5194 if (!src_surface
|| !dst_surface
)
5196 if (src_surface
!= dst_surface
)
5197 ERR("Loading surface with different mipmap structure.\n");
5202 wined3d_mutex_unlock();
5207 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5209 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5210 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5212 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5214 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5215 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5218 /*****************************************************************************
5220 *****************************************************************************/
5222 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5225 ddraw_surface7_QueryInterface
,
5226 ddraw_surface7_AddRef
,
5227 ddraw_surface7_Release
,
5228 /* IDirectDrawSurface */
5229 ddraw_surface7_AddAttachedSurface
,
5230 ddraw_surface7_AddOverlayDirtyRect
,
5232 ddraw_surface7_BltBatch
,
5233 ddraw_surface7_BltFast
,
5234 ddraw_surface7_DeleteAttachedSurface
,
5235 ddraw_surface7_EnumAttachedSurfaces
,
5236 ddraw_surface7_EnumOverlayZOrders
,
5237 ddraw_surface7_Flip
,
5238 ddraw_surface7_GetAttachedSurface
,
5239 ddraw_surface7_GetBltStatus
,
5240 ddraw_surface7_GetCaps
,
5241 ddraw_surface7_GetClipper
,
5242 ddraw_surface7_GetColorKey
,
5243 ddraw_surface7_GetDC
,
5244 ddraw_surface7_GetFlipStatus
,
5245 ddraw_surface7_GetOverlayPosition
,
5246 ddraw_surface7_GetPalette
,
5247 ddraw_surface7_GetPixelFormat
,
5248 ddraw_surface7_GetSurfaceDesc
,
5249 ddraw_surface7_Initialize
,
5250 ddraw_surface7_IsLost
,
5251 ddraw_surface7_Lock
,
5252 ddraw_surface7_ReleaseDC
,
5253 ddraw_surface7_Restore
,
5254 ddraw_surface7_SetClipper
,
5255 ddraw_surface7_SetColorKey
,
5256 ddraw_surface7_SetOverlayPosition
,
5257 ddraw_surface7_SetPalette
,
5258 ddraw_surface7_Unlock
,
5259 ddraw_surface7_UpdateOverlay
,
5260 ddraw_surface7_UpdateOverlayDisplay
,
5261 ddraw_surface7_UpdateOverlayZOrder
,
5262 /* IDirectDrawSurface2 */
5263 ddraw_surface7_GetDDInterface
,
5264 ddraw_surface7_PageLock
,
5265 ddraw_surface7_PageUnlock
,
5266 /* IDirectDrawSurface3 */
5267 ddraw_surface7_SetSurfaceDesc
,
5268 /* IDirectDrawSurface4 */
5269 ddraw_surface7_SetPrivateData
,
5270 ddraw_surface7_GetPrivateData
,
5271 ddraw_surface7_FreePrivateData
,
5272 ddraw_surface7_GetUniquenessValue
,
5273 ddraw_surface7_ChangeUniquenessValue
,
5274 /* IDirectDrawSurface7 */
5275 ddraw_surface7_SetPriority
,
5276 ddraw_surface7_GetPriority
,
5277 ddraw_surface7_SetLOD
,
5278 ddraw_surface7_GetLOD
,
5281 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5284 ddraw_surface4_QueryInterface
,
5285 ddraw_surface4_AddRef
,
5286 ddraw_surface4_Release
,
5287 /* IDirectDrawSurface */
5288 ddraw_surface4_AddAttachedSurface
,
5289 ddraw_surface4_AddOverlayDirtyRect
,
5291 ddraw_surface4_BltBatch
,
5292 ddraw_surface4_BltFast
,
5293 ddraw_surface4_DeleteAttachedSurface
,
5294 ddraw_surface4_EnumAttachedSurfaces
,
5295 ddraw_surface4_EnumOverlayZOrders
,
5296 ddraw_surface4_Flip
,
5297 ddraw_surface4_GetAttachedSurface
,
5298 ddraw_surface4_GetBltStatus
,
5299 ddraw_surface4_GetCaps
,
5300 ddraw_surface4_GetClipper
,
5301 ddraw_surface4_GetColorKey
,
5302 ddraw_surface4_GetDC
,
5303 ddraw_surface4_GetFlipStatus
,
5304 ddraw_surface4_GetOverlayPosition
,
5305 ddraw_surface4_GetPalette
,
5306 ddraw_surface4_GetPixelFormat
,
5307 ddraw_surface4_GetSurfaceDesc
,
5308 ddraw_surface4_Initialize
,
5309 ddraw_surface4_IsLost
,
5310 ddraw_surface4_Lock
,
5311 ddraw_surface4_ReleaseDC
,
5312 ddraw_surface4_Restore
,
5313 ddraw_surface4_SetClipper
,
5314 ddraw_surface4_SetColorKey
,
5315 ddraw_surface4_SetOverlayPosition
,
5316 ddraw_surface4_SetPalette
,
5317 ddraw_surface4_Unlock
,
5318 ddraw_surface4_UpdateOverlay
,
5319 ddraw_surface4_UpdateOverlayDisplay
,
5320 ddraw_surface4_UpdateOverlayZOrder
,
5321 /* IDirectDrawSurface2 */
5322 ddraw_surface4_GetDDInterface
,
5323 ddraw_surface4_PageLock
,
5324 ddraw_surface4_PageUnlock
,
5325 /* IDirectDrawSurface3 */
5326 ddraw_surface4_SetSurfaceDesc
,
5327 /* IDirectDrawSurface4 */
5328 ddraw_surface4_SetPrivateData
,
5329 ddraw_surface4_GetPrivateData
,
5330 ddraw_surface4_FreePrivateData
,
5331 ddraw_surface4_GetUniquenessValue
,
5332 ddraw_surface4_ChangeUniquenessValue
,
5335 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5338 ddraw_surface3_QueryInterface
,
5339 ddraw_surface3_AddRef
,
5340 ddraw_surface3_Release
,
5341 /* IDirectDrawSurface */
5342 ddraw_surface3_AddAttachedSurface
,
5343 ddraw_surface3_AddOverlayDirtyRect
,
5345 ddraw_surface3_BltBatch
,
5346 ddraw_surface3_BltFast
,
5347 ddraw_surface3_DeleteAttachedSurface
,
5348 ddraw_surface3_EnumAttachedSurfaces
,
5349 ddraw_surface3_EnumOverlayZOrders
,
5350 ddraw_surface3_Flip
,
5351 ddraw_surface3_GetAttachedSurface
,
5352 ddraw_surface3_GetBltStatus
,
5353 ddraw_surface3_GetCaps
,
5354 ddraw_surface3_GetClipper
,
5355 ddraw_surface3_GetColorKey
,
5356 ddraw_surface3_GetDC
,
5357 ddraw_surface3_GetFlipStatus
,
5358 ddraw_surface3_GetOverlayPosition
,
5359 ddraw_surface3_GetPalette
,
5360 ddraw_surface3_GetPixelFormat
,
5361 ddraw_surface3_GetSurfaceDesc
,
5362 ddraw_surface3_Initialize
,
5363 ddraw_surface3_IsLost
,
5364 ddraw_surface3_Lock
,
5365 ddraw_surface3_ReleaseDC
,
5366 ddraw_surface3_Restore
,
5367 ddraw_surface3_SetClipper
,
5368 ddraw_surface3_SetColorKey
,
5369 ddraw_surface3_SetOverlayPosition
,
5370 ddraw_surface3_SetPalette
,
5371 ddraw_surface3_Unlock
,
5372 ddraw_surface3_UpdateOverlay
,
5373 ddraw_surface3_UpdateOverlayDisplay
,
5374 ddraw_surface3_UpdateOverlayZOrder
,
5375 /* IDirectDrawSurface2 */
5376 ddraw_surface3_GetDDInterface
,
5377 ddraw_surface3_PageLock
,
5378 ddraw_surface3_PageUnlock
,
5379 /* IDirectDrawSurface3 */
5380 ddraw_surface3_SetSurfaceDesc
,
5383 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5386 ddraw_surface2_QueryInterface
,
5387 ddraw_surface2_AddRef
,
5388 ddraw_surface2_Release
,
5389 /* IDirectDrawSurface */
5390 ddraw_surface2_AddAttachedSurface
,
5391 ddraw_surface2_AddOverlayDirtyRect
,
5393 ddraw_surface2_BltBatch
,
5394 ddraw_surface2_BltFast
,
5395 ddraw_surface2_DeleteAttachedSurface
,
5396 ddraw_surface2_EnumAttachedSurfaces
,
5397 ddraw_surface2_EnumOverlayZOrders
,
5398 ddraw_surface2_Flip
,
5399 ddraw_surface2_GetAttachedSurface
,
5400 ddraw_surface2_GetBltStatus
,
5401 ddraw_surface2_GetCaps
,
5402 ddraw_surface2_GetClipper
,
5403 ddraw_surface2_GetColorKey
,
5404 ddraw_surface2_GetDC
,
5405 ddraw_surface2_GetFlipStatus
,
5406 ddraw_surface2_GetOverlayPosition
,
5407 ddraw_surface2_GetPalette
,
5408 ddraw_surface2_GetPixelFormat
,
5409 ddraw_surface2_GetSurfaceDesc
,
5410 ddraw_surface2_Initialize
,
5411 ddraw_surface2_IsLost
,
5412 ddraw_surface2_Lock
,
5413 ddraw_surface2_ReleaseDC
,
5414 ddraw_surface2_Restore
,
5415 ddraw_surface2_SetClipper
,
5416 ddraw_surface2_SetColorKey
,
5417 ddraw_surface2_SetOverlayPosition
,
5418 ddraw_surface2_SetPalette
,
5419 ddraw_surface2_Unlock
,
5420 ddraw_surface2_UpdateOverlay
,
5421 ddraw_surface2_UpdateOverlayDisplay
,
5422 ddraw_surface2_UpdateOverlayZOrder
,
5423 /* IDirectDrawSurface2 */
5424 ddraw_surface2_GetDDInterface
,
5425 ddraw_surface2_PageLock
,
5426 ddraw_surface2_PageUnlock
,
5429 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5432 ddraw_surface1_QueryInterface
,
5433 ddraw_surface1_AddRef
,
5434 ddraw_surface1_Release
,
5435 /* IDirectDrawSurface */
5436 ddraw_surface1_AddAttachedSurface
,
5437 ddraw_surface1_AddOverlayDirtyRect
,
5439 ddraw_surface1_BltBatch
,
5440 ddraw_surface1_BltFast
,
5441 ddraw_surface1_DeleteAttachedSurface
,
5442 ddraw_surface1_EnumAttachedSurfaces
,
5443 ddraw_surface1_EnumOverlayZOrders
,
5444 ddraw_surface1_Flip
,
5445 ddraw_surface1_GetAttachedSurface
,
5446 ddraw_surface1_GetBltStatus
,
5447 ddraw_surface1_GetCaps
,
5448 ddraw_surface1_GetClipper
,
5449 ddraw_surface1_GetColorKey
,
5450 ddraw_surface1_GetDC
,
5451 ddraw_surface1_GetFlipStatus
,
5452 ddraw_surface1_GetOverlayPosition
,
5453 ddraw_surface1_GetPalette
,
5454 ddraw_surface1_GetPixelFormat
,
5455 ddraw_surface1_GetSurfaceDesc
,
5456 ddraw_surface1_Initialize
,
5457 ddraw_surface1_IsLost
,
5458 ddraw_surface1_Lock
,
5459 ddraw_surface1_ReleaseDC
,
5460 ddraw_surface1_Restore
,
5461 ddraw_surface1_SetClipper
,
5462 ddraw_surface1_SetColorKey
,
5463 ddraw_surface1_SetOverlayPosition
,
5464 ddraw_surface1_SetPalette
,
5465 ddraw_surface1_Unlock
,
5466 ddraw_surface1_UpdateOverlay
,
5467 ddraw_surface1_UpdateOverlayDisplay
,
5468 ddraw_surface1_UpdateOverlayZOrder
,
5471 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5473 ddraw_gamma_control_QueryInterface
,
5474 ddraw_gamma_control_AddRef
,
5475 ddraw_gamma_control_Release
,
5476 ddraw_gamma_control_GetGammaRamp
,
5477 ddraw_gamma_control_SetGammaRamp
,
5480 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5482 d3d_texture2_QueryInterface
,
5483 d3d_texture2_AddRef
,
5484 d3d_texture2_Release
,
5485 d3d_texture2_GetHandle
,
5486 d3d_texture2_PaletteChanged
,
5490 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5492 d3d_texture1_QueryInterface
,
5493 d3d_texture1_AddRef
,
5494 d3d_texture1_Release
,
5495 d3d_texture1_Initialize
,
5496 d3d_texture1_GetHandle
,
5497 d3d_texture1_PaletteChanged
,
5499 d3d_texture1_Unload
,
5502 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5503 * IDirectDrawSurface interface to ddraw methods. */
5504 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5506 if (!iface
) return NULL
;
5507 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5509 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5512 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5515 IDirectDrawSurface7_Release(iface
);
5517 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5520 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5522 if (!iface
) return NULL
;
5523 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5525 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5528 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5531 IDirectDrawSurface4_Release(iface
);
5533 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5536 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5538 if (!iface
) return NULL
;
5539 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5541 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5544 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5547 IDirectDrawSurface3_Release(iface
);
5549 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5552 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5554 if (!iface
) return NULL
;
5555 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5557 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5560 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5563 IDirectDrawSurface2_Release(iface
);
5565 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5568 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5570 if (!iface
) return NULL
;
5571 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5573 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5576 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5579 IDirectDrawSurface_Release(iface
);
5581 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5584 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5586 if (!iface
) return NULL
;
5587 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5588 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5591 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5593 if (!iface
) return NULL
;
5594 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5595 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5598 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5600 struct ddraw_surface
*surface
= parent
;
5602 TRACE("surface %p.\n", surface
);
5604 /* Check for attached surfaces and detach them. */
5605 if (surface
->first_attached
!= surface
)
5607 /* Well, this shouldn't happen: The surface being attached is
5608 * referenced in AddAttachedSurface(), so it shouldn't be released
5609 * until DeleteAttachedSurface() is called, because the refcount is
5610 * held. It looks like the application released it often enough to
5612 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5614 /* The refcount will drop to -1 here */
5615 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5616 ERR("DeleteAttachedSurface failed.\n");
5619 while (surface
->next_attached
)
5620 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5621 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5622 ERR("DeleteAttachedSurface failed.\n");
5624 /* Having a texture handle set implies that the device still exists. */
5625 if (surface
->Handle
)
5626 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5628 /* Reduce the ddraw surface count. */
5629 list_remove(&surface
->surface_list_entry
);
5631 if (surface
->clipper
)
5632 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5634 if (surface
== surface
->ddraw
->primary
)
5635 surface
->ddraw
->primary
= NULL
;
5637 wined3d_private_store_cleanup(&surface
->private_store
);
5639 HeapFree(GetProcessHeap(), 0, surface
);
5642 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5644 ddraw_surface_wined3d_object_destroyed
,
5647 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5649 TRACE("parent %p.\n", parent
);
5651 HeapFree(GetProcessHeap(), 0, parent
);
5654 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5656 ddraw_texture_wined3d_object_destroyed
,
5659 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5664 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5665 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5667 struct ddraw_surface
*root
, *mip
, **attach
;
5668 struct wined3d_resource_desc wined3d_desc
;
5669 struct wined3d_texture
*wined3d_texture
;
5670 struct wined3d_resource
*resource
;
5671 struct wined3d_display_mode mode
;
5672 DDSURFACEDESC2
*desc
, *mip_desc
;
5673 struct ddraw_texture
*texture
;
5674 UINT layers
, levels
, i
, j
;
5675 unsigned int pitch
= 0;
5678 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5679 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5680 if (TRACE_ON(ddraw
))
5682 TRACE("Requesting surface desc:\n");
5683 DDRAW_dump_surface_desc(surface_desc
);
5687 return CLASS_E_NOAGGREGATION
;
5692 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5693 return E_OUTOFMEMORY
;
5695 texture
->version
= version
;
5696 texture
->surface_desc
= *surface_desc
;
5697 desc
= &texture
->surface_desc
;
5699 /* Ensure DDSD_CAPS is always set. */
5700 desc
->dwFlags
|= DDSD_CAPS
;
5702 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5704 DWORD flippable
= desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
);
5706 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5708 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5709 HeapFree(GetProcessHeap(), 0, texture
);
5710 return DDERR_INVALIDCAPS
;
5715 if (flippable
!= (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
))
5717 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5718 HeapFree(GetProcessHeap(), 0, texture
);
5719 return DDERR_INVALIDCAPS
;
5722 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5724 WARN("Tried to create a flippable primary surface without any back buffers.\n");
5725 HeapFree(GetProcessHeap(), 0, texture
);
5726 return DDERR_INVALIDCAPS
;
5729 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5731 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5732 HeapFree(GetProcessHeap(), 0, texture
);
5733 return DDERR_NOEXCLUSIVEMODE
;
5738 /* This is a special case in ddrawex, but not allowed in ddraw. */
5739 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5740 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5742 WARN("Tried to create a surface in both system and video memory.\n");
5743 HeapFree(GetProcessHeap(), 0, texture
);
5744 return DDERR_INVALIDCAPS
;
5747 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5748 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5750 WARN("Cube map faces requested without cube map flag.\n");
5751 HeapFree(GetProcessHeap(), 0, texture
);
5752 return DDERR_INVALIDCAPS
;
5755 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5756 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5758 WARN("Cube map without faces requested.\n");
5759 HeapFree(GetProcessHeap(), 0, texture
);
5760 return DDERR_INVALIDPARAMS
;
5763 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5764 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5765 FIXME("Partial cube maps not implemented.\n");
5767 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5769 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5771 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5772 HeapFree(GetProcessHeap(), 0, texture
);
5773 return DDERR_INVALIDCAPS
;
5775 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5777 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5778 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5779 HeapFree(GetProcessHeap(), 0, texture
);
5780 return DDERR_INVALIDCAPS
;
5784 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5786 ERR("Failed to get display mode, hr %#x.\n", hr
);
5787 HeapFree(GetProcessHeap(), 0, texture
);
5788 return hr_ddraw_from_wined3d(hr
);
5791 /* No pixelformat given? Use the current screen format. */
5792 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5794 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5795 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5796 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5799 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5800 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5802 WARN("Unsupported / unknown pixelformat.\n");
5803 HeapFree(GetProcessHeap(), 0, texture
);
5804 return DDERR_INVALIDPIXELFORMAT
;
5807 /* No width or no height? Use the screen size. */
5808 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5810 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5812 WARN("No width / height specified.\n");
5813 HeapFree(GetProcessHeap(), 0, texture
);
5814 return DDERR_INVALIDPARAMS
;
5817 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5818 desc
->dwWidth
= mode
.width
;
5819 desc
->dwHeight
= mode
.height
;
5822 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5824 HeapFree(GetProcessHeap(), 0, texture
);
5825 return DDERR_INVALIDPARAMS
;
5828 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5830 /* The first surface is a front buffer, the back buffers are created
5832 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5833 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5834 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5835 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5837 struct wined3d_swapchain_desc swapchain_desc
;
5839 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5840 swapchain_desc
.backbuffer_width
= mode
.width
;
5841 swapchain_desc
.backbuffer_height
= mode
.height
;
5842 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5844 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5845 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5847 ERR("Failed to reset device.\n");
5848 HeapFree(GetProcessHeap(), 0, texture
);
5849 return hr_ddraw_from_wined3d(hr
);
5854 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5855 wined3d_desc
.multisample_quality
= 0;
5856 wined3d_desc
.usage
= 0;
5857 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5858 wined3d_desc
.width
= desc
->dwWidth
;
5859 wined3d_desc
.height
= desc
->dwHeight
;
5860 wined3d_desc
.depth
= 1;
5861 wined3d_desc
.size
= 0;
5863 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5865 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5866 /* Do not fail surface creation, only fail 3D device creation. */
5869 /* Mipmap count fixes */
5870 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5872 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5874 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5876 /* Mipmap count is given, should not be 0. */
5877 if (!desc
->u2
.dwMipMapCount
)
5879 HeapFree(GetProcessHeap(), 0, texture
);
5880 return DDERR_INVALIDPARAMS
;
5885 /* Undocumented feature: Create sublevels until either the
5886 * width or the height is 1. */
5887 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5892 desc
->u2
.dwMipMapCount
= 1;
5895 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5896 levels
= desc
->u2
.dwMipMapCount
;
5903 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5905 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5907 enum wined3d_resource_type rtype
;
5910 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5911 rtype
= WINED3D_RTYPE_CUBE_TEXTURE
;
5912 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5913 rtype
= WINED3D_RTYPE_TEXTURE
;
5915 rtype
= WINED3D_RTYPE_SURFACE
;
5917 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5918 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5919 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5920 usage
= WINED3DUSAGE_RENDERTARGET
;
5922 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5923 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, rtype
, wined3d_desc
.format
)))
5924 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5926 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5928 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5930 /* Tests show surfaces without memory flags get these flags added
5931 * right after creation. */
5932 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5936 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5937 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5939 WARN("System memory overlays are not allowed.\n");
5940 HeapFree(GetProcessHeap(), 0, texture
);
5941 return DDERR_NOOVERLAYHW
;
5944 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5946 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
5950 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5951 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
5952 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5953 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5954 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5955 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
5957 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5959 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
5960 /* Managed textures have the system memory flag set. */
5961 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5963 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5965 /* Videomemory adds localvidmem. This is mutually exclusive with
5966 * systemmemory and texturemanage. */
5967 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5968 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
5972 /* If the surface is of the 'ALLOCONLOAD' type, ignore the LPSURFACE
5973 * field. Frank Herbert's Dune specifies a NULL pointer for lpSurface. */
5974 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
) || !desc
->lpSurface
)
5975 desc
->dwFlags
&= ~DDSD_LPSURFACE
;
5976 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5978 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
5980 WARN("User memory surfaces should be in the system memory pool.\n");
5981 HeapFree(GetProcessHeap(), 0, texture
);
5982 return DDERR_INVALIDCAPS
;
5987 WARN("User memory surfaces not supported before version 4.\n");
5988 HeapFree(GetProcessHeap(), 0, texture
);
5989 return DDERR_INVALIDPARAMS
;
5992 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
5994 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
5996 WARN("Pitch specified on a compressed user memory surface.\n");
5997 HeapFree(GetProcessHeap(), 0, texture
);
5998 return DDERR_INVALIDPARAMS
;
6001 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6003 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6004 HeapFree(GetProcessHeap(), 0, texture
);
6005 return DDERR_INVALIDPARAMS
;
6008 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6009 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6010 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6012 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6013 HeapFree(GetProcessHeap(), 0, texture
);
6014 return DDERR_INVALIDPARAMS
;
6019 if (!(desc
->dwFlags
& DDSD_PITCH
))
6021 WARN("User memory surfaces should explicitly specify the pitch.\n");
6022 HeapFree(GetProcessHeap(), 0, texture
);
6023 return DDERR_INVALIDPARAMS
;
6026 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6027 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6029 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6030 HeapFree(GetProcessHeap(), 0, texture
);
6031 return DDERR_INVALIDPARAMS
;
6034 pitch
= desc
->u1
.lPitch
;
6038 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6039 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6040 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6041 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6042 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6043 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6044 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6045 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6047 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6048 HeapFree(GetProcessHeap(), 0, texture
);
6049 return DDERR_NOCOLORKEYHW
;
6052 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6053 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6055 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6056 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6058 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6060 wined3d_desc
.resource_type
= WINED3D_RTYPE_CUBE_TEXTURE
;
6065 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
6069 /* Some applications assume surfaces will always be mapped at the same
6070 * address. Some of those also assume that this address is valid even when
6071 * the surface isn't mapped, and that updates done this way will be
6072 * visible on the screen. The game Nox is such an application,
6073 * Commandos: Behind Enemy Lines is another. We set
6074 * WINED3D_SURFACE_PIN_SYSMEM because of this. */
6075 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
6076 WINED3D_SURFACE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6078 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6079 HeapFree(GetProcessHeap(), 0, texture
);
6080 return hr_ddraw_from_wined3d(hr
);
6083 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6084 root
= wined3d_resource_get_parent(resource
);
6085 root
->wined3d_texture
= wined3d_texture
;
6086 root
->is_complex_root
= TRUE
;
6087 texture
->root
= root
;
6089 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6090 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6091 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6092 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6093 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6094 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6095 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6096 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6097 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6098 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6099 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6100 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6102 for (i
= 0; i
< layers
; ++i
)
6104 attach
= &root
->complex_array
[layers
- 1 - i
];
6106 for (j
= 0; j
< levels
; ++j
)
6108 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
6109 mip
= wined3d_resource_get_parent(resource
);
6110 mip_desc
= &mip
->surface_desc
;
6113 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6115 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6117 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6119 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6123 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6124 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6126 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6127 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6129 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6130 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6132 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6133 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6135 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6136 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6138 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6139 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6149 attach
= &mip
->complex_array
[0];
6153 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6154 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6155 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6157 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6161 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6163 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6164 struct ddraw_surface
*last
= root
;
6166 attach
= &last
->complex_array
[0];
6167 for (i
= 0; i
< count
; ++i
)
6169 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6175 texture
->version
= version
;
6176 texture
->surface_desc
= root
->surface_desc
;
6177 desc
= &texture
->surface_desc
;
6179 /* Only one surface in the flipping chain is a back buffer, one is
6180 * a front buffer, the others are just flippable surfaces. */
6181 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6182 | DDSCAPS_BACKBUFFER
);
6184 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6185 desc
->u5
.dwBackBufferCount
= 0;
6187 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1,
6188 WINED3D_SURFACE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6190 HeapFree(GetProcessHeap(), 0, texture
);
6191 hr
= hr_ddraw_from_wined3d(hr
);
6195 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6196 last
= wined3d_resource_get_parent(resource
);
6197 last
->wined3d_texture
= wined3d_texture
;
6198 texture
->root
= last
;
6200 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6201 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6202 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6203 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6204 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6205 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6206 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6207 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6208 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6209 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6210 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6211 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6214 attach
= &last
->complex_array
[0];
6219 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6220 ddraw
->primary
= root
;
6227 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6228 else if (version
== 4)
6229 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6231 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6236 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
, struct ddraw_texture
*texture
,
6237 struct wined3d_surface
*wined3d_surface
, const struct wined3d_parent_ops
**parent_ops
)
6239 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6240 struct wined3d_resource_desc wined3d_desc
;
6241 unsigned int version
= texture
->version
;
6243 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6244 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6245 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6246 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6247 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6248 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6249 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6250 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6251 surface
->iface_count
= 1;
6252 surface
->version
= version
;
6253 surface
->ddraw
= ddraw
;
6258 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6260 else if (version
== 4)
6263 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6268 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6271 *desc
= texture
->surface_desc
;
6272 wined3d_resource_get_desc(wined3d_surface_get_resource(wined3d_surface
), &wined3d_desc
);
6273 desc
->dwWidth
= wined3d_desc
.width
;
6274 desc
->dwHeight
= wined3d_desc
.height
;
6275 surface
->first_attached
= surface
;
6277 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6279 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6280 desc
->u1
.dwLinearSize
= ~0u;
6282 desc
->u1
.dwLinearSize
= wined3d_surface_get_pitch(wined3d_surface
) * ((desc
->dwHeight
+ 3) / 4);
6283 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6284 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6288 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6289 desc
->u1
.lPitch
= wined3d_surface_get_pitch(wined3d_surface
);
6290 desc
->dwFlags
|= DDSD_PITCH
;
6291 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6293 desc
->lpSurface
= NULL
;
6295 wined3d_surface_incref(wined3d_surface
);
6296 surface
->wined3d_surface
= wined3d_surface
;
6297 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6299 wined3d_private_store_init(&surface
->private_store
);
6302 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6304 struct ddraw_surface
*surface
= parent
;
6306 /* If the surface reference count drops to zero, we release our reference
6307 * to the view, but don't clear the pointer yet, in case e.g. a
6308 * GetRenderTarget() call brings the surface back before the view is
6309 * actually destroyed. When the view is destroyed, we need to clear the
6310 * pointer, or a subsequent surface AddRef() would reference it again.
6312 * This is safe because as long as the view still has a reference to the
6313 * texture, the surface is also still alive, and we're called before the
6314 * view releases that reference. */
6315 surface
->wined3d_rtv
= NULL
;
6318 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6320 view_wined3d_object_destroyed
,
6323 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6327 if (surface
->wined3d_rtv
)
6328 return surface
->wined3d_rtv
;
6330 if (FAILED(hr
= wined3d_rendertarget_view_create_from_surface(surface
->wined3d_surface
,
6331 surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6333 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6337 return surface
->wined3d_rtv
;