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 WINEDDBLTFX
*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
*DestRect
,
1533 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1535 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1536 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1540 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1541 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1543 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1544 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1546 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1547 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1548 return DDERR_INVALIDPARAMS
;
1551 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1552 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1553 return DDERR_INVALIDPARAMS
;
1556 if (Flags
& DDBLT_DDROPS
)
1558 FIXME("DDBLT_DDROPS not implemented.\n");
1560 FIXME(" rop %#x, pattern %p.\n", DDBltFx
->dwDDROP
, DDBltFx
->u5
.lpDDSPattern
);
1561 return DDERR_NORASTEROPHW
;
1564 wined3d_mutex_lock();
1566 if (Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1568 if (Flags
& DDBLT_ROP
)
1570 wined3d_mutex_unlock();
1571 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1572 return DDERR_INVALIDPARAMS
;
1576 wined3d_mutex_unlock();
1577 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1578 return DDERR_INVALIDPARAMS
;
1582 wined3d_mutex_unlock();
1583 WARN("Depth or colorfill used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1584 return DDERR_INVALIDPARAMS
;
1587 if ((Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1588 Flags
&= ~DDBLT_DEPTHFILL
;
1590 if ((dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_COLORFILL
))
1592 wined3d_mutex_unlock();
1593 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1594 return DDERR_INVALIDPARAMS
;
1596 if (!(dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_DEPTHFILL
))
1598 wined3d_mutex_unlock();
1599 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1600 return DDERR_INVALIDPARAMS
;
1604 if (Flags
& DDBLT_ROP
)
1608 wined3d_mutex_unlock();
1609 WARN("DDBLT_ROP used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1610 return DDERR_INVALIDPARAMS
;
1613 Flags
&= ~DDBLT_ROP
;
1614 switch (DDBltFx
->dwROP
)
1623 if (DDBltFx
->dwROP
== WHITENESS
)
1624 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1626 rop_fx
.u5
.dwFillColor
= 0;
1628 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1629 Flags
|= DDBLT_DEPTHFILL
;
1631 Flags
|= DDBLT_COLORFILL
;
1637 wined3d_mutex_unlock();
1638 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", DDBltFx
->dwROP
);
1639 return DDERR_NORASTEROPHW
;
1643 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1645 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1646 wined3d_mutex_unlock();
1647 return DDERR_INVALIDPARAMS
;
1650 if (Flags
& ~WINED3D_BLT_MASK
)
1652 wined3d_mutex_unlock();
1653 FIXME("Unhandled flags %#x.\n", Flags
);
1657 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1658 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1659 * surfaces. So far no blitting operations using surfaces in the bltfx
1660 * struct are supported anyway. */
1661 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1662 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1664 wined3d_mutex_unlock();
1667 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1672 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1673 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1675 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1676 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1678 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1679 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1681 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1682 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1685 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1686 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1688 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1689 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1691 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1692 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1694 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1695 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1698 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1699 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1701 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1702 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1704 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1705 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1707 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1708 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1711 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1712 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1714 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1715 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1717 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1718 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1720 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1721 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1724 /*****************************************************************************
1725 * IDirectDrawSurface7::AddAttachedSurface
1727 * Attaches a surface to another surface. How the surface attachments work
1728 * is not totally understood yet, and this method is prone to problems.
1729 * The surface that is attached is AddRef-ed.
1731 * Tests with complex surfaces suggest that the surface attachments form a
1732 * tree, but no method to test this has been found yet.
1734 * The attachment list consists of a first surface (first_attached) and
1735 * for each surface a pointer to the next attached surface (next_attached).
1736 * For the first surface, and a surface that has no attachments
1737 * first_attached points to the surface itself. A surface that has
1738 * no successors in the chain has next_attached set to NULL.
1740 * Newly attached surfaces are attached right after the root surface.
1741 * If a surface is attached to a complex surface compound, it's attached to
1742 * the surface that the app requested, not the complex root. See
1743 * GetAttachedSurface for a description how surfaces are found.
1745 * This is how the current implementation works, and it was coded by looking
1746 * at the needs of the applications.
1748 * So far only Z-Buffer attachments are tested, and they are activated in
1749 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1750 * Back buffers should work in 2D mode, but they are not tested(They can be
1751 * attached in older iface versions). Rendering to the front buffer and
1752 * switching between that and double buffering is not yet implemented in
1753 * WineD3D, so for 3D it might have unexpected results.
1755 * ddraw_surface_attach_surface is the real thing,
1756 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1757 * performs additional checks. Version 7 of this interface is much more restrictive
1758 * than its predecessors.
1761 * Attach: Surface to attach to iface
1765 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1767 *****************************************************************************/
1768 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1770 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1773 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1775 wined3d_mutex_lock();
1777 /* Check if the surface is already attached somewhere */
1778 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1780 /* TODO: Test for the structure of the manual attachment. Is it a
1781 * chain or a list? What happens if one surface is attached to 2
1782 * different surfaces? */
1783 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1784 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1786 wined3d_mutex_unlock();
1787 return DDERR_SURFACEALREADYATTACHED
;
1790 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1791 Surf
->next_attached
= This
->next_attached
;
1792 Surf
->first_attached
= This
->first_attached
;
1793 This
->next_attached
= Surf
;
1795 /* Check if the WineD3D depth stencil needs updating */
1796 if (This
->ddraw
->d3ddevice
)
1797 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1799 wined3d_mutex_unlock();
1804 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1806 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1807 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1810 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1812 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1813 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1816 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1817 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1818 return DDERR_CANNOTATTACHSURFACE
;
1821 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1826 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1827 IUnknown_AddRef(attachment_impl
->attached_iface
);
1831 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1833 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1834 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1837 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1839 /* Tests suggest that
1840 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1841 * -> offscreen plain surfaces can be attached to primaries
1842 * -> primaries can be attached to offscreen plain surfaces
1843 * -> z buffers can be attached to primaries */
1844 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1845 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1847 /* Sizes have to match */
1848 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1849 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1851 WARN("Surface sizes do not match.\n");
1852 return DDERR_CANNOTATTACHSURFACE
;
1855 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1856 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1858 WARN("Invalid attachment combination.\n");
1859 return DDERR_CANNOTATTACHSURFACE
;
1862 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1865 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1866 IUnknown_AddRef(attachment_impl
->attached_iface
);
1870 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1872 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1873 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1876 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1878 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1879 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1882 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1883 IUnknown_AddRef(attachment_impl
->attached_iface
);
1884 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1888 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1890 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1891 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1894 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1896 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1897 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1900 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1901 IUnknown_AddRef(attachment_impl
->attached_iface
);
1902 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1906 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1908 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1909 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1912 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1914 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1915 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1918 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1919 IUnknown_AddRef(attachment_impl
->attached_iface
);
1920 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1924 /*****************************************************************************
1925 * IDirectDrawSurface7::DeleteAttachedSurface
1927 * Removes a surface from the attachment chain. The surface's refcount
1928 * is decreased by one after it has been removed
1931 * Flags: Some flags, not used by this implementation
1932 * Attach: Surface to detach
1936 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1938 *****************************************************************************/
1939 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1940 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1942 struct ddraw_surface
*prev
= surface
;
1944 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1946 wined3d_mutex_lock();
1947 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1949 wined3d_mutex_unlock();
1950 return DDERR_CANNOTDETACHSURFACE
;
1953 if (attachment
->attached_iface
!= detach_iface
)
1955 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1956 wined3d_mutex_unlock();
1957 return DDERR_SURFACENOTATTACHED
;
1960 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1961 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1963 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1964 /* FIXME: we should probably also subtract from dwMipMapCount of this
1965 * and all parent surfaces */
1968 /* Find the predecessor of the detached surface */
1971 if (prev
->next_attached
== attachment
)
1973 prev
= prev
->next_attached
;
1976 /* There must be a surface, otherwise there's a bug */
1979 /* Unchain the surface */
1980 prev
->next_attached
= attachment
->next_attached
;
1981 attachment
->next_attached
= NULL
;
1982 attachment
->first_attached
= attachment
;
1984 /* Check if the wined3d depth stencil needs updating. */
1985 if (surface
->ddraw
->d3ddevice
)
1986 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1987 wined3d_mutex_unlock();
1989 /* Set attached_iface to NULL before releasing it, the surface may go
1991 attachment
->attached_iface
= NULL
;
1992 IUnknown_Release(detach_iface
);
1997 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1998 DWORD flags
, IDirectDrawSurface7
*attachment
)
2000 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2001 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2003 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2005 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2008 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2009 DWORD flags
, IDirectDrawSurface4
*attachment
)
2011 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2012 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2014 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2016 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2019 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2020 DWORD flags
, IDirectDrawSurface3
*attachment
)
2022 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2023 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2025 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2027 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2030 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2031 DWORD flags
, IDirectDrawSurface2
*attachment
)
2033 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2034 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2036 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2038 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2041 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2042 DWORD flags
, IDirectDrawSurface
*attachment
)
2044 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2045 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2047 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2049 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2052 /*****************************************************************************
2053 * IDirectDrawSurface7::AddOverlayDirtyRect
2055 * "This method is not currently implemented"
2063 *****************************************************************************/
2064 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2066 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2068 return DDERR_UNSUPPORTED
; /* unchecked */
2071 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2073 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2075 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2077 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2080 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2082 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2091 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2102 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2104 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2107 /*****************************************************************************
2108 * IDirectDrawSurface7::GetDC
2110 * Returns a GDI device context for the surface
2113 * hdc: Address of a HDC variable to store the dc to
2117 * DDERR_INVALIDPARAMS if hdc is NULL
2118 * For details, see IWineD3DSurface::GetDC
2120 *****************************************************************************/
2121 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2123 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2126 TRACE("iface %p, dc %p.\n", iface
, dc
);
2129 return DDERR_INVALIDPARAMS
;
2131 wined3d_mutex_lock();
2132 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2133 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2135 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, dc
);
2141 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2143 const struct ddraw_palette
*palette
;
2145 if (surface
->palette
)
2146 palette
= surface
->palette
;
2147 else if (surface
->ddraw
->primary
)
2148 palette
= surface
->ddraw
->primary
->palette
;
2153 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *dc
);
2157 wined3d_mutex_unlock();
2160 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2161 * does not touch *dc. */
2162 case WINED3DERR_INVALIDCALL
:
2164 return DDERR_INVALIDPARAMS
;
2171 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2173 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2175 TRACE("iface %p, dc %p.\n", iface
, dc
);
2177 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2180 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2182 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2184 TRACE("iface %p, dc %p.\n", iface
, dc
);
2186 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2189 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2191 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2193 TRACE("iface %p, dc %p.\n", iface
, dc
);
2195 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2198 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2200 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2202 TRACE("iface %p, dc %p.\n", iface
, dc
);
2204 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2207 /*****************************************************************************
2208 * IDirectDrawSurface7::ReleaseDC
2210 * Releases the DC that was constructed with GetDC
2213 * hdc: HDC to release
2217 * For more details, see IWineD3DSurface::ReleaseDC
2219 *****************************************************************************/
2220 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2222 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2225 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2227 wined3d_mutex_lock();
2228 if (SUCCEEDED(hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, hdc
)))
2231 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2232 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2234 wined3d_mutex_unlock();
2240 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2242 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2244 TRACE("iface %p, dc %p.\n", iface
, dc
);
2246 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2249 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2253 TRACE("iface %p, dc %p.\n", iface
, dc
);
2255 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2258 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2262 TRACE("iface %p, dc %p.\n", iface
, dc
);
2264 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2267 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2269 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2271 TRACE("iface %p, dc %p.\n", iface
, dc
);
2273 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2276 /*****************************************************************************
2277 * IDirectDrawSurface7::GetCaps
2279 * Returns the surface's caps
2282 * Caps: Address to write the caps to
2286 * DDERR_INVALIDPARAMS if Caps is NULL
2288 *****************************************************************************/
2289 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2291 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2293 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2296 return DDERR_INVALIDPARAMS
;
2298 *Caps
= surface
->surface_desc
.ddsCaps
;
2303 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2305 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2307 TRACE("iface %p, caps %p.\n", iface
, caps
);
2309 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2312 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2314 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2318 TRACE("iface %p, caps %p.\n", iface
, caps
);
2320 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2321 if (FAILED(hr
)) return hr
;
2323 caps
->dwCaps
= caps2
.dwCaps
;
2327 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2329 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2333 TRACE("iface %p, caps %p.\n", iface
, caps
);
2335 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2336 if (FAILED(hr
)) return hr
;
2338 caps
->dwCaps
= caps2
.dwCaps
;
2342 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2344 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2348 TRACE("iface %p, caps %p.\n", iface
, caps
);
2350 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2351 if (FAILED(hr
)) return hr
;
2353 caps
->dwCaps
= caps2
.dwCaps
;
2357 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2359 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2360 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2362 struct wined3d_resource
*resource
;
2364 TRACE("iface %p, priority %u.\n", iface
, priority
);
2366 wined3d_mutex_lock();
2367 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2368 * calls on such surfaces segfault on Windows. */
2369 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2371 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2372 hr
= DDERR_INVALIDPARAMS
;
2376 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2377 wined3d_resource_set_priority(resource
, priority
);
2380 wined3d_mutex_unlock();
2385 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2387 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2388 const struct wined3d_resource
*resource
;
2389 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2392 TRACE("iface %p, priority %p.\n", iface
, priority
);
2394 wined3d_mutex_lock();
2395 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2397 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2398 hr
= DDERR_INVALIDOBJECT
;
2400 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2402 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2403 hr
= DDERR_INVALIDPARAMS
;
2407 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2408 *priority
= wined3d_resource_get_priority(resource
);
2411 wined3d_mutex_unlock();
2416 /*****************************************************************************
2417 * IDirectDrawSurface7::SetPrivateData
2419 * Stores some data in the surface that is intended for the application's
2423 * tag: GUID that identifies the data
2424 * Data: Pointer to the private data
2425 * Size: Size of the private data
2430 * For more details, see IWineD3DSurface::SetPrivateData
2432 *****************************************************************************/
2433 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2434 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2436 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2439 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2440 iface
, debugstr_guid(tag
), data
, size
, flags
);
2444 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2445 return DDERR_INVALIDPARAMS
;
2448 wined3d_mutex_lock();
2449 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2450 wined3d_mutex_unlock();
2451 return hr_ddraw_from_wined3d(hr
);
2454 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2455 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2457 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2459 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2460 iface
, debugstr_guid(tag
), data
, size
, flags
);
2462 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2465 /*****************************************************************************
2466 * IDirectDrawSurface7::GetPrivateData
2468 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2471 * tag: GUID of the data to return
2472 * Data: Address where to write the data to
2473 * Size: Size of the buffer at Data
2477 * DDERR_INVALIDPARAMS if Data is NULL
2478 * For more details, see IWineD3DSurface::GetPrivateData
2480 *****************************************************************************/
2481 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2483 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2484 const struct wined3d_private_data
*stored_data
;
2487 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2488 iface
, debugstr_guid(tag
), data
, size
);
2490 wined3d_mutex_lock();
2491 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2494 hr
= DDERR_NOTFOUND
;
2499 hr
= DDERR_INVALIDPARAMS
;
2502 if (*size
< stored_data
->size
)
2504 *size
= stored_data
->size
;
2505 hr
= DDERR_MOREDATA
;
2510 hr
= DDERR_INVALIDPARAMS
;
2514 *size
= stored_data
->size
;
2515 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2519 wined3d_mutex_unlock();
2523 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2525 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2527 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2528 iface
, debugstr_guid(tag
), data
, size
);
2530 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2533 /*****************************************************************************
2534 * IDirectDrawSurface7::FreePrivateData
2536 * Frees private data stored in the surface
2539 * tag: Tag of the data to free
2543 * For more details, see IWineD3DSurface::FreePrivateData
2545 *****************************************************************************/
2546 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2548 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2549 struct wined3d_private_data
*entry
;
2551 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2553 wined3d_mutex_lock();
2554 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2557 wined3d_mutex_unlock();
2558 return DDERR_NOTFOUND
;
2561 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2562 wined3d_mutex_unlock();
2567 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2569 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2571 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2573 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2576 /*****************************************************************************
2577 * IDirectDrawSurface7::PageLock
2579 * Prevents a sysmem surface from being paged out
2582 * Flags: Not used, must be 0(unchecked)
2585 * DD_OK, because it's a stub
2587 *****************************************************************************/
2588 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2590 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2592 /* This is Windows memory management related - we don't need this */
2596 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2598 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2600 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2602 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2605 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2607 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2609 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2611 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2614 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2616 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2618 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2620 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2623 /*****************************************************************************
2624 * IDirectDrawSurface7::PageUnlock
2626 * Allows a sysmem surface to be paged out
2629 * Flags: Not used, must be 0(unchecked)
2632 * DD_OK, because it's a stub
2634 *****************************************************************************/
2635 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2637 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2642 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2644 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2646 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2648 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2651 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2653 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2655 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2657 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2660 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2662 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2664 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2666 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2669 /*****************************************************************************
2670 * IDirectDrawSurface7::BltBatch
2672 * An unimplemented function
2680 *****************************************************************************/
2681 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2683 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2685 /* MSDN: "not currently implemented" */
2686 return DDERR_UNSUPPORTED
;
2689 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2691 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2693 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2695 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2698 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2700 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2709 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2718 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(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 /*****************************************************************************
2726 * IDirectDrawSurface7::EnumAttachedSurfaces
2728 * Enumerates all surfaces attached to this surface
2731 * context: Pointer to pass unmodified to the callback
2732 * cb: Callback function to call for each surface
2736 * DDERR_INVALIDPARAMS if cb is NULL
2738 *****************************************************************************/
2739 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2740 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2742 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2743 struct ddraw_surface
*surf
;
2744 DDSURFACEDESC2 desc
;
2747 /* Attached surfaces aren't handled in WineD3D */
2748 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2751 return DDERR_INVALIDPARAMS
;
2753 wined3d_mutex_lock();
2755 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2757 surf
= surface
->complex_array
[i
];
2760 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2761 desc
= surf
->surface_desc
;
2762 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2763 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2765 wined3d_mutex_unlock();
2770 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2772 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2773 desc
= surf
->surface_desc
;
2774 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2775 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2777 wined3d_mutex_unlock();
2782 TRACE(" end of enumeration.\n");
2784 wined3d_mutex_unlock();
2789 struct callback_info2
2791 LPDDENUMSURFACESCALLBACK2 callback
;
2795 struct callback_info
2797 LPDDENUMSURFACESCALLBACK callback
;
2801 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2803 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2804 const struct callback_info2
*info
= context
;
2806 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2807 ddraw_surface7_Release(surface
);
2809 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2812 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2814 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2815 const struct callback_info
*info
= context
;
2817 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2818 ddraw_surface7_Release(surface
);
2820 /* FIXME: Check surface_test.dwSize */
2821 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2822 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2825 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2826 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2828 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2829 struct callback_info2 info
;
2831 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2833 info
.callback
= callback
;
2834 info
.context
= context
;
2836 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2837 &info
, EnumCallback2
);
2840 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2841 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2843 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2844 struct callback_info info
;
2846 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2848 info
.callback
= callback
;
2849 info
.context
= context
;
2851 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2852 &info
, EnumCallback
);
2855 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2856 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2858 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2859 struct callback_info info
;
2861 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2863 info
.callback
= callback
;
2864 info
.context
= context
;
2866 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2867 &info
, EnumCallback
);
2870 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2871 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2873 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2874 struct callback_info info
;
2876 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2878 info
.callback
= callback
;
2879 info
.context
= context
;
2881 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2882 &info
, EnumCallback
);
2885 /*****************************************************************************
2886 * IDirectDrawSurface7::EnumOverlayZOrders
2888 * "Enumerates the overlay surfaces on the specified destination"
2891 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2892 * context: context to pass back to the callback
2893 * cb: callback function to call for each enumerated surface
2896 * DD_OK, because it's a stub
2898 *****************************************************************************/
2899 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2900 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2902 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2907 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2908 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2910 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2911 struct callback_info2 info
;
2913 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2915 info
.callback
= callback
;
2916 info
.context
= context
;
2918 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2919 flags
, &info
, EnumCallback2
);
2922 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2923 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2925 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2926 struct callback_info info
;
2928 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2930 info
.callback
= callback
;
2931 info
.context
= context
;
2933 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2934 flags
, &info
, EnumCallback
);
2937 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2938 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2940 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2941 struct callback_info info
;
2943 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2945 info
.callback
= callback
;
2946 info
.context
= context
;
2948 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2949 flags
, &info
, EnumCallback
);
2952 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2953 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2955 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2956 struct callback_info info
;
2958 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2960 info
.callback
= callback
;
2961 info
.context
= context
;
2963 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2964 flags
, &info
, EnumCallback
);
2967 /*****************************************************************************
2968 * IDirectDrawSurface7::GetBltStatus
2970 * Returns the blitting status
2973 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2976 * See IWineD3DSurface::Blt
2978 *****************************************************************************/
2979 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2981 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2985 case WINEDDGBS_CANBLT
:
2986 case WINEDDGBS_ISBLTDONE
:
2990 return DDERR_INVALIDPARAMS
;
2994 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2996 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2998 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3000 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3003 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3005 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3007 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3009 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3012 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3014 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3016 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3018 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3021 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3023 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3025 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3027 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3030 /*****************************************************************************
3031 * IDirectDrawSurface7::GetColorKey
3033 * Returns the color key assigned to the surface
3037 * CKey: Address to store the key to
3041 * DDERR_INVALIDPARAMS if CKey is NULL
3043 *****************************************************************************/
3044 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3046 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3048 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3051 return DDERR_INVALIDPARAMS
;
3053 wined3d_mutex_lock();
3057 case DDCKEY_DESTBLT
:
3058 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3060 wined3d_mutex_unlock();
3061 return DDERR_NOCOLORKEY
;
3063 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3066 case DDCKEY_DESTOVERLAY
:
3067 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3069 wined3d_mutex_unlock();
3070 return DDERR_NOCOLORKEY
;
3072 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3076 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3078 wined3d_mutex_unlock();
3079 return DDERR_NOCOLORKEY
;
3081 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3084 case DDCKEY_SRCOVERLAY
:
3085 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3087 wined3d_mutex_unlock();
3088 return DDERR_NOCOLORKEY
;
3090 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3094 wined3d_mutex_unlock();
3095 return DDERR_INVALIDPARAMS
;
3098 wined3d_mutex_unlock();
3103 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3105 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3107 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3109 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3112 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3114 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3123 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3132 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(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 /*****************************************************************************
3140 * IDirectDrawSurface7::GetFlipStatus
3142 * Returns the flipping status of the surface
3145 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3148 * See IWineD3DSurface::GetFlipStatus
3150 *****************************************************************************/
3151 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3153 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3155 /* XXX: DDERR_INVALIDSURFACETYPE */
3159 case WINEDDGFS_CANFLIP
:
3160 case WINEDDGFS_ISFLIPDONE
:
3164 return DDERR_INVALIDPARAMS
;
3168 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3170 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3172 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3174 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3177 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3179 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3181 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3183 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3186 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3188 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3190 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3192 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3195 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3197 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3199 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3201 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3204 /*****************************************************************************
3205 * IDirectDrawSurface7::GetOverlayPosition
3207 * Returns the display coordinates of a visible and active overlay surface
3214 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3215 *****************************************************************************/
3216 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3218 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3221 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3223 wined3d_mutex_lock();
3224 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3225 surface
->sub_resource_idx
, x
, y
);
3226 wined3d_mutex_unlock();
3231 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3233 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3235 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3237 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3240 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3242 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3262 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3264 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3267 /*****************************************************************************
3268 * IDirectDrawSurface7::GetPixelFormat
3270 * Returns the pixel format of the Surface
3273 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3274 * format should be written
3278 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3280 *****************************************************************************/
3281 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3283 /* What is DDERR_INVALIDSURFACETYPE for here? */
3284 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3286 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3289 return DDERR_INVALIDPARAMS
;
3291 wined3d_mutex_lock();
3292 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3293 wined3d_mutex_unlock();
3298 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3300 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3302 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3304 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3307 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3309 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3318 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3327 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3329 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3331 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3334 /*****************************************************************************
3335 * IDirectDrawSurface7::GetSurfaceDesc
3337 * Returns the description of this surface
3340 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3345 * DDERR_INVALIDPARAMS if DDSD is NULL
3347 *****************************************************************************/
3348 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3350 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3352 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3355 return DDERR_INVALIDPARAMS
;
3357 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3359 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3360 return DDERR_INVALIDPARAMS
;
3363 wined3d_mutex_lock();
3364 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3365 TRACE("Returning surface desc:\n");
3366 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3367 wined3d_mutex_unlock();
3372 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3376 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3378 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3381 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3383 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3385 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3387 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3389 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3391 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3392 return DDERR_INVALIDPARAMS
;
3395 wined3d_mutex_lock();
3396 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3397 TRACE("Returning surface desc:\n");
3398 if (TRACE_ON(ddraw
))
3400 /* DDRAW_dump_surface_desc handles the smaller size */
3401 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3403 wined3d_mutex_unlock();
3408 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3410 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3412 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3414 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3417 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3419 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3421 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3423 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3426 /*****************************************************************************
3427 * IDirectDrawSurface7::Initialize
3429 * Initializes the surface. This is a no-op in Wine
3432 * DD: Pointer to an DirectDraw interface
3433 * DDSD: Surface description for initialization
3436 * DDERR_ALREADYINITIALIZED
3438 *****************************************************************************/
3439 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3440 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3442 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3444 return DDERR_ALREADYINITIALIZED
;
3447 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3448 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3450 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3452 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3454 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3455 ddraw
, surface_desc
);
3458 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3459 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3461 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3462 DDSURFACEDESC2 surface_desc2
;
3464 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3466 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3467 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3468 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3471 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3472 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3474 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3475 DDSURFACEDESC2 surface_desc2
;
3477 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3479 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3480 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3481 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3484 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3485 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3487 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3488 DDSURFACEDESC2 surface_desc2
;
3490 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3492 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3493 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3494 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3497 /*****************************************************************************
3498 * IDirect3DTexture1::Initialize
3500 * The sdk says it's not implemented
3508 *****************************************************************************/
3509 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3510 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3512 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3514 return DDERR_UNSUPPORTED
; /* Unchecked */
3517 /*****************************************************************************
3518 * IDirectDrawSurface7::IsLost
3520 * Checks if the surface is lost
3523 * DD_OK, if the surface is usable
3524 * DDERR_ISLOST if the surface is lost
3525 * See IWineD3DSurface::IsLost for more details
3527 *****************************************************************************/
3528 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3530 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3532 TRACE("iface %p.\n", iface
);
3534 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3535 return DDERR_SURFACELOST
;
3540 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3542 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3544 TRACE("iface %p.\n", iface
);
3546 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3549 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3551 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3553 TRACE("iface %p.\n", iface
);
3555 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3558 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3560 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3562 TRACE("iface %p.\n", iface
);
3564 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3567 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3569 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3571 TRACE("iface %p.\n", iface
);
3573 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3576 /*****************************************************************************
3577 * IDirectDrawSurface7::Restore
3579 * Restores a lost surface. This makes the surface usable again, but
3580 * doesn't reload its old contents
3584 * See IWineD3DSurface::Restore for more details
3586 *****************************************************************************/
3587 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3589 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3591 TRACE("iface %p.\n", iface
);
3593 ddraw_update_lost_surfaces(surface
->ddraw
);
3594 surface
->is_lost
= FALSE
;
3599 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3601 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3603 TRACE("iface %p.\n", iface
);
3605 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3608 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3610 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3612 TRACE("iface %p.\n", iface
);
3614 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3617 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3619 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3621 TRACE("iface %p.\n", iface
);
3623 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3626 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3628 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3630 TRACE("iface %p.\n", iface
);
3632 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3635 /*****************************************************************************
3636 * IDirectDrawSurface7::SetOverlayPosition
3638 * Changes the display coordinates of an overlay surface
3645 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3646 *****************************************************************************/
3647 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3649 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3652 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3654 wined3d_mutex_lock();
3655 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3656 surface
->sub_resource_idx
, x
, y
);
3657 wined3d_mutex_unlock();
3662 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3664 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3666 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3668 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3671 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3673 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3682 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3691 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3693 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3695 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3698 /*****************************************************************************
3699 * IDirectDrawSurface7::UpdateOverlay
3701 * Modifies the attributes of an overlay surface.
3704 * SrcRect: The section of the source being used for the overlay
3705 * DstSurface: Address of the surface that is overlaid
3706 * DstRect: Place of the overlay
3707 * Flags: some DDOVER_* flags
3710 * DDERR_UNSUPPORTED, because we don't support overlays
3712 *****************************************************************************/
3713 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3714 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3716 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3717 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3718 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3719 unsigned int dst_sub_resource_idx
= 0;
3722 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3723 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3726 FIXME("Ignoring fx %p.\n", fx
);
3728 wined3d_mutex_lock();
3731 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3732 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3734 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3735 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3736 wined3d_mutex_unlock();
3740 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3741 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3742 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3748 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3749 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3751 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3752 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3754 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3755 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3757 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3758 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3761 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3762 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3764 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3765 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3767 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3768 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3770 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3771 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3774 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3775 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3777 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3778 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3780 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3781 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3783 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3784 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3787 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3788 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3790 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3791 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3793 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3794 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3796 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3797 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3800 /*****************************************************************************
3801 * IDirectDrawSurface7::UpdateOverlayDisplay
3803 * The DX7 sdk says that it's not implemented
3808 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3810 *****************************************************************************/
3811 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3813 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3815 return DDERR_UNSUPPORTED
;
3818 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3820 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3822 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3824 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3827 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3829 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3831 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3833 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3836 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3838 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3840 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3842 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3845 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3847 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3849 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3851 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3854 /*****************************************************************************
3855 * IDirectDrawSurface7::UpdateOverlayZOrder
3857 * Sets an overlay's Z order
3860 * Flags: DDOVERZ_* flags
3861 * DDSRef: Defines the relative position in the overlay chain
3864 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3866 *****************************************************************************/
3867 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3868 DWORD flags
, IDirectDrawSurface7
*reference
)
3870 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3872 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
3874 wined3d_mutex_lock();
3875 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
3877 WARN("Not an overlay surface.\n");
3878 wined3d_mutex_unlock();
3879 return DDERR_NOTAOVERLAYSURFACE
;
3881 wined3d_mutex_unlock();
3886 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3887 DWORD flags
, IDirectDrawSurface4
*reference
)
3889 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3890 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3892 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3894 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3895 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3898 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3899 DWORD flags
, IDirectDrawSurface3
*reference
)
3901 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3902 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3904 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3906 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3907 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3910 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3911 DWORD flags
, IDirectDrawSurface2
*reference
)
3913 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3914 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3916 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3918 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3919 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3922 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3923 DWORD flags
, IDirectDrawSurface
*reference
)
3925 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3926 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3928 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3930 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3931 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3934 /*****************************************************************************
3935 * IDirectDrawSurface7::GetDDInterface
3937 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3938 * surface belongs to
3941 * DD: Address to write the interface pointer to
3945 * DDERR_INVALIDPARAMS if DD is NULL
3947 *****************************************************************************/
3948 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3950 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3952 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3955 return DDERR_INVALIDPARAMS
;
3957 switch(This
->version
)
3960 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3964 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3968 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3972 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3976 IUnknown_AddRef((IUnknown
*)*DD
);
3981 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3983 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3985 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3987 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3990 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3992 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3994 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3996 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3999 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4001 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4003 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4005 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4008 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4010 TRACE("iface %p.\n", iface
);
4015 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4017 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4019 TRACE("iface %p.\n", iface
);
4021 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4024 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4026 TRACE("iface %p, value %p.\n", iface
, pValue
);
4033 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4035 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4037 TRACE("iface %p, value %p.\n", iface
, pValue
);
4039 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4042 /*****************************************************************************
4043 * IDirectDrawSurface7::SetLOD
4045 * Sets the level of detail of a texture
4048 * MaxLOD: LOD to set
4052 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4054 *****************************************************************************/
4055 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4057 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4060 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4062 wined3d_mutex_lock();
4063 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4065 wined3d_mutex_unlock();
4066 return DDERR_INVALIDOBJECT
;
4069 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4070 wined3d_mutex_unlock();
4075 /*****************************************************************************
4076 * IDirectDrawSurface7::GetLOD
4078 * Returns the level of detail of a Direct3D texture
4081 * MaxLOD: Address to write the LOD to
4085 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4086 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4088 *****************************************************************************/
4089 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4091 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4093 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4096 return DDERR_INVALIDPARAMS
;
4098 wined3d_mutex_lock();
4099 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4101 wined3d_mutex_unlock();
4102 return DDERR_INVALIDOBJECT
;
4105 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4106 wined3d_mutex_unlock();
4111 /*****************************************************************************
4112 * IDirectDrawSurface7::BltFast
4114 * Performs a fast Blit.
4117 * dstx: The x coordinate to blit to on the destination
4118 * dsty: The y coordinate to blit to on the destination
4119 * Source: The source surface
4120 * rsrc: The source rectangle
4121 * trans: Type of transfer. Some DDBLTFAST_* flags
4125 * For more details, see IWineD3DSurface::BltFast
4127 *****************************************************************************/
4128 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4129 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4131 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4132 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4133 DWORD src_w
, src_h
, dst_w
, dst_h
;
4138 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4139 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4141 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4142 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4146 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4150 src_w
= src_rect
->right
- src_rect
->left
;
4151 src_h
= src_rect
->bottom
- src_rect
->top
;
4152 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4153 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4155 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4156 return DDERR_INVALIDRECT
;
4159 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4160 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4161 flags
|= WINED3D_BLT_SRC_CKEY
;
4162 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4163 flags
|= WINED3D_BLT_DST_CKEY
;
4164 if (trans
& DDBLTFAST_WAIT
)
4165 flags
|= WINED3D_BLT_WAIT
;
4166 if (trans
& DDBLTFAST_DONOTWAIT
)
4167 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4169 wined3d_mutex_lock();
4170 if (dst_impl
->clipper
)
4172 wined3d_mutex_unlock();
4173 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4174 return DDERR_BLTFASTCANTCLIP
;
4177 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4178 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
);
4180 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
4181 src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4182 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4183 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
);
4184 wined3d_mutex_unlock();
4188 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4193 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4194 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4196 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4197 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4199 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4200 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4202 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4203 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4206 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4207 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4209 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4210 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4212 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4213 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4215 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4216 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4219 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4220 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4222 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4223 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4225 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4226 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4228 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4229 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4232 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4233 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4235 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4236 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4238 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4239 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4241 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4242 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4245 /*****************************************************************************
4246 * IDirectDrawSurface7::GetClipper
4248 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4252 * Clipper: Address to store the interface pointer at
4256 * DDERR_INVALIDPARAMS if Clipper is NULL
4257 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4259 *****************************************************************************/
4260 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4262 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4264 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4267 return DDERR_INVALIDPARAMS
;
4269 wined3d_mutex_lock();
4270 if (!surface
->clipper
)
4272 wined3d_mutex_unlock();
4273 return DDERR_NOCLIPPERATTACHED
;
4276 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4277 IDirectDrawClipper_AddRef(*Clipper
);
4278 wined3d_mutex_unlock();
4283 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4285 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4287 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4289 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4292 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4294 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4296 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4298 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4301 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4303 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4305 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4307 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4310 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4312 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4314 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4316 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4319 /*****************************************************************************
4320 * IDirectDrawSurface7::SetClipper
4322 * Sets a clipper for the surface
4325 * Clipper: IDirectDrawClipper interface of the clipper to set
4330 *****************************************************************************/
4331 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4332 IDirectDrawClipper
*iclipper
)
4334 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4335 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4336 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4339 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4341 wined3d_mutex_lock();
4342 if (clipper
== This
->clipper
)
4344 wined3d_mutex_unlock();
4348 This
->clipper
= clipper
;
4350 if (clipper
!= NULL
)
4351 IDirectDrawClipper_AddRef(iclipper
);
4353 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4355 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4359 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4364 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4365 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4369 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4370 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4374 wined3d_mutex_unlock();
4379 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4381 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4383 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4385 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4388 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4390 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4392 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4394 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4397 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4399 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4401 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4403 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4406 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4408 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4410 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4412 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4415 /*****************************************************************************
4416 * IDirectDrawSurface7::SetSurfaceDesc
4418 * Sets the surface description. It can override the pixel format, the surface
4420 * It's not really tested.
4423 * DDSD: Pointer to the new surface description to set
4428 * DDERR_INVALIDPARAMS if DDSD is NULL
4430 *****************************************************************************/
4431 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4433 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4435 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4436 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4437 enum wined3d_format_id format_id
;
4438 UINT pitch
, width
, height
;
4440 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4444 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4445 return DDERR_INVALIDPARAMS
;
4449 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4450 return DDERR_INVALIDPARAMS
;
4452 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4453 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4454 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4456 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4457 return DDERR_INVALIDSURFACETYPE
;
4460 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4461 * for PIXELFORMAT to work */
4462 if (DDSD
->dwFlags
& ~allowed_flags
)
4464 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4465 return DDERR_INVALIDPARAMS
;
4467 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4469 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4470 return DDERR_INVALIDPARAMS
;
4472 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4474 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4475 return DDERR_INVALIDCAPS
;
4477 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4479 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4481 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4482 return DDERR_INVALIDPARAMS
;
4484 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4486 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4487 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4488 return DDERR_INVALIDPARAMS
;
4490 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4491 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4492 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4493 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4494 pitch
= DDSD
->u1
.lPitch
;
4495 width
= DDSD
->dwWidth
;
4497 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4499 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4500 return DDERR_INVALIDPARAMS
;
4504 pitch
= This
->surface_desc
.u1
.lPitch
;
4505 width
= This
->surface_desc
.dwWidth
;
4508 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4510 if (!DDSD
->dwHeight
)
4512 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4513 return DDERR_INVALIDPARAMS
;
4515 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4516 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4517 height
= DDSD
->dwHeight
;
4521 height
= This
->surface_desc
.dwHeight
;
4524 wined3d_mutex_lock();
4525 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4527 enum wined3d_format_id current_format_id
;
4528 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4530 if (format_id
== WINED3DFMT_UNKNOWN
)
4532 ERR("Requested to set an unknown pixelformat\n");
4533 wined3d_mutex_unlock();
4534 return DDERR_INVALIDPARAMS
;
4536 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4537 if (format_id
!= current_format_id
)
4538 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4542 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4545 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4546 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4548 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4549 wined3d_mutex_unlock();
4550 return hr_ddraw_from_wined3d(hr
);
4553 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4554 This
->surface_desc
.dwWidth
= width
;
4555 if (DDSD
->dwFlags
& DDSD_PITCH
)
4556 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4557 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4558 This
->surface_desc
.dwHeight
= height
;
4559 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4560 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4562 wined3d_mutex_unlock();
4567 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4568 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4570 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4572 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4574 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4575 surface_desc
, flags
);
4578 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4579 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4581 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4582 DDSURFACEDESC2 surface_desc2
;
4584 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4586 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4587 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4588 surface_desc
? &surface_desc2
: NULL
, flags
);
4591 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4593 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4594 struct ddraw_palette
*palette_impl
;
4597 TRACE("iface %p, palette %p.\n", iface
, palette
);
4600 return DDERR_INVALIDPARAMS
;
4601 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4603 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4604 return DDERR_SURFACELOST
;
4607 wined3d_mutex_lock();
4608 if ((palette_impl
= surface
->palette
))
4610 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4611 IDirectDrawPalette_AddRef(*palette
);
4616 hr
= DDERR_NOPALETTEATTACHED
;
4618 wined3d_mutex_unlock();
4623 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4625 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4627 TRACE("iface %p, palette %p.\n", iface
, palette
);
4629 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4632 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4634 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4636 TRACE("iface %p, palette %p.\n", iface
, palette
);
4638 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4641 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4643 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4645 TRACE("iface %p, palette %p.\n", iface
, palette
);
4647 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4650 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4652 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4654 TRACE("iface %p, palette %p.\n", iface
, palette
);
4656 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4659 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4661 DDCOLORKEY fixed_color_key
;
4662 HRESULT hr
= WINED3D_OK
;
4664 if (flags
& DDCKEY_COLORSPACE
)
4666 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4668 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4669 return DDERR_NOCOLORKEYHW
;
4671 flags
&= ~DDCKEY_COLORSPACE
;
4674 wined3d_mutex_lock();
4678 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4679 switch (flags
& ~DDCKEY_COLORSPACE
)
4681 case DDCKEY_DESTBLT
:
4682 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4683 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4686 case DDCKEY_DESTOVERLAY
:
4687 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4688 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4691 case DDCKEY_SRCOVERLAY
:
4692 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4693 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4697 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4698 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4702 wined3d_mutex_unlock();
4703 return DDERR_INVALIDPARAMS
;
4708 switch (flags
& ~DDCKEY_COLORSPACE
)
4710 case DDCKEY_DESTBLT
:
4711 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4714 case DDCKEY_DESTOVERLAY
:
4715 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4718 case DDCKEY_SRCOVERLAY
:
4719 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4723 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4727 wined3d_mutex_unlock();
4728 return DDERR_INVALIDPARAMS
;
4732 if (surface
->is_complex_root
)
4733 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4734 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4736 wined3d_mutex_unlock();
4738 return hr_ddraw_from_wined3d(hr
);
4741 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4743 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4745 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4747 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4748 return DDERR_NOTONMIPMAPSUBLEVEL
;
4750 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4753 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4755 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4757 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4759 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4762 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4764 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(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_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4773 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(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_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4782 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(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_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4791 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4793 TRACE("iface %p, palette %p.\n", iface
, palette
);
4795 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4796 return DDERR_NOTONMIPMAPSUBLEVEL
;
4797 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4799 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4800 return DDERR_SURFACELOST
;
4803 return ddraw_surface_set_palette(surface
, palette
);
4806 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4808 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4810 TRACE("iface %p, palette %p.\n", iface
, palette
);
4812 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4814 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4815 return DDERR_SURFACELOST
;
4818 return ddraw_surface_set_palette(surface
, palette
);
4821 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4823 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4825 TRACE("iface %p, palette %p.\n", iface
, palette
);
4827 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4829 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4830 return DDERR_SURFACELOST
;
4833 return ddraw_surface_set_palette(surface
, palette
);
4836 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4838 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4840 TRACE("iface %p, palette %p.\n", iface
, palette
);
4842 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4844 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4845 return DDERR_SURFACELOST
;
4848 return ddraw_surface_set_palette(surface
, palette
);
4851 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4853 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4855 TRACE("iface %p, palette %p.\n", iface
, palette
);
4857 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4859 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4860 return DDERR_SURFACELOST
;
4863 return ddraw_surface_set_palette(surface
, palette
);
4866 /**********************************************************
4867 * IDirectDrawGammaControl::GetGammaRamp
4869 * Returns the current gamma ramp for a surface
4873 * gamma_ramp: Address to write the ramp to
4877 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4879 **********************************************************/
4880 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4881 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4883 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4885 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4889 WARN("Invalid gamma_ramp passed.\n");
4890 return DDERR_INVALIDPARAMS
;
4893 wined3d_mutex_lock();
4894 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4896 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4897 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4901 ERR("Not implemented for non-primary surfaces.\n");
4903 wined3d_mutex_unlock();
4908 /**********************************************************
4909 * IDirectDrawGammaControl::SetGammaRamp
4911 * Sets the red, green and blue gamma ramps for
4914 * flags: Can be DDSGR_CALIBRATE to request calibration
4915 * gamma_ramp: Structure containing the new gamma ramp
4919 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4921 **********************************************************/
4922 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4923 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4925 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4927 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4931 WARN("Invalid gamma_ramp passed.\n");
4932 return DDERR_INVALIDPARAMS
;
4935 wined3d_mutex_lock();
4936 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4938 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4939 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4940 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4944 ERR("Not implemented for non-primary surfaces.\n");
4946 wined3d_mutex_unlock();
4951 /*****************************************************************************
4952 * IDirect3DTexture2::PaletteChanged
4954 * Informs the texture about a palette change
4957 * start: Start index of the change
4958 * count: The number of changed entries
4961 * D3D_OK, because it's a stub
4963 *****************************************************************************/
4964 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4966 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4971 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4973 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4975 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4977 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4980 /*****************************************************************************
4981 * IDirect3DTexture::Unload
4983 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4989 *****************************************************************************/
4990 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4992 WARN("iface %p. Not implemented.\n", iface
);
4994 return DDERR_UNSUPPORTED
;
4997 /*****************************************************************************
4998 * IDirect3DTexture2::GetHandle
5000 * Returns handle for the texture. At the moment, the interface
5001 * to the IWineD3DTexture is used.
5004 * device: Device this handle is assigned to
5005 * handle: Address to store the handle at.
5010 *****************************************************************************/
5011 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5012 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5014 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5015 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5017 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5019 wined3d_mutex_lock();
5021 if (!surface
->Handle
)
5023 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5024 if (h
== DDRAW_INVALID_HANDLE
)
5026 ERR("Failed to allocate a texture handle.\n");
5027 wined3d_mutex_unlock();
5028 return DDERR_OUTOFMEMORY
;
5031 surface
->Handle
= h
+ 1;
5034 TRACE("Returning handle %08x.\n", surface
->Handle
);
5035 *handle
= surface
->Handle
;
5037 wined3d_mutex_unlock();
5042 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5043 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5045 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5046 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5048 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5050 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5051 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5054 /*****************************************************************************
5055 * get_sub_mimaplevel
5057 * Helper function that returns the next mipmap level
5059 * tex_ptr: Surface of which to return the next level
5061 *****************************************************************************/
5062 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5064 /* Now go down the mipmap chain to the next surface */
5065 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5066 IDirectDrawSurface7
*next_level
;
5069 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5070 if (FAILED(hr
)) return NULL
;
5072 ddraw_surface7_Release(next_level
);
5074 return impl_from_IDirectDrawSurface7(next_level
);
5077 /*****************************************************************************
5078 * IDirect3DTexture2::Load
5080 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5082 * This function isn't relayed to WineD3D because the whole interface is
5083 * implemented in DDraw only. For speed improvements an implementation which
5084 * takes OpenGL more into account could be placed into WineD3D.
5087 * src_texture: Address of the texture to load
5091 * D3DERR_TEXTURE_LOAD_FAILED.
5093 *****************************************************************************/
5094 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5096 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5097 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5098 struct wined3d_resource
*dst_resource
, *src_resource
;
5101 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5103 if (src_surface
== dst_surface
)
5105 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5109 wined3d_mutex_lock();
5111 dst_resource
= wined3d_texture_get_resource(dst_surface
->wined3d_texture
);
5112 src_resource
= wined3d_texture_get_resource(src_surface
->wined3d_texture
);
5114 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5115 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5116 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5118 ERR("Trying to load surfaces with different mip-map counts.\n");
5123 struct ddraw_palette
*dst_pal
, *src_pal
;
5124 DDSURFACEDESC
*src_desc
, *dst_desc
;
5126 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5128 /* Suppress the ALLOCONLOAD flag */
5129 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5131 /* Get the palettes */
5132 dst_pal
= dst_surface
->palette
;
5133 src_pal
= src_surface
->palette
;
5137 PALETTEENTRY palent
[256];
5141 wined3d_mutex_unlock();
5142 return DDERR_NOPALETTEATTACHED
;
5144 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5145 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5148 /* Copy one surface on the other */
5149 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5150 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5152 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5154 /* Should also check for same pixel format, u1.lPitch, ... */
5155 ERR("Error in surface sizes.\n");
5156 wined3d_mutex_unlock();
5157 return D3DERR_TEXTURE_LOAD_FAILED
;
5161 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5163 /* Copy the src blit color key if the source has one, don't erase
5164 * the destination's ckey if the source has none */
5165 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5167 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5168 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5171 if (FAILED(hr
= wined3d_resource_map(src_resource
,
5172 src_surface
->sub_resource_idx
, &src_map_desc
, NULL
, 0)))
5174 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5175 wined3d_mutex_unlock();
5176 return D3DERR_TEXTURE_LOAD_FAILED
;
5179 if (FAILED(hr
= wined3d_resource_map(dst_resource
,
5180 dst_surface
->sub_resource_idx
, &dst_map_desc
, NULL
, 0)))
5182 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5183 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5184 wined3d_mutex_unlock();
5185 return D3DERR_TEXTURE_LOAD_FAILED
;
5188 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5189 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5191 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5193 wined3d_resource_unmap(dst_resource
, dst_surface
->sub_resource_idx
);
5194 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5197 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5198 src_surface
= get_sub_mimaplevel(src_surface
);
5202 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5203 dst_surface
= get_sub_mimaplevel(dst_surface
);
5207 if (!src_surface
|| !dst_surface
)
5209 if (src_surface
!= dst_surface
)
5210 ERR("Loading surface with different mipmap structure.\n");
5215 wined3d_mutex_unlock();
5220 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5222 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5223 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5225 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5227 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5228 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5231 /*****************************************************************************
5233 *****************************************************************************/
5235 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5238 ddraw_surface7_QueryInterface
,
5239 ddraw_surface7_AddRef
,
5240 ddraw_surface7_Release
,
5241 /* IDirectDrawSurface */
5242 ddraw_surface7_AddAttachedSurface
,
5243 ddraw_surface7_AddOverlayDirtyRect
,
5245 ddraw_surface7_BltBatch
,
5246 ddraw_surface7_BltFast
,
5247 ddraw_surface7_DeleteAttachedSurface
,
5248 ddraw_surface7_EnumAttachedSurfaces
,
5249 ddraw_surface7_EnumOverlayZOrders
,
5250 ddraw_surface7_Flip
,
5251 ddraw_surface7_GetAttachedSurface
,
5252 ddraw_surface7_GetBltStatus
,
5253 ddraw_surface7_GetCaps
,
5254 ddraw_surface7_GetClipper
,
5255 ddraw_surface7_GetColorKey
,
5256 ddraw_surface7_GetDC
,
5257 ddraw_surface7_GetFlipStatus
,
5258 ddraw_surface7_GetOverlayPosition
,
5259 ddraw_surface7_GetPalette
,
5260 ddraw_surface7_GetPixelFormat
,
5261 ddraw_surface7_GetSurfaceDesc
,
5262 ddraw_surface7_Initialize
,
5263 ddraw_surface7_IsLost
,
5264 ddraw_surface7_Lock
,
5265 ddraw_surface7_ReleaseDC
,
5266 ddraw_surface7_Restore
,
5267 ddraw_surface7_SetClipper
,
5268 ddraw_surface7_SetColorKey
,
5269 ddraw_surface7_SetOverlayPosition
,
5270 ddraw_surface7_SetPalette
,
5271 ddraw_surface7_Unlock
,
5272 ddraw_surface7_UpdateOverlay
,
5273 ddraw_surface7_UpdateOverlayDisplay
,
5274 ddraw_surface7_UpdateOverlayZOrder
,
5275 /* IDirectDrawSurface2 */
5276 ddraw_surface7_GetDDInterface
,
5277 ddraw_surface7_PageLock
,
5278 ddraw_surface7_PageUnlock
,
5279 /* IDirectDrawSurface3 */
5280 ddraw_surface7_SetSurfaceDesc
,
5281 /* IDirectDrawSurface4 */
5282 ddraw_surface7_SetPrivateData
,
5283 ddraw_surface7_GetPrivateData
,
5284 ddraw_surface7_FreePrivateData
,
5285 ddraw_surface7_GetUniquenessValue
,
5286 ddraw_surface7_ChangeUniquenessValue
,
5287 /* IDirectDrawSurface7 */
5288 ddraw_surface7_SetPriority
,
5289 ddraw_surface7_GetPriority
,
5290 ddraw_surface7_SetLOD
,
5291 ddraw_surface7_GetLOD
,
5294 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5297 ddraw_surface4_QueryInterface
,
5298 ddraw_surface4_AddRef
,
5299 ddraw_surface4_Release
,
5300 /* IDirectDrawSurface */
5301 ddraw_surface4_AddAttachedSurface
,
5302 ddraw_surface4_AddOverlayDirtyRect
,
5304 ddraw_surface4_BltBatch
,
5305 ddraw_surface4_BltFast
,
5306 ddraw_surface4_DeleteAttachedSurface
,
5307 ddraw_surface4_EnumAttachedSurfaces
,
5308 ddraw_surface4_EnumOverlayZOrders
,
5309 ddraw_surface4_Flip
,
5310 ddraw_surface4_GetAttachedSurface
,
5311 ddraw_surface4_GetBltStatus
,
5312 ddraw_surface4_GetCaps
,
5313 ddraw_surface4_GetClipper
,
5314 ddraw_surface4_GetColorKey
,
5315 ddraw_surface4_GetDC
,
5316 ddraw_surface4_GetFlipStatus
,
5317 ddraw_surface4_GetOverlayPosition
,
5318 ddraw_surface4_GetPalette
,
5319 ddraw_surface4_GetPixelFormat
,
5320 ddraw_surface4_GetSurfaceDesc
,
5321 ddraw_surface4_Initialize
,
5322 ddraw_surface4_IsLost
,
5323 ddraw_surface4_Lock
,
5324 ddraw_surface4_ReleaseDC
,
5325 ddraw_surface4_Restore
,
5326 ddraw_surface4_SetClipper
,
5327 ddraw_surface4_SetColorKey
,
5328 ddraw_surface4_SetOverlayPosition
,
5329 ddraw_surface4_SetPalette
,
5330 ddraw_surface4_Unlock
,
5331 ddraw_surface4_UpdateOverlay
,
5332 ddraw_surface4_UpdateOverlayDisplay
,
5333 ddraw_surface4_UpdateOverlayZOrder
,
5334 /* IDirectDrawSurface2 */
5335 ddraw_surface4_GetDDInterface
,
5336 ddraw_surface4_PageLock
,
5337 ddraw_surface4_PageUnlock
,
5338 /* IDirectDrawSurface3 */
5339 ddraw_surface4_SetSurfaceDesc
,
5340 /* IDirectDrawSurface4 */
5341 ddraw_surface4_SetPrivateData
,
5342 ddraw_surface4_GetPrivateData
,
5343 ddraw_surface4_FreePrivateData
,
5344 ddraw_surface4_GetUniquenessValue
,
5345 ddraw_surface4_ChangeUniquenessValue
,
5348 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5351 ddraw_surface3_QueryInterface
,
5352 ddraw_surface3_AddRef
,
5353 ddraw_surface3_Release
,
5354 /* IDirectDrawSurface */
5355 ddraw_surface3_AddAttachedSurface
,
5356 ddraw_surface3_AddOverlayDirtyRect
,
5358 ddraw_surface3_BltBatch
,
5359 ddraw_surface3_BltFast
,
5360 ddraw_surface3_DeleteAttachedSurface
,
5361 ddraw_surface3_EnumAttachedSurfaces
,
5362 ddraw_surface3_EnumOverlayZOrders
,
5363 ddraw_surface3_Flip
,
5364 ddraw_surface3_GetAttachedSurface
,
5365 ddraw_surface3_GetBltStatus
,
5366 ddraw_surface3_GetCaps
,
5367 ddraw_surface3_GetClipper
,
5368 ddraw_surface3_GetColorKey
,
5369 ddraw_surface3_GetDC
,
5370 ddraw_surface3_GetFlipStatus
,
5371 ddraw_surface3_GetOverlayPosition
,
5372 ddraw_surface3_GetPalette
,
5373 ddraw_surface3_GetPixelFormat
,
5374 ddraw_surface3_GetSurfaceDesc
,
5375 ddraw_surface3_Initialize
,
5376 ddraw_surface3_IsLost
,
5377 ddraw_surface3_Lock
,
5378 ddraw_surface3_ReleaseDC
,
5379 ddraw_surface3_Restore
,
5380 ddraw_surface3_SetClipper
,
5381 ddraw_surface3_SetColorKey
,
5382 ddraw_surface3_SetOverlayPosition
,
5383 ddraw_surface3_SetPalette
,
5384 ddraw_surface3_Unlock
,
5385 ddraw_surface3_UpdateOverlay
,
5386 ddraw_surface3_UpdateOverlayDisplay
,
5387 ddraw_surface3_UpdateOverlayZOrder
,
5388 /* IDirectDrawSurface2 */
5389 ddraw_surface3_GetDDInterface
,
5390 ddraw_surface3_PageLock
,
5391 ddraw_surface3_PageUnlock
,
5392 /* IDirectDrawSurface3 */
5393 ddraw_surface3_SetSurfaceDesc
,
5396 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5399 ddraw_surface2_QueryInterface
,
5400 ddraw_surface2_AddRef
,
5401 ddraw_surface2_Release
,
5402 /* IDirectDrawSurface */
5403 ddraw_surface2_AddAttachedSurface
,
5404 ddraw_surface2_AddOverlayDirtyRect
,
5406 ddraw_surface2_BltBatch
,
5407 ddraw_surface2_BltFast
,
5408 ddraw_surface2_DeleteAttachedSurface
,
5409 ddraw_surface2_EnumAttachedSurfaces
,
5410 ddraw_surface2_EnumOverlayZOrders
,
5411 ddraw_surface2_Flip
,
5412 ddraw_surface2_GetAttachedSurface
,
5413 ddraw_surface2_GetBltStatus
,
5414 ddraw_surface2_GetCaps
,
5415 ddraw_surface2_GetClipper
,
5416 ddraw_surface2_GetColorKey
,
5417 ddraw_surface2_GetDC
,
5418 ddraw_surface2_GetFlipStatus
,
5419 ddraw_surface2_GetOverlayPosition
,
5420 ddraw_surface2_GetPalette
,
5421 ddraw_surface2_GetPixelFormat
,
5422 ddraw_surface2_GetSurfaceDesc
,
5423 ddraw_surface2_Initialize
,
5424 ddraw_surface2_IsLost
,
5425 ddraw_surface2_Lock
,
5426 ddraw_surface2_ReleaseDC
,
5427 ddraw_surface2_Restore
,
5428 ddraw_surface2_SetClipper
,
5429 ddraw_surface2_SetColorKey
,
5430 ddraw_surface2_SetOverlayPosition
,
5431 ddraw_surface2_SetPalette
,
5432 ddraw_surface2_Unlock
,
5433 ddraw_surface2_UpdateOverlay
,
5434 ddraw_surface2_UpdateOverlayDisplay
,
5435 ddraw_surface2_UpdateOverlayZOrder
,
5436 /* IDirectDrawSurface2 */
5437 ddraw_surface2_GetDDInterface
,
5438 ddraw_surface2_PageLock
,
5439 ddraw_surface2_PageUnlock
,
5442 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5445 ddraw_surface1_QueryInterface
,
5446 ddraw_surface1_AddRef
,
5447 ddraw_surface1_Release
,
5448 /* IDirectDrawSurface */
5449 ddraw_surface1_AddAttachedSurface
,
5450 ddraw_surface1_AddOverlayDirtyRect
,
5452 ddraw_surface1_BltBatch
,
5453 ddraw_surface1_BltFast
,
5454 ddraw_surface1_DeleteAttachedSurface
,
5455 ddraw_surface1_EnumAttachedSurfaces
,
5456 ddraw_surface1_EnumOverlayZOrders
,
5457 ddraw_surface1_Flip
,
5458 ddraw_surface1_GetAttachedSurface
,
5459 ddraw_surface1_GetBltStatus
,
5460 ddraw_surface1_GetCaps
,
5461 ddraw_surface1_GetClipper
,
5462 ddraw_surface1_GetColorKey
,
5463 ddraw_surface1_GetDC
,
5464 ddraw_surface1_GetFlipStatus
,
5465 ddraw_surface1_GetOverlayPosition
,
5466 ddraw_surface1_GetPalette
,
5467 ddraw_surface1_GetPixelFormat
,
5468 ddraw_surface1_GetSurfaceDesc
,
5469 ddraw_surface1_Initialize
,
5470 ddraw_surface1_IsLost
,
5471 ddraw_surface1_Lock
,
5472 ddraw_surface1_ReleaseDC
,
5473 ddraw_surface1_Restore
,
5474 ddraw_surface1_SetClipper
,
5475 ddraw_surface1_SetColorKey
,
5476 ddraw_surface1_SetOverlayPosition
,
5477 ddraw_surface1_SetPalette
,
5478 ddraw_surface1_Unlock
,
5479 ddraw_surface1_UpdateOverlay
,
5480 ddraw_surface1_UpdateOverlayDisplay
,
5481 ddraw_surface1_UpdateOverlayZOrder
,
5484 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5486 ddraw_gamma_control_QueryInterface
,
5487 ddraw_gamma_control_AddRef
,
5488 ddraw_gamma_control_Release
,
5489 ddraw_gamma_control_GetGammaRamp
,
5490 ddraw_gamma_control_SetGammaRamp
,
5493 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5495 d3d_texture2_QueryInterface
,
5496 d3d_texture2_AddRef
,
5497 d3d_texture2_Release
,
5498 d3d_texture2_GetHandle
,
5499 d3d_texture2_PaletteChanged
,
5503 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5505 d3d_texture1_QueryInterface
,
5506 d3d_texture1_AddRef
,
5507 d3d_texture1_Release
,
5508 d3d_texture1_Initialize
,
5509 d3d_texture1_GetHandle
,
5510 d3d_texture1_PaletteChanged
,
5512 d3d_texture1_Unload
,
5515 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5516 * IDirectDrawSurface interface to ddraw methods. */
5517 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5519 if (!iface
) return NULL
;
5520 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5522 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5525 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5528 IDirectDrawSurface7_Release(iface
);
5530 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5533 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5535 if (!iface
) return NULL
;
5536 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5538 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5541 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5544 IDirectDrawSurface4_Release(iface
);
5546 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5549 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5551 if (!iface
) return NULL
;
5552 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5554 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5557 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5560 IDirectDrawSurface3_Release(iface
);
5562 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5565 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5567 if (!iface
) return NULL
;
5568 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5570 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5573 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5576 IDirectDrawSurface2_Release(iface
);
5578 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5581 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5583 if (!iface
) return NULL
;
5584 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5586 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5589 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5592 IDirectDrawSurface_Release(iface
);
5594 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5597 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5599 if (!iface
) return NULL
;
5600 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5601 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5604 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5606 if (!iface
) return NULL
;
5607 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5608 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5611 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5613 struct ddraw_surface
*surface
= parent
;
5615 TRACE("surface %p.\n", surface
);
5617 /* Check for attached surfaces and detach them. */
5618 if (surface
->first_attached
!= surface
)
5620 /* Well, this shouldn't happen: The surface being attached is
5621 * referenced in AddAttachedSurface(), so it shouldn't be released
5622 * until DeleteAttachedSurface() is called, because the refcount is
5623 * held. It looks like the application released it often enough to
5625 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5627 /* The refcount will drop to -1 here */
5628 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5629 ERR("DeleteAttachedSurface failed.\n");
5632 while (surface
->next_attached
)
5633 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5634 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5635 ERR("DeleteAttachedSurface failed.\n");
5637 /* Having a texture handle set implies that the device still exists. */
5638 if (surface
->Handle
)
5639 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5641 /* Reduce the ddraw surface count. */
5642 list_remove(&surface
->surface_list_entry
);
5644 if (surface
->clipper
)
5645 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5647 if (surface
== surface
->ddraw
->primary
)
5648 surface
->ddraw
->primary
= NULL
;
5650 wined3d_private_store_cleanup(&surface
->private_store
);
5652 HeapFree(GetProcessHeap(), 0, surface
);
5655 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5657 ddraw_surface_wined3d_object_destroyed
,
5660 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5662 TRACE("parent %p.\n", parent
);
5664 HeapFree(GetProcessHeap(), 0, parent
);
5667 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5669 ddraw_texture_wined3d_object_destroyed
,
5672 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5677 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5678 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5680 struct wined3d_resource_desc wined3d_desc
, wined3d_mip_desc
;
5681 struct ddraw_surface
*root
, *mip
, **attach
;
5682 struct wined3d_texture
*wined3d_texture
;
5683 struct wined3d_resource
*resource
;
5684 struct wined3d_display_mode mode
;
5685 DDSURFACEDESC2
*desc
, *mip_desc
;
5686 struct ddraw_texture
*texture
;
5687 unsigned int layers
= 1;
5688 unsigned int pitch
= 0;
5692 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5693 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5694 if (TRACE_ON(ddraw
))
5696 TRACE("Requesting surface desc:\n");
5697 DDRAW_dump_surface_desc(surface_desc
);
5701 return CLASS_E_NOAGGREGATION
;
5706 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5707 return E_OUTOFMEMORY
;
5709 texture
->version
= version
;
5710 texture
->surface_desc
= *surface_desc
;
5711 desc
= &texture
->surface_desc
;
5713 /* Ensure DDSD_CAPS is always set. */
5714 desc
->dwFlags
|= DDSD_CAPS
;
5716 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5718 DWORD flippable
= desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
);
5720 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5722 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5723 HeapFree(GetProcessHeap(), 0, texture
);
5724 return DDERR_INVALIDCAPS
;
5729 if (flippable
!= (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
))
5731 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5732 HeapFree(GetProcessHeap(), 0, texture
);
5733 return DDERR_INVALIDCAPS
;
5736 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5738 WARN("Tried to create a flippable primary surface without any back buffers.\n");
5739 HeapFree(GetProcessHeap(), 0, texture
);
5740 return DDERR_INVALIDCAPS
;
5743 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5745 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5746 HeapFree(GetProcessHeap(), 0, texture
);
5747 return DDERR_NOEXCLUSIVEMODE
;
5752 /* This is a special case in ddrawex, but not allowed in ddraw. */
5753 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5754 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5756 WARN("Tried to create a surface in both system and video memory.\n");
5757 HeapFree(GetProcessHeap(), 0, texture
);
5758 return DDERR_INVALIDCAPS
;
5761 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
5762 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5764 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
5765 HeapFree(GetProcessHeap(), 0, texture
);
5766 return DDERR_INVALIDCAPS
;
5769 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5770 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5772 WARN("Cube map faces requested without cube map flag.\n");
5773 HeapFree(GetProcessHeap(), 0, texture
);
5774 return DDERR_INVALIDCAPS
;
5777 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5778 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5780 WARN("Cube map without faces requested.\n");
5781 HeapFree(GetProcessHeap(), 0, texture
);
5782 return DDERR_INVALIDPARAMS
;
5785 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5786 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5787 FIXME("Partial cube maps not implemented.\n");
5789 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5791 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5793 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5794 HeapFree(GetProcessHeap(), 0, texture
);
5795 return DDERR_INVALIDCAPS
;
5797 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5799 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5800 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5801 HeapFree(GetProcessHeap(), 0, texture
);
5802 return DDERR_INVALIDCAPS
;
5806 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5808 ERR("Failed to get display mode, hr %#x.\n", hr
);
5809 HeapFree(GetProcessHeap(), 0, texture
);
5810 return hr_ddraw_from_wined3d(hr
);
5813 /* No pixelformat given? Use the current screen format. */
5814 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5816 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5817 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5818 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5821 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
5822 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5823 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5825 WARN("Unsupported / unknown pixelformat.\n");
5826 HeapFree(GetProcessHeap(), 0, texture
);
5827 return DDERR_INVALIDPIXELFORMAT
;
5830 /* No width or no height? Use the screen size. */
5831 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5833 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5835 WARN("No width / height specified.\n");
5836 HeapFree(GetProcessHeap(), 0, texture
);
5837 return DDERR_INVALIDPARAMS
;
5840 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5841 desc
->dwWidth
= mode
.width
;
5842 desc
->dwHeight
= mode
.height
;
5845 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5847 HeapFree(GetProcessHeap(), 0, texture
);
5848 return DDERR_INVALIDPARAMS
;
5851 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5853 /* The first surface is a front buffer, the back buffers are created
5855 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5856 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5857 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5858 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5860 struct wined3d_swapchain_desc swapchain_desc
;
5862 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5863 swapchain_desc
.backbuffer_width
= mode
.width
;
5864 swapchain_desc
.backbuffer_height
= mode
.height
;
5865 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5867 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5868 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5870 ERR("Failed to reset device.\n");
5871 HeapFree(GetProcessHeap(), 0, texture
);
5872 return hr_ddraw_from_wined3d(hr
);
5877 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5878 wined3d_desc
.multisample_quality
= 0;
5879 wined3d_desc
.usage
= 0;
5880 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5881 wined3d_desc
.width
= desc
->dwWidth
;
5882 wined3d_desc
.height
= desc
->dwHeight
;
5883 wined3d_desc
.depth
= 1;
5884 wined3d_desc
.size
= 0;
5886 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5888 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5889 /* Do not fail surface creation, only fail 3D device creation. */
5892 /* Mipmap count fixes */
5893 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5895 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5897 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5899 /* Mipmap count is given, should not be 0. */
5900 if (!desc
->u2
.dwMipMapCount
)
5902 HeapFree(GetProcessHeap(), 0, texture
);
5903 return DDERR_INVALIDPARAMS
;
5908 /* Undocumented feature: Create sublevels until either the
5909 * width or the height is 1. */
5911 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5913 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5918 desc
->u2
.dwMipMapCount
= 1;
5921 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5922 levels
= desc
->u2
.dwMipMapCount
;
5929 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5931 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5933 enum wined3d_resource_type rtype
;
5936 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5938 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
5939 rtype
= WINED3D_RTYPE_TEXTURE_2D
;
5941 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5942 rtype
= WINED3D_RTYPE_TEXTURE_2D
;
5944 rtype
= WINED3D_RTYPE_SURFACE
;
5946 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5947 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5948 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5949 usage
= WINED3DUSAGE_RENDERTARGET
;
5951 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5952 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, rtype
, wined3d_desc
.format
)))
5953 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5955 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5957 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5959 /* Tests show surfaces without memory flags get these flags added
5960 * right after creation. */
5961 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5965 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5966 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5968 WARN("System memory overlays are not allowed.\n");
5969 HeapFree(GetProcessHeap(), 0, texture
);
5970 return DDERR_NOOVERLAYHW
;
5973 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5975 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
5979 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5980 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
5981 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5982 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5983 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5984 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
5986 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5988 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
5989 /* Managed textures have the system memory flag set. */
5990 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5992 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5994 /* Videomemory adds localvidmem. This is mutually exclusive with
5995 * systemmemory and texturemanage. */
5996 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5997 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
6001 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6003 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
6005 WARN("User memory surfaces should be in the system memory pool.\n");
6006 HeapFree(GetProcessHeap(), 0, texture
);
6007 return DDERR_INVALIDCAPS
;
6012 WARN("User memory surfaces not supported before version 4.\n");
6013 HeapFree(GetProcessHeap(), 0, texture
);
6014 return DDERR_INVALIDPARAMS
;
6017 if (!desc
->lpSurface
)
6019 WARN("NULL surface memory pointer specified.\n");
6020 HeapFree(GetProcessHeap(), 0, texture
);
6021 return DDERR_INVALIDPARAMS
;
6024 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6026 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6028 WARN("Pitch specified on a compressed user memory surface.\n");
6029 HeapFree(GetProcessHeap(), 0, texture
);
6030 return DDERR_INVALIDPARAMS
;
6033 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6035 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6036 HeapFree(GetProcessHeap(), 0, texture
);
6037 return DDERR_INVALIDPARAMS
;
6040 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6041 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6042 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6044 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6045 HeapFree(GetProcessHeap(), 0, texture
);
6046 return DDERR_INVALIDPARAMS
;
6051 if (!(desc
->dwFlags
& DDSD_PITCH
))
6053 WARN("User memory surfaces should explicitly specify the pitch.\n");
6054 HeapFree(GetProcessHeap(), 0, texture
);
6055 return DDERR_INVALIDPARAMS
;
6058 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6059 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6061 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6062 HeapFree(GetProcessHeap(), 0, texture
);
6063 return DDERR_INVALIDPARAMS
;
6066 pitch
= desc
->u1
.lPitch
;
6070 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6071 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6072 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6073 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6074 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6075 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6076 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6077 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6079 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6080 HeapFree(GetProcessHeap(), 0, texture
);
6081 return DDERR_NOCOLORKEYHW
;
6084 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6085 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6087 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6088 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6090 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6092 wined3d_desc
.usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6096 /* Some applications assume surfaces will always be mapped at the same
6097 * address. Some of those also assume that this address is valid even when
6098 * the surface isn't mapped, and that updates done this way will be
6099 * visible on the screen. The game Nox is such an application,
6100 * Commandos: Behind Enemy Lines is another. We set
6101 * WINED3D_TEXTURE_CREATE_PIN_SYSMEM because of this. */
6102 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
6103 WINED3D_TEXTURE_CREATE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6105 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6106 HeapFree(GetProcessHeap(), 0, texture
);
6107 return hr_ddraw_from_wined3d(hr
);
6110 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6111 root
= wined3d_resource_get_parent(resource
);
6112 wined3d_texture_decref(wined3d_texture
);
6113 root
->is_complex_root
= TRUE
;
6114 texture
->root
= root
;
6116 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6117 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6118 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6119 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6120 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6121 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6122 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6123 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6124 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6125 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6126 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6127 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6129 for (i
= 0; i
< layers
; ++i
)
6131 attach
= &root
->complex_array
[layers
- 1 - i
];
6133 for (j
= 0; j
< levels
; ++j
)
6135 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
6136 mip
= wined3d_resource_get_parent(resource
);
6137 mip_desc
= &mip
->surface_desc
;
6141 wined3d_resource_get_desc(resource
, &wined3d_mip_desc
);
6142 mip_desc
->dwWidth
= wined3d_mip_desc
.width
;
6143 mip_desc
->dwHeight
= wined3d_mip_desc
.height
;
6145 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6149 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6152 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6154 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6158 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6159 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6161 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6162 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6164 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6165 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6167 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6168 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6170 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6171 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6173 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6174 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6184 attach
= &mip
->complex_array
[0];
6188 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6189 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6190 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6192 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6196 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6198 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6199 struct ddraw_surface
*last
= root
;
6201 attach
= &last
->complex_array
[0];
6202 for (i
= 0; i
< count
; ++i
)
6204 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6210 texture
->version
= version
;
6211 texture
->surface_desc
= root
->surface_desc
;
6212 desc
= &texture
->surface_desc
;
6214 /* Only one surface in the flipping chain is a back buffer, one is
6215 * a front buffer, the others are just flippable surfaces. */
6216 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6217 | DDSCAPS_BACKBUFFER
);
6219 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6220 desc
->u5
.dwBackBufferCount
= 0;
6222 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1,
6223 WINED3D_TEXTURE_CREATE_PIN_SYSMEM
, NULL
, texture
,
6224 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6226 HeapFree(GetProcessHeap(), 0, texture
);
6227 hr
= hr_ddraw_from_wined3d(hr
);
6231 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6232 last
= wined3d_resource_get_parent(resource
);
6233 wined3d_texture_decref(wined3d_texture
);
6234 texture
->root
= last
;
6236 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6237 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6238 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6239 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6240 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6241 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6242 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6243 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6244 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6245 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6246 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6247 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6250 attach
= &last
->complex_array
[0];
6255 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6256 ddraw
->primary
= root
;
6263 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6264 else if (version
== 4)
6265 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6267 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6272 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
6273 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
6274 const struct wined3d_parent_ops
**parent_ops
)
6276 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
6277 unsigned int texture_level
, row_pitch
, slice_pitch
;
6278 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6279 unsigned int version
= texture
->version
;
6281 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6282 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6283 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6284 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6285 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6286 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6287 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6288 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6289 surface
->iface_count
= 1;
6290 surface
->version
= version
;
6291 surface
->ddraw
= ddraw
;
6296 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6298 else if (version
== 4)
6301 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6306 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6309 *desc
= texture
->surface_desc
;
6310 surface
->first_attached
= surface
;
6312 texture_level
= desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
? sub_resource_idx
% desc
->u2
.dwMipMapCount
: 0;
6313 wined3d_texture_get_pitch(wined3d_texture
, texture_level
, &row_pitch
, &slice_pitch
);
6314 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6316 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6317 desc
->u1
.dwLinearSize
= ~0u;
6319 desc
->u1
.dwLinearSize
= slice_pitch
;
6320 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6321 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6325 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6326 desc
->u1
.lPitch
= row_pitch
;
6327 desc
->dwFlags
|= DDSD_PITCH
;
6328 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6330 desc
->lpSurface
= NULL
;
6332 wined3d_texture_incref(surface
->wined3d_texture
= wined3d_texture
);
6333 surface
->sub_resource_idx
= sub_resource_idx
;
6334 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6336 wined3d_private_store_init(&surface
->private_store
);
6339 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6341 struct ddraw_surface
*surface
= parent
;
6343 /* If the surface reference count drops to zero, we release our reference
6344 * to the view, but don't clear the pointer yet, in case e.g. a
6345 * GetRenderTarget() call brings the surface back before the view is
6346 * actually destroyed. When the view is destroyed, we need to clear the
6347 * pointer, or a subsequent surface AddRef() would reference it again.
6349 * This is safe because as long as the view still has a reference to the
6350 * texture, the surface is also still alive, and we're called before the
6351 * view releases that reference. */
6352 surface
->wined3d_rtv
= NULL
;
6355 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6357 view_wined3d_object_destroyed
,
6360 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6364 if (surface
->wined3d_rtv
)
6365 return surface
->wined3d_rtv
;
6367 if (FAILED(hr
= wined3d_rendertarget_view_create_from_sub_resource(surface
->wined3d_texture
,
6368 surface
->sub_resource_idx
, surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6370 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6374 return surface
->wined3d_rtv
;