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 if (!(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1244 WARN("Not in exclusive mode.\n");
1245 wined3d_mutex_unlock();
1246 return DDERR_NOEXCLUSIVEMODE
;
1249 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1250 tmp
= dst_impl
->wined3d_surface
;
1251 texture
= dst_impl
->wined3d_texture
;
1252 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1253 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1257 for (current
= iface
; current
!= src
;)
1259 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
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
;
1265 ddraw_surface7_Release(current
);
1266 if (current
== iface
)
1268 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1269 wined3d_mutex_unlock();
1270 return DDERR_NOTFLIPPABLE
;
1274 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1275 if (rtv
== dst_impl
->wined3d_rtv
)
1276 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1277 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1278 dst_impl
->wined3d_rtv
= src_rtv
;
1279 wined3d_resource_set_parent(wined3d_surface_get_resource(src_impl
->wined3d_surface
), dst_impl
);
1280 dst_impl
->wined3d_surface
= src_impl
->wined3d_surface
;
1281 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1282 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1283 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1284 ddraw_texture
= prev_ddraw_texture
;
1288 for (current
= iface
;;)
1290 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1292 ERR("Can't find a flip target\n");
1293 wined3d_mutex_unlock();
1294 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1296 ddraw_surface7_Release(current
);
1297 if (current
== iface
)
1299 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1303 src_impl
= impl_from_IDirectDrawSurface7(current
);
1304 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1305 if (rtv
== dst_impl
->wined3d_rtv
)
1306 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1307 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1308 dst_impl
->wined3d_rtv
= src_rtv
;
1309 wined3d_resource_set_parent(wined3d_surface_get_resource(src_impl
->wined3d_surface
), dst_impl
);
1310 dst_impl
->wined3d_surface
= src_impl
->wined3d_surface
;
1311 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1312 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1313 ddraw_texture
= prev_ddraw_texture
;
1314 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1315 dst_impl
= src_impl
;
1319 /* We don't have to worry about potential texture bindings, since
1320 * flippable surfaces can never be textures. */
1321 if (rtv
== src_impl
->wined3d_rtv
)
1322 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1323 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1324 src_impl
->wined3d_rtv
= tmp_rtv
;
1325 wined3d_resource_set_parent(wined3d_surface_get_resource(tmp
), src_impl
);
1326 src_impl
->wined3d_surface
= tmp
;
1327 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1328 src_impl
->wined3d_texture
= texture
;
1334 FIXME("Ignoring flags %#x.\n", flags
);
1336 WARN("Ignoring flags %#x.\n", flags
);
1339 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1340 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1344 wined3d_mutex_unlock();
1349 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1350 IDirectDrawSurface4
*dst
, DWORD flags
)
1352 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1353 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1355 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1357 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1358 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1361 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1362 IDirectDrawSurface3
*dst
, DWORD flags
)
1364 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1365 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1367 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1369 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1370 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1373 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1374 IDirectDrawSurface2
*dst
, DWORD flags
)
1376 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1377 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1379 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1381 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1382 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1385 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1386 IDirectDrawSurface
*dst
, DWORD flags
)
1388 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1389 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1391 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1393 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1394 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1397 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1398 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1399 const WINEDDBLTFX
*fx
, enum wined3d_texture_filter_type filter
)
1401 struct wined3d_surface
*wined3d_src_surface
= src_surface
? src_surface
->wined3d_surface
: NULL
;
1402 RECT src_rect
, dst_rect
;
1403 float scale_x
, scale_y
;
1404 const RECT
*clip_rect
;
1405 UINT clip_list_size
;
1410 if (!dst_surface
->clipper
)
1412 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1413 hr
= ddraw_surface_update_frontbuffer(src_surface
, src_rect_in
, TRUE
);
1415 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, dst_rect_in
,
1416 wined3d_src_surface
, src_rect_in
, flags
, fx
, filter
);
1417 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1418 hr
= ddraw_surface_update_frontbuffer(dst_surface
, dst_rect_in
, FALSE
);
1427 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1428 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1432 dst_rect
= *dst_rect_in
;
1435 if (IsRectEmpty(&dst_rect
))
1436 return DDERR_INVALIDRECT
;
1444 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1445 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1449 src_rect
= *src_rect_in
;
1452 if (IsRectEmpty(&src_rect
))
1453 return DDERR_INVALIDRECT
;
1457 SetRect(&src_rect
, 0, 0, 0, 0);
1460 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1461 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1463 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1464 &dst_rect
, NULL
, &clip_list_size
)))
1466 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1470 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1472 WARN("Failed to allocate clip list.\n");
1473 return E_OUTOFMEMORY
;
1476 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1477 &dst_rect
, clip_list
, &clip_list_size
)))
1479 WARN("Failed to get clip list, hr %#x.\n", hr
);
1480 HeapFree(GetProcessHeap(), 0, clip_list
);
1484 clip_rect
= (RECT
*)clip_list
->Buffer
;
1485 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1487 RECT src_rect_clipped
= src_rect
;
1491 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1492 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1493 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1494 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1496 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1498 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1503 if (FAILED(hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, &clip_rect
[i
],
1504 wined3d_src_surface
, &src_rect_clipped
, flags
, fx
, filter
)))
1507 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1509 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1514 HeapFree(GetProcessHeap(), 0, clip_list
);
1518 /*****************************************************************************
1519 * IDirectDrawSurface7::Blt
1521 * Performs a blit on the surface
1524 * DestRect: Destination rectangle, can be NULL
1525 * SrcSurface: Source surface, can be NULL
1526 * SrcRect: Source rectangle, can be NULL
1528 * DDBltFx: Some extended blt parameters, connected to the flags
1532 * See IWineD3DSurface::Blt for more details
1534 *****************************************************************************/
1535 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1536 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1538 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1539 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1543 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1544 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1546 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1547 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1549 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1550 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1551 return DDERR_INVALIDPARAMS
;
1554 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1555 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1556 return DDERR_INVALIDPARAMS
;
1559 wined3d_mutex_lock();
1561 if (Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1563 if (Flags
& DDBLT_ROP
)
1565 wined3d_mutex_unlock();
1566 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1567 return DDERR_INVALIDPARAMS
;
1571 wined3d_mutex_unlock();
1572 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1573 return DDERR_INVALIDPARAMS
;
1577 wined3d_mutex_unlock();
1578 WARN("Depth or colorfill used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1579 return DDERR_INVALIDPARAMS
;
1582 if ((Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1583 Flags
&= ~DDBLT_DEPTHFILL
;
1585 if ((dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_COLORFILL
))
1587 wined3d_mutex_unlock();
1588 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1589 return DDERR_INVALIDPARAMS
;
1591 if (!(dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_DEPTHFILL
))
1593 wined3d_mutex_unlock();
1594 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1595 return DDERR_INVALIDPARAMS
;
1599 if (Flags
& DDBLT_ROP
)
1603 wined3d_mutex_unlock();
1604 WARN("DDBLT_ROP used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1605 return DDERR_INVALIDPARAMS
;
1608 Flags
&= ~DDBLT_ROP
;
1609 switch (DDBltFx
->dwROP
)
1618 if (DDBltFx
->dwROP
== WHITENESS
)
1619 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1621 rop_fx
.u5
.dwFillColor
= 0;
1623 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1624 Flags
|= DDBLT_DEPTHFILL
;
1626 Flags
|= DDBLT_COLORFILL
;
1632 wined3d_mutex_unlock();
1633 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", DDBltFx
->dwROP
);
1634 return DDERR_NORASTEROPHW
;
1638 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1640 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1641 wined3d_mutex_unlock();
1642 return DDERR_INVALIDPARAMS
;
1645 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1646 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1647 * surfaces. So far no blitting operations using surfaces in the bltfx
1648 * struct are supported anyway. */
1649 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1650 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1652 wined3d_mutex_unlock();
1655 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1656 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1661 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1662 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1664 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1665 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1667 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1668 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1670 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1671 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1674 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1675 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1677 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1678 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1680 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1681 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1683 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1684 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1687 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1688 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1690 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1691 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1693 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1694 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1696 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1697 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1700 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1701 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1703 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1704 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1706 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1707 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1709 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1710 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1713 /*****************************************************************************
1714 * IDirectDrawSurface7::AddAttachedSurface
1716 * Attaches a surface to another surface. How the surface attachments work
1717 * is not totally understood yet, and this method is prone to problems.
1718 * The surface that is attached is AddRef-ed.
1720 * Tests with complex surfaces suggest that the surface attachments form a
1721 * tree, but no method to test this has been found yet.
1723 * The attachment list consists of a first surface (first_attached) and
1724 * for each surface a pointer to the next attached surface (next_attached).
1725 * For the first surface, and a surface that has no attachments
1726 * first_attached points to the surface itself. A surface that has
1727 * no successors in the chain has next_attached set to NULL.
1729 * Newly attached surfaces are attached right after the root surface.
1730 * If a surface is attached to a complex surface compound, it's attached to
1731 * the surface that the app requested, not the complex root. See
1732 * GetAttachedSurface for a description how surfaces are found.
1734 * This is how the current implementation works, and it was coded by looking
1735 * at the needs of the applications.
1737 * So far only Z-Buffer attachments are tested, and they are activated in
1738 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1739 * Back buffers should work in 2D mode, but they are not tested(They can be
1740 * attached in older iface versions). Rendering to the front buffer and
1741 * switching between that and double buffering is not yet implemented in
1742 * WineD3D, so for 3D it might have unexpected results.
1744 * ddraw_surface_attach_surface is the real thing,
1745 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1746 * performs additional checks. Version 7 of this interface is much more restrictive
1747 * than its predecessors.
1750 * Attach: Surface to attach to iface
1754 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1756 *****************************************************************************/
1757 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1759 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1762 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1764 wined3d_mutex_lock();
1766 /* Check if the surface is already attached somewhere */
1767 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1769 /* TODO: Test for the structure of the manual attachment. Is it a
1770 * chain or a list? What happens if one surface is attached to 2
1771 * different surfaces? */
1772 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1773 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1775 wined3d_mutex_unlock();
1776 return DDERR_SURFACEALREADYATTACHED
;
1779 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1780 Surf
->next_attached
= This
->next_attached
;
1781 Surf
->first_attached
= This
->first_attached
;
1782 This
->next_attached
= Surf
;
1784 /* Check if the WineD3D depth stencil needs updating */
1785 if (This
->ddraw
->d3ddevice
)
1786 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1788 wined3d_mutex_unlock();
1793 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1795 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1796 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1799 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1801 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1802 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1805 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1806 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1807 return DDERR_CANNOTATTACHSURFACE
;
1810 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1815 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1816 IUnknown_AddRef(attachment_impl
->attached_iface
);
1820 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1822 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1823 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1826 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1828 /* Tests suggest that
1829 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1830 * -> offscreen plain surfaces can be attached to primaries
1831 * -> primaries can be attached to offscreen plain surfaces
1832 * -> z buffers can be attached to primaries */
1833 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1834 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1836 /* Sizes have to match */
1837 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1838 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1840 WARN("Surface sizes do not match.\n");
1841 return DDERR_CANNOTATTACHSURFACE
;
1844 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1845 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1847 WARN("Invalid attachment combination.\n");
1848 return DDERR_CANNOTATTACHSURFACE
;
1851 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1854 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1855 IUnknown_AddRef(attachment_impl
->attached_iface
);
1859 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1861 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1862 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1865 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1867 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1868 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1871 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1872 IUnknown_AddRef(attachment_impl
->attached_iface
);
1873 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1877 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1879 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1880 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1883 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1885 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1886 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1889 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1890 IUnknown_AddRef(attachment_impl
->attached_iface
);
1891 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1895 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1897 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1898 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1901 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1903 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1904 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1907 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1908 IUnknown_AddRef(attachment_impl
->attached_iface
);
1909 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1913 /*****************************************************************************
1914 * IDirectDrawSurface7::DeleteAttachedSurface
1916 * Removes a surface from the attachment chain. The surface's refcount
1917 * is decreased by one after it has been removed
1920 * Flags: Some flags, not used by this implementation
1921 * Attach: Surface to detach
1925 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1927 *****************************************************************************/
1928 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1929 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1931 struct ddraw_surface
*prev
= surface
;
1933 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1935 wined3d_mutex_lock();
1936 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1938 wined3d_mutex_unlock();
1939 return DDERR_CANNOTDETACHSURFACE
;
1942 if (attachment
->attached_iface
!= detach_iface
)
1944 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1945 wined3d_mutex_unlock();
1946 return DDERR_SURFACENOTATTACHED
;
1949 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1950 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1952 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1953 /* FIXME: we should probably also subtract from dwMipMapCount of this
1954 * and all parent surfaces */
1957 /* Find the predecessor of the detached surface */
1960 if (prev
->next_attached
== attachment
)
1962 prev
= prev
->next_attached
;
1965 /* There must be a surface, otherwise there's a bug */
1968 /* Unchain the surface */
1969 prev
->next_attached
= attachment
->next_attached
;
1970 attachment
->next_attached
= NULL
;
1971 attachment
->first_attached
= attachment
;
1973 /* Check if the wined3d depth stencil needs updating. */
1974 if (surface
->ddraw
->d3ddevice
)
1975 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1976 wined3d_mutex_unlock();
1978 /* Set attached_iface to NULL before releasing it, the surface may go
1980 attachment
->attached_iface
= NULL
;
1981 IUnknown_Release(detach_iface
);
1986 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1987 DWORD flags
, IDirectDrawSurface7
*attachment
)
1989 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1990 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1992 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1994 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1997 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1998 DWORD flags
, IDirectDrawSurface4
*attachment
)
2000 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2001 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2003 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2005 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2008 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2009 DWORD flags
, IDirectDrawSurface3
*attachment
)
2011 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2012 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2014 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2016 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2019 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2020 DWORD flags
, IDirectDrawSurface2
*attachment
)
2022 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2023 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2025 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2027 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2030 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2031 DWORD flags
, IDirectDrawSurface
*attachment
)
2033 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2034 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2036 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2038 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2041 /*****************************************************************************
2042 * IDirectDrawSurface7::AddOverlayDirtyRect
2044 * "This method is not currently implemented"
2052 *****************************************************************************/
2053 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2055 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2057 return DDERR_UNSUPPORTED
; /* unchecked */
2060 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2064 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2066 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2069 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2071 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2073 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2075 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2078 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2080 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2082 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2084 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2087 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2089 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2091 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2093 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2096 /*****************************************************************************
2097 * IDirectDrawSurface7::GetDC
2099 * Returns a GDI device context for the surface
2102 * hdc: Address of a HDC variable to store the dc to
2106 * DDERR_INVALIDPARAMS if hdc is NULL
2107 * For details, see IWineD3DSurface::GetDC
2109 *****************************************************************************/
2110 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
2112 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2115 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2118 return DDERR_INVALIDPARAMS
;
2120 wined3d_mutex_lock();
2121 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2122 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2124 hr
= wined3d_surface_getdc(surface
->wined3d_surface
, hdc
);
2126 if (SUCCEEDED(hr
) && format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2128 const struct ddraw_palette
*palette
;
2130 if (surface
->palette
)
2131 palette
= surface
->palette
;
2132 else if (surface
->ddraw
->primary
)
2133 palette
= surface
->ddraw
->primary
->palette
;
2138 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *hdc
);
2141 wined3d_mutex_unlock();
2144 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
2147 case WINED3DERR_INVALIDCALL
:
2148 if(hdc
) *hdc
= NULL
;
2149 return DDERR_INVALIDPARAMS
;
2155 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2157 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2159 TRACE("iface %p, dc %p.\n", iface
, dc
);
2161 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2164 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2166 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2168 TRACE("iface %p, dc %p.\n", iface
, dc
);
2170 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2173 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2175 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2177 TRACE("iface %p, dc %p.\n", iface
, dc
);
2179 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2182 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2184 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2186 TRACE("iface %p, dc %p.\n", iface
, dc
);
2188 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2191 /*****************************************************************************
2192 * IDirectDrawSurface7::ReleaseDC
2194 * Releases the DC that was constructed with GetDC
2197 * hdc: HDC to release
2201 * For more details, see IWineD3DSurface::ReleaseDC
2203 *****************************************************************************/
2204 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2206 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2209 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2211 wined3d_mutex_lock();
2212 hr
= wined3d_surface_releasedc(surface
->wined3d_surface
, hdc
);
2213 if (SUCCEEDED(hr
) && (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2214 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2215 wined3d_mutex_unlock();
2220 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2222 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2224 TRACE("iface %p, dc %p.\n", iface
, dc
);
2226 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2229 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2231 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2233 TRACE("iface %p, dc %p.\n", iface
, dc
);
2235 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2238 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2240 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2242 TRACE("iface %p, dc %p.\n", iface
, dc
);
2244 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2247 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2249 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2251 TRACE("iface %p, dc %p.\n", iface
, dc
);
2253 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2256 /*****************************************************************************
2257 * IDirectDrawSurface7::GetCaps
2259 * Returns the surface's caps
2262 * Caps: Address to write the caps to
2266 * DDERR_INVALIDPARAMS if Caps is NULL
2268 *****************************************************************************/
2269 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2271 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2273 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2276 return DDERR_INVALIDPARAMS
;
2278 *Caps
= surface
->surface_desc
.ddsCaps
;
2283 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2285 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2287 TRACE("iface %p, caps %p.\n", iface
, caps
);
2289 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2292 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2294 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2298 TRACE("iface %p, caps %p.\n", iface
, caps
);
2300 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2301 if (FAILED(hr
)) return hr
;
2303 caps
->dwCaps
= caps2
.dwCaps
;
2307 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2309 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2313 TRACE("iface %p, caps %p.\n", iface
, caps
);
2315 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2316 if (FAILED(hr
)) return hr
;
2318 caps
->dwCaps
= caps2
.dwCaps
;
2322 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2324 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2328 TRACE("iface %p, caps %p.\n", iface
, caps
);
2330 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2331 if (FAILED(hr
)) return hr
;
2333 caps
->dwCaps
= caps2
.dwCaps
;
2337 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2339 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2340 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2342 struct wined3d_resource
*resource
;
2344 TRACE("iface %p, priority %u.\n", iface
, priority
);
2346 wined3d_mutex_lock();
2347 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2348 * calls on such surfaces segfault on Windows. */
2349 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2351 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2352 hr
= DDERR_INVALIDPARAMS
;
2356 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2357 wined3d_resource_set_priority(resource
, priority
);
2360 wined3d_mutex_unlock();
2365 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2367 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2368 const struct wined3d_resource
*resource
;
2369 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2372 TRACE("iface %p, priority %p.\n", iface
, priority
);
2374 wined3d_mutex_lock();
2375 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2377 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2378 hr
= DDERR_INVALIDOBJECT
;
2380 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->wined3d_texture
)
2382 WARN("Called on non-managed texture or mipmap sublevel, returning DDERR_INVALIDPARAMS.\n");
2383 hr
= DDERR_INVALIDPARAMS
;
2387 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2388 *priority
= wined3d_resource_get_priority(resource
);
2391 wined3d_mutex_unlock();
2396 /*****************************************************************************
2397 * IDirectDrawSurface7::SetPrivateData
2399 * Stores some data in the surface that is intended for the application's
2403 * tag: GUID that identifies the data
2404 * Data: Pointer to the private data
2405 * Size: Size of the private data
2410 * For more details, see IWineD3DSurface::SetPrivateData
2412 *****************************************************************************/
2413 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2414 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2416 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2419 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2420 iface
, debugstr_guid(tag
), data
, size
, flags
);
2424 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2425 return DDERR_INVALIDPARAMS
;
2428 wined3d_mutex_lock();
2429 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2430 wined3d_mutex_unlock();
2431 return hr_ddraw_from_wined3d(hr
);
2434 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2435 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2437 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2439 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2440 iface
, debugstr_guid(tag
), data
, size
, flags
);
2442 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2445 /*****************************************************************************
2446 * IDirectDrawSurface7::GetPrivateData
2448 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2451 * tag: GUID of the data to return
2452 * Data: Address where to write the data to
2453 * Size: Size of the buffer at Data
2457 * DDERR_INVALIDPARAMS if Data is NULL
2458 * For more details, see IWineD3DSurface::GetPrivateData
2460 *****************************************************************************/
2461 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2463 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2464 const struct wined3d_private_data
*stored_data
;
2467 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2468 iface
, debugstr_guid(tag
), data
, size
);
2470 wined3d_mutex_lock();
2471 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2474 hr
= DDERR_NOTFOUND
;
2479 hr
= DDERR_INVALIDPARAMS
;
2482 if (*size
< stored_data
->size
)
2484 *size
= stored_data
->size
;
2485 hr
= DDERR_MOREDATA
;
2490 hr
= DDERR_INVALIDPARAMS
;
2494 *size
= stored_data
->size
;
2495 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2499 wined3d_mutex_unlock();
2503 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2505 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2507 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2508 iface
, debugstr_guid(tag
), data
, size
);
2510 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2513 /*****************************************************************************
2514 * IDirectDrawSurface7::FreePrivateData
2516 * Frees private data stored in the surface
2519 * tag: Tag of the data to free
2523 * For more details, see IWineD3DSurface::FreePrivateData
2525 *****************************************************************************/
2526 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2528 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2529 struct wined3d_private_data
*entry
;
2531 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2533 wined3d_mutex_lock();
2534 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2537 wined3d_mutex_unlock();
2538 return DDERR_NOTFOUND
;
2541 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2542 wined3d_mutex_unlock();
2547 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2549 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2551 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2553 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2556 /*****************************************************************************
2557 * IDirectDrawSurface7::PageLock
2559 * Prevents a sysmem surface from being paged out
2562 * Flags: Not used, must be 0(unchecked)
2565 * DD_OK, because it's a stub
2567 *****************************************************************************/
2568 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2570 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2572 /* This is Windows memory management related - we don't need this */
2576 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2578 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2580 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2582 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2585 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2587 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2589 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2591 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2594 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2596 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2598 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2600 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2603 /*****************************************************************************
2604 * IDirectDrawSurface7::PageUnlock
2606 * Allows a sysmem surface to be paged out
2609 * Flags: Not used, must be 0(unchecked)
2612 * DD_OK, because it's a stub
2614 *****************************************************************************/
2615 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2617 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2622 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2624 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2626 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2628 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2631 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2633 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2635 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2637 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2640 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2642 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2644 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2646 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2649 /*****************************************************************************
2650 * IDirectDrawSurface7::BltBatch
2652 * An unimplemented function
2660 *****************************************************************************/
2661 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2663 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2665 /* MSDN: "not currently implemented" */
2666 return DDERR_UNSUPPORTED
;
2669 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2671 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2673 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2675 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2678 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2680 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2682 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2684 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2687 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2689 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2691 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2693 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2696 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2698 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2700 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2702 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2705 /*****************************************************************************
2706 * IDirectDrawSurface7::EnumAttachedSurfaces
2708 * Enumerates all surfaces attached to this surface
2711 * context: Pointer to pass unmodified to the callback
2712 * cb: Callback function to call for each surface
2716 * DDERR_INVALIDPARAMS if cb is NULL
2718 *****************************************************************************/
2719 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2720 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2722 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2723 struct ddraw_surface
*surf
;
2724 DDSURFACEDESC2 desc
;
2727 /* Attached surfaces aren't handled in WineD3D */
2728 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2731 return DDERR_INVALIDPARAMS
;
2733 wined3d_mutex_lock();
2735 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2737 surf
= surface
->complex_array
[i
];
2740 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2741 desc
= surf
->surface_desc
;
2742 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2743 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2745 wined3d_mutex_unlock();
2750 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2752 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2753 desc
= surf
->surface_desc
;
2754 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2755 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2757 wined3d_mutex_unlock();
2762 TRACE(" end of enumeration.\n");
2764 wined3d_mutex_unlock();
2769 struct callback_info2
2771 LPDDENUMSURFACESCALLBACK2 callback
;
2775 struct callback_info
2777 LPDDENUMSURFACESCALLBACK callback
;
2781 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2783 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2784 const struct callback_info2
*info
= context
;
2786 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2787 ddraw_surface7_Release(surface
);
2789 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2792 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2794 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2795 const struct callback_info
*info
= context
;
2797 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2798 ddraw_surface7_Release(surface
);
2800 /* FIXME: Check surface_test.dwSize */
2801 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2802 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2805 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2806 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2808 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2809 struct callback_info2 info
;
2811 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2813 info
.callback
= callback
;
2814 info
.context
= context
;
2816 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2817 &info
, EnumCallback2
);
2820 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2821 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2823 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2824 struct callback_info info
;
2826 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2828 info
.callback
= callback
;
2829 info
.context
= context
;
2831 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2832 &info
, EnumCallback
);
2835 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2836 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2838 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2839 struct callback_info info
;
2841 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2843 info
.callback
= callback
;
2844 info
.context
= context
;
2846 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2847 &info
, EnumCallback
);
2850 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2851 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2853 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2854 struct callback_info info
;
2856 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2858 info
.callback
= callback
;
2859 info
.context
= context
;
2861 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2862 &info
, EnumCallback
);
2865 /*****************************************************************************
2866 * IDirectDrawSurface7::EnumOverlayZOrders
2868 * "Enumerates the overlay surfaces on the specified destination"
2871 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2872 * context: context to pass back to the callback
2873 * cb: callback function to call for each enumerated surface
2876 * DD_OK, because it's a stub
2878 *****************************************************************************/
2879 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2880 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2882 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2887 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2888 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2890 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2891 struct callback_info2 info
;
2893 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2895 info
.callback
= callback
;
2896 info
.context
= context
;
2898 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2899 flags
, &info
, EnumCallback2
);
2902 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2903 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2905 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2906 struct callback_info info
;
2908 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2910 info
.callback
= callback
;
2911 info
.context
= context
;
2913 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2914 flags
, &info
, EnumCallback
);
2917 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2918 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2920 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2921 struct callback_info info
;
2923 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2925 info
.callback
= callback
;
2926 info
.context
= context
;
2928 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2929 flags
, &info
, EnumCallback
);
2932 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2933 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2935 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2936 struct callback_info info
;
2938 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2940 info
.callback
= callback
;
2941 info
.context
= context
;
2943 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2944 flags
, &info
, EnumCallback
);
2947 /*****************************************************************************
2948 * IDirectDrawSurface7::GetBltStatus
2950 * Returns the blitting status
2953 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2956 * See IWineD3DSurface::Blt
2958 *****************************************************************************/
2959 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2961 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2965 case WINEDDGBS_CANBLT
:
2966 case WINEDDGBS_ISBLTDONE
:
2970 return DDERR_INVALIDPARAMS
;
2974 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2976 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2978 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2980 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2983 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2985 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2987 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2989 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2992 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2994 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2996 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2998 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3001 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3003 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3005 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3007 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3010 /*****************************************************************************
3011 * IDirectDrawSurface7::GetColorKey
3013 * Returns the color key assigned to the surface
3017 * CKey: Address to store the key to
3021 * DDERR_INVALIDPARAMS if CKey is NULL
3023 *****************************************************************************/
3024 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3026 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3028 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3031 return DDERR_INVALIDPARAMS
;
3033 wined3d_mutex_lock();
3037 case DDCKEY_DESTBLT
:
3038 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3040 wined3d_mutex_unlock();
3041 return DDERR_NOCOLORKEY
;
3043 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3046 case DDCKEY_DESTOVERLAY
:
3047 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3049 wined3d_mutex_unlock();
3050 return DDERR_NOCOLORKEY
;
3052 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3056 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3058 wined3d_mutex_unlock();
3059 return DDERR_NOCOLORKEY
;
3061 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3064 case DDCKEY_SRCOVERLAY
:
3065 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3067 wined3d_mutex_unlock();
3068 return DDERR_NOCOLORKEY
;
3070 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3074 wined3d_mutex_unlock();
3075 return DDERR_INVALIDPARAMS
;
3078 wined3d_mutex_unlock();
3083 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3085 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3087 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3089 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3092 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3094 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3096 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3098 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3101 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3103 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3105 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3107 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3110 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3112 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3114 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3116 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3119 /*****************************************************************************
3120 * IDirectDrawSurface7::GetFlipStatus
3122 * Returns the flipping status of the surface
3125 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3128 * See IWineD3DSurface::GetFlipStatus
3130 *****************************************************************************/
3131 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3133 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3135 /* XXX: DDERR_INVALIDSURFACETYPE */
3139 case WINEDDGFS_CANFLIP
:
3140 case WINEDDGFS_ISFLIPDONE
:
3144 return DDERR_INVALIDPARAMS
;
3148 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3150 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3152 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3154 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3157 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3159 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3161 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3163 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3166 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3168 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3170 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3172 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3175 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3177 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3179 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3181 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3184 /*****************************************************************************
3185 * IDirectDrawSurface7::GetOverlayPosition
3187 * Returns the display coordinates of a visible and active overlay surface
3194 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3195 *****************************************************************************/
3196 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
3198 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3201 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
3203 wined3d_mutex_lock();
3204 hr
= wined3d_surface_get_overlay_position(surface
->wined3d_surface
, X
, Y
);
3205 wined3d_mutex_unlock();
3210 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3212 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3214 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3216 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3219 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3221 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3223 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3225 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3228 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3230 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3232 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3234 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3237 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3239 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3241 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3243 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3246 /*****************************************************************************
3247 * IDirectDrawSurface7::GetPixelFormat
3249 * Returns the pixel format of the Surface
3252 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3253 * format should be written
3257 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3259 *****************************************************************************/
3260 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3262 /* What is DDERR_INVALIDSURFACETYPE for here? */
3263 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3265 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3268 return DDERR_INVALIDPARAMS
;
3270 wined3d_mutex_lock();
3271 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3272 wined3d_mutex_unlock();
3277 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3279 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3281 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3283 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3286 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3288 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3290 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3292 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3295 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3297 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3299 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3301 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3304 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3306 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3308 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3310 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3313 /*****************************************************************************
3314 * IDirectDrawSurface7::GetSurfaceDesc
3316 * Returns the description of this surface
3319 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3324 * DDERR_INVALIDPARAMS if DDSD is NULL
3326 *****************************************************************************/
3327 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3329 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3331 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3334 return DDERR_INVALIDPARAMS
;
3336 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3338 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3339 return DDERR_INVALIDPARAMS
;
3342 wined3d_mutex_lock();
3343 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3344 TRACE("Returning surface desc:\n");
3345 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3346 wined3d_mutex_unlock();
3351 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3353 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3355 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3357 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3360 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3362 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3364 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3366 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3368 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3370 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3371 return DDERR_INVALIDPARAMS
;
3374 wined3d_mutex_lock();
3375 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3376 TRACE("Returning surface desc:\n");
3377 if (TRACE_ON(ddraw
))
3379 /* DDRAW_dump_surface_desc handles the smaller size */
3380 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3382 wined3d_mutex_unlock();
3387 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3389 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3391 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3393 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3396 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3398 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3400 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3402 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3405 /*****************************************************************************
3406 * IDirectDrawSurface7::Initialize
3408 * Initializes the surface. This is a no-op in Wine
3411 * DD: Pointer to an DirectDraw interface
3412 * DDSD: Surface description for initialization
3415 * DDERR_ALREADYINITIALIZED
3417 *****************************************************************************/
3418 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3419 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3421 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3423 return DDERR_ALREADYINITIALIZED
;
3426 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3427 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3429 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3431 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3433 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3434 ddraw
, surface_desc
);
3437 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3438 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3440 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3441 DDSURFACEDESC2 surface_desc2
;
3443 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3445 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3446 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3447 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3450 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3451 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3453 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3454 DDSURFACEDESC2 surface_desc2
;
3456 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3458 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3459 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3460 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3463 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3464 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3466 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3467 DDSURFACEDESC2 surface_desc2
;
3469 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3471 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3472 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3473 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3476 /*****************************************************************************
3477 * IDirect3DTexture1::Initialize
3479 * The sdk says it's not implemented
3487 *****************************************************************************/
3488 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3489 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3491 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3493 return DDERR_UNSUPPORTED
; /* Unchecked */
3496 /*****************************************************************************
3497 * IDirectDrawSurface7::IsLost
3499 * Checks if the surface is lost
3502 * DD_OK, if the surface is usable
3503 * DDERR_ISLOST if the surface is lost
3504 * See IWineD3DSurface::IsLost for more details
3506 *****************************************************************************/
3507 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3509 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3511 TRACE("iface %p.\n", iface
);
3513 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3514 return DDERR_SURFACELOST
;
3519 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3521 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3523 TRACE("iface %p.\n", iface
);
3525 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3528 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3530 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3532 TRACE("iface %p.\n", iface
);
3534 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3537 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3539 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3541 TRACE("iface %p.\n", iface
);
3543 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3546 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3548 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3550 TRACE("iface %p.\n", iface
);
3552 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3555 /*****************************************************************************
3556 * IDirectDrawSurface7::Restore
3558 * Restores a lost surface. This makes the surface usable again, but
3559 * doesn't reload its old contents
3563 * See IWineD3DSurface::Restore for more details
3565 *****************************************************************************/
3566 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3568 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3570 TRACE("iface %p.\n", iface
);
3572 ddraw_update_lost_surfaces(surface
->ddraw
);
3573 surface
->is_lost
= FALSE
;
3578 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3580 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3582 TRACE("iface %p.\n", iface
);
3584 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3587 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3589 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3591 TRACE("iface %p.\n", iface
);
3593 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3596 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3598 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3600 TRACE("iface %p.\n", iface
);
3602 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3605 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3607 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3609 TRACE("iface %p.\n", iface
);
3611 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3614 /*****************************************************************************
3615 * IDirectDrawSurface7::SetOverlayPosition
3617 * Changes the display coordinates of an overlay surface
3624 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3625 *****************************************************************************/
3626 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3628 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3631 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3633 wined3d_mutex_lock();
3634 hr
= wined3d_surface_set_overlay_position(surface
->wined3d_surface
, X
, Y
);
3635 wined3d_mutex_unlock();
3640 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3642 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3644 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3646 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3649 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3651 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3653 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3655 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3658 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3660 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3662 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3664 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3667 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3669 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3671 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3673 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3676 /*****************************************************************************
3677 * IDirectDrawSurface7::UpdateOverlay
3679 * Modifies the attributes of an overlay surface.
3682 * SrcRect: The section of the source being used for the overlay
3683 * DstSurface: Address of the surface that is overlaid
3684 * DstRect: Place of the overlay
3685 * Flags: some DDOVER_* flags
3688 * DDERR_UNSUPPORTED, because we don't support overlays
3690 *****************************************************************************/
3691 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3692 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3694 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3695 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3698 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3699 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3701 wined3d_mutex_lock();
3702 hr
= wined3d_surface_update_overlay(src_impl
->wined3d_surface
, SrcRect
,
3703 dst_impl
? dst_impl
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3704 wined3d_mutex_unlock();
3707 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3708 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3709 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3715 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3716 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3718 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3719 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3721 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3722 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3724 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3725 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3728 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3729 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3731 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3732 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3734 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3735 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3737 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3738 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3741 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3742 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3744 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3745 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3747 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3748 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3750 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3751 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3754 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3755 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3757 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3758 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3760 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3761 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3763 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3764 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3767 /*****************************************************************************
3768 * IDirectDrawSurface7::UpdateOverlayDisplay
3770 * The DX7 sdk says that it's not implemented
3775 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3777 *****************************************************************************/
3778 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3780 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3782 return DDERR_UNSUPPORTED
;
3785 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3787 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3789 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3791 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3794 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3796 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3798 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3800 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3803 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3805 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3807 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3809 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3812 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3814 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3816 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3818 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3821 /*****************************************************************************
3822 * IDirectDrawSurface7::UpdateOverlayZOrder
3824 * Sets an overlay's Z order
3827 * Flags: DDOVERZ_* flags
3828 * DDSRef: Defines the relative position in the overlay chain
3831 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3833 *****************************************************************************/
3834 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3835 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3837 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3838 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3841 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3843 wined3d_mutex_lock();
3844 hr
= wined3d_surface_update_overlay_z_order(surface
->wined3d_surface
,
3845 Flags
, reference_impl
? reference_impl
->wined3d_surface
: NULL
);
3846 wined3d_mutex_unlock();
3851 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3852 DWORD flags
, IDirectDrawSurface4
*reference
)
3854 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3855 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3857 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3859 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3860 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3863 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3864 DWORD flags
, IDirectDrawSurface3
*reference
)
3866 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3867 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3869 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3871 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3872 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3875 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3876 DWORD flags
, IDirectDrawSurface2
*reference
)
3878 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3879 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3881 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3883 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3884 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3887 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3888 DWORD flags
, IDirectDrawSurface
*reference
)
3890 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3891 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3893 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3895 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3896 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3899 /*****************************************************************************
3900 * IDirectDrawSurface7::GetDDInterface
3902 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3903 * surface belongs to
3906 * DD: Address to write the interface pointer to
3910 * DDERR_INVALIDPARAMS if DD is NULL
3912 *****************************************************************************/
3913 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3915 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3917 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3920 return DDERR_INVALIDPARAMS
;
3922 switch(This
->version
)
3925 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3929 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3933 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3937 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3941 IUnknown_AddRef((IUnknown
*)*DD
);
3946 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3948 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3950 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3952 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3955 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3957 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3959 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3961 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3964 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3966 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3968 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3970 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3973 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3975 TRACE("iface %p.\n", iface
);
3980 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3982 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3984 TRACE("iface %p.\n", iface
);
3986 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
3989 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3991 TRACE("iface %p, value %p.\n", iface
, pValue
);
3998 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4000 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4002 TRACE("iface %p, value %p.\n", iface
, pValue
);
4004 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4007 /*****************************************************************************
4008 * IDirectDrawSurface7::SetLOD
4010 * Sets the level of detail of a texture
4013 * MaxLOD: LOD to set
4017 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4019 *****************************************************************************/
4020 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4022 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4025 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4027 wined3d_mutex_lock();
4028 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4030 wined3d_mutex_unlock();
4031 return DDERR_INVALIDOBJECT
;
4034 if (!surface
->wined3d_texture
)
4036 ERR("The ddraw surface has no wined3d texture.\n");
4037 wined3d_mutex_unlock();
4038 return DDERR_INVALIDOBJECT
;
4041 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4042 wined3d_mutex_unlock();
4047 /*****************************************************************************
4048 * IDirectDrawSurface7::GetLOD
4050 * Returns the level of detail of a Direct3D texture
4053 * MaxLOD: Address to write the LOD to
4057 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4058 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4060 *****************************************************************************/
4061 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4063 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4065 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4068 return DDERR_INVALIDPARAMS
;
4070 wined3d_mutex_lock();
4071 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4073 wined3d_mutex_unlock();
4074 return DDERR_INVALIDOBJECT
;
4077 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4078 wined3d_mutex_unlock();
4083 /*****************************************************************************
4084 * IDirectDrawSurface7::BltFast
4086 * Performs a fast Blit.
4089 * dstx: The x coordinate to blit to on the destination
4090 * dsty: The y coordinate to blit to on the destination
4091 * Source: The source surface
4092 * rsrc: The source rectangle
4093 * trans: Type of transfer. Some DDBLTFAST_* flags
4097 * For more details, see IWineD3DSurface::BltFast
4099 *****************************************************************************/
4100 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
4101 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
4103 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4104 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
4105 DWORD src_w
, src_h
, dst_w
, dst_h
;
4110 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4111 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
4113 dst_w
= This
->surface_desc
.dwWidth
;
4114 dst_h
= This
->surface_desc
.dwHeight
;
4116 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
4121 src_w
= rsrc
->right
- rsrc
->left
;
4122 src_h
= rsrc
->bottom
- rsrc
->top
;
4126 src_w
= src
->surface_desc
.dwWidth
;
4127 src_h
= src
->surface_desc
.dwHeight
;
4130 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
4131 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
4133 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4134 return DDERR_INVALIDRECT
;
4137 SetRect(&dst_rect
, dstx
, dsty
, dstx
+ src_w
, dsty
+ src_h
);
4138 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4139 flags
|= WINEDDBLT_KEYSRC
;
4140 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4141 flags
|= WINEDDBLT_KEYDEST
;
4142 if (trans
& DDBLTFAST_WAIT
)
4143 flags
|= WINEDDBLT_WAIT
;
4144 if (trans
& DDBLTFAST_DONOTWAIT
)
4145 flags
|= WINEDDBLT_DONOTWAIT
;
4147 wined3d_mutex_lock();
4150 wined3d_mutex_unlock();
4151 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4152 return DDERR_BLTFASTCANTCLIP
;
4155 if (src
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4156 hr
= ddraw_surface_update_frontbuffer(src
, rsrc
, TRUE
);
4158 hr
= wined3d_surface_blt(This
->wined3d_surface
, &dst_rect
,
4159 src
->wined3d_surface
, rsrc
, flags
, NULL
, WINED3D_TEXF_POINT
);
4160 if (SUCCEEDED(hr
) && (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4161 hr
= ddraw_surface_update_frontbuffer(This
, &dst_rect
, FALSE
);
4162 wined3d_mutex_unlock();
4166 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4167 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
4172 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4173 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4175 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4176 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4178 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4179 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4181 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4182 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4185 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4186 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4188 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4189 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4191 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4192 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4194 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4195 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4198 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4199 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4201 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4202 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4204 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4205 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4207 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4208 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4211 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4212 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4214 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4215 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4217 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4218 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4220 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4221 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4224 /*****************************************************************************
4225 * IDirectDrawSurface7::GetClipper
4227 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4231 * Clipper: Address to store the interface pointer at
4235 * DDERR_INVALIDPARAMS if Clipper is NULL
4236 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4238 *****************************************************************************/
4239 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4241 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4243 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4246 return DDERR_INVALIDPARAMS
;
4248 wined3d_mutex_lock();
4249 if (!surface
->clipper
)
4251 wined3d_mutex_unlock();
4252 return DDERR_NOCLIPPERATTACHED
;
4255 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4256 IDirectDrawClipper_AddRef(*Clipper
);
4257 wined3d_mutex_unlock();
4262 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4264 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4266 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4268 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4271 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4273 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4275 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4277 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4280 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4282 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4284 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4286 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4289 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4291 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4293 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4295 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4298 /*****************************************************************************
4299 * IDirectDrawSurface7::SetClipper
4301 * Sets a clipper for the surface
4304 * Clipper: IDirectDrawClipper interface of the clipper to set
4309 *****************************************************************************/
4310 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4311 IDirectDrawClipper
*iclipper
)
4313 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4314 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4315 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4318 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4320 wined3d_mutex_lock();
4321 if (clipper
== This
->clipper
)
4323 wined3d_mutex_unlock();
4327 This
->clipper
= clipper
;
4329 if (clipper
!= NULL
)
4330 IDirectDrawClipper_AddRef(iclipper
);
4332 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4334 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4338 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4343 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4344 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4348 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4349 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4353 wined3d_mutex_unlock();
4358 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4360 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4362 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4364 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4367 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4369 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4371 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4373 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4376 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4378 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4380 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4382 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4385 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4387 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4389 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4391 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4394 /*****************************************************************************
4395 * IDirectDrawSurface7::SetSurfaceDesc
4397 * Sets the surface description. It can override the pixel format, the surface
4399 * It's not really tested.
4402 * DDSD: Pointer to the new surface description to set
4407 * DDERR_INVALIDPARAMS if DDSD is NULL
4409 *****************************************************************************/
4410 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4412 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4414 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4415 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4416 enum wined3d_format_id format_id
;
4417 UINT pitch
, width
, height
;
4419 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4423 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4424 return DDERR_INVALIDPARAMS
;
4428 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4429 return DDERR_INVALIDPARAMS
;
4431 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4432 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4433 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4435 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4436 return DDERR_INVALIDSURFACETYPE
;
4439 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4440 * for PIXELFORMAT to work */
4441 if (DDSD
->dwFlags
& ~allowed_flags
)
4443 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4444 return DDERR_INVALIDPARAMS
;
4446 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4448 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4449 return DDERR_INVALIDPARAMS
;
4451 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4453 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4454 return DDERR_INVALIDCAPS
;
4456 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4458 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4460 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4461 return DDERR_INVALIDPARAMS
;
4463 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4465 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4466 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4467 return DDERR_INVALIDPARAMS
;
4469 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4470 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4471 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4472 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4473 pitch
= DDSD
->u1
.lPitch
;
4474 width
= DDSD
->dwWidth
;
4476 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4478 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4479 return DDERR_INVALIDPARAMS
;
4483 pitch
= This
->surface_desc
.u1
.lPitch
;
4484 width
= This
->surface_desc
.dwWidth
;
4487 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4489 if (!DDSD
->dwHeight
)
4491 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4492 return DDERR_INVALIDPARAMS
;
4494 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4495 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4496 height
= DDSD
->dwHeight
;
4500 height
= This
->surface_desc
.dwHeight
;
4503 wined3d_mutex_lock();
4504 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4506 enum wined3d_format_id current_format_id
;
4507 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4509 if (format_id
== WINED3DFMT_UNKNOWN
)
4511 ERR("Requested to set an unknown pixelformat\n");
4512 wined3d_mutex_unlock();
4513 return DDERR_INVALIDPARAMS
;
4515 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4516 if (format_id
!= current_format_id
)
4517 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4521 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4524 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4525 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4527 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4528 wined3d_mutex_unlock();
4529 return hr_ddraw_from_wined3d(hr
);
4532 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4533 This
->surface_desc
.dwWidth
= width
;
4534 if (DDSD
->dwFlags
& DDSD_PITCH
)
4535 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4536 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4537 This
->surface_desc
.dwHeight
= height
;
4538 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4539 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4541 wined3d_mutex_unlock();
4546 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4547 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4549 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4551 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4553 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4554 surface_desc
, flags
);
4557 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4558 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4560 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4561 DDSURFACEDESC2 surface_desc2
;
4563 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4565 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4566 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4567 surface_desc
? &surface_desc2
: NULL
, flags
);
4570 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4572 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4573 struct ddraw_palette
*palette_impl
;
4576 TRACE("iface %p, palette %p.\n", iface
, palette
);
4579 return DDERR_INVALIDPARAMS
;
4580 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4582 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4583 return DDERR_SURFACELOST
;
4586 wined3d_mutex_lock();
4587 if ((palette_impl
= surface
->palette
))
4589 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4590 IDirectDrawPalette_AddRef(*palette
);
4595 hr
= DDERR_NOPALETTEATTACHED
;
4597 wined3d_mutex_unlock();
4602 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4604 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4606 TRACE("iface %p, palette %p.\n", iface
, palette
);
4608 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4611 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4613 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4615 TRACE("iface %p, palette %p.\n", iface
, palette
);
4617 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4620 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4622 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4624 TRACE("iface %p, palette %p.\n", iface
, palette
);
4626 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4629 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4631 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4633 TRACE("iface %p, palette %p.\n", iface
, palette
);
4635 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4638 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4640 DDCOLORKEY fixed_color_key
;
4641 HRESULT hr
= WINED3D_OK
;
4643 if (flags
& DDCKEY_COLORSPACE
)
4645 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4647 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4648 return DDERR_NOCOLORKEYHW
;
4650 flags
&= ~DDCKEY_COLORSPACE
;
4653 wined3d_mutex_lock();
4657 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4658 switch (flags
& ~DDCKEY_COLORSPACE
)
4660 case DDCKEY_DESTBLT
:
4661 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4662 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4665 case DDCKEY_DESTOVERLAY
:
4666 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4667 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4670 case DDCKEY_SRCOVERLAY
:
4671 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4672 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4676 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4677 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4681 wined3d_mutex_unlock();
4682 return DDERR_INVALIDPARAMS
;
4687 switch (flags
& ~DDCKEY_COLORSPACE
)
4689 case DDCKEY_DESTBLT
:
4690 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4693 case DDCKEY_DESTOVERLAY
:
4694 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4697 case DDCKEY_SRCOVERLAY
:
4698 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4702 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4706 wined3d_mutex_unlock();
4707 return DDERR_INVALIDPARAMS
;
4711 if (surface
->wined3d_texture
)
4712 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4713 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4715 wined3d_mutex_unlock();
4717 return hr_ddraw_from_wined3d(hr
);
4720 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4722 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4724 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4726 wined3d_mutex_lock();
4727 if (!surface
->wined3d_texture
)
4729 wined3d_mutex_unlock();
4730 return DDERR_NOTONMIPMAPSUBLEVEL
;
4732 wined3d_mutex_unlock();
4734 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4737 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4739 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4741 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4743 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4746 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4748 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4750 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4752 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4755 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4757 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4759 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4761 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4764 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4766 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4768 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4770 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4773 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4775 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4777 TRACE("iface %p, palette %p.\n", iface
, palette
);
4779 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4780 return DDERR_NOTONMIPMAPSUBLEVEL
;
4781 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4783 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4784 return DDERR_SURFACELOST
;
4787 return ddraw_surface_set_palette(surface
, palette
);
4790 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4792 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4794 TRACE("iface %p, palette %p.\n", iface
, palette
);
4796 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4798 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4799 return DDERR_SURFACELOST
;
4802 return ddraw_surface_set_palette(surface
, palette
);
4805 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4807 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4809 TRACE("iface %p, palette %p.\n", iface
, palette
);
4811 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4813 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4814 return DDERR_SURFACELOST
;
4817 return ddraw_surface_set_palette(surface
, palette
);
4820 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4822 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4824 TRACE("iface %p, palette %p.\n", iface
, palette
);
4826 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4828 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4829 return DDERR_SURFACELOST
;
4832 return ddraw_surface_set_palette(surface
, palette
);
4835 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4837 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4839 TRACE("iface %p, palette %p.\n", iface
, palette
);
4841 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4843 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4844 return DDERR_SURFACELOST
;
4847 return ddraw_surface_set_palette(surface
, palette
);
4850 /**********************************************************
4851 * IDirectDrawGammaControl::GetGammaRamp
4853 * Returns the current gamma ramp for a surface
4857 * gamma_ramp: Address to write the ramp to
4861 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4863 **********************************************************/
4864 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4865 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4867 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4869 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4873 WARN("Invalid gamma_ramp passed.\n");
4874 return DDERR_INVALIDPARAMS
;
4877 wined3d_mutex_lock();
4878 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4880 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4881 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4885 ERR("Not implemented for non-primary surfaces.\n");
4887 wined3d_mutex_unlock();
4892 /**********************************************************
4893 * IDirectDrawGammaControl::SetGammaRamp
4895 * Sets the red, green and blue gamma ramps for
4898 * flags: Can be DDSGR_CALIBRATE to request calibration
4899 * gamma_ramp: Structure containing the new gamma ramp
4903 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4905 **********************************************************/
4906 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4907 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4909 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4911 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4915 WARN("Invalid gamma_ramp passed.\n");
4916 return DDERR_INVALIDPARAMS
;
4919 wined3d_mutex_lock();
4920 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4922 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4923 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4924 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4928 ERR("Not implemented for non-primary surfaces.\n");
4930 wined3d_mutex_unlock();
4935 /*****************************************************************************
4936 * IDirect3DTexture2::PaletteChanged
4938 * Informs the texture about a palette change
4941 * start: Start index of the change
4942 * count: The number of changed entries
4945 * D3D_OK, because it's a stub
4947 *****************************************************************************/
4948 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4950 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4955 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4957 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4959 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4961 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4964 /*****************************************************************************
4965 * IDirect3DTexture::Unload
4967 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4973 *****************************************************************************/
4974 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4976 WARN("iface %p. Not implemented.\n", iface
);
4978 return DDERR_UNSUPPORTED
;
4981 /*****************************************************************************
4982 * IDirect3DTexture2::GetHandle
4984 * Returns handle for the texture. At the moment, the interface
4985 * to the IWineD3DTexture is used.
4988 * device: Device this handle is assigned to
4989 * handle: Address to store the handle at.
4994 *****************************************************************************/
4995 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4996 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4998 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
4999 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5001 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5003 wined3d_mutex_lock();
5005 if (!surface
->Handle
)
5007 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5008 if (h
== DDRAW_INVALID_HANDLE
)
5010 ERR("Failed to allocate a texture handle.\n");
5011 wined3d_mutex_unlock();
5012 return DDERR_OUTOFMEMORY
;
5015 surface
->Handle
= h
+ 1;
5018 TRACE("Returning handle %08x.\n", surface
->Handle
);
5019 *handle
= surface
->Handle
;
5021 wined3d_mutex_unlock();
5026 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5027 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5029 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5030 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5032 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5034 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5035 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5038 /*****************************************************************************
5039 * get_sub_mimaplevel
5041 * Helper function that returns the next mipmap level
5043 * tex_ptr: Surface of which to return the next level
5045 *****************************************************************************/
5046 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5048 /* Now go down the mipmap chain to the next surface */
5049 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5050 IDirectDrawSurface7
*next_level
;
5053 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5054 if (FAILED(hr
)) return NULL
;
5056 ddraw_surface7_Release(next_level
);
5058 return impl_from_IDirectDrawSurface7(next_level
);
5061 /*****************************************************************************
5062 * IDirect3DTexture2::Load
5064 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5066 * This function isn't relayed to WineD3D because the whole interface is
5067 * implemented in DDraw only. For speed improvements an implementation which
5068 * takes OpenGL more into account could be placed into WineD3D.
5071 * src_texture: Address of the texture to load
5075 * D3DERR_TEXTURE_LOAD_FAILED.
5077 *****************************************************************************/
5078 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5080 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5081 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5084 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5086 if (src_surface
== dst_surface
)
5088 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5092 wined3d_mutex_lock();
5094 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5095 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5096 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5098 ERR("Trying to load surfaces with different mip-map counts.\n");
5103 struct ddraw_palette
*dst_pal
, *src_pal
;
5104 DDSURFACEDESC
*src_desc
, *dst_desc
;
5106 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5108 /* Suppress the ALLOCONLOAD flag */
5109 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5111 /* Get the palettes */
5112 dst_pal
= dst_surface
->palette
;
5113 src_pal
= src_surface
->palette
;
5117 PALETTEENTRY palent
[256];
5121 wined3d_mutex_unlock();
5122 return DDERR_NOPALETTEATTACHED
;
5124 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5125 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5128 /* Copy one surface on the other */
5129 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5130 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5132 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5134 /* Should also check for same pixel format, u1.lPitch, ... */
5135 ERR("Error in surface sizes.\n");
5136 wined3d_mutex_unlock();
5137 return D3DERR_TEXTURE_LOAD_FAILED
;
5141 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5143 /* Copy the src blit color key if the source has one, don't erase
5144 * the destination's ckey if the source has none */
5145 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5147 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5148 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5151 /* Copy the main memory texture into the surface that corresponds
5152 * to the OpenGL texture object. */
5154 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_map_desc
, NULL
, 0);
5157 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5158 wined3d_mutex_unlock();
5159 return D3DERR_TEXTURE_LOAD_FAILED
;
5162 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_map_desc
, NULL
, 0);
5165 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5166 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5167 wined3d_mutex_unlock();
5168 return D3DERR_TEXTURE_LOAD_FAILED
;
5171 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5172 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5174 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5176 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5177 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
5180 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5181 src_surface
= get_sub_mimaplevel(src_surface
);
5185 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5186 dst_surface
= get_sub_mimaplevel(dst_surface
);
5190 if (!src_surface
|| !dst_surface
)
5192 if (src_surface
!= dst_surface
)
5193 ERR("Loading surface with different mipmap structure.\n");
5198 wined3d_mutex_unlock();
5203 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5205 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5206 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5208 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5210 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5211 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5214 /*****************************************************************************
5216 *****************************************************************************/
5218 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5221 ddraw_surface7_QueryInterface
,
5222 ddraw_surface7_AddRef
,
5223 ddraw_surface7_Release
,
5224 /* IDirectDrawSurface */
5225 ddraw_surface7_AddAttachedSurface
,
5226 ddraw_surface7_AddOverlayDirtyRect
,
5228 ddraw_surface7_BltBatch
,
5229 ddraw_surface7_BltFast
,
5230 ddraw_surface7_DeleteAttachedSurface
,
5231 ddraw_surface7_EnumAttachedSurfaces
,
5232 ddraw_surface7_EnumOverlayZOrders
,
5233 ddraw_surface7_Flip
,
5234 ddraw_surface7_GetAttachedSurface
,
5235 ddraw_surface7_GetBltStatus
,
5236 ddraw_surface7_GetCaps
,
5237 ddraw_surface7_GetClipper
,
5238 ddraw_surface7_GetColorKey
,
5239 ddraw_surface7_GetDC
,
5240 ddraw_surface7_GetFlipStatus
,
5241 ddraw_surface7_GetOverlayPosition
,
5242 ddraw_surface7_GetPalette
,
5243 ddraw_surface7_GetPixelFormat
,
5244 ddraw_surface7_GetSurfaceDesc
,
5245 ddraw_surface7_Initialize
,
5246 ddraw_surface7_IsLost
,
5247 ddraw_surface7_Lock
,
5248 ddraw_surface7_ReleaseDC
,
5249 ddraw_surface7_Restore
,
5250 ddraw_surface7_SetClipper
,
5251 ddraw_surface7_SetColorKey
,
5252 ddraw_surface7_SetOverlayPosition
,
5253 ddraw_surface7_SetPalette
,
5254 ddraw_surface7_Unlock
,
5255 ddraw_surface7_UpdateOverlay
,
5256 ddraw_surface7_UpdateOverlayDisplay
,
5257 ddraw_surface7_UpdateOverlayZOrder
,
5258 /* IDirectDrawSurface2 */
5259 ddraw_surface7_GetDDInterface
,
5260 ddraw_surface7_PageLock
,
5261 ddraw_surface7_PageUnlock
,
5262 /* IDirectDrawSurface3 */
5263 ddraw_surface7_SetSurfaceDesc
,
5264 /* IDirectDrawSurface4 */
5265 ddraw_surface7_SetPrivateData
,
5266 ddraw_surface7_GetPrivateData
,
5267 ddraw_surface7_FreePrivateData
,
5268 ddraw_surface7_GetUniquenessValue
,
5269 ddraw_surface7_ChangeUniquenessValue
,
5270 /* IDirectDrawSurface7 */
5271 ddraw_surface7_SetPriority
,
5272 ddraw_surface7_GetPriority
,
5273 ddraw_surface7_SetLOD
,
5274 ddraw_surface7_GetLOD
,
5277 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5280 ddraw_surface4_QueryInterface
,
5281 ddraw_surface4_AddRef
,
5282 ddraw_surface4_Release
,
5283 /* IDirectDrawSurface */
5284 ddraw_surface4_AddAttachedSurface
,
5285 ddraw_surface4_AddOverlayDirtyRect
,
5287 ddraw_surface4_BltBatch
,
5288 ddraw_surface4_BltFast
,
5289 ddraw_surface4_DeleteAttachedSurface
,
5290 ddraw_surface4_EnumAttachedSurfaces
,
5291 ddraw_surface4_EnumOverlayZOrders
,
5292 ddraw_surface4_Flip
,
5293 ddraw_surface4_GetAttachedSurface
,
5294 ddraw_surface4_GetBltStatus
,
5295 ddraw_surface4_GetCaps
,
5296 ddraw_surface4_GetClipper
,
5297 ddraw_surface4_GetColorKey
,
5298 ddraw_surface4_GetDC
,
5299 ddraw_surface4_GetFlipStatus
,
5300 ddraw_surface4_GetOverlayPosition
,
5301 ddraw_surface4_GetPalette
,
5302 ddraw_surface4_GetPixelFormat
,
5303 ddraw_surface4_GetSurfaceDesc
,
5304 ddraw_surface4_Initialize
,
5305 ddraw_surface4_IsLost
,
5306 ddraw_surface4_Lock
,
5307 ddraw_surface4_ReleaseDC
,
5308 ddraw_surface4_Restore
,
5309 ddraw_surface4_SetClipper
,
5310 ddraw_surface4_SetColorKey
,
5311 ddraw_surface4_SetOverlayPosition
,
5312 ddraw_surface4_SetPalette
,
5313 ddraw_surface4_Unlock
,
5314 ddraw_surface4_UpdateOverlay
,
5315 ddraw_surface4_UpdateOverlayDisplay
,
5316 ddraw_surface4_UpdateOverlayZOrder
,
5317 /* IDirectDrawSurface2 */
5318 ddraw_surface4_GetDDInterface
,
5319 ddraw_surface4_PageLock
,
5320 ddraw_surface4_PageUnlock
,
5321 /* IDirectDrawSurface3 */
5322 ddraw_surface4_SetSurfaceDesc
,
5323 /* IDirectDrawSurface4 */
5324 ddraw_surface4_SetPrivateData
,
5325 ddraw_surface4_GetPrivateData
,
5326 ddraw_surface4_FreePrivateData
,
5327 ddraw_surface4_GetUniquenessValue
,
5328 ddraw_surface4_ChangeUniquenessValue
,
5331 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5334 ddraw_surface3_QueryInterface
,
5335 ddraw_surface3_AddRef
,
5336 ddraw_surface3_Release
,
5337 /* IDirectDrawSurface */
5338 ddraw_surface3_AddAttachedSurface
,
5339 ddraw_surface3_AddOverlayDirtyRect
,
5341 ddraw_surface3_BltBatch
,
5342 ddraw_surface3_BltFast
,
5343 ddraw_surface3_DeleteAttachedSurface
,
5344 ddraw_surface3_EnumAttachedSurfaces
,
5345 ddraw_surface3_EnumOverlayZOrders
,
5346 ddraw_surface3_Flip
,
5347 ddraw_surface3_GetAttachedSurface
,
5348 ddraw_surface3_GetBltStatus
,
5349 ddraw_surface3_GetCaps
,
5350 ddraw_surface3_GetClipper
,
5351 ddraw_surface3_GetColorKey
,
5352 ddraw_surface3_GetDC
,
5353 ddraw_surface3_GetFlipStatus
,
5354 ddraw_surface3_GetOverlayPosition
,
5355 ddraw_surface3_GetPalette
,
5356 ddraw_surface3_GetPixelFormat
,
5357 ddraw_surface3_GetSurfaceDesc
,
5358 ddraw_surface3_Initialize
,
5359 ddraw_surface3_IsLost
,
5360 ddraw_surface3_Lock
,
5361 ddraw_surface3_ReleaseDC
,
5362 ddraw_surface3_Restore
,
5363 ddraw_surface3_SetClipper
,
5364 ddraw_surface3_SetColorKey
,
5365 ddraw_surface3_SetOverlayPosition
,
5366 ddraw_surface3_SetPalette
,
5367 ddraw_surface3_Unlock
,
5368 ddraw_surface3_UpdateOverlay
,
5369 ddraw_surface3_UpdateOverlayDisplay
,
5370 ddraw_surface3_UpdateOverlayZOrder
,
5371 /* IDirectDrawSurface2 */
5372 ddraw_surface3_GetDDInterface
,
5373 ddraw_surface3_PageLock
,
5374 ddraw_surface3_PageUnlock
,
5375 /* IDirectDrawSurface3 */
5376 ddraw_surface3_SetSurfaceDesc
,
5379 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5382 ddraw_surface2_QueryInterface
,
5383 ddraw_surface2_AddRef
,
5384 ddraw_surface2_Release
,
5385 /* IDirectDrawSurface */
5386 ddraw_surface2_AddAttachedSurface
,
5387 ddraw_surface2_AddOverlayDirtyRect
,
5389 ddraw_surface2_BltBatch
,
5390 ddraw_surface2_BltFast
,
5391 ddraw_surface2_DeleteAttachedSurface
,
5392 ddraw_surface2_EnumAttachedSurfaces
,
5393 ddraw_surface2_EnumOverlayZOrders
,
5394 ddraw_surface2_Flip
,
5395 ddraw_surface2_GetAttachedSurface
,
5396 ddraw_surface2_GetBltStatus
,
5397 ddraw_surface2_GetCaps
,
5398 ddraw_surface2_GetClipper
,
5399 ddraw_surface2_GetColorKey
,
5400 ddraw_surface2_GetDC
,
5401 ddraw_surface2_GetFlipStatus
,
5402 ddraw_surface2_GetOverlayPosition
,
5403 ddraw_surface2_GetPalette
,
5404 ddraw_surface2_GetPixelFormat
,
5405 ddraw_surface2_GetSurfaceDesc
,
5406 ddraw_surface2_Initialize
,
5407 ddraw_surface2_IsLost
,
5408 ddraw_surface2_Lock
,
5409 ddraw_surface2_ReleaseDC
,
5410 ddraw_surface2_Restore
,
5411 ddraw_surface2_SetClipper
,
5412 ddraw_surface2_SetColorKey
,
5413 ddraw_surface2_SetOverlayPosition
,
5414 ddraw_surface2_SetPalette
,
5415 ddraw_surface2_Unlock
,
5416 ddraw_surface2_UpdateOverlay
,
5417 ddraw_surface2_UpdateOverlayDisplay
,
5418 ddraw_surface2_UpdateOverlayZOrder
,
5419 /* IDirectDrawSurface2 */
5420 ddraw_surface2_GetDDInterface
,
5421 ddraw_surface2_PageLock
,
5422 ddraw_surface2_PageUnlock
,
5425 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5428 ddraw_surface1_QueryInterface
,
5429 ddraw_surface1_AddRef
,
5430 ddraw_surface1_Release
,
5431 /* IDirectDrawSurface */
5432 ddraw_surface1_AddAttachedSurface
,
5433 ddraw_surface1_AddOverlayDirtyRect
,
5435 ddraw_surface1_BltBatch
,
5436 ddraw_surface1_BltFast
,
5437 ddraw_surface1_DeleteAttachedSurface
,
5438 ddraw_surface1_EnumAttachedSurfaces
,
5439 ddraw_surface1_EnumOverlayZOrders
,
5440 ddraw_surface1_Flip
,
5441 ddraw_surface1_GetAttachedSurface
,
5442 ddraw_surface1_GetBltStatus
,
5443 ddraw_surface1_GetCaps
,
5444 ddraw_surface1_GetClipper
,
5445 ddraw_surface1_GetColorKey
,
5446 ddraw_surface1_GetDC
,
5447 ddraw_surface1_GetFlipStatus
,
5448 ddraw_surface1_GetOverlayPosition
,
5449 ddraw_surface1_GetPalette
,
5450 ddraw_surface1_GetPixelFormat
,
5451 ddraw_surface1_GetSurfaceDesc
,
5452 ddraw_surface1_Initialize
,
5453 ddraw_surface1_IsLost
,
5454 ddraw_surface1_Lock
,
5455 ddraw_surface1_ReleaseDC
,
5456 ddraw_surface1_Restore
,
5457 ddraw_surface1_SetClipper
,
5458 ddraw_surface1_SetColorKey
,
5459 ddraw_surface1_SetOverlayPosition
,
5460 ddraw_surface1_SetPalette
,
5461 ddraw_surface1_Unlock
,
5462 ddraw_surface1_UpdateOverlay
,
5463 ddraw_surface1_UpdateOverlayDisplay
,
5464 ddraw_surface1_UpdateOverlayZOrder
,
5467 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5469 ddraw_gamma_control_QueryInterface
,
5470 ddraw_gamma_control_AddRef
,
5471 ddraw_gamma_control_Release
,
5472 ddraw_gamma_control_GetGammaRamp
,
5473 ddraw_gamma_control_SetGammaRamp
,
5476 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5478 d3d_texture2_QueryInterface
,
5479 d3d_texture2_AddRef
,
5480 d3d_texture2_Release
,
5481 d3d_texture2_GetHandle
,
5482 d3d_texture2_PaletteChanged
,
5486 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5488 d3d_texture1_QueryInterface
,
5489 d3d_texture1_AddRef
,
5490 d3d_texture1_Release
,
5491 d3d_texture1_Initialize
,
5492 d3d_texture1_GetHandle
,
5493 d3d_texture1_PaletteChanged
,
5495 d3d_texture1_Unload
,
5498 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5499 * IDirectDrawSurface interface to ddraw methods. */
5500 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5502 if (!iface
) return NULL
;
5503 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5505 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5508 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5511 IDirectDrawSurface7_Release(iface
);
5513 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5516 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5518 if (!iface
) return NULL
;
5519 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5521 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5524 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5527 IDirectDrawSurface4_Release(iface
);
5529 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5532 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5534 if (!iface
) return NULL
;
5535 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5537 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5540 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5543 IDirectDrawSurface3_Release(iface
);
5545 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5548 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5550 if (!iface
) return NULL
;
5551 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5553 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5556 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5559 IDirectDrawSurface2_Release(iface
);
5561 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5564 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5566 if (!iface
) return NULL
;
5567 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5569 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5572 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5575 IDirectDrawSurface_Release(iface
);
5577 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5580 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5582 if (!iface
) return NULL
;
5583 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5584 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5587 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5589 if (!iface
) return NULL
;
5590 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5591 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5594 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5596 struct ddraw_surface
*surface
= parent
;
5598 TRACE("surface %p.\n", surface
);
5600 /* Check for attached surfaces and detach them. */
5601 if (surface
->first_attached
!= surface
)
5603 /* Well, this shouldn't happen: The surface being attached is
5604 * referenced in AddAttachedSurface(), so it shouldn't be released
5605 * until DeleteAttachedSurface() is called, because the refcount is
5606 * held. It looks like the application released it often enough to
5608 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5610 /* The refcount will drop to -1 here */
5611 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5612 ERR("DeleteAttachedSurface failed.\n");
5615 while (surface
->next_attached
)
5616 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5617 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5618 ERR("DeleteAttachedSurface failed.\n");
5620 /* Having a texture handle set implies that the device still exists. */
5621 if (surface
->Handle
)
5622 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5624 /* Reduce the ddraw surface count. */
5625 list_remove(&surface
->surface_list_entry
);
5627 if (surface
->clipper
)
5628 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5630 if (surface
== surface
->ddraw
->primary
)
5631 surface
->ddraw
->primary
= NULL
;
5633 wined3d_private_store_cleanup(&surface
->private_store
);
5635 HeapFree(GetProcessHeap(), 0, surface
);
5638 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5640 ddraw_surface_wined3d_object_destroyed
,
5643 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5645 TRACE("parent %p.\n", parent
);
5647 HeapFree(GetProcessHeap(), 0, parent
);
5650 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5652 ddraw_texture_wined3d_object_destroyed
,
5655 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5660 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5661 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5663 struct ddraw_surface
*root
, *mip
, **attach
;
5664 struct wined3d_resource_desc wined3d_desc
;
5665 struct wined3d_texture
*wined3d_texture
;
5666 struct wined3d_resource
*resource
;
5667 struct wined3d_display_mode mode
;
5668 DDSURFACEDESC2
*desc
, *mip_desc
;
5669 struct ddraw_texture
*texture
;
5670 UINT layers
, levels
, i
, j
;
5671 unsigned int pitch
= 0;
5674 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5675 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5676 if (TRACE_ON(ddraw
))
5678 TRACE("Requesting surface desc:\n");
5679 DDRAW_dump_surface_desc(surface_desc
);
5683 return CLASS_E_NOAGGREGATION
;
5688 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5689 return E_OUTOFMEMORY
;
5691 texture
->version
= version
;
5692 texture
->surface_desc
= *surface_desc
;
5693 desc
= &texture
->surface_desc
;
5695 /* Ensure DDSD_CAPS is always set. */
5696 desc
->dwFlags
|= DDSD_CAPS
;
5698 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5700 DWORD flippable
= desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
);
5702 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5704 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5705 HeapFree(GetProcessHeap(), 0, texture
);
5706 return DDERR_INVALIDCAPS
;
5711 if (flippable
!= (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
))
5713 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5714 HeapFree(GetProcessHeap(), 0, texture
);
5715 return DDERR_INVALIDCAPS
;
5718 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5720 WARN("Tried to create a flippable primary surface without any back buffers.\n");
5721 HeapFree(GetProcessHeap(), 0, texture
);
5722 return DDERR_INVALIDCAPS
;
5725 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5727 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5728 HeapFree(GetProcessHeap(), 0, texture
);
5729 return DDERR_NOEXCLUSIVEMODE
;
5734 /* This is a special case in ddrawex, but not allowed in ddraw. */
5735 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5736 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5738 WARN("Tried to create a surface in both system and video memory.\n");
5739 HeapFree(GetProcessHeap(), 0, texture
);
5740 return DDERR_INVALIDCAPS
;
5743 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5744 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5746 WARN("Cube map faces requested without cube map flag.\n");
5747 HeapFree(GetProcessHeap(), 0, texture
);
5748 return DDERR_INVALIDCAPS
;
5751 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5752 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5754 WARN("Cube map without faces requested.\n");
5755 HeapFree(GetProcessHeap(), 0, texture
);
5756 return DDERR_INVALIDPARAMS
;
5759 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5760 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5761 FIXME("Partial cube maps not implemented.\n");
5763 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5765 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5767 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5768 HeapFree(GetProcessHeap(), 0, texture
);
5769 return DDERR_INVALIDCAPS
;
5771 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5773 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5774 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5775 HeapFree(GetProcessHeap(), 0, texture
);
5776 return DDERR_INVALIDCAPS
;
5780 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5782 ERR("Failed to get display mode, hr %#x.\n", hr
);
5783 HeapFree(GetProcessHeap(), 0, texture
);
5784 return hr_ddraw_from_wined3d(hr
);
5787 /* No pixelformat given? Use the current screen format. */
5788 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5790 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5791 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5792 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5795 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5796 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5798 WARN("Unsupported / unknown pixelformat.\n");
5799 HeapFree(GetProcessHeap(), 0, texture
);
5800 return DDERR_INVALIDPIXELFORMAT
;
5803 /* No width or no height? Use the screen size. */
5804 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5806 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5808 WARN("No width / height specified.\n");
5809 HeapFree(GetProcessHeap(), 0, texture
);
5810 return DDERR_INVALIDPARAMS
;
5813 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5814 desc
->dwWidth
= mode
.width
;
5815 desc
->dwHeight
= mode
.height
;
5818 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5820 HeapFree(GetProcessHeap(), 0, texture
);
5821 return DDERR_INVALIDPARAMS
;
5824 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5826 /* The first surface is a front buffer, the back buffers are created
5828 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5829 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5830 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5831 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5833 struct wined3d_swapchain_desc swapchain_desc
;
5835 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5836 swapchain_desc
.backbuffer_width
= mode
.width
;
5837 swapchain_desc
.backbuffer_height
= mode
.height
;
5838 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5840 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5841 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5843 ERR("Failed to reset device.\n");
5844 HeapFree(GetProcessHeap(), 0, texture
);
5845 return hr_ddraw_from_wined3d(hr
);
5850 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5851 wined3d_desc
.multisample_quality
= 0;
5852 wined3d_desc
.usage
= 0;
5853 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5854 wined3d_desc
.width
= desc
->dwWidth
;
5855 wined3d_desc
.height
= desc
->dwHeight
;
5856 wined3d_desc
.depth
= 1;
5857 wined3d_desc
.size
= 0;
5859 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5861 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5862 /* Do not fail surface creation, only fail 3D device creation. */
5865 /* Mipmap count fixes */
5866 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5868 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5870 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5872 /* Mipmap count is given, should not be 0. */
5873 if (!desc
->u2
.dwMipMapCount
)
5875 HeapFree(GetProcessHeap(), 0, texture
);
5876 return DDERR_INVALIDPARAMS
;
5881 /* Undocumented feature: Create sublevels until either the
5882 * width or the height is 1. */
5883 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5888 desc
->u2
.dwMipMapCount
= 1;
5891 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5892 levels
= desc
->u2
.dwMipMapCount
;
5899 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5901 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5903 enum wined3d_resource_type rtype
;
5906 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5907 rtype
= WINED3D_RTYPE_CUBE_TEXTURE
;
5908 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5909 rtype
= WINED3D_RTYPE_TEXTURE
;
5911 rtype
= WINED3D_RTYPE_SURFACE
;
5913 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5914 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5915 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5916 usage
= WINED3DUSAGE_RENDERTARGET
;
5918 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5919 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, rtype
, wined3d_desc
.format
)))
5920 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5922 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5924 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5926 /* Tests show surfaces without memory flags get these flags added
5927 * right after creation. */
5928 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5932 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5933 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5935 WARN("System memory overlays are not allowed.\n");
5936 HeapFree(GetProcessHeap(), 0, texture
);
5937 return DDERR_NOOVERLAYHW
;
5940 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5942 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
5946 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5947 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
5948 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5949 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5950 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5951 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
5953 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5955 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
5956 /* Managed textures have the system memory flag set. */
5957 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5959 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5961 /* Videomemory adds localvidmem. This is mutually exclusive with
5962 * systemmemory and texturemanage. */
5963 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5964 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
5968 /* If the surface is of the 'ALLOCONLOAD' type, ignore the LPSURFACE
5969 * field. Frank Herbert's Dune specifies a NULL pointer for lpSurface. */
5970 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
) || !desc
->lpSurface
)
5971 desc
->dwFlags
&= ~DDSD_LPSURFACE
;
5972 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5974 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
5976 WARN("User memory surfaces should be in the system memory pool.\n");
5977 HeapFree(GetProcessHeap(), 0, texture
);
5978 return DDERR_INVALIDCAPS
;
5983 WARN("User memory surfaces not supported before version 4.\n");
5984 HeapFree(GetProcessHeap(), 0, texture
);
5985 return DDERR_INVALIDPARAMS
;
5988 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
5990 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
5992 WARN("Pitch specified on a compressed user memory surface.\n");
5993 HeapFree(GetProcessHeap(), 0, texture
);
5994 return DDERR_INVALIDPARAMS
;
5997 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
5999 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6000 HeapFree(GetProcessHeap(), 0, texture
);
6001 return DDERR_INVALIDPARAMS
;
6004 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6005 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6006 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6008 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6009 HeapFree(GetProcessHeap(), 0, texture
);
6010 return DDERR_INVALIDPARAMS
;
6015 if (!(desc
->dwFlags
& DDSD_PITCH
))
6017 WARN("User memory surfaces should explicitly specify the pitch.\n");
6018 HeapFree(GetProcessHeap(), 0, texture
);
6019 return DDERR_INVALIDPARAMS
;
6022 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6023 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6025 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6026 HeapFree(GetProcessHeap(), 0, texture
);
6027 return DDERR_INVALIDPARAMS
;
6030 pitch
= desc
->u1
.lPitch
;
6034 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6035 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6036 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6037 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6038 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6039 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6040 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6041 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6043 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6044 HeapFree(GetProcessHeap(), 0, texture
);
6045 return DDERR_NOCOLORKEYHW
;
6048 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6049 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6051 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6052 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6054 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6056 wined3d_desc
.resource_type
= WINED3D_RTYPE_CUBE_TEXTURE
;
6061 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
6065 /* Some applications assume surfaces will always be mapped at the same
6066 * address. Some of those also assume that this address is valid even when
6067 * the surface isn't mapped, and that updates done this way will be
6068 * visible on the screen. The game Nox is such an application,
6069 * Commandos: Behind Enemy Lines is another. We set
6070 * WINED3D_SURFACE_PIN_SYSMEM because of this. */
6071 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
6072 WINED3D_SURFACE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6074 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6075 HeapFree(GetProcessHeap(), 0, texture
);
6076 return hr_ddraw_from_wined3d(hr
);
6079 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6080 root
= wined3d_resource_get_parent(resource
);
6081 root
->wined3d_texture
= wined3d_texture
;
6082 root
->is_complex_root
= TRUE
;
6083 texture
->root
= root
;
6085 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6086 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6087 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6088 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6089 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6090 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6091 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6092 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6093 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6094 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6095 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6096 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6098 for (i
= 0; i
< layers
; ++i
)
6100 attach
= &root
->complex_array
[layers
- 1 - i
];
6102 for (j
= 0; j
< levels
; ++j
)
6104 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
6105 mip
= wined3d_resource_get_parent(resource
);
6106 mip_desc
= &mip
->surface_desc
;
6109 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6111 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6113 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6115 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6119 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6120 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6122 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6123 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6125 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6126 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6128 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6129 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6131 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6132 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6134 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6135 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6145 attach
= &mip
->complex_array
[0];
6149 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6150 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6151 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6153 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6157 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6159 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6160 struct ddraw_surface
*last
= root
;
6162 attach
= &last
->complex_array
[0];
6163 for (i
= 0; i
< count
; ++i
)
6165 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6171 texture
->version
= version
;
6172 texture
->surface_desc
= root
->surface_desc
;
6173 desc
= &texture
->surface_desc
;
6175 /* Only one surface in the flipping chain is a back buffer, one is
6176 * a front buffer, the others are just flippable surfaces. */
6177 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6178 | DDSCAPS_BACKBUFFER
);
6180 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6181 desc
->u5
.dwBackBufferCount
= 0;
6183 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1,
6184 WINED3D_SURFACE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6186 HeapFree(GetProcessHeap(), 0, texture
);
6187 hr
= hr_ddraw_from_wined3d(hr
);
6191 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6192 last
= wined3d_resource_get_parent(resource
);
6193 last
->wined3d_texture
= wined3d_texture
;
6194 texture
->root
= last
;
6196 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6197 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6198 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6199 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6200 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6201 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6202 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6203 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6204 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6205 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6206 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6207 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6210 attach
= &last
->complex_array
[0];
6215 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6216 ddraw
->primary
= root
;
6223 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6224 else if (version
== 4)
6225 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6227 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6232 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
, struct ddraw_texture
*texture
,
6233 struct wined3d_surface
*wined3d_surface
, const struct wined3d_parent_ops
**parent_ops
)
6235 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6236 struct wined3d_resource_desc wined3d_desc
;
6237 unsigned int version
= texture
->version
;
6239 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6240 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6241 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6242 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6243 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6244 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6245 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6246 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6247 surface
->iface_count
= 1;
6248 surface
->version
= version
;
6249 surface
->ddraw
= ddraw
;
6254 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6256 else if (version
== 4)
6259 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6264 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6267 *desc
= texture
->surface_desc
;
6268 wined3d_resource_get_desc(wined3d_surface_get_resource(wined3d_surface
), &wined3d_desc
);
6269 desc
->dwWidth
= wined3d_desc
.width
;
6270 desc
->dwHeight
= wined3d_desc
.height
;
6271 surface
->first_attached
= surface
;
6273 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6275 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6276 desc
->u1
.dwLinearSize
= ~0u;
6278 desc
->u1
.dwLinearSize
= wined3d_surface_get_pitch(wined3d_surface
) * ((desc
->dwHeight
+ 3) / 4);
6279 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6280 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6284 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6285 desc
->u1
.lPitch
= wined3d_surface_get_pitch(wined3d_surface
);
6286 desc
->dwFlags
|= DDSD_PITCH
;
6287 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6289 desc
->lpSurface
= NULL
;
6291 wined3d_surface_incref(wined3d_surface
);
6292 surface
->wined3d_surface
= wined3d_surface
;
6293 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6295 wined3d_private_store_init(&surface
->private_store
);
6298 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6300 struct ddraw_surface
*surface
= parent
;
6302 /* If the surface reference count drops to zero, we release our reference
6303 * to the view, but don't clear the pointer yet, in case e.g. a
6304 * GetRenderTarget() call brings the surface back before the view is
6305 * actually destroyed. When the view is destroyed, we need to clear the
6306 * pointer, or a subsequent surface AddRef() would reference it again.
6308 * This is safe because as long as the view still has a reference to the
6309 * texture, the surface is also still alive, and we're called before the
6310 * view releases that reference. */
6311 surface
->wined3d_rtv
= NULL
;
6314 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6316 view_wined3d_object_destroyed
,
6319 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6323 if (surface
->wined3d_rtv
)
6324 return surface
->wined3d_rtv
;
6326 if (FAILED(hr
= wined3d_rendertarget_view_create_from_surface(surface
->wined3d_surface
,
6327 surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6329 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6333 return surface
->wined3d_rtv
;