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
24 #include "ddraw_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
28 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
29 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
31 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
33 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
36 static BOOL
ddraw_surface_is_lost(const struct ddraw_surface
*surface
)
38 return ddraw_surface_can_be_lost(surface
)
39 && (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
);
42 static BOOL
ddraw_gdi_is_front(struct ddraw
*ddraw
)
44 struct ddraw_surface
*surface
;
46 if (!ddraw
->gdi_surface
|| !(surface
= wined3d_texture_get_sub_resource_parent(ddraw
->gdi_surface
, 0)))
49 return surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
;
52 /* This is slow, of course. Also, in case of locks, we can't prevent other
53 * applications from drawing to the screen while we've locked the frontbuffer.
54 * We'd like to do this in wined3d instead, but for that to work wined3d needs
55 * to support windowless rendering first. */
56 HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
,
57 const RECT
*rect
, BOOL read
, unsigned int swap_interval
)
59 struct wined3d_texture
*dst_texture
, *wined3d_texture
;
60 struct ddraw
*ddraw
= surface
->ddraw
;
61 HDC surface_dc
, screen_dc
;
67 if (ddraw
->flags
& DDRAW_SWAPPED
&& !read
)
69 ddraw
->flags
&= ~DDRAW_SWAPPED
;
75 SetRect(&r
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
81 w
= rect
->right
- rect
->left
;
82 h
= rect
->bottom
- rect
->top
;
87 /* The interaction between ddraw and GDI drawing is not all that well
88 * documented, and somewhat arcane. In ddraw exclusive mode, GDI draws
89 * seemingly go to the *original* frontbuffer/primary surface, while ddraw
90 * draws/flips go to the *current* frontbuffer surface. The bottom line is
91 * that if the current frontbuffer is not the GDI frontbuffer, and there's
92 * e.g. a popup window in front of the ddraw swapchain window, we can't
93 * use wined3d_swapchain_present() to get the ddraw contents to the screen
94 * while in exclusive mode, since it would get obscured by the popup
95 * window. On the other hand, if the current frontbuffer *is* the GDI
96 * frontbuffer, that's what's supposed to happen; the popup should obscure
97 * (oart of) the ddraw swapchain window.
99 * This affects the "Deer Hunter" demo, which uses a popup window and GDI
100 * draws to draw part of the user interface. See also the "fswindow"
101 * sample is the DirectX 7 SDK. */
102 if (ddraw
->swapchain_window
&& (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
103 || ddraw
->swapchain_window
== GetForegroundWindow() || ddraw_gdi_is_front(ddraw
)))
105 /* Nothing to do, we control the frontbuffer, or at least the parts we
111 dst_texture
= wined3d_swapchain_get_back_buffer(ddraw
->wined3d_swapchain
, 0);
113 dst_texture
= ddraw
->wined3d_frontbuffer
;
115 if (SUCCEEDED(hr
= wined3d_texture_blt(dst_texture
, 0, rect
,
116 ddraw_surface_get_any_texture(surface
, DDRAW_SURFACE_READ
), surface
->sub_resource_idx
, rect
, 0,
117 NULL
, WINED3D_TEXF_POINT
)) && swap_interval
)
119 hr
= wined3d_swapchain_present(ddraw
->wined3d_swapchain
, rect
, rect
, NULL
, swap_interval
, 0);
120 ddraw
->flags
|= DDRAW_SWAPPED
;
125 wined3d_texture
= ddraw_surface_get_default_texture(surface
, read
? (rect
? DDRAW_SURFACE_RW
: DDRAW_SURFACE_WRITE
)
126 : DDRAW_SURFACE_READ
);
128 if (FAILED(hr
= wined3d_texture_get_dc(wined3d_texture
, surface
->sub_resource_idx
, &surface_dc
)))
130 ERR("Failed to get surface DC, hr %#x.\n", hr
);
133 if (surface
->palette
)
134 wined3d_palette_apply_to_dc(surface
->palette
->wined3d_palette
, surface_dc
);
136 if (!(screen_dc
= GetDC(NULL
)))
138 wined3d_texture_release_dc(wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
139 ERR("Failed to get screen DC.\n");
144 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
145 screen_dc
, x
, y
, SRCCOPY
);
147 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
148 surface_dc
, x
, y
, SRCCOPY
);
150 ReleaseDC(NULL
, screen_dc
);
151 wined3d_texture_release_dc(wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
155 ERR("Failed to blit to/from screen.\n");
162 /*****************************************************************************
163 * IUnknown parts follow
164 *****************************************************************************/
166 /*****************************************************************************
167 * IDirectDrawSurface7::QueryInterface
169 * A normal QueryInterface implementation. For QueryInterface rules
170 * see ddraw.c, IDirectDraw7::QueryInterface. This method
171 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
172 * in all versions, the IDirectDrawGammaControl interface and it can
173 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
176 * riid: The interface id queried for
177 * obj: Address to write the pointer to
181 * E_NOINTERFACE if the requested interface wasn't found
183 *****************************************************************************/
184 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
186 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
188 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
190 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
194 return DDERR_INVALIDPARAMS
;
196 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
198 IDirectDrawSurface7_AddRef(iface
);
200 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
204 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
206 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
207 *obj
= &This
->IDirectDrawSurface4_iface
;
208 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
212 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
214 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
215 *obj
= &This
->IDirectDrawSurface3_iface
;
216 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
220 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
222 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
223 *obj
= &This
->IDirectDrawSurface2_iface
;
224 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
228 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
229 || IsEqualGUID(riid
, &IID_IUnknown
))
231 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
232 *obj
= &This
->IDirectDrawSurface_iface
;
233 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
237 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
239 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
240 *obj
= &This
->IDirectDrawGammaControl_iface
;
241 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
245 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
247 WARN("Color control not implemented.\n");
249 return E_NOINTERFACE
;
252 if (This
->version
!= 7)
254 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
255 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
256 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
258 wined3d_mutex_lock();
263 if (FAILED(hr
= d3d_device_create(This
->ddraw
, riid
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
264 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
266 This
->device1
= NULL
;
267 wined3d_mutex_unlock();
268 WARN("Failed to create device, hr %#x.\n", hr
);
272 wined3d_mutex_unlock();
274 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
275 *obj
= &This
->device1
->IDirect3DDevice_iface
;
279 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
281 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
282 *obj
= &This
->IDirect3DTexture2_iface
;
286 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
288 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
289 *obj
= &This
->IDirect3DTexture_iface
;
294 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
296 if (This
->version
!= 7)
299 return E_NOINTERFACE
;
302 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
304 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
306 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
308 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
311 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
313 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
315 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
317 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
320 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
322 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
324 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
326 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
329 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
331 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
333 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
335 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
338 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
339 REFIID riid
, void **object
)
341 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
343 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
345 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
348 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
350 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
352 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
354 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
357 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
359 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
361 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
363 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
366 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
368 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
369 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
371 if (iface_count
== 1)
373 if (surface
->ifaceToRelease
)
374 IUnknown_AddRef(surface
->ifaceToRelease
);
375 wined3d_mutex_lock();
376 if (surface
->wined3d_rtv
)
377 wined3d_rendertarget_view_incref(surface
->wined3d_rtv
);
378 wined3d_texture_incref(surface
->draw_texture
? surface
->draw_texture
: surface
->wined3d_texture
);
379 wined3d_mutex_unlock();
383 /*****************************************************************************
384 * IDirectDrawSurface7::AddRef
386 * A normal addref implementation
391 *****************************************************************************/
392 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
394 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
395 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
397 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
401 ddraw_surface_add_iface(This
);
407 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
409 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
410 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
412 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
416 ddraw_surface_add_iface(This
);
422 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
424 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
425 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
427 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
431 ddraw_surface_add_iface(This
);
437 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
439 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
440 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
442 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
446 ddraw_surface_add_iface(This
);
452 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
454 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
455 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
457 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
461 ddraw_surface_add_iface(This
);
467 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
469 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
470 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
472 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
476 ddraw_surface_add_iface(This
);
482 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
484 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
486 TRACE("iface %p.\n", iface
);
488 return IUnknown_AddRef(surface
->texture_outer
);
491 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
493 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
495 TRACE("iface %p.\n", iface
);
497 return IUnknown_AddRef(surface
->texture_outer
);
500 static HRESULT
ddraw_surface_set_palette(struct ddraw_surface
*surface
, IDirectDrawPalette
*palette
)
502 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(palette
);
503 struct ddraw_palette
*prev
;
505 TRACE("iface %p, palette %p.\n", surface
, palette
);
507 if (palette_impl
&& palette_impl
->flags
& DDPCAPS_ALPHA
508 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
510 WARN("Alpha palette set on non-texture surface, returning DDERR_INVALIDSURFACETYPE.\n");
511 return DDERR_INVALIDSURFACETYPE
;
514 if (!format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
515 return DDERR_INVALIDPIXELFORMAT
;
517 wined3d_mutex_lock();
519 prev
= surface
->palette
;
520 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
523 prev
->flags
&= ~DDPCAPS_PRIMARYSURFACE
;
525 palette_impl
->flags
|= DDPCAPS_PRIMARYSURFACE
;
526 wined3d_swapchain_set_palette(surface
->ddraw
->wined3d_swapchain
,
527 palette_impl
? palette_impl
->wined3d_palette
: NULL
);
528 ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
, 0);
531 IDirectDrawPalette_AddRef(&palette_impl
->IDirectDrawPalette_iface
);
533 IDirectDrawPalette_Release(&prev
->IDirectDrawPalette_iface
);
534 surface
->palette
= palette_impl
;
536 wined3d_mutex_unlock();
541 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
543 struct ddraw_surface
*surf
;
546 TRACE("surface %p.\n", surface
);
548 /* The refcount test shows that the palette is detached when the surface
550 ddraw_surface_set_palette(surface
, NULL
);
552 /* Loop through all complex attached surfaces and destroy them.
554 * Yet again, only the root can have more than one complexly attached
555 * surface, all the others have a total of one. */
556 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
558 if (!surface
->complex_array
[i
])
561 surf
= surface
->complex_array
[i
];
562 surface
->complex_array
[i
] = NULL
;
563 if (!surf
->is_complex_root
)
565 struct ddraw_texture
*texture
= wined3d_texture_get_parent(surf
->wined3d_texture
);
566 struct wined3d_device
*wined3d_device
= texture
->wined3d_device
;
567 struct ddraw_surface
*root
= texture
->root
;
569 ddraw_surface_cleanup(surf
);
572 wined3d_device_decref(wined3d_device
);
576 if (surface
->device1
)
577 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
579 if (surface
->iface_count
> 1)
581 /* This can happen when a complex surface is destroyed, because the
582 * 2nd surface was addref()ed when the app called
583 * GetAttachedSurface(). */
584 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
585 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
588 if (surface
->wined3d_rtv
)
589 wined3d_rendertarget_view_decref(surface
->wined3d_rtv
);
590 wined3d_texture_decref(surface
->draw_texture
? surface
->draw_texture
: surface
->wined3d_texture
);
593 static ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
597 /* Prevent the surface from being destroyed if it's still attached to
598 * another surface. It will be destroyed when the root is destroyed. */
599 if (This
->iface_count
== 1 && This
->attached_iface
)
600 IUnknown_AddRef(This
->attached_iface
);
601 iface_count
= InterlockedDecrement(&This
->iface_count
);
603 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
605 if (iface_count
== 0)
607 struct ddraw_texture
*texture
= wined3d_texture_get_parent(This
->wined3d_texture
);
608 struct wined3d_device
*wined3d_device
= texture
->wined3d_device
;
609 IUnknown
*release_iface
= This
->ifaceToRelease
;
611 /* Complex attached surfaces are destroyed implicitly when the root is released */
612 wined3d_mutex_lock();
613 if(!This
->is_complex_root
)
615 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
616 wined3d_mutex_unlock();
619 ddraw_surface_cleanup(This
);
620 wined3d_mutex_unlock();
623 IUnknown_Release(release_iface
);
624 /* Release the device only after anything that may reference it (the
625 * wined3d texture and rendertarget view in particular) is released. */
626 wined3d_device_decref(wined3d_device
);
632 /*****************************************************************************
633 * IDirectDrawSurface7::Release
635 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
636 * surface is destroyed.
638 * Destroying the surface is a bit tricky. For the connection between
639 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
640 * It has a nice graph explaining the connection.
642 * What happens here is basically this:
643 * When a surface is destroyed, its WineD3DSurface is released,
644 * and the refcount of the DirectDraw interface is reduced by 1. If it has
645 * complex surfaces attached to it, then these surfaces are destroyed too,
646 * regardless of their refcount. If any surface being destroyed has another
647 * surface attached to it (with a "soft" attachment, not complex), then
648 * this surface is detached with DeleteAttachedSurface.
650 * When the surface is a texture, the WineD3DTexture is released.
651 * If the surface is the Direct3D render target, then the D3D
652 * capabilities of the WineD3DDevice are uninitialized, which causes the
653 * swapchain to be released.
655 * When a complex sublevel falls to ref zero, then this is ignored.
660 *****************************************************************************/
661 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
663 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
664 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
666 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
670 ddraw_surface_release_iface(This
);
676 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
678 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
679 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
681 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
685 ddraw_surface_release_iface(This
);
691 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
693 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
694 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
696 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
700 ddraw_surface_release_iface(This
);
706 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
708 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
709 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
711 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
715 ddraw_surface_release_iface(This
);
721 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
723 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
724 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
726 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
730 ddraw_surface_release_iface(This
);
736 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
738 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
739 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
741 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
745 ddraw_surface_release_iface(This
);
751 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
753 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
755 TRACE("iface %p.\n", iface
);
757 return IUnknown_Release(surface
->texture_outer
);
760 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
762 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
764 TRACE("iface %p.\n", iface
);
766 return IUnknown_Release(surface
->texture_outer
);
769 /*****************************************************************************
770 * IDirectDrawSurface7::GetAttachedSurface
772 * Returns an attached surface with the requested caps. Surface attachment
773 * and complex surfaces are not clearly described by the MSDN or sdk,
774 * so this method is tricky and likely to contain problems.
775 * This implementation searches the complex list first, then the
778 * The chains are searched from This down to the last surface in the chain,
779 * not from the first element in the chain. The first surface found is
780 * returned. The MSDN says that this method fails if more than one surface
781 * matches the caps, but it is not sure if that is right. The attachment
782 * structure may not even allow two matching surfaces.
784 * The found surface is AddRef-ed before it is returned.
787 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
788 * Surface: Address to store the found surface
792 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
793 * DDERR_NOTFOUND if no surface was found
795 *****************************************************************************/
796 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
797 DDSCAPS2
*caps
, IDirectDrawSurface7
**surface
)
799 struct ddraw_surface
*head_surface
= impl_from_IDirectDrawSurface7(iface
);
800 struct ddraw_surface
*surf
;
804 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, surface
);
806 if (ddraw_surface_is_lost(head_surface
))
808 WARN("Surface %p is lost.\n", head_surface
);
811 return DDERR_SURFACELOST
;
814 wined3d_mutex_lock();
816 if(head_surface
->version
< 7)
818 /* Earlier dx apps put garbage into these members, clear them */
819 our_caps
.dwCaps
= caps
->dwCaps
;
820 our_caps
.dwCaps2
= 0;
821 our_caps
.dwCaps3
= 0;
822 our_caps
.u1
.dwCaps4
= 0;
829 TRACE("head_surface %p, looking for caps %#x, %#x, %#x, %#x.\n", head_surface
, our_caps
.dwCaps
,
830 our_caps
.dwCaps2
, our_caps
.dwCaps3
, our_caps
.u1
.dwCaps4
); /* FIXME: Better debugging */
832 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
834 surf
= head_surface
->complex_array
[i
];
837 TRACE("Surface %p, caps %#x, %#x, %#x, %#x.\n", surf
,
838 surf
->surface_desc
.ddsCaps
.dwCaps
,
839 surf
->surface_desc
.ddsCaps
.dwCaps2
,
840 surf
->surface_desc
.ddsCaps
.dwCaps3
,
841 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
843 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
844 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
846 /* MSDN: "This method fails if more than one surface is attached
847 * that matches the capabilities requested."
849 * Not sure how to test this.
852 TRACE("head_surface %p, returning surface %p.\n", head_surface
, surf
);
853 *surface
= &surf
->IDirectDrawSurface7_iface
;
854 ddraw_surface7_AddRef(*surface
);
855 wined3d_mutex_unlock();
861 /* Next, look at the attachment chain */
864 while( (surf
= surf
->next_attached
) )
866 TRACE("Surface %p, caps %#x, %#x, %#x, %#x.\n", surf
,
867 surf
->surface_desc
.ddsCaps
.dwCaps
,
868 surf
->surface_desc
.ddsCaps
.dwCaps2
,
869 surf
->surface_desc
.ddsCaps
.dwCaps3
,
870 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
872 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
873 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
875 TRACE("head_surface %p, returning surface %p.\n", head_surface
, surf
);
876 *surface
= &surf
->IDirectDrawSurface7_iface
;
877 ddraw_surface7_AddRef(*surface
);
878 wined3d_mutex_unlock();
883 TRACE("head_surface %p, didn't find a valid surface.\n", head_surface
);
885 wined3d_mutex_unlock();
888 return DDERR_NOTFOUND
;
891 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
892 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
895 struct ddraw_surface
*attachment_impl
;
896 IDirectDrawSurface7
*attachment7
;
899 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
901 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
908 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
909 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
910 ddraw_surface4_AddRef(*attachment
);
911 ddraw_surface7_Release(attachment7
);
916 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
917 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
919 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
920 struct ddraw_surface
*attachment_impl
;
921 IDirectDrawSurface7
*attachment7
;
925 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
927 caps2
.dwCaps
= caps
->dwCaps
;
930 caps2
.u1
.dwCaps4
= 0;
932 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
933 &caps2
, &attachment7
);
939 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
940 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
941 ddraw_surface3_AddRef(*attachment
);
942 ddraw_surface7_Release(attachment7
);
947 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
948 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
950 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
951 struct ddraw_surface
*attachment_impl
;
952 IDirectDrawSurface7
*attachment7
;
956 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
958 caps2
.dwCaps
= caps
->dwCaps
;
961 caps2
.u1
.dwCaps4
= 0;
963 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
964 &caps2
, &attachment7
);
970 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
971 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
972 ddraw_surface2_AddRef(*attachment
);
973 ddraw_surface7_Release(attachment7
);
978 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
979 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
981 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
982 struct ddraw_surface
*attachment_impl
;
983 IDirectDrawSurface7
*attachment7
;
987 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
989 caps2
.dwCaps
= caps
->dwCaps
;
992 caps2
.u1
.dwCaps4
= 0;
994 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
995 &caps2
, &attachment7
);
1001 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
1002 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
1003 ddraw_surface1_AddRef(*attachment
);
1004 ddraw_surface7_Release(attachment7
);
1009 /*****************************************************************************
1010 * IDirectDrawSurface7::Lock
1012 * Locks the surface and returns a pointer to the surface's memory
1015 * Rect: Rectangle to lock. If NULL, the whole surface is locked
1016 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
1017 * Flags: Locking flags, e.g Read only or write only
1018 * h: An event handle that's not used and must be NULL
1022 * DDERR_INVALIDPARAMS if DDSD is NULL
1024 *****************************************************************************/
1025 static HRESULT
surface_lock(struct ddraw_surface
*surface
,
1026 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, unsigned int surface_desc_size
,
1027 DWORD flags
, HANDLE h
)
1029 struct wined3d_map_desc map_desc
;
1030 unsigned int wined3d_flags
;
1031 struct wined3d_box box
;
1034 TRACE("surface %p, rect %s, surface_desc %p, surface_desc_size %u, flags %#x, h %p.\n",
1035 surface
, wine_dbgstr_rect(rect
), surface_desc
, surface_desc_size
, flags
, h
);
1037 /* surface->surface_desc.dwWidth and dwHeight are changeable, thus lock */
1038 wined3d_mutex_lock();
1040 /* Should I check for the handle to be NULL?
1042 * The DDLOCK flags and the D3DLOCK flags are equal
1043 * for the supported values. The others are ignored by WineD3D
1046 /* Windows zeroes this if the rect is invalid */
1047 surface_desc
->lpSurface
= NULL
;
1051 if ((rect
->left
< 0) || (rect
->top
< 0)
1052 || (rect
->left
> rect
->right
) || (rect
->right
> surface
->surface_desc
.dwWidth
)
1053 || (rect
->top
> rect
->bottom
) || (rect
->bottom
> surface
->surface_desc
.dwHeight
))
1055 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
1056 wined3d_mutex_unlock();
1057 return DDERR_INVALIDPARAMS
;
1059 wined3d_box_set(&box
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, 0, 1);
1062 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1063 hr
= ddraw_surface_update_frontbuffer(surface
, rect
, TRUE
, 0);
1066 wined3d_flags
= wined3dmapflags_from_ddrawmapflags(flags
);
1067 hr
= wined3d_resource_map(wined3d_texture_get_resource
1068 (ddraw_surface_get_default_texture(surface
, wined3d_flags
& WINED3D_MAP_WRITE
? DDRAW_SURFACE_RW
1069 : DDRAW_SURFACE_READ
)), surface
->sub_resource_idx
, &map_desc
, rect
? &box
: NULL
, wined3d_flags
);
1073 wined3d_mutex_unlock();
1076 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
1077 * specific error. But since wined3d returns that error in this only occasion,
1078 * keep d3d8 and d3d9 free from the return value override. There are many different
1079 * places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it is much easier
1080 * to do it in one place in ddraw.
1082 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1087 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1089 if (flags
& DDLOCK_READONLY
)
1090 SetRectEmpty(&surface
->ddraw
->primary_lock
);
1092 surface
->ddraw
->primary_lock
= *rect
;
1094 SetRect(&surface
->ddraw
->primary_lock
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
1097 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1098 DD_STRUCT_COPY_BYSIZE_(surface_desc
, &surface
->surface_desc
, surface_desc_size
, surface
->surface_desc
.dwSize
);
1099 surface_desc
->lpSurface
= map_desc
.data
;
1101 TRACE("locked surface returning description :\n");
1102 if (TRACE_ON(ddraw
))
1103 DDRAW_dump_surface_desc(surface_desc
);
1105 wined3d_mutex_unlock();
1110 static BOOL
surface_validate_lock_desc(struct ddraw_surface
*surface
,
1111 const DDSURFACEDESC
*desc
, unsigned int *size
)
1116 if (desc
->dwSize
== sizeof(DDSURFACEDESC
) || desc
->dwSize
== sizeof(DDSURFACEDESC2
))
1118 *size
= desc
->dwSize
;
1122 if (surface
->version
== 7
1123 && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
1124 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1126 if (desc
->dwSize
>= sizeof(DDSURFACEDESC2
))
1127 *size
= sizeof(DDSURFACEDESC2
);
1129 *size
= sizeof(DDSURFACEDESC
);
1133 WARN("Invalid structure size %u.\n", desc
->dwSize
);
1137 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1138 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1140 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1141 unsigned int surface_desc_size
;
1143 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1144 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1146 if (!surface_validate_lock_desc(surface
, (DDSURFACEDESC
*)surface_desc
, &surface_desc_size
))
1147 return DDERR_INVALIDPARAMS
;
1149 if (ddraw_surface_is_lost(surface
))
1151 WARN("Surface is lost.\n");
1152 return DDERR_SURFACELOST
;
1155 return surface_lock(surface
, rect
, surface_desc
, surface_desc_size
, flags
, h
);
1158 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1159 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1161 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1162 unsigned int surface_desc_size
;
1164 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1165 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1167 if (!surface_validate_lock_desc(surface
, (DDSURFACEDESC
*)surface_desc
, &surface_desc_size
))
1168 return DDERR_INVALIDPARAMS
;
1170 if (ddraw_surface_is_lost(surface
))
1172 WARN("Surface is lost.\n");
1173 return DDERR_SURFACELOST
;
1176 return surface_lock(surface
, rect
, surface_desc
, surface_desc_size
, flags
, h
);
1179 static HRESULT
ddraw_surface_lock_ddsd(struct ddraw_surface
*surface
, RECT
*rect
,
1180 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1182 unsigned int surface_desc_size
;
1183 DDSURFACEDESC2 surface_desc2
;
1186 if (!surface_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1187 return DDERR_INVALIDPARAMS
;
1189 if (ddraw_surface_is_lost(surface
))
1191 WARN("Surface is lost.\n");
1192 return DDERR_SURFACELOST
;
1195 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1196 surface_desc2
.dwFlags
= 0;
1197 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1198 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1199 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1203 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1204 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1206 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1208 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1209 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1211 return ddraw_surface_lock_ddsd(surface
, rect
, surface_desc
, flags
, h
);
1214 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1215 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1217 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1219 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1220 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1222 return ddraw_surface_lock_ddsd(surface
, rect
, surface_desc
, flags
, h
);
1225 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1226 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1228 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1230 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1231 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1233 return ddraw_surface_lock_ddsd(surface
, rect
, surface_desc
, flags
, h
);
1236 /* FRAPS hooks IDirectDrawSurface::Unlock and expects the version 1 method to be called when the
1237 * game uses later interfaces. */
1238 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1240 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1243 TRACE("iface %p, data %p.\n", iface
, data
);
1245 wined3d_mutex_lock();
1246 hr
= wined3d_resource_unmap(wined3d_texture_get_resource
1247 (ddraw_surface_get_default_texture(surface
, 0)), surface
->sub_resource_idx
);
1248 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1249 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
, 0);
1250 wined3d_mutex_unlock();
1255 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*rect
)
1257 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1259 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1261 return ddraw_surface1_Unlock(&surface
->IDirectDrawSurface_iface
, NULL
);
1264 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*rect
)
1266 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1268 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1270 return ddraw_surface1_Unlock(&surface
->IDirectDrawSurface_iface
, NULL
);
1273 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1275 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1277 TRACE("iface %p, data %p.\n", iface
, data
);
1279 return ddraw_surface1_Unlock(&surface
->IDirectDrawSurface_iface
, data
);
1282 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1284 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1286 TRACE("iface %p, data %p.\n", iface
, data
);
1288 return ddraw_surface1_Unlock(&surface
->IDirectDrawSurface_iface
, data
);
1291 static unsigned int ddraw_swap_interval_from_flags(DWORD flags
)
1293 if (flags
& DDFLIP_NOVSYNC
)
1296 switch (flags
& (DDFLIP_INTERVAL2
| DDFLIP_INTERVAL3
| DDFLIP_INTERVAL4
))
1298 case DDFLIP_INTERVAL2
:
1300 case DDFLIP_INTERVAL3
:
1302 case DDFLIP_INTERVAL4
:
1309 /* FRAPS hooks IDirectDrawSurface::Flip and expects the version 1 method to be called when the
1310 * game uses later interfaces. */
1311 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1312 IDirectDrawSurface
*src
, DWORD flags
)
1314 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
1315 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
1316 struct ddraw_texture
*dst_ddraw_texture
, *src_ddraw_texture
;
1317 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1318 DDSCAPS caps
= {DDSCAPS_FLIP
};
1319 struct wined3d_texture
*texture
, *draw_texture
;
1320 IDirectDrawSurface
*current
;
1321 void *texture_memory
;
1324 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1326 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1327 return DDERR_NOTFLIPPABLE
;
1329 if (ddraw_surface_is_lost(dst_impl
))
1330 return DDERR_SURFACELOST
;
1332 wined3d_mutex_lock();
1334 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1335 && !(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1337 WARN("Not in exclusive mode.\n");
1338 wined3d_mutex_unlock();
1339 return DDERR_NOEXCLUSIVEMODE
;
1342 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1343 if (dst_impl
->sub_resource_idx
)
1344 ERR("Invalid sub-resource index %u on surface %p.\n", dst_impl
->sub_resource_idx
, dst_impl
);
1345 texture
= dst_impl
->wined3d_texture
;
1346 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1347 dst_ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1348 texture_memory
= dst_ddraw_texture
->texture_memory
;
1349 draw_texture
= dst_impl
->draw_texture
;
1353 for (current
= iface
; current
!= src
;)
1355 if (FAILED(hr
= ddraw_surface1_GetAttachedSurface(current
, &caps
, ¤t
)))
1357 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1358 wined3d_mutex_unlock();
1359 return DDERR_NOTFLIPPABLE
;
1361 ddraw_surface1_Release(current
);
1362 if (current
== iface
)
1364 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1365 wined3d_mutex_unlock();
1366 return DDERR_NOTFLIPPABLE
;
1370 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1371 if (rtv
== dst_impl
->wined3d_rtv
)
1372 wined3d_device_context_set_rendertarget_view(dst_impl
->ddraw
->immediate_context
, 0, src_rtv
, FALSE
);
1373 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1374 dst_impl
->wined3d_rtv
= src_rtv
;
1375 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1376 if (src_impl
->draw_texture
)
1377 wined3d_texture_set_sub_resource_parent(src_impl
->draw_texture
, 0, dst_impl
);
1378 src_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1379 dst_ddraw_texture
->texture_memory
= src_ddraw_texture
->texture_memory
;
1380 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), dst_ddraw_texture
);
1381 if (src_impl
->draw_texture
)
1382 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->draw_texture
), dst_ddraw_texture
);
1383 dst_ddraw_texture
= src_ddraw_texture
;
1384 if (src_impl
->sub_resource_idx
)
1385 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1386 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1387 dst_impl
->draw_texture
= src_impl
->draw_texture
;
1391 for (current
= iface
;;)
1393 if (FAILED(hr
= ddraw_surface1_GetAttachedSurface(current
, &caps
, ¤t
)))
1395 ERR("Can't find a flip target\n");
1396 wined3d_mutex_unlock();
1397 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1399 ddraw_surface1_Release(current
);
1400 if (current
== iface
)
1402 dst_impl
= impl_from_IDirectDrawSurface(iface
);
1406 src_impl
= impl_from_IDirectDrawSurface(current
);
1407 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1408 if (rtv
== dst_impl
->wined3d_rtv
)
1409 wined3d_device_context_set_rendertarget_view(dst_impl
->ddraw
->immediate_context
, 0, src_rtv
, FALSE
);
1410 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1411 dst_impl
->wined3d_rtv
= src_rtv
;
1412 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1413 if (src_impl
->draw_texture
)
1414 wined3d_texture_set_sub_resource_parent(src_impl
->draw_texture
, 0, dst_impl
);
1415 src_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1416 dst_ddraw_texture
->texture_memory
= src_ddraw_texture
->texture_memory
;
1417 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), dst_ddraw_texture
);
1418 if (src_impl
->draw_texture
)
1419 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->draw_texture
), dst_ddraw_texture
);
1420 dst_ddraw_texture
= src_ddraw_texture
;
1421 if (src_impl
->sub_resource_idx
)
1422 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1423 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1424 dst_impl
->draw_texture
= src_impl
->draw_texture
;
1425 dst_impl
= src_impl
;
1429 /* We don't have to worry about potential texture bindings, since
1430 * flippable surfaces can never be textures. */
1431 if (rtv
== src_impl
->wined3d_rtv
)
1432 wined3d_device_context_set_rendertarget_view(dst_impl
->ddraw
->immediate_context
, 0, tmp_rtv
, FALSE
);
1433 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1434 src_impl
->wined3d_rtv
= tmp_rtv
;
1435 wined3d_texture_set_sub_resource_parent(texture
, 0, src_impl
);
1437 wined3d_texture_set_sub_resource_parent(draw_texture
, 0, src_impl
);
1438 dst_ddraw_texture
->texture_memory
= texture_memory
;
1439 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), dst_ddraw_texture
);
1441 wined3d_resource_set_parent(wined3d_texture_get_resource(draw_texture
), dst_ddraw_texture
);
1442 src_impl
->wined3d_texture
= texture
;
1443 src_impl
->draw_texture
= draw_texture
;
1445 if (flags
& ~(DDFLIP_NOVSYNC
| DDFLIP_INTERVAL2
| DDFLIP_INTERVAL3
| DDFLIP_INTERVAL4
))
1449 FIXME("Ignoring flags %#x.\n", flags
);
1451 WARN("Ignoring flags %#x.\n", flags
);
1454 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1455 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
, ddraw_swap_interval_from_flags(flags
));
1459 wined3d_mutex_unlock();
1464 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1465 IDirectDrawSurface7
*src
, DWORD flags
)
1467 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1468 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1470 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1472 return ddraw_surface1_Flip(&surface
->IDirectDrawSurface_iface
,
1473 src_impl
? &src_impl
->IDirectDrawSurface_iface
: NULL
, flags
);
1476 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1477 IDirectDrawSurface4
*src
, DWORD flags
)
1479 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1480 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
1482 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1484 return ddraw_surface1_Flip(&surface
->IDirectDrawSurface_iface
,
1485 src_impl
? &src_impl
->IDirectDrawSurface_iface
: NULL
, flags
);
1488 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1489 IDirectDrawSurface3
*src
, DWORD flags
)
1491 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1492 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src
);
1494 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1496 return ddraw_surface1_Flip(&surface
->IDirectDrawSurface_iface
,
1497 src_impl
? &src_impl
->IDirectDrawSurface_iface
: NULL
, flags
);
1500 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1501 IDirectDrawSurface2
*src
, DWORD flags
)
1503 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1504 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src
);
1506 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1508 return ddraw_surface1_Flip(&surface
->IDirectDrawSurface_iface
,
1509 src_impl
? &src_impl
->IDirectDrawSurface_iface
: NULL
, flags
);
1512 static HRESULT
ddraw_surface_blt(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect
,
1513 struct ddraw_surface
*src_surface
, const RECT
*src_rect
, DWORD flags
, DWORD fill_colour
,
1514 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1516 struct wined3d_device
*wined3d_device
= dst_surface
->ddraw
->wined3d_device
;
1517 struct wined3d_color colour
;
1518 DWORD wined3d_flags
;
1520 if (flags
& DDBLT_COLORFILL
)
1522 wined3d_flags
= WINED3DCLEAR_TARGET
;
1523 if (!(flags
& DDBLT_ASYNC
))
1524 wined3d_flags
|= WINED3DCLEAR_SYNCHRONOUS
;
1526 if (!wined3d_colour_from_ddraw_colour(&dst_surface
->surface_desc
.u4
.ddpfPixelFormat
,
1527 dst_surface
->palette
, fill_colour
, &colour
))
1528 return DDERR_INVALIDPARAMS
;
1530 wined3d_device_apply_stateblock(wined3d_device
, dst_surface
->ddraw
->state
);
1531 ddraw_surface_get_draw_texture(dst_surface
, dst_rect
? DDRAW_SURFACE_RW
: DDRAW_SURFACE_WRITE
);
1532 return wined3d_device_clear_rendertarget_view(wined3d_device
,
1533 ddraw_surface_get_rendertarget_view(dst_surface
),
1534 dst_rect
, wined3d_flags
, &colour
, 0.0f
, 0);
1537 if (flags
& DDBLT_DEPTHFILL
)
1539 wined3d_flags
= WINED3DCLEAR_ZBUFFER
;
1540 if (!(flags
& DDBLT_ASYNC
))
1541 wined3d_flags
|= WINED3DCLEAR_SYNCHRONOUS
;
1543 if (!wined3d_colour_from_ddraw_colour(&dst_surface
->surface_desc
.u4
.ddpfPixelFormat
,
1544 dst_surface
->palette
, fill_colour
, &colour
))
1545 return DDERR_INVALIDPARAMS
;
1547 wined3d_device_apply_stateblock(wined3d_device
, dst_surface
->ddraw
->state
);
1548 ddraw_surface_get_draw_texture(dst_surface
, dst_rect
? DDRAW_SURFACE_RW
: DDRAW_SURFACE_WRITE
);
1549 return wined3d_device_clear_rendertarget_view(wined3d_device
,
1550 ddraw_surface_get_rendertarget_view(dst_surface
),
1551 dst_rect
, wined3d_flags
, NULL
, colour
.r
, 0);
1554 wined3d_flags
= flags
& ~DDBLT_ASYNC
;
1555 if (wined3d_flags
& ~WINED3D_BLT_MASK
)
1557 FIXME("Unhandled flags %#x.\n", flags
);
1561 if (!(flags
& DDBLT_ASYNC
))
1562 wined3d_flags
|= WINED3D_BLT_SYNCHRONOUS
;
1564 return wined3d_texture_blt(ddraw_surface_get_any_texture(dst_surface
, DDRAW_SURFACE_RW
),
1565 dst_surface
->sub_resource_idx
, dst_rect
, ddraw_surface_get_any_texture(src_surface
, DDRAW_SURFACE_READ
),
1566 src_surface
->sub_resource_idx
, src_rect
, wined3d_flags
, fx
, filter
);
1569 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1570 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
, DWORD fill_colour
,
1571 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1573 RECT src_rect
, dst_rect
;
1574 float scale_x
, scale_y
;
1575 const RECT
*clip_rect
;
1576 UINT clip_list_size
;
1582 SetRect(&dst_rect
, 0, 0, dst_surface
->surface_desc
.dwWidth
,
1583 dst_surface
->surface_desc
.dwHeight
);
1585 dst_rect
= *dst_rect_in
;
1587 if (IsRectEmpty(&dst_rect
))
1588 return DDERR_INVALIDRECT
;
1593 SetRect(&src_rect
, 0, 0, src_surface
->surface_desc
.dwWidth
,
1594 src_surface
->surface_desc
.dwHeight
);
1596 src_rect
= *src_rect_in
;
1598 if (IsRectEmpty(&src_rect
))
1599 return DDERR_INVALIDRECT
;
1603 SetRectEmpty(&src_rect
);
1606 if (!dst_surface
->clipper
)
1608 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1609 hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect
, TRUE
, 0);
1611 hr
= ddraw_surface_blt(dst_surface
, &dst_rect
, src_surface
, &src_rect
, flags
, fill_colour
, fx
, filter
);
1612 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1613 hr
= ddraw_surface_update_frontbuffer(dst_surface
, &dst_rect
, FALSE
, 0);
1618 if (!ddraw_clipper_is_valid(dst_surface
->clipper
))
1620 FIXME("Attempting to blit with an invalid clipper.\n");
1621 return DDERR_INVALIDPARAMS
;
1624 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1625 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1627 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1628 &dst_rect
, NULL
, &clip_list_size
)))
1630 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1634 if (!(clip_list
= heap_alloc(clip_list_size
)))
1636 WARN("Failed to allocate clip list.\n");
1637 return E_OUTOFMEMORY
;
1640 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1641 &dst_rect
, clip_list
, &clip_list_size
)))
1643 WARN("Failed to get clip list, hr %#x.\n", hr
);
1644 heap_free(clip_list
);
1648 clip_rect
= (RECT
*)clip_list
->Buffer
;
1649 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1651 RECT src_rect_clipped
= src_rect
;
1655 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1656 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1657 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1658 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1660 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1662 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
, 0)))
1667 if (FAILED(hr
= ddraw_surface_blt(dst_surface
, &clip_rect
[i
],
1668 src_surface
, &src_rect_clipped
, flags
, fill_colour
, fx
, filter
)))
1671 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1673 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
, 0)))
1678 heap_free(clip_list
);
1682 /* FRAPS hooks IDirectDrawSurface::Blt and expects the version 1 method to be called when the
1683 * game uses later interfaces. */
1684 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1685 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1687 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
1688 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1689 struct wined3d_blt_fx wined3d_fx
= {0};
1690 DWORD unsupported_flags
;
1691 DWORD fill_colour
= 0;
1695 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1696 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1698 unsupported_flags
= DDBLT_ALPHADEST
1699 | DDBLT_ALPHADESTCONSTOVERRIDE
1700 | DDBLT_ALPHADESTNEG
1701 | DDBLT_ALPHADESTSURFACEOVERRIDE
1702 | DDBLT_ALPHAEDGEBLEND
1704 | DDBLT_ALPHASRCCONSTOVERRIDE
1706 | DDBLT_ALPHASRCSURFACEOVERRIDE
1708 | DDBLT_ZBUFFERDESTCONSTOVERRIDE
1709 | DDBLT_ZBUFFERDESTOVERRIDE
1710 | DDBLT_ZBUFFERSRCCONSTOVERRIDE
1711 | DDBLT_ZBUFFERSRCOVERRIDE
;
1712 if (flags
& unsupported_flags
)
1714 WARN("Ignoring unsupported flags %#x.\n", flags
& unsupported_flags
);
1715 flags
&= ~unsupported_flags
;
1718 if ((flags
& DDBLT_KEYSRCOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYSRC
))
1720 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1721 return DDERR_INVALIDPARAMS
;
1724 if ((flags
& DDBLT_KEYDESTOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYDEST
))
1726 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1727 return DDERR_INVALIDPARAMS
;
1730 if (flags
& DDBLT_DDROPS
)
1732 FIXME("DDBLT_DDROPS not implemented.\n");
1734 FIXME(" rop %#x, pattern %p.\n", fx
->dwDDROP
, fx
->u5
.lpDDSPattern
);
1735 return DDERR_NORASTEROPHW
;
1738 wined3d_mutex_lock();
1740 if (flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1742 if (flags
& DDBLT_ROP
)
1744 wined3d_mutex_unlock();
1745 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1746 return DDERR_INVALIDPARAMS
;
1750 wined3d_mutex_unlock();
1751 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1752 return DDERR_INVALIDPARAMS
;
1756 wined3d_mutex_unlock();
1757 WARN("Depth or colorfill used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1758 return DDERR_INVALIDPARAMS
;
1761 if ((flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1762 flags
&= ~DDBLT_DEPTHFILL
;
1764 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_COLORFILL
))
1766 wined3d_mutex_unlock();
1767 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1768 return DDERR_INVALIDPARAMS
;
1770 if (!(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_DEPTHFILL
))
1772 wined3d_mutex_unlock();
1773 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1774 return DDERR_INVALIDPARAMS
;
1778 if (flags
& DDBLT_ROP
)
1782 wined3d_mutex_unlock();
1783 WARN("DDBLT_ROP used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1784 return DDERR_INVALIDPARAMS
;
1787 if (src_impl
&& src_rect
1788 && ((ULONG
)src_rect
->left
>= src_rect
->right
|| src_rect
->right
> src_impl
->surface_desc
.dwWidth
1789 || (ULONG
)src_rect
->top
>= src_rect
->bottom
|| src_rect
->bottom
> src_impl
->surface_desc
.dwHeight
))
1791 wined3d_mutex_unlock();
1792 WARN("Invalid source rectangle.\n");
1793 return DDERR_INVALIDRECT
;
1796 flags
&= ~DDBLT_ROP
;
1806 if (fx
->dwROP
== WHITENESS
)
1807 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1809 rop_fx
.u5
.dwFillColor
= 0;
1811 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1812 flags
|= DDBLT_DEPTHFILL
;
1814 flags
|= DDBLT_COLORFILL
;
1820 wined3d_mutex_unlock();
1821 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", fx
->dwROP
);
1822 return DDERR_NORASTEROPHW
;
1826 if (!(flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) && !src_impl
)
1828 WARN("No source surface.\n");
1829 wined3d_mutex_unlock();
1830 return DDERR_INVALIDPARAMS
;
1833 if (flags
& DDBLT_KEYSRC
&& (!src_impl
|| !(src_impl
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1835 WARN("DDBLT_KEYSRC blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1836 wined3d_mutex_unlock();
1837 return DDERR_INVALIDPARAMS
;
1839 if (flags
& DDBLT_KEYDEST
&& !(dst_impl
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1841 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1842 wined3d_mutex_unlock();
1843 return DDERR_INVALIDPARAMS
;
1848 wined3d_fx
.fx
= fx
->dwDDFX
;
1849 fill_colour
= fx
->u5
.dwFillColor
;
1850 wined3d_fx
.dst_color_key
.color_space_low_value
= fx
->ddckDestColorkey
.dwColorSpaceLowValue
;
1851 wined3d_fx
.dst_color_key
.color_space_high_value
= fx
->ddckDestColorkey
.dwColorSpaceHighValue
;
1852 wined3d_fx
.src_color_key
.color_space_low_value
= fx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
1853 wined3d_fx
.src_color_key
.color_space_high_value
= fx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
1856 hr
= ddraw_surface_blt_clipped(dst_impl
, dst_rect
, src_impl
,
1857 src_rect
, flags
, fill_colour
, fx
? &wined3d_fx
: NULL
, WINED3D_TEXF_LINEAR
);
1859 wined3d_mutex_unlock();
1862 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1867 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*dst_rect
,
1868 IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1870 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface7(iface
);
1871 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
1873 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1874 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1876 return ddraw_surface1_Blt(&dst
->IDirectDrawSurface_iface
, dst_rect
,
1877 src
? &src
->IDirectDrawSurface_iface
: NULL
, src_rect
, flags
, fx
);
1880 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1881 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1883 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1884 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1886 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1887 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1889 return ddraw_surface1_Blt(&dst
->IDirectDrawSurface_iface
, dst_rect
,
1890 src
? &src
->IDirectDrawSurface_iface
: NULL
, src_rect
, flags
, fx
);
1893 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1894 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1896 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1897 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1899 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1900 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1902 return ddraw_surface1_Blt(&dst
->IDirectDrawSurface_iface
, dst_rect
,
1903 src
? &src
->IDirectDrawSurface_iface
: NULL
, src_rect
, flags
, fx
);
1906 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1907 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1909 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1910 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1912 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1913 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1915 return ddraw_surface1_Blt(&dst
->IDirectDrawSurface_iface
, dst_rect
,
1916 src
? &src
->IDirectDrawSurface_iface
: NULL
, src_rect
, flags
, fx
);
1919 /*****************************************************************************
1920 * IDirectDrawSurface7::AddAttachedSurface
1922 * Attaches a surface to another surface. How the surface attachments work
1923 * is not totally understood yet, and this method is prone to problems.
1924 * The surface that is attached is AddRef-ed.
1926 * Tests with complex surfaces suggest that the surface attachments form a
1927 * tree, but no method to test this has been found yet.
1929 * The attachment list consists of a first surface (first_attached) and
1930 * for each surface a pointer to the next attached surface (next_attached).
1931 * For the first surface, and a surface that has no attachments
1932 * first_attached points to the surface itself. A surface that has
1933 * no successors in the chain has next_attached set to NULL.
1935 * Newly attached surfaces are attached right after the root surface.
1936 * If a surface is attached to a complex surface compound, it's attached to
1937 * the surface that the app requested, not the complex root. See
1938 * GetAttachedSurface for a description how surfaces are found.
1940 * This is how the current implementation works, and it was coded by looking
1941 * at the needs of the applications.
1943 * So far only Z-Buffer attachments are tested, and they are activated in
1944 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1945 * Back buffers should work in 2D mode, but they are not tested(They can be
1946 * attached in older iface versions). Rendering to the front buffer and
1947 * switching between that and double buffering is not yet implemented in
1948 * WineD3D, so for 3D it might have unexpected results.
1950 * ddraw_surface_attach_surface is the real thing,
1951 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1952 * performs additional checks. Version 7 of this interface is much more restrictive
1953 * than its predecessors.
1956 * Attach: Surface to attach to iface
1960 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1962 *****************************************************************************/
1963 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1965 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1968 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1970 wined3d_mutex_lock();
1972 /* Check if the surface is already attached somewhere */
1973 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1975 /* TODO: Test for the structure of the manual attachment. Is it a
1976 * chain or a list? What happens if one surface is attached to 2
1977 * different surfaces? */
1978 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1979 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1981 wined3d_mutex_unlock();
1982 return DDERR_SURFACEALREADYATTACHED
;
1985 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1986 Surf
->next_attached
= This
->next_attached
;
1987 Surf
->first_attached
= This
->first_attached
;
1988 This
->next_attached
= Surf
;
1990 /* Check if the WineD3D depth stencil needs updating */
1991 if (This
->ddraw
->d3ddevice
)
1992 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1994 wined3d_mutex_unlock();
1999 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
2001 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
2002 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2005 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
2007 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
2008 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
2011 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
2012 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
2013 return DDERR_CANNOTATTACHSURFACE
;
2016 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
2021 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
2022 IUnknown_AddRef(attachment_impl
->attached_iface
);
2026 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
2028 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2029 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2032 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
2034 /* Tests suggest that
2035 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
2036 * -> offscreen plain surfaces can be attached to primaries
2037 * -> primaries can be attached to offscreen plain surfaces
2038 * -> z buffers can be attached to primaries */
2039 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
2040 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
2042 /* Sizes have to match */
2043 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
2044 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
2046 WARN("Surface sizes do not match.\n");
2047 return DDERR_CANNOTATTACHSURFACE
;
2050 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
2051 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
2053 WARN("Invalid attachment combination.\n");
2054 return DDERR_CANNOTATTACHSURFACE
;
2057 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
2060 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
2061 IUnknown_AddRef(attachment_impl
->attached_iface
);
2065 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
2067 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2068 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2071 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
2073 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
2074 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
2077 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
2078 IUnknown_AddRef(attachment_impl
->attached_iface
);
2079 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
2083 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
2085 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2086 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2089 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
2091 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
2092 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
2095 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
2096 IUnknown_AddRef(attachment_impl
->attached_iface
);
2097 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
2101 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
2103 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2104 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2107 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
2109 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
2110 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
2113 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
2114 IUnknown_AddRef(attachment_impl
->attached_iface
);
2115 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
2119 /*****************************************************************************
2120 * IDirectDrawSurface7::DeleteAttachedSurface
2122 * Removes a surface from the attachment chain. The surface's refcount
2123 * is decreased by one after it has been removed
2126 * Flags: Some flags, not used by this implementation
2127 * Attach: Surface to detach
2131 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
2133 *****************************************************************************/
2134 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
2135 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
2137 struct ddraw_surface
*prev
= surface
;
2139 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
2141 wined3d_mutex_lock();
2142 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
2144 wined3d_mutex_unlock();
2145 return DDERR_CANNOTDETACHSURFACE
;
2148 if (attachment
->attached_iface
!= detach_iface
)
2150 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
2151 wined3d_mutex_unlock();
2152 return DDERR_SURFACENOTATTACHED
;
2155 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
2156 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2158 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2159 /* FIXME: we should probably also subtract from dwMipMapCount of this
2160 * and all parent surfaces */
2163 /* Find the predecessor of the detached surface */
2164 while (prev
->next_attached
!= attachment
)
2166 if (!(prev
= prev
->next_attached
))
2168 ERR("Failed to find predecessor of %p.\n", attachment
);
2169 wined3d_mutex_unlock();
2170 return DDERR_SURFACENOTATTACHED
;
2174 /* Unchain the surface */
2175 prev
->next_attached
= attachment
->next_attached
;
2176 attachment
->next_attached
= NULL
;
2177 attachment
->first_attached
= attachment
;
2179 /* Check if the wined3d depth stencil needs updating. Note that we don't
2180 * just call d3d_device_update_depth_stencil() here since it uses
2181 * QueryInterface(). Some applications, SCP - Containment Breach in
2182 * particular, modify the QueryInterface() pointer in the surface vtbl
2183 * but don't cleanup properly after the relevant dll is unloaded. */
2184 if (attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
2185 && wined3d_device_get_depth_stencil_view(surface
->ddraw
->wined3d_device
) == attachment
->wined3d_rtv
)
2186 wined3d_device_context_set_depth_stencil_view(surface
->ddraw
->immediate_context
, NULL
);
2187 wined3d_mutex_unlock();
2189 /* Set attached_iface to NULL before releasing it, the surface may go
2191 attachment
->attached_iface
= NULL
;
2192 IUnknown_Release(detach_iface
);
2197 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
2198 DWORD flags
, IDirectDrawSurface7
*attachment
)
2200 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2201 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2203 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2205 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2208 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2209 DWORD flags
, IDirectDrawSurface4
*attachment
)
2211 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2212 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2214 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2216 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2219 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2220 DWORD flags
, IDirectDrawSurface3
*attachment
)
2222 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2223 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2225 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2227 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2230 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2231 DWORD flags
, IDirectDrawSurface2
*attachment
)
2233 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2234 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2236 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2238 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2241 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2242 DWORD flags
, IDirectDrawSurface
*attachment
)
2244 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2245 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2247 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2249 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2252 /*****************************************************************************
2253 * IDirectDrawSurface7::AddOverlayDirtyRect
2255 * "This method is not currently implemented"
2263 *****************************************************************************/
2264 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2266 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2268 return DDERR_UNSUPPORTED
; /* unchecked */
2271 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2273 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2275 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2277 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2280 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2282 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2284 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2286 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2289 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2291 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2293 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2295 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2298 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2300 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2302 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2304 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2307 /*****************************************************************************
2308 * IDirectDrawSurface7::GetDC
2310 * Returns a GDI device context for the surface
2313 * hdc: Address of a HDC variable to store the dc to
2317 * DDERR_INVALIDPARAMS if hdc is NULL
2319 *****************************************************************************/
2320 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2322 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2325 TRACE("iface %p, dc %p.\n", iface
, dc
);
2328 return DDERR_INVALIDPARAMS
;
2330 wined3d_mutex_lock();
2332 hr
= DDERR_DCALREADYCREATED
;
2333 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2334 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
, 0);
2336 hr
= wined3d_texture_get_dc(ddraw_surface_get_default_texture(surface
, DDRAW_SURFACE_RW
), surface
->sub_resource_idx
, dc
);
2342 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2344 const struct ddraw_palette
*palette
;
2346 if (surface
->palette
)
2347 palette
= surface
->palette
;
2348 else if (surface
->ddraw
->primary
)
2349 palette
= surface
->ddraw
->primary
->palette
;
2354 wined3d_palette_apply_to_dc(palette
->wined3d_palette
, *dc
);
2358 wined3d_mutex_unlock();
2361 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2362 * does not touch *dc. */
2363 case WINED3DERR_INVALIDCALL
:
2365 return DDERR_CANTCREATEDC
;
2372 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2376 TRACE("iface %p, dc %p.\n", iface
, dc
);
2378 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2381 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2383 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2385 TRACE("iface %p, dc %p.\n", iface
, dc
);
2387 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2390 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2392 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2394 TRACE("iface %p, dc %p.\n", iface
, dc
);
2396 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2399 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2401 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2403 TRACE("iface %p, dc %p.\n", iface
, dc
);
2405 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2408 /*****************************************************************************
2409 * IDirectDrawSurface7::ReleaseDC
2411 * Releases the DC that was constructed with GetDC
2414 * hdc: HDC to release
2417 * DD_OK on success, error code otherwise.
2419 *****************************************************************************/
2420 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2422 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2425 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2427 wined3d_mutex_lock();
2432 else if (SUCCEEDED(hr
= wined3d_texture_release_dc(ddraw_surface_get_default_texture(surface
, 0),
2433 surface
->sub_resource_idx
, hdc
)))
2436 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2437 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
, 0);
2439 wined3d_mutex_unlock();
2445 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2447 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2449 TRACE("iface %p, dc %p.\n", iface
, dc
);
2451 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2454 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2456 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2458 TRACE("iface %p, dc %p.\n", iface
, dc
);
2460 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2463 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2465 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2467 TRACE("iface %p, dc %p.\n", iface
, dc
);
2469 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2472 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2474 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2476 TRACE("iface %p, dc %p.\n", iface
, dc
);
2478 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2481 /*****************************************************************************
2482 * IDirectDrawSurface7::GetCaps
2484 * Returns the surface's caps
2487 * Caps: Address to write the caps to
2491 * DDERR_INVALIDPARAMS if Caps is NULL
2493 *****************************************************************************/
2494 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2496 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2498 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2501 return DDERR_INVALIDPARAMS
;
2503 *Caps
= surface
->surface_desc
.ddsCaps
;
2508 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2510 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2512 TRACE("iface %p, caps %p.\n", iface
, caps
);
2514 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2517 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2519 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2523 TRACE("iface %p, caps %p.\n", iface
, caps
);
2525 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2526 if (FAILED(hr
)) return hr
;
2528 caps
->dwCaps
= caps2
.dwCaps
;
2532 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2534 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2538 TRACE("iface %p, caps %p.\n", iface
, caps
);
2540 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2541 if (FAILED(hr
)) return hr
;
2543 caps
->dwCaps
= caps2
.dwCaps
;
2547 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2549 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2553 TRACE("iface %p, caps %p.\n", iface
, caps
);
2555 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2556 if (FAILED(hr
)) return hr
;
2558 caps
->dwCaps
= caps2
.dwCaps
;
2562 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2564 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2565 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2567 struct wined3d_resource
*resource
;
2569 TRACE("iface %p, priority %u.\n", iface
, priority
);
2571 wined3d_mutex_lock();
2572 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2573 * calls on such surfaces segfault on Windows. */
2574 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2576 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2577 hr
= DDERR_INVALIDPARAMS
;
2581 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2582 wined3d_resource_set_priority(resource
, priority
);
2583 if (surface
->draw_texture
)
2584 wined3d_resource_set_priority(wined3d_texture_get_resource(surface
->draw_texture
), priority
);
2588 wined3d_mutex_unlock();
2593 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2595 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2596 const struct wined3d_resource
*resource
;
2597 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2600 TRACE("iface %p, priority %p.\n", iface
, priority
);
2602 wined3d_mutex_lock();
2603 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2605 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2606 hr
= DDERR_INVALIDOBJECT
;
2608 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2610 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2611 hr
= DDERR_INVALIDPARAMS
;
2615 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2616 *priority
= wined3d_resource_get_priority(resource
);
2619 wined3d_mutex_unlock();
2624 /*****************************************************************************
2625 * IDirectDrawSurface7::SetPrivateData
2627 * Stores some data in the surface that is intended for the application's
2631 * tag: GUID that identifies the data
2632 * Data: Pointer to the private data
2633 * Size: Size of the private data
2637 * D3D_OK on success, error code otherwise.
2639 *****************************************************************************/
2640 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2641 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2643 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2646 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2647 iface
, debugstr_guid(tag
), data
, size
, flags
);
2651 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2652 return DDERR_INVALIDPARAMS
;
2655 wined3d_mutex_lock();
2656 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2657 wined3d_mutex_unlock();
2658 return hr_ddraw_from_wined3d(hr
);
2661 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2662 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2664 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2666 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2667 iface
, debugstr_guid(tag
), data
, size
, flags
);
2669 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2672 /*****************************************************************************
2673 * IDirectDrawSurface7::GetPrivateData
2675 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2678 * tag: GUID of the data to return
2679 * Data: Address where to write the data to
2680 * Size: Size of the buffer at Data
2684 * DDERR_INVALIDPARAMS if Data is NULL
2686 *****************************************************************************/
2687 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2689 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2690 const struct wined3d_private_data
*stored_data
;
2693 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2694 iface
, debugstr_guid(tag
), data
, size
);
2696 wined3d_mutex_lock();
2697 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2700 hr
= DDERR_NOTFOUND
;
2705 hr
= DDERR_INVALIDPARAMS
;
2708 if (*size
< stored_data
->size
)
2710 *size
= stored_data
->size
;
2711 hr
= DDERR_MOREDATA
;
2716 hr
= DDERR_INVALIDPARAMS
;
2720 *size
= stored_data
->size
;
2721 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2725 wined3d_mutex_unlock();
2729 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2731 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2733 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2734 iface
, debugstr_guid(tag
), data
, size
);
2736 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2739 /*****************************************************************************
2740 * IDirectDrawSurface7::FreePrivateData
2742 * Frees private data stored in the surface
2745 * tag: Tag of the data to free
2748 * D3D_OK on success, error code otherwise.
2750 *****************************************************************************/
2751 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2753 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2754 struct wined3d_private_data
*entry
;
2756 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2758 wined3d_mutex_lock();
2759 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2762 wined3d_mutex_unlock();
2763 return DDERR_NOTFOUND
;
2766 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2767 wined3d_mutex_unlock();
2772 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2774 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2776 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2778 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2781 /*****************************************************************************
2782 * IDirectDrawSurface7::PageLock
2784 * Prevents a sysmem surface from being paged out
2787 * Flags: Not used, must be 0(unchecked)
2790 * DD_OK, because it's a stub
2792 *****************************************************************************/
2793 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2795 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2797 /* This is Windows memory management related - we don't need this */
2801 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2803 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2805 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2807 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2810 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2812 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2814 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2816 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2819 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2821 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2823 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2825 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2828 /*****************************************************************************
2829 * IDirectDrawSurface7::PageUnlock
2831 * Allows a sysmem surface to be paged out
2834 * Flags: Not used, must be 0(unchecked)
2837 * DD_OK, because it's a stub
2839 *****************************************************************************/
2840 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2842 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2847 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2849 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2851 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2853 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2856 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2858 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2860 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2862 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2865 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2867 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2869 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2871 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2874 /*****************************************************************************
2875 * IDirectDrawSurface7::BltBatch
2877 * An unimplemented function
2885 *****************************************************************************/
2886 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2888 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2890 /* MSDN: "not currently implemented" */
2891 return DDERR_UNSUPPORTED
;
2894 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2896 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2898 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2900 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2903 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2905 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2907 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2909 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2912 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2914 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2916 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2918 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2921 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2923 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2925 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2927 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2930 /*****************************************************************************
2931 * IDirectDrawSurface7::EnumAttachedSurfaces
2933 * Enumerates all surfaces attached to this surface
2936 * context: Pointer to pass unmodified to the callback
2937 * cb: Callback function to call for each surface
2941 * DDERR_INVALIDPARAMS if cb is NULL
2943 *****************************************************************************/
2944 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2945 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2947 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2948 struct ddraw_surface
*surf
;
2949 DDSURFACEDESC2 desc
;
2952 /* Attached surfaces aren't handled in WineD3D */
2953 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2956 return DDERR_INVALIDPARAMS
;
2958 wined3d_mutex_lock();
2960 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2962 surf
= surface
->complex_array
[i
];
2965 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2966 desc
= surf
->surface_desc
;
2967 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2968 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2970 wined3d_mutex_unlock();
2975 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2977 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2978 desc
= surf
->surface_desc
;
2979 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2980 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2982 wined3d_mutex_unlock();
2987 TRACE(" end of enumeration.\n");
2989 wined3d_mutex_unlock();
2994 struct callback_info2
2996 LPDDENUMSURFACESCALLBACK2 callback
;
3000 struct callback_info
3002 LPDDENUMSURFACESCALLBACK callback
;
3006 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
3008 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3009 const struct callback_info2
*info
= context
;
3011 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3012 ddraw_surface7_Release(surface
);
3014 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
3017 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
3019 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3020 const struct callback_info
*info
= context
;
3022 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3023 ddraw_surface7_Release(surface
);
3025 /* FIXME: Check surface_test.dwSize */
3026 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
3027 (DDSURFACEDESC
*)surface_desc
, info
->context
);
3030 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
3031 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3033 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3034 struct callback_info2 info
;
3036 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
3038 info
.callback
= callback
;
3039 info
.context
= context
;
3041 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
3042 &info
, EnumCallback2
);
3045 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
3046 void *context
, LPDDENUMSURFACESCALLBACK callback
)
3048 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3049 struct callback_info info
;
3051 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
3053 info
.callback
= callback
;
3054 info
.context
= context
;
3056 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
3057 &info
, EnumCallback
);
3060 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
3061 void *context
, LPDDENUMSURFACESCALLBACK callback
)
3063 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3064 struct callback_info info
;
3066 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
3068 info
.callback
= callback
;
3069 info
.context
= context
;
3071 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
3072 &info
, EnumCallback
);
3075 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
3076 void *context
, LPDDENUMSURFACESCALLBACK callback
)
3078 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3079 struct callback_info info
;
3081 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
3083 info
.callback
= callback
;
3084 info
.context
= context
;
3086 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
3087 &info
, EnumCallback
);
3090 /*****************************************************************************
3091 * IDirectDrawSurface7::EnumOverlayZOrders
3093 * "Enumerates the overlay surfaces on the specified destination"
3096 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
3097 * context: context to pass back to the callback
3098 * cb: callback function to call for each enumerated surface
3101 * DD_OK, because it's a stub
3103 *****************************************************************************/
3104 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
3105 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
3107 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
3112 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
3113 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3115 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3116 struct callback_info2 info
;
3118 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3120 info
.callback
= callback
;
3121 info
.context
= context
;
3123 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3124 flags
, &info
, EnumCallback2
);
3127 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
3128 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3130 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3131 struct callback_info info
;
3133 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3135 info
.callback
= callback
;
3136 info
.context
= context
;
3138 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3139 flags
, &info
, EnumCallback
);
3142 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
3143 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3145 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3146 struct callback_info info
;
3148 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3150 info
.callback
= callback
;
3151 info
.context
= context
;
3153 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3154 flags
, &info
, EnumCallback
);
3157 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
3158 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3160 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3161 struct callback_info info
;
3163 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3165 info
.callback
= callback
;
3166 info
.context
= context
;
3168 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3169 flags
, &info
, EnumCallback
);
3172 /*****************************************************************************
3173 * IDirectDrawSurface7::GetBltStatus
3175 * Returns the blitting status
3178 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
3180 *****************************************************************************/
3181 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3183 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3187 case WINEDDGBS_CANBLT
:
3188 case WINEDDGBS_ISBLTDONE
:
3192 return DDERR_INVALIDPARAMS
;
3196 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3198 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3200 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3202 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3205 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3207 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3209 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3211 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3214 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3216 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3218 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3220 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3223 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3225 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3227 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3229 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3232 /*****************************************************************************
3233 * IDirectDrawSurface7::GetColorKey
3235 * Returns the color key assigned to the surface
3239 * CKey: Address to store the key to
3243 * DDERR_INVALIDPARAMS if CKey is NULL
3245 *****************************************************************************/
3246 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3248 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3250 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3253 return DDERR_INVALIDPARAMS
;
3255 wined3d_mutex_lock();
3259 case DDCKEY_DESTBLT
:
3260 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3262 wined3d_mutex_unlock();
3263 return DDERR_NOCOLORKEY
;
3265 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3268 case DDCKEY_DESTOVERLAY
:
3269 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3271 wined3d_mutex_unlock();
3272 return DDERR_NOCOLORKEY
;
3274 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3278 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3280 wined3d_mutex_unlock();
3281 return DDERR_NOCOLORKEY
;
3283 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3286 case DDCKEY_SRCOVERLAY
:
3287 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3289 wined3d_mutex_unlock();
3290 return DDERR_NOCOLORKEY
;
3292 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3296 wined3d_mutex_unlock();
3297 return DDERR_INVALIDPARAMS
;
3300 wined3d_mutex_unlock();
3305 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3307 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3309 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3311 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3314 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3316 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3318 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3320 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3323 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3325 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3327 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3329 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3332 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3334 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3336 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3338 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3341 /*****************************************************************************
3342 * IDirectDrawSurface7::GetFlipStatus
3344 * Returns the flipping status of the surface
3347 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3349 *****************************************************************************/
3350 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3352 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3354 /* XXX: DDERR_INVALIDSURFACETYPE */
3358 case WINEDDGFS_CANFLIP
:
3359 case WINEDDGFS_ISFLIPDONE
:
3363 return DDERR_INVALIDPARAMS
;
3367 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3369 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3371 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3373 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3376 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3378 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3380 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3382 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3385 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3387 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3389 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3391 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3394 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3396 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3398 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3400 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3403 /*****************************************************************************
3404 * IDirectDrawSurface7::GetOverlayPosition
3406 * Returns the display coordinates of a visible and active overlay surface
3413 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3414 *****************************************************************************/
3415 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3417 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3420 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3422 wined3d_mutex_lock();
3423 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3424 surface
->sub_resource_idx
, x
, y
);
3425 wined3d_mutex_unlock();
3430 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3432 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3434 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3436 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3439 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3441 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3443 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3445 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3448 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3450 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3452 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3454 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3457 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3459 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3461 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3463 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3466 /*****************************************************************************
3467 * IDirectDrawSurface7::GetPixelFormat
3469 * Returns the pixel format of the Surface
3472 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3473 * format should be written
3477 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3479 *****************************************************************************/
3480 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3482 /* What is DDERR_INVALIDSURFACETYPE for here? */
3483 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3485 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3488 return DDERR_INVALIDPARAMS
;
3490 wined3d_mutex_lock();
3491 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3492 wined3d_mutex_unlock();
3497 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3499 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3501 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3503 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3506 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3508 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3510 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3512 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3515 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3517 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3519 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3521 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3524 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3526 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3528 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3530 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3533 /*****************************************************************************
3534 * IDirectDrawSurface7::GetSurfaceDesc
3536 * Returns the description of this surface
3539 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3544 * DDERR_INVALIDPARAMS if DDSD is NULL
3546 *****************************************************************************/
3547 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3549 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3551 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3554 return DDERR_INVALIDPARAMS
;
3556 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3558 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3559 return DDERR_INVALIDPARAMS
;
3562 wined3d_mutex_lock();
3563 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3564 TRACE("Returning surface desc:\n");
3565 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3566 wined3d_mutex_unlock();
3571 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3573 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3575 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3577 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3580 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3582 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3584 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3586 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3588 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3590 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3591 return DDERR_INVALIDPARAMS
;
3594 wined3d_mutex_lock();
3595 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3596 TRACE("Returning surface desc:\n");
3597 if (TRACE_ON(ddraw
))
3599 /* DDRAW_dump_surface_desc handles the smaller size */
3600 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3602 wined3d_mutex_unlock();
3607 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3609 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3611 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3613 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3616 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3618 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3620 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3622 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3625 /*****************************************************************************
3626 * IDirectDrawSurface7::Initialize
3628 * Initializes the surface. This is a no-op in Wine
3631 * DD: Pointer to an DirectDraw interface
3632 * DDSD: Surface description for initialization
3635 * DDERR_ALREADYINITIALIZED
3637 *****************************************************************************/
3638 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3639 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3641 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3643 return DDERR_ALREADYINITIALIZED
;
3646 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3647 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3649 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3651 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3653 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3654 ddraw
, surface_desc
);
3657 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3658 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3660 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3661 DDSURFACEDESC2 surface_desc2
;
3663 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3665 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3666 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3667 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3670 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3671 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3673 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3674 DDSURFACEDESC2 surface_desc2
;
3676 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3678 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3679 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3680 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3683 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3684 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3686 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3687 DDSURFACEDESC2 surface_desc2
;
3689 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3691 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3692 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3693 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3696 /*****************************************************************************
3697 * IDirect3DTexture1::Initialize
3699 * The sdk says it's not implemented
3707 *****************************************************************************/
3708 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3709 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3711 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3713 return DDERR_UNSUPPORTED
; /* Unchecked */
3716 /*****************************************************************************
3717 * IDirectDrawSurface7::IsLost
3719 * Checks if the surface is lost
3722 * DD_OK, if the surface is usable
3723 * DDERR_ISLOST if the surface is lost
3725 *****************************************************************************/
3726 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3728 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3730 TRACE("iface %p.\n", iface
);
3732 return ddraw_surface_is_lost(surface
) ? DDERR_SURFACELOST
: DD_OK
;
3735 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3737 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3739 TRACE("iface %p.\n", iface
);
3741 return ddraw_surface_is_lost(surface
) ? DDERR_SURFACELOST
: DD_OK
;
3744 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3746 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3748 TRACE("iface %p.\n", iface
);
3750 return ddraw_surface_is_lost(surface
) ? DDERR_SURFACELOST
: DD_OK
;
3753 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3755 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3757 TRACE("iface %p.\n", iface
);
3759 return ddraw_surface_is_lost(surface
) ? DDERR_SURFACELOST
: DD_OK
;
3762 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3764 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3766 TRACE("iface %p.\n", iface
);
3768 return ddraw_surface_is_lost(surface
) ? DDERR_SURFACELOST
: DD_OK
;
3771 /*****************************************************************************
3772 * IDirectDrawSurface7::Restore
3774 * Restores a lost surface. This makes the surface usable again, but
3775 * doesn't reload its old contents
3778 * DD_OK on success, error code otherwise.
3780 *****************************************************************************/
3781 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3783 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3786 TRACE("iface %p.\n", iface
);
3788 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3790 struct wined3d_swapchain
*swapchain
= surface
->ddraw
->wined3d_swapchain
;
3791 struct wined3d_sub_resource_desc wined3d_desc
;
3792 struct wined3d_display_mode mode
;
3795 if (FAILED(hr
= wined3d_swapchain_get_display_mode(swapchain
, &mode
, NULL
)))
3797 WARN("Failed to get display mode, hr %#x.\n", hr
);
3801 if (FAILED(hr
= wined3d_texture_get_sub_resource_desc(surface
->wined3d_texture
, 0, &wined3d_desc
)))
3803 WARN("Failed to get resource desc, hr %#x.\n", hr
);
3807 if (mode
.width
!= wined3d_desc
.width
|| mode
.height
!= wined3d_desc
.height
)
3809 WARN("Display mode dimensions %ux%u don't match surface dimensions %ux%u.\n",
3810 mode
.width
, mode
.height
, wined3d_desc
.width
, wined3d_desc
.height
);
3811 return DDERR_WRONGMODE
;
3814 if (mode
.format_id
!= wined3d_desc
.format
)
3816 WARN("Display mode format %#x doesn't match surface format %#x.\n",
3817 mode
.format_id
, wined3d_desc
.format
);
3818 return DDERR_WRONGMODE
;
3822 if (!ddraw_surface_can_be_lost(surface
))
3824 ddraw_update_lost_surfaces(surface
->ddraw
);
3825 if (surface
->ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
)
3826 return DDERR_WRONGMODE
;
3828 surface
->is_lost
= FALSE
;
3829 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
3831 if (surface
->complex_array
[i
])
3832 surface
->complex_array
[i
]->is_lost
= FALSE
;
3838 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3840 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3842 TRACE("iface %p.\n", iface
);
3844 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3847 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3849 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3851 TRACE("iface %p.\n", iface
);
3853 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3856 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3858 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3860 TRACE("iface %p.\n", iface
);
3862 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3865 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3867 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3869 TRACE("iface %p.\n", iface
);
3871 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3874 /*****************************************************************************
3875 * IDirectDrawSurface7::SetOverlayPosition
3877 * Changes the display coordinates of an overlay surface
3884 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3885 *****************************************************************************/
3886 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3888 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3891 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3893 wined3d_mutex_lock();
3894 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3895 surface
->sub_resource_idx
, x
, y
);
3896 wined3d_mutex_unlock();
3901 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3903 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3905 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3907 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3910 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3912 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3914 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3916 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3919 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3921 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3923 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3925 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3928 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3930 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3932 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3934 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3937 /*****************************************************************************
3938 * IDirectDrawSurface7::UpdateOverlay
3940 * Modifies the attributes of an overlay surface.
3943 * SrcRect: The section of the source being used for the overlay
3944 * DstSurface: Address of the surface that is overlaid
3945 * DstRect: Place of the overlay
3946 * Flags: some DDOVER_* flags
3949 * DDERR_UNSUPPORTED, because we don't support overlays
3951 *****************************************************************************/
3952 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3953 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3955 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3956 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3957 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3958 unsigned int dst_sub_resource_idx
= 0;
3961 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3962 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3965 FIXME("Ignoring fx %p.\n", fx
);
3967 wined3d_mutex_lock();
3970 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3971 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3973 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3974 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3975 wined3d_mutex_unlock();
3977 return hr_ddraw_from_wined3d(hr
);
3980 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3981 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3983 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3984 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3986 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3987 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3989 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3990 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3993 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3994 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3996 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3997 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3999 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
4000 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
4002 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
4003 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
4006 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
4007 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
4009 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
4010 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
4012 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
4013 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
4015 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
4016 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
4019 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
4020 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
4022 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
4023 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
4025 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
4026 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
4028 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
4029 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
4032 /*****************************************************************************
4033 * IDirectDrawSurface7::UpdateOverlayDisplay
4035 * The DX7 sdk says that it's not implemented
4040 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
4042 *****************************************************************************/
4043 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
4045 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
4047 return DDERR_UNSUPPORTED
;
4050 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
4052 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4054 TRACE("iface %p, flags %#x.\n", iface
, flags
);
4056 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
4059 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
4061 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4063 TRACE("iface %p, flags %#x.\n", iface
, flags
);
4065 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
4068 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
4070 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4072 TRACE("iface %p, flags %#x.\n", iface
, flags
);
4074 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
4077 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
4079 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4081 TRACE("iface %p, flags %#x.\n", iface
, flags
);
4083 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
4086 /*****************************************************************************
4087 * IDirectDrawSurface7::UpdateOverlayZOrder
4089 * Sets an overlay's Z order
4092 * Flags: DDOVERZ_* flags
4093 * DDSRef: Defines the relative position in the overlay chain
4096 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
4098 *****************************************************************************/
4099 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
4100 DWORD flags
, IDirectDrawSurface7
*reference
)
4102 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4104 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
4106 wined3d_mutex_lock();
4107 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
4109 WARN("Not an overlay surface.\n");
4110 wined3d_mutex_unlock();
4111 return DDERR_NOTAOVERLAYSURFACE
;
4113 wined3d_mutex_unlock();
4118 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
4119 DWORD flags
, IDirectDrawSurface4
*reference
)
4121 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4122 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
4124 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4126 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4127 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4130 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
4131 DWORD flags
, IDirectDrawSurface3
*reference
)
4133 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4134 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
4136 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4138 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4139 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4142 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
4143 DWORD flags
, IDirectDrawSurface2
*reference
)
4145 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4146 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
4148 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4150 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4151 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4154 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
4155 DWORD flags
, IDirectDrawSurface
*reference
)
4157 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4158 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
4160 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4162 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4163 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4166 /*****************************************************************************
4167 * IDirectDrawSurface7::GetDDInterface
4169 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
4170 * surface belongs to
4173 * DD: Address to write the interface pointer to
4177 * DDERR_INVALIDPARAMS if DD is NULL
4179 *****************************************************************************/
4180 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
4182 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4184 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
4187 return DDERR_INVALIDPARAMS
;
4189 switch(This
->version
)
4192 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
4196 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
4200 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
4204 *DD
= &This
->ddraw
->IDirectDraw_iface
;
4208 IUnknown_AddRef((IUnknown
*)*DD
);
4213 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
4215 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4217 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4219 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4222 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
4224 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4226 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4228 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4231 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4233 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4235 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4237 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4240 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4242 TRACE("iface %p.\n", iface
);
4247 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4249 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4251 TRACE("iface %p.\n", iface
);
4253 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4256 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4258 TRACE("iface %p, value %p.\n", iface
, pValue
);
4265 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4267 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4269 TRACE("iface %p, value %p.\n", iface
, pValue
);
4271 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4274 /*****************************************************************************
4275 * IDirectDrawSurface7::SetLOD
4277 * Sets the level of detail of a texture
4280 * MaxLOD: LOD to set
4284 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4286 *****************************************************************************/
4287 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4289 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4292 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4294 wined3d_mutex_lock();
4295 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4297 wined3d_mutex_unlock();
4298 return DDERR_INVALIDOBJECT
;
4301 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4302 if (SUCCEEDED(hr
) && surface
->draw_texture
)
4303 hr
= wined3d_texture_set_lod(surface
->draw_texture
, MaxLOD
);
4304 wined3d_mutex_unlock();
4309 /*****************************************************************************
4310 * IDirectDrawSurface7::GetLOD
4312 * Returns the level of detail of a Direct3D texture
4315 * MaxLOD: Address to write the LOD to
4319 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4320 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4322 *****************************************************************************/
4323 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4325 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4327 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4330 return DDERR_INVALIDPARAMS
;
4332 wined3d_mutex_lock();
4333 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4335 wined3d_mutex_unlock();
4336 return DDERR_INVALIDOBJECT
;
4339 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4340 wined3d_mutex_unlock();
4345 /*****************************************************************************
4346 * IDirectDrawSurface7::BltFast
4348 * Performs a fast Blit.
4351 * dstx: The x coordinate to blit to on the destination
4352 * dsty: The y coordinate to blit to on the destination
4353 * Source: The source surface
4354 * rsrc: The source rectangle
4355 * trans: Type of transfer. Some DDBLTFAST_* flags
4358 * DD_OK on success, error code otherwise.
4360 *****************************************************************************/
4361 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4362 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4364 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4365 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4366 DWORD flags
= WINED3D_BLT_SYNCHRONOUS
;
4367 DWORD src_w
, src_h
, dst_w
, dst_h
;
4371 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4372 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4374 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4375 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4379 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4383 src_w
= src_rect
->right
- src_rect
->left
;
4384 src_h
= src_rect
->bottom
- src_rect
->top
;
4385 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4386 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4388 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4389 return DDERR_INVALIDRECT
;
4392 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4393 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4394 flags
|= WINED3D_BLT_SRC_CKEY
;
4395 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4396 flags
|= WINED3D_BLT_DST_CKEY
;
4397 if (trans
& DDBLTFAST_WAIT
)
4398 flags
|= WINED3D_BLT_WAIT
;
4399 if (trans
& DDBLTFAST_DONOTWAIT
)
4400 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4402 wined3d_mutex_lock();
4403 if (dst_impl
->clipper
)
4405 wined3d_mutex_unlock();
4406 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4407 return DDERR_BLTFASTCANTCLIP
;
4410 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4411 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
, 0);
4413 hr
= wined3d_texture_blt(ddraw_surface_get_any_texture(dst_impl
, DDRAW_SURFACE_RW
),
4414 dst_impl
->sub_resource_idx
, &dst_rect
, ddraw_surface_get_any_texture(src_impl
,DDRAW_SURFACE_READ
),
4415 src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4416 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4417 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
, 0);
4418 wined3d_mutex_unlock();
4422 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4427 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4428 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4430 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4431 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4433 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4434 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4436 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4437 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4440 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4441 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4443 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4444 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4446 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4447 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4449 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4450 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4453 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4454 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4456 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4457 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4459 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4460 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4462 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4463 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4466 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4467 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4469 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4470 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4472 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4473 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4475 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4476 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4479 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**clipper
)
4481 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4483 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4486 return DDERR_INVALIDPARAMS
;
4488 wined3d_mutex_lock();
4489 if (!surface
->clipper
)
4491 wined3d_mutex_unlock();
4493 return DDERR_NOCLIPPERATTACHED
;
4496 *clipper
= &surface
->clipper
->IDirectDrawClipper_iface
;
4497 if (ddraw_clipper_is_valid(surface
->clipper
))
4498 IDirectDrawClipper_AddRef(*clipper
);
4499 wined3d_mutex_unlock();
4504 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4506 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4508 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4510 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4513 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4515 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4517 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4519 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4522 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4524 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4526 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4528 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4531 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4533 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4535 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4537 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4540 /*****************************************************************************
4541 * IDirectDrawSurface7::SetClipper
4543 * Sets a clipper for the surface
4546 * Clipper: IDirectDrawClipper interface of the clipper to set
4551 *****************************************************************************/
4552 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4553 IDirectDrawClipper
*iclipper
)
4555 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4556 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4557 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4560 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4562 wined3d_mutex_lock();
4563 if (clipper
== This
->clipper
)
4565 wined3d_mutex_unlock();
4569 This
->clipper
= clipper
;
4571 if (clipper
!= NULL
)
4572 IDirectDrawClipper_AddRef(iclipper
);
4573 if (old_clipper
&& ddraw_clipper_is_valid(old_clipper
))
4574 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4576 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4580 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4585 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4586 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4590 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4591 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4595 wined3d_mutex_unlock();
4600 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4602 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4604 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4606 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4609 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4611 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4613 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4615 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4618 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4620 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4622 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4624 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4627 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4629 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4631 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4633 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4636 /*****************************************************************************
4637 * IDirectDrawSurface7::SetSurfaceDesc
4639 * Sets the surface description. It can override the pixel format, the surface
4641 * It's not really tested.
4644 * DDSD: Pointer to the new surface description to set
4649 * DDERR_INVALIDPARAMS if DDSD is NULL
4651 *****************************************************************************/
4652 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4654 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4656 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4657 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4658 enum wined3d_format_id format_id
;
4659 UINT pitch
, width
, height
;
4661 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4665 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4666 return DDERR_INVALIDPARAMS
;
4670 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4671 return DDERR_INVALIDPARAMS
;
4673 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4674 || surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4675 || surface
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4677 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4678 return DDERR_INVALIDSURFACETYPE
;
4681 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4682 * for PIXELFORMAT to work */
4683 if (DDSD
->dwFlags
& ~allowed_flags
)
4685 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4686 return DDERR_INVALIDPARAMS
;
4688 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4690 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4691 return DDERR_INVALIDPARAMS
;
4693 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4695 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4696 return DDERR_INVALIDCAPS
;
4698 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4700 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4702 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4703 return DDERR_INVALIDPARAMS
;
4705 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4707 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4708 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4709 return DDERR_INVALIDPARAMS
;
4711 if (DDSD
->dwWidth
!= surface
->surface_desc
.dwWidth
)
4712 TRACE("Surface width changed from %u to %u.\n", surface
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4713 if (DDSD
->u1
.lPitch
!= surface
->surface_desc
.u1
.lPitch
)
4714 TRACE("Surface pitch changed from %u to %u.\n", surface
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4715 pitch
= DDSD
->u1
.lPitch
;
4716 width
= DDSD
->dwWidth
;
4718 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4720 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4721 return DDERR_INVALIDPARAMS
;
4725 pitch
= surface
->surface_desc
.u1
.lPitch
;
4726 width
= surface
->surface_desc
.dwWidth
;
4729 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4731 if (!DDSD
->dwHeight
)
4733 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4734 return DDERR_INVALIDPARAMS
;
4736 if (DDSD
->dwHeight
!= surface
->surface_desc
.dwHeight
)
4737 TRACE("Surface height changed from %u to %u.\n", surface
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4738 height
= DDSD
->dwHeight
;
4742 height
= surface
->surface_desc
.dwHeight
;
4745 wined3d_mutex_lock();
4746 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4748 enum wined3d_format_id current_format_id
;
4749 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4751 if (format_id
== WINED3DFMT_UNKNOWN
)
4753 ERR("Requested to set an unknown pixelformat\n");
4754 wined3d_mutex_unlock();
4755 return DDERR_INVALIDPARAMS
;
4757 current_format_id
= wined3dformat_from_ddrawformat(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
4758 if (format_id
!= current_format_id
)
4759 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4763 format_id
= wined3dformat_from_ddrawformat(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
4766 if (FAILED(hr
= wined3d_texture_update_desc(surface
->wined3d_texture
, surface
->sub_resource_idx
,
4767 width
, height
, format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4769 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4770 wined3d_mutex_unlock();
4771 return hr_ddraw_from_wined3d(hr
);
4774 if (surface
->draw_texture
&& FAILED(hr
= wined3d_texture_update_desc(surface
->draw_texture
,
4775 surface
->sub_resource_idx
, width
, height
, format_id
, WINED3D_MULTISAMPLE_NONE
, 0, NULL
, 0)))
4777 ERR("Failed to update surface desc for draw_texture, hr %#x.\n", hr
);
4778 wined3d_mutex_unlock();
4779 return hr_ddraw_from_wined3d(hr
);
4782 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4783 surface
->surface_desc
.dwWidth
= width
;
4784 if (DDSD
->dwFlags
& DDSD_PITCH
)
4785 surface
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4786 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4787 surface
->surface_desc
.dwHeight
= height
;
4788 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4789 surface
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4791 wined3d_mutex_unlock();
4796 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4797 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4799 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4801 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4803 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4804 surface_desc
, flags
);
4807 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4808 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4810 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4811 DDSURFACEDESC2 surface_desc2
;
4813 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4815 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4816 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4817 surface_desc
? &surface_desc2
: NULL
, flags
);
4820 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4822 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4823 struct ddraw_palette
*palette_impl
;
4826 TRACE("iface %p, palette %p.\n", iface
, palette
);
4829 return DDERR_INVALIDPARAMS
;
4830 if (ddraw_surface_is_lost(surface
))
4832 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4833 return DDERR_SURFACELOST
;
4836 wined3d_mutex_lock();
4837 if ((palette_impl
= surface
->palette
))
4839 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4840 IDirectDrawPalette_AddRef(*palette
);
4845 hr
= DDERR_NOPALETTEATTACHED
;
4847 wined3d_mutex_unlock();
4852 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4854 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4856 TRACE("iface %p, palette %p.\n", iface
, palette
);
4858 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4861 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4863 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4865 TRACE("iface %p, palette %p.\n", iface
, palette
);
4867 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4870 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4872 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4874 TRACE("iface %p, palette %p.\n", iface
, palette
);
4876 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4879 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4881 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4883 TRACE("iface %p, palette %p.\n", iface
, palette
);
4885 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4888 static HRESULT
ddraw_surface_set_wined3d_textures_colour_key(struct ddraw_surface
*surface
, DWORD flags
,
4889 struct wined3d_color_key
*color_key
)
4893 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
, color_key
);
4894 if (surface
->draw_texture
&& SUCCEEDED(hr
))
4895 hr
= wined3d_texture_set_color_key(surface
->draw_texture
, flags
, color_key
);
4900 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4902 DDCOLORKEY fixed_color_key
;
4903 HRESULT hr
= WINED3D_OK
;
4905 if (flags
& DDCKEY_COLORSPACE
)
4907 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4909 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4910 return DDERR_NOCOLORKEYHW
;
4912 flags
&= ~DDCKEY_COLORSPACE
;
4915 wined3d_mutex_lock();
4919 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4920 switch (flags
& ~DDCKEY_COLORSPACE
)
4922 case DDCKEY_DESTBLT
:
4923 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4924 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4927 case DDCKEY_DESTOVERLAY
:
4928 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4929 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4932 case DDCKEY_SRCOVERLAY
:
4933 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4934 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4938 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4939 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4943 wined3d_mutex_unlock();
4944 return DDERR_INVALIDPARAMS
;
4949 switch (flags
& ~DDCKEY_COLORSPACE
)
4951 case DDCKEY_DESTBLT
:
4952 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4955 case DDCKEY_DESTOVERLAY
:
4956 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4959 case DDCKEY_SRCOVERLAY
:
4960 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4964 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4968 wined3d_mutex_unlock();
4969 return DDERR_INVALIDPARAMS
;
4973 if (surface
->is_complex_root
)
4974 hr
= ddraw_surface_set_wined3d_textures_colour_key(surface
, flags
,
4975 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4977 wined3d_mutex_unlock();
4979 return hr_ddraw_from_wined3d(hr
);
4982 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4984 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4986 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4988 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4989 return DDERR_NOTONMIPMAPSUBLEVEL
;
4991 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4994 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4996 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4998 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
5000 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
5003 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
5005 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
5007 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
5009 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
5012 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
5014 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
5016 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
5018 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
5021 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
5023 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
5025 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
5027 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
5030 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
5032 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
5034 TRACE("iface %p, palette %p.\n", iface
, palette
);
5036 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
5037 return DDERR_NOTONMIPMAPSUBLEVEL
;
5038 if (ddraw_surface_is_lost(surface
))
5040 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
5041 return DDERR_SURFACELOST
;
5044 return ddraw_surface_set_palette(surface
, palette
);
5047 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
5049 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
5051 TRACE("iface %p, palette %p.\n", iface
, palette
);
5053 if (ddraw_surface_is_lost(surface
))
5055 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
5056 return DDERR_SURFACELOST
;
5059 return ddraw_surface_set_palette(surface
, palette
);
5062 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
5064 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
5066 TRACE("iface %p, palette %p.\n", iface
, palette
);
5068 if (ddraw_surface_is_lost(surface
))
5070 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
5071 return DDERR_SURFACELOST
;
5074 return ddraw_surface_set_palette(surface
, palette
);
5077 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
5079 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
5081 TRACE("iface %p, palette %p.\n", iface
, palette
);
5083 if (ddraw_surface_is_lost(surface
))
5085 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
5086 return DDERR_SURFACELOST
;
5089 return ddraw_surface_set_palette(surface
, palette
);
5092 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
5094 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
5096 TRACE("iface %p, palette %p.\n", iface
, palette
);
5098 if (ddraw_surface_is_lost(surface
))
5100 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
5101 return DDERR_SURFACELOST
;
5104 return ddraw_surface_set_palette(surface
, palette
);
5107 /**********************************************************
5108 * IDirectDrawGammaControl::GetGammaRamp
5110 * Returns the current gamma ramp for a surface
5114 * gamma_ramp: Address to write the ramp to
5118 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
5120 **********************************************************/
5121 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
5122 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
5124 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
5126 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
5130 WARN("Invalid gamma_ramp passed.\n");
5131 return DDERR_INVALIDPARAMS
;
5134 wined3d_mutex_lock();
5135 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5137 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
5138 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
5142 ERR("Not implemented for non-primary surfaces.\n");
5144 wined3d_mutex_unlock();
5149 /**********************************************************
5150 * IDirectDrawGammaControl::SetGammaRamp
5152 * Sets the red, green and blue gamma ramps for
5155 * flags: Can be DDSGR_CALIBRATE to request calibration
5156 * gamma_ramp: Structure containing the new gamma ramp
5160 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
5162 **********************************************************/
5163 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
5164 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
5166 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
5168 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
5172 WARN("Invalid gamma_ramp passed.\n");
5173 return DDERR_INVALIDPARAMS
;
5176 wined3d_mutex_lock();
5177 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5179 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
5180 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
5181 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
5185 ERR("Not implemented for non-primary surfaces.\n");
5187 wined3d_mutex_unlock();
5192 /*****************************************************************************
5193 * IDirect3DTexture2::PaletteChanged
5195 * Informs the texture about a palette change
5198 * start: Start index of the change
5199 * count: The number of changed entries
5202 * D3D_OK, because it's a stub
5204 *****************************************************************************/
5205 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
5207 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
5212 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
5214 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5216 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
5218 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
5221 /*****************************************************************************
5222 * IDirect3DTexture::Unload
5224 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
5230 *****************************************************************************/
5231 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
5233 WARN("iface %p. Not implemented.\n", iface
);
5235 return DDERR_UNSUPPORTED
;
5238 /*****************************************************************************
5239 * IDirect3DTexture2::GetHandle
5241 * Returns handle for the texture.
5244 * device: Device this handle is assigned to
5245 * handle: Address to store the handle at.
5250 *****************************************************************************/
5251 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5252 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5254 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5255 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5257 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5259 wined3d_mutex_lock();
5261 if (!surface
->Handle
)
5263 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5264 if (h
== DDRAW_INVALID_HANDLE
)
5266 ERR("Failed to allocate a texture handle.\n");
5267 wined3d_mutex_unlock();
5268 return DDERR_OUTOFMEMORY
;
5271 surface
->Handle
= h
+ 1;
5274 TRACE("Returning handle %08x.\n", surface
->Handle
);
5275 *handle
= surface
->Handle
;
5277 wined3d_mutex_unlock();
5282 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5283 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5285 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5286 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5288 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5290 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5291 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5294 /*****************************************************************************
5295 * get_sub_mimaplevel
5297 * Helper function that returns the next mipmap level
5299 * tex_ptr: Surface of which to return the next level
5301 *****************************************************************************/
5302 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5304 /* Now go down the mipmap chain to the next surface */
5305 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5306 IDirectDrawSurface7
*next_level
;
5309 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5310 if (FAILED(hr
)) return NULL
;
5312 ddraw_surface7_Release(next_level
);
5314 return impl_from_IDirectDrawSurface7(next_level
);
5317 /*****************************************************************************
5318 * IDirect3DTexture2::Load
5320 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5322 * This function isn't relayed to WineD3D because the whole interface is
5323 * implemented in DDraw only. For speed improvements an implementation which
5324 * takes OpenGL more into account could be placed into WineD3D.
5327 * src_texture: Address of the texture to load
5331 * D3DERR_TEXTURE_LOAD_FAILED.
5333 *****************************************************************************/
5334 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5336 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5337 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5338 struct wined3d_resource
*dst_resource
, *src_resource
;
5341 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5343 if (src_surface
== dst_surface
)
5345 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5349 wined3d_mutex_lock();
5351 dst_resource
= wined3d_texture_get_resource(ddraw_surface_get_default_texture(dst_surface
, DDRAW_SURFACE_WRITE
));
5352 src_resource
= wined3d_texture_get_resource(ddraw_surface_get_default_texture(src_surface
, DDRAW_SURFACE_READ
));
5354 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5355 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5356 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5358 ERR("Trying to load surfaces with different mip-map counts.\n");
5363 struct ddraw_palette
*dst_pal
, *src_pal
;
5364 DDSURFACEDESC
*src_desc
, *dst_desc
;
5366 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5368 /* Suppress the ALLOCONLOAD flag */
5369 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5371 /* Get the palettes */
5372 dst_pal
= dst_surface
->palette
;
5373 src_pal
= src_surface
->palette
;
5377 PALETTEENTRY palent
[256];
5381 wined3d_mutex_unlock();
5382 return DDERR_NOPALETTEATTACHED
;
5384 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5385 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5388 /* Copy one surface on the other */
5389 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5390 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5392 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5394 /* Should also check for same pixel format, u1.lPitch, ... */
5395 ERR("Error in surface sizes.\n");
5396 wined3d_mutex_unlock();
5397 return D3DERR_TEXTURE_LOAD_FAILED
;
5401 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5403 /* Copy the src blit color key if the source has one, don't erase
5404 * the destination's ckey if the source has none */
5405 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5407 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5408 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5411 if (FAILED(hr
= wined3d_resource_map(src_resource
,
5412 src_surface
->sub_resource_idx
, &src_map_desc
, NULL
, WINED3D_MAP_READ
)))
5414 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5415 wined3d_mutex_unlock();
5416 return D3DERR_TEXTURE_LOAD_FAILED
;
5419 if (FAILED(hr
= wined3d_resource_map(dst_resource
,
5420 dst_surface
->sub_resource_idx
, &dst_map_desc
, NULL
, WINED3D_MAP_WRITE
)))
5422 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5423 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5424 wined3d_mutex_unlock();
5425 return D3DERR_TEXTURE_LOAD_FAILED
;
5428 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5429 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5431 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5433 wined3d_resource_unmap(dst_resource
, dst_surface
->sub_resource_idx
);
5434 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5437 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5438 src_surface
= get_sub_mimaplevel(src_surface
);
5442 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5443 dst_surface
= get_sub_mimaplevel(dst_surface
);
5447 if (!src_surface
|| !dst_surface
)
5449 if (src_surface
!= dst_surface
)
5450 ERR("Loading surface with different mipmap structure.\n");
5455 wined3d_mutex_unlock();
5460 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5462 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5463 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5465 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5467 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5468 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5471 /*****************************************************************************
5473 *****************************************************************************/
5475 /* Some windowed mode wrappers expect this vtbl to be writable. */
5476 static struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5479 ddraw_surface7_QueryInterface
,
5480 ddraw_surface7_AddRef
,
5481 ddraw_surface7_Release
,
5482 /* IDirectDrawSurface */
5483 ddraw_surface7_AddAttachedSurface
,
5484 ddraw_surface7_AddOverlayDirtyRect
,
5486 ddraw_surface7_BltBatch
,
5487 ddraw_surface7_BltFast
,
5488 ddraw_surface7_DeleteAttachedSurface
,
5489 ddraw_surface7_EnumAttachedSurfaces
,
5490 ddraw_surface7_EnumOverlayZOrders
,
5491 ddraw_surface7_Flip
,
5492 ddraw_surface7_GetAttachedSurface
,
5493 ddraw_surface7_GetBltStatus
,
5494 ddraw_surface7_GetCaps
,
5495 ddraw_surface7_GetClipper
,
5496 ddraw_surface7_GetColorKey
,
5497 ddraw_surface7_GetDC
,
5498 ddraw_surface7_GetFlipStatus
,
5499 ddraw_surface7_GetOverlayPosition
,
5500 ddraw_surface7_GetPalette
,
5501 ddraw_surface7_GetPixelFormat
,
5502 ddraw_surface7_GetSurfaceDesc
,
5503 ddraw_surface7_Initialize
,
5504 ddraw_surface7_IsLost
,
5505 ddraw_surface7_Lock
,
5506 ddraw_surface7_ReleaseDC
,
5507 ddraw_surface7_Restore
,
5508 ddraw_surface7_SetClipper
,
5509 ddraw_surface7_SetColorKey
,
5510 ddraw_surface7_SetOverlayPosition
,
5511 ddraw_surface7_SetPalette
,
5512 ddraw_surface7_Unlock
,
5513 ddraw_surface7_UpdateOverlay
,
5514 ddraw_surface7_UpdateOverlayDisplay
,
5515 ddraw_surface7_UpdateOverlayZOrder
,
5516 /* IDirectDrawSurface2 */
5517 ddraw_surface7_GetDDInterface
,
5518 ddraw_surface7_PageLock
,
5519 ddraw_surface7_PageUnlock
,
5520 /* IDirectDrawSurface3 */
5521 ddraw_surface7_SetSurfaceDesc
,
5522 /* IDirectDrawSurface4 */
5523 ddraw_surface7_SetPrivateData
,
5524 ddraw_surface7_GetPrivateData
,
5525 ddraw_surface7_FreePrivateData
,
5526 ddraw_surface7_GetUniquenessValue
,
5527 ddraw_surface7_ChangeUniquenessValue
,
5528 /* IDirectDrawSurface7 */
5529 ddraw_surface7_SetPriority
,
5530 ddraw_surface7_GetPriority
,
5531 ddraw_surface7_SetLOD
,
5532 ddraw_surface7_GetLOD
,
5535 /* Some windowed mode wrappers expect this vtbl to be writable. */
5536 static struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5539 ddraw_surface4_QueryInterface
,
5540 ddraw_surface4_AddRef
,
5541 ddraw_surface4_Release
,
5542 /* IDirectDrawSurface */
5543 ddraw_surface4_AddAttachedSurface
,
5544 ddraw_surface4_AddOverlayDirtyRect
,
5546 ddraw_surface4_BltBatch
,
5547 ddraw_surface4_BltFast
,
5548 ddraw_surface4_DeleteAttachedSurface
,
5549 ddraw_surface4_EnumAttachedSurfaces
,
5550 ddraw_surface4_EnumOverlayZOrders
,
5551 ddraw_surface4_Flip
,
5552 ddraw_surface4_GetAttachedSurface
,
5553 ddraw_surface4_GetBltStatus
,
5554 ddraw_surface4_GetCaps
,
5555 ddraw_surface4_GetClipper
,
5556 ddraw_surface4_GetColorKey
,
5557 ddraw_surface4_GetDC
,
5558 ddraw_surface4_GetFlipStatus
,
5559 ddraw_surface4_GetOverlayPosition
,
5560 ddraw_surface4_GetPalette
,
5561 ddraw_surface4_GetPixelFormat
,
5562 ddraw_surface4_GetSurfaceDesc
,
5563 ddraw_surface4_Initialize
,
5564 ddraw_surface4_IsLost
,
5565 ddraw_surface4_Lock
,
5566 ddraw_surface4_ReleaseDC
,
5567 ddraw_surface4_Restore
,
5568 ddraw_surface4_SetClipper
,
5569 ddraw_surface4_SetColorKey
,
5570 ddraw_surface4_SetOverlayPosition
,
5571 ddraw_surface4_SetPalette
,
5572 ddraw_surface4_Unlock
,
5573 ddraw_surface4_UpdateOverlay
,
5574 ddraw_surface4_UpdateOverlayDisplay
,
5575 ddraw_surface4_UpdateOverlayZOrder
,
5576 /* IDirectDrawSurface2 */
5577 ddraw_surface4_GetDDInterface
,
5578 ddraw_surface4_PageLock
,
5579 ddraw_surface4_PageUnlock
,
5580 /* IDirectDrawSurface3 */
5581 ddraw_surface4_SetSurfaceDesc
,
5582 /* IDirectDrawSurface4 */
5583 ddraw_surface4_SetPrivateData
,
5584 ddraw_surface4_GetPrivateData
,
5585 ddraw_surface4_FreePrivateData
,
5586 ddraw_surface4_GetUniquenessValue
,
5587 ddraw_surface4_ChangeUniquenessValue
,
5590 /* Some windowed mode wrappers expect this vtbl to be writable. */
5591 static struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5594 ddraw_surface3_QueryInterface
,
5595 ddraw_surface3_AddRef
,
5596 ddraw_surface3_Release
,
5597 /* IDirectDrawSurface */
5598 ddraw_surface3_AddAttachedSurface
,
5599 ddraw_surface3_AddOverlayDirtyRect
,
5601 ddraw_surface3_BltBatch
,
5602 ddraw_surface3_BltFast
,
5603 ddraw_surface3_DeleteAttachedSurface
,
5604 ddraw_surface3_EnumAttachedSurfaces
,
5605 ddraw_surface3_EnumOverlayZOrders
,
5606 ddraw_surface3_Flip
,
5607 ddraw_surface3_GetAttachedSurface
,
5608 ddraw_surface3_GetBltStatus
,
5609 ddraw_surface3_GetCaps
,
5610 ddraw_surface3_GetClipper
,
5611 ddraw_surface3_GetColorKey
,
5612 ddraw_surface3_GetDC
,
5613 ddraw_surface3_GetFlipStatus
,
5614 ddraw_surface3_GetOverlayPosition
,
5615 ddraw_surface3_GetPalette
,
5616 ddraw_surface3_GetPixelFormat
,
5617 ddraw_surface3_GetSurfaceDesc
,
5618 ddraw_surface3_Initialize
,
5619 ddraw_surface3_IsLost
,
5620 ddraw_surface3_Lock
,
5621 ddraw_surface3_ReleaseDC
,
5622 ddraw_surface3_Restore
,
5623 ddraw_surface3_SetClipper
,
5624 ddraw_surface3_SetColorKey
,
5625 ddraw_surface3_SetOverlayPosition
,
5626 ddraw_surface3_SetPalette
,
5627 ddraw_surface3_Unlock
,
5628 ddraw_surface3_UpdateOverlay
,
5629 ddraw_surface3_UpdateOverlayDisplay
,
5630 ddraw_surface3_UpdateOverlayZOrder
,
5631 /* IDirectDrawSurface2 */
5632 ddraw_surface3_GetDDInterface
,
5633 ddraw_surface3_PageLock
,
5634 ddraw_surface3_PageUnlock
,
5635 /* IDirectDrawSurface3 */
5636 ddraw_surface3_SetSurfaceDesc
,
5639 /* Some windowed mode wrappers expect this vtbl to be writable. */
5640 static struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5643 ddraw_surface2_QueryInterface
,
5644 ddraw_surface2_AddRef
,
5645 ddraw_surface2_Release
,
5646 /* IDirectDrawSurface */
5647 ddraw_surface2_AddAttachedSurface
,
5648 ddraw_surface2_AddOverlayDirtyRect
,
5650 ddraw_surface2_BltBatch
,
5651 ddraw_surface2_BltFast
,
5652 ddraw_surface2_DeleteAttachedSurface
,
5653 ddraw_surface2_EnumAttachedSurfaces
,
5654 ddraw_surface2_EnumOverlayZOrders
,
5655 ddraw_surface2_Flip
,
5656 ddraw_surface2_GetAttachedSurface
,
5657 ddraw_surface2_GetBltStatus
,
5658 ddraw_surface2_GetCaps
,
5659 ddraw_surface2_GetClipper
,
5660 ddraw_surface2_GetColorKey
,
5661 ddraw_surface2_GetDC
,
5662 ddraw_surface2_GetFlipStatus
,
5663 ddraw_surface2_GetOverlayPosition
,
5664 ddraw_surface2_GetPalette
,
5665 ddraw_surface2_GetPixelFormat
,
5666 ddraw_surface2_GetSurfaceDesc
,
5667 ddraw_surface2_Initialize
,
5668 ddraw_surface2_IsLost
,
5669 ddraw_surface2_Lock
,
5670 ddraw_surface2_ReleaseDC
,
5671 ddraw_surface2_Restore
,
5672 ddraw_surface2_SetClipper
,
5673 ddraw_surface2_SetColorKey
,
5674 ddraw_surface2_SetOverlayPosition
,
5675 ddraw_surface2_SetPalette
,
5676 ddraw_surface2_Unlock
,
5677 ddraw_surface2_UpdateOverlay
,
5678 ddraw_surface2_UpdateOverlayDisplay
,
5679 ddraw_surface2_UpdateOverlayZOrder
,
5680 /* IDirectDrawSurface2 */
5681 ddraw_surface2_GetDDInterface
,
5682 ddraw_surface2_PageLock
,
5683 ddraw_surface2_PageUnlock
,
5686 /* Bad Mojo Redux expects this vtbl to be writable. */
5687 static struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5690 ddraw_surface1_QueryInterface
,
5691 ddraw_surface1_AddRef
,
5692 ddraw_surface1_Release
,
5693 /* IDirectDrawSurface */
5694 ddraw_surface1_AddAttachedSurface
,
5695 ddraw_surface1_AddOverlayDirtyRect
,
5697 ddraw_surface1_BltBatch
,
5698 ddraw_surface1_BltFast
,
5699 ddraw_surface1_DeleteAttachedSurface
,
5700 ddraw_surface1_EnumAttachedSurfaces
,
5701 ddraw_surface1_EnumOverlayZOrders
,
5702 ddraw_surface1_Flip
,
5703 ddraw_surface1_GetAttachedSurface
,
5704 ddraw_surface1_GetBltStatus
,
5705 ddraw_surface1_GetCaps
,
5706 ddraw_surface1_GetClipper
,
5707 ddraw_surface1_GetColorKey
,
5708 ddraw_surface1_GetDC
,
5709 ddraw_surface1_GetFlipStatus
,
5710 ddraw_surface1_GetOverlayPosition
,
5711 ddraw_surface1_GetPalette
,
5712 ddraw_surface1_GetPixelFormat
,
5713 ddraw_surface1_GetSurfaceDesc
,
5714 ddraw_surface1_Initialize
,
5715 ddraw_surface1_IsLost
,
5716 ddraw_surface1_Lock
,
5717 ddraw_surface1_ReleaseDC
,
5718 ddraw_surface1_Restore
,
5719 ddraw_surface1_SetClipper
,
5720 ddraw_surface1_SetColorKey
,
5721 ddraw_surface1_SetOverlayPosition
,
5722 ddraw_surface1_SetPalette
,
5723 ddraw_surface1_Unlock
,
5724 ddraw_surface1_UpdateOverlay
,
5725 ddraw_surface1_UpdateOverlayDisplay
,
5726 ddraw_surface1_UpdateOverlayZOrder
,
5729 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5731 ddraw_gamma_control_QueryInterface
,
5732 ddraw_gamma_control_AddRef
,
5733 ddraw_gamma_control_Release
,
5734 ddraw_gamma_control_GetGammaRamp
,
5735 ddraw_gamma_control_SetGammaRamp
,
5738 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5740 d3d_texture2_QueryInterface
,
5741 d3d_texture2_AddRef
,
5742 d3d_texture2_Release
,
5743 d3d_texture2_GetHandle
,
5744 d3d_texture2_PaletteChanged
,
5748 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5750 d3d_texture1_QueryInterface
,
5751 d3d_texture1_AddRef
,
5752 d3d_texture1_Release
,
5753 d3d_texture1_Initialize
,
5754 d3d_texture1_GetHandle
,
5755 d3d_texture1_PaletteChanged
,
5757 d3d_texture1_Unload
,
5760 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5761 * IDirectDrawSurface interface to ddraw methods. */
5762 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5764 if (!iface
) return NULL
;
5765 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5767 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5770 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5773 IDirectDrawSurface7_Release(iface
);
5775 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5778 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5780 if (!iface
) return NULL
;
5781 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5783 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5786 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5789 IDirectDrawSurface4_Release(iface
);
5791 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5794 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5796 if (!iface
) return NULL
;
5797 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5799 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5802 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5805 IDirectDrawSurface3_Release(iface
);
5807 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5810 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5812 if (!iface
) return NULL
;
5813 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5815 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5818 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5821 IDirectDrawSurface2_Release(iface
);
5823 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5826 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5828 if (!iface
) return NULL
;
5829 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5831 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5834 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5837 IDirectDrawSurface_Release(iface
);
5839 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5842 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5844 if (!iface
) return NULL
;
5845 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5846 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5849 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5851 if (!iface
) return NULL
;
5852 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5853 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5856 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5858 struct ddraw_surface
*surface
= parent
;
5860 TRACE("surface %p.\n", surface
);
5862 /* This shouldn't happen, ddraw_surface_release_iface() should prevent the
5863 * surface from being destroyed in this case. */
5864 if (surface
->first_attached
!= surface
)
5865 ERR("Surface is still attached to surface %p.\n", surface
->first_attached
);
5867 while (surface
->next_attached
)
5868 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5869 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5870 ERR("DeleteAttachedSurface failed.\n");
5872 /* Having a texture handle set implies that the device still exists. */
5873 if (surface
->Handle
)
5874 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5876 /* Reduce the ddraw surface count. */
5877 list_remove(&surface
->surface_list_entry
);
5879 if (surface
->clipper
&& ddraw_clipper_is_valid(surface
->clipper
))
5880 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5882 if (surface
== surface
->ddraw
->primary
)
5884 surface
->ddraw
->primary
= NULL
;
5885 surface
->ddraw
->gdi_surface
= NULL
;
5888 wined3d_private_store_cleanup(&surface
->private_store
);
5890 if (surface
->draw_texture
)
5891 wined3d_texture_decref(surface
->wined3d_texture
);
5896 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5898 ddraw_surface_wined3d_object_destroyed
,
5901 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5903 struct ddraw_texture
*texture
= parent
;
5905 TRACE("texture %p, texture_memory %p.\n", texture
, texture
->texture_memory
);
5907 heap_free(texture
->texture_memory
);
5911 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5913 ddraw_texture_wined3d_object_destroyed
,
5916 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5921 static HRESULT
ddraw_surface_reserve_memory(struct wined3d_texture
*wined3d_texture
)
5923 static const unsigned int extra_size
= 0x10000;
5925 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
5926 struct wined3d_resource_desc resource_desc
;
5927 struct wined3d_sub_resource_desc desc
;
5928 unsigned int pitch
, slice_pitch
;
5929 unsigned int sub_resource_idx
;
5930 HRESULT hr
= WINED3D_OK
;
5931 unsigned int offset
;
5933 wined3d_resource_get_desc(wined3d_texture_get_resource(wined3d_texture
), &resource_desc
);
5934 if (!(texture
->texture_memory
= heap_alloc_zero(resource_desc
.size
+ extra_size
)))
5936 ERR("Out of memory.\n");
5937 return E_OUTOFMEMORY
;
5939 TRACE("texture->texture_memory %p.\n", texture
->texture_memory
);
5942 sub_resource_idx
= 0;
5943 while (wined3d_texture_get_sub_resource_desc(wined3d_texture
, sub_resource_idx
, &desc
)
5946 wined3d_texture_get_pitch(wined3d_texture
, sub_resource_idx
, &pitch
, &slice_pitch
);
5948 if (FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
, sub_resource_idx
,
5949 desc
.width
, desc
.height
, resource_desc
.format
,
5950 desc
.multisample_type
, desc
.multisample_quality
,
5951 (BYTE
*)texture
->texture_memory
+ offset
, pitch
)))
5953 heap_free(texture
->texture_memory
);
5954 texture
->texture_memory
= NULL
;
5958 offset
+= desc
.size
;
5963 static HRESULT
ddraw_surface_create_wined3d_texture(DDSURFACEDESC2
*desc
, struct wined3d_device
*wined3d_device
,
5964 const struct wined3d_resource_desc
*wined3d_desc
, unsigned int layers
, unsigned int levels
,
5965 struct ddraw_texture
*texture
, struct wined3d_texture
**wined3d_texture
)
5967 struct wined3d_resource_desc draw_texture_desc
;
5968 struct wined3d_texture
*draw_texture
;
5969 struct ddraw_surface
*parent
;
5970 unsigned int bind_flags
;
5975 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5976 || (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5977 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
5979 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5980 bind_flags
|= WINED3D_BIND_DEPTH_STENCIL
;
5981 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5982 bind_flags
|= WINED3D_BIND_RENDER_TARGET
;
5984 if (!bind_flags
|| (wined3d_desc
->access
& WINED3D_RESOURCE_ACCESS_GPU
&& !(bind_flags
& ~wined3d_desc
->bind_flags
)))
5985 goto no_draw_texture
;
5987 draw_texture_desc
= *wined3d_desc
;
5988 draw_texture_desc
.bind_flags
= bind_flags
;
5989 draw_texture_desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
;
5991 if (FAILED(hr
= wined3d_texture_create(wined3d_device
, &draw_texture_desc
, layers
,
5992 levels
, 0, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &draw_texture
)))
5994 WARN("Failed to create draw texture, hr %#x.\n", hr
);
5995 goto no_draw_texture
;
5997 wined3d_texture_decref(draw_texture
);
5999 /* Some applications assume surfaces will always be mapped at the same
6000 * address. Some of those also assume that this address is valid even when
6001 * the surface isn't mapped, and that updates done this way will be
6002 * visible on the screen. The game Nox is such an application,
6003 * Commandos: Behind Enemy Lines is another. Setting
6004 * WINED3D_TEXTURE_CREATE_GET_DC_LENIENT will ensure this. */
6005 if (FAILED(hr
= wined3d_texture_create(wined3d_device
, wined3d_desc
, layers
, levels
,
6006 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, NULL
, &ddraw_null_wined3d_parent_ops
,
6009 parent
= wined3d_texture_get_sub_resource_parent(draw_texture
, 0);
6010 if (texture
->version
== 7)
6011 IDirectDrawSurface7_Release(&parent
->IDirectDrawSurface7_iface
);
6012 else if (texture
->version
== 4)
6013 IDirectDrawSurface4_Release(&parent
->IDirectDrawSurface4_iface
);
6015 IDirectDrawSurface_Release(&parent
->IDirectDrawSurface_iface
);
6018 wined3d_resource_set_parent(wined3d_texture_get_resource(*wined3d_texture
), texture
);
6019 for (i
= 0; i
< layers
* levels
; ++i
)
6021 parent
= wined3d_texture_get_sub_resource_parent(draw_texture
, i
);
6022 assert(parent
->wined3d_texture
== draw_texture
);
6023 parent
->draw_texture
= draw_texture
;
6024 parent
->wined3d_texture
= *wined3d_texture
;
6025 wined3d_texture_set_sub_resource_parent(*wined3d_texture
, i
, parent
);
6026 wined3d_texture_incref(*wined3d_texture
);
6028 wined3d_texture_decref(*wined3d_texture
);
6029 TRACE("Surface %p, created draw_texture %p, wined3d_texture %p.\n",
6030 wined3d_texture_get_sub_resource_parent(draw_texture
, 0), draw_texture
, wined3d_texture
);
6034 if (SUCCEEDED(hr
= wined3d_texture_create(wined3d_device
, wined3d_desc
, layers
, levels
,
6035 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
,
6037 wined3d_texture_decref(*wined3d_texture
);
6041 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
6042 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
6044 struct wined3d_sub_resource_desc wined3d_mip_desc
;
6045 struct ddraw_surface
*root
, *mip
, **attach
;
6046 struct wined3d_resource_desc wined3d_desc
;
6047 DDPIXELFORMAT wined3d_display_mode_format
;
6048 struct wined3d_texture
*wined3d_texture
;
6049 struct wined3d_display_mode mode
;
6050 DDSURFACEDESC2
*desc
, *mip_desc
;
6051 struct ddraw_texture
*texture
;
6052 BOOL sysmem_fallback
= FALSE
;
6053 unsigned int layers
= 1;
6054 unsigned int pitch
= 0;
6055 BOOL reserve_memory
;
6059 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
6060 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
6061 if (TRACE_ON(ddraw
))
6063 TRACE("Requesting surface desc:\n");
6064 DDRAW_dump_surface_desc(surface_desc
);
6068 return CLASS_E_NOAGGREGATION
;
6073 if (!(texture
= heap_alloc(sizeof(*texture
))))
6074 return E_OUTOFMEMORY
;
6076 texture
->texture_memory
= NULL
;
6077 texture
->version
= version
;
6078 texture
->surface_desc
= *surface_desc
;
6079 desc
= &texture
->surface_desc
;
6081 /* Ensure DDSD_CAPS is always set. */
6082 desc
->dwFlags
|= DDSD_CAPS
;
6084 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
6086 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
6088 WARN("Tried to create a flippable surface without any back buffers.\n");
6090 return DDERR_INVALIDCAPS
;
6093 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
))
6095 WARN("Tried to create a flippable surface without DDSCAPS_COMPLEX.\n");
6097 return DDERR_INVALIDCAPS
;
6100 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6102 WARN("Tried to create a flippable cubemap.\n");
6104 return DDERR_INVALIDPARAMS
;
6107 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6109 FIXME("Flippable textures not implemented.\n");
6111 return DDERR_INVALIDCAPS
;
6116 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6118 WARN("Tried to specify a back buffer count for a non-flippable surface.\n");
6119 hr
= desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
? DDERR_INVALIDPARAMS
: DDERR_INVALIDCAPS
;
6125 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6127 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6129 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
6131 return DDERR_INVALIDCAPS
;
6134 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
))
6136 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
6138 return DDERR_INVALIDCAPS
;
6141 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
) && !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
6143 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
6145 return DDERR_NOEXCLUSIVEMODE
;
6149 /* This is a special case in ddrawex, but not allowed in ddraw. */
6150 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
6151 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
6153 WARN("Tried to create a surface in both system and video memory.\n");
6155 return DDERR_INVALIDCAPS
;
6158 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
6159 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
6161 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
6163 return DDERR_INVALIDCAPS
;
6166 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
6167 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
6169 WARN("Cube map faces requested without cube map flag.\n");
6171 return DDERR_INVALIDCAPS
;
6174 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6175 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
6177 WARN("Cube map without faces requested.\n");
6179 return DDERR_INVALIDPARAMS
;
6182 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6183 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
6184 FIXME("Partial cube maps not implemented.\n");
6186 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
6188 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
6190 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
6192 return DDERR_INVALIDCAPS
;
6194 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
6196 WARN("DDSCAPS2_TEXTUREMANAGE used with DDSCAPS_VIDEOMEMORY "
6197 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
6199 return DDERR_INVALIDCAPS
;
6203 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_WRITEONLY
6204 && !(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
6206 WARN("DDSCAPS_WRITEONLY used without DDSCAPS2_TEXTUREMANAGE, returning DDERR_INVALIDCAPS.\n");
6208 return DDERR_INVALIDCAPS
;
6211 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
6213 ERR("Failed to get display mode, hr %#x.\n", hr
);
6215 return hr_ddraw_from_wined3d(hr
);
6218 wined3d_display_mode_format
.dwSize
= sizeof(wined3d_display_mode_format
);
6219 ddrawformat_from_wined3dformat(&wined3d_display_mode_format
, mode
.format_id
);
6221 /* No pixelformat given? Use the current screen format. */
6222 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
6224 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
6225 desc
->u4
.ddpfPixelFormat
= wined3d_display_mode_format
;
6228 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
6229 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
6230 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
6232 WARN("Unsupported / unknown pixelformat.\n");
6234 return DDERR_INVALIDPIXELFORMAT
;
6237 /* No width or no height? Use the screen size. */
6238 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
6240 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
6242 WARN("No width / height specified.\n");
6244 return DDERR_INVALIDPARAMS
;
6247 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
6248 desc
->dwWidth
= mode
.width
;
6249 desc
->dwHeight
= mode
.height
;
6252 if (!desc
->dwWidth
|| !desc
->dwHeight
)
6255 return DDERR_INVALIDPARAMS
;
6258 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
6259 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
6261 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6263 /* The first surface is a front buffer, the back buffers are created
6265 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
6266 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
6268 struct wined3d_swapchain_desc swapchain_desc
;
6270 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
6271 swapchain_desc
.backbuffer_width
= mode
.width
;
6272 swapchain_desc
.backbuffer_height
= mode
.height
;
6273 swapchain_desc
.backbuffer_format
= mode
.format_id
;
6275 if (ddraw
->d3ddevice
)
6277 if (ddraw
->d3ddevice
->recording
)
6278 wined3d_stateblock_decref(ddraw
->d3ddevice
->recording
);
6279 ddraw
->d3ddevice
->recording
= NULL
;
6280 ddraw
->d3ddevice
->update_state
= ddraw
->d3ddevice
->state
;
6282 wined3d_stateblock_reset(ddraw
->state
);
6284 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
6285 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
6287 ERR("Failed to reset device.\n");
6289 return hr_ddraw_from_wined3d(hr
);
6292 wined3d_stateblock_set_render_state(ddraw
->state
, WINED3D_RS_ZENABLE
,
6293 !!swapchain_desc
.enable_auto_depth_stencil
);
6297 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
6298 wined3d_desc
.multisample_quality
= 0;
6299 wined3d_desc
.usage
= 0;
6300 wined3d_desc
.bind_flags
= 0;
6301 wined3d_desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
| WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
6302 wined3d_desc
.width
= desc
->dwWidth
;
6303 wined3d_desc
.height
= desc
->dwHeight
;
6304 wined3d_desc
.depth
= 1;
6305 wined3d_desc
.size
= 0;
6307 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
6309 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
6310 /* Do not fail surface creation, only fail 3D device creation. */
6313 /* Mipmap count fixes */
6314 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
6316 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
6318 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
6320 /* Mipmap count is given, should not be 0. */
6321 if (!desc
->u2
.dwMipMapCount
)
6324 return DDERR_INVALIDPARAMS
;
6329 /* Undocumented feature: Create sublevels until either the
6330 * width or the height is 1. */
6332 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
6334 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
6339 desc
->u2
.dwMipMapCount
= 1;
6342 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
6343 levels
= desc
->u2
.dwMipMapCount
;
6350 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
6352 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
6354 unsigned int bind_flags
= 0;
6357 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6359 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6360 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
6362 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6364 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
6367 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6368 bind_flags
|= WINED3D_BIND_DEPTH_STENCIL
;
6369 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6370 bind_flags
|= WINED3D_BIND_RENDER_TARGET
;
6372 if (!(ddraw
->flags
& DDRAW_NO3D
) && SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
,
6373 ddraw
->wined3d_adapter
, WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
,
6374 usage
, bind_flags
, WINED3D_RTYPE_TEXTURE_2D
, wined3d_desc
.format
)))
6376 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
6380 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6381 sysmem_fallback
= TRUE
;
6384 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
6386 /* Tests show surfaces without memory flags get these flags added
6387 * right after creation. */
6388 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
6392 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
6393 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
6395 WARN("System memory overlays are not allowed.\n");
6397 return DDERR_NOOVERLAYHW
;
6400 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
6402 wined3d_desc
.access
= WINED3D_RESOURCE_ACCESS_CPU
6403 | WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
6407 if (!(ddraw
->flags
& DDRAW_NO3D
))
6409 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6410 wined3d_desc
.bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
6411 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6412 wined3d_desc
.bind_flags
|= WINED3D_BIND_DEPTH_STENCIL
;
6413 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6414 wined3d_desc
.bind_flags
|= WINED3D_BIND_RENDER_TARGET
;
6417 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
6419 wined3d_desc
.bind_flags
&= ~WINED3D_BIND_RENDER_TARGET
;
6420 wined3d_desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
| WINED3D_RESOURCE_ACCESS_CPU
6421 | WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
6422 /* Managed textures have the system memory flag set. */
6423 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6425 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
6427 /* Videomemory adds localvidmem. This is mutually exclusive with
6428 * systemmemory and texturemanage. */
6429 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
6430 /* Dynamic resources can't be written by the GPU. */
6431 if (!(wined3d_desc
.bind_flags
& (WINED3D_BIND_RENDER_TARGET
| WINED3D_BIND_DEPTH_STENCIL
)))
6432 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
6436 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6438 if (wined3d_desc
.access
& WINED3D_RESOURCE_ACCESS_GPU
)
6440 WARN("User memory surfaces should not be GPU accessible.\n");
6442 return DDERR_INVALIDCAPS
;
6447 WARN("User memory surfaces not supported before version 4.\n");
6449 return DDERR_INVALIDPARAMS
;
6452 if (!desc
->lpSurface
)
6454 WARN("NULL surface memory pointer specified.\n");
6456 return DDERR_INVALIDPARAMS
;
6459 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6461 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6463 WARN("Pitch specified on a compressed user memory surface.\n");
6465 return DDERR_INVALIDPARAMS
;
6468 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6470 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6472 return DDERR_INVALIDPARAMS
;
6475 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6476 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d_adapter
,
6477 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6479 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6481 return DDERR_INVALIDPARAMS
;
6486 if (!(desc
->dwFlags
& DDSD_PITCH
))
6488 WARN("User memory surfaces should explicitly specify the pitch.\n");
6490 return DDERR_INVALIDPARAMS
;
6493 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d_adapter
,
6494 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6496 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6498 return DDERR_INVALIDPARAMS
;
6501 pitch
= desc
->u1
.lPitch
;
6505 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6506 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6507 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6508 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6509 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6510 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6511 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6512 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6514 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6516 return DDERR_NOCOLORKEYHW
;
6519 if ((ddraw
->flags
& DDRAW_NO3D
) && (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
6521 WARN("Video memory surfaces not supported without 3D support.\n");
6523 return DDERR_NODIRECTDRAWHW
;
6526 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6527 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6529 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6530 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6532 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6534 wined3d_desc
.usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6538 if (FAILED(hr
= ddraw_surface_create_wined3d_texture(desc
, ddraw
->wined3d_device
, &wined3d_desc
, layers
, levels
,
6539 texture
, &wined3d_texture
)))
6541 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6543 return hr_ddraw_from_wined3d(hr
);
6546 root
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6548 root
->is_complex_root
= TRUE
;
6549 root
->sysmem_fallback
= sysmem_fallback
;
6550 texture
->root
= root
;
6551 wined3d_device_incref(texture
->wined3d_device
= ddraw
->wined3d_device
);
6553 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6554 ddraw_surface_set_wined3d_textures_colour_key(root
, DDCKEY_DESTOVERLAY
,
6555 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6556 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6557 ddraw_surface_set_wined3d_textures_colour_key(root
, DDCKEY_DESTBLT
,
6558 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6559 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6560 ddraw_surface_set_wined3d_textures_colour_key(root
, DDCKEY_SRCOVERLAY
,
6561 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6562 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6563 ddraw_surface_set_wined3d_textures_colour_key(root
, DDCKEY_SRCBLT
,
6564 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6566 for (i
= 0; i
< layers
; ++i
)
6568 attach
= &root
->complex_array
[layers
- 1 - i
];
6570 for (j
= 0; j
< levels
; ++j
)
6572 mip
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, i
* levels
+ j
);
6573 mip
->sysmem_fallback
= sysmem_fallback
;
6574 mip_desc
= &mip
->surface_desc
;
6575 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
6576 mip_desc
->u2
.dwMipMapCount
= levels
- j
;
6580 wined3d_texture_get_sub_resource_desc(wined3d_texture
, i
* levels
+ j
, &wined3d_mip_desc
);
6581 mip_desc
->dwWidth
= wined3d_mip_desc
.width
;
6582 mip_desc
->dwHeight
= wined3d_mip_desc
.height
;
6584 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6588 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6591 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6593 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6597 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6598 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6600 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6601 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6603 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6604 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6606 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6607 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6609 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6610 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6612 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6613 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6623 attach
= &mip
->complex_array
[0];
6627 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
, 0,
6628 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6629 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6631 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6635 reserve_memory
= !(desc
->dwFlags
& DDSD_LPSURFACE
)
6636 && desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
6637 && wined3d_display_mode_format
.u1
.dwRGBBitCount
<= 16;
6639 if (reserve_memory
&& FAILED(hr
= ddraw_surface_reserve_memory(wined3d_texture
)))
6641 ERR("Failed to reserve surface memory, hr %#x.\n", hr
);
6645 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6647 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6648 struct ddraw_surface
*last
= root
;
6650 attach
= &last
->complex_array
[0];
6651 for (i
= 0; i
< count
; ++i
)
6653 if (!(texture
= heap_alloc(sizeof(*texture
))))
6659 texture
->texture_memory
= NULL
;
6660 texture
->version
= version
;
6661 texture
->surface_desc
= root
->surface_desc
;
6662 desc
= &texture
->surface_desc
;
6664 /* Only one surface in the flipping chain is a back buffer, one is
6665 * a front buffer, the others are just flippable surfaces. */
6666 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6667 | DDSCAPS_BACKBUFFER
);
6669 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6670 desc
->u5
.dwBackBufferCount
= 0;
6672 if (FAILED(hr
= ddraw_surface_create_wined3d_texture(desc
, ddraw
->wined3d_device
, &wined3d_desc
, 1, 1,
6673 texture
, &wined3d_texture
)))
6676 hr
= hr_ddraw_from_wined3d(hr
);
6680 last
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6681 last
->sysmem_fallback
= sysmem_fallback
;
6682 texture
->root
= last
;
6683 wined3d_device_incref(texture
->wined3d_device
= ddraw
->wined3d_device
);
6685 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6686 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6687 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6688 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6689 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6690 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6691 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6692 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6693 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6694 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6695 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6696 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6698 if (reserve_memory
&& FAILED(hr
= ddraw_surface_reserve_memory(wined3d_texture
)))
6700 hr
= hr_ddraw_from_wined3d(hr
);
6704 attach
= &last
->complex_array
[0];
6709 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6711 ddraw
->primary
= root
;
6712 ddraw
->gdi_surface
= root
->wined3d_texture
;
6720 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6721 else if (version
== 4)
6722 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6724 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6729 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
6730 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
6731 const struct wined3d_parent_ops
**parent_ops
)
6733 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
6734 unsigned int texture_level
, row_pitch
, slice_pitch
;
6735 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6736 unsigned int version
= texture
->version
;
6738 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6739 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6740 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6741 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6742 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6743 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6744 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6745 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6746 surface
->iface_count
= 1;
6747 surface
->version
= version
;
6748 surface
->ddraw
= ddraw
;
6753 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6755 else if (version
== 4)
6758 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6763 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6766 *desc
= texture
->surface_desc
;
6767 surface
->first_attached
= surface
;
6769 texture_level
= desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
? sub_resource_idx
% desc
->u2
.dwMipMapCount
: 0;
6770 wined3d_texture_get_pitch(wined3d_texture
, texture_level
, &row_pitch
, &slice_pitch
);
6771 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6773 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6774 desc
->u1
.dwLinearSize
= ~0u;
6776 desc
->u1
.dwLinearSize
= slice_pitch
;
6777 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6778 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6782 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6783 desc
->u1
.lPitch
= row_pitch
;
6784 desc
->dwFlags
|= DDSD_PITCH
;
6785 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6787 desc
->lpSurface
= NULL
;
6789 wined3d_texture_incref(surface
->wined3d_texture
= wined3d_texture
);
6790 surface
->sub_resource_idx
= sub_resource_idx
;
6791 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6792 surface
->texture_location
= DDRAW_SURFACE_LOCATION_DEFAULT
;
6794 wined3d_private_store_init(&surface
->private_store
);
6797 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6799 struct ddraw_surface
*surface
= parent
;
6801 /* If the surface reference count drops to zero, we release our reference
6802 * to the view, but don't clear the pointer yet, in case e.g. a
6803 * GetRenderTarget() call brings the surface back before the view is
6804 * actually destroyed. When the view is destroyed, we need to clear the
6805 * pointer, or a subsequent surface AddRef() would reference it again.
6807 * This is safe because as long as the view still has a reference to the
6808 * texture, the surface is also still alive, and we're called before the
6809 * view releases that reference. */
6810 surface
->wined3d_rtv
= NULL
;
6813 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6815 view_wined3d_object_destroyed
,
6818 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6820 struct wined3d_texture
*wined3d_texture
;
6823 if (surface
->wined3d_rtv
)
6824 return surface
->wined3d_rtv
;
6826 wined3d_texture
= surface
->draw_texture
? surface
->draw_texture
: surface
->wined3d_texture
;
6827 if (FAILED(hr
= wined3d_rendertarget_view_create_from_sub_resource(wined3d_texture
,
6828 surface
->sub_resource_idx
, surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6830 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6834 return surface
->wined3d_rtv
;