1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
32 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
34 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
36 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
39 /* This is slow, of course. Also, in case of locks, we can't prevent other
40 * applications from drawing to the screen while we've locked the frontbuffer.
41 * We'd like to do this in wined3d instead, but for that to work wined3d needs
42 * to support windowless rendering first. */
43 HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
, const RECT
*rect
, BOOL read
)
45 HDC surface_dc
, screen_dc
;
53 SetRect(&r
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
59 w
= rect
->right
- rect
->left
;
60 h
= rect
->bottom
- rect
->top
;
65 if (surface
->ddraw
->swapchain_window
)
67 /* Nothing to do, we control the frontbuffer, or at least the parts we
72 return wined3d_texture_blt(surface
->ddraw
->wined3d_frontbuffer
, 0, rect
,
73 surface
->wined3d_texture
, surface
->sub_resource_idx
, rect
, 0, NULL
, WINED3D_TEXF_POINT
);
76 if (FAILED(hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, &surface_dc
)))
78 ERR("Failed to get surface DC, hr %#x.\n", hr
);
82 wined3d_palette_apply_to_dc(surface
->palette
->wineD3DPalette
, surface_dc
);
84 if (!(screen_dc
= GetDC(NULL
)))
86 wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
87 ERR("Failed to get screen DC.\n");
92 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
93 screen_dc
, x
, y
, SRCCOPY
);
95 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
96 surface_dc
, x
, y
, SRCCOPY
);
98 ReleaseDC(NULL
, screen_dc
);
99 wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, surface_dc
);
103 ERR("Failed to blit to/from screen.\n");
110 /*****************************************************************************
111 * IUnknown parts follow
112 *****************************************************************************/
114 /*****************************************************************************
115 * IDirectDrawSurface7::QueryInterface
117 * A normal QueryInterface implementation. For QueryInterface rules
118 * see ddraw.c, IDirectDraw7::QueryInterface. This method
119 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
120 * in all versions, the IDirectDrawGammaControl interface and it can
121 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
124 * riid: The interface id queried for
125 * obj: Address to write the pointer to
129 * E_NOINTERFACE if the requested interface wasn't found
131 *****************************************************************************/
132 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
134 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
136 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
138 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
142 return DDERR_INVALIDPARAMS
;
144 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
146 IDirectDrawSurface7_AddRef(iface
);
148 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
152 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
154 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
155 *obj
= &This
->IDirectDrawSurface4_iface
;
156 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
160 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
162 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
163 *obj
= &This
->IDirectDrawSurface3_iface
;
164 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
168 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
170 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
171 *obj
= &This
->IDirectDrawSurface2_iface
;
172 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
176 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
177 || IsEqualGUID(riid
, &IID_IUnknown
))
179 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
180 *obj
= &This
->IDirectDrawSurface_iface
;
181 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
185 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
187 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
188 *obj
= &This
->IDirectDrawGammaControl_iface
;
189 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
193 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
195 WARN("Color control not implemented.\n");
197 return E_NOINTERFACE
;
200 if (This
->version
!= 7)
202 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
203 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
204 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
206 wined3d_mutex_lock();
211 if (FAILED(hr
= d3d_device_create(This
->ddraw
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
212 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
214 This
->device1
= NULL
;
215 wined3d_mutex_unlock();
216 WARN("Failed to create device, hr %#x.\n", hr
);
220 wined3d_mutex_unlock();
222 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
223 *obj
= &This
->device1
->IDirect3DDevice_iface
;
227 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
229 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
230 *obj
= &This
->IDirect3DTexture2_iface
;
234 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
236 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
237 *obj
= &This
->IDirect3DTexture_iface
;
242 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
244 if (This
->version
!= 7)
247 return E_NOINTERFACE
;
250 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
252 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
254 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
256 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
259 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
261 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
263 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
265 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
268 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
270 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
272 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
274 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
277 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
279 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
281 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
283 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
286 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
287 REFIID riid
, void **object
)
289 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
291 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
293 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
296 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
298 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
300 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
302 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
305 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
307 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
309 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
311 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
314 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
316 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
317 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
319 if (iface_count
== 1)
321 if (surface
->ifaceToRelease
)
322 IUnknown_AddRef(surface
->ifaceToRelease
);
323 wined3d_mutex_lock();
324 if (surface
->wined3d_rtv
)
325 wined3d_rendertarget_view_incref(surface
->wined3d_rtv
);
326 wined3d_texture_incref(surface
->wined3d_texture
);
327 wined3d_mutex_unlock();
331 /*****************************************************************************
332 * IDirectDrawSurface7::AddRef
334 * A normal addref implementation
339 *****************************************************************************/
340 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
342 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
343 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
345 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
349 ddraw_surface_add_iface(This
);
355 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
357 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
358 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
360 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
364 ddraw_surface_add_iface(This
);
370 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
372 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
373 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
375 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
379 ddraw_surface_add_iface(This
);
385 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
387 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
388 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
390 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
394 ddraw_surface_add_iface(This
);
400 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
402 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
403 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
405 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
409 ddraw_surface_add_iface(This
);
415 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
417 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
418 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
420 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
424 ddraw_surface_add_iface(This
);
430 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
432 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
434 TRACE("iface %p.\n", iface
);
436 return IUnknown_AddRef(surface
->texture_outer
);
439 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
441 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
443 TRACE("iface %p.\n", iface
);
445 return IUnknown_AddRef(surface
->texture_outer
);
448 static HRESULT
ddraw_surface_set_palette(struct ddraw_surface
*surface
, IDirectDrawPalette
*palette
)
450 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(palette
);
451 struct ddraw_palette
*prev
;
453 TRACE("iface %p, palette %p.\n", surface
, palette
);
455 if (palette_impl
&& palette_impl
->flags
& DDPCAPS_ALPHA
456 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
458 WARN("Alpha palette set on non-texture surface, returning DDERR_INVALIDSURFACETYPE.\n");
459 return DDERR_INVALIDSURFACETYPE
;
462 if (!format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
463 return DDERR_INVALIDPIXELFORMAT
;
465 wined3d_mutex_lock();
467 prev
= surface
->palette
;
468 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
471 prev
->flags
&= ~DDPCAPS_PRIMARYSURFACE
;
473 palette_impl
->flags
|= DDPCAPS_PRIMARYSURFACE
;
474 wined3d_swapchain_set_palette(surface
->ddraw
->wined3d_swapchain
,
475 palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
476 ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
479 IDirectDrawPalette_AddRef(&palette_impl
->IDirectDrawPalette_iface
);
481 IDirectDrawPalette_Release(&prev
->IDirectDrawPalette_iface
);
482 surface
->palette
= palette_impl
;
484 wined3d_mutex_unlock();
489 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
491 struct ddraw_surface
*surf
;
494 TRACE("surface %p.\n", surface
);
496 /* The refcount test shows that the palette is detached when the surface
498 ddraw_surface_set_palette(surface
, NULL
);
500 /* Loop through all complex attached surfaces and destroy them.
502 * Yet again, only the root can have more than one complexly attached
503 * surface, all the others have a total of one. */
504 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
506 if (!surface
->complex_array
[i
])
509 surf
= surface
->complex_array
[i
];
510 surface
->complex_array
[i
] = NULL
;
511 if (!surf
->is_complex_root
)
512 ddraw_surface_cleanup(surf
);
515 if (surface
->device1
)
516 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
518 if (surface
->iface_count
> 1)
520 /* This can happen when a complex surface is destroyed, because the
521 * 2nd surface was addref()ed when the app called
522 * GetAttachedSurface(). */
523 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
524 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
527 if (surface
->wined3d_rtv
)
528 wined3d_rendertarget_view_decref(surface
->wined3d_rtv
);
529 wined3d_texture_decref(surface
->wined3d_texture
);
532 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
534 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
535 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
537 if (iface_count
== 0)
539 IUnknown
*release_iface
= This
->ifaceToRelease
;
541 /* Complex attached surfaces are destroyed implicitly when the root is released */
542 wined3d_mutex_lock();
543 if(!This
->is_complex_root
)
545 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
546 wined3d_mutex_unlock();
549 ddraw_surface_cleanup(This
);
550 wined3d_mutex_unlock();
553 IUnknown_Release(release_iface
);
559 /*****************************************************************************
560 * IDirectDrawSurface7::Release
562 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
563 * surface is destroyed.
565 * Destroying the surface is a bit tricky. For the connection between
566 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
567 * It has a nice graph explaining the connection.
569 * What happens here is basically this:
570 * When a surface is destroyed, its WineD3DSurface is released,
571 * and the refcount of the DirectDraw interface is reduced by 1. If it has
572 * complex surfaces attached to it, then these surfaces are destroyed too,
573 * regardless of their refcount. If any surface being destroyed has another
574 * surface attached to it (with a "soft" attachment, not complex), then
575 * this surface is detached with DeleteAttachedSurface.
577 * When the surface is a texture, the WineD3DTexture is released.
578 * If the surface is the Direct3D render target, then the D3D
579 * capabilities of the WineD3DDevice are uninitialized, which causes the
580 * swapchain to be released.
582 * When a complex sublevel falls to ref zero, then this is ignored.
587 *****************************************************************************/
588 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
590 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
591 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
593 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
597 ddraw_surface_release_iface(This
);
603 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
605 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
606 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
608 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
612 ddraw_surface_release_iface(This
);
618 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
620 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
621 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
623 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
627 ddraw_surface_release_iface(This
);
633 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
635 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
636 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
638 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
642 ddraw_surface_release_iface(This
);
648 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
650 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
651 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
653 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
657 ddraw_surface_release_iface(This
);
663 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
665 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
666 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
668 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
672 ddraw_surface_release_iface(This
);
678 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
680 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
682 TRACE("iface %p.\n", iface
);
684 return IUnknown_Release(surface
->texture_outer
);
687 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
689 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
691 TRACE("iface %p.\n", iface
);
693 return IUnknown_Release(surface
->texture_outer
);
696 /*****************************************************************************
697 * IDirectDrawSurface7::GetAttachedSurface
699 * Returns an attached surface with the requested caps. Surface attachment
700 * and complex surfaces are not clearly described by the MSDN or sdk,
701 * so this method is tricky and likely to contain problems.
702 * This implementation searches the complex list first, then the
705 * The chains are searched from This down to the last surface in the chain,
706 * not from the first element in the chain. The first surface found is
707 * returned. The MSDN says that this method fails if more than one surface
708 * matches the caps, but it is not sure if that is right. The attachment
709 * structure may not even allow two matching surfaces.
711 * The found surface is AddRef-ed before it is returned.
714 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
715 * Surface: Address to store the found surface
719 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
720 * DDERR_NOTFOUND if no surface was found
722 *****************************************************************************/
723 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
724 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
726 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
727 struct ddraw_surface
*surf
;
731 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
733 wined3d_mutex_lock();
735 if(This
->version
< 7)
737 /* Earlier dx apps put garbage into these members, clear them */
738 our_caps
.dwCaps
= Caps
->dwCaps
;
739 our_caps
.dwCaps2
= 0;
740 our_caps
.dwCaps3
= 0;
741 our_caps
.u1
.dwCaps4
= 0;
748 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 */
750 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
752 surf
= This
->complex_array
[i
];
755 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
756 surf
->surface_desc
.ddsCaps
.dwCaps
,
757 surf
->surface_desc
.ddsCaps
.dwCaps2
,
758 surf
->surface_desc
.ddsCaps
.dwCaps3
,
759 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
761 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
762 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
764 /* MSDN: "This method fails if more than one surface is attached
765 * that matches the capabilities requested."
767 * Not sure how to test this.
770 TRACE("(%p): Returning surface %p\n", This
, surf
);
771 *Surface
= &surf
->IDirectDrawSurface7_iface
;
772 ddraw_surface7_AddRef(*Surface
);
773 wined3d_mutex_unlock();
779 /* Next, look at the attachment chain */
782 while( (surf
= surf
->next_attached
) )
784 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
785 surf
->surface_desc
.ddsCaps
.dwCaps
,
786 surf
->surface_desc
.ddsCaps
.dwCaps2
,
787 surf
->surface_desc
.ddsCaps
.dwCaps3
,
788 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
790 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
791 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
793 TRACE("(%p): Returning surface %p\n", This
, surf
);
794 *Surface
= &surf
->IDirectDrawSurface7_iface
;
795 ddraw_surface7_AddRef(*Surface
);
796 wined3d_mutex_unlock();
801 TRACE("(%p) Didn't find a valid surface\n", This
);
803 wined3d_mutex_unlock();
806 return DDERR_NOTFOUND
;
809 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
810 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
812 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
813 struct ddraw_surface
*attachment_impl
;
814 IDirectDrawSurface7
*attachment7
;
817 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
819 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
826 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
827 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
828 ddraw_surface4_AddRef(*attachment
);
829 ddraw_surface7_Release(attachment7
);
834 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
835 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
837 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
838 struct ddraw_surface
*attachment_impl
;
839 IDirectDrawSurface7
*attachment7
;
843 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
845 caps2
.dwCaps
= caps
->dwCaps
;
848 caps2
.u1
.dwCaps4
= 0;
850 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
851 &caps2
, &attachment7
);
857 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
858 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
859 ddraw_surface3_AddRef(*attachment
);
860 ddraw_surface7_Release(attachment7
);
865 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
866 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
868 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
869 struct ddraw_surface
*attachment_impl
;
870 IDirectDrawSurface7
*attachment7
;
874 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
876 caps2
.dwCaps
= caps
->dwCaps
;
879 caps2
.u1
.dwCaps4
= 0;
881 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
882 &caps2
, &attachment7
);
888 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
889 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
890 ddraw_surface2_AddRef(*attachment
);
891 ddraw_surface7_Release(attachment7
);
896 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
897 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
899 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
900 struct ddraw_surface
*attachment_impl
;
901 IDirectDrawSurface7
*attachment7
;
905 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
907 caps2
.dwCaps
= caps
->dwCaps
;
910 caps2
.u1
.dwCaps4
= 0;
912 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
913 &caps2
, &attachment7
);
919 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
920 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
921 ddraw_surface1_AddRef(*attachment
);
922 ddraw_surface7_Release(attachment7
);
927 /*****************************************************************************
928 * IDirectDrawSurface7::Lock
930 * Locks the surface and returns a pointer to the surface's memory
933 * Rect: Rectangle to lock. If NULL, the whole surface is locked
934 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
935 * Flags: Locking flags, e.g Read only or write only
936 * h: An event handle that's not used and must be NULL
940 * DDERR_INVALIDPARAMS if DDSD is NULL
941 * For more details, see IWineD3DSurface::LockRect
943 *****************************************************************************/
944 static HRESULT
surface_lock(struct ddraw_surface
*surface
,
945 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
947 struct wined3d_box box
;
948 struct wined3d_map_desc map_desc
;
951 TRACE("surface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
952 surface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
954 /* surface->surface_desc.dwWidth and dwHeight are changeable, thus lock */
955 wined3d_mutex_lock();
957 /* Should I check for the handle to be NULL?
959 * The DDLOCK flags and the D3DLOCK flags are equal
960 * for the supported values. The others are ignored by WineD3D
963 /* Windows zeroes this if the rect is invalid */
964 surface_desc
->lpSurface
= NULL
;
968 if ((rect
->left
< 0) || (rect
->top
< 0)
969 || (rect
->left
> rect
->right
) || (rect
->right
> surface
->surface_desc
.dwWidth
)
970 || (rect
->top
> rect
->bottom
) || (rect
->bottom
> surface
->surface_desc
.dwHeight
))
972 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
973 wined3d_mutex_unlock();
974 return DDERR_INVALIDPARAMS
;
976 box
.left
= rect
->left
;
978 box
.right
= rect
->right
;
979 box
.bottom
= rect
->bottom
;
984 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
985 hr
= ddraw_surface_update_frontbuffer(surface
, rect
, TRUE
);
987 hr
= wined3d_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
),
988 surface
->sub_resource_idx
, &map_desc
, rect
? &box
: NULL
, flags
);
991 wined3d_mutex_unlock();
994 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
995 * specific error. But since IWineD3DSurface::LockRect returns that error in this
996 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
997 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
998 * is much easier to do it in one place in ddraw
1000 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1005 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1007 if (flags
& DDLOCK_READONLY
)
1008 memset(&surface
->ddraw
->primary_lock
, 0, sizeof(surface
->ddraw
->primary_lock
));
1010 surface
->ddraw
->primary_lock
= *rect
;
1012 SetRect(&surface
->ddraw
->primary_lock
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
1015 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1016 DD_STRUCT_COPY_BYSIZE(surface_desc
, &surface
->surface_desc
);
1017 surface_desc
->lpSurface
= map_desc
.data
;
1019 TRACE("locked surface returning description :\n");
1020 if (TRACE_ON(ddraw
))
1021 DDRAW_dump_surface_desc(surface_desc
);
1023 wined3d_mutex_unlock();
1028 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1029 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1031 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1033 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1034 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1036 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1037 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1038 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1040 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1041 return DDERR_INVALIDPARAMS
;
1043 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1046 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1047 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1049 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1051 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1052 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1054 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1055 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1056 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1058 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1059 return DDERR_INVALIDPARAMS
;
1061 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1064 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1065 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1067 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1068 DDSURFACEDESC2 surface_desc2
;
1071 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1072 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1074 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1075 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1076 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1078 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1079 return DDERR_INVALIDPARAMS
;
1082 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1083 surface_desc2
.dwFlags
= 0;
1084 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1085 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1086 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1090 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1091 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1093 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1094 DDSURFACEDESC2 surface_desc2
;
1097 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1098 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1100 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1101 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1102 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1104 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1105 return DDERR_INVALIDPARAMS
;
1108 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1109 surface_desc2
.dwFlags
= 0;
1110 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1111 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1112 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1116 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1117 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1119 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1120 DDSURFACEDESC2 surface_desc2
;
1122 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1123 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1125 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1126 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1127 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1129 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1130 return DDERR_INVALIDPARAMS
;
1133 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1134 surface_desc2
.dwFlags
= 0;
1135 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1136 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1137 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1141 /*****************************************************************************
1142 * IDirectDrawSurface7::Unlock
1144 * Unlocks an locked surface
1147 * Rect: Not used by this implementation
1151 * For more details, see IWineD3DSurface::UnlockRect
1153 *****************************************************************************/
1154 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1156 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1159 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1161 wined3d_mutex_lock();
1162 hr
= wined3d_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), surface
->sub_resource_idx
);
1163 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1164 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1165 wined3d_mutex_unlock();
1170 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1172 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1174 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1176 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1179 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1181 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1183 TRACE("iface %p, data %p.\n", iface
, data
);
1185 /* data might not be the LPRECT of later versions, so drop it. */
1186 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1189 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1191 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1193 TRACE("iface %p, data %p.\n", iface
, data
);
1195 /* data might not be the LPRECT of later versions, so drop it. */
1196 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1199 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1201 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1203 TRACE("iface %p, data %p.\n", iface
, data
);
1205 /* data might not be the LPRECT of later versions, so drop it. */
1206 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1209 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1210 IDirectDrawSurface7
*src
, DWORD flags
)
1212 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1213 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1214 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1215 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1216 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1217 struct wined3d_texture
*texture
;
1218 IDirectDrawSurface7
*current
;
1221 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1223 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1224 return DDERR_NOTFLIPPABLE
;
1226 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1227 return DDERR_SURFACELOST
;
1229 wined3d_mutex_lock();
1231 if (!(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1233 WARN("Not in exclusive mode.\n");
1234 wined3d_mutex_unlock();
1235 return DDERR_NOEXCLUSIVEMODE
;
1238 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1239 if (dst_impl
->sub_resource_idx
)
1240 ERR("Invalid sub-resource index %u on surface %p.\n", dst_impl
->sub_resource_idx
, dst_impl
);
1241 texture
= dst_impl
->wined3d_texture
;
1242 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1243 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1247 for (current
= iface
; current
!= src
;)
1249 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1251 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1252 wined3d_mutex_unlock();
1253 return DDERR_NOTFLIPPABLE
;
1255 ddraw_surface7_Release(current
);
1256 if (current
== iface
)
1258 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1259 wined3d_mutex_unlock();
1260 return DDERR_NOTFLIPPABLE
;
1264 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1265 if (rtv
== dst_impl
->wined3d_rtv
)
1266 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1267 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1268 dst_impl
->wined3d_rtv
= src_rtv
;
1269 wined3d_resource_set_parent(wined3d_texture_get_sub_resource(src_impl
->wined3d_texture
, 0), dst_impl
);
1270 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1271 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1272 if (src_impl
->sub_resource_idx
)
1273 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1274 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1275 ddraw_texture
= prev_ddraw_texture
;
1279 for (current
= iface
;;)
1281 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1283 ERR("Can't find a flip target\n");
1284 wined3d_mutex_unlock();
1285 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1287 ddraw_surface7_Release(current
);
1288 if (current
== iface
)
1290 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1294 src_impl
= impl_from_IDirectDrawSurface7(current
);
1295 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1296 if (rtv
== dst_impl
->wined3d_rtv
)
1297 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1298 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1299 dst_impl
->wined3d_rtv
= src_rtv
;
1300 wined3d_resource_set_parent(wined3d_texture_get_sub_resource(src_impl
->wined3d_texture
, 0), dst_impl
);
1301 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1302 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1303 ddraw_texture
= prev_ddraw_texture
;
1304 if (src_impl
->sub_resource_idx
)
1305 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1306 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1307 dst_impl
= src_impl
;
1311 /* We don't have to worry about potential texture bindings, since
1312 * flippable surfaces can never be textures. */
1313 if (rtv
== src_impl
->wined3d_rtv
)
1314 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1315 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1316 src_impl
->wined3d_rtv
= tmp_rtv
;
1317 wined3d_resource_set_parent(wined3d_texture_get_sub_resource(texture
, 0), src_impl
);
1318 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1319 src_impl
->wined3d_texture
= texture
;
1325 FIXME("Ignoring flags %#x.\n", flags
);
1327 WARN("Ignoring flags %#x.\n", flags
);
1330 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1331 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1335 wined3d_mutex_unlock();
1340 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1341 IDirectDrawSurface4
*dst
, DWORD flags
)
1343 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1344 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1346 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1348 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1349 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1352 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1353 IDirectDrawSurface3
*dst
, DWORD flags
)
1355 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1356 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1358 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1360 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1361 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1364 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1365 IDirectDrawSurface2
*dst
, DWORD flags
)
1367 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1368 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1370 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1372 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1373 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1376 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1377 IDirectDrawSurface
*dst
, DWORD flags
)
1379 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1380 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1382 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1384 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1385 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1388 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1389 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1390 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1392 struct wined3d_texture
*wined3d_src_texture
;
1393 unsigned int src_sub_resource_idx
;
1394 RECT src_rect
, dst_rect
;
1395 float scale_x
, scale_y
;
1396 const RECT
*clip_rect
;
1397 UINT clip_list_size
;
1406 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1407 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1411 dst_rect
= *dst_rect_in
;
1414 if (IsRectEmpty(&dst_rect
))
1415 return DDERR_INVALIDRECT
;
1423 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1424 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1428 src_rect
= *src_rect_in
;
1431 if (IsRectEmpty(&src_rect
))
1432 return DDERR_INVALIDRECT
;
1434 wined3d_src_texture
= src_surface
->wined3d_texture
;
1435 src_sub_resource_idx
= src_surface
->sub_resource_idx
;
1439 SetRect(&src_rect
, 0, 0, 0, 0);
1440 wined3d_src_texture
= NULL
;
1441 src_sub_resource_idx
= 0;
1444 if (!dst_surface
->clipper
)
1446 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1447 hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect
, TRUE
);
1449 hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
, &dst_rect
,
1450 wined3d_src_texture
, src_sub_resource_idx
, &src_rect
, flags
, fx
, filter
);
1451 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1452 hr
= ddraw_surface_update_frontbuffer(dst_surface
, &dst_rect
, FALSE
);
1457 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1458 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1460 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1461 &dst_rect
, NULL
, &clip_list_size
)))
1463 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1467 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1469 WARN("Failed to allocate clip list.\n");
1470 return E_OUTOFMEMORY
;
1473 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1474 &dst_rect
, clip_list
, &clip_list_size
)))
1476 WARN("Failed to get clip list, hr %#x.\n", hr
);
1477 HeapFree(GetProcessHeap(), 0, clip_list
);
1481 clip_rect
= (RECT
*)clip_list
->Buffer
;
1482 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1484 RECT src_rect_clipped
= src_rect
;
1488 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1489 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1490 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1491 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1493 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1495 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1500 if (FAILED(hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
,
1501 &clip_rect
[i
], wined3d_src_texture
, src_sub_resource_idx
, &src_rect_clipped
, flags
, fx
, filter
)))
1504 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1506 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1511 HeapFree(GetProcessHeap(), 0, clip_list
);
1515 /*****************************************************************************
1516 * IDirectDrawSurface7::Blt
1518 * Performs a blit on the surface
1521 * DestRect: Destination rectangle, can be NULL
1522 * SrcSurface: Source surface, can be NULL
1523 * SrcRect: Source rectangle, can be NULL
1525 * DDBltFx: Some extended blt parameters, connected to the flags
1529 * See IWineD3DSurface::Blt for more details
1531 *****************************************************************************/
1532 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*dst_rect
,
1533 IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1535 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1536 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
1537 struct wined3d_blt_fx wined3d_fx
;
1541 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1542 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1544 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1545 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1547 if ((flags
& DDBLT_KEYSRCOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYSRC
))
1549 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1550 return DDERR_INVALIDPARAMS
;
1553 if ((flags
& DDBLT_KEYDESTOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYDEST
))
1555 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1556 return DDERR_INVALIDPARAMS
;
1559 if (flags
& DDBLT_DDROPS
)
1561 FIXME("DDBLT_DDROPS not implemented.\n");
1563 FIXME(" rop %#x, pattern %p.\n", fx
->dwDDROP
, fx
->u5
.lpDDSPattern
);
1564 return DDERR_NORASTEROPHW
;
1567 wined3d_mutex_lock();
1569 if (flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1571 if (flags
& DDBLT_ROP
)
1573 wined3d_mutex_unlock();
1574 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1575 return DDERR_INVALIDPARAMS
;
1579 wined3d_mutex_unlock();
1580 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1581 return DDERR_INVALIDPARAMS
;
1585 wined3d_mutex_unlock();
1586 WARN("Depth or colorfill used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1587 return DDERR_INVALIDPARAMS
;
1590 if ((flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1591 flags
&= ~DDBLT_DEPTHFILL
;
1593 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_COLORFILL
))
1595 wined3d_mutex_unlock();
1596 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1597 return DDERR_INVALIDPARAMS
;
1599 if (!(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_DEPTHFILL
))
1601 wined3d_mutex_unlock();
1602 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1603 return DDERR_INVALIDPARAMS
;
1607 if (flags
& DDBLT_ROP
)
1611 wined3d_mutex_unlock();
1612 WARN("DDBLT_ROP used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1613 return DDERR_INVALIDPARAMS
;
1616 flags
&= ~DDBLT_ROP
;
1626 if (fx
->dwROP
== WHITENESS
)
1627 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1629 rop_fx
.u5
.dwFillColor
= 0;
1631 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1632 flags
|= DDBLT_DEPTHFILL
;
1634 flags
|= DDBLT_COLORFILL
;
1640 wined3d_mutex_unlock();
1641 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", fx
->dwROP
);
1642 return DDERR_NORASTEROPHW
;
1646 if (flags
& DDBLT_KEYSRC
&& (!src_impl
|| !(src_impl
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1648 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1649 wined3d_mutex_unlock();
1650 return DDERR_INVALIDPARAMS
;
1653 if (flags
& ~WINED3D_BLT_MASK
)
1655 wined3d_mutex_unlock();
1656 FIXME("Unhandled flags %#x.\n", flags
);
1662 wined3d_fx
.fx
= fx
->dwDDFX
;
1663 wined3d_fx
.fill_color
= fx
->u5
.dwFillColor
;
1664 wined3d_fx
.dst_color_key
.color_space_low_value
= fx
->ddckDestColorkey
.dwColorSpaceLowValue
;
1665 wined3d_fx
.dst_color_key
.color_space_high_value
= fx
->ddckDestColorkey
.dwColorSpaceHighValue
;
1666 wined3d_fx
.src_color_key
.color_space_low_value
= fx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
1667 wined3d_fx
.src_color_key
.color_space_high_value
= fx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
1670 hr
= ddraw_surface_blt_clipped(dst_impl
, dst_rect
, src_impl
,
1671 src_rect
, flags
, fx
? &wined3d_fx
: NULL
, WINED3D_TEXF_LINEAR
);
1673 wined3d_mutex_unlock();
1676 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1681 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1682 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1684 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1685 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1687 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1688 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1690 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1691 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1694 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1695 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1697 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1698 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1700 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1701 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1703 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1704 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1707 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1708 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1710 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1711 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1713 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1714 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1716 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1717 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1720 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1721 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1723 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1724 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1726 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1727 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1729 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1730 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1733 /*****************************************************************************
1734 * IDirectDrawSurface7::AddAttachedSurface
1736 * Attaches a surface to another surface. How the surface attachments work
1737 * is not totally understood yet, and this method is prone to problems.
1738 * The surface that is attached is AddRef-ed.
1740 * Tests with complex surfaces suggest that the surface attachments form a
1741 * tree, but no method to test this has been found yet.
1743 * The attachment list consists of a first surface (first_attached) and
1744 * for each surface a pointer to the next attached surface (next_attached).
1745 * For the first surface, and a surface that has no attachments
1746 * first_attached points to the surface itself. A surface that has
1747 * no successors in the chain has next_attached set to NULL.
1749 * Newly attached surfaces are attached right after the root surface.
1750 * If a surface is attached to a complex surface compound, it's attached to
1751 * the surface that the app requested, not the complex root. See
1752 * GetAttachedSurface for a description how surfaces are found.
1754 * This is how the current implementation works, and it was coded by looking
1755 * at the needs of the applications.
1757 * So far only Z-Buffer attachments are tested, and they are activated in
1758 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1759 * Back buffers should work in 2D mode, but they are not tested(They can be
1760 * attached in older iface versions). Rendering to the front buffer and
1761 * switching between that and double buffering is not yet implemented in
1762 * WineD3D, so for 3D it might have unexpected results.
1764 * ddraw_surface_attach_surface is the real thing,
1765 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1766 * performs additional checks. Version 7 of this interface is much more restrictive
1767 * than its predecessors.
1770 * Attach: Surface to attach to iface
1774 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1776 *****************************************************************************/
1777 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1779 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1782 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1784 wined3d_mutex_lock();
1786 /* Check if the surface is already attached somewhere */
1787 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1789 /* TODO: Test for the structure of the manual attachment. Is it a
1790 * chain or a list? What happens if one surface is attached to 2
1791 * different surfaces? */
1792 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1793 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1795 wined3d_mutex_unlock();
1796 return DDERR_SURFACEALREADYATTACHED
;
1799 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1800 Surf
->next_attached
= This
->next_attached
;
1801 Surf
->first_attached
= This
->first_attached
;
1802 This
->next_attached
= Surf
;
1804 /* Check if the WineD3D depth stencil needs updating */
1805 if (This
->ddraw
->d3ddevice
)
1806 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1808 wined3d_mutex_unlock();
1813 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1815 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1816 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1819 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1821 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1822 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1825 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1826 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1827 return DDERR_CANNOTATTACHSURFACE
;
1830 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1835 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1836 IUnknown_AddRef(attachment_impl
->attached_iface
);
1840 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1842 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1843 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1846 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1848 /* Tests suggest that
1849 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1850 * -> offscreen plain surfaces can be attached to primaries
1851 * -> primaries can be attached to offscreen plain surfaces
1852 * -> z buffers can be attached to primaries */
1853 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1854 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1856 /* Sizes have to match */
1857 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1858 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1860 WARN("Surface sizes do not match.\n");
1861 return DDERR_CANNOTATTACHSURFACE
;
1864 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1865 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1867 WARN("Invalid attachment combination.\n");
1868 return DDERR_CANNOTATTACHSURFACE
;
1871 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1874 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1875 IUnknown_AddRef(attachment_impl
->attached_iface
);
1879 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1881 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1882 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1885 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1887 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1888 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1891 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1892 IUnknown_AddRef(attachment_impl
->attached_iface
);
1893 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1897 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1899 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1900 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1903 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1905 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1906 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1909 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1910 IUnknown_AddRef(attachment_impl
->attached_iface
);
1911 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1915 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1917 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1918 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1921 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1923 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1924 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1927 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1928 IUnknown_AddRef(attachment_impl
->attached_iface
);
1929 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1933 /*****************************************************************************
1934 * IDirectDrawSurface7::DeleteAttachedSurface
1936 * Removes a surface from the attachment chain. The surface's refcount
1937 * is decreased by one after it has been removed
1940 * Flags: Some flags, not used by this implementation
1941 * Attach: Surface to detach
1945 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1947 *****************************************************************************/
1948 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1949 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1951 struct ddraw_surface
*prev
= surface
;
1953 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1955 wined3d_mutex_lock();
1956 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1958 wined3d_mutex_unlock();
1959 return DDERR_CANNOTDETACHSURFACE
;
1962 if (attachment
->attached_iface
!= detach_iface
)
1964 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1965 wined3d_mutex_unlock();
1966 return DDERR_SURFACENOTATTACHED
;
1969 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1970 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1972 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1973 /* FIXME: we should probably also subtract from dwMipMapCount of this
1974 * and all parent surfaces */
1977 /* Find the predecessor of the detached surface */
1980 if (prev
->next_attached
== attachment
)
1982 prev
= prev
->next_attached
;
1985 /* There must be a surface, otherwise there's a bug */
1988 /* Unchain the surface */
1989 prev
->next_attached
= attachment
->next_attached
;
1990 attachment
->next_attached
= NULL
;
1991 attachment
->first_attached
= attachment
;
1993 /* Check if the wined3d depth stencil needs updating. */
1994 if (surface
->ddraw
->d3ddevice
)
1995 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1996 wined3d_mutex_unlock();
1998 /* Set attached_iface to NULL before releasing it, the surface may go
2000 attachment
->attached_iface
= NULL
;
2001 IUnknown_Release(detach_iface
);
2006 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
2007 DWORD flags
, IDirectDrawSurface7
*attachment
)
2009 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2010 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2012 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2014 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2017 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2018 DWORD flags
, IDirectDrawSurface4
*attachment
)
2020 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2021 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2023 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2025 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2028 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2029 DWORD flags
, IDirectDrawSurface3
*attachment
)
2031 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2032 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2034 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2036 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2039 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2040 DWORD flags
, IDirectDrawSurface2
*attachment
)
2042 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2043 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2045 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2047 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2050 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2051 DWORD flags
, IDirectDrawSurface
*attachment
)
2053 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2054 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2056 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2058 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2061 /*****************************************************************************
2062 * IDirectDrawSurface7::AddOverlayDirtyRect
2064 * "This method is not currently implemented"
2072 *****************************************************************************/
2073 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2075 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2077 return DDERR_UNSUPPORTED
; /* unchecked */
2080 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2082 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2084 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2086 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2089 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2091 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2093 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2095 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2098 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2102 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2104 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2107 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2109 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2111 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2113 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2116 /*****************************************************************************
2117 * IDirectDrawSurface7::GetDC
2119 * Returns a GDI device context for the surface
2122 * hdc: Address of a HDC variable to store the dc to
2126 * DDERR_INVALIDPARAMS if hdc is NULL
2127 * For details, see IWineD3DSurface::GetDC
2129 *****************************************************************************/
2130 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2132 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2135 TRACE("iface %p, dc %p.\n", iface
, dc
);
2138 return DDERR_INVALIDPARAMS
;
2140 wined3d_mutex_lock();
2141 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2142 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2144 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, dc
);
2150 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2152 const struct ddraw_palette
*palette
;
2154 if (surface
->palette
)
2155 palette
= surface
->palette
;
2156 else if (surface
->ddraw
->primary
)
2157 palette
= surface
->ddraw
->primary
->palette
;
2162 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *dc
);
2166 wined3d_mutex_unlock();
2169 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2170 * does not touch *dc. */
2171 case WINED3DERR_INVALIDCALL
:
2173 return DDERR_INVALIDPARAMS
;
2180 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2182 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2184 TRACE("iface %p, dc %p.\n", iface
, dc
);
2186 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2189 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2191 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2193 TRACE("iface %p, dc %p.\n", iface
, dc
);
2195 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2198 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2200 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2202 TRACE("iface %p, dc %p.\n", iface
, dc
);
2204 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2207 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2209 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2211 TRACE("iface %p, dc %p.\n", iface
, dc
);
2213 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2216 /*****************************************************************************
2217 * IDirectDrawSurface7::ReleaseDC
2219 * Releases the DC that was constructed with GetDC
2222 * hdc: HDC to release
2226 * For more details, see IWineD3DSurface::ReleaseDC
2228 *****************************************************************************/
2229 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2231 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2234 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2236 wined3d_mutex_lock();
2237 if (SUCCEEDED(hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, hdc
)))
2240 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2241 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2243 wined3d_mutex_unlock();
2249 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2253 TRACE("iface %p, dc %p.\n", iface
, dc
);
2255 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2258 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2262 TRACE("iface %p, dc %p.\n", iface
, dc
);
2264 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2267 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2269 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2271 TRACE("iface %p, dc %p.\n", iface
, dc
);
2273 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2276 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2278 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2280 TRACE("iface %p, dc %p.\n", iface
, dc
);
2282 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2285 /*****************************************************************************
2286 * IDirectDrawSurface7::GetCaps
2288 * Returns the surface's caps
2291 * Caps: Address to write the caps to
2295 * DDERR_INVALIDPARAMS if Caps is NULL
2297 *****************************************************************************/
2298 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2300 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2302 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2305 return DDERR_INVALIDPARAMS
;
2307 *Caps
= surface
->surface_desc
.ddsCaps
;
2312 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2314 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2316 TRACE("iface %p, caps %p.\n", iface
, caps
);
2318 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2321 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2323 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2327 TRACE("iface %p, caps %p.\n", iface
, caps
);
2329 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2330 if (FAILED(hr
)) return hr
;
2332 caps
->dwCaps
= caps2
.dwCaps
;
2336 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2338 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2342 TRACE("iface %p, caps %p.\n", iface
, caps
);
2344 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2345 if (FAILED(hr
)) return hr
;
2347 caps
->dwCaps
= caps2
.dwCaps
;
2351 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2353 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2357 TRACE("iface %p, caps %p.\n", iface
, caps
);
2359 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2360 if (FAILED(hr
)) return hr
;
2362 caps
->dwCaps
= caps2
.dwCaps
;
2366 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2368 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2369 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2371 struct wined3d_resource
*resource
;
2373 TRACE("iface %p, priority %u.\n", iface
, priority
);
2375 wined3d_mutex_lock();
2376 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2377 * calls on such surfaces segfault on Windows. */
2378 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2380 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2381 hr
= DDERR_INVALIDPARAMS
;
2385 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2386 wined3d_resource_set_priority(resource
, priority
);
2389 wined3d_mutex_unlock();
2394 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2396 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2397 const struct wined3d_resource
*resource
;
2398 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2401 TRACE("iface %p, priority %p.\n", iface
, priority
);
2403 wined3d_mutex_lock();
2404 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2406 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2407 hr
= DDERR_INVALIDOBJECT
;
2409 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2411 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2412 hr
= DDERR_INVALIDPARAMS
;
2416 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2417 *priority
= wined3d_resource_get_priority(resource
);
2420 wined3d_mutex_unlock();
2425 /*****************************************************************************
2426 * IDirectDrawSurface7::SetPrivateData
2428 * Stores some data in the surface that is intended for the application's
2432 * tag: GUID that identifies the data
2433 * Data: Pointer to the private data
2434 * Size: Size of the private data
2439 * For more details, see IWineD3DSurface::SetPrivateData
2441 *****************************************************************************/
2442 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2443 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2445 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2448 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2449 iface
, debugstr_guid(tag
), data
, size
, flags
);
2453 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2454 return DDERR_INVALIDPARAMS
;
2457 wined3d_mutex_lock();
2458 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2459 wined3d_mutex_unlock();
2460 return hr_ddraw_from_wined3d(hr
);
2463 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2464 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2466 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2468 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2469 iface
, debugstr_guid(tag
), data
, size
, flags
);
2471 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2474 /*****************************************************************************
2475 * IDirectDrawSurface7::GetPrivateData
2477 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2480 * tag: GUID of the data to return
2481 * Data: Address where to write the data to
2482 * Size: Size of the buffer at Data
2486 * DDERR_INVALIDPARAMS if Data is NULL
2487 * For more details, see IWineD3DSurface::GetPrivateData
2489 *****************************************************************************/
2490 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2492 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2493 const struct wined3d_private_data
*stored_data
;
2496 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2497 iface
, debugstr_guid(tag
), data
, size
);
2499 wined3d_mutex_lock();
2500 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2503 hr
= DDERR_NOTFOUND
;
2508 hr
= DDERR_INVALIDPARAMS
;
2511 if (*size
< stored_data
->size
)
2513 *size
= stored_data
->size
;
2514 hr
= DDERR_MOREDATA
;
2519 hr
= DDERR_INVALIDPARAMS
;
2523 *size
= stored_data
->size
;
2524 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2528 wined3d_mutex_unlock();
2532 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2534 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2536 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2537 iface
, debugstr_guid(tag
), data
, size
);
2539 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2542 /*****************************************************************************
2543 * IDirectDrawSurface7::FreePrivateData
2545 * Frees private data stored in the surface
2548 * tag: Tag of the data to free
2552 * For more details, see IWineD3DSurface::FreePrivateData
2554 *****************************************************************************/
2555 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2557 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2558 struct wined3d_private_data
*entry
;
2560 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2562 wined3d_mutex_lock();
2563 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2566 wined3d_mutex_unlock();
2567 return DDERR_NOTFOUND
;
2570 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2571 wined3d_mutex_unlock();
2576 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2578 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2580 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2582 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2585 /*****************************************************************************
2586 * IDirectDrawSurface7::PageLock
2588 * Prevents a sysmem surface from being paged out
2591 * Flags: Not used, must be 0(unchecked)
2594 * DD_OK, because it's a stub
2596 *****************************************************************************/
2597 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2599 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2601 /* This is Windows memory management related - we don't need this */
2605 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2607 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2609 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2611 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2614 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2616 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2618 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2620 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2623 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2625 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2627 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2629 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2632 /*****************************************************************************
2633 * IDirectDrawSurface7::PageUnlock
2635 * Allows a sysmem surface to be paged out
2638 * Flags: Not used, must be 0(unchecked)
2641 * DD_OK, because it's a stub
2643 *****************************************************************************/
2644 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2646 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2651 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2653 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2655 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2657 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2660 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2662 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2664 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2666 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2669 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2671 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2673 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2675 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2678 /*****************************************************************************
2679 * IDirectDrawSurface7::BltBatch
2681 * An unimplemented function
2689 *****************************************************************************/
2690 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2692 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2694 /* MSDN: "not currently implemented" */
2695 return DDERR_UNSUPPORTED
;
2698 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2700 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2702 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2704 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2707 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2709 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2711 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2713 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2716 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2718 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2720 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2722 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2725 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2727 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2729 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2731 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2734 /*****************************************************************************
2735 * IDirectDrawSurface7::EnumAttachedSurfaces
2737 * Enumerates all surfaces attached to this surface
2740 * context: Pointer to pass unmodified to the callback
2741 * cb: Callback function to call for each surface
2745 * DDERR_INVALIDPARAMS if cb is NULL
2747 *****************************************************************************/
2748 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2749 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2751 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2752 struct ddraw_surface
*surf
;
2753 DDSURFACEDESC2 desc
;
2756 /* Attached surfaces aren't handled in WineD3D */
2757 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2760 return DDERR_INVALIDPARAMS
;
2762 wined3d_mutex_lock();
2764 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2766 surf
= surface
->complex_array
[i
];
2769 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2770 desc
= surf
->surface_desc
;
2771 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2772 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2774 wined3d_mutex_unlock();
2779 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2781 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2782 desc
= surf
->surface_desc
;
2783 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2784 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2786 wined3d_mutex_unlock();
2791 TRACE(" end of enumeration.\n");
2793 wined3d_mutex_unlock();
2798 struct callback_info2
2800 LPDDENUMSURFACESCALLBACK2 callback
;
2804 struct callback_info
2806 LPDDENUMSURFACESCALLBACK callback
;
2810 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2812 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2813 const struct callback_info2
*info
= context
;
2815 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2816 ddraw_surface7_Release(surface
);
2818 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2821 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2823 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2824 const struct callback_info
*info
= context
;
2826 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2827 ddraw_surface7_Release(surface
);
2829 /* FIXME: Check surface_test.dwSize */
2830 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2831 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2834 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2835 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2837 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2838 struct callback_info2 info
;
2840 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2842 info
.callback
= callback
;
2843 info
.context
= context
;
2845 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2846 &info
, EnumCallback2
);
2849 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2850 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2852 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2853 struct callback_info info
;
2855 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2857 info
.callback
= callback
;
2858 info
.context
= context
;
2860 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2861 &info
, EnumCallback
);
2864 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2865 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2867 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2868 struct callback_info info
;
2870 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2872 info
.callback
= callback
;
2873 info
.context
= context
;
2875 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2876 &info
, EnumCallback
);
2879 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2880 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2882 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2883 struct callback_info info
;
2885 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2887 info
.callback
= callback
;
2888 info
.context
= context
;
2890 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2891 &info
, EnumCallback
);
2894 /*****************************************************************************
2895 * IDirectDrawSurface7::EnumOverlayZOrders
2897 * "Enumerates the overlay surfaces on the specified destination"
2900 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2901 * context: context to pass back to the callback
2902 * cb: callback function to call for each enumerated surface
2905 * DD_OK, because it's a stub
2907 *****************************************************************************/
2908 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2909 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2911 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2916 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2917 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2919 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2920 struct callback_info2 info
;
2922 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2924 info
.callback
= callback
;
2925 info
.context
= context
;
2927 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2928 flags
, &info
, EnumCallback2
);
2931 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2932 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2934 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2935 struct callback_info info
;
2937 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2939 info
.callback
= callback
;
2940 info
.context
= context
;
2942 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2943 flags
, &info
, EnumCallback
);
2946 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2947 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2949 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2950 struct callback_info info
;
2952 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2954 info
.callback
= callback
;
2955 info
.context
= context
;
2957 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2958 flags
, &info
, EnumCallback
);
2961 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2962 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2964 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2965 struct callback_info info
;
2967 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2969 info
.callback
= callback
;
2970 info
.context
= context
;
2972 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2973 flags
, &info
, EnumCallback
);
2976 /*****************************************************************************
2977 * IDirectDrawSurface7::GetBltStatus
2979 * Returns the blitting status
2982 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2985 * See IWineD3DSurface::Blt
2987 *****************************************************************************/
2988 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2990 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2994 case WINEDDGBS_CANBLT
:
2995 case WINEDDGBS_ISBLTDONE
:
2999 return DDERR_INVALIDPARAMS
;
3003 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3005 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3007 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3009 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3012 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3014 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3016 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3018 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3021 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3023 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3025 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3027 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3030 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3032 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3034 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3036 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3039 /*****************************************************************************
3040 * IDirectDrawSurface7::GetColorKey
3042 * Returns the color key assigned to the surface
3046 * CKey: Address to store the key to
3050 * DDERR_INVALIDPARAMS if CKey is NULL
3052 *****************************************************************************/
3053 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3055 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3057 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3060 return DDERR_INVALIDPARAMS
;
3062 wined3d_mutex_lock();
3066 case DDCKEY_DESTBLT
:
3067 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3069 wined3d_mutex_unlock();
3070 return DDERR_NOCOLORKEY
;
3072 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3075 case DDCKEY_DESTOVERLAY
:
3076 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3078 wined3d_mutex_unlock();
3079 return DDERR_NOCOLORKEY
;
3081 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3085 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3087 wined3d_mutex_unlock();
3088 return DDERR_NOCOLORKEY
;
3090 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3093 case DDCKEY_SRCOVERLAY
:
3094 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3096 wined3d_mutex_unlock();
3097 return DDERR_NOCOLORKEY
;
3099 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3103 wined3d_mutex_unlock();
3104 return DDERR_INVALIDPARAMS
;
3107 wined3d_mutex_unlock();
3112 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3114 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3116 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3118 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3121 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3123 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3125 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3127 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3130 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3132 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3134 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3136 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3139 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3141 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3143 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3145 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3148 /*****************************************************************************
3149 * IDirectDrawSurface7::GetFlipStatus
3151 * Returns the flipping status of the surface
3154 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3157 * See IWineD3DSurface::GetFlipStatus
3159 *****************************************************************************/
3160 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3162 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3164 /* XXX: DDERR_INVALIDSURFACETYPE */
3168 case WINEDDGFS_CANFLIP
:
3169 case WINEDDGFS_ISFLIPDONE
:
3173 return DDERR_INVALIDPARAMS
;
3177 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3179 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3181 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3183 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3186 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3188 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3190 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3192 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3195 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3197 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3199 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3201 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3204 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3206 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3208 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3210 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3213 /*****************************************************************************
3214 * IDirectDrawSurface7::GetOverlayPosition
3216 * Returns the display coordinates of a visible and active overlay surface
3223 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3224 *****************************************************************************/
3225 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3227 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3230 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3232 wined3d_mutex_lock();
3233 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3234 surface
->sub_resource_idx
, x
, y
);
3235 wined3d_mutex_unlock();
3240 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3242 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3244 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3246 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3249 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3253 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3255 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3258 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3262 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3264 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3267 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3269 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3271 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3273 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3276 /*****************************************************************************
3277 * IDirectDrawSurface7::GetPixelFormat
3279 * Returns the pixel format of the Surface
3282 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3283 * format should be written
3287 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3289 *****************************************************************************/
3290 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3292 /* What is DDERR_INVALIDSURFACETYPE for here? */
3293 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3295 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3298 return DDERR_INVALIDPARAMS
;
3300 wined3d_mutex_lock();
3301 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3302 wined3d_mutex_unlock();
3307 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3309 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3311 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3313 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3316 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3318 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3320 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3322 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3325 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3327 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3329 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3331 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3334 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3336 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3338 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3340 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3343 /*****************************************************************************
3344 * IDirectDrawSurface7::GetSurfaceDesc
3346 * Returns the description of this surface
3349 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3354 * DDERR_INVALIDPARAMS if DDSD is NULL
3356 *****************************************************************************/
3357 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3359 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3361 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3364 return DDERR_INVALIDPARAMS
;
3366 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3368 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3369 return DDERR_INVALIDPARAMS
;
3372 wined3d_mutex_lock();
3373 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3374 TRACE("Returning surface desc:\n");
3375 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3376 wined3d_mutex_unlock();
3381 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3383 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3385 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3387 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3390 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3392 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3394 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3396 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3398 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3400 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3401 return DDERR_INVALIDPARAMS
;
3404 wined3d_mutex_lock();
3405 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3406 TRACE("Returning surface desc:\n");
3407 if (TRACE_ON(ddraw
))
3409 /* DDRAW_dump_surface_desc handles the smaller size */
3410 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3412 wined3d_mutex_unlock();
3417 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3419 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3421 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3423 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3426 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3428 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3430 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3432 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3435 /*****************************************************************************
3436 * IDirectDrawSurface7::Initialize
3438 * Initializes the surface. This is a no-op in Wine
3441 * DD: Pointer to an DirectDraw interface
3442 * DDSD: Surface description for initialization
3445 * DDERR_ALREADYINITIALIZED
3447 *****************************************************************************/
3448 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3449 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3451 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3453 return DDERR_ALREADYINITIALIZED
;
3456 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3457 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3459 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3461 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3463 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3464 ddraw
, surface_desc
);
3467 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3468 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3470 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3471 DDSURFACEDESC2 surface_desc2
;
3473 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3475 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3476 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3477 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3480 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3481 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3483 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3484 DDSURFACEDESC2 surface_desc2
;
3486 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3488 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3489 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3490 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3493 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3494 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3496 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3497 DDSURFACEDESC2 surface_desc2
;
3499 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3501 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3502 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3503 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3506 /*****************************************************************************
3507 * IDirect3DTexture1::Initialize
3509 * The sdk says it's not implemented
3517 *****************************************************************************/
3518 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3519 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3521 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3523 return DDERR_UNSUPPORTED
; /* Unchecked */
3526 /*****************************************************************************
3527 * IDirectDrawSurface7::IsLost
3529 * Checks if the surface is lost
3532 * DD_OK, if the surface is usable
3533 * DDERR_ISLOST if the surface is lost
3534 * See IWineD3DSurface::IsLost for more details
3536 *****************************************************************************/
3537 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3539 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3541 TRACE("iface %p.\n", iface
);
3543 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3544 return DDERR_SURFACELOST
;
3549 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3551 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3553 TRACE("iface %p.\n", iface
);
3555 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3558 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3560 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3562 TRACE("iface %p.\n", iface
);
3564 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3567 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3569 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3571 TRACE("iface %p.\n", iface
);
3573 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3576 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3578 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3580 TRACE("iface %p.\n", iface
);
3582 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3585 /*****************************************************************************
3586 * IDirectDrawSurface7::Restore
3588 * Restores a lost surface. This makes the surface usable again, but
3589 * doesn't reload its old contents
3593 * See IWineD3DSurface::Restore for more details
3595 *****************************************************************************/
3596 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3598 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3600 TRACE("iface %p.\n", iface
);
3602 ddraw_update_lost_surfaces(surface
->ddraw
);
3603 surface
->is_lost
= FALSE
;
3608 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3610 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3612 TRACE("iface %p.\n", iface
);
3614 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3617 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3619 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3621 TRACE("iface %p.\n", iface
);
3623 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3626 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3628 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3630 TRACE("iface %p.\n", iface
);
3632 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3635 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3637 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3639 TRACE("iface %p.\n", iface
);
3641 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3644 /*****************************************************************************
3645 * IDirectDrawSurface7::SetOverlayPosition
3647 * Changes the display coordinates of an overlay surface
3654 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3655 *****************************************************************************/
3656 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3658 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3661 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3663 wined3d_mutex_lock();
3664 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3665 surface
->sub_resource_idx
, x
, y
);
3666 wined3d_mutex_unlock();
3671 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3673 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3675 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3677 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3680 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3682 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3684 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3686 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3689 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3691 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3693 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3695 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3698 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3700 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3702 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3704 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3707 /*****************************************************************************
3708 * IDirectDrawSurface7::UpdateOverlay
3710 * Modifies the attributes of an overlay surface.
3713 * SrcRect: The section of the source being used for the overlay
3714 * DstSurface: Address of the surface that is overlaid
3715 * DstRect: Place of the overlay
3716 * Flags: some DDOVER_* flags
3719 * DDERR_UNSUPPORTED, because we don't support overlays
3721 *****************************************************************************/
3722 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3723 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3725 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3726 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3727 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3728 unsigned int dst_sub_resource_idx
= 0;
3731 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3732 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3735 FIXME("Ignoring fx %p.\n", fx
);
3737 wined3d_mutex_lock();
3740 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3741 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3743 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3744 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3745 wined3d_mutex_unlock();
3749 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3750 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3751 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3757 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3758 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3760 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3761 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3763 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3764 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3766 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3767 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3770 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3771 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3773 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3774 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3776 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3777 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3779 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3780 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3783 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3784 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3786 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3787 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3789 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3790 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3792 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3793 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3796 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3797 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3799 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3800 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3802 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3803 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3805 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3806 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3809 /*****************************************************************************
3810 * IDirectDrawSurface7::UpdateOverlayDisplay
3812 * The DX7 sdk says that it's not implemented
3817 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3819 *****************************************************************************/
3820 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3822 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3824 return DDERR_UNSUPPORTED
;
3827 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3829 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3831 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3833 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3836 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3838 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3840 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3842 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3845 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3847 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3849 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3851 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3854 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3856 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3858 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3860 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3863 /*****************************************************************************
3864 * IDirectDrawSurface7::UpdateOverlayZOrder
3866 * Sets an overlay's Z order
3869 * Flags: DDOVERZ_* flags
3870 * DDSRef: Defines the relative position in the overlay chain
3873 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3875 *****************************************************************************/
3876 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3877 DWORD flags
, IDirectDrawSurface7
*reference
)
3879 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3881 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
3883 wined3d_mutex_lock();
3884 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
3886 WARN("Not an overlay surface.\n");
3887 wined3d_mutex_unlock();
3888 return DDERR_NOTAOVERLAYSURFACE
;
3890 wined3d_mutex_unlock();
3895 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3896 DWORD flags
, IDirectDrawSurface4
*reference
)
3898 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3899 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3901 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3903 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3904 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3907 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3908 DWORD flags
, IDirectDrawSurface3
*reference
)
3910 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3911 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3913 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3915 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3916 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3919 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3920 DWORD flags
, IDirectDrawSurface2
*reference
)
3922 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3923 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3925 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3927 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3928 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3931 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3932 DWORD flags
, IDirectDrawSurface
*reference
)
3934 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3935 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3937 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3939 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3940 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3943 /*****************************************************************************
3944 * IDirectDrawSurface7::GetDDInterface
3946 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3947 * surface belongs to
3950 * DD: Address to write the interface pointer to
3954 * DDERR_INVALIDPARAMS if DD is NULL
3956 *****************************************************************************/
3957 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3959 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3961 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3964 return DDERR_INVALIDPARAMS
;
3966 switch(This
->version
)
3969 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3973 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3977 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3981 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3985 IUnknown_AddRef((IUnknown
*)*DD
);
3990 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3992 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3994 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3996 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3999 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
4001 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4003 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4005 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4008 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4010 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4012 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4014 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4017 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4019 TRACE("iface %p.\n", iface
);
4024 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4026 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4028 TRACE("iface %p.\n", iface
);
4030 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4033 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4035 TRACE("iface %p, value %p.\n", iface
, pValue
);
4042 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4044 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4046 TRACE("iface %p, value %p.\n", iface
, pValue
);
4048 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4051 /*****************************************************************************
4052 * IDirectDrawSurface7::SetLOD
4054 * Sets the level of detail of a texture
4057 * MaxLOD: LOD to set
4061 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4063 *****************************************************************************/
4064 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4066 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4069 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4071 wined3d_mutex_lock();
4072 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4074 wined3d_mutex_unlock();
4075 return DDERR_INVALIDOBJECT
;
4078 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4079 wined3d_mutex_unlock();
4084 /*****************************************************************************
4085 * IDirectDrawSurface7::GetLOD
4087 * Returns the level of detail of a Direct3D texture
4090 * MaxLOD: Address to write the LOD to
4094 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4095 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4097 *****************************************************************************/
4098 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4102 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4105 return DDERR_INVALIDPARAMS
;
4107 wined3d_mutex_lock();
4108 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4110 wined3d_mutex_unlock();
4111 return DDERR_INVALIDOBJECT
;
4114 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4115 wined3d_mutex_unlock();
4120 /*****************************************************************************
4121 * IDirectDrawSurface7::BltFast
4123 * Performs a fast Blit.
4126 * dstx: The x coordinate to blit to on the destination
4127 * dsty: The y coordinate to blit to on the destination
4128 * Source: The source surface
4129 * rsrc: The source rectangle
4130 * trans: Type of transfer. Some DDBLTFAST_* flags
4134 * For more details, see IWineD3DSurface::BltFast
4136 *****************************************************************************/
4137 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4138 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4140 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4141 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4142 DWORD src_w
, src_h
, dst_w
, dst_h
;
4147 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4148 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4150 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4151 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4155 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4159 src_w
= src_rect
->right
- src_rect
->left
;
4160 src_h
= src_rect
->bottom
- src_rect
->top
;
4161 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4162 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4164 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4165 return DDERR_INVALIDRECT
;
4168 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4169 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4170 flags
|= WINED3D_BLT_SRC_CKEY
;
4171 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4172 flags
|= WINED3D_BLT_DST_CKEY
;
4173 if (trans
& DDBLTFAST_WAIT
)
4174 flags
|= WINED3D_BLT_WAIT
;
4175 if (trans
& DDBLTFAST_DONOTWAIT
)
4176 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4178 wined3d_mutex_lock();
4179 if (dst_impl
->clipper
)
4181 wined3d_mutex_unlock();
4182 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4183 return DDERR_BLTFASTCANTCLIP
;
4186 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4187 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
);
4189 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
4190 src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4191 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4192 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
);
4193 wined3d_mutex_unlock();
4197 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4202 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4203 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4205 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4206 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4208 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4209 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4211 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4212 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4215 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4216 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4218 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4219 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4221 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4222 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4224 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4225 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4228 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4229 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4231 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4232 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4234 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4235 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4237 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4238 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4241 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4242 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4244 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4245 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4247 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4248 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4250 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4251 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4254 /*****************************************************************************
4255 * IDirectDrawSurface7::GetClipper
4257 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4261 * Clipper: Address to store the interface pointer at
4265 * DDERR_INVALIDPARAMS if Clipper is NULL
4266 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4268 *****************************************************************************/
4269 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4271 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4273 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4276 return DDERR_INVALIDPARAMS
;
4278 wined3d_mutex_lock();
4279 if (!surface
->clipper
)
4281 wined3d_mutex_unlock();
4282 return DDERR_NOCLIPPERATTACHED
;
4285 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4286 IDirectDrawClipper_AddRef(*Clipper
);
4287 wined3d_mutex_unlock();
4292 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4294 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4296 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4298 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4301 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4303 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4305 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4307 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4310 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4312 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4314 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4316 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4319 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4321 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4323 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4325 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4328 /*****************************************************************************
4329 * IDirectDrawSurface7::SetClipper
4331 * Sets a clipper for the surface
4334 * Clipper: IDirectDrawClipper interface of the clipper to set
4339 *****************************************************************************/
4340 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4341 IDirectDrawClipper
*iclipper
)
4343 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4344 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4345 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4348 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4350 wined3d_mutex_lock();
4351 if (clipper
== This
->clipper
)
4353 wined3d_mutex_unlock();
4357 This
->clipper
= clipper
;
4359 if (clipper
!= NULL
)
4360 IDirectDrawClipper_AddRef(iclipper
);
4362 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4364 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4368 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4373 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4374 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4378 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4379 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4383 wined3d_mutex_unlock();
4388 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4390 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4392 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4394 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4397 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4399 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4401 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4403 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4406 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4408 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4410 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4412 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4415 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4417 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4419 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4421 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4424 /*****************************************************************************
4425 * IDirectDrawSurface7::SetSurfaceDesc
4427 * Sets the surface description. It can override the pixel format, the surface
4429 * It's not really tested.
4432 * DDSD: Pointer to the new surface description to set
4437 * DDERR_INVALIDPARAMS if DDSD is NULL
4439 *****************************************************************************/
4440 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4442 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4444 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4445 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4446 enum wined3d_format_id format_id
;
4447 UINT pitch
, width
, height
;
4449 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4453 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4454 return DDERR_INVALIDPARAMS
;
4458 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4459 return DDERR_INVALIDPARAMS
;
4461 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4462 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4463 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4465 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4466 return DDERR_INVALIDSURFACETYPE
;
4469 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4470 * for PIXELFORMAT to work */
4471 if (DDSD
->dwFlags
& ~allowed_flags
)
4473 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4474 return DDERR_INVALIDPARAMS
;
4476 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4478 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4479 return DDERR_INVALIDPARAMS
;
4481 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4483 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4484 return DDERR_INVALIDCAPS
;
4486 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4488 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4490 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4491 return DDERR_INVALIDPARAMS
;
4493 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4495 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4496 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4497 return DDERR_INVALIDPARAMS
;
4499 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4500 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4501 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4502 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4503 pitch
= DDSD
->u1
.lPitch
;
4504 width
= DDSD
->dwWidth
;
4506 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4508 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4509 return DDERR_INVALIDPARAMS
;
4513 pitch
= This
->surface_desc
.u1
.lPitch
;
4514 width
= This
->surface_desc
.dwWidth
;
4517 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4519 if (!DDSD
->dwHeight
)
4521 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4522 return DDERR_INVALIDPARAMS
;
4524 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4525 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4526 height
= DDSD
->dwHeight
;
4530 height
= This
->surface_desc
.dwHeight
;
4533 wined3d_mutex_lock();
4534 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4536 enum wined3d_format_id current_format_id
;
4537 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4539 if (format_id
== WINED3DFMT_UNKNOWN
)
4541 ERR("Requested to set an unknown pixelformat\n");
4542 wined3d_mutex_unlock();
4543 return DDERR_INVALIDPARAMS
;
4545 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4546 if (format_id
!= current_format_id
)
4547 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4551 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4554 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4555 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4557 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4558 wined3d_mutex_unlock();
4559 return hr_ddraw_from_wined3d(hr
);
4562 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4563 This
->surface_desc
.dwWidth
= width
;
4564 if (DDSD
->dwFlags
& DDSD_PITCH
)
4565 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4566 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4567 This
->surface_desc
.dwHeight
= height
;
4568 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4569 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4571 wined3d_mutex_unlock();
4576 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4577 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4579 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4581 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4583 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4584 surface_desc
, flags
);
4587 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4588 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4590 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4591 DDSURFACEDESC2 surface_desc2
;
4593 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4595 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4596 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4597 surface_desc
? &surface_desc2
: NULL
, flags
);
4600 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4602 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4603 struct ddraw_palette
*palette_impl
;
4606 TRACE("iface %p, palette %p.\n", iface
, palette
);
4609 return DDERR_INVALIDPARAMS
;
4610 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4612 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4613 return DDERR_SURFACELOST
;
4616 wined3d_mutex_lock();
4617 if ((palette_impl
= surface
->palette
))
4619 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4620 IDirectDrawPalette_AddRef(*palette
);
4625 hr
= DDERR_NOPALETTEATTACHED
;
4627 wined3d_mutex_unlock();
4632 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4634 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4636 TRACE("iface %p, palette %p.\n", iface
, palette
);
4638 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4641 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4643 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4645 TRACE("iface %p, palette %p.\n", iface
, palette
);
4647 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4650 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4652 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4654 TRACE("iface %p, palette %p.\n", iface
, palette
);
4656 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4659 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4661 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4663 TRACE("iface %p, palette %p.\n", iface
, palette
);
4665 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4668 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4670 DDCOLORKEY fixed_color_key
;
4671 HRESULT hr
= WINED3D_OK
;
4673 if (flags
& DDCKEY_COLORSPACE
)
4675 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4677 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4678 return DDERR_NOCOLORKEYHW
;
4680 flags
&= ~DDCKEY_COLORSPACE
;
4683 wined3d_mutex_lock();
4687 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4688 switch (flags
& ~DDCKEY_COLORSPACE
)
4690 case DDCKEY_DESTBLT
:
4691 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4692 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4695 case DDCKEY_DESTOVERLAY
:
4696 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4697 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4700 case DDCKEY_SRCOVERLAY
:
4701 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4702 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4706 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4707 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4711 wined3d_mutex_unlock();
4712 return DDERR_INVALIDPARAMS
;
4717 switch (flags
& ~DDCKEY_COLORSPACE
)
4719 case DDCKEY_DESTBLT
:
4720 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4723 case DDCKEY_DESTOVERLAY
:
4724 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4727 case DDCKEY_SRCOVERLAY
:
4728 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4732 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4736 wined3d_mutex_unlock();
4737 return DDERR_INVALIDPARAMS
;
4741 if (surface
->is_complex_root
)
4742 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4743 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4745 wined3d_mutex_unlock();
4747 return hr_ddraw_from_wined3d(hr
);
4750 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4752 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4754 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4756 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4757 return DDERR_NOTONMIPMAPSUBLEVEL
;
4759 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4762 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4764 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4766 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4768 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4771 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4773 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4775 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4777 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4780 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4782 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4784 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4786 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4789 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4791 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4793 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4795 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4798 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4800 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4802 TRACE("iface %p, palette %p.\n", iface
, palette
);
4804 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4805 return DDERR_NOTONMIPMAPSUBLEVEL
;
4806 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4808 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4809 return DDERR_SURFACELOST
;
4812 return ddraw_surface_set_palette(surface
, palette
);
4815 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4817 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4819 TRACE("iface %p, palette %p.\n", iface
, palette
);
4821 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4823 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4824 return DDERR_SURFACELOST
;
4827 return ddraw_surface_set_palette(surface
, palette
);
4830 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4832 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4834 TRACE("iface %p, palette %p.\n", iface
, palette
);
4836 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4838 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4839 return DDERR_SURFACELOST
;
4842 return ddraw_surface_set_palette(surface
, palette
);
4845 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4847 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4849 TRACE("iface %p, palette %p.\n", iface
, palette
);
4851 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4853 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4854 return DDERR_SURFACELOST
;
4857 return ddraw_surface_set_palette(surface
, palette
);
4860 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4862 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4864 TRACE("iface %p, palette %p.\n", iface
, palette
);
4866 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4868 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4869 return DDERR_SURFACELOST
;
4872 return ddraw_surface_set_palette(surface
, palette
);
4875 /**********************************************************
4876 * IDirectDrawGammaControl::GetGammaRamp
4878 * Returns the current gamma ramp for a surface
4882 * gamma_ramp: Address to write the ramp to
4886 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4888 **********************************************************/
4889 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4890 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4892 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4894 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4898 WARN("Invalid gamma_ramp passed.\n");
4899 return DDERR_INVALIDPARAMS
;
4902 wined3d_mutex_lock();
4903 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4905 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4906 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4910 ERR("Not implemented for non-primary surfaces.\n");
4912 wined3d_mutex_unlock();
4917 /**********************************************************
4918 * IDirectDrawGammaControl::SetGammaRamp
4920 * Sets the red, green and blue gamma ramps for
4923 * flags: Can be DDSGR_CALIBRATE to request calibration
4924 * gamma_ramp: Structure containing the new gamma ramp
4928 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4930 **********************************************************/
4931 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4932 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4934 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4936 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4940 WARN("Invalid gamma_ramp passed.\n");
4941 return DDERR_INVALIDPARAMS
;
4944 wined3d_mutex_lock();
4945 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4947 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4948 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4949 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4953 ERR("Not implemented for non-primary surfaces.\n");
4955 wined3d_mutex_unlock();
4960 /*****************************************************************************
4961 * IDirect3DTexture2::PaletteChanged
4963 * Informs the texture about a palette change
4966 * start: Start index of the change
4967 * count: The number of changed entries
4970 * D3D_OK, because it's a stub
4972 *****************************************************************************/
4973 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4975 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4980 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4982 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4984 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4986 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4989 /*****************************************************************************
4990 * IDirect3DTexture::Unload
4992 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4998 *****************************************************************************/
4999 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
5001 WARN("iface %p. Not implemented.\n", iface
);
5003 return DDERR_UNSUPPORTED
;
5006 /*****************************************************************************
5007 * IDirect3DTexture2::GetHandle
5009 * Returns handle for the texture. At the moment, the interface
5010 * to the IWineD3DTexture is used.
5013 * device: Device this handle is assigned to
5014 * handle: Address to store the handle at.
5019 *****************************************************************************/
5020 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5021 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5023 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5024 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5026 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5028 wined3d_mutex_lock();
5030 if (!surface
->Handle
)
5032 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5033 if (h
== DDRAW_INVALID_HANDLE
)
5035 ERR("Failed to allocate a texture handle.\n");
5036 wined3d_mutex_unlock();
5037 return DDERR_OUTOFMEMORY
;
5040 surface
->Handle
= h
+ 1;
5043 TRACE("Returning handle %08x.\n", surface
->Handle
);
5044 *handle
= surface
->Handle
;
5046 wined3d_mutex_unlock();
5051 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5052 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5054 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5055 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5057 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5059 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5060 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5063 /*****************************************************************************
5064 * get_sub_mimaplevel
5066 * Helper function that returns the next mipmap level
5068 * tex_ptr: Surface of which to return the next level
5070 *****************************************************************************/
5071 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5073 /* Now go down the mipmap chain to the next surface */
5074 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5075 IDirectDrawSurface7
*next_level
;
5078 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5079 if (FAILED(hr
)) return NULL
;
5081 ddraw_surface7_Release(next_level
);
5083 return impl_from_IDirectDrawSurface7(next_level
);
5086 /*****************************************************************************
5087 * IDirect3DTexture2::Load
5089 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5091 * This function isn't relayed to WineD3D because the whole interface is
5092 * implemented in DDraw only. For speed improvements an implementation which
5093 * takes OpenGL more into account could be placed into WineD3D.
5096 * src_texture: Address of the texture to load
5100 * D3DERR_TEXTURE_LOAD_FAILED.
5102 *****************************************************************************/
5103 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5105 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5106 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5107 struct wined3d_resource
*dst_resource
, *src_resource
;
5110 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5112 if (src_surface
== dst_surface
)
5114 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5118 wined3d_mutex_lock();
5120 dst_resource
= wined3d_texture_get_resource(dst_surface
->wined3d_texture
);
5121 src_resource
= wined3d_texture_get_resource(src_surface
->wined3d_texture
);
5123 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5124 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5125 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5127 ERR("Trying to load surfaces with different mip-map counts.\n");
5132 struct ddraw_palette
*dst_pal
, *src_pal
;
5133 DDSURFACEDESC
*src_desc
, *dst_desc
;
5135 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5137 /* Suppress the ALLOCONLOAD flag */
5138 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5140 /* Get the palettes */
5141 dst_pal
= dst_surface
->palette
;
5142 src_pal
= src_surface
->palette
;
5146 PALETTEENTRY palent
[256];
5150 wined3d_mutex_unlock();
5151 return DDERR_NOPALETTEATTACHED
;
5153 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5154 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5157 /* Copy one surface on the other */
5158 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5159 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5161 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5163 /* Should also check for same pixel format, u1.lPitch, ... */
5164 ERR("Error in surface sizes.\n");
5165 wined3d_mutex_unlock();
5166 return D3DERR_TEXTURE_LOAD_FAILED
;
5170 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5172 /* Copy the src blit color key if the source has one, don't erase
5173 * the destination's ckey if the source has none */
5174 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5176 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5177 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5180 if (FAILED(hr
= wined3d_resource_map(src_resource
,
5181 src_surface
->sub_resource_idx
, &src_map_desc
, NULL
, 0)))
5183 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5184 wined3d_mutex_unlock();
5185 return D3DERR_TEXTURE_LOAD_FAILED
;
5188 if (FAILED(hr
= wined3d_resource_map(dst_resource
,
5189 dst_surface
->sub_resource_idx
, &dst_map_desc
, NULL
, 0)))
5191 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5192 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5193 wined3d_mutex_unlock();
5194 return D3DERR_TEXTURE_LOAD_FAILED
;
5197 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5198 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5200 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5202 wined3d_resource_unmap(dst_resource
, dst_surface
->sub_resource_idx
);
5203 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5206 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5207 src_surface
= get_sub_mimaplevel(src_surface
);
5211 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5212 dst_surface
= get_sub_mimaplevel(dst_surface
);
5216 if (!src_surface
|| !dst_surface
)
5218 if (src_surface
!= dst_surface
)
5219 ERR("Loading surface with different mipmap structure.\n");
5224 wined3d_mutex_unlock();
5229 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5231 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5232 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5234 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5236 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5237 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5240 /*****************************************************************************
5242 *****************************************************************************/
5244 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5247 ddraw_surface7_QueryInterface
,
5248 ddraw_surface7_AddRef
,
5249 ddraw_surface7_Release
,
5250 /* IDirectDrawSurface */
5251 ddraw_surface7_AddAttachedSurface
,
5252 ddraw_surface7_AddOverlayDirtyRect
,
5254 ddraw_surface7_BltBatch
,
5255 ddraw_surface7_BltFast
,
5256 ddraw_surface7_DeleteAttachedSurface
,
5257 ddraw_surface7_EnumAttachedSurfaces
,
5258 ddraw_surface7_EnumOverlayZOrders
,
5259 ddraw_surface7_Flip
,
5260 ddraw_surface7_GetAttachedSurface
,
5261 ddraw_surface7_GetBltStatus
,
5262 ddraw_surface7_GetCaps
,
5263 ddraw_surface7_GetClipper
,
5264 ddraw_surface7_GetColorKey
,
5265 ddraw_surface7_GetDC
,
5266 ddraw_surface7_GetFlipStatus
,
5267 ddraw_surface7_GetOverlayPosition
,
5268 ddraw_surface7_GetPalette
,
5269 ddraw_surface7_GetPixelFormat
,
5270 ddraw_surface7_GetSurfaceDesc
,
5271 ddraw_surface7_Initialize
,
5272 ddraw_surface7_IsLost
,
5273 ddraw_surface7_Lock
,
5274 ddraw_surface7_ReleaseDC
,
5275 ddraw_surface7_Restore
,
5276 ddraw_surface7_SetClipper
,
5277 ddraw_surface7_SetColorKey
,
5278 ddraw_surface7_SetOverlayPosition
,
5279 ddraw_surface7_SetPalette
,
5280 ddraw_surface7_Unlock
,
5281 ddraw_surface7_UpdateOverlay
,
5282 ddraw_surface7_UpdateOverlayDisplay
,
5283 ddraw_surface7_UpdateOverlayZOrder
,
5284 /* IDirectDrawSurface2 */
5285 ddraw_surface7_GetDDInterface
,
5286 ddraw_surface7_PageLock
,
5287 ddraw_surface7_PageUnlock
,
5288 /* IDirectDrawSurface3 */
5289 ddraw_surface7_SetSurfaceDesc
,
5290 /* IDirectDrawSurface4 */
5291 ddraw_surface7_SetPrivateData
,
5292 ddraw_surface7_GetPrivateData
,
5293 ddraw_surface7_FreePrivateData
,
5294 ddraw_surface7_GetUniquenessValue
,
5295 ddraw_surface7_ChangeUniquenessValue
,
5296 /* IDirectDrawSurface7 */
5297 ddraw_surface7_SetPriority
,
5298 ddraw_surface7_GetPriority
,
5299 ddraw_surface7_SetLOD
,
5300 ddraw_surface7_GetLOD
,
5303 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5306 ddraw_surface4_QueryInterface
,
5307 ddraw_surface4_AddRef
,
5308 ddraw_surface4_Release
,
5309 /* IDirectDrawSurface */
5310 ddraw_surface4_AddAttachedSurface
,
5311 ddraw_surface4_AddOverlayDirtyRect
,
5313 ddraw_surface4_BltBatch
,
5314 ddraw_surface4_BltFast
,
5315 ddraw_surface4_DeleteAttachedSurface
,
5316 ddraw_surface4_EnumAttachedSurfaces
,
5317 ddraw_surface4_EnumOverlayZOrders
,
5318 ddraw_surface4_Flip
,
5319 ddraw_surface4_GetAttachedSurface
,
5320 ddraw_surface4_GetBltStatus
,
5321 ddraw_surface4_GetCaps
,
5322 ddraw_surface4_GetClipper
,
5323 ddraw_surface4_GetColorKey
,
5324 ddraw_surface4_GetDC
,
5325 ddraw_surface4_GetFlipStatus
,
5326 ddraw_surface4_GetOverlayPosition
,
5327 ddraw_surface4_GetPalette
,
5328 ddraw_surface4_GetPixelFormat
,
5329 ddraw_surface4_GetSurfaceDesc
,
5330 ddraw_surface4_Initialize
,
5331 ddraw_surface4_IsLost
,
5332 ddraw_surface4_Lock
,
5333 ddraw_surface4_ReleaseDC
,
5334 ddraw_surface4_Restore
,
5335 ddraw_surface4_SetClipper
,
5336 ddraw_surface4_SetColorKey
,
5337 ddraw_surface4_SetOverlayPosition
,
5338 ddraw_surface4_SetPalette
,
5339 ddraw_surface4_Unlock
,
5340 ddraw_surface4_UpdateOverlay
,
5341 ddraw_surface4_UpdateOverlayDisplay
,
5342 ddraw_surface4_UpdateOverlayZOrder
,
5343 /* IDirectDrawSurface2 */
5344 ddraw_surface4_GetDDInterface
,
5345 ddraw_surface4_PageLock
,
5346 ddraw_surface4_PageUnlock
,
5347 /* IDirectDrawSurface3 */
5348 ddraw_surface4_SetSurfaceDesc
,
5349 /* IDirectDrawSurface4 */
5350 ddraw_surface4_SetPrivateData
,
5351 ddraw_surface4_GetPrivateData
,
5352 ddraw_surface4_FreePrivateData
,
5353 ddraw_surface4_GetUniquenessValue
,
5354 ddraw_surface4_ChangeUniquenessValue
,
5357 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5360 ddraw_surface3_QueryInterface
,
5361 ddraw_surface3_AddRef
,
5362 ddraw_surface3_Release
,
5363 /* IDirectDrawSurface */
5364 ddraw_surface3_AddAttachedSurface
,
5365 ddraw_surface3_AddOverlayDirtyRect
,
5367 ddraw_surface3_BltBatch
,
5368 ddraw_surface3_BltFast
,
5369 ddraw_surface3_DeleteAttachedSurface
,
5370 ddraw_surface3_EnumAttachedSurfaces
,
5371 ddraw_surface3_EnumOverlayZOrders
,
5372 ddraw_surface3_Flip
,
5373 ddraw_surface3_GetAttachedSurface
,
5374 ddraw_surface3_GetBltStatus
,
5375 ddraw_surface3_GetCaps
,
5376 ddraw_surface3_GetClipper
,
5377 ddraw_surface3_GetColorKey
,
5378 ddraw_surface3_GetDC
,
5379 ddraw_surface3_GetFlipStatus
,
5380 ddraw_surface3_GetOverlayPosition
,
5381 ddraw_surface3_GetPalette
,
5382 ddraw_surface3_GetPixelFormat
,
5383 ddraw_surface3_GetSurfaceDesc
,
5384 ddraw_surface3_Initialize
,
5385 ddraw_surface3_IsLost
,
5386 ddraw_surface3_Lock
,
5387 ddraw_surface3_ReleaseDC
,
5388 ddraw_surface3_Restore
,
5389 ddraw_surface3_SetClipper
,
5390 ddraw_surface3_SetColorKey
,
5391 ddraw_surface3_SetOverlayPosition
,
5392 ddraw_surface3_SetPalette
,
5393 ddraw_surface3_Unlock
,
5394 ddraw_surface3_UpdateOverlay
,
5395 ddraw_surface3_UpdateOverlayDisplay
,
5396 ddraw_surface3_UpdateOverlayZOrder
,
5397 /* IDirectDrawSurface2 */
5398 ddraw_surface3_GetDDInterface
,
5399 ddraw_surface3_PageLock
,
5400 ddraw_surface3_PageUnlock
,
5401 /* IDirectDrawSurface3 */
5402 ddraw_surface3_SetSurfaceDesc
,
5405 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5408 ddraw_surface2_QueryInterface
,
5409 ddraw_surface2_AddRef
,
5410 ddraw_surface2_Release
,
5411 /* IDirectDrawSurface */
5412 ddraw_surface2_AddAttachedSurface
,
5413 ddraw_surface2_AddOverlayDirtyRect
,
5415 ddraw_surface2_BltBatch
,
5416 ddraw_surface2_BltFast
,
5417 ddraw_surface2_DeleteAttachedSurface
,
5418 ddraw_surface2_EnumAttachedSurfaces
,
5419 ddraw_surface2_EnumOverlayZOrders
,
5420 ddraw_surface2_Flip
,
5421 ddraw_surface2_GetAttachedSurface
,
5422 ddraw_surface2_GetBltStatus
,
5423 ddraw_surface2_GetCaps
,
5424 ddraw_surface2_GetClipper
,
5425 ddraw_surface2_GetColorKey
,
5426 ddraw_surface2_GetDC
,
5427 ddraw_surface2_GetFlipStatus
,
5428 ddraw_surface2_GetOverlayPosition
,
5429 ddraw_surface2_GetPalette
,
5430 ddraw_surface2_GetPixelFormat
,
5431 ddraw_surface2_GetSurfaceDesc
,
5432 ddraw_surface2_Initialize
,
5433 ddraw_surface2_IsLost
,
5434 ddraw_surface2_Lock
,
5435 ddraw_surface2_ReleaseDC
,
5436 ddraw_surface2_Restore
,
5437 ddraw_surface2_SetClipper
,
5438 ddraw_surface2_SetColorKey
,
5439 ddraw_surface2_SetOverlayPosition
,
5440 ddraw_surface2_SetPalette
,
5441 ddraw_surface2_Unlock
,
5442 ddraw_surface2_UpdateOverlay
,
5443 ddraw_surface2_UpdateOverlayDisplay
,
5444 ddraw_surface2_UpdateOverlayZOrder
,
5445 /* IDirectDrawSurface2 */
5446 ddraw_surface2_GetDDInterface
,
5447 ddraw_surface2_PageLock
,
5448 ddraw_surface2_PageUnlock
,
5451 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5454 ddraw_surface1_QueryInterface
,
5455 ddraw_surface1_AddRef
,
5456 ddraw_surface1_Release
,
5457 /* IDirectDrawSurface */
5458 ddraw_surface1_AddAttachedSurface
,
5459 ddraw_surface1_AddOverlayDirtyRect
,
5461 ddraw_surface1_BltBatch
,
5462 ddraw_surface1_BltFast
,
5463 ddraw_surface1_DeleteAttachedSurface
,
5464 ddraw_surface1_EnumAttachedSurfaces
,
5465 ddraw_surface1_EnumOverlayZOrders
,
5466 ddraw_surface1_Flip
,
5467 ddraw_surface1_GetAttachedSurface
,
5468 ddraw_surface1_GetBltStatus
,
5469 ddraw_surface1_GetCaps
,
5470 ddraw_surface1_GetClipper
,
5471 ddraw_surface1_GetColorKey
,
5472 ddraw_surface1_GetDC
,
5473 ddraw_surface1_GetFlipStatus
,
5474 ddraw_surface1_GetOverlayPosition
,
5475 ddraw_surface1_GetPalette
,
5476 ddraw_surface1_GetPixelFormat
,
5477 ddraw_surface1_GetSurfaceDesc
,
5478 ddraw_surface1_Initialize
,
5479 ddraw_surface1_IsLost
,
5480 ddraw_surface1_Lock
,
5481 ddraw_surface1_ReleaseDC
,
5482 ddraw_surface1_Restore
,
5483 ddraw_surface1_SetClipper
,
5484 ddraw_surface1_SetColorKey
,
5485 ddraw_surface1_SetOverlayPosition
,
5486 ddraw_surface1_SetPalette
,
5487 ddraw_surface1_Unlock
,
5488 ddraw_surface1_UpdateOverlay
,
5489 ddraw_surface1_UpdateOverlayDisplay
,
5490 ddraw_surface1_UpdateOverlayZOrder
,
5493 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5495 ddraw_gamma_control_QueryInterface
,
5496 ddraw_gamma_control_AddRef
,
5497 ddraw_gamma_control_Release
,
5498 ddraw_gamma_control_GetGammaRamp
,
5499 ddraw_gamma_control_SetGammaRamp
,
5502 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5504 d3d_texture2_QueryInterface
,
5505 d3d_texture2_AddRef
,
5506 d3d_texture2_Release
,
5507 d3d_texture2_GetHandle
,
5508 d3d_texture2_PaletteChanged
,
5512 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5514 d3d_texture1_QueryInterface
,
5515 d3d_texture1_AddRef
,
5516 d3d_texture1_Release
,
5517 d3d_texture1_Initialize
,
5518 d3d_texture1_GetHandle
,
5519 d3d_texture1_PaletteChanged
,
5521 d3d_texture1_Unload
,
5524 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5525 * IDirectDrawSurface interface to ddraw methods. */
5526 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5528 if (!iface
) return NULL
;
5529 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5531 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5534 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5537 IDirectDrawSurface7_Release(iface
);
5539 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5542 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5544 if (!iface
) return NULL
;
5545 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5547 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5550 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5553 IDirectDrawSurface4_Release(iface
);
5555 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5558 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5560 if (!iface
) return NULL
;
5561 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5563 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5566 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5569 IDirectDrawSurface3_Release(iface
);
5571 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5574 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5576 if (!iface
) return NULL
;
5577 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5579 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5582 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5585 IDirectDrawSurface2_Release(iface
);
5587 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5590 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5592 if (!iface
) return NULL
;
5593 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5595 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5598 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5601 IDirectDrawSurface_Release(iface
);
5603 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5606 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5608 if (!iface
) return NULL
;
5609 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5610 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5613 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5615 if (!iface
) return NULL
;
5616 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5617 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5620 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5622 struct ddraw_surface
*surface
= parent
;
5624 TRACE("surface %p.\n", surface
);
5626 /* Check for attached surfaces and detach them. */
5627 if (surface
->first_attached
!= surface
)
5629 /* Well, this shouldn't happen: The surface being attached is
5630 * referenced in AddAttachedSurface(), so it shouldn't be released
5631 * until DeleteAttachedSurface() is called, because the refcount is
5632 * held. It looks like the application released it often enough to
5634 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5636 /* The refcount will drop to -1 here */
5637 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5638 ERR("DeleteAttachedSurface failed.\n");
5641 while (surface
->next_attached
)
5642 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5643 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5644 ERR("DeleteAttachedSurface failed.\n");
5646 /* Having a texture handle set implies that the device still exists. */
5647 if (surface
->Handle
)
5648 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5650 /* Reduce the ddraw surface count. */
5651 list_remove(&surface
->surface_list_entry
);
5653 if (surface
->clipper
)
5654 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5656 if (surface
== surface
->ddraw
->primary
)
5657 surface
->ddraw
->primary
= NULL
;
5659 wined3d_private_store_cleanup(&surface
->private_store
);
5661 HeapFree(GetProcessHeap(), 0, surface
);
5664 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5666 ddraw_surface_wined3d_object_destroyed
,
5669 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5671 TRACE("parent %p.\n", parent
);
5673 HeapFree(GetProcessHeap(), 0, parent
);
5676 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5678 ddraw_texture_wined3d_object_destroyed
,
5681 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5686 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5687 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5689 struct wined3d_resource_desc wined3d_desc
, wined3d_mip_desc
;
5690 struct ddraw_surface
*root
, *mip
, **attach
;
5691 struct wined3d_texture
*wined3d_texture
;
5692 struct wined3d_resource
*resource
;
5693 struct wined3d_display_mode mode
;
5694 DDSURFACEDESC2
*desc
, *mip_desc
;
5695 struct ddraw_texture
*texture
;
5696 unsigned int layers
= 1;
5697 unsigned int pitch
= 0;
5701 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5702 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5703 if (TRACE_ON(ddraw
))
5705 TRACE("Requesting surface desc:\n");
5706 DDRAW_dump_surface_desc(surface_desc
);
5710 return CLASS_E_NOAGGREGATION
;
5715 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5716 return E_OUTOFMEMORY
;
5718 texture
->version
= version
;
5719 texture
->surface_desc
= *surface_desc
;
5720 desc
= &texture
->surface_desc
;
5722 /* Ensure DDSD_CAPS is always set. */
5723 desc
->dwFlags
|= DDSD_CAPS
;
5725 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5727 DWORD flippable
= desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
);
5729 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5731 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5732 HeapFree(GetProcessHeap(), 0, texture
);
5733 return DDERR_INVALIDCAPS
;
5738 if (flippable
!= (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
))
5740 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5741 HeapFree(GetProcessHeap(), 0, texture
);
5742 return DDERR_INVALIDCAPS
;
5745 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5747 WARN("Tried to create a flippable primary surface without any back buffers.\n");
5748 HeapFree(GetProcessHeap(), 0, texture
);
5749 return DDERR_INVALIDCAPS
;
5752 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5754 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5755 HeapFree(GetProcessHeap(), 0, texture
);
5756 return DDERR_NOEXCLUSIVEMODE
;
5761 /* This is a special case in ddrawex, but not allowed in ddraw. */
5762 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5763 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5765 WARN("Tried to create a surface in both system and video memory.\n");
5766 HeapFree(GetProcessHeap(), 0, texture
);
5767 return DDERR_INVALIDCAPS
;
5770 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
5771 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5773 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
5774 HeapFree(GetProcessHeap(), 0, texture
);
5775 return DDERR_INVALIDCAPS
;
5778 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5779 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5781 WARN("Cube map faces requested without cube map flag.\n");
5782 HeapFree(GetProcessHeap(), 0, texture
);
5783 return DDERR_INVALIDCAPS
;
5786 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5787 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5789 WARN("Cube map without faces requested.\n");
5790 HeapFree(GetProcessHeap(), 0, texture
);
5791 return DDERR_INVALIDPARAMS
;
5794 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5795 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5796 FIXME("Partial cube maps not implemented.\n");
5798 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5800 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5802 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5803 HeapFree(GetProcessHeap(), 0, texture
);
5804 return DDERR_INVALIDCAPS
;
5806 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5808 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5809 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5810 HeapFree(GetProcessHeap(), 0, texture
);
5811 return DDERR_INVALIDCAPS
;
5815 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5817 ERR("Failed to get display mode, hr %#x.\n", hr
);
5818 HeapFree(GetProcessHeap(), 0, texture
);
5819 return hr_ddraw_from_wined3d(hr
);
5822 /* No pixelformat given? Use the current screen format. */
5823 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5825 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5826 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5827 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5830 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
5831 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5832 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5834 WARN("Unsupported / unknown pixelformat.\n");
5835 HeapFree(GetProcessHeap(), 0, texture
);
5836 return DDERR_INVALIDPIXELFORMAT
;
5839 /* No width or no height? Use the screen size. */
5840 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5842 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5844 WARN("No width / height specified.\n");
5845 HeapFree(GetProcessHeap(), 0, texture
);
5846 return DDERR_INVALIDPARAMS
;
5849 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5850 desc
->dwWidth
= mode
.width
;
5851 desc
->dwHeight
= mode
.height
;
5854 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5856 HeapFree(GetProcessHeap(), 0, texture
);
5857 return DDERR_INVALIDPARAMS
;
5860 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5862 /* The first surface is a front buffer, the back buffers are created
5864 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5865 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5866 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5867 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5869 struct wined3d_swapchain_desc swapchain_desc
;
5871 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5872 swapchain_desc
.backbuffer_width
= mode
.width
;
5873 swapchain_desc
.backbuffer_height
= mode
.height
;
5874 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5876 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5877 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5879 ERR("Failed to reset device.\n");
5880 HeapFree(GetProcessHeap(), 0, texture
);
5881 return hr_ddraw_from_wined3d(hr
);
5886 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5887 wined3d_desc
.multisample_quality
= 0;
5888 wined3d_desc
.usage
= 0;
5889 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5890 wined3d_desc
.width
= desc
->dwWidth
;
5891 wined3d_desc
.height
= desc
->dwHeight
;
5892 wined3d_desc
.depth
= 1;
5893 wined3d_desc
.size
= 0;
5895 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5897 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5898 /* Do not fail surface creation, only fail 3D device creation. */
5901 /* Mipmap count fixes */
5902 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5904 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5906 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5908 /* Mipmap count is given, should not be 0. */
5909 if (!desc
->u2
.dwMipMapCount
)
5911 HeapFree(GetProcessHeap(), 0, texture
);
5912 return DDERR_INVALIDPARAMS
;
5917 /* Undocumented feature: Create sublevels until either the
5918 * width or the height is 1. */
5920 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5922 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5927 desc
->u2
.dwMipMapCount
= 1;
5930 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5931 levels
= desc
->u2
.dwMipMapCount
;
5938 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5940 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5942 enum wined3d_resource_type rtype
;
5945 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5947 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
5948 rtype
= WINED3D_RTYPE_TEXTURE_2D
;
5950 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5951 rtype
= WINED3D_RTYPE_TEXTURE_2D
;
5953 rtype
= WINED3D_RTYPE_SURFACE
;
5955 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5956 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5957 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5958 usage
= WINED3DUSAGE_RENDERTARGET
;
5960 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5961 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, rtype
, wined3d_desc
.format
)))
5962 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5964 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5966 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5968 /* Tests show surfaces without memory flags get these flags added
5969 * right after creation. */
5970 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5974 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5975 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5977 WARN("System memory overlays are not allowed.\n");
5978 HeapFree(GetProcessHeap(), 0, texture
);
5979 return DDERR_NOOVERLAYHW
;
5982 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5984 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
5988 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5989 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
5990 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5991 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5992 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5993 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
5995 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5997 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
5998 /* Managed textures have the system memory flag set. */
5999 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6001 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
6003 /* Videomemory adds localvidmem. This is mutually exclusive with
6004 * systemmemory and texturemanage. */
6005 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
6006 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
6010 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6012 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
6014 WARN("User memory surfaces should be in the system memory pool.\n");
6015 HeapFree(GetProcessHeap(), 0, texture
);
6016 return DDERR_INVALIDCAPS
;
6021 WARN("User memory surfaces not supported before version 4.\n");
6022 HeapFree(GetProcessHeap(), 0, texture
);
6023 return DDERR_INVALIDPARAMS
;
6026 if (!desc
->lpSurface
)
6028 WARN("NULL surface memory pointer specified.\n");
6029 HeapFree(GetProcessHeap(), 0, texture
);
6030 return DDERR_INVALIDPARAMS
;
6033 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6035 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6037 WARN("Pitch specified on a compressed user memory surface.\n");
6038 HeapFree(GetProcessHeap(), 0, texture
);
6039 return DDERR_INVALIDPARAMS
;
6042 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6044 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6045 HeapFree(GetProcessHeap(), 0, texture
);
6046 return DDERR_INVALIDPARAMS
;
6049 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6050 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6051 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6053 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6054 HeapFree(GetProcessHeap(), 0, texture
);
6055 return DDERR_INVALIDPARAMS
;
6060 if (!(desc
->dwFlags
& DDSD_PITCH
))
6062 WARN("User memory surfaces should explicitly specify the pitch.\n");
6063 HeapFree(GetProcessHeap(), 0, texture
);
6064 return DDERR_INVALIDPARAMS
;
6067 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6068 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6070 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6071 HeapFree(GetProcessHeap(), 0, texture
);
6072 return DDERR_INVALIDPARAMS
;
6075 pitch
= desc
->u1
.lPitch
;
6079 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6080 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6081 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6082 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6083 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6084 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6085 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6086 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6088 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6089 HeapFree(GetProcessHeap(), 0, texture
);
6090 return DDERR_NOCOLORKEYHW
;
6093 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6094 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6096 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6097 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6099 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6101 wined3d_desc
.usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6105 /* Some applications assume surfaces will always be mapped at the same
6106 * address. Some of those also assume that this address is valid even when
6107 * the surface isn't mapped, and that updates done this way will be
6108 * visible on the screen. The game Nox is such an application,
6109 * Commandos: Behind Enemy Lines is another. We set
6110 * WINED3D_TEXTURE_CREATE_PIN_SYSMEM because of this. */
6111 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
6112 WINED3D_TEXTURE_CREATE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6114 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6115 HeapFree(GetProcessHeap(), 0, texture
);
6116 return hr_ddraw_from_wined3d(hr
);
6119 root
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6120 wined3d_texture_decref(wined3d_texture
);
6121 root
->is_complex_root
= TRUE
;
6122 texture
->root
= root
;
6124 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6125 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6126 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6127 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6128 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6129 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6130 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6131 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6132 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6133 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6134 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6135 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6137 for (i
= 0; i
< layers
; ++i
)
6139 attach
= &root
->complex_array
[layers
- 1 - i
];
6141 for (j
= 0; j
< levels
; ++j
)
6143 mip
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, i
* levels
+ j
);
6144 mip_desc
= &mip
->surface_desc
;
6148 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
6149 wined3d_resource_get_desc(resource
, &wined3d_mip_desc
);
6150 mip_desc
->dwWidth
= wined3d_mip_desc
.width
;
6151 mip_desc
->dwHeight
= wined3d_mip_desc
.height
;
6153 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6157 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6160 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6162 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6166 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6167 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6169 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6170 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6172 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6173 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6175 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6176 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6178 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6179 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6181 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6182 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6192 attach
= &mip
->complex_array
[0];
6196 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6197 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6198 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6200 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6204 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6206 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6207 struct ddraw_surface
*last
= root
;
6209 attach
= &last
->complex_array
[0];
6210 for (i
= 0; i
< count
; ++i
)
6212 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6218 texture
->version
= version
;
6219 texture
->surface_desc
= root
->surface_desc
;
6220 desc
= &texture
->surface_desc
;
6222 /* Only one surface in the flipping chain is a back buffer, one is
6223 * a front buffer, the others are just flippable surfaces. */
6224 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6225 | DDSCAPS_BACKBUFFER
);
6227 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6228 desc
->u5
.dwBackBufferCount
= 0;
6230 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1,
6231 WINED3D_TEXTURE_CREATE_PIN_SYSMEM
, NULL
, texture
,
6232 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6234 HeapFree(GetProcessHeap(), 0, texture
);
6235 hr
= hr_ddraw_from_wined3d(hr
);
6239 last
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6240 wined3d_texture_decref(wined3d_texture
);
6241 texture
->root
= last
;
6243 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6244 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6245 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6246 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6247 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6248 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6249 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6250 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6251 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6252 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6253 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6254 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6257 attach
= &last
->complex_array
[0];
6262 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6263 ddraw
->primary
= root
;
6270 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6271 else if (version
== 4)
6272 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6274 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6279 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
6280 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
6281 const struct wined3d_parent_ops
**parent_ops
)
6283 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
6284 unsigned int texture_level
, row_pitch
, slice_pitch
;
6285 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6286 unsigned int version
= texture
->version
;
6288 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6289 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6290 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6291 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6292 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6293 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6294 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6295 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6296 surface
->iface_count
= 1;
6297 surface
->version
= version
;
6298 surface
->ddraw
= ddraw
;
6303 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6305 else if (version
== 4)
6308 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6313 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6316 *desc
= texture
->surface_desc
;
6317 surface
->first_attached
= surface
;
6319 texture_level
= desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
? sub_resource_idx
% desc
->u2
.dwMipMapCount
: 0;
6320 wined3d_texture_get_pitch(wined3d_texture
, texture_level
, &row_pitch
, &slice_pitch
);
6321 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6323 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6324 desc
->u1
.dwLinearSize
= ~0u;
6326 desc
->u1
.dwLinearSize
= slice_pitch
;
6327 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6328 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6332 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6333 desc
->u1
.lPitch
= row_pitch
;
6334 desc
->dwFlags
|= DDSD_PITCH
;
6335 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6337 desc
->lpSurface
= NULL
;
6339 wined3d_texture_incref(surface
->wined3d_texture
= wined3d_texture
);
6340 surface
->sub_resource_idx
= sub_resource_idx
;
6341 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6343 wined3d_private_store_init(&surface
->private_store
);
6346 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6348 struct ddraw_surface
*surface
= parent
;
6350 /* If the surface reference count drops to zero, we release our reference
6351 * to the view, but don't clear the pointer yet, in case e.g. a
6352 * GetRenderTarget() call brings the surface back before the view is
6353 * actually destroyed. When the view is destroyed, we need to clear the
6354 * pointer, or a subsequent surface AddRef() would reference it again.
6356 * This is safe because as long as the view still has a reference to the
6357 * texture, the surface is also still alive, and we're called before the
6358 * view releases that reference. */
6359 surface
->wined3d_rtv
= NULL
;
6362 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6364 view_wined3d_object_destroyed
,
6367 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6371 if (surface
->wined3d_rtv
)
6372 return surface
->wined3d_rtv
;
6374 if (FAILED(hr
= wined3d_rendertarget_view_create_from_sub_resource(surface
->wined3d_texture
,
6375 surface
->sub_resource_idx
, surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6377 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6381 return surface
->wined3d_rtv
;