1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "ddraw_private.h"
26 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
27 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
29 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
31 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
34 /* This is slow, of course. Also, in case of locks, we can't prevent other
35 * applications from drawing to the screen while we've locked the frontbuffer.
36 * We'd like to do this in wined3d instead, but for that to work wined3d needs
37 * to support windowless rendering first. */
38 HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
, const RECT
*rect
, BOOL read
)
40 HDC surface_dc
, screen_dc
;
48 SetRect(&r
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
54 w
= rect
->right
- rect
->left
;
55 h
= rect
->bottom
- rect
->top
;
60 if (surface
->ddraw
->swapchain_window
)
62 /* Nothing to do, we control the frontbuffer, or at least the parts we
67 return wined3d_texture_blt(surface
->ddraw
->wined3d_frontbuffer
, 0, rect
,
68 surface
->wined3d_texture
, surface
->sub_resource_idx
, rect
, 0, NULL
, WINED3D_TEXF_POINT
);
71 if (FAILED(hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, &surface_dc
)))
73 ERR("Failed to get surface DC, hr %#x.\n", hr
);
77 wined3d_palette_apply_to_dc(surface
->palette
->wineD3DPalette
, surface_dc
);
79 if (!(screen_dc
= GetDC(NULL
)))
81 wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
82 ERR("Failed to get screen DC.\n");
87 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
88 screen_dc
, x
, y
, SRCCOPY
);
90 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
91 surface_dc
, x
, y
, SRCCOPY
);
93 ReleaseDC(NULL
, screen_dc
);
94 wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
98 ERR("Failed to blit to/from screen.\n");
105 /*****************************************************************************
106 * IUnknown parts follow
107 *****************************************************************************/
109 /*****************************************************************************
110 * IDirectDrawSurface7::QueryInterface
112 * A normal QueryInterface implementation. For QueryInterface rules
113 * see ddraw.c, IDirectDraw7::QueryInterface. This method
114 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
115 * in all versions, the IDirectDrawGammaControl interface and it can
116 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
119 * riid: The interface id queried for
120 * obj: Address to write the pointer to
124 * E_NOINTERFACE if the requested interface wasn't found
126 *****************************************************************************/
127 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
129 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
131 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
133 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
137 return DDERR_INVALIDPARAMS
;
139 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
141 IDirectDrawSurface7_AddRef(iface
);
143 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
147 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
149 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
150 *obj
= &This
->IDirectDrawSurface4_iface
;
151 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
155 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
157 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
158 *obj
= &This
->IDirectDrawSurface3_iface
;
159 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
163 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
165 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
166 *obj
= &This
->IDirectDrawSurface2_iface
;
167 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
171 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
172 || IsEqualGUID(riid
, &IID_IUnknown
))
174 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
175 *obj
= &This
->IDirectDrawSurface_iface
;
176 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
180 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
182 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
183 *obj
= &This
->IDirectDrawGammaControl_iface
;
184 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
188 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
190 WARN("Color control not implemented.\n");
192 return E_NOINTERFACE
;
195 if (This
->version
!= 7)
197 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
198 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
199 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
201 wined3d_mutex_lock();
206 if (FAILED(hr
= d3d_device_create(This
->ddraw
, riid
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
207 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
209 This
->device1
= NULL
;
210 wined3d_mutex_unlock();
211 WARN("Failed to create device, hr %#x.\n", hr
);
215 wined3d_mutex_unlock();
217 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
218 *obj
= &This
->device1
->IDirect3DDevice_iface
;
222 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
224 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
225 *obj
= &This
->IDirect3DTexture2_iface
;
229 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
231 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
232 *obj
= &This
->IDirect3DTexture_iface
;
237 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
239 if (This
->version
!= 7)
242 return E_NOINTERFACE
;
245 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
247 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
249 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
251 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
254 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
256 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
258 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
260 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
263 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
265 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
267 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
269 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
272 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
274 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
276 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
278 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
281 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
282 REFIID riid
, void **object
)
284 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
286 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
288 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
291 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
293 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
295 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
297 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
300 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
302 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
304 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
306 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
309 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
311 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
312 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
314 if (iface_count
== 1)
316 if (surface
->ifaceToRelease
)
317 IUnknown_AddRef(surface
->ifaceToRelease
);
318 wined3d_mutex_lock();
319 if (surface
->wined3d_rtv
)
320 wined3d_rendertarget_view_incref(surface
->wined3d_rtv
);
321 wined3d_texture_incref(surface
->wined3d_texture
);
322 wined3d_mutex_unlock();
326 /*****************************************************************************
327 * IDirectDrawSurface7::AddRef
329 * A normal addref implementation
334 *****************************************************************************/
335 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
337 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
338 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
340 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
344 ddraw_surface_add_iface(This
);
350 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
352 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
353 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
355 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
359 ddraw_surface_add_iface(This
);
365 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
367 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
368 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
370 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
374 ddraw_surface_add_iface(This
);
380 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
382 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
383 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
385 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
389 ddraw_surface_add_iface(This
);
395 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
397 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
398 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
400 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
404 ddraw_surface_add_iface(This
);
410 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
412 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
413 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
415 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
419 ddraw_surface_add_iface(This
);
425 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
427 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
429 TRACE("iface %p.\n", iface
);
431 return IUnknown_AddRef(surface
->texture_outer
);
434 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
436 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
438 TRACE("iface %p.\n", iface
);
440 return IUnknown_AddRef(surface
->texture_outer
);
443 static HRESULT
ddraw_surface_set_palette(struct ddraw_surface
*surface
, IDirectDrawPalette
*palette
)
445 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(palette
);
446 struct ddraw_palette
*prev
;
448 TRACE("iface %p, palette %p.\n", surface
, palette
);
450 if (palette_impl
&& palette_impl
->flags
& DDPCAPS_ALPHA
451 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
453 WARN("Alpha palette set on non-texture surface, returning DDERR_INVALIDSURFACETYPE.\n");
454 return DDERR_INVALIDSURFACETYPE
;
457 if (!format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
458 return DDERR_INVALIDPIXELFORMAT
;
460 wined3d_mutex_lock();
462 prev
= surface
->palette
;
463 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
466 prev
->flags
&= ~DDPCAPS_PRIMARYSURFACE
;
468 palette_impl
->flags
|= DDPCAPS_PRIMARYSURFACE
;
469 wined3d_swapchain_set_palette(surface
->ddraw
->wined3d_swapchain
,
470 palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
471 ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
474 IDirectDrawPalette_AddRef(&palette_impl
->IDirectDrawPalette_iface
);
476 IDirectDrawPalette_Release(&prev
->IDirectDrawPalette_iface
);
477 surface
->palette
= palette_impl
;
479 wined3d_mutex_unlock();
484 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
486 struct ddraw_surface
*surf
;
489 TRACE("surface %p.\n", surface
);
491 /* The refcount test shows that the palette is detached when the surface
493 ddraw_surface_set_palette(surface
, NULL
);
495 /* Loop through all complex attached surfaces and destroy them.
497 * Yet again, only the root can have more than one complexly attached
498 * surface, all the others have a total of one. */
499 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
501 if (!surface
->complex_array
[i
])
504 surf
= surface
->complex_array
[i
];
505 surface
->complex_array
[i
] = NULL
;
506 if (!surf
->is_complex_root
)
507 ddraw_surface_cleanup(surf
);
510 if (surface
->device1
)
511 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
513 if (surface
->iface_count
> 1)
515 /* This can happen when a complex surface is destroyed, because the
516 * 2nd surface was addref()ed when the app called
517 * GetAttachedSurface(). */
518 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
519 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
522 if (surface
->wined3d_rtv
)
523 wined3d_rendertarget_view_decref(surface
->wined3d_rtv
);
524 wined3d_texture_decref(surface
->wined3d_texture
);
527 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
529 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
530 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
532 if (iface_count
== 0)
534 IUnknown
*release_iface
= This
->ifaceToRelease
;
536 /* Complex attached surfaces are destroyed implicitly when the root is released */
537 wined3d_mutex_lock();
538 if(!This
->is_complex_root
)
540 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
541 wined3d_mutex_unlock();
544 ddraw_surface_cleanup(This
);
545 wined3d_mutex_unlock();
548 IUnknown_Release(release_iface
);
554 /*****************************************************************************
555 * IDirectDrawSurface7::Release
557 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
558 * surface is destroyed.
560 * Destroying the surface is a bit tricky. For the connection between
561 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
562 * It has a nice graph explaining the connection.
564 * What happens here is basically this:
565 * When a surface is destroyed, its WineD3DSurface is released,
566 * and the refcount of the DirectDraw interface is reduced by 1. If it has
567 * complex surfaces attached to it, then these surfaces are destroyed too,
568 * regardless of their refcount. If any surface being destroyed has another
569 * surface attached to it (with a "soft" attachment, not complex), then
570 * this surface is detached with DeleteAttachedSurface.
572 * When the surface is a texture, the WineD3DTexture is released.
573 * If the surface is the Direct3D render target, then the D3D
574 * capabilities of the WineD3DDevice are uninitialized, which causes the
575 * swapchain to be released.
577 * When a complex sublevel falls to ref zero, then this is ignored.
582 *****************************************************************************/
583 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
585 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
586 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
588 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
592 ddraw_surface_release_iface(This
);
598 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
600 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
601 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
603 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
607 ddraw_surface_release_iface(This
);
613 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
615 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
616 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
618 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
622 ddraw_surface_release_iface(This
);
628 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
630 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
631 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
633 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
637 ddraw_surface_release_iface(This
);
643 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
645 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
646 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
648 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
652 ddraw_surface_release_iface(This
);
658 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
660 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
661 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
663 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
667 ddraw_surface_release_iface(This
);
673 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
675 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
677 TRACE("iface %p.\n", iface
);
679 return IUnknown_Release(surface
->texture_outer
);
682 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
684 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
686 TRACE("iface %p.\n", iface
);
688 return IUnknown_Release(surface
->texture_outer
);
691 /*****************************************************************************
692 * IDirectDrawSurface7::GetAttachedSurface
694 * Returns an attached surface with the requested caps. Surface attachment
695 * and complex surfaces are not clearly described by the MSDN or sdk,
696 * so this method is tricky and likely to contain problems.
697 * This implementation searches the complex list first, then the
700 * The chains are searched from This down to the last surface in the chain,
701 * not from the first element in the chain. The first surface found is
702 * returned. The MSDN says that this method fails if more than one surface
703 * matches the caps, but it is not sure if that is right. The attachment
704 * structure may not even allow two matching surfaces.
706 * The found surface is AddRef-ed before it is returned.
709 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
710 * Surface: Address to store the found surface
714 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
715 * DDERR_NOTFOUND if no surface was found
717 *****************************************************************************/
718 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
719 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
721 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
722 struct ddraw_surface
*surf
;
726 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
728 wined3d_mutex_lock();
730 if(This
->version
< 7)
732 /* Earlier dx apps put garbage into these members, clear them */
733 our_caps
.dwCaps
= Caps
->dwCaps
;
734 our_caps
.dwCaps2
= 0;
735 our_caps
.dwCaps3
= 0;
736 our_caps
.u1
.dwCaps4
= 0;
743 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 */
745 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
747 surf
= This
->complex_array
[i
];
750 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
751 surf
->surface_desc
.ddsCaps
.dwCaps
,
752 surf
->surface_desc
.ddsCaps
.dwCaps2
,
753 surf
->surface_desc
.ddsCaps
.dwCaps3
,
754 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
756 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
757 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
759 /* MSDN: "This method fails if more than one surface is attached
760 * that matches the capabilities requested."
762 * Not sure how to test this.
765 TRACE("(%p): Returning surface %p\n", This
, surf
);
766 *Surface
= &surf
->IDirectDrawSurface7_iface
;
767 ddraw_surface7_AddRef(*Surface
);
768 wined3d_mutex_unlock();
774 /* Next, look at the attachment chain */
777 while( (surf
= surf
->next_attached
) )
779 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
780 surf
->surface_desc
.ddsCaps
.dwCaps
,
781 surf
->surface_desc
.ddsCaps
.dwCaps2
,
782 surf
->surface_desc
.ddsCaps
.dwCaps3
,
783 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
785 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
786 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
788 TRACE("(%p): Returning surface %p\n", This
, surf
);
789 *Surface
= &surf
->IDirectDrawSurface7_iface
;
790 ddraw_surface7_AddRef(*Surface
);
791 wined3d_mutex_unlock();
796 TRACE("(%p) Didn't find a valid surface\n", This
);
798 wined3d_mutex_unlock();
801 return DDERR_NOTFOUND
;
804 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
805 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
807 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
808 struct ddraw_surface
*attachment_impl
;
809 IDirectDrawSurface7
*attachment7
;
812 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
814 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
821 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
822 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
823 ddraw_surface4_AddRef(*attachment
);
824 ddraw_surface7_Release(attachment7
);
829 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
830 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
832 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
833 struct ddraw_surface
*attachment_impl
;
834 IDirectDrawSurface7
*attachment7
;
838 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
840 caps2
.dwCaps
= caps
->dwCaps
;
843 caps2
.u1
.dwCaps4
= 0;
845 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
846 &caps2
, &attachment7
);
852 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
853 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
854 ddraw_surface3_AddRef(*attachment
);
855 ddraw_surface7_Release(attachment7
);
860 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
861 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
863 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
864 struct ddraw_surface
*attachment_impl
;
865 IDirectDrawSurface7
*attachment7
;
869 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
871 caps2
.dwCaps
= caps
->dwCaps
;
874 caps2
.u1
.dwCaps4
= 0;
876 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
877 &caps2
, &attachment7
);
883 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
884 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
885 ddraw_surface2_AddRef(*attachment
);
886 ddraw_surface7_Release(attachment7
);
891 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
892 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
895 struct ddraw_surface
*attachment_impl
;
896 IDirectDrawSurface7
*attachment7
;
900 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
902 caps2
.dwCaps
= caps
->dwCaps
;
905 caps2
.u1
.dwCaps4
= 0;
907 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
908 &caps2
, &attachment7
);
914 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
915 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
916 ddraw_surface1_AddRef(*attachment
);
917 ddraw_surface7_Release(attachment7
);
922 /*****************************************************************************
923 * IDirectDrawSurface7::Lock
925 * Locks the surface and returns a pointer to the surface's memory
928 * Rect: Rectangle to lock. If NULL, the whole surface is locked
929 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
930 * Flags: Locking flags, e.g Read only or write only
931 * h: An event handle that's not used and must be NULL
935 * DDERR_INVALIDPARAMS if DDSD is NULL
936 * For more details, see IWineD3DSurface::LockRect
938 *****************************************************************************/
939 static HRESULT
surface_lock(struct ddraw_surface
*surface
,
940 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
942 struct wined3d_box box
;
943 struct wined3d_map_desc map_desc
;
946 TRACE("surface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
947 surface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
949 /* surface->surface_desc.dwWidth and dwHeight are changeable, thus lock */
950 wined3d_mutex_lock();
952 /* Should I check for the handle to be NULL?
954 * The DDLOCK flags and the D3DLOCK flags are equal
955 * for the supported values. The others are ignored by WineD3D
958 /* Windows zeroes this if the rect is invalid */
959 surface_desc
->lpSurface
= NULL
;
963 if ((rect
->left
< 0) || (rect
->top
< 0)
964 || (rect
->left
> rect
->right
) || (rect
->right
> surface
->surface_desc
.dwWidth
)
965 || (rect
->top
> rect
->bottom
) || (rect
->bottom
> surface
->surface_desc
.dwHeight
))
967 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
968 wined3d_mutex_unlock();
969 return DDERR_INVALIDPARAMS
;
971 box
.left
= rect
->left
;
973 box
.right
= rect
->right
;
974 box
.bottom
= rect
->bottom
;
979 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
980 hr
= ddraw_surface_update_frontbuffer(surface
, rect
, TRUE
);
982 hr
= wined3d_resource_sub_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
),
983 surface
->sub_resource_idx
, &map_desc
, rect
? &box
: NULL
, flags
);
986 wined3d_mutex_unlock();
989 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
990 * specific error. But since IWineD3DSurface::LockRect returns that error in this
991 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
992 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
993 * is much easier to do it in one place in ddraw
995 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1000 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1002 if (flags
& DDLOCK_READONLY
)
1003 memset(&surface
->ddraw
->primary_lock
, 0, sizeof(surface
->ddraw
->primary_lock
));
1005 surface
->ddraw
->primary_lock
= *rect
;
1007 SetRect(&surface
->ddraw
->primary_lock
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
1010 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1011 DD_STRUCT_COPY_BYSIZE(surface_desc
, &surface
->surface_desc
);
1012 surface_desc
->lpSurface
= map_desc
.data
;
1014 TRACE("locked surface returning description :\n");
1015 if (TRACE_ON(ddraw
))
1016 DDRAW_dump_surface_desc(surface_desc
);
1018 wined3d_mutex_unlock();
1023 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1024 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1026 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1028 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1029 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1031 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1032 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1033 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1035 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1036 return DDERR_INVALIDPARAMS
;
1038 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1041 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1042 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1044 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1046 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1047 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1049 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1050 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1051 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1053 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1054 return DDERR_INVALIDPARAMS
;
1056 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1059 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1060 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1063 DDSURFACEDESC2 surface_desc2
;
1066 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1067 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1069 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1070 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1071 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1073 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1074 return DDERR_INVALIDPARAMS
;
1077 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1078 surface_desc2
.dwFlags
= 0;
1079 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1080 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1081 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1085 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1086 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1088 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1089 DDSURFACEDESC2 surface_desc2
;
1092 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1093 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1095 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1096 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1097 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1099 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1100 return DDERR_INVALIDPARAMS
;
1103 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1104 surface_desc2
.dwFlags
= 0;
1105 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1106 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1107 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1111 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1112 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1114 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1115 DDSURFACEDESC2 surface_desc2
;
1117 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1118 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1120 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1121 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1122 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1124 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1125 return DDERR_INVALIDPARAMS
;
1128 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1129 surface_desc2
.dwFlags
= 0;
1130 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1131 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1132 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1136 /*****************************************************************************
1137 * IDirectDrawSurface7::Unlock
1139 * Unlocks an locked surface
1142 * Rect: Not used by this implementation
1146 * For more details, see IWineD3DSurface::UnlockRect
1148 *****************************************************************************/
1149 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1151 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1154 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1156 wined3d_mutex_lock();
1157 hr
= wined3d_resource_sub_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), surface
->sub_resource_idx
);
1158 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1159 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1160 wined3d_mutex_unlock();
1165 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1167 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1169 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1171 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1174 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1176 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1178 TRACE("iface %p, data %p.\n", iface
, data
);
1180 /* data might not be the LPRECT of later versions, so drop it. */
1181 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1184 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1188 TRACE("iface %p, data %p.\n", iface
, data
);
1190 /* data might not be the LPRECT of later versions, so drop it. */
1191 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1194 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1196 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1198 TRACE("iface %p, data %p.\n", iface
, data
);
1200 /* data might not be the LPRECT of later versions, so drop it. */
1201 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1204 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1205 IDirectDrawSurface7
*src
, DWORD flags
)
1207 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1208 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1209 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1210 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1211 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1212 struct wined3d_texture
*texture
;
1213 IDirectDrawSurface7
*current
;
1216 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1218 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1219 return DDERR_NOTFLIPPABLE
;
1221 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1222 return DDERR_SURFACELOST
;
1224 wined3d_mutex_lock();
1226 if (!(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1228 WARN("Not in exclusive mode.\n");
1229 wined3d_mutex_unlock();
1230 return DDERR_NOEXCLUSIVEMODE
;
1233 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1234 if (dst_impl
->sub_resource_idx
)
1235 ERR("Invalid sub-resource index %u on surface %p.\n", dst_impl
->sub_resource_idx
, dst_impl
);
1236 texture
= dst_impl
->wined3d_texture
;
1237 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1238 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1242 for (current
= iface
; current
!= src
;)
1244 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1246 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1247 wined3d_mutex_unlock();
1248 return DDERR_NOTFLIPPABLE
;
1250 ddraw_surface7_Release(current
);
1251 if (current
== iface
)
1253 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1254 wined3d_mutex_unlock();
1255 return DDERR_NOTFLIPPABLE
;
1259 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1260 if (rtv
== dst_impl
->wined3d_rtv
)
1261 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1262 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1263 dst_impl
->wined3d_rtv
= src_rtv
;
1264 wined3d_resource_set_parent(wined3d_texture_get_sub_resource(src_impl
->wined3d_texture
, 0), dst_impl
);
1265 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1266 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1267 if (src_impl
->sub_resource_idx
)
1268 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1269 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1270 ddraw_texture
= prev_ddraw_texture
;
1274 for (current
= iface
;;)
1276 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1278 ERR("Can't find a flip target\n");
1279 wined3d_mutex_unlock();
1280 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1282 ddraw_surface7_Release(current
);
1283 if (current
== iface
)
1285 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1289 src_impl
= impl_from_IDirectDrawSurface7(current
);
1290 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1291 if (rtv
== dst_impl
->wined3d_rtv
)
1292 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1293 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1294 dst_impl
->wined3d_rtv
= src_rtv
;
1295 wined3d_resource_set_parent(wined3d_texture_get_sub_resource(src_impl
->wined3d_texture
, 0), dst_impl
);
1296 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1297 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1298 ddraw_texture
= prev_ddraw_texture
;
1299 if (src_impl
->sub_resource_idx
)
1300 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1301 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1302 dst_impl
= src_impl
;
1306 /* We don't have to worry about potential texture bindings, since
1307 * flippable surfaces can never be textures. */
1308 if (rtv
== src_impl
->wined3d_rtv
)
1309 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1310 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1311 src_impl
->wined3d_rtv
= tmp_rtv
;
1312 wined3d_resource_set_parent(wined3d_texture_get_sub_resource(texture
, 0), src_impl
);
1313 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1314 src_impl
->wined3d_texture
= texture
;
1320 FIXME("Ignoring flags %#x.\n", flags
);
1322 WARN("Ignoring flags %#x.\n", flags
);
1325 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1326 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1330 wined3d_mutex_unlock();
1335 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1336 IDirectDrawSurface4
*dst
, DWORD flags
)
1338 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1339 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1341 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1343 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1344 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1347 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1348 IDirectDrawSurface3
*dst
, DWORD flags
)
1350 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1351 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1353 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1355 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1356 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1359 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1360 IDirectDrawSurface2
*dst
, DWORD flags
)
1362 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1363 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1365 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1367 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1368 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1371 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1372 IDirectDrawSurface
*dst
, DWORD flags
)
1374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1375 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1377 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1379 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1380 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1383 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1384 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1385 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1387 struct wined3d_texture
*wined3d_src_texture
;
1388 unsigned int src_sub_resource_idx
;
1389 RECT src_rect
, dst_rect
;
1390 float scale_x
, scale_y
;
1391 const RECT
*clip_rect
;
1392 UINT clip_list_size
;
1401 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1402 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1406 dst_rect
= *dst_rect_in
;
1409 if (IsRectEmpty(&dst_rect
))
1410 return DDERR_INVALIDRECT
;
1418 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1419 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1423 src_rect
= *src_rect_in
;
1426 if (IsRectEmpty(&src_rect
))
1427 return DDERR_INVALIDRECT
;
1429 wined3d_src_texture
= src_surface
->wined3d_texture
;
1430 src_sub_resource_idx
= src_surface
->sub_resource_idx
;
1434 SetRect(&src_rect
, 0, 0, 0, 0);
1435 wined3d_src_texture
= NULL
;
1436 src_sub_resource_idx
= 0;
1439 if (!dst_surface
->clipper
)
1441 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1442 hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect
, TRUE
);
1444 hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
, &dst_rect
,
1445 wined3d_src_texture
, src_sub_resource_idx
, &src_rect
, flags
, fx
, filter
);
1446 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1447 hr
= ddraw_surface_update_frontbuffer(dst_surface
, &dst_rect
, FALSE
);
1452 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1453 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1455 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1456 &dst_rect
, NULL
, &clip_list_size
)))
1458 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1462 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1464 WARN("Failed to allocate clip list.\n");
1465 return E_OUTOFMEMORY
;
1468 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1469 &dst_rect
, clip_list
, &clip_list_size
)))
1471 WARN("Failed to get clip list, hr %#x.\n", hr
);
1472 HeapFree(GetProcessHeap(), 0, clip_list
);
1476 clip_rect
= (RECT
*)clip_list
->Buffer
;
1477 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1479 RECT src_rect_clipped
= src_rect
;
1483 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1484 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1485 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1486 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1488 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1490 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1495 if (FAILED(hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
,
1496 &clip_rect
[i
], wined3d_src_texture
, src_sub_resource_idx
, &src_rect_clipped
, flags
, fx
, filter
)))
1499 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1501 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1506 HeapFree(GetProcessHeap(), 0, clip_list
);
1510 /*****************************************************************************
1511 * IDirectDrawSurface7::Blt
1513 * Performs a blit on the surface
1516 * DestRect: Destination rectangle, can be NULL
1517 * SrcSurface: Source surface, can be NULL
1518 * SrcRect: Source rectangle, can be NULL
1520 * DDBltFx: Some extended blt parameters, connected to the flags
1524 * See IWineD3DSurface::Blt for more details
1526 *****************************************************************************/
1527 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*dst_rect
,
1528 IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1530 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1531 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
1532 struct wined3d_blt_fx wined3d_fx
;
1536 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1537 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1539 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1540 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1542 if ((flags
& DDBLT_KEYSRCOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYSRC
))
1544 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1545 return DDERR_INVALIDPARAMS
;
1548 if ((flags
& DDBLT_KEYDESTOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYDEST
))
1550 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1551 return DDERR_INVALIDPARAMS
;
1554 if (flags
& DDBLT_DDROPS
)
1556 FIXME("DDBLT_DDROPS not implemented.\n");
1558 FIXME(" rop %#x, pattern %p.\n", fx
->dwDDROP
, fx
->u5
.lpDDSPattern
);
1559 return DDERR_NORASTEROPHW
;
1562 wined3d_mutex_lock();
1564 if (flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1566 if (flags
& DDBLT_ROP
)
1568 wined3d_mutex_unlock();
1569 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1570 return DDERR_INVALIDPARAMS
;
1574 wined3d_mutex_unlock();
1575 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1576 return DDERR_INVALIDPARAMS
;
1580 wined3d_mutex_unlock();
1581 WARN("Depth or colorfill used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1582 return DDERR_INVALIDPARAMS
;
1585 if ((flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1586 flags
&= ~DDBLT_DEPTHFILL
;
1588 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_COLORFILL
))
1590 wined3d_mutex_unlock();
1591 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1592 return DDERR_INVALIDPARAMS
;
1594 if (!(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_DEPTHFILL
))
1596 wined3d_mutex_unlock();
1597 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1598 return DDERR_INVALIDPARAMS
;
1602 if (flags
& DDBLT_ROP
)
1606 wined3d_mutex_unlock();
1607 WARN("DDBLT_ROP used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1608 return DDERR_INVALIDPARAMS
;
1611 flags
&= ~DDBLT_ROP
;
1621 if (fx
->dwROP
== WHITENESS
)
1622 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1624 rop_fx
.u5
.dwFillColor
= 0;
1626 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1627 flags
|= DDBLT_DEPTHFILL
;
1629 flags
|= DDBLT_COLORFILL
;
1635 wined3d_mutex_unlock();
1636 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", fx
->dwROP
);
1637 return DDERR_NORASTEROPHW
;
1641 if (flags
& DDBLT_KEYSRC
&& (!src_impl
|| !(src_impl
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1643 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1644 wined3d_mutex_unlock();
1645 return DDERR_INVALIDPARAMS
;
1648 if (flags
& ~WINED3D_BLT_MASK
)
1650 wined3d_mutex_unlock();
1651 FIXME("Unhandled flags %#x.\n", flags
);
1657 wined3d_fx
.fx
= fx
->dwDDFX
;
1658 wined3d_fx
.fill_color
= fx
->u5
.dwFillColor
;
1659 wined3d_fx
.dst_color_key
.color_space_low_value
= fx
->ddckDestColorkey
.dwColorSpaceLowValue
;
1660 wined3d_fx
.dst_color_key
.color_space_high_value
= fx
->ddckDestColorkey
.dwColorSpaceHighValue
;
1661 wined3d_fx
.src_color_key
.color_space_low_value
= fx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
1662 wined3d_fx
.src_color_key
.color_space_high_value
= fx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
1665 hr
= ddraw_surface_blt_clipped(dst_impl
, dst_rect
, src_impl
,
1666 src_rect
, flags
, fx
? &wined3d_fx
: NULL
, WINED3D_TEXF_LINEAR
);
1668 wined3d_mutex_unlock();
1671 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1676 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1677 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1679 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1680 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1682 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1683 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1685 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1686 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1689 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1690 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1692 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1693 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1695 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1696 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1698 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1699 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1702 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1703 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1705 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1706 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1708 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1709 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1711 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1712 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1715 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1716 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1718 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1719 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1721 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1722 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1724 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1725 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1728 /*****************************************************************************
1729 * IDirectDrawSurface7::AddAttachedSurface
1731 * Attaches a surface to another surface. How the surface attachments work
1732 * is not totally understood yet, and this method is prone to problems.
1733 * The surface that is attached is AddRef-ed.
1735 * Tests with complex surfaces suggest that the surface attachments form a
1736 * tree, but no method to test this has been found yet.
1738 * The attachment list consists of a first surface (first_attached) and
1739 * for each surface a pointer to the next attached surface (next_attached).
1740 * For the first surface, and a surface that has no attachments
1741 * first_attached points to the surface itself. A surface that has
1742 * no successors in the chain has next_attached set to NULL.
1744 * Newly attached surfaces are attached right after the root surface.
1745 * If a surface is attached to a complex surface compound, it's attached to
1746 * the surface that the app requested, not the complex root. See
1747 * GetAttachedSurface for a description how surfaces are found.
1749 * This is how the current implementation works, and it was coded by looking
1750 * at the needs of the applications.
1752 * So far only Z-Buffer attachments are tested, and they are activated in
1753 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1754 * Back buffers should work in 2D mode, but they are not tested(They can be
1755 * attached in older iface versions). Rendering to the front buffer and
1756 * switching between that and double buffering is not yet implemented in
1757 * WineD3D, so for 3D it might have unexpected results.
1759 * ddraw_surface_attach_surface is the real thing,
1760 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1761 * performs additional checks. Version 7 of this interface is much more restrictive
1762 * than its predecessors.
1765 * Attach: Surface to attach to iface
1769 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1771 *****************************************************************************/
1772 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1774 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1777 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1779 wined3d_mutex_lock();
1781 /* Check if the surface is already attached somewhere */
1782 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1784 /* TODO: Test for the structure of the manual attachment. Is it a
1785 * chain or a list? What happens if one surface is attached to 2
1786 * different surfaces? */
1787 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1788 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1790 wined3d_mutex_unlock();
1791 return DDERR_SURFACEALREADYATTACHED
;
1794 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1795 Surf
->next_attached
= This
->next_attached
;
1796 Surf
->first_attached
= This
->first_attached
;
1797 This
->next_attached
= Surf
;
1799 /* Check if the WineD3D depth stencil needs updating */
1800 if (This
->ddraw
->d3ddevice
)
1801 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1803 wined3d_mutex_unlock();
1808 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1810 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1811 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1814 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1816 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1817 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1820 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1821 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1822 return DDERR_CANNOTATTACHSURFACE
;
1825 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1830 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1831 IUnknown_AddRef(attachment_impl
->attached_iface
);
1835 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1837 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1838 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1841 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1843 /* Tests suggest that
1844 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1845 * -> offscreen plain surfaces can be attached to primaries
1846 * -> primaries can be attached to offscreen plain surfaces
1847 * -> z buffers can be attached to primaries */
1848 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1849 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1851 /* Sizes have to match */
1852 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1853 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1855 WARN("Surface sizes do not match.\n");
1856 return DDERR_CANNOTATTACHSURFACE
;
1859 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1860 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1862 WARN("Invalid attachment combination.\n");
1863 return DDERR_CANNOTATTACHSURFACE
;
1866 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1869 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1870 IUnknown_AddRef(attachment_impl
->attached_iface
);
1874 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1876 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1877 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1880 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1882 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1883 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1886 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1887 IUnknown_AddRef(attachment_impl
->attached_iface
);
1888 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1892 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1895 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1898 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1900 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1901 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1904 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1905 IUnknown_AddRef(attachment_impl
->attached_iface
);
1906 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1910 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1912 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1913 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1916 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1918 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1919 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1922 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1923 IUnknown_AddRef(attachment_impl
->attached_iface
);
1924 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1928 /*****************************************************************************
1929 * IDirectDrawSurface7::DeleteAttachedSurface
1931 * Removes a surface from the attachment chain. The surface's refcount
1932 * is decreased by one after it has been removed
1935 * Flags: Some flags, not used by this implementation
1936 * Attach: Surface to detach
1940 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1942 *****************************************************************************/
1943 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1944 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1946 struct ddraw_surface
*prev
= surface
;
1948 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1950 wined3d_mutex_lock();
1951 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1953 wined3d_mutex_unlock();
1954 return DDERR_CANNOTDETACHSURFACE
;
1957 if (attachment
->attached_iface
!= detach_iface
)
1959 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1960 wined3d_mutex_unlock();
1961 return DDERR_SURFACENOTATTACHED
;
1964 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1965 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1967 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1968 /* FIXME: we should probably also subtract from dwMipMapCount of this
1969 * and all parent surfaces */
1972 /* Find the predecessor of the detached surface */
1975 if (prev
->next_attached
== attachment
)
1977 prev
= prev
->next_attached
;
1980 /* There must be a surface, otherwise there's a bug */
1983 /* Unchain the surface */
1984 prev
->next_attached
= attachment
->next_attached
;
1985 attachment
->next_attached
= NULL
;
1986 attachment
->first_attached
= attachment
;
1988 /* Check if the wined3d depth stencil needs updating. */
1989 if (surface
->ddraw
->d3ddevice
)
1990 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1991 wined3d_mutex_unlock();
1993 /* Set attached_iface to NULL before releasing it, the surface may go
1995 attachment
->attached_iface
= NULL
;
1996 IUnknown_Release(detach_iface
);
2001 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
2002 DWORD flags
, IDirectDrawSurface7
*attachment
)
2004 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2005 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2007 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2009 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2012 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2013 DWORD flags
, IDirectDrawSurface4
*attachment
)
2015 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2016 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2018 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2020 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2023 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2024 DWORD flags
, IDirectDrawSurface3
*attachment
)
2026 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2027 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2029 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2031 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2034 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2035 DWORD flags
, IDirectDrawSurface2
*attachment
)
2037 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2038 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2040 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2042 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2045 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2046 DWORD flags
, IDirectDrawSurface
*attachment
)
2048 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2049 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2051 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2053 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2056 /*****************************************************************************
2057 * IDirectDrawSurface7::AddOverlayDirtyRect
2059 * "This method is not currently implemented"
2067 *****************************************************************************/
2068 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2070 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2072 return DDERR_UNSUPPORTED
; /* unchecked */
2075 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2077 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2079 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2081 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2084 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2086 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2088 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2090 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2093 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2095 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2097 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2099 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2102 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2104 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2106 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2108 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2111 /*****************************************************************************
2112 * IDirectDrawSurface7::GetDC
2114 * Returns a GDI device context for the surface
2117 * hdc: Address of a HDC variable to store the dc to
2121 * DDERR_INVALIDPARAMS if hdc is NULL
2122 * For details, see IWineD3DSurface::GetDC
2124 *****************************************************************************/
2125 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2127 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2130 TRACE("iface %p, dc %p.\n", iface
, dc
);
2133 return DDERR_INVALIDPARAMS
;
2135 wined3d_mutex_lock();
2136 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2137 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2139 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, dc
);
2145 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2147 const struct ddraw_palette
*palette
;
2149 if (surface
->palette
)
2150 palette
= surface
->palette
;
2151 else if (surface
->ddraw
->primary
)
2152 palette
= surface
->ddraw
->primary
->palette
;
2157 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *dc
);
2161 wined3d_mutex_unlock();
2164 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2165 * does not touch *dc. */
2166 case WINED3DERR_INVALIDCALL
:
2168 return DDERR_INVALIDPARAMS
;
2175 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2177 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2179 TRACE("iface %p, dc %p.\n", iface
, dc
);
2181 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2184 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2188 TRACE("iface %p, dc %p.\n", iface
, dc
);
2190 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2193 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2195 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2197 TRACE("iface %p, dc %p.\n", iface
, dc
);
2199 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2202 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2204 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2206 TRACE("iface %p, dc %p.\n", iface
, dc
);
2208 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2211 /*****************************************************************************
2212 * IDirectDrawSurface7::ReleaseDC
2214 * Releases the DC that was constructed with GetDC
2217 * hdc: HDC to release
2221 * For more details, see IWineD3DSurface::ReleaseDC
2223 *****************************************************************************/
2224 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2226 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2229 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2231 wined3d_mutex_lock();
2232 if (SUCCEEDED(hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, hdc
)))
2235 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2236 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2238 wined3d_mutex_unlock();
2244 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2246 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2248 TRACE("iface %p, dc %p.\n", iface
, dc
);
2250 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2253 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2255 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2257 TRACE("iface %p, dc %p.\n", iface
, dc
);
2259 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2262 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2264 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2266 TRACE("iface %p, dc %p.\n", iface
, dc
);
2268 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2271 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2273 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2275 TRACE("iface %p, dc %p.\n", iface
, dc
);
2277 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2280 /*****************************************************************************
2281 * IDirectDrawSurface7::GetCaps
2283 * Returns the surface's caps
2286 * Caps: Address to write the caps to
2290 * DDERR_INVALIDPARAMS if Caps is NULL
2292 *****************************************************************************/
2293 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2295 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2297 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2300 return DDERR_INVALIDPARAMS
;
2302 *Caps
= surface
->surface_desc
.ddsCaps
;
2307 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2309 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2311 TRACE("iface %p, caps %p.\n", iface
, caps
);
2313 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2316 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2318 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2322 TRACE("iface %p, caps %p.\n", iface
, caps
);
2324 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2325 if (FAILED(hr
)) return hr
;
2327 caps
->dwCaps
= caps2
.dwCaps
;
2331 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2333 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2337 TRACE("iface %p, caps %p.\n", iface
, caps
);
2339 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2340 if (FAILED(hr
)) return hr
;
2342 caps
->dwCaps
= caps2
.dwCaps
;
2346 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2348 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2352 TRACE("iface %p, caps %p.\n", iface
, caps
);
2354 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2355 if (FAILED(hr
)) return hr
;
2357 caps
->dwCaps
= caps2
.dwCaps
;
2361 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2363 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2364 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2366 struct wined3d_resource
*resource
;
2368 TRACE("iface %p, priority %u.\n", iface
, priority
);
2370 wined3d_mutex_lock();
2371 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2372 * calls on such surfaces segfault on Windows. */
2373 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2375 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2376 hr
= DDERR_INVALIDPARAMS
;
2380 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2381 wined3d_resource_set_priority(resource
, priority
);
2384 wined3d_mutex_unlock();
2389 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2391 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2392 const struct wined3d_resource
*resource
;
2393 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2396 TRACE("iface %p, priority %p.\n", iface
, priority
);
2398 wined3d_mutex_lock();
2399 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2401 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2402 hr
= DDERR_INVALIDOBJECT
;
2404 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2406 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2407 hr
= DDERR_INVALIDPARAMS
;
2411 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2412 *priority
= wined3d_resource_get_priority(resource
);
2415 wined3d_mutex_unlock();
2420 /*****************************************************************************
2421 * IDirectDrawSurface7::SetPrivateData
2423 * Stores some data in the surface that is intended for the application's
2427 * tag: GUID that identifies the data
2428 * Data: Pointer to the private data
2429 * Size: Size of the private data
2434 * For more details, see IWineD3DSurface::SetPrivateData
2436 *****************************************************************************/
2437 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2438 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2440 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2443 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2444 iface
, debugstr_guid(tag
), data
, size
, flags
);
2448 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2449 return DDERR_INVALIDPARAMS
;
2452 wined3d_mutex_lock();
2453 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2454 wined3d_mutex_unlock();
2455 return hr_ddraw_from_wined3d(hr
);
2458 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2459 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2461 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2463 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2464 iface
, debugstr_guid(tag
), data
, size
, flags
);
2466 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2469 /*****************************************************************************
2470 * IDirectDrawSurface7::GetPrivateData
2472 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2475 * tag: GUID of the data to return
2476 * Data: Address where to write the data to
2477 * Size: Size of the buffer at Data
2481 * DDERR_INVALIDPARAMS if Data is NULL
2482 * For more details, see IWineD3DSurface::GetPrivateData
2484 *****************************************************************************/
2485 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2487 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2488 const struct wined3d_private_data
*stored_data
;
2491 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2492 iface
, debugstr_guid(tag
), data
, size
);
2494 wined3d_mutex_lock();
2495 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2498 hr
= DDERR_NOTFOUND
;
2503 hr
= DDERR_INVALIDPARAMS
;
2506 if (*size
< stored_data
->size
)
2508 *size
= stored_data
->size
;
2509 hr
= DDERR_MOREDATA
;
2514 hr
= DDERR_INVALIDPARAMS
;
2518 *size
= stored_data
->size
;
2519 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2523 wined3d_mutex_unlock();
2527 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2529 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2531 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2532 iface
, debugstr_guid(tag
), data
, size
);
2534 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2537 /*****************************************************************************
2538 * IDirectDrawSurface7::FreePrivateData
2540 * Frees private data stored in the surface
2543 * tag: Tag of the data to free
2547 * For more details, see IWineD3DSurface::FreePrivateData
2549 *****************************************************************************/
2550 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2552 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2553 struct wined3d_private_data
*entry
;
2555 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2557 wined3d_mutex_lock();
2558 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2561 wined3d_mutex_unlock();
2562 return DDERR_NOTFOUND
;
2565 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2566 wined3d_mutex_unlock();
2571 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2573 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2575 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2577 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2580 /*****************************************************************************
2581 * IDirectDrawSurface7::PageLock
2583 * Prevents a sysmem surface from being paged out
2586 * Flags: Not used, must be 0(unchecked)
2589 * DD_OK, because it's a stub
2591 *****************************************************************************/
2592 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2594 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2596 /* This is Windows memory management related - we don't need this */
2600 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2602 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2604 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2606 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2609 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2611 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2613 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2615 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2618 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2620 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2622 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2624 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2627 /*****************************************************************************
2628 * IDirectDrawSurface7::PageUnlock
2630 * Allows a sysmem surface to be paged out
2633 * Flags: Not used, must be 0(unchecked)
2636 * DD_OK, because it's a stub
2638 *****************************************************************************/
2639 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2641 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2646 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2648 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2650 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2652 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2655 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2657 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2659 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2661 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2664 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2666 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2668 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2670 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2673 /*****************************************************************************
2674 * IDirectDrawSurface7::BltBatch
2676 * An unimplemented function
2684 *****************************************************************************/
2685 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2687 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2689 /* MSDN: "not currently implemented" */
2690 return DDERR_UNSUPPORTED
;
2693 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2695 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2697 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2699 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2702 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2704 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2706 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2708 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2711 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2713 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2715 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2717 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2720 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2722 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2724 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2726 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2729 /*****************************************************************************
2730 * IDirectDrawSurface7::EnumAttachedSurfaces
2732 * Enumerates all surfaces attached to this surface
2735 * context: Pointer to pass unmodified to the callback
2736 * cb: Callback function to call for each surface
2740 * DDERR_INVALIDPARAMS if cb is NULL
2742 *****************************************************************************/
2743 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2744 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2746 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2747 struct ddraw_surface
*surf
;
2748 DDSURFACEDESC2 desc
;
2751 /* Attached surfaces aren't handled in WineD3D */
2752 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2755 return DDERR_INVALIDPARAMS
;
2757 wined3d_mutex_lock();
2759 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2761 surf
= surface
->complex_array
[i
];
2764 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2765 desc
= surf
->surface_desc
;
2766 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2767 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2769 wined3d_mutex_unlock();
2774 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
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 TRACE(" end of enumeration.\n");
2788 wined3d_mutex_unlock();
2793 struct callback_info2
2795 LPDDENUMSURFACESCALLBACK2 callback
;
2799 struct callback_info
2801 LPDDENUMSURFACESCALLBACK callback
;
2805 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2807 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2808 const struct callback_info2
*info
= context
;
2810 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2811 ddraw_surface7_Release(surface
);
2813 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2816 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2818 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2819 const struct callback_info
*info
= context
;
2821 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2822 ddraw_surface7_Release(surface
);
2824 /* FIXME: Check surface_test.dwSize */
2825 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2826 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2829 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2830 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2832 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2833 struct callback_info2 info
;
2835 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2837 info
.callback
= callback
;
2838 info
.context
= context
;
2840 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2841 &info
, EnumCallback2
);
2844 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2845 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2847 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2848 struct callback_info info
;
2850 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2852 info
.callback
= callback
;
2853 info
.context
= context
;
2855 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2856 &info
, EnumCallback
);
2859 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2860 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2862 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2863 struct callback_info info
;
2865 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2867 info
.callback
= callback
;
2868 info
.context
= context
;
2870 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2871 &info
, EnumCallback
);
2874 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2875 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2877 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2878 struct callback_info info
;
2880 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2882 info
.callback
= callback
;
2883 info
.context
= context
;
2885 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2886 &info
, EnumCallback
);
2889 /*****************************************************************************
2890 * IDirectDrawSurface7::EnumOverlayZOrders
2892 * "Enumerates the overlay surfaces on the specified destination"
2895 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2896 * context: context to pass back to the callback
2897 * cb: callback function to call for each enumerated surface
2900 * DD_OK, because it's a stub
2902 *****************************************************************************/
2903 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2904 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2906 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2911 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2912 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2914 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2915 struct callback_info2 info
;
2917 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2919 info
.callback
= callback
;
2920 info
.context
= context
;
2922 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2923 flags
, &info
, EnumCallback2
);
2926 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2927 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2929 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2930 struct callback_info info
;
2932 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2934 info
.callback
= callback
;
2935 info
.context
= context
;
2937 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2938 flags
, &info
, EnumCallback
);
2941 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2942 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2944 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2945 struct callback_info info
;
2947 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2949 info
.callback
= callback
;
2950 info
.context
= context
;
2952 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2953 flags
, &info
, EnumCallback
);
2956 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2957 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2959 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2960 struct callback_info info
;
2962 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2964 info
.callback
= callback
;
2965 info
.context
= context
;
2967 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2968 flags
, &info
, EnumCallback
);
2971 /*****************************************************************************
2972 * IDirectDrawSurface7::GetBltStatus
2974 * Returns the blitting status
2977 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2980 * See IWineD3DSurface::Blt
2982 *****************************************************************************/
2983 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2985 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2989 case WINEDDGBS_CANBLT
:
2990 case WINEDDGBS_ISBLTDONE
:
2994 return DDERR_INVALIDPARAMS
;
2998 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3000 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3002 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3004 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3007 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3009 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3011 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3013 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3016 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3018 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3020 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3022 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3025 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3027 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3029 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3031 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3034 /*****************************************************************************
3035 * IDirectDrawSurface7::GetColorKey
3037 * Returns the color key assigned to the surface
3041 * CKey: Address to store the key to
3045 * DDERR_INVALIDPARAMS if CKey is NULL
3047 *****************************************************************************/
3048 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3050 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3052 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3055 return DDERR_INVALIDPARAMS
;
3057 wined3d_mutex_lock();
3061 case DDCKEY_DESTBLT
:
3062 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3064 wined3d_mutex_unlock();
3065 return DDERR_NOCOLORKEY
;
3067 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3070 case DDCKEY_DESTOVERLAY
:
3071 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3073 wined3d_mutex_unlock();
3074 return DDERR_NOCOLORKEY
;
3076 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3080 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3082 wined3d_mutex_unlock();
3083 return DDERR_NOCOLORKEY
;
3085 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3088 case DDCKEY_SRCOVERLAY
:
3089 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3091 wined3d_mutex_unlock();
3092 return DDERR_NOCOLORKEY
;
3094 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3098 wined3d_mutex_unlock();
3099 return DDERR_INVALIDPARAMS
;
3102 wined3d_mutex_unlock();
3107 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3109 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3111 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3113 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3116 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3118 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3120 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3122 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3125 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3127 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3129 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3131 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3134 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3136 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3138 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3140 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3143 /*****************************************************************************
3144 * IDirectDrawSurface7::GetFlipStatus
3146 * Returns the flipping status of the surface
3149 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3152 * See IWineD3DSurface::GetFlipStatus
3154 *****************************************************************************/
3155 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3157 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3159 /* XXX: DDERR_INVALIDSURFACETYPE */
3163 case WINEDDGFS_CANFLIP
:
3164 case WINEDDGFS_ISFLIPDONE
:
3168 return DDERR_INVALIDPARAMS
;
3172 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3174 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3176 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3178 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3181 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3183 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3185 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3187 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3190 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3192 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3194 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3196 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3199 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3201 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3203 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3205 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3208 /*****************************************************************************
3209 * IDirectDrawSurface7::GetOverlayPosition
3211 * Returns the display coordinates of a visible and active overlay surface
3218 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3219 *****************************************************************************/
3220 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3222 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3225 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3227 wined3d_mutex_lock();
3228 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3229 surface
->sub_resource_idx
, x
, y
);
3230 wined3d_mutex_unlock();
3235 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3237 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3239 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3241 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3244 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3246 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3248 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3250 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3253 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3255 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3257 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3259 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3262 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3264 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3266 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3268 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3271 /*****************************************************************************
3272 * IDirectDrawSurface7::GetPixelFormat
3274 * Returns the pixel format of the Surface
3277 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3278 * format should be written
3282 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3284 *****************************************************************************/
3285 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3287 /* What is DDERR_INVALIDSURFACETYPE for here? */
3288 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3290 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3293 return DDERR_INVALIDPARAMS
;
3295 wined3d_mutex_lock();
3296 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3297 wined3d_mutex_unlock();
3302 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3304 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3306 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3308 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3311 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3313 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3315 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3317 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3320 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3322 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3324 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3326 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3329 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3331 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3333 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3335 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3338 /*****************************************************************************
3339 * IDirectDrawSurface7::GetSurfaceDesc
3341 * Returns the description of this surface
3344 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3349 * DDERR_INVALIDPARAMS if DDSD is NULL
3351 *****************************************************************************/
3352 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3354 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3356 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3359 return DDERR_INVALIDPARAMS
;
3361 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3363 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3364 return DDERR_INVALIDPARAMS
;
3367 wined3d_mutex_lock();
3368 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3369 TRACE("Returning surface desc:\n");
3370 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3371 wined3d_mutex_unlock();
3376 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3378 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3380 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3382 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3385 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3387 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3389 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3391 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3393 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3395 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3396 return DDERR_INVALIDPARAMS
;
3399 wined3d_mutex_lock();
3400 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3401 TRACE("Returning surface desc:\n");
3402 if (TRACE_ON(ddraw
))
3404 /* DDRAW_dump_surface_desc handles the smaller size */
3405 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3407 wined3d_mutex_unlock();
3412 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3414 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3416 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3418 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3421 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3423 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3425 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3427 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3430 /*****************************************************************************
3431 * IDirectDrawSurface7::Initialize
3433 * Initializes the surface. This is a no-op in Wine
3436 * DD: Pointer to an DirectDraw interface
3437 * DDSD: Surface description for initialization
3440 * DDERR_ALREADYINITIALIZED
3442 *****************************************************************************/
3443 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3444 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3446 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3448 return DDERR_ALREADYINITIALIZED
;
3451 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3452 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3454 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3456 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3458 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3459 ddraw
, surface_desc
);
3462 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3463 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3465 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3466 DDSURFACEDESC2 surface_desc2
;
3468 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3470 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3471 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3472 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3475 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3476 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3478 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3479 DDSURFACEDESC2 surface_desc2
;
3481 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3483 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3484 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3485 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3488 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3489 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3491 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3492 DDSURFACEDESC2 surface_desc2
;
3494 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3496 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3497 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3498 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3501 /*****************************************************************************
3502 * IDirect3DTexture1::Initialize
3504 * The sdk says it's not implemented
3512 *****************************************************************************/
3513 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3514 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3516 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3518 return DDERR_UNSUPPORTED
; /* Unchecked */
3521 /*****************************************************************************
3522 * IDirectDrawSurface7::IsLost
3524 * Checks if the surface is lost
3527 * DD_OK, if the surface is usable
3528 * DDERR_ISLOST if the surface is lost
3529 * See IWineD3DSurface::IsLost for more details
3531 *****************************************************************************/
3532 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3534 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3536 TRACE("iface %p.\n", iface
);
3538 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3539 return DDERR_SURFACELOST
;
3544 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3546 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3548 TRACE("iface %p.\n", iface
);
3550 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3553 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3555 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3557 TRACE("iface %p.\n", iface
);
3559 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3562 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3564 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3566 TRACE("iface %p.\n", iface
);
3568 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3571 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3573 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3575 TRACE("iface %p.\n", iface
);
3577 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3580 /*****************************************************************************
3581 * IDirectDrawSurface7::Restore
3583 * Restores a lost surface. This makes the surface usable again, but
3584 * doesn't reload its old contents
3588 * See IWineD3DSurface::Restore for more details
3590 *****************************************************************************/
3591 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3593 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3595 TRACE("iface %p.\n", iface
);
3597 ddraw_update_lost_surfaces(surface
->ddraw
);
3598 surface
->is_lost
= FALSE
;
3603 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3605 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3607 TRACE("iface %p.\n", iface
);
3609 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3612 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3614 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3616 TRACE("iface %p.\n", iface
);
3618 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3621 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3623 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3625 TRACE("iface %p.\n", iface
);
3627 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3630 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3632 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3634 TRACE("iface %p.\n", iface
);
3636 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3639 /*****************************************************************************
3640 * IDirectDrawSurface7::SetOverlayPosition
3642 * Changes the display coordinates of an overlay surface
3649 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3650 *****************************************************************************/
3651 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3653 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3656 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3658 wined3d_mutex_lock();
3659 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3660 surface
->sub_resource_idx
, x
, y
);
3661 wined3d_mutex_unlock();
3666 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3668 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3670 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3672 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3675 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3677 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3679 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3681 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3684 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3686 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3688 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3690 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3693 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3695 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3697 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3699 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3702 /*****************************************************************************
3703 * IDirectDrawSurface7::UpdateOverlay
3705 * Modifies the attributes of an overlay surface.
3708 * SrcRect: The section of the source being used for the overlay
3709 * DstSurface: Address of the surface that is overlaid
3710 * DstRect: Place of the overlay
3711 * Flags: some DDOVER_* flags
3714 * DDERR_UNSUPPORTED, because we don't support overlays
3716 *****************************************************************************/
3717 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3718 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3720 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3721 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3722 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3723 unsigned int dst_sub_resource_idx
= 0;
3726 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3727 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3730 FIXME("Ignoring fx %p.\n", fx
);
3732 wined3d_mutex_lock();
3735 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3736 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3738 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3739 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3740 wined3d_mutex_unlock();
3744 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3745 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3746 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3752 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3753 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3755 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3756 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3758 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3759 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3761 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3762 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3765 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3766 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3768 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3769 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3771 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3772 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3774 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3775 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3778 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3779 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3781 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3782 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3784 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3785 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3787 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3788 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3791 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3792 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3794 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3795 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3797 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3798 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3800 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3801 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3804 /*****************************************************************************
3805 * IDirectDrawSurface7::UpdateOverlayDisplay
3807 * The DX7 sdk says that it's not implemented
3812 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3814 *****************************************************************************/
3815 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3817 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3819 return DDERR_UNSUPPORTED
;
3822 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3824 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3826 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3828 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3831 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3833 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3835 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3837 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3840 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3842 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3844 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3846 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3849 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3851 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3853 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3855 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3858 /*****************************************************************************
3859 * IDirectDrawSurface7::UpdateOverlayZOrder
3861 * Sets an overlay's Z order
3864 * Flags: DDOVERZ_* flags
3865 * DDSRef: Defines the relative position in the overlay chain
3868 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3870 *****************************************************************************/
3871 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3872 DWORD flags
, IDirectDrawSurface7
*reference
)
3874 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3876 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
3878 wined3d_mutex_lock();
3879 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
3881 WARN("Not an overlay surface.\n");
3882 wined3d_mutex_unlock();
3883 return DDERR_NOTAOVERLAYSURFACE
;
3885 wined3d_mutex_unlock();
3890 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3891 DWORD flags
, IDirectDrawSurface4
*reference
)
3893 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3894 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3896 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3898 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3899 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3902 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3903 DWORD flags
, IDirectDrawSurface3
*reference
)
3905 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3906 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(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_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3915 DWORD flags
, IDirectDrawSurface2
*reference
)
3917 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3918 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(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_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3927 DWORD flags
, IDirectDrawSurface
*reference
)
3929 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3930 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(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 /*****************************************************************************
3939 * IDirectDrawSurface7::GetDDInterface
3941 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3942 * surface belongs to
3945 * DD: Address to write the interface pointer to
3949 * DDERR_INVALIDPARAMS if DD is NULL
3951 *****************************************************************************/
3952 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3954 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3956 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3959 return DDERR_INVALIDPARAMS
;
3961 switch(This
->version
)
3964 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3968 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3972 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3976 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3980 IUnknown_AddRef((IUnknown
*)*DD
);
3985 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3987 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3989 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3991 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3994 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3996 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3998 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4000 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4003 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4005 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4007 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4009 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4012 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4014 TRACE("iface %p.\n", iface
);
4019 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4021 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4023 TRACE("iface %p.\n", iface
);
4025 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4028 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4030 TRACE("iface %p, value %p.\n", iface
, pValue
);
4037 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4039 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4041 TRACE("iface %p, value %p.\n", iface
, pValue
);
4043 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4046 /*****************************************************************************
4047 * IDirectDrawSurface7::SetLOD
4049 * Sets the level of detail of a texture
4052 * MaxLOD: LOD to set
4056 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4058 *****************************************************************************/
4059 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4061 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4064 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4066 wined3d_mutex_lock();
4067 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4069 wined3d_mutex_unlock();
4070 return DDERR_INVALIDOBJECT
;
4073 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4074 wined3d_mutex_unlock();
4079 /*****************************************************************************
4080 * IDirectDrawSurface7::GetLOD
4082 * Returns the level of detail of a Direct3D texture
4085 * MaxLOD: Address to write the LOD to
4089 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4090 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4092 *****************************************************************************/
4093 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4095 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4097 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4100 return DDERR_INVALIDPARAMS
;
4102 wined3d_mutex_lock();
4103 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4105 wined3d_mutex_unlock();
4106 return DDERR_INVALIDOBJECT
;
4109 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4110 wined3d_mutex_unlock();
4115 /*****************************************************************************
4116 * IDirectDrawSurface7::BltFast
4118 * Performs a fast Blit.
4121 * dstx: The x coordinate to blit to on the destination
4122 * dsty: The y coordinate to blit to on the destination
4123 * Source: The source surface
4124 * rsrc: The source rectangle
4125 * trans: Type of transfer. Some DDBLTFAST_* flags
4129 * For more details, see IWineD3DSurface::BltFast
4131 *****************************************************************************/
4132 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4133 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4135 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4136 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4137 DWORD src_w
, src_h
, dst_w
, dst_h
;
4142 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4143 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4145 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4146 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4150 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4154 src_w
= src_rect
->right
- src_rect
->left
;
4155 src_h
= src_rect
->bottom
- src_rect
->top
;
4156 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4157 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4159 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4160 return DDERR_INVALIDRECT
;
4163 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4164 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4165 flags
|= WINED3D_BLT_SRC_CKEY
;
4166 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4167 flags
|= WINED3D_BLT_DST_CKEY
;
4168 if (trans
& DDBLTFAST_WAIT
)
4169 flags
|= WINED3D_BLT_WAIT
;
4170 if (trans
& DDBLTFAST_DONOTWAIT
)
4171 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4173 wined3d_mutex_lock();
4174 if (dst_impl
->clipper
)
4176 wined3d_mutex_unlock();
4177 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4178 return DDERR_BLTFASTCANTCLIP
;
4181 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4182 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
);
4184 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
4185 src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4186 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4187 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
);
4188 wined3d_mutex_unlock();
4192 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4197 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4198 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4200 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4201 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4203 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4204 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4206 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4207 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4210 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4211 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4213 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4214 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4216 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4217 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4219 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4220 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4223 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4224 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4226 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4227 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4229 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4230 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4232 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4233 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4236 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4237 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4239 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4240 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4242 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4243 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4245 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4246 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4249 /*****************************************************************************
4250 * IDirectDrawSurface7::GetClipper
4252 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4256 * Clipper: Address to store the interface pointer at
4260 * DDERR_INVALIDPARAMS if Clipper is NULL
4261 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4263 *****************************************************************************/
4264 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4266 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4268 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4271 return DDERR_INVALIDPARAMS
;
4273 wined3d_mutex_lock();
4274 if (!surface
->clipper
)
4276 wined3d_mutex_unlock();
4277 return DDERR_NOCLIPPERATTACHED
;
4280 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4281 IDirectDrawClipper_AddRef(*Clipper
);
4282 wined3d_mutex_unlock();
4287 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4289 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4291 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4293 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4296 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4298 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4300 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4302 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4305 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4307 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4309 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4311 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4314 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4316 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4318 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4320 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4323 /*****************************************************************************
4324 * IDirectDrawSurface7::SetClipper
4326 * Sets a clipper for the surface
4329 * Clipper: IDirectDrawClipper interface of the clipper to set
4334 *****************************************************************************/
4335 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4336 IDirectDrawClipper
*iclipper
)
4338 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4339 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4340 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4343 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4345 wined3d_mutex_lock();
4346 if (clipper
== This
->clipper
)
4348 wined3d_mutex_unlock();
4352 This
->clipper
= clipper
;
4354 if (clipper
!= NULL
)
4355 IDirectDrawClipper_AddRef(iclipper
);
4357 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4359 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4363 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4368 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4369 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4373 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4374 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4378 wined3d_mutex_unlock();
4383 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4385 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4387 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4389 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4392 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4394 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4396 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4398 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4401 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4403 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4405 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4407 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4410 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4412 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4414 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4416 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4419 /*****************************************************************************
4420 * IDirectDrawSurface7::SetSurfaceDesc
4422 * Sets the surface description. It can override the pixel format, the surface
4424 * It's not really tested.
4427 * DDSD: Pointer to the new surface description to set
4432 * DDERR_INVALIDPARAMS if DDSD is NULL
4434 *****************************************************************************/
4435 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4437 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4439 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4440 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4441 enum wined3d_format_id format_id
;
4442 UINT pitch
, width
, height
;
4444 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4448 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4449 return DDERR_INVALIDPARAMS
;
4453 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4454 return DDERR_INVALIDPARAMS
;
4456 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4457 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4458 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4460 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4461 return DDERR_INVALIDSURFACETYPE
;
4464 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4465 * for PIXELFORMAT to work */
4466 if (DDSD
->dwFlags
& ~allowed_flags
)
4468 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4469 return DDERR_INVALIDPARAMS
;
4471 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4473 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4474 return DDERR_INVALIDPARAMS
;
4476 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4478 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4479 return DDERR_INVALIDCAPS
;
4481 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4483 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4485 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4486 return DDERR_INVALIDPARAMS
;
4488 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4490 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4491 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4492 return DDERR_INVALIDPARAMS
;
4494 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4495 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4496 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4497 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4498 pitch
= DDSD
->u1
.lPitch
;
4499 width
= DDSD
->dwWidth
;
4501 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4503 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4504 return DDERR_INVALIDPARAMS
;
4508 pitch
= This
->surface_desc
.u1
.lPitch
;
4509 width
= This
->surface_desc
.dwWidth
;
4512 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4514 if (!DDSD
->dwHeight
)
4516 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4517 return DDERR_INVALIDPARAMS
;
4519 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4520 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4521 height
= DDSD
->dwHeight
;
4525 height
= This
->surface_desc
.dwHeight
;
4528 wined3d_mutex_lock();
4529 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4531 enum wined3d_format_id current_format_id
;
4532 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4534 if (format_id
== WINED3DFMT_UNKNOWN
)
4536 ERR("Requested to set an unknown pixelformat\n");
4537 wined3d_mutex_unlock();
4538 return DDERR_INVALIDPARAMS
;
4540 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4541 if (format_id
!= current_format_id
)
4542 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4546 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4549 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4550 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4552 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4553 wined3d_mutex_unlock();
4554 return hr_ddraw_from_wined3d(hr
);
4557 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4558 This
->surface_desc
.dwWidth
= width
;
4559 if (DDSD
->dwFlags
& DDSD_PITCH
)
4560 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4561 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4562 This
->surface_desc
.dwHeight
= height
;
4563 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4564 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4566 wined3d_mutex_unlock();
4571 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4572 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4574 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4576 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4578 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4579 surface_desc
, flags
);
4582 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4583 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4585 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4586 DDSURFACEDESC2 surface_desc2
;
4588 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4590 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4591 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4592 surface_desc
? &surface_desc2
: NULL
, flags
);
4595 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4597 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4598 struct ddraw_palette
*palette_impl
;
4601 TRACE("iface %p, palette %p.\n", iface
, palette
);
4604 return DDERR_INVALIDPARAMS
;
4605 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4607 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4608 return DDERR_SURFACELOST
;
4611 wined3d_mutex_lock();
4612 if ((palette_impl
= surface
->palette
))
4614 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4615 IDirectDrawPalette_AddRef(*palette
);
4620 hr
= DDERR_NOPALETTEATTACHED
;
4622 wined3d_mutex_unlock();
4627 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4629 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4631 TRACE("iface %p, palette %p.\n", iface
, palette
);
4633 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4636 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4638 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4640 TRACE("iface %p, palette %p.\n", iface
, palette
);
4642 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4645 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4647 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4649 TRACE("iface %p, palette %p.\n", iface
, palette
);
4651 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4654 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4656 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4658 TRACE("iface %p, palette %p.\n", iface
, palette
);
4660 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4663 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4665 DDCOLORKEY fixed_color_key
;
4666 HRESULT hr
= WINED3D_OK
;
4668 if (flags
& DDCKEY_COLORSPACE
)
4670 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4672 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4673 return DDERR_NOCOLORKEYHW
;
4675 flags
&= ~DDCKEY_COLORSPACE
;
4678 wined3d_mutex_lock();
4682 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4683 switch (flags
& ~DDCKEY_COLORSPACE
)
4685 case DDCKEY_DESTBLT
:
4686 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4687 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4690 case DDCKEY_DESTOVERLAY
:
4691 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4692 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4695 case DDCKEY_SRCOVERLAY
:
4696 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4697 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4701 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4702 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4706 wined3d_mutex_unlock();
4707 return DDERR_INVALIDPARAMS
;
4712 switch (flags
& ~DDCKEY_COLORSPACE
)
4714 case DDCKEY_DESTBLT
:
4715 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4718 case DDCKEY_DESTOVERLAY
:
4719 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4722 case DDCKEY_SRCOVERLAY
:
4723 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4727 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4731 wined3d_mutex_unlock();
4732 return DDERR_INVALIDPARAMS
;
4736 if (surface
->is_complex_root
)
4737 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4738 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4740 wined3d_mutex_unlock();
4742 return hr_ddraw_from_wined3d(hr
);
4745 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4747 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4749 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4751 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4752 return DDERR_NOTONMIPMAPSUBLEVEL
;
4754 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4757 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4759 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4761 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4763 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4766 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4768 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4770 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4772 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4775 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4777 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4779 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4781 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4784 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4786 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4788 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4790 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4793 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4795 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4797 TRACE("iface %p, palette %p.\n", iface
, palette
);
4799 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4800 return DDERR_NOTONMIPMAPSUBLEVEL
;
4801 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4803 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4804 return DDERR_SURFACELOST
;
4807 return ddraw_surface_set_palette(surface
, palette
);
4810 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4812 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4814 TRACE("iface %p, palette %p.\n", iface
, palette
);
4816 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4818 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4819 return DDERR_SURFACELOST
;
4822 return ddraw_surface_set_palette(surface
, palette
);
4825 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4827 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4829 TRACE("iface %p, palette %p.\n", iface
, palette
);
4831 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4833 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4834 return DDERR_SURFACELOST
;
4837 return ddraw_surface_set_palette(surface
, palette
);
4840 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4842 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4844 TRACE("iface %p, palette %p.\n", iface
, palette
);
4846 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4848 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4849 return DDERR_SURFACELOST
;
4852 return ddraw_surface_set_palette(surface
, palette
);
4855 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4857 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4859 TRACE("iface %p, palette %p.\n", iface
, palette
);
4861 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4863 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4864 return DDERR_SURFACELOST
;
4867 return ddraw_surface_set_palette(surface
, palette
);
4870 /**********************************************************
4871 * IDirectDrawGammaControl::GetGammaRamp
4873 * Returns the current gamma ramp for a surface
4877 * gamma_ramp: Address to write the ramp to
4881 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4883 **********************************************************/
4884 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4885 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4887 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4889 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4893 WARN("Invalid gamma_ramp passed.\n");
4894 return DDERR_INVALIDPARAMS
;
4897 wined3d_mutex_lock();
4898 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4900 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4901 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4905 ERR("Not implemented for non-primary surfaces.\n");
4907 wined3d_mutex_unlock();
4912 /**********************************************************
4913 * IDirectDrawGammaControl::SetGammaRamp
4915 * Sets the red, green and blue gamma ramps for
4918 * flags: Can be DDSGR_CALIBRATE to request calibration
4919 * gamma_ramp: Structure containing the new gamma ramp
4923 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4925 **********************************************************/
4926 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4927 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4929 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4931 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4935 WARN("Invalid gamma_ramp passed.\n");
4936 return DDERR_INVALIDPARAMS
;
4939 wined3d_mutex_lock();
4940 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4942 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4943 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4944 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4948 ERR("Not implemented for non-primary surfaces.\n");
4950 wined3d_mutex_unlock();
4955 /*****************************************************************************
4956 * IDirect3DTexture2::PaletteChanged
4958 * Informs the texture about a palette change
4961 * start: Start index of the change
4962 * count: The number of changed entries
4965 * D3D_OK, because it's a stub
4967 *****************************************************************************/
4968 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4970 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4975 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4977 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4979 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4981 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4984 /*****************************************************************************
4985 * IDirect3DTexture::Unload
4987 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4993 *****************************************************************************/
4994 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4996 WARN("iface %p. Not implemented.\n", iface
);
4998 return DDERR_UNSUPPORTED
;
5001 /*****************************************************************************
5002 * IDirect3DTexture2::GetHandle
5004 * Returns handle for the texture. At the moment, the interface
5005 * to the IWineD3DTexture is used.
5008 * device: Device this handle is assigned to
5009 * handle: Address to store the handle at.
5014 *****************************************************************************/
5015 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5016 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5018 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5019 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5021 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5023 wined3d_mutex_lock();
5025 if (!surface
->Handle
)
5027 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5028 if (h
== DDRAW_INVALID_HANDLE
)
5030 ERR("Failed to allocate a texture handle.\n");
5031 wined3d_mutex_unlock();
5032 return DDERR_OUTOFMEMORY
;
5035 surface
->Handle
= h
+ 1;
5038 TRACE("Returning handle %08x.\n", surface
->Handle
);
5039 *handle
= surface
->Handle
;
5041 wined3d_mutex_unlock();
5046 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5047 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5049 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5050 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5052 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5054 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5055 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5058 /*****************************************************************************
5059 * get_sub_mimaplevel
5061 * Helper function that returns the next mipmap level
5063 * tex_ptr: Surface of which to return the next level
5065 *****************************************************************************/
5066 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5068 /* Now go down the mipmap chain to the next surface */
5069 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5070 IDirectDrawSurface7
*next_level
;
5073 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5074 if (FAILED(hr
)) return NULL
;
5076 ddraw_surface7_Release(next_level
);
5078 return impl_from_IDirectDrawSurface7(next_level
);
5081 static BOOL
compare_format(DDPIXELFORMAT
*format1
, DDPIXELFORMAT
*format2
)
5083 if ((format1
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_FOURCC
)) !=
5084 (format2
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_FOURCC
)))
5087 if (format1
->dwFlags
& (DDPF_RGB
|DDPF_YUV
))
5089 if (!(format1
->dwFlags
& DDPF_ALPHA
))
5091 /* The RGB and YUV bits are stored in the same fields */
5092 if (format1
->u1
.dwRGBBitCount
!= format2
->u1
.dwRGBBitCount
)
5095 if (format1
->u2
.dwRBitMask
!= format2
->u2
.dwRBitMask
)
5098 if (format1
->u3
.dwGBitMask
!= format2
->u3
.dwGBitMask
)
5101 if (format1
->u4
.dwBBitMask
!= format2
->u4
.dwBBitMask
)
5105 if (format1
->dwFlags
& (DDPF_ALPHAPIXELS
| DDPF_ALPHA
))
5107 if (format1
->u5
.dwRGBAlphaBitMask
!= format2
->u5
.dwRGBAlphaBitMask
)
5112 if (format1
->dwFlags
& DDPF_FOURCC
)
5114 if (format1
->dwFourCC
!= format2
->dwFourCC
)
5121 /*****************************************************************************
5122 * IDirect3DTexture2::Load
5124 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5126 * This function isn't relayed to WineD3D because the whole interface is
5127 * implemented in DDraw only. For speed improvements an implementation which
5128 * takes OpenGL more into account could be placed into WineD3D.
5131 * src_texture: Address of the texture to load
5135 * D3DERR_TEXTURE_LOAD_FAILED.
5137 *****************************************************************************/
5138 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5140 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5141 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5142 RECT src_rect
, dst_rect
;
5145 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5147 if (src_surface
== dst_surface
)
5149 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5153 wined3d_mutex_lock();
5157 DDSURFACEDESC
*src_desc
= (DDSURFACEDESC
*)&src_surface
->surface_desc
;
5159 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5161 if (compare_format(&src_surface
->surface_desc
.u4
.ddpfPixelFormat
,
5162 &dst_surface
->surface_desc
.u4
.ddpfPixelFormat
))
5164 struct ddraw_palette
*dst_pal
, *src_pal
;
5166 /* Get the palettes */
5167 dst_pal
= dst_surface
->palette
;
5168 src_pal
= src_surface
->palette
;
5172 PALETTEENTRY palent
[256];
5176 wined3d_mutex_unlock();
5177 return DDERR_NOPALETTEATTACHED
;
5179 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5180 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5183 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5185 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5186 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5191 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5195 /* Suppress the ALLOCONLOAD flag */
5196 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5198 SetRect(&src_rect
, 0, 0, src_surface
->surface_desc
.dwWidth
, src_surface
->surface_desc
.dwHeight
);
5199 SetRect(&dst_rect
, 0, 0, dst_surface
->surface_desc
.dwWidth
, dst_surface
->surface_desc
.dwHeight
);
5201 hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
, &dst_rect
,
5202 src_surface
->wined3d_texture
, src_surface
->sub_resource_idx
, &src_rect
,
5203 0, NULL
, WINED3D_TEXF_LINEAR
);
5206 ERR("Failed to blit surface, hr %#x.\n", hr
);
5207 wined3d_mutex_unlock();
5211 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5212 src_surface
= get_sub_mimaplevel(src_surface
);
5216 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5217 dst_surface
= get_sub_mimaplevel(dst_surface
);
5221 if (src_surface
&& !dst_surface
)
5222 return DDERR_NOTFOUND
;
5224 if (!src_surface
|| !dst_surface
)
5228 wined3d_mutex_unlock();
5233 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5235 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5236 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5238 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5240 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5241 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5244 /*****************************************************************************
5246 *****************************************************************************/
5248 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5251 ddraw_surface7_QueryInterface
,
5252 ddraw_surface7_AddRef
,
5253 ddraw_surface7_Release
,
5254 /* IDirectDrawSurface */
5255 ddraw_surface7_AddAttachedSurface
,
5256 ddraw_surface7_AddOverlayDirtyRect
,
5258 ddraw_surface7_BltBatch
,
5259 ddraw_surface7_BltFast
,
5260 ddraw_surface7_DeleteAttachedSurface
,
5261 ddraw_surface7_EnumAttachedSurfaces
,
5262 ddraw_surface7_EnumOverlayZOrders
,
5263 ddraw_surface7_Flip
,
5264 ddraw_surface7_GetAttachedSurface
,
5265 ddraw_surface7_GetBltStatus
,
5266 ddraw_surface7_GetCaps
,
5267 ddraw_surface7_GetClipper
,
5268 ddraw_surface7_GetColorKey
,
5269 ddraw_surface7_GetDC
,
5270 ddraw_surface7_GetFlipStatus
,
5271 ddraw_surface7_GetOverlayPosition
,
5272 ddraw_surface7_GetPalette
,
5273 ddraw_surface7_GetPixelFormat
,
5274 ddraw_surface7_GetSurfaceDesc
,
5275 ddraw_surface7_Initialize
,
5276 ddraw_surface7_IsLost
,
5277 ddraw_surface7_Lock
,
5278 ddraw_surface7_ReleaseDC
,
5279 ddraw_surface7_Restore
,
5280 ddraw_surface7_SetClipper
,
5281 ddraw_surface7_SetColorKey
,
5282 ddraw_surface7_SetOverlayPosition
,
5283 ddraw_surface7_SetPalette
,
5284 ddraw_surface7_Unlock
,
5285 ddraw_surface7_UpdateOverlay
,
5286 ddraw_surface7_UpdateOverlayDisplay
,
5287 ddraw_surface7_UpdateOverlayZOrder
,
5288 /* IDirectDrawSurface2 */
5289 ddraw_surface7_GetDDInterface
,
5290 ddraw_surface7_PageLock
,
5291 ddraw_surface7_PageUnlock
,
5292 /* IDirectDrawSurface3 */
5293 ddraw_surface7_SetSurfaceDesc
,
5294 /* IDirectDrawSurface4 */
5295 ddraw_surface7_SetPrivateData
,
5296 ddraw_surface7_GetPrivateData
,
5297 ddraw_surface7_FreePrivateData
,
5298 ddraw_surface7_GetUniquenessValue
,
5299 ddraw_surface7_ChangeUniquenessValue
,
5300 /* IDirectDrawSurface7 */
5301 ddraw_surface7_SetPriority
,
5302 ddraw_surface7_GetPriority
,
5303 ddraw_surface7_SetLOD
,
5304 ddraw_surface7_GetLOD
,
5307 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5310 ddraw_surface4_QueryInterface
,
5311 ddraw_surface4_AddRef
,
5312 ddraw_surface4_Release
,
5313 /* IDirectDrawSurface */
5314 ddraw_surface4_AddAttachedSurface
,
5315 ddraw_surface4_AddOverlayDirtyRect
,
5317 ddraw_surface4_BltBatch
,
5318 ddraw_surface4_BltFast
,
5319 ddraw_surface4_DeleteAttachedSurface
,
5320 ddraw_surface4_EnumAttachedSurfaces
,
5321 ddraw_surface4_EnumOverlayZOrders
,
5322 ddraw_surface4_Flip
,
5323 ddraw_surface4_GetAttachedSurface
,
5324 ddraw_surface4_GetBltStatus
,
5325 ddraw_surface4_GetCaps
,
5326 ddraw_surface4_GetClipper
,
5327 ddraw_surface4_GetColorKey
,
5328 ddraw_surface4_GetDC
,
5329 ddraw_surface4_GetFlipStatus
,
5330 ddraw_surface4_GetOverlayPosition
,
5331 ddraw_surface4_GetPalette
,
5332 ddraw_surface4_GetPixelFormat
,
5333 ddraw_surface4_GetSurfaceDesc
,
5334 ddraw_surface4_Initialize
,
5335 ddraw_surface4_IsLost
,
5336 ddraw_surface4_Lock
,
5337 ddraw_surface4_ReleaseDC
,
5338 ddraw_surface4_Restore
,
5339 ddraw_surface4_SetClipper
,
5340 ddraw_surface4_SetColorKey
,
5341 ddraw_surface4_SetOverlayPosition
,
5342 ddraw_surface4_SetPalette
,
5343 ddraw_surface4_Unlock
,
5344 ddraw_surface4_UpdateOverlay
,
5345 ddraw_surface4_UpdateOverlayDisplay
,
5346 ddraw_surface4_UpdateOverlayZOrder
,
5347 /* IDirectDrawSurface2 */
5348 ddraw_surface4_GetDDInterface
,
5349 ddraw_surface4_PageLock
,
5350 ddraw_surface4_PageUnlock
,
5351 /* IDirectDrawSurface3 */
5352 ddraw_surface4_SetSurfaceDesc
,
5353 /* IDirectDrawSurface4 */
5354 ddraw_surface4_SetPrivateData
,
5355 ddraw_surface4_GetPrivateData
,
5356 ddraw_surface4_FreePrivateData
,
5357 ddraw_surface4_GetUniquenessValue
,
5358 ddraw_surface4_ChangeUniquenessValue
,
5361 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5364 ddraw_surface3_QueryInterface
,
5365 ddraw_surface3_AddRef
,
5366 ddraw_surface3_Release
,
5367 /* IDirectDrawSurface */
5368 ddraw_surface3_AddAttachedSurface
,
5369 ddraw_surface3_AddOverlayDirtyRect
,
5371 ddraw_surface3_BltBatch
,
5372 ddraw_surface3_BltFast
,
5373 ddraw_surface3_DeleteAttachedSurface
,
5374 ddraw_surface3_EnumAttachedSurfaces
,
5375 ddraw_surface3_EnumOverlayZOrders
,
5376 ddraw_surface3_Flip
,
5377 ddraw_surface3_GetAttachedSurface
,
5378 ddraw_surface3_GetBltStatus
,
5379 ddraw_surface3_GetCaps
,
5380 ddraw_surface3_GetClipper
,
5381 ddraw_surface3_GetColorKey
,
5382 ddraw_surface3_GetDC
,
5383 ddraw_surface3_GetFlipStatus
,
5384 ddraw_surface3_GetOverlayPosition
,
5385 ddraw_surface3_GetPalette
,
5386 ddraw_surface3_GetPixelFormat
,
5387 ddraw_surface3_GetSurfaceDesc
,
5388 ddraw_surface3_Initialize
,
5389 ddraw_surface3_IsLost
,
5390 ddraw_surface3_Lock
,
5391 ddraw_surface3_ReleaseDC
,
5392 ddraw_surface3_Restore
,
5393 ddraw_surface3_SetClipper
,
5394 ddraw_surface3_SetColorKey
,
5395 ddraw_surface3_SetOverlayPosition
,
5396 ddraw_surface3_SetPalette
,
5397 ddraw_surface3_Unlock
,
5398 ddraw_surface3_UpdateOverlay
,
5399 ddraw_surface3_UpdateOverlayDisplay
,
5400 ddraw_surface3_UpdateOverlayZOrder
,
5401 /* IDirectDrawSurface2 */
5402 ddraw_surface3_GetDDInterface
,
5403 ddraw_surface3_PageLock
,
5404 ddraw_surface3_PageUnlock
,
5405 /* IDirectDrawSurface3 */
5406 ddraw_surface3_SetSurfaceDesc
,
5409 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5412 ddraw_surface2_QueryInterface
,
5413 ddraw_surface2_AddRef
,
5414 ddraw_surface2_Release
,
5415 /* IDirectDrawSurface */
5416 ddraw_surface2_AddAttachedSurface
,
5417 ddraw_surface2_AddOverlayDirtyRect
,
5419 ddraw_surface2_BltBatch
,
5420 ddraw_surface2_BltFast
,
5421 ddraw_surface2_DeleteAttachedSurface
,
5422 ddraw_surface2_EnumAttachedSurfaces
,
5423 ddraw_surface2_EnumOverlayZOrders
,
5424 ddraw_surface2_Flip
,
5425 ddraw_surface2_GetAttachedSurface
,
5426 ddraw_surface2_GetBltStatus
,
5427 ddraw_surface2_GetCaps
,
5428 ddraw_surface2_GetClipper
,
5429 ddraw_surface2_GetColorKey
,
5430 ddraw_surface2_GetDC
,
5431 ddraw_surface2_GetFlipStatus
,
5432 ddraw_surface2_GetOverlayPosition
,
5433 ddraw_surface2_GetPalette
,
5434 ddraw_surface2_GetPixelFormat
,
5435 ddraw_surface2_GetSurfaceDesc
,
5436 ddraw_surface2_Initialize
,
5437 ddraw_surface2_IsLost
,
5438 ddraw_surface2_Lock
,
5439 ddraw_surface2_ReleaseDC
,
5440 ddraw_surface2_Restore
,
5441 ddraw_surface2_SetClipper
,
5442 ddraw_surface2_SetColorKey
,
5443 ddraw_surface2_SetOverlayPosition
,
5444 ddraw_surface2_SetPalette
,
5445 ddraw_surface2_Unlock
,
5446 ddraw_surface2_UpdateOverlay
,
5447 ddraw_surface2_UpdateOverlayDisplay
,
5448 ddraw_surface2_UpdateOverlayZOrder
,
5449 /* IDirectDrawSurface2 */
5450 ddraw_surface2_GetDDInterface
,
5451 ddraw_surface2_PageLock
,
5452 ddraw_surface2_PageUnlock
,
5455 static struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5458 ddraw_surface1_QueryInterface
,
5459 ddraw_surface1_AddRef
,
5460 ddraw_surface1_Release
,
5461 /* IDirectDrawSurface */
5462 ddraw_surface1_AddAttachedSurface
,
5463 ddraw_surface1_AddOverlayDirtyRect
,
5465 ddraw_surface1_BltBatch
,
5466 ddraw_surface1_BltFast
,
5467 ddraw_surface1_DeleteAttachedSurface
,
5468 ddraw_surface1_EnumAttachedSurfaces
,
5469 ddraw_surface1_EnumOverlayZOrders
,
5470 ddraw_surface1_Flip
,
5471 ddraw_surface1_GetAttachedSurface
,
5472 ddraw_surface1_GetBltStatus
,
5473 ddraw_surface1_GetCaps
,
5474 ddraw_surface1_GetClipper
,
5475 ddraw_surface1_GetColorKey
,
5476 ddraw_surface1_GetDC
,
5477 ddraw_surface1_GetFlipStatus
,
5478 ddraw_surface1_GetOverlayPosition
,
5479 ddraw_surface1_GetPalette
,
5480 ddraw_surface1_GetPixelFormat
,
5481 ddraw_surface1_GetSurfaceDesc
,
5482 ddraw_surface1_Initialize
,
5483 ddraw_surface1_IsLost
,
5484 ddraw_surface1_Lock
,
5485 ddraw_surface1_ReleaseDC
,
5486 ddraw_surface1_Restore
,
5487 ddraw_surface1_SetClipper
,
5488 ddraw_surface1_SetColorKey
,
5489 ddraw_surface1_SetOverlayPosition
,
5490 ddraw_surface1_SetPalette
,
5491 ddraw_surface1_Unlock
,
5492 ddraw_surface1_UpdateOverlay
,
5493 ddraw_surface1_UpdateOverlayDisplay
,
5494 ddraw_surface1_UpdateOverlayZOrder
,
5497 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5499 ddraw_gamma_control_QueryInterface
,
5500 ddraw_gamma_control_AddRef
,
5501 ddraw_gamma_control_Release
,
5502 ddraw_gamma_control_GetGammaRamp
,
5503 ddraw_gamma_control_SetGammaRamp
,
5506 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5508 d3d_texture2_QueryInterface
,
5509 d3d_texture2_AddRef
,
5510 d3d_texture2_Release
,
5511 d3d_texture2_GetHandle
,
5512 d3d_texture2_PaletteChanged
,
5516 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5518 d3d_texture1_QueryInterface
,
5519 d3d_texture1_AddRef
,
5520 d3d_texture1_Release
,
5521 d3d_texture1_Initialize
,
5522 d3d_texture1_GetHandle
,
5523 d3d_texture1_PaletteChanged
,
5525 d3d_texture1_Unload
,
5528 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5529 * IDirectDrawSurface interface to ddraw methods. */
5530 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5532 if (!iface
) return NULL
;
5533 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5535 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5538 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5541 IDirectDrawSurface7_Release(iface
);
5543 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5546 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5548 if (!iface
) return NULL
;
5549 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5551 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5554 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5557 IDirectDrawSurface4_Release(iface
);
5559 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5562 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5564 if (!iface
) return NULL
;
5565 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5567 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5570 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5573 IDirectDrawSurface3_Release(iface
);
5575 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5578 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5580 if (!iface
) return NULL
;
5581 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5583 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5586 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5589 IDirectDrawSurface2_Release(iface
);
5591 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5594 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5596 if (!iface
) return NULL
;
5597 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5599 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5602 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5605 IDirectDrawSurface_Release(iface
);
5607 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5610 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5612 if (!iface
) return NULL
;
5613 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5614 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5617 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5619 if (!iface
) return NULL
;
5620 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5621 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5624 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5626 struct ddraw_surface
*surface
= parent
;
5628 TRACE("surface %p.\n", surface
);
5630 /* Check for attached surfaces and detach them. */
5631 if (surface
->first_attached
!= surface
)
5633 /* Well, this shouldn't happen: The surface being attached is
5634 * referenced in AddAttachedSurface(), so it shouldn't be released
5635 * until DeleteAttachedSurface() is called, because the refcount is
5636 * held. It looks like the application released it often enough to
5638 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5640 /* The refcount will drop to -1 here */
5641 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5642 ERR("DeleteAttachedSurface failed.\n");
5645 while (surface
->next_attached
)
5646 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5647 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5648 ERR("DeleteAttachedSurface failed.\n");
5650 /* Having a texture handle set implies that the device still exists. */
5651 if (surface
->Handle
)
5652 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5654 /* Reduce the ddraw surface count. */
5655 list_remove(&surface
->surface_list_entry
);
5657 if (surface
->clipper
)
5658 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5660 if (surface
== surface
->ddraw
->primary
)
5661 surface
->ddraw
->primary
= NULL
;
5663 wined3d_private_store_cleanup(&surface
->private_store
);
5665 HeapFree(GetProcessHeap(), 0, surface
);
5668 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5670 ddraw_surface_wined3d_object_destroyed
,
5673 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5675 TRACE("parent %p.\n", parent
);
5677 HeapFree(GetProcessHeap(), 0, parent
);
5680 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5682 ddraw_texture_wined3d_object_destroyed
,
5685 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5690 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5691 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5693 struct wined3d_resource_desc wined3d_desc
, wined3d_mip_desc
;
5694 struct ddraw_surface
*root
, *mip
, **attach
;
5695 struct wined3d_texture
*wined3d_texture
;
5696 struct wined3d_resource
*resource
;
5697 struct wined3d_display_mode mode
;
5698 DDSURFACEDESC2
*desc
, *mip_desc
;
5699 struct ddraw_texture
*texture
;
5700 unsigned int layers
= 1;
5701 unsigned int pitch
= 0;
5705 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5706 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5707 if (TRACE_ON(ddraw
))
5709 TRACE("Requesting surface desc:\n");
5710 DDRAW_dump_surface_desc(surface_desc
);
5714 return CLASS_E_NOAGGREGATION
;
5719 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5720 return E_OUTOFMEMORY
;
5722 texture
->version
= version
;
5723 texture
->surface_desc
= *surface_desc
;
5724 desc
= &texture
->surface_desc
;
5726 /* Ensure DDSD_CAPS is always set. */
5727 desc
->dwFlags
|= DDSD_CAPS
;
5729 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5731 DWORD flippable
= desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
);
5733 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5735 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5736 HeapFree(GetProcessHeap(), 0, texture
);
5737 return DDERR_INVALIDCAPS
;
5742 if (flippable
!= (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
))
5744 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5745 HeapFree(GetProcessHeap(), 0, texture
);
5746 return DDERR_INVALIDCAPS
;
5749 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5751 WARN("Tried to create a flippable primary surface without any back buffers.\n");
5752 HeapFree(GetProcessHeap(), 0, texture
);
5753 return DDERR_INVALIDCAPS
;
5756 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5758 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5759 HeapFree(GetProcessHeap(), 0, texture
);
5760 return DDERR_NOEXCLUSIVEMODE
;
5765 /* This is a special case in ddrawex, but not allowed in ddraw. */
5766 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5767 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5769 WARN("Tried to create a surface in both system and video memory.\n");
5770 HeapFree(GetProcessHeap(), 0, texture
);
5771 return DDERR_INVALIDCAPS
;
5774 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
5775 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5777 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
5778 HeapFree(GetProcessHeap(), 0, texture
);
5779 return DDERR_INVALIDCAPS
;
5782 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5783 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5785 WARN("Cube map faces requested without cube map flag.\n");
5786 HeapFree(GetProcessHeap(), 0, texture
);
5787 return DDERR_INVALIDCAPS
;
5790 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5791 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5793 WARN("Cube map without faces requested.\n");
5794 HeapFree(GetProcessHeap(), 0, texture
);
5795 return DDERR_INVALIDPARAMS
;
5798 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5799 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5800 FIXME("Partial cube maps not implemented.\n");
5802 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5804 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5806 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5807 HeapFree(GetProcessHeap(), 0, texture
);
5808 return DDERR_INVALIDCAPS
;
5810 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5812 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5813 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5814 HeapFree(GetProcessHeap(), 0, texture
);
5815 return DDERR_INVALIDCAPS
;
5819 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5821 ERR("Failed to get display mode, hr %#x.\n", hr
);
5822 HeapFree(GetProcessHeap(), 0, texture
);
5823 return hr_ddraw_from_wined3d(hr
);
5826 /* No pixelformat given? Use the current screen format. */
5827 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5829 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5830 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5831 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5834 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
5835 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5836 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5838 WARN("Unsupported / unknown pixelformat.\n");
5839 HeapFree(GetProcessHeap(), 0, texture
);
5840 return DDERR_INVALIDPIXELFORMAT
;
5843 /* No width or no height? Use the screen size. */
5844 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5846 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5848 WARN("No width / height specified.\n");
5849 HeapFree(GetProcessHeap(), 0, texture
);
5850 return DDERR_INVALIDPARAMS
;
5853 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5854 desc
->dwWidth
= mode
.width
;
5855 desc
->dwHeight
= mode
.height
;
5858 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5860 HeapFree(GetProcessHeap(), 0, texture
);
5861 return DDERR_INVALIDPARAMS
;
5864 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5866 /* The first surface is a front buffer, the back buffers are created
5868 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5869 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5870 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5871 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5873 struct wined3d_swapchain_desc swapchain_desc
;
5875 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5876 swapchain_desc
.backbuffer_width
= mode
.width
;
5877 swapchain_desc
.backbuffer_height
= mode
.height
;
5878 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5880 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5881 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5883 ERR("Failed to reset device.\n");
5884 HeapFree(GetProcessHeap(), 0, texture
);
5885 return hr_ddraw_from_wined3d(hr
);
5890 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5891 wined3d_desc
.multisample_quality
= 0;
5892 wined3d_desc
.usage
= 0;
5893 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5894 wined3d_desc
.width
= desc
->dwWidth
;
5895 wined3d_desc
.height
= desc
->dwHeight
;
5896 wined3d_desc
.depth
= 1;
5897 wined3d_desc
.size
= 0;
5899 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5901 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5902 /* Do not fail surface creation, only fail 3D device creation. */
5905 /* Mipmap count fixes */
5906 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5908 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5910 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5912 /* Mipmap count is given, should not be 0. */
5913 if (!desc
->u2
.dwMipMapCount
)
5915 HeapFree(GetProcessHeap(), 0, texture
);
5916 return DDERR_INVALIDPARAMS
;
5921 /* Undocumented feature: Create sublevels until either the
5922 * width or the height is 1. */
5924 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5926 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5931 desc
->u2
.dwMipMapCount
= 1;
5934 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5935 levels
= desc
->u2
.dwMipMapCount
;
5942 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5944 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5946 enum wined3d_resource_type rtype
;
5949 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5951 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
5952 rtype
= WINED3D_RTYPE_TEXTURE_2D
;
5954 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5955 rtype
= WINED3D_RTYPE_TEXTURE_2D
;
5957 rtype
= WINED3D_RTYPE_SURFACE
;
5959 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5960 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5961 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5962 usage
= WINED3DUSAGE_RENDERTARGET
;
5964 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5965 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, rtype
, wined3d_desc
.format
)))
5966 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5968 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5970 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5972 /* Tests show surfaces without memory flags get these flags added
5973 * right after creation. */
5974 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5978 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5979 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5981 WARN("System memory overlays are not allowed.\n");
5982 HeapFree(GetProcessHeap(), 0, texture
);
5983 return DDERR_NOOVERLAYHW
;
5986 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5989 * The ddraw RGB device allows to use system memory surfaces as rendering target.
5990 * This does not cause problems because the RGB device does software rasterization
5991 * though it will fail with hardware accelerated ddraw. In order to be partially
5992 * compatible with games requesting explicitly the RGB device, we ignore the
5993 * specified location and try to create rendering targets in video memory if
5996 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
5997 SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5998 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, WINED3DUSAGE_RENDERTARGET
,
5999 WINED3D_RTYPE_SURFACE
, wined3d_desc
.format
)))
6001 FIXME("Application wants to create rendering target in system memory, using video memory instead\n");
6002 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
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. We set
6131 * WINED3D_TEXTURE_CREATE_PIN_SYSMEM because of this. */
6132 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
6133 WINED3D_TEXTURE_CREATE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6135 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6136 HeapFree(GetProcessHeap(), 0, texture
);
6137 return hr_ddraw_from_wined3d(hr
);
6140 root
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6141 wined3d_texture_decref(wined3d_texture
);
6142 root
->is_complex_root
= TRUE
;
6143 texture
->root
= root
;
6145 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6146 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6147 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6148 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6149 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6150 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6151 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6152 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6153 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6154 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6155 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6156 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6158 for (i
= 0; i
< layers
; ++i
)
6160 attach
= &root
->complex_array
[layers
- 1 - i
];
6162 for (j
= 0; j
< levels
; ++j
)
6164 mip
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, i
* levels
+ j
);
6165 mip_desc
= &mip
->surface_desc
;
6169 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
6170 wined3d_resource_get_desc(resource
, &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,
6252 WINED3D_TEXTURE_CREATE_PIN_SYSMEM
, 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
;