1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
32 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
34 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
36 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
39 /* This is slow, of course. Also, in case of locks, we can't prevent other
40 * applications from drawing to the screen while we've locked the frontbuffer.
41 * We'd like to do this in wined3d instead, but for that to work wined3d needs
42 * to support windowless rendering first. */
43 HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
, const RECT
*rect
, BOOL read
)
45 HDC surface_dc
, screen_dc
;
53 SetRect(&r
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
59 w
= rect
->right
- rect
->left
;
60 h
= rect
->bottom
- rect
->top
;
65 if (surface
->ddraw
->swapchain_window
)
67 /* Nothing to do, we control the frontbuffer, or at least the parts we
72 return wined3d_texture_blt(surface
->ddraw
->wined3d_frontbuffer
, 0, rect
,
73 surface
->wined3d_texture
, surface
->sub_resource_idx
, rect
, 0, NULL
, WINED3D_TEXF_POINT
);
76 if (FAILED(hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, &surface_dc
)))
78 ERR("Failed to get surface DC, hr %#x.\n", hr
);
82 wined3d_palette_apply_to_dc(surface
->palette
->wineD3DPalette
, surface_dc
);
84 if (!(screen_dc
= GetDC(NULL
)))
86 wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
87 ERR("Failed to get screen DC.\n");
92 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
93 screen_dc
, x
, y
, SRCCOPY
);
95 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
96 surface_dc
, x
, y
, SRCCOPY
);
98 ReleaseDC(NULL
, screen_dc
);
99 wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
103 ERR("Failed to blit to/from screen.\n");
110 /*****************************************************************************
111 * IUnknown parts follow
112 *****************************************************************************/
114 /*****************************************************************************
115 * IDirectDrawSurface7::QueryInterface
117 * A normal QueryInterface implementation. For QueryInterface rules
118 * see ddraw.c, IDirectDraw7::QueryInterface. This method
119 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
120 * in all versions, the IDirectDrawGammaControl interface and it can
121 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
124 * riid: The interface id queried for
125 * obj: Address to write the pointer to
129 * E_NOINTERFACE if the requested interface wasn't found
131 *****************************************************************************/
132 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
134 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
136 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
138 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
142 return DDERR_INVALIDPARAMS
;
144 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
146 IDirectDrawSurface7_AddRef(iface
);
148 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
152 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
154 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
155 *obj
= &This
->IDirectDrawSurface4_iface
;
156 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
160 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
162 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
163 *obj
= &This
->IDirectDrawSurface3_iface
;
164 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
168 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
170 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
171 *obj
= &This
->IDirectDrawSurface2_iface
;
172 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
176 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
177 || IsEqualGUID(riid
, &IID_IUnknown
))
179 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
180 *obj
= &This
->IDirectDrawSurface_iface
;
181 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
185 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
187 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
188 *obj
= &This
->IDirectDrawGammaControl_iface
;
189 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
193 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
195 WARN("Color control not implemented.\n");
197 return E_NOINTERFACE
;
200 if (This
->version
!= 7)
202 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
203 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
204 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
206 wined3d_mutex_lock();
211 if (FAILED(hr
= d3d_device_create(This
->ddraw
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
212 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
214 This
->device1
= NULL
;
215 wined3d_mutex_unlock();
216 WARN("Failed to create device, hr %#x.\n", hr
);
220 wined3d_mutex_unlock();
222 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
223 *obj
= &This
->device1
->IDirect3DDevice_iface
;
227 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
229 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
230 *obj
= &This
->IDirect3DTexture2_iface
;
234 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
236 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
237 *obj
= &This
->IDirect3DTexture_iface
;
242 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
244 if (This
->version
!= 7)
247 return E_NOINTERFACE
;
250 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
252 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
254 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
256 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
259 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
261 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
263 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
265 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
268 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
270 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
272 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
274 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
277 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
279 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
281 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
283 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
286 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
287 REFIID riid
, void **object
)
289 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
291 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
293 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
296 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
298 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
300 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
302 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
305 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
307 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
309 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
311 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
314 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
316 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
317 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
319 if (iface_count
== 1)
321 if (surface
->ifaceToRelease
)
322 IUnknown_AddRef(surface
->ifaceToRelease
);
323 wined3d_mutex_lock();
324 if (surface
->wined3d_rtv
)
325 wined3d_rendertarget_view_incref(surface
->wined3d_rtv
);
326 wined3d_texture_incref(surface
->wined3d_texture
);
327 wined3d_mutex_unlock();
331 /*****************************************************************************
332 * IDirectDrawSurface7::AddRef
334 * A normal addref implementation
339 *****************************************************************************/
340 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
342 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
343 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
345 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
349 ddraw_surface_add_iface(This
);
355 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
357 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
358 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
360 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
364 ddraw_surface_add_iface(This
);
370 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
372 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
373 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
375 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
379 ddraw_surface_add_iface(This
);
385 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
387 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
388 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
390 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
394 ddraw_surface_add_iface(This
);
400 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
402 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
403 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
405 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
409 ddraw_surface_add_iface(This
);
415 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
417 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
418 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
420 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
424 ddraw_surface_add_iface(This
);
430 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
432 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
434 TRACE("iface %p.\n", iface
);
436 return IUnknown_AddRef(surface
->texture_outer
);
439 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
441 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
443 TRACE("iface %p.\n", iface
);
445 return IUnknown_AddRef(surface
->texture_outer
);
448 static HRESULT
ddraw_surface_set_palette(struct ddraw_surface
*surface
, IDirectDrawPalette
*palette
)
450 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(palette
);
451 struct ddraw_palette
*prev
;
453 TRACE("iface %p, palette %p.\n", surface
, palette
);
455 if (palette_impl
&& palette_impl
->flags
& DDPCAPS_ALPHA
456 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
458 WARN("Alpha palette set on non-texture surface, returning DDERR_INVALIDSURFACETYPE.\n");
459 return DDERR_INVALIDSURFACETYPE
;
462 if (!format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
463 return DDERR_INVALIDPIXELFORMAT
;
465 wined3d_mutex_lock();
467 prev
= surface
->palette
;
468 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
471 prev
->flags
&= ~DDPCAPS_PRIMARYSURFACE
;
473 palette_impl
->flags
|= DDPCAPS_PRIMARYSURFACE
;
474 wined3d_swapchain_set_palette(surface
->ddraw
->wined3d_swapchain
,
475 palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
476 ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
479 IDirectDrawPalette_AddRef(&palette_impl
->IDirectDrawPalette_iface
);
481 IDirectDrawPalette_Release(&prev
->IDirectDrawPalette_iface
);
482 surface
->palette
= palette_impl
;
484 wined3d_mutex_unlock();
489 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
491 struct ddraw_surface
*surf
;
494 TRACE("surface %p.\n", surface
);
496 /* The refcount test shows that the palette is detached when the surface
498 ddraw_surface_set_palette(surface
, NULL
);
500 /* Loop through all complex attached surfaces and destroy them.
502 * Yet again, only the root can have more than one complexly attached
503 * surface, all the others have a total of one. */
504 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
506 if (!surface
->complex_array
[i
])
509 surf
= surface
->complex_array
[i
];
510 surface
->complex_array
[i
] = NULL
;
511 if (!surf
->is_complex_root
)
512 ddraw_surface_cleanup(surf
);
515 if (surface
->device1
)
516 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
518 if (surface
->iface_count
> 1)
520 /* This can happen when a complex surface is destroyed, because the
521 * 2nd surface was addref()ed when the app called
522 * GetAttachedSurface(). */
523 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
524 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
527 if (surface
->wined3d_rtv
)
528 wined3d_rendertarget_view_decref(surface
->wined3d_rtv
);
529 wined3d_texture_decref(surface
->wined3d_texture
);
532 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
536 /* Prevent the surface from being destroyed if it's still attached to
537 * another surface. It will be destroyed when the root is destroyed. */
538 if (This
->iface_count
== 1 && This
->attached_iface
)
539 IUnknown_AddRef(This
->attached_iface
);
540 iface_count
= InterlockedDecrement(&This
->iface_count
);
542 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
544 if (iface_count
== 0)
546 IUnknown
*release_iface
= This
->ifaceToRelease
;
548 /* Complex attached surfaces are destroyed implicitly when the root is released */
549 wined3d_mutex_lock();
550 if(!This
->is_complex_root
)
552 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
553 wined3d_mutex_unlock();
556 ddraw_surface_cleanup(This
);
557 wined3d_mutex_unlock();
560 IUnknown_Release(release_iface
);
566 /*****************************************************************************
567 * IDirectDrawSurface7::Release
569 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
570 * surface is destroyed.
572 * Destroying the surface is a bit tricky. For the connection between
573 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
574 * It has a nice graph explaining the connection.
576 * What happens here is basically this:
577 * When a surface is destroyed, its WineD3DSurface is released,
578 * and the refcount of the DirectDraw interface is reduced by 1. If it has
579 * complex surfaces attached to it, then these surfaces are destroyed too,
580 * regardless of their refcount. If any surface being destroyed has another
581 * surface attached to it (with a "soft" attachment, not complex), then
582 * this surface is detached with DeleteAttachedSurface.
584 * When the surface is a texture, the WineD3DTexture is released.
585 * If the surface is the Direct3D render target, then the D3D
586 * capabilities of the WineD3DDevice are uninitialized, which causes the
587 * swapchain to be released.
589 * When a complex sublevel falls to ref zero, then this is ignored.
594 *****************************************************************************/
595 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
597 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
598 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
600 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
604 ddraw_surface_release_iface(This
);
610 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
612 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
613 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
615 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
619 ddraw_surface_release_iface(This
);
625 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
627 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
628 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
630 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
634 ddraw_surface_release_iface(This
);
640 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
642 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
643 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
645 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
649 ddraw_surface_release_iface(This
);
655 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
657 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
658 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
660 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
664 ddraw_surface_release_iface(This
);
670 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
672 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
673 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
675 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
679 ddraw_surface_release_iface(This
);
685 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
687 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
689 TRACE("iface %p.\n", iface
);
691 return IUnknown_Release(surface
->texture_outer
);
694 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
696 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
698 TRACE("iface %p.\n", iface
);
700 return IUnknown_Release(surface
->texture_outer
);
703 /*****************************************************************************
704 * IDirectDrawSurface7::GetAttachedSurface
706 * Returns an attached surface with the requested caps. Surface attachment
707 * and complex surfaces are not clearly described by the MSDN or sdk,
708 * so this method is tricky and likely to contain problems.
709 * This implementation searches the complex list first, then the
712 * The chains are searched from This down to the last surface in the chain,
713 * not from the first element in the chain. The first surface found is
714 * returned. The MSDN says that this method fails if more than one surface
715 * matches the caps, but it is not sure if that is right. The attachment
716 * structure may not even allow two matching surfaces.
718 * The found surface is AddRef-ed before it is returned.
721 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
722 * Surface: Address to store the found surface
726 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
727 * DDERR_NOTFOUND if no surface was found
729 *****************************************************************************/
730 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
731 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
733 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
734 struct ddraw_surface
*surf
;
738 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
740 wined3d_mutex_lock();
742 if(This
->version
< 7)
744 /* Earlier dx apps put garbage into these members, clear them */
745 our_caps
.dwCaps
= Caps
->dwCaps
;
746 our_caps
.dwCaps2
= 0;
747 our_caps
.dwCaps3
= 0;
748 our_caps
.u1
.dwCaps4
= 0;
755 TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This
, our_caps
.dwCaps
, our_caps
.dwCaps2
, our_caps
.dwCaps3
, our_caps
.u1
.dwCaps4
); /* FIXME: Better debugging */
757 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
759 surf
= This
->complex_array
[i
];
762 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
763 surf
->surface_desc
.ddsCaps
.dwCaps
,
764 surf
->surface_desc
.ddsCaps
.dwCaps2
,
765 surf
->surface_desc
.ddsCaps
.dwCaps3
,
766 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
768 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
769 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
771 /* MSDN: "This method fails if more than one surface is attached
772 * that matches the capabilities requested."
774 * Not sure how to test this.
777 TRACE("(%p): Returning surface %p\n", This
, surf
);
778 *Surface
= &surf
->IDirectDrawSurface7_iface
;
779 ddraw_surface7_AddRef(*Surface
);
780 wined3d_mutex_unlock();
786 /* Next, look at the attachment chain */
789 while( (surf
= surf
->next_attached
) )
791 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
792 surf
->surface_desc
.ddsCaps
.dwCaps
,
793 surf
->surface_desc
.ddsCaps
.dwCaps2
,
794 surf
->surface_desc
.ddsCaps
.dwCaps3
,
795 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
797 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
798 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
800 TRACE("(%p): Returning surface %p\n", This
, surf
);
801 *Surface
= &surf
->IDirectDrawSurface7_iface
;
802 ddraw_surface7_AddRef(*Surface
);
803 wined3d_mutex_unlock();
808 TRACE("(%p) Didn't find a valid surface\n", This
);
810 wined3d_mutex_unlock();
813 return DDERR_NOTFOUND
;
816 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
817 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
819 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
820 struct ddraw_surface
*attachment_impl
;
821 IDirectDrawSurface7
*attachment7
;
824 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
826 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
833 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
834 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
835 ddraw_surface4_AddRef(*attachment
);
836 ddraw_surface7_Release(attachment7
);
841 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
842 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
844 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
845 struct ddraw_surface
*attachment_impl
;
846 IDirectDrawSurface7
*attachment7
;
850 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
852 caps2
.dwCaps
= caps
->dwCaps
;
855 caps2
.u1
.dwCaps4
= 0;
857 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
858 &caps2
, &attachment7
);
864 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
865 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
866 ddraw_surface3_AddRef(*attachment
);
867 ddraw_surface7_Release(attachment7
);
872 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
873 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
875 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
876 struct ddraw_surface
*attachment_impl
;
877 IDirectDrawSurface7
*attachment7
;
881 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
883 caps2
.dwCaps
= caps
->dwCaps
;
886 caps2
.u1
.dwCaps4
= 0;
888 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
889 &caps2
, &attachment7
);
895 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
896 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
897 ddraw_surface2_AddRef(*attachment
);
898 ddraw_surface7_Release(attachment7
);
903 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
904 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
906 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
907 struct ddraw_surface
*attachment_impl
;
908 IDirectDrawSurface7
*attachment7
;
912 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
914 caps2
.dwCaps
= caps
->dwCaps
;
917 caps2
.u1
.dwCaps4
= 0;
919 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
920 &caps2
, &attachment7
);
926 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
927 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
928 ddraw_surface1_AddRef(*attachment
);
929 ddraw_surface7_Release(attachment7
);
934 /*****************************************************************************
935 * IDirectDrawSurface7::Lock
937 * Locks the surface and returns a pointer to the surface's memory
940 * Rect: Rectangle to lock. If NULL, the whole surface is locked
941 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
942 * Flags: Locking flags, e.g Read only or write only
943 * h: An event handle that's not used and must be NULL
947 * DDERR_INVALIDPARAMS if DDSD is NULL
948 * For more details, see IWineD3DSurface::LockRect
950 *****************************************************************************/
951 static HRESULT
surface_lock(struct ddraw_surface
*surface
,
952 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
954 struct wined3d_box box
;
955 struct wined3d_map_desc map_desc
;
958 TRACE("surface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
959 surface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
961 /* surface->surface_desc.dwWidth and dwHeight are changeable, thus lock */
962 wined3d_mutex_lock();
964 /* Should I check for the handle to be NULL?
966 * The DDLOCK flags and the D3DLOCK flags are equal
967 * for the supported values. The others are ignored by WineD3D
970 /* Windows zeroes this if the rect is invalid */
971 surface_desc
->lpSurface
= NULL
;
975 if ((rect
->left
< 0) || (rect
->top
< 0)
976 || (rect
->left
> rect
->right
) || (rect
->right
> surface
->surface_desc
.dwWidth
)
977 || (rect
->top
> rect
->bottom
) || (rect
->bottom
> surface
->surface_desc
.dwHeight
))
979 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
980 wined3d_mutex_unlock();
981 return DDERR_INVALIDPARAMS
;
983 box
.left
= rect
->left
;
985 box
.right
= rect
->right
;
986 box
.bottom
= rect
->bottom
;
991 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
992 hr
= ddraw_surface_update_frontbuffer(surface
, rect
, TRUE
);
994 hr
= wined3d_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
),
995 surface
->sub_resource_idx
, &map_desc
, rect
? &box
: NULL
, flags
);
998 wined3d_mutex_unlock();
1001 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
1002 * specific error. But since IWineD3DSurface::LockRect returns that error in this
1003 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
1004 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
1005 * is much easier to do it in one place in ddraw
1007 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1012 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1014 if (flags
& DDLOCK_READONLY
)
1015 SetRectEmpty(&surface
->ddraw
->primary_lock
);
1017 surface
->ddraw
->primary_lock
= *rect
;
1019 SetRect(&surface
->ddraw
->primary_lock
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
1022 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1023 DD_STRUCT_COPY_BYSIZE(surface_desc
, &surface
->surface_desc
);
1024 surface_desc
->lpSurface
= map_desc
.data
;
1026 TRACE("locked surface returning description :\n");
1027 if (TRACE_ON(ddraw
))
1028 DDRAW_dump_surface_desc(surface_desc
);
1030 wined3d_mutex_unlock();
1035 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1036 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1038 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1040 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1041 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1043 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1044 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1045 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1047 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1048 return DDERR_INVALIDPARAMS
;
1050 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1053 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1054 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1056 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1058 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1059 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1061 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1062 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1063 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1065 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1066 return DDERR_INVALIDPARAMS
;
1068 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1071 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1072 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1074 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1075 DDSURFACEDESC2 surface_desc2
;
1078 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1079 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1081 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1082 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1083 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1085 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1086 return DDERR_INVALIDPARAMS
;
1089 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1090 surface_desc2
.dwFlags
= 0;
1091 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1092 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1093 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1097 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1098 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1101 DDSURFACEDESC2 surface_desc2
;
1104 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1105 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1107 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1108 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1109 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1111 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1112 return DDERR_INVALIDPARAMS
;
1115 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1116 surface_desc2
.dwFlags
= 0;
1117 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1118 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1119 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1123 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1124 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1126 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1127 DDSURFACEDESC2 surface_desc2
;
1129 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1130 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1132 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1133 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1134 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1136 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1137 return DDERR_INVALIDPARAMS
;
1140 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1141 surface_desc2
.dwFlags
= 0;
1142 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1143 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1144 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1148 /*****************************************************************************
1149 * IDirectDrawSurface7::Unlock
1151 * Unlocks an locked surface
1154 * Rect: Not used by this implementation
1158 * For more details, see IWineD3DSurface::UnlockRect
1160 *****************************************************************************/
1161 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1163 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1166 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1168 wined3d_mutex_lock();
1169 hr
= wined3d_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), surface
->sub_resource_idx
);
1170 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1171 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1172 wined3d_mutex_unlock();
1177 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1179 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1181 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1183 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1186 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1188 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1190 TRACE("iface %p, data %p.\n", iface
, data
);
1192 /* data might not be the LPRECT of later versions, so drop it. */
1193 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1196 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1198 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1200 TRACE("iface %p, data %p.\n", iface
, data
);
1202 /* data might not be the LPRECT of later versions, so drop it. */
1203 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1206 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1208 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1210 TRACE("iface %p, data %p.\n", iface
, data
);
1212 /* data might not be the LPRECT of later versions, so drop it. */
1213 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1216 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1217 IDirectDrawSurface7
*src
, DWORD flags
)
1219 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1220 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1221 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1222 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1223 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1224 struct wined3d_texture
*texture
;
1225 IDirectDrawSurface7
*current
;
1228 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1230 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1231 return DDERR_NOTFLIPPABLE
;
1233 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1234 return DDERR_SURFACELOST
;
1236 wined3d_mutex_lock();
1238 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1239 && !(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1241 WARN("Not in exclusive mode.\n");
1242 wined3d_mutex_unlock();
1243 return DDERR_NOEXCLUSIVEMODE
;
1246 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1247 if (dst_impl
->sub_resource_idx
)
1248 ERR("Invalid sub-resource index %u on surface %p.\n", dst_impl
->sub_resource_idx
, dst_impl
);
1249 texture
= dst_impl
->wined3d_texture
;
1250 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1251 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1255 for (current
= iface
; current
!= src
;)
1257 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1259 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1260 wined3d_mutex_unlock();
1261 return DDERR_NOTFLIPPABLE
;
1263 ddraw_surface7_Release(current
);
1264 if (current
== iface
)
1266 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1267 wined3d_mutex_unlock();
1268 return DDERR_NOTFLIPPABLE
;
1272 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1273 if (rtv
== dst_impl
->wined3d_rtv
)
1274 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1275 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1276 dst_impl
->wined3d_rtv
= src_rtv
;
1277 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1278 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1279 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1280 if (src_impl
->sub_resource_idx
)
1281 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1282 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1283 ddraw_texture
= prev_ddraw_texture
;
1287 for (current
= iface
;;)
1289 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1291 ERR("Can't find a flip target\n");
1292 wined3d_mutex_unlock();
1293 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1295 ddraw_surface7_Release(current
);
1296 if (current
== iface
)
1298 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1302 src_impl
= impl_from_IDirectDrawSurface7(current
);
1303 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1304 if (rtv
== dst_impl
->wined3d_rtv
)
1305 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1306 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1307 dst_impl
->wined3d_rtv
= src_rtv
;
1308 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1309 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1310 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1311 ddraw_texture
= prev_ddraw_texture
;
1312 if (src_impl
->sub_resource_idx
)
1313 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1314 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1315 dst_impl
= src_impl
;
1319 /* We don't have to worry about potential texture bindings, since
1320 * flippable surfaces can never be textures. */
1321 if (rtv
== src_impl
->wined3d_rtv
)
1322 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1323 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1324 src_impl
->wined3d_rtv
= tmp_rtv
;
1325 wined3d_texture_set_sub_resource_parent(texture
, 0, src_impl
);
1326 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1327 src_impl
->wined3d_texture
= texture
;
1333 FIXME("Ignoring flags %#x.\n", flags
);
1335 WARN("Ignoring flags %#x.\n", flags
);
1338 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1339 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1343 wined3d_mutex_unlock();
1348 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1349 IDirectDrawSurface4
*src
, DWORD flags
)
1351 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1352 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
1354 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1356 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1357 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1360 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1361 IDirectDrawSurface3
*src
, DWORD flags
)
1363 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1364 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src
);
1366 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1368 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1369 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1372 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1373 IDirectDrawSurface2
*src
, DWORD flags
)
1375 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1376 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src
);
1378 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1380 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1381 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1384 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1385 IDirectDrawSurface
*src
, DWORD flags
)
1387 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1388 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
1390 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1392 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1393 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1396 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1397 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1398 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1400 struct wined3d_texture
*wined3d_src_texture
;
1401 unsigned int src_sub_resource_idx
;
1402 RECT src_rect
, dst_rect
;
1403 float scale_x
, scale_y
;
1404 const RECT
*clip_rect
;
1405 UINT clip_list_size
;
1411 SetRect(&dst_rect
, 0, 0, dst_surface
->surface_desc
.dwWidth
,
1412 dst_surface
->surface_desc
.dwHeight
);
1414 dst_rect
= *dst_rect_in
;
1416 if (IsRectEmpty(&dst_rect
))
1417 return DDERR_INVALIDRECT
;
1422 SetRect(&src_rect
, 0, 0, src_surface
->surface_desc
.dwWidth
,
1423 src_surface
->surface_desc
.dwHeight
);
1425 src_rect
= *src_rect_in
;
1427 if (IsRectEmpty(&src_rect
))
1428 return DDERR_INVALIDRECT
;
1430 wined3d_src_texture
= src_surface
->wined3d_texture
;
1431 src_sub_resource_idx
= src_surface
->sub_resource_idx
;
1435 SetRectEmpty(&src_rect
);
1436 wined3d_src_texture
= NULL
;
1437 src_sub_resource_idx
= 0;
1440 if (!dst_surface
->clipper
)
1442 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1443 hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect
, TRUE
);
1445 hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
, &dst_rect
,
1446 wined3d_src_texture
, src_sub_resource_idx
, &src_rect
, flags
, fx
, filter
);
1447 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1448 hr
= ddraw_surface_update_frontbuffer(dst_surface
, &dst_rect
, FALSE
);
1453 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1454 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1456 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1457 &dst_rect
, NULL
, &clip_list_size
)))
1459 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1463 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1465 WARN("Failed to allocate clip list.\n");
1466 return E_OUTOFMEMORY
;
1469 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1470 &dst_rect
, clip_list
, &clip_list_size
)))
1472 WARN("Failed to get clip list, hr %#x.\n", hr
);
1473 HeapFree(GetProcessHeap(), 0, clip_list
);
1477 clip_rect
= (RECT
*)clip_list
->Buffer
;
1478 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1480 RECT src_rect_clipped
= src_rect
;
1484 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1485 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1486 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1487 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1489 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1491 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1496 if (FAILED(hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
,
1497 &clip_rect
[i
], wined3d_src_texture
, src_sub_resource_idx
, &src_rect_clipped
, flags
, fx
, filter
)))
1500 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1502 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1507 HeapFree(GetProcessHeap(), 0, clip_list
);
1511 /*****************************************************************************
1512 * IDirectDrawSurface7::Blt
1514 * Performs a blit on the surface
1517 * DestRect: Destination rectangle, can be NULL
1518 * SrcSurface: Source surface, can be NULL
1519 * SrcRect: Source rectangle, can be NULL
1521 * DDBltFx: Some extended blt parameters, connected to the flags
1525 * See IWineD3DSurface::Blt for more details
1527 *****************************************************************************/
1528 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*dst_rect
,
1529 IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1531 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1532 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
1533 struct wined3d_blt_fx wined3d_fx
;
1537 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1538 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1540 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1541 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1543 if ((flags
& DDBLT_KEYSRCOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYSRC
))
1545 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1546 return DDERR_INVALIDPARAMS
;
1549 if ((flags
& DDBLT_KEYDESTOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYDEST
))
1551 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1552 return DDERR_INVALIDPARAMS
;
1555 if (flags
& DDBLT_DDROPS
)
1557 FIXME("DDBLT_DDROPS not implemented.\n");
1559 FIXME(" rop %#x, pattern %p.\n", fx
->dwDDROP
, fx
->u5
.lpDDSPattern
);
1560 return DDERR_NORASTEROPHW
;
1563 wined3d_mutex_lock();
1565 if (flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1567 if (flags
& DDBLT_ROP
)
1569 wined3d_mutex_unlock();
1570 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1571 return DDERR_INVALIDPARAMS
;
1575 wined3d_mutex_unlock();
1576 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1577 return DDERR_INVALIDPARAMS
;
1581 wined3d_mutex_unlock();
1582 WARN("Depth or colorfill used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1583 return DDERR_INVALIDPARAMS
;
1586 if ((flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1587 flags
&= ~DDBLT_DEPTHFILL
;
1589 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_COLORFILL
))
1591 wined3d_mutex_unlock();
1592 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1593 return DDERR_INVALIDPARAMS
;
1595 if (!(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_DEPTHFILL
))
1597 wined3d_mutex_unlock();
1598 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1599 return DDERR_INVALIDPARAMS
;
1603 if (flags
& DDBLT_ROP
)
1607 wined3d_mutex_unlock();
1608 WARN("DDBLT_ROP used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1609 return DDERR_INVALIDPARAMS
;
1612 flags
&= ~DDBLT_ROP
;
1622 if (fx
->dwROP
== WHITENESS
)
1623 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1625 rop_fx
.u5
.dwFillColor
= 0;
1627 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1628 flags
|= DDBLT_DEPTHFILL
;
1630 flags
|= DDBLT_COLORFILL
;
1636 wined3d_mutex_unlock();
1637 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", fx
->dwROP
);
1638 return DDERR_NORASTEROPHW
;
1642 if (flags
& DDBLT_KEYSRC
&& (!src_impl
|| !(src_impl
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1644 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1645 wined3d_mutex_unlock();
1646 return DDERR_INVALIDPARAMS
;
1649 if (flags
& ~WINED3D_BLT_MASK
)
1651 wined3d_mutex_unlock();
1652 FIXME("Unhandled flags %#x.\n", flags
);
1658 wined3d_fx
.fx
= fx
->dwDDFX
;
1659 wined3d_fx
.fill_color
= fx
->u5
.dwFillColor
;
1660 wined3d_fx
.dst_color_key
.color_space_low_value
= fx
->ddckDestColorkey
.dwColorSpaceLowValue
;
1661 wined3d_fx
.dst_color_key
.color_space_high_value
= fx
->ddckDestColorkey
.dwColorSpaceHighValue
;
1662 wined3d_fx
.src_color_key
.color_space_low_value
= fx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
1663 wined3d_fx
.src_color_key
.color_space_high_value
= fx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
1666 hr
= ddraw_surface_blt_clipped(dst_impl
, dst_rect
, src_impl
,
1667 src_rect
, flags
, fx
? &wined3d_fx
: NULL
, WINED3D_TEXF_LINEAR
);
1669 wined3d_mutex_unlock();
1672 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1677 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1678 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1680 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1681 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1683 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1684 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1686 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1687 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1690 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1691 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1693 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1694 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1696 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1697 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1699 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1700 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1703 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1704 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1706 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1707 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1709 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1710 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1712 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1713 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1716 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1717 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1719 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1720 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1722 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1723 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1725 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1726 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1729 /*****************************************************************************
1730 * IDirectDrawSurface7::AddAttachedSurface
1732 * Attaches a surface to another surface. How the surface attachments work
1733 * is not totally understood yet, and this method is prone to problems.
1734 * The surface that is attached is AddRef-ed.
1736 * Tests with complex surfaces suggest that the surface attachments form a
1737 * tree, but no method to test this has been found yet.
1739 * The attachment list consists of a first surface (first_attached) and
1740 * for each surface a pointer to the next attached surface (next_attached).
1741 * For the first surface, and a surface that has no attachments
1742 * first_attached points to the surface itself. A surface that has
1743 * no successors in the chain has next_attached set to NULL.
1745 * Newly attached surfaces are attached right after the root surface.
1746 * If a surface is attached to a complex surface compound, it's attached to
1747 * the surface that the app requested, not the complex root. See
1748 * GetAttachedSurface for a description how surfaces are found.
1750 * This is how the current implementation works, and it was coded by looking
1751 * at the needs of the applications.
1753 * So far only Z-Buffer attachments are tested, and they are activated in
1754 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1755 * Back buffers should work in 2D mode, but they are not tested(They can be
1756 * attached in older iface versions). Rendering to the front buffer and
1757 * switching between that and double buffering is not yet implemented in
1758 * WineD3D, so for 3D it might have unexpected results.
1760 * ddraw_surface_attach_surface is the real thing,
1761 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1762 * performs additional checks. Version 7 of this interface is much more restrictive
1763 * than its predecessors.
1766 * Attach: Surface to attach to iface
1770 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1772 *****************************************************************************/
1773 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1775 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1778 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1780 wined3d_mutex_lock();
1782 /* Check if the surface is already attached somewhere */
1783 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1785 /* TODO: Test for the structure of the manual attachment. Is it a
1786 * chain or a list? What happens if one surface is attached to 2
1787 * different surfaces? */
1788 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1789 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1791 wined3d_mutex_unlock();
1792 return DDERR_SURFACEALREADYATTACHED
;
1795 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1796 Surf
->next_attached
= This
->next_attached
;
1797 Surf
->first_attached
= This
->first_attached
;
1798 This
->next_attached
= Surf
;
1800 /* Check if the WineD3D depth stencil needs updating */
1801 if (This
->ddraw
->d3ddevice
)
1802 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1804 wined3d_mutex_unlock();
1809 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1811 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1812 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1815 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1817 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1818 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1821 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1822 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1823 return DDERR_CANNOTATTACHSURFACE
;
1826 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1831 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1832 IUnknown_AddRef(attachment_impl
->attached_iface
);
1836 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1838 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1839 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1842 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1844 /* Tests suggest that
1845 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1846 * -> offscreen plain surfaces can be attached to primaries
1847 * -> primaries can be attached to offscreen plain surfaces
1848 * -> z buffers can be attached to primaries */
1849 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1850 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1852 /* Sizes have to match */
1853 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1854 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1856 WARN("Surface sizes do not match.\n");
1857 return DDERR_CANNOTATTACHSURFACE
;
1860 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1861 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1863 WARN("Invalid attachment combination.\n");
1864 return DDERR_CANNOTATTACHSURFACE
;
1867 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1870 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1871 IUnknown_AddRef(attachment_impl
->attached_iface
);
1875 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1877 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1878 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1881 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1883 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1884 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1887 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1888 IUnknown_AddRef(attachment_impl
->attached_iface
);
1889 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1893 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1895 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1896 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1899 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1901 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1902 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1905 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1906 IUnknown_AddRef(attachment_impl
->attached_iface
);
1907 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1911 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1913 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1914 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1917 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1919 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1920 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1923 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1924 IUnknown_AddRef(attachment_impl
->attached_iface
);
1925 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1929 /*****************************************************************************
1930 * IDirectDrawSurface7::DeleteAttachedSurface
1932 * Removes a surface from the attachment chain. The surface's refcount
1933 * is decreased by one after it has been removed
1936 * Flags: Some flags, not used by this implementation
1937 * Attach: Surface to detach
1941 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1943 *****************************************************************************/
1944 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1945 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1947 struct ddraw_surface
*prev
= surface
;
1949 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1951 wined3d_mutex_lock();
1952 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1954 wined3d_mutex_unlock();
1955 return DDERR_CANNOTDETACHSURFACE
;
1958 if (attachment
->attached_iface
!= detach_iface
)
1960 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1961 wined3d_mutex_unlock();
1962 return DDERR_SURFACENOTATTACHED
;
1965 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1966 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1968 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1969 /* FIXME: we should probably also subtract from dwMipMapCount of this
1970 * and all parent surfaces */
1973 /* Find the predecessor of the detached surface */
1974 while (prev
->next_attached
!= attachment
)
1976 if (!(prev
= prev
->next_attached
))
1978 ERR("Failed to find predecessor of %p.\n", attachment
);
1979 wined3d_mutex_unlock();
1980 return DDERR_SURFACENOTATTACHED
;
1984 /* Unchain the surface */
1985 prev
->next_attached
= attachment
->next_attached
;
1986 attachment
->next_attached
= NULL
;
1987 attachment
->first_attached
= attachment
;
1989 /* Check if the wined3d depth stencil needs updating. Note that we don't
1990 * just call d3d_device_update_depth_stencil() here since it uses
1991 * QueryInterface(). Some applications, SCP - Containment Breach in
1992 * particular, modify the QueryInterface() pointer in the surface vtbl
1993 * but don't cleanup properly after the relevant dll is unloaded. */
1994 if (attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
1995 && wined3d_device_get_depth_stencil_view(surface
->ddraw
->wined3d_device
) == surface
->wined3d_rtv
)
1996 wined3d_device_set_depth_stencil_view(surface
->ddraw
->wined3d_device
, NULL
);
1997 wined3d_mutex_unlock();
1999 /* Set attached_iface to NULL before releasing it, the surface may go
2001 attachment
->attached_iface
= NULL
;
2002 IUnknown_Release(detach_iface
);
2007 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
2008 DWORD flags
, IDirectDrawSurface7
*attachment
)
2010 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2011 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2013 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2015 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2018 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2019 DWORD flags
, IDirectDrawSurface4
*attachment
)
2021 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2022 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2024 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2026 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2029 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2030 DWORD flags
, IDirectDrawSurface3
*attachment
)
2032 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2033 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2035 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2037 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2040 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2041 DWORD flags
, IDirectDrawSurface2
*attachment
)
2043 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2044 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2046 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2048 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2051 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2052 DWORD flags
, IDirectDrawSurface
*attachment
)
2054 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2055 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2057 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2059 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2062 /*****************************************************************************
2063 * IDirectDrawSurface7::AddOverlayDirtyRect
2065 * "This method is not currently implemented"
2073 *****************************************************************************/
2074 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2076 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2078 return DDERR_UNSUPPORTED
; /* unchecked */
2081 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2083 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2085 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2087 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2090 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2092 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2094 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2096 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2099 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2101 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2103 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2105 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2108 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2110 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2112 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2114 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2117 /*****************************************************************************
2118 * IDirectDrawSurface7::GetDC
2120 * Returns a GDI device context for the surface
2123 * hdc: Address of a HDC variable to store the dc to
2127 * DDERR_INVALIDPARAMS if hdc is NULL
2128 * For details, see IWineD3DSurface::GetDC
2130 *****************************************************************************/
2131 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2133 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2136 TRACE("iface %p, dc %p.\n", iface
, dc
);
2139 return DDERR_INVALIDPARAMS
;
2141 wined3d_mutex_lock();
2143 hr
= DDERR_DCALREADYCREATED
;
2144 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2145 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2147 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, dc
);
2153 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2155 const struct ddraw_palette
*palette
;
2157 if (surface
->palette
)
2158 palette
= surface
->palette
;
2159 else if (surface
->ddraw
->primary
)
2160 palette
= surface
->ddraw
->primary
->palette
;
2165 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *dc
);
2169 wined3d_mutex_unlock();
2172 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2173 * does not touch *dc. */
2174 case WINED3DERR_INVALIDCALL
:
2176 return DDERR_CANTCREATEDC
;
2183 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2185 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2187 TRACE("iface %p, dc %p.\n", iface
, dc
);
2189 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2192 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2194 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2196 TRACE("iface %p, dc %p.\n", iface
, dc
);
2198 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2201 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2203 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2205 TRACE("iface %p, dc %p.\n", iface
, dc
);
2207 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2210 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2212 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2214 TRACE("iface %p, dc %p.\n", iface
, dc
);
2216 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2219 /*****************************************************************************
2220 * IDirectDrawSurface7::ReleaseDC
2222 * Releases the DC that was constructed with GetDC
2225 * hdc: HDC to release
2229 * For more details, see IWineD3DSurface::ReleaseDC
2231 *****************************************************************************/
2232 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2234 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2237 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2239 wined3d_mutex_lock();
2244 else if (SUCCEEDED(hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, hdc
)))
2247 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2248 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2250 wined3d_mutex_unlock();
2256 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2258 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2260 TRACE("iface %p, dc %p.\n", iface
, dc
);
2262 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2265 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2267 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2269 TRACE("iface %p, dc %p.\n", iface
, dc
);
2271 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2274 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2276 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2278 TRACE("iface %p, dc %p.\n", iface
, dc
);
2280 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2283 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2285 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2287 TRACE("iface %p, dc %p.\n", iface
, dc
);
2289 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2292 /*****************************************************************************
2293 * IDirectDrawSurface7::GetCaps
2295 * Returns the surface's caps
2298 * Caps: Address to write the caps to
2302 * DDERR_INVALIDPARAMS if Caps is NULL
2304 *****************************************************************************/
2305 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2307 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2309 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2312 return DDERR_INVALIDPARAMS
;
2314 *Caps
= surface
->surface_desc
.ddsCaps
;
2319 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2321 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2323 TRACE("iface %p, caps %p.\n", iface
, caps
);
2325 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2328 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2330 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2334 TRACE("iface %p, caps %p.\n", iface
, caps
);
2336 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2337 if (FAILED(hr
)) return hr
;
2339 caps
->dwCaps
= caps2
.dwCaps
;
2343 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2345 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2349 TRACE("iface %p, caps %p.\n", iface
, caps
);
2351 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2352 if (FAILED(hr
)) return hr
;
2354 caps
->dwCaps
= caps2
.dwCaps
;
2358 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2360 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2364 TRACE("iface %p, caps %p.\n", iface
, caps
);
2366 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2367 if (FAILED(hr
)) return hr
;
2369 caps
->dwCaps
= caps2
.dwCaps
;
2373 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2375 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2376 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2378 struct wined3d_resource
*resource
;
2380 TRACE("iface %p, priority %u.\n", iface
, priority
);
2382 wined3d_mutex_lock();
2383 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2384 * calls on such surfaces segfault on Windows. */
2385 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2387 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2388 hr
= DDERR_INVALIDPARAMS
;
2392 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2393 wined3d_resource_set_priority(resource
, priority
);
2396 wined3d_mutex_unlock();
2401 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2403 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2404 const struct wined3d_resource
*resource
;
2405 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2408 TRACE("iface %p, priority %p.\n", iface
, priority
);
2410 wined3d_mutex_lock();
2411 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2413 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2414 hr
= DDERR_INVALIDOBJECT
;
2416 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2418 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2419 hr
= DDERR_INVALIDPARAMS
;
2423 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2424 *priority
= wined3d_resource_get_priority(resource
);
2427 wined3d_mutex_unlock();
2432 /*****************************************************************************
2433 * IDirectDrawSurface7::SetPrivateData
2435 * Stores some data in the surface that is intended for the application's
2439 * tag: GUID that identifies the data
2440 * Data: Pointer to the private data
2441 * Size: Size of the private data
2446 * For more details, see IWineD3DSurface::SetPrivateData
2448 *****************************************************************************/
2449 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2450 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2452 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2455 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2456 iface
, debugstr_guid(tag
), data
, size
, flags
);
2460 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2461 return DDERR_INVALIDPARAMS
;
2464 wined3d_mutex_lock();
2465 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2466 wined3d_mutex_unlock();
2467 return hr_ddraw_from_wined3d(hr
);
2470 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2471 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2473 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2475 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2476 iface
, debugstr_guid(tag
), data
, size
, flags
);
2478 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2481 /*****************************************************************************
2482 * IDirectDrawSurface7::GetPrivateData
2484 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2487 * tag: GUID of the data to return
2488 * Data: Address where to write the data to
2489 * Size: Size of the buffer at Data
2493 * DDERR_INVALIDPARAMS if Data is NULL
2494 * For more details, see IWineD3DSurface::GetPrivateData
2496 *****************************************************************************/
2497 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2499 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2500 const struct wined3d_private_data
*stored_data
;
2503 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2504 iface
, debugstr_guid(tag
), data
, size
);
2506 wined3d_mutex_lock();
2507 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2510 hr
= DDERR_NOTFOUND
;
2515 hr
= DDERR_INVALIDPARAMS
;
2518 if (*size
< stored_data
->size
)
2520 *size
= stored_data
->size
;
2521 hr
= DDERR_MOREDATA
;
2526 hr
= DDERR_INVALIDPARAMS
;
2530 *size
= stored_data
->size
;
2531 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2535 wined3d_mutex_unlock();
2539 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2541 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2543 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2544 iface
, debugstr_guid(tag
), data
, size
);
2546 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2549 /*****************************************************************************
2550 * IDirectDrawSurface7::FreePrivateData
2552 * Frees private data stored in the surface
2555 * tag: Tag of the data to free
2559 * For more details, see IWineD3DSurface::FreePrivateData
2561 *****************************************************************************/
2562 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2564 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2565 struct wined3d_private_data
*entry
;
2567 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2569 wined3d_mutex_lock();
2570 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2573 wined3d_mutex_unlock();
2574 return DDERR_NOTFOUND
;
2577 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2578 wined3d_mutex_unlock();
2583 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2585 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2587 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2589 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2592 /*****************************************************************************
2593 * IDirectDrawSurface7::PageLock
2595 * Prevents a sysmem surface from being paged out
2598 * Flags: Not used, must be 0(unchecked)
2601 * DD_OK, because it's a stub
2603 *****************************************************************************/
2604 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2606 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2608 /* This is Windows memory management related - we don't need this */
2612 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2614 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2616 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2618 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2621 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2623 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2625 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2627 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2630 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2632 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2634 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2636 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2639 /*****************************************************************************
2640 * IDirectDrawSurface7::PageUnlock
2642 * Allows a sysmem surface to be paged out
2645 * Flags: Not used, must be 0(unchecked)
2648 * DD_OK, because it's a stub
2650 *****************************************************************************/
2651 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2653 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2658 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2660 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2662 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2664 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2667 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2669 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2671 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2673 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2676 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2678 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2680 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2682 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2685 /*****************************************************************************
2686 * IDirectDrawSurface7::BltBatch
2688 * An unimplemented function
2696 *****************************************************************************/
2697 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2699 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2701 /* MSDN: "not currently implemented" */
2702 return DDERR_UNSUPPORTED
;
2705 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2707 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2709 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2711 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2714 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2716 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2718 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2720 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2723 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2725 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2727 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2729 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2732 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2734 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2736 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2738 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2741 /*****************************************************************************
2742 * IDirectDrawSurface7::EnumAttachedSurfaces
2744 * Enumerates all surfaces attached to this surface
2747 * context: Pointer to pass unmodified to the callback
2748 * cb: Callback function to call for each surface
2752 * DDERR_INVALIDPARAMS if cb is NULL
2754 *****************************************************************************/
2755 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2756 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2758 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2759 struct ddraw_surface
*surf
;
2760 DDSURFACEDESC2 desc
;
2763 /* Attached surfaces aren't handled in WineD3D */
2764 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2767 return DDERR_INVALIDPARAMS
;
2769 wined3d_mutex_lock();
2771 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2773 surf
= surface
->complex_array
[i
];
2776 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2777 desc
= surf
->surface_desc
;
2778 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2779 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2781 wined3d_mutex_unlock();
2786 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2788 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2789 desc
= surf
->surface_desc
;
2790 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2791 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2793 wined3d_mutex_unlock();
2798 TRACE(" end of enumeration.\n");
2800 wined3d_mutex_unlock();
2805 struct callback_info2
2807 LPDDENUMSURFACESCALLBACK2 callback
;
2811 struct callback_info
2813 LPDDENUMSURFACESCALLBACK callback
;
2817 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2819 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2820 const struct callback_info2
*info
= context
;
2822 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2823 ddraw_surface7_Release(surface
);
2825 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2828 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2830 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2831 const struct callback_info
*info
= context
;
2833 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2834 ddraw_surface7_Release(surface
);
2836 /* FIXME: Check surface_test.dwSize */
2837 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2838 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2841 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2842 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2844 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2845 struct callback_info2 info
;
2847 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2849 info
.callback
= callback
;
2850 info
.context
= context
;
2852 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2853 &info
, EnumCallback2
);
2856 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2857 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2859 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2860 struct callback_info info
;
2862 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2864 info
.callback
= callback
;
2865 info
.context
= context
;
2867 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2868 &info
, EnumCallback
);
2871 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2872 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2874 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2875 struct callback_info info
;
2877 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2879 info
.callback
= callback
;
2880 info
.context
= context
;
2882 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2883 &info
, EnumCallback
);
2886 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2887 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2889 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2890 struct callback_info info
;
2892 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2894 info
.callback
= callback
;
2895 info
.context
= context
;
2897 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2898 &info
, EnumCallback
);
2901 /*****************************************************************************
2902 * IDirectDrawSurface7::EnumOverlayZOrders
2904 * "Enumerates the overlay surfaces on the specified destination"
2907 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2908 * context: context to pass back to the callback
2909 * cb: callback function to call for each enumerated surface
2912 * DD_OK, because it's a stub
2914 *****************************************************************************/
2915 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2916 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2918 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2923 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2924 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2926 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2927 struct callback_info2 info
;
2929 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2931 info
.callback
= callback
;
2932 info
.context
= context
;
2934 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2935 flags
, &info
, EnumCallback2
);
2938 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2939 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2941 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2942 struct callback_info info
;
2944 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2946 info
.callback
= callback
;
2947 info
.context
= context
;
2949 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2950 flags
, &info
, EnumCallback
);
2953 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2954 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2956 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2957 struct callback_info info
;
2959 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2961 info
.callback
= callback
;
2962 info
.context
= context
;
2964 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2965 flags
, &info
, EnumCallback
);
2968 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2969 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2971 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2972 struct callback_info info
;
2974 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2976 info
.callback
= callback
;
2977 info
.context
= context
;
2979 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2980 flags
, &info
, EnumCallback
);
2983 /*****************************************************************************
2984 * IDirectDrawSurface7::GetBltStatus
2986 * Returns the blitting status
2989 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2992 * See IWineD3DSurface::Blt
2994 *****************************************************************************/
2995 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2997 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3001 case WINEDDGBS_CANBLT
:
3002 case WINEDDGBS_ISBLTDONE
:
3006 return DDERR_INVALIDPARAMS
;
3010 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3012 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3014 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3016 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3019 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3021 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3023 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3025 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3028 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3030 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3032 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3034 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3037 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3039 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3041 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3043 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3046 /*****************************************************************************
3047 * IDirectDrawSurface7::GetColorKey
3049 * Returns the color key assigned to the surface
3053 * CKey: Address to store the key to
3057 * DDERR_INVALIDPARAMS if CKey is NULL
3059 *****************************************************************************/
3060 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3062 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3064 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3067 return DDERR_INVALIDPARAMS
;
3069 wined3d_mutex_lock();
3073 case DDCKEY_DESTBLT
:
3074 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3076 wined3d_mutex_unlock();
3077 return DDERR_NOCOLORKEY
;
3079 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3082 case DDCKEY_DESTOVERLAY
:
3083 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3085 wined3d_mutex_unlock();
3086 return DDERR_NOCOLORKEY
;
3088 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3092 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3094 wined3d_mutex_unlock();
3095 return DDERR_NOCOLORKEY
;
3097 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3100 case DDCKEY_SRCOVERLAY
:
3101 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3103 wined3d_mutex_unlock();
3104 return DDERR_NOCOLORKEY
;
3106 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3110 wined3d_mutex_unlock();
3111 return DDERR_INVALIDPARAMS
;
3114 wined3d_mutex_unlock();
3119 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3121 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3123 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3125 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3128 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3130 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3132 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3134 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3137 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3139 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3141 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3143 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3146 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3148 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3150 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3152 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3155 /*****************************************************************************
3156 * IDirectDrawSurface7::GetFlipStatus
3158 * Returns the flipping status of the surface
3161 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3164 * See IWineD3DSurface::GetFlipStatus
3166 *****************************************************************************/
3167 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3169 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3171 /* XXX: DDERR_INVALIDSURFACETYPE */
3175 case WINEDDGFS_CANFLIP
:
3176 case WINEDDGFS_ISFLIPDONE
:
3180 return DDERR_INVALIDPARAMS
;
3184 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3188 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3190 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3193 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3195 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3197 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3199 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3202 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3204 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3206 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3208 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3211 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3213 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3215 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3217 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3220 /*****************************************************************************
3221 * IDirectDrawSurface7::GetOverlayPosition
3223 * Returns the display coordinates of a visible and active overlay surface
3230 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3231 *****************************************************************************/
3232 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3234 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3237 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3239 wined3d_mutex_lock();
3240 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3241 surface
->sub_resource_idx
, x
, y
);
3242 wined3d_mutex_unlock();
3247 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3249 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3251 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3253 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3256 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3258 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3260 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3262 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3265 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3267 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3269 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3271 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3274 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3276 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3278 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3280 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3283 /*****************************************************************************
3284 * IDirectDrawSurface7::GetPixelFormat
3286 * Returns the pixel format of the Surface
3289 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3290 * format should be written
3294 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3296 *****************************************************************************/
3297 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3299 /* What is DDERR_INVALIDSURFACETYPE for here? */
3300 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3302 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3305 return DDERR_INVALIDPARAMS
;
3307 wined3d_mutex_lock();
3308 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3309 wined3d_mutex_unlock();
3314 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3316 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3318 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3320 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3323 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3325 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3327 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3329 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3332 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3334 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3336 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3338 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3341 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3343 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3345 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3347 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3350 /*****************************************************************************
3351 * IDirectDrawSurface7::GetSurfaceDesc
3353 * Returns the description of this surface
3356 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3361 * DDERR_INVALIDPARAMS if DDSD is NULL
3363 *****************************************************************************/
3364 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3366 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3368 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3371 return DDERR_INVALIDPARAMS
;
3373 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3375 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3376 return DDERR_INVALIDPARAMS
;
3379 wined3d_mutex_lock();
3380 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3381 TRACE("Returning surface desc:\n");
3382 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3383 wined3d_mutex_unlock();
3388 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3390 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3392 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3394 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3397 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3399 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3401 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3403 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3405 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3407 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3408 return DDERR_INVALIDPARAMS
;
3411 wined3d_mutex_lock();
3412 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3413 TRACE("Returning surface desc:\n");
3414 if (TRACE_ON(ddraw
))
3416 /* DDRAW_dump_surface_desc handles the smaller size */
3417 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3419 wined3d_mutex_unlock();
3424 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3426 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3428 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3430 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3433 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3435 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3437 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3439 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3442 /*****************************************************************************
3443 * IDirectDrawSurface7::Initialize
3445 * Initializes the surface. This is a no-op in Wine
3448 * DD: Pointer to an DirectDraw interface
3449 * DDSD: Surface description for initialization
3452 * DDERR_ALREADYINITIALIZED
3454 *****************************************************************************/
3455 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3456 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3458 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3460 return DDERR_ALREADYINITIALIZED
;
3463 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3464 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3466 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3468 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3470 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3471 ddraw
, surface_desc
);
3474 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3475 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3477 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3478 DDSURFACEDESC2 surface_desc2
;
3480 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3482 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3483 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3484 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3487 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3488 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3490 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3491 DDSURFACEDESC2 surface_desc2
;
3493 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3495 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3496 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3497 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3500 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3501 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3503 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3504 DDSURFACEDESC2 surface_desc2
;
3506 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3508 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3509 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3510 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3513 /*****************************************************************************
3514 * IDirect3DTexture1::Initialize
3516 * The sdk says it's not implemented
3524 *****************************************************************************/
3525 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3526 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3528 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3530 return DDERR_UNSUPPORTED
; /* Unchecked */
3533 /*****************************************************************************
3534 * IDirectDrawSurface7::IsLost
3536 * Checks if the surface is lost
3539 * DD_OK, if the surface is usable
3540 * DDERR_ISLOST if the surface is lost
3541 * See IWineD3DSurface::IsLost for more details
3543 *****************************************************************************/
3544 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3546 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3548 TRACE("iface %p.\n", iface
);
3550 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3551 return DDERR_SURFACELOST
;
3556 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3558 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3560 TRACE("iface %p.\n", iface
);
3562 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3565 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3567 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3569 TRACE("iface %p.\n", iface
);
3571 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3574 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3576 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3578 TRACE("iface %p.\n", iface
);
3580 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3583 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3585 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3587 TRACE("iface %p.\n", iface
);
3589 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3592 /*****************************************************************************
3593 * IDirectDrawSurface7::Restore
3595 * Restores a lost surface. This makes the surface usable again, but
3596 * doesn't reload its old contents
3600 * See IWineD3DSurface::Restore for more details
3602 *****************************************************************************/
3603 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3605 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3607 TRACE("iface %p.\n", iface
);
3609 ddraw_update_lost_surfaces(surface
->ddraw
);
3610 surface
->is_lost
= FALSE
;
3615 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3617 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3619 TRACE("iface %p.\n", iface
);
3621 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3624 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3626 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3628 TRACE("iface %p.\n", iface
);
3630 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3633 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3635 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3637 TRACE("iface %p.\n", iface
);
3639 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3642 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3644 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3646 TRACE("iface %p.\n", iface
);
3648 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3651 /*****************************************************************************
3652 * IDirectDrawSurface7::SetOverlayPosition
3654 * Changes the display coordinates of an overlay surface
3661 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3662 *****************************************************************************/
3663 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3665 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3668 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3670 wined3d_mutex_lock();
3671 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3672 surface
->sub_resource_idx
, x
, y
);
3673 wined3d_mutex_unlock();
3678 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3680 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3682 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3684 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3687 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3689 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3691 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3693 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3696 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3698 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3700 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3702 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3705 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3707 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3709 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3711 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3714 /*****************************************************************************
3715 * IDirectDrawSurface7::UpdateOverlay
3717 * Modifies the attributes of an overlay surface.
3720 * SrcRect: The section of the source being used for the overlay
3721 * DstSurface: Address of the surface that is overlaid
3722 * DstRect: Place of the overlay
3723 * Flags: some DDOVER_* flags
3726 * DDERR_UNSUPPORTED, because we don't support overlays
3728 *****************************************************************************/
3729 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3730 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3732 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3733 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3734 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3735 unsigned int dst_sub_resource_idx
= 0;
3738 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3739 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3742 FIXME("Ignoring fx %p.\n", fx
);
3744 wined3d_mutex_lock();
3747 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3748 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3750 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3751 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3752 wined3d_mutex_unlock();
3756 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3757 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3758 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3764 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3765 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3767 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3768 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3770 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3771 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3773 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3774 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3777 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3778 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3780 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3781 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3783 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3784 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3786 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3787 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3790 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3791 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3793 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3794 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3796 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3797 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3799 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3800 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3803 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3804 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3806 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3807 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3809 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3810 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3812 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3813 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3816 /*****************************************************************************
3817 * IDirectDrawSurface7::UpdateOverlayDisplay
3819 * The DX7 sdk says that it's not implemented
3824 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3826 *****************************************************************************/
3827 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3829 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3831 return DDERR_UNSUPPORTED
;
3834 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3836 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3838 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3840 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3843 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3845 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3847 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3849 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3852 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3854 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3856 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3858 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3861 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3863 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3865 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3867 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3870 /*****************************************************************************
3871 * IDirectDrawSurface7::UpdateOverlayZOrder
3873 * Sets an overlay's Z order
3876 * Flags: DDOVERZ_* flags
3877 * DDSRef: Defines the relative position in the overlay chain
3880 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3882 *****************************************************************************/
3883 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3884 DWORD flags
, IDirectDrawSurface7
*reference
)
3886 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3888 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
3890 wined3d_mutex_lock();
3891 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
3893 WARN("Not an overlay surface.\n");
3894 wined3d_mutex_unlock();
3895 return DDERR_NOTAOVERLAYSURFACE
;
3897 wined3d_mutex_unlock();
3902 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3903 DWORD flags
, IDirectDrawSurface4
*reference
)
3905 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3906 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3908 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3910 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3911 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3914 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3915 DWORD flags
, IDirectDrawSurface3
*reference
)
3917 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3918 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3920 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3922 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3923 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3926 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3927 DWORD flags
, IDirectDrawSurface2
*reference
)
3929 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3930 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3932 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3934 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3935 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3938 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3939 DWORD flags
, IDirectDrawSurface
*reference
)
3941 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3942 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3944 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3946 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3947 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3950 /*****************************************************************************
3951 * IDirectDrawSurface7::GetDDInterface
3953 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3954 * surface belongs to
3957 * DD: Address to write the interface pointer to
3961 * DDERR_INVALIDPARAMS if DD is NULL
3963 *****************************************************************************/
3964 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3966 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3968 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3971 return DDERR_INVALIDPARAMS
;
3973 switch(This
->version
)
3976 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3980 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3984 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3988 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3992 IUnknown_AddRef((IUnknown
*)*DD
);
3997 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3999 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4001 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4003 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4006 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
4008 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4010 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4012 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4015 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4017 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4019 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4021 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4024 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4026 TRACE("iface %p.\n", iface
);
4031 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4033 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4035 TRACE("iface %p.\n", iface
);
4037 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4040 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4042 TRACE("iface %p, value %p.\n", iface
, pValue
);
4049 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4051 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4053 TRACE("iface %p, value %p.\n", iface
, pValue
);
4055 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4058 /*****************************************************************************
4059 * IDirectDrawSurface7::SetLOD
4061 * Sets the level of detail of a texture
4064 * MaxLOD: LOD to set
4068 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4070 *****************************************************************************/
4071 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4073 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4076 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4078 wined3d_mutex_lock();
4079 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4081 wined3d_mutex_unlock();
4082 return DDERR_INVALIDOBJECT
;
4085 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4086 wined3d_mutex_unlock();
4091 /*****************************************************************************
4092 * IDirectDrawSurface7::GetLOD
4094 * Returns the level of detail of a Direct3D texture
4097 * MaxLOD: Address to write the LOD to
4101 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4102 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4104 *****************************************************************************/
4105 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4107 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4109 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4112 return DDERR_INVALIDPARAMS
;
4114 wined3d_mutex_lock();
4115 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4117 wined3d_mutex_unlock();
4118 return DDERR_INVALIDOBJECT
;
4121 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4122 wined3d_mutex_unlock();
4127 /*****************************************************************************
4128 * IDirectDrawSurface7::BltFast
4130 * Performs a fast Blit.
4133 * dstx: The x coordinate to blit to on the destination
4134 * dsty: The y coordinate to blit to on the destination
4135 * Source: The source surface
4136 * rsrc: The source rectangle
4137 * trans: Type of transfer. Some DDBLTFAST_* flags
4141 * For more details, see IWineD3DSurface::BltFast
4143 *****************************************************************************/
4144 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4145 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4147 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4148 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4149 DWORD src_w
, src_h
, dst_w
, dst_h
;
4154 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4155 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4157 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4158 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4162 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4166 src_w
= src_rect
->right
- src_rect
->left
;
4167 src_h
= src_rect
->bottom
- src_rect
->top
;
4168 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4169 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4171 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4172 return DDERR_INVALIDRECT
;
4175 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4176 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4177 flags
|= WINED3D_BLT_SRC_CKEY
;
4178 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4179 flags
|= WINED3D_BLT_DST_CKEY
;
4180 if (trans
& DDBLTFAST_WAIT
)
4181 flags
|= WINED3D_BLT_WAIT
;
4182 if (trans
& DDBLTFAST_DONOTWAIT
)
4183 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4185 wined3d_mutex_lock();
4186 if (dst_impl
->clipper
)
4188 wined3d_mutex_unlock();
4189 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4190 return DDERR_BLTFASTCANTCLIP
;
4193 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4194 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
);
4196 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
4197 src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4198 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4199 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
);
4200 wined3d_mutex_unlock();
4204 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4209 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4210 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4212 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4213 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4215 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4216 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4218 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4219 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4222 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4223 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4225 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4226 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4228 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4229 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4231 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4232 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4235 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4236 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4238 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4239 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4241 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4242 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4244 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4245 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4248 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4249 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4251 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4252 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4254 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4255 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4257 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4258 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4261 /*****************************************************************************
4262 * IDirectDrawSurface7::GetClipper
4264 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4268 * Clipper: Address to store the interface pointer at
4272 * DDERR_INVALIDPARAMS if Clipper is NULL
4273 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4275 *****************************************************************************/
4276 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4278 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4280 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4283 return DDERR_INVALIDPARAMS
;
4285 wined3d_mutex_lock();
4286 if (!surface
->clipper
)
4288 wined3d_mutex_unlock();
4289 return DDERR_NOCLIPPERATTACHED
;
4292 *Clipper
= &surface
->clipper
->IDirectDrawClipper_iface
;
4293 IDirectDrawClipper_AddRef(*Clipper
);
4294 wined3d_mutex_unlock();
4299 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4301 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4303 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4305 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4308 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4310 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4312 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4314 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4317 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4319 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4321 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4323 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4326 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4328 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4330 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4332 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4335 /*****************************************************************************
4336 * IDirectDrawSurface7::SetClipper
4338 * Sets a clipper for the surface
4341 * Clipper: IDirectDrawClipper interface of the clipper to set
4346 *****************************************************************************/
4347 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4348 IDirectDrawClipper
*iclipper
)
4350 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4351 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4352 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4355 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4357 wined3d_mutex_lock();
4358 if (clipper
== This
->clipper
)
4360 wined3d_mutex_unlock();
4364 This
->clipper
= clipper
;
4366 if (clipper
!= NULL
)
4367 IDirectDrawClipper_AddRef(iclipper
);
4369 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4371 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4375 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4380 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4381 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4385 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4386 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4390 wined3d_mutex_unlock();
4395 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4397 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4399 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4401 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4404 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4406 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4408 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4410 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4413 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4415 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4417 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4419 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4422 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4424 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4426 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4428 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4431 /*****************************************************************************
4432 * IDirectDrawSurface7::SetSurfaceDesc
4434 * Sets the surface description. It can override the pixel format, the surface
4436 * It's not really tested.
4439 * DDSD: Pointer to the new surface description to set
4444 * DDERR_INVALIDPARAMS if DDSD is NULL
4446 *****************************************************************************/
4447 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4449 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4451 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4452 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4453 enum wined3d_format_id format_id
;
4454 UINT pitch
, width
, height
;
4456 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4460 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4461 return DDERR_INVALIDPARAMS
;
4465 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4466 return DDERR_INVALIDPARAMS
;
4468 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4469 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4470 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4472 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4473 return DDERR_INVALIDSURFACETYPE
;
4476 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4477 * for PIXELFORMAT to work */
4478 if (DDSD
->dwFlags
& ~allowed_flags
)
4480 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4481 return DDERR_INVALIDPARAMS
;
4483 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4485 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4486 return DDERR_INVALIDPARAMS
;
4488 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4490 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4491 return DDERR_INVALIDCAPS
;
4493 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4495 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4497 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4498 return DDERR_INVALIDPARAMS
;
4500 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4502 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4503 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4504 return DDERR_INVALIDPARAMS
;
4506 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4507 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4508 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4509 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4510 pitch
= DDSD
->u1
.lPitch
;
4511 width
= DDSD
->dwWidth
;
4513 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4515 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4516 return DDERR_INVALIDPARAMS
;
4520 pitch
= This
->surface_desc
.u1
.lPitch
;
4521 width
= This
->surface_desc
.dwWidth
;
4524 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4526 if (!DDSD
->dwHeight
)
4528 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4529 return DDERR_INVALIDPARAMS
;
4531 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4532 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4533 height
= DDSD
->dwHeight
;
4537 height
= This
->surface_desc
.dwHeight
;
4540 wined3d_mutex_lock();
4541 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4543 enum wined3d_format_id current_format_id
;
4544 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4546 if (format_id
== WINED3DFMT_UNKNOWN
)
4548 ERR("Requested to set an unknown pixelformat\n");
4549 wined3d_mutex_unlock();
4550 return DDERR_INVALIDPARAMS
;
4552 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4553 if (format_id
!= current_format_id
)
4554 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4558 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4561 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4562 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4564 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4565 wined3d_mutex_unlock();
4566 return hr_ddraw_from_wined3d(hr
);
4569 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4570 This
->surface_desc
.dwWidth
= width
;
4571 if (DDSD
->dwFlags
& DDSD_PITCH
)
4572 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4573 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4574 This
->surface_desc
.dwHeight
= height
;
4575 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4576 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4578 wined3d_mutex_unlock();
4583 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4584 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4586 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4588 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4590 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4591 surface_desc
, flags
);
4594 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4595 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4597 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4598 DDSURFACEDESC2 surface_desc2
;
4600 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4602 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4603 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4604 surface_desc
? &surface_desc2
: NULL
, flags
);
4607 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4609 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4610 struct ddraw_palette
*palette_impl
;
4613 TRACE("iface %p, palette %p.\n", iface
, palette
);
4616 return DDERR_INVALIDPARAMS
;
4617 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4619 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4620 return DDERR_SURFACELOST
;
4623 wined3d_mutex_lock();
4624 if ((palette_impl
= surface
->palette
))
4626 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4627 IDirectDrawPalette_AddRef(*palette
);
4632 hr
= DDERR_NOPALETTEATTACHED
;
4634 wined3d_mutex_unlock();
4639 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4641 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4643 TRACE("iface %p, palette %p.\n", iface
, palette
);
4645 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4648 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4650 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4652 TRACE("iface %p, palette %p.\n", iface
, palette
);
4654 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4657 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4659 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4661 TRACE("iface %p, palette %p.\n", iface
, palette
);
4663 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4666 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4668 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4670 TRACE("iface %p, palette %p.\n", iface
, palette
);
4672 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4675 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4677 DDCOLORKEY fixed_color_key
;
4678 HRESULT hr
= WINED3D_OK
;
4680 if (flags
& DDCKEY_COLORSPACE
)
4682 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4684 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4685 return DDERR_NOCOLORKEYHW
;
4687 flags
&= ~DDCKEY_COLORSPACE
;
4690 wined3d_mutex_lock();
4694 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4695 switch (flags
& ~DDCKEY_COLORSPACE
)
4697 case DDCKEY_DESTBLT
:
4698 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4699 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4702 case DDCKEY_DESTOVERLAY
:
4703 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4704 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4707 case DDCKEY_SRCOVERLAY
:
4708 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4709 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4713 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4714 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4718 wined3d_mutex_unlock();
4719 return DDERR_INVALIDPARAMS
;
4724 switch (flags
& ~DDCKEY_COLORSPACE
)
4726 case DDCKEY_DESTBLT
:
4727 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4730 case DDCKEY_DESTOVERLAY
:
4731 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4734 case DDCKEY_SRCOVERLAY
:
4735 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4739 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4743 wined3d_mutex_unlock();
4744 return DDERR_INVALIDPARAMS
;
4748 if (surface
->is_complex_root
)
4749 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4750 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4752 wined3d_mutex_unlock();
4754 return hr_ddraw_from_wined3d(hr
);
4757 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4759 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4761 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4763 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4764 return DDERR_NOTONMIPMAPSUBLEVEL
;
4766 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4769 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4771 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4773 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4775 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4778 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4780 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4782 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4784 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4787 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4789 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4791 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4793 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4796 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4798 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4800 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4802 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4805 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4807 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4809 TRACE("iface %p, palette %p.\n", iface
, palette
);
4811 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4812 return DDERR_NOTONMIPMAPSUBLEVEL
;
4813 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4815 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4816 return DDERR_SURFACELOST
;
4819 return ddraw_surface_set_palette(surface
, palette
);
4822 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4824 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4826 TRACE("iface %p, palette %p.\n", iface
, palette
);
4828 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4830 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4831 return DDERR_SURFACELOST
;
4834 return ddraw_surface_set_palette(surface
, palette
);
4837 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4839 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4841 TRACE("iface %p, palette %p.\n", iface
, palette
);
4843 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4845 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4846 return DDERR_SURFACELOST
;
4849 return ddraw_surface_set_palette(surface
, palette
);
4852 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4854 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4856 TRACE("iface %p, palette %p.\n", iface
, palette
);
4858 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4860 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4861 return DDERR_SURFACELOST
;
4864 return ddraw_surface_set_palette(surface
, palette
);
4867 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4869 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4871 TRACE("iface %p, palette %p.\n", iface
, palette
);
4873 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4875 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4876 return DDERR_SURFACELOST
;
4879 return ddraw_surface_set_palette(surface
, palette
);
4882 /**********************************************************
4883 * IDirectDrawGammaControl::GetGammaRamp
4885 * Returns the current gamma ramp for a surface
4889 * gamma_ramp: Address to write the ramp to
4893 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4895 **********************************************************/
4896 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4897 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4899 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4901 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4905 WARN("Invalid gamma_ramp passed.\n");
4906 return DDERR_INVALIDPARAMS
;
4909 wined3d_mutex_lock();
4910 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4912 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4913 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4917 ERR("Not implemented for non-primary surfaces.\n");
4919 wined3d_mutex_unlock();
4924 /**********************************************************
4925 * IDirectDrawGammaControl::SetGammaRamp
4927 * Sets the red, green and blue gamma ramps for
4930 * flags: Can be DDSGR_CALIBRATE to request calibration
4931 * gamma_ramp: Structure containing the new gamma ramp
4935 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4937 **********************************************************/
4938 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4939 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4941 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4943 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4947 WARN("Invalid gamma_ramp passed.\n");
4948 return DDERR_INVALIDPARAMS
;
4951 wined3d_mutex_lock();
4952 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4954 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4955 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4956 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4960 ERR("Not implemented for non-primary surfaces.\n");
4962 wined3d_mutex_unlock();
4967 /*****************************************************************************
4968 * IDirect3DTexture2::PaletteChanged
4970 * Informs the texture about a palette change
4973 * start: Start index of the change
4974 * count: The number of changed entries
4977 * D3D_OK, because it's a stub
4979 *****************************************************************************/
4980 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4982 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4987 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4989 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4991 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4993 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4996 /*****************************************************************************
4997 * IDirect3DTexture::Unload
4999 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
5005 *****************************************************************************/
5006 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
5008 WARN("iface %p. Not implemented.\n", iface
);
5010 return DDERR_UNSUPPORTED
;
5013 /*****************************************************************************
5014 * IDirect3DTexture2::GetHandle
5016 * Returns handle for the texture. At the moment, the interface
5017 * to the IWineD3DTexture is used.
5020 * device: Device this handle is assigned to
5021 * handle: Address to store the handle at.
5026 *****************************************************************************/
5027 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5028 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5030 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5031 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5033 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5035 wined3d_mutex_lock();
5037 if (!surface
->Handle
)
5039 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5040 if (h
== DDRAW_INVALID_HANDLE
)
5042 ERR("Failed to allocate a texture handle.\n");
5043 wined3d_mutex_unlock();
5044 return DDERR_OUTOFMEMORY
;
5047 surface
->Handle
= h
+ 1;
5050 TRACE("Returning handle %08x.\n", surface
->Handle
);
5051 *handle
= surface
->Handle
;
5053 wined3d_mutex_unlock();
5058 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5059 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5061 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5062 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5064 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5066 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5067 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5070 /*****************************************************************************
5071 * get_sub_mimaplevel
5073 * Helper function that returns the next mipmap level
5075 * tex_ptr: Surface of which to return the next level
5077 *****************************************************************************/
5078 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5080 /* Now go down the mipmap chain to the next surface */
5081 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5082 IDirectDrawSurface7
*next_level
;
5085 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5086 if (FAILED(hr
)) return NULL
;
5088 ddraw_surface7_Release(next_level
);
5090 return impl_from_IDirectDrawSurface7(next_level
);
5093 /*****************************************************************************
5094 * IDirect3DTexture2::Load
5096 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5098 * This function isn't relayed to WineD3D because the whole interface is
5099 * implemented in DDraw only. For speed improvements an implementation which
5100 * takes OpenGL more into account could be placed into WineD3D.
5103 * src_texture: Address of the texture to load
5107 * D3DERR_TEXTURE_LOAD_FAILED.
5109 *****************************************************************************/
5110 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5112 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5113 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5114 struct wined3d_resource
*dst_resource
, *src_resource
;
5117 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5119 if (src_surface
== dst_surface
)
5121 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5125 wined3d_mutex_lock();
5127 dst_resource
= wined3d_texture_get_resource(dst_surface
->wined3d_texture
);
5128 src_resource
= wined3d_texture_get_resource(src_surface
->wined3d_texture
);
5130 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5131 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5132 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5134 ERR("Trying to load surfaces with different mip-map counts.\n");
5139 struct ddraw_palette
*dst_pal
, *src_pal
;
5140 DDSURFACEDESC
*src_desc
, *dst_desc
;
5142 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5144 /* Suppress the ALLOCONLOAD flag */
5145 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5147 /* Get the palettes */
5148 dst_pal
= dst_surface
->palette
;
5149 src_pal
= src_surface
->palette
;
5153 PALETTEENTRY palent
[256];
5157 wined3d_mutex_unlock();
5158 return DDERR_NOPALETTEATTACHED
;
5160 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5161 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5164 /* Copy one surface on the other */
5165 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5166 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5168 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5170 /* Should also check for same pixel format, u1.lPitch, ... */
5171 ERR("Error in surface sizes.\n");
5172 wined3d_mutex_unlock();
5173 return D3DERR_TEXTURE_LOAD_FAILED
;
5177 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5179 /* Copy the src blit color key if the source has one, don't erase
5180 * the destination's ckey if the source has none */
5181 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5183 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5184 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5187 if (FAILED(hr
= wined3d_resource_map(src_resource
,
5188 src_surface
->sub_resource_idx
, &src_map_desc
, NULL
, 0)))
5190 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5191 wined3d_mutex_unlock();
5192 return D3DERR_TEXTURE_LOAD_FAILED
;
5195 if (FAILED(hr
= wined3d_resource_map(dst_resource
,
5196 dst_surface
->sub_resource_idx
, &dst_map_desc
, NULL
, 0)))
5198 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5199 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5200 wined3d_mutex_unlock();
5201 return D3DERR_TEXTURE_LOAD_FAILED
;
5204 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5205 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5207 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5209 wined3d_resource_unmap(dst_resource
, dst_surface
->sub_resource_idx
);
5210 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5213 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5214 src_surface
= get_sub_mimaplevel(src_surface
);
5218 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5219 dst_surface
= get_sub_mimaplevel(dst_surface
);
5223 if (!src_surface
|| !dst_surface
)
5225 if (src_surface
!= dst_surface
)
5226 ERR("Loading surface with different mipmap structure.\n");
5231 wined3d_mutex_unlock();
5236 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5238 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5239 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5241 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5243 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5244 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5247 /*****************************************************************************
5249 *****************************************************************************/
5251 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5254 ddraw_surface7_QueryInterface
,
5255 ddraw_surface7_AddRef
,
5256 ddraw_surface7_Release
,
5257 /* IDirectDrawSurface */
5258 ddraw_surface7_AddAttachedSurface
,
5259 ddraw_surface7_AddOverlayDirtyRect
,
5261 ddraw_surface7_BltBatch
,
5262 ddraw_surface7_BltFast
,
5263 ddraw_surface7_DeleteAttachedSurface
,
5264 ddraw_surface7_EnumAttachedSurfaces
,
5265 ddraw_surface7_EnumOverlayZOrders
,
5266 ddraw_surface7_Flip
,
5267 ddraw_surface7_GetAttachedSurface
,
5268 ddraw_surface7_GetBltStatus
,
5269 ddraw_surface7_GetCaps
,
5270 ddraw_surface7_GetClipper
,
5271 ddraw_surface7_GetColorKey
,
5272 ddraw_surface7_GetDC
,
5273 ddraw_surface7_GetFlipStatus
,
5274 ddraw_surface7_GetOverlayPosition
,
5275 ddraw_surface7_GetPalette
,
5276 ddraw_surface7_GetPixelFormat
,
5277 ddraw_surface7_GetSurfaceDesc
,
5278 ddraw_surface7_Initialize
,
5279 ddraw_surface7_IsLost
,
5280 ddraw_surface7_Lock
,
5281 ddraw_surface7_ReleaseDC
,
5282 ddraw_surface7_Restore
,
5283 ddraw_surface7_SetClipper
,
5284 ddraw_surface7_SetColorKey
,
5285 ddraw_surface7_SetOverlayPosition
,
5286 ddraw_surface7_SetPalette
,
5287 ddraw_surface7_Unlock
,
5288 ddraw_surface7_UpdateOverlay
,
5289 ddraw_surface7_UpdateOverlayDisplay
,
5290 ddraw_surface7_UpdateOverlayZOrder
,
5291 /* IDirectDrawSurface2 */
5292 ddraw_surface7_GetDDInterface
,
5293 ddraw_surface7_PageLock
,
5294 ddraw_surface7_PageUnlock
,
5295 /* IDirectDrawSurface3 */
5296 ddraw_surface7_SetSurfaceDesc
,
5297 /* IDirectDrawSurface4 */
5298 ddraw_surface7_SetPrivateData
,
5299 ddraw_surface7_GetPrivateData
,
5300 ddraw_surface7_FreePrivateData
,
5301 ddraw_surface7_GetUniquenessValue
,
5302 ddraw_surface7_ChangeUniquenessValue
,
5303 /* IDirectDrawSurface7 */
5304 ddraw_surface7_SetPriority
,
5305 ddraw_surface7_GetPriority
,
5306 ddraw_surface7_SetLOD
,
5307 ddraw_surface7_GetLOD
,
5310 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5313 ddraw_surface4_QueryInterface
,
5314 ddraw_surface4_AddRef
,
5315 ddraw_surface4_Release
,
5316 /* IDirectDrawSurface */
5317 ddraw_surface4_AddAttachedSurface
,
5318 ddraw_surface4_AddOverlayDirtyRect
,
5320 ddraw_surface4_BltBatch
,
5321 ddraw_surface4_BltFast
,
5322 ddraw_surface4_DeleteAttachedSurface
,
5323 ddraw_surface4_EnumAttachedSurfaces
,
5324 ddraw_surface4_EnumOverlayZOrders
,
5325 ddraw_surface4_Flip
,
5326 ddraw_surface4_GetAttachedSurface
,
5327 ddraw_surface4_GetBltStatus
,
5328 ddraw_surface4_GetCaps
,
5329 ddraw_surface4_GetClipper
,
5330 ddraw_surface4_GetColorKey
,
5331 ddraw_surface4_GetDC
,
5332 ddraw_surface4_GetFlipStatus
,
5333 ddraw_surface4_GetOverlayPosition
,
5334 ddraw_surface4_GetPalette
,
5335 ddraw_surface4_GetPixelFormat
,
5336 ddraw_surface4_GetSurfaceDesc
,
5337 ddraw_surface4_Initialize
,
5338 ddraw_surface4_IsLost
,
5339 ddraw_surface4_Lock
,
5340 ddraw_surface4_ReleaseDC
,
5341 ddraw_surface4_Restore
,
5342 ddraw_surface4_SetClipper
,
5343 ddraw_surface4_SetColorKey
,
5344 ddraw_surface4_SetOverlayPosition
,
5345 ddraw_surface4_SetPalette
,
5346 ddraw_surface4_Unlock
,
5347 ddraw_surface4_UpdateOverlay
,
5348 ddraw_surface4_UpdateOverlayDisplay
,
5349 ddraw_surface4_UpdateOverlayZOrder
,
5350 /* IDirectDrawSurface2 */
5351 ddraw_surface4_GetDDInterface
,
5352 ddraw_surface4_PageLock
,
5353 ddraw_surface4_PageUnlock
,
5354 /* IDirectDrawSurface3 */
5355 ddraw_surface4_SetSurfaceDesc
,
5356 /* IDirectDrawSurface4 */
5357 ddraw_surface4_SetPrivateData
,
5358 ddraw_surface4_GetPrivateData
,
5359 ddraw_surface4_FreePrivateData
,
5360 ddraw_surface4_GetUniquenessValue
,
5361 ddraw_surface4_ChangeUniquenessValue
,
5364 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5367 ddraw_surface3_QueryInterface
,
5368 ddraw_surface3_AddRef
,
5369 ddraw_surface3_Release
,
5370 /* IDirectDrawSurface */
5371 ddraw_surface3_AddAttachedSurface
,
5372 ddraw_surface3_AddOverlayDirtyRect
,
5374 ddraw_surface3_BltBatch
,
5375 ddraw_surface3_BltFast
,
5376 ddraw_surface3_DeleteAttachedSurface
,
5377 ddraw_surface3_EnumAttachedSurfaces
,
5378 ddraw_surface3_EnumOverlayZOrders
,
5379 ddraw_surface3_Flip
,
5380 ddraw_surface3_GetAttachedSurface
,
5381 ddraw_surface3_GetBltStatus
,
5382 ddraw_surface3_GetCaps
,
5383 ddraw_surface3_GetClipper
,
5384 ddraw_surface3_GetColorKey
,
5385 ddraw_surface3_GetDC
,
5386 ddraw_surface3_GetFlipStatus
,
5387 ddraw_surface3_GetOverlayPosition
,
5388 ddraw_surface3_GetPalette
,
5389 ddraw_surface3_GetPixelFormat
,
5390 ddraw_surface3_GetSurfaceDesc
,
5391 ddraw_surface3_Initialize
,
5392 ddraw_surface3_IsLost
,
5393 ddraw_surface3_Lock
,
5394 ddraw_surface3_ReleaseDC
,
5395 ddraw_surface3_Restore
,
5396 ddraw_surface3_SetClipper
,
5397 ddraw_surface3_SetColorKey
,
5398 ddraw_surface3_SetOverlayPosition
,
5399 ddraw_surface3_SetPalette
,
5400 ddraw_surface3_Unlock
,
5401 ddraw_surface3_UpdateOverlay
,
5402 ddraw_surface3_UpdateOverlayDisplay
,
5403 ddraw_surface3_UpdateOverlayZOrder
,
5404 /* IDirectDrawSurface2 */
5405 ddraw_surface3_GetDDInterface
,
5406 ddraw_surface3_PageLock
,
5407 ddraw_surface3_PageUnlock
,
5408 /* IDirectDrawSurface3 */
5409 ddraw_surface3_SetSurfaceDesc
,
5412 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5415 ddraw_surface2_QueryInterface
,
5416 ddraw_surface2_AddRef
,
5417 ddraw_surface2_Release
,
5418 /* IDirectDrawSurface */
5419 ddraw_surface2_AddAttachedSurface
,
5420 ddraw_surface2_AddOverlayDirtyRect
,
5422 ddraw_surface2_BltBatch
,
5423 ddraw_surface2_BltFast
,
5424 ddraw_surface2_DeleteAttachedSurface
,
5425 ddraw_surface2_EnumAttachedSurfaces
,
5426 ddraw_surface2_EnumOverlayZOrders
,
5427 ddraw_surface2_Flip
,
5428 ddraw_surface2_GetAttachedSurface
,
5429 ddraw_surface2_GetBltStatus
,
5430 ddraw_surface2_GetCaps
,
5431 ddraw_surface2_GetClipper
,
5432 ddraw_surface2_GetColorKey
,
5433 ddraw_surface2_GetDC
,
5434 ddraw_surface2_GetFlipStatus
,
5435 ddraw_surface2_GetOverlayPosition
,
5436 ddraw_surface2_GetPalette
,
5437 ddraw_surface2_GetPixelFormat
,
5438 ddraw_surface2_GetSurfaceDesc
,
5439 ddraw_surface2_Initialize
,
5440 ddraw_surface2_IsLost
,
5441 ddraw_surface2_Lock
,
5442 ddraw_surface2_ReleaseDC
,
5443 ddraw_surface2_Restore
,
5444 ddraw_surface2_SetClipper
,
5445 ddraw_surface2_SetColorKey
,
5446 ddraw_surface2_SetOverlayPosition
,
5447 ddraw_surface2_SetPalette
,
5448 ddraw_surface2_Unlock
,
5449 ddraw_surface2_UpdateOverlay
,
5450 ddraw_surface2_UpdateOverlayDisplay
,
5451 ddraw_surface2_UpdateOverlayZOrder
,
5452 /* IDirectDrawSurface2 */
5453 ddraw_surface2_GetDDInterface
,
5454 ddraw_surface2_PageLock
,
5455 ddraw_surface2_PageUnlock
,
5458 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5461 ddraw_surface1_QueryInterface
,
5462 ddraw_surface1_AddRef
,
5463 ddraw_surface1_Release
,
5464 /* IDirectDrawSurface */
5465 ddraw_surface1_AddAttachedSurface
,
5466 ddraw_surface1_AddOverlayDirtyRect
,
5468 ddraw_surface1_BltBatch
,
5469 ddraw_surface1_BltFast
,
5470 ddraw_surface1_DeleteAttachedSurface
,
5471 ddraw_surface1_EnumAttachedSurfaces
,
5472 ddraw_surface1_EnumOverlayZOrders
,
5473 ddraw_surface1_Flip
,
5474 ddraw_surface1_GetAttachedSurface
,
5475 ddraw_surface1_GetBltStatus
,
5476 ddraw_surface1_GetCaps
,
5477 ddraw_surface1_GetClipper
,
5478 ddraw_surface1_GetColorKey
,
5479 ddraw_surface1_GetDC
,
5480 ddraw_surface1_GetFlipStatus
,
5481 ddraw_surface1_GetOverlayPosition
,
5482 ddraw_surface1_GetPalette
,
5483 ddraw_surface1_GetPixelFormat
,
5484 ddraw_surface1_GetSurfaceDesc
,
5485 ddraw_surface1_Initialize
,
5486 ddraw_surface1_IsLost
,
5487 ddraw_surface1_Lock
,
5488 ddraw_surface1_ReleaseDC
,
5489 ddraw_surface1_Restore
,
5490 ddraw_surface1_SetClipper
,
5491 ddraw_surface1_SetColorKey
,
5492 ddraw_surface1_SetOverlayPosition
,
5493 ddraw_surface1_SetPalette
,
5494 ddraw_surface1_Unlock
,
5495 ddraw_surface1_UpdateOverlay
,
5496 ddraw_surface1_UpdateOverlayDisplay
,
5497 ddraw_surface1_UpdateOverlayZOrder
,
5500 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5502 ddraw_gamma_control_QueryInterface
,
5503 ddraw_gamma_control_AddRef
,
5504 ddraw_gamma_control_Release
,
5505 ddraw_gamma_control_GetGammaRamp
,
5506 ddraw_gamma_control_SetGammaRamp
,
5509 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5511 d3d_texture2_QueryInterface
,
5512 d3d_texture2_AddRef
,
5513 d3d_texture2_Release
,
5514 d3d_texture2_GetHandle
,
5515 d3d_texture2_PaletteChanged
,
5519 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5521 d3d_texture1_QueryInterface
,
5522 d3d_texture1_AddRef
,
5523 d3d_texture1_Release
,
5524 d3d_texture1_Initialize
,
5525 d3d_texture1_GetHandle
,
5526 d3d_texture1_PaletteChanged
,
5528 d3d_texture1_Unload
,
5531 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5532 * IDirectDrawSurface interface to ddraw methods. */
5533 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5535 if (!iface
) return NULL
;
5536 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5538 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5541 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5544 IDirectDrawSurface7_Release(iface
);
5546 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5549 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5551 if (!iface
) return NULL
;
5552 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5554 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5557 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5560 IDirectDrawSurface4_Release(iface
);
5562 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5565 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5567 if (!iface
) return NULL
;
5568 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5570 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5573 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5576 IDirectDrawSurface3_Release(iface
);
5578 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5581 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5583 if (!iface
) return NULL
;
5584 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5586 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5589 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5592 IDirectDrawSurface2_Release(iface
);
5594 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5597 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5599 if (!iface
) return NULL
;
5600 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5602 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5605 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5608 IDirectDrawSurface_Release(iface
);
5610 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5613 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5615 if (!iface
) return NULL
;
5616 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5617 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5620 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5622 if (!iface
) return NULL
;
5623 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5624 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5627 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5629 struct ddraw_surface
*surface
= parent
;
5631 TRACE("surface %p.\n", surface
);
5633 /* This shouldn't happen, ddraw_surface_release_iface() should prevent the
5634 * surface from being destroyed in this case. */
5635 if (surface
->first_attached
!= surface
)
5636 ERR("Surface is still attached to surface %p.\n", surface
->first_attached
);
5638 while (surface
->next_attached
)
5639 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5640 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5641 ERR("DeleteAttachedSurface failed.\n");
5643 /* Having a texture handle set implies that the device still exists. */
5644 if (surface
->Handle
)
5645 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5647 /* Reduce the ddraw surface count. */
5648 list_remove(&surface
->surface_list_entry
);
5650 if (surface
->clipper
)
5651 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5653 if (surface
== surface
->ddraw
->primary
)
5654 surface
->ddraw
->primary
= NULL
;
5656 wined3d_private_store_cleanup(&surface
->private_store
);
5658 HeapFree(GetProcessHeap(), 0, surface
);
5661 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5663 ddraw_surface_wined3d_object_destroyed
,
5666 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5668 TRACE("parent %p.\n", parent
);
5670 HeapFree(GetProcessHeap(), 0, parent
);
5673 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5675 ddraw_texture_wined3d_object_destroyed
,
5678 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5683 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5684 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5686 struct wined3d_sub_resource_desc wined3d_mip_desc
;
5687 struct ddraw_surface
*root
, *mip
, **attach
;
5688 struct wined3d_resource_desc wined3d_desc
;
5689 struct wined3d_texture
*wined3d_texture
;
5690 struct wined3d_display_mode mode
;
5691 DDSURFACEDESC2
*desc
, *mip_desc
;
5692 struct ddraw_texture
*texture
;
5693 unsigned int layers
= 1;
5694 unsigned int pitch
= 0;
5698 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5699 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5700 if (TRACE_ON(ddraw
))
5702 TRACE("Requesting surface desc:\n");
5703 DDRAW_dump_surface_desc(surface_desc
);
5707 return CLASS_E_NOAGGREGATION
;
5712 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5713 return E_OUTOFMEMORY
;
5715 texture
->version
= version
;
5716 texture
->surface_desc
= *surface_desc
;
5717 desc
= &texture
->surface_desc
;
5719 /* Ensure DDSD_CAPS is always set. */
5720 desc
->dwFlags
|= DDSD_CAPS
;
5722 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5724 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5726 WARN("Tried to create a flippable surface without any back buffers.\n");
5727 HeapFree(GetProcessHeap(), 0, texture
);
5728 return DDERR_INVALIDCAPS
;
5731 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
))
5733 WARN("Tried to create a flippable surface without DDSCAPS_COMPLEX.\n");
5734 HeapFree(GetProcessHeap(), 0, texture
);
5735 return DDERR_INVALIDCAPS
;
5738 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5740 WARN("Tried to create a flippable cubemap.\n");
5741 HeapFree(GetProcessHeap(), 0, texture
);
5742 return DDERR_INVALIDPARAMS
;
5745 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5747 FIXME("Flippable textures not implemented.\n");
5748 HeapFree(GetProcessHeap(), 0, texture
);
5749 return DDERR_INVALIDCAPS
;
5754 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
5756 WARN("Tried to specify a back buffer count for a non-flippable surface.\n");
5757 hr
= desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
? DDERR_INVALIDPARAMS
: DDERR_INVALIDCAPS
;
5758 HeapFree(GetProcessHeap(), 0, texture
);
5763 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5765 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5767 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5768 HeapFree(GetProcessHeap(), 0, texture
);
5769 return DDERR_INVALIDCAPS
;
5772 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
))
5774 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5775 HeapFree(GetProcessHeap(), 0, texture
);
5776 return DDERR_INVALIDCAPS
;
5779 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
) && !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5781 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5782 HeapFree(GetProcessHeap(), 0, texture
);
5783 return DDERR_NOEXCLUSIVEMODE
;
5787 /* This is a special case in ddrawex, but not allowed in ddraw. */
5788 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5789 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5791 WARN("Tried to create a surface in both system and video memory.\n");
5792 HeapFree(GetProcessHeap(), 0, texture
);
5793 return DDERR_INVALIDCAPS
;
5796 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
5797 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5799 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
5800 HeapFree(GetProcessHeap(), 0, texture
);
5801 return DDERR_INVALIDCAPS
;
5804 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5805 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5807 WARN("Cube map faces requested without cube map flag.\n");
5808 HeapFree(GetProcessHeap(), 0, texture
);
5809 return DDERR_INVALIDCAPS
;
5812 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5813 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5815 WARN("Cube map without faces requested.\n");
5816 HeapFree(GetProcessHeap(), 0, texture
);
5817 return DDERR_INVALIDPARAMS
;
5820 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5821 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5822 FIXME("Partial cube maps not implemented.\n");
5824 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5826 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5828 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5829 HeapFree(GetProcessHeap(), 0, texture
);
5830 return DDERR_INVALIDCAPS
;
5832 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5834 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5835 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5836 HeapFree(GetProcessHeap(), 0, texture
);
5837 return DDERR_INVALIDCAPS
;
5841 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5843 ERR("Failed to get display mode, hr %#x.\n", hr
);
5844 HeapFree(GetProcessHeap(), 0, texture
);
5845 return hr_ddraw_from_wined3d(hr
);
5848 /* No pixelformat given? Use the current screen format. */
5849 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5851 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5852 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5853 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5856 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
5857 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5858 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5860 WARN("Unsupported / unknown pixelformat.\n");
5861 HeapFree(GetProcessHeap(), 0, texture
);
5862 return DDERR_INVALIDPIXELFORMAT
;
5865 /* No width or no height? Use the screen size. */
5866 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5868 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5870 WARN("No width / height specified.\n");
5871 HeapFree(GetProcessHeap(), 0, texture
);
5872 return DDERR_INVALIDPARAMS
;
5875 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5876 desc
->dwWidth
= mode
.width
;
5877 desc
->dwHeight
= mode
.height
;
5880 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5882 HeapFree(GetProcessHeap(), 0, texture
);
5883 return DDERR_INVALIDPARAMS
;
5886 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5887 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5889 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5891 /* The first surface is a front buffer, the back buffers are created
5893 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5894 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5896 struct wined3d_swapchain_desc swapchain_desc
;
5898 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5899 swapchain_desc
.backbuffer_width
= mode
.width
;
5900 swapchain_desc
.backbuffer_height
= mode
.height
;
5901 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5903 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5904 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5906 ERR("Failed to reset device.\n");
5907 HeapFree(GetProcessHeap(), 0, texture
);
5908 return hr_ddraw_from_wined3d(hr
);
5913 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5914 wined3d_desc
.multisample_quality
= 0;
5915 wined3d_desc
.usage
= 0;
5916 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5917 wined3d_desc
.width
= desc
->dwWidth
;
5918 wined3d_desc
.height
= desc
->dwHeight
;
5919 wined3d_desc
.depth
= 1;
5920 wined3d_desc
.size
= 0;
5922 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5924 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5925 /* Do not fail surface creation, only fail 3D device creation. */
5928 /* Mipmap count fixes */
5929 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5931 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5933 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5935 /* Mipmap count is given, should not be 0. */
5936 if (!desc
->u2
.dwMipMapCount
)
5938 HeapFree(GetProcessHeap(), 0, texture
);
5939 return DDERR_INVALIDPARAMS
;
5944 /* Undocumented feature: Create sublevels until either the
5945 * width or the height is 1. */
5947 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5949 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5954 desc
->u2
.dwMipMapCount
= 1;
5957 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5958 levels
= desc
->u2
.dwMipMapCount
;
5965 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5967 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5971 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5972 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
| WINED3DUSAGE_TEXTURE
;
5973 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5974 usage
|= WINED3DUSAGE_TEXTURE
;
5976 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5977 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5978 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5979 usage
= WINED3DUSAGE_RENDERTARGET
;
5981 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5982 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, WINED3D_RTYPE_TEXTURE_2D
, wined3d_desc
.format
)))
5983 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5985 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5987 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5989 /* Tests show surfaces without memory flags get these flags added
5990 * right after creation. */
5991 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5995 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5996 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5998 WARN("System memory overlays are not allowed.\n");
5999 HeapFree(GetProcessHeap(), 0, texture
);
6000 return DDERR_NOOVERLAYHW
;
6003 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
6005 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
6009 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6010 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
6011 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6012 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
6013 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6014 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
6016 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
6018 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
6019 /* Managed textures have the system memory flag set. */
6020 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6022 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
6024 /* Videomemory adds localvidmem. This is mutually exclusive with
6025 * systemmemory and texturemanage. */
6026 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
6027 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
6031 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6033 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
6035 WARN("User memory surfaces should be in the system memory pool.\n");
6036 HeapFree(GetProcessHeap(), 0, texture
);
6037 return DDERR_INVALIDCAPS
;
6042 WARN("User memory surfaces not supported before version 4.\n");
6043 HeapFree(GetProcessHeap(), 0, texture
);
6044 return DDERR_INVALIDPARAMS
;
6047 if (!desc
->lpSurface
)
6049 WARN("NULL surface memory pointer specified.\n");
6050 HeapFree(GetProcessHeap(), 0, texture
);
6051 return DDERR_INVALIDPARAMS
;
6054 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6056 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6058 WARN("Pitch specified on a compressed user memory surface.\n");
6059 HeapFree(GetProcessHeap(), 0, texture
);
6060 return DDERR_INVALIDPARAMS
;
6063 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6065 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6066 HeapFree(GetProcessHeap(), 0, texture
);
6067 return DDERR_INVALIDPARAMS
;
6070 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6071 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6072 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6074 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6075 HeapFree(GetProcessHeap(), 0, texture
);
6076 return DDERR_INVALIDPARAMS
;
6081 if (!(desc
->dwFlags
& DDSD_PITCH
))
6083 WARN("User memory surfaces should explicitly specify the pitch.\n");
6084 HeapFree(GetProcessHeap(), 0, texture
);
6085 return DDERR_INVALIDPARAMS
;
6088 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6089 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6091 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6092 HeapFree(GetProcessHeap(), 0, texture
);
6093 return DDERR_INVALIDPARAMS
;
6096 pitch
= desc
->u1
.lPitch
;
6100 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6101 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6102 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6103 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6104 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6105 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6106 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6107 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6109 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6110 HeapFree(GetProcessHeap(), 0, texture
);
6111 return DDERR_NOCOLORKEYHW
;
6114 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6115 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6117 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6118 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6120 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6122 wined3d_desc
.usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6126 /* Some applications assume surfaces will always be mapped at the same
6127 * address. Some of those also assume that this address is valid even when
6128 * the surface isn't mapped, and that updates done this way will be
6129 * visible on the screen. The game Nox is such an application,
6130 * Commandos: Behind Enemy Lines is another. Setting
6131 * WINED3D_TEXTURE_CREATE_GET_DC_LENIENT will ensure this. */
6132 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, layers
, levels
,
6133 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
,
6134 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6136 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6137 HeapFree(GetProcessHeap(), 0, texture
);
6138 return hr_ddraw_from_wined3d(hr
);
6141 root
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6142 wined3d_texture_decref(wined3d_texture
);
6143 root
->is_complex_root
= TRUE
;
6144 texture
->root
= root
;
6146 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6147 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6148 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6149 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6150 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6151 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6152 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6153 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6154 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6155 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6156 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6157 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6159 for (i
= 0; i
< layers
; ++i
)
6161 attach
= &root
->complex_array
[layers
- 1 - i
];
6163 for (j
= 0; j
< levels
; ++j
)
6165 mip
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, i
* levels
+ j
);
6166 mip_desc
= &mip
->surface_desc
;
6170 wined3d_texture_get_sub_resource_desc(wined3d_texture
, i
* levels
+ j
, &wined3d_mip_desc
);
6171 mip_desc
->dwWidth
= wined3d_mip_desc
.width
;
6172 mip_desc
->dwHeight
= wined3d_mip_desc
.height
;
6174 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6178 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6181 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6183 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6187 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6188 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6190 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6191 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6193 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6194 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6196 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6197 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6199 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6200 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6202 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6203 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6213 attach
= &mip
->complex_array
[0];
6217 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6218 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6219 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6221 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6225 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6227 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6228 struct ddraw_surface
*last
= root
;
6230 attach
= &last
->complex_array
[0];
6231 for (i
= 0; i
< count
; ++i
)
6233 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6239 texture
->version
= version
;
6240 texture
->surface_desc
= root
->surface_desc
;
6241 desc
= &texture
->surface_desc
;
6243 /* Only one surface in the flipping chain is a back buffer, one is
6244 * a front buffer, the others are just flippable surfaces. */
6245 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6246 | DDSCAPS_BACKBUFFER
);
6248 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6249 desc
->u5
.dwBackBufferCount
= 0;
6251 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1, 1,
6252 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
,
6253 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6255 HeapFree(GetProcessHeap(), 0, texture
);
6256 hr
= hr_ddraw_from_wined3d(hr
);
6260 last
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6261 wined3d_texture_decref(wined3d_texture
);
6262 texture
->root
= last
;
6264 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6265 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6266 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6267 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6268 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6269 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6270 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6271 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6272 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6273 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6274 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6275 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6278 attach
= &last
->complex_array
[0];
6283 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6284 ddraw
->primary
= root
;
6291 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6292 else if (version
== 4)
6293 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6295 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6300 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
6301 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
6302 const struct wined3d_parent_ops
**parent_ops
)
6304 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
6305 unsigned int texture_level
, row_pitch
, slice_pitch
;
6306 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6307 unsigned int version
= texture
->version
;
6309 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6310 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6311 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6312 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6313 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6314 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6315 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6316 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6317 surface
->iface_count
= 1;
6318 surface
->version
= version
;
6319 surface
->ddraw
= ddraw
;
6324 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6326 else if (version
== 4)
6329 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6334 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6337 *desc
= texture
->surface_desc
;
6338 surface
->first_attached
= surface
;
6340 texture_level
= desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
? sub_resource_idx
% desc
->u2
.dwMipMapCount
: 0;
6341 wined3d_texture_get_pitch(wined3d_texture
, texture_level
, &row_pitch
, &slice_pitch
);
6342 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6344 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6345 desc
->u1
.dwLinearSize
= ~0u;
6347 desc
->u1
.dwLinearSize
= slice_pitch
;
6348 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6349 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6353 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6354 desc
->u1
.lPitch
= row_pitch
;
6355 desc
->dwFlags
|= DDSD_PITCH
;
6356 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6358 desc
->lpSurface
= NULL
;
6360 wined3d_texture_incref(surface
->wined3d_texture
= wined3d_texture
);
6361 surface
->sub_resource_idx
= sub_resource_idx
;
6362 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6364 wined3d_private_store_init(&surface
->private_store
);
6367 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6369 struct ddraw_surface
*surface
= parent
;
6371 /* If the surface reference count drops to zero, we release our reference
6372 * to the view, but don't clear the pointer yet, in case e.g. a
6373 * GetRenderTarget() call brings the surface back before the view is
6374 * actually destroyed. When the view is destroyed, we need to clear the
6375 * pointer, or a subsequent surface AddRef() would reference it again.
6377 * This is safe because as long as the view still has a reference to the
6378 * texture, the surface is also still alive, and we're called before the
6379 * view releases that reference. */
6380 surface
->wined3d_rtv
= NULL
;
6383 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6385 view_wined3d_object_destroyed
,
6388 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6392 if (surface
->wined3d_rtv
)
6393 return surface
->wined3d_rtv
;
6395 if (FAILED(hr
= wined3d_rendertarget_view_create_from_sub_resource(surface
->wined3d_texture
,
6396 surface
->sub_resource_idx
, surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6398 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6402 return surface
->wined3d_rtv
;