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
->wined3d_palette
, 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
->wined3d_palette
: 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 static ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
536 /* Prevent the surface from being destroyed if it's still attached to
537 * another surface. It will be destroyed when the root is destroyed. */
538 if (This
->iface_count
== 1 && This
->attached_iface
)
539 IUnknown_AddRef(This
->attached_iface
);
540 iface_count
= InterlockedDecrement(&This
->iface_count
);
542 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
544 if (iface_count
== 0)
546 struct ddraw_texture
*texture
= wined3d_texture_get_parent(This
->wined3d_texture
);
547 struct wined3d_device
*wined3d_device
= texture
->wined3d_device
;
548 IUnknown
*release_iface
= This
->ifaceToRelease
;
550 /* Complex attached surfaces are destroyed implicitly when the root is released */
551 wined3d_mutex_lock();
552 if(!This
->is_complex_root
)
554 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
555 wined3d_mutex_unlock();
558 ddraw_surface_cleanup(This
);
559 wined3d_mutex_unlock();
562 IUnknown_Release(release_iface
);
563 /* Release the device only after anything that may reference it (the
564 * wined3d texture and rendertarget view in particular) is released. */
565 wined3d_device_decref(wined3d_device
);
571 /*****************************************************************************
572 * IDirectDrawSurface7::Release
574 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
575 * surface is destroyed.
577 * Destroying the surface is a bit tricky. For the connection between
578 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
579 * It has a nice graph explaining the connection.
581 * What happens here is basically this:
582 * When a surface is destroyed, its WineD3DSurface is released,
583 * and the refcount of the DirectDraw interface is reduced by 1. If it has
584 * complex surfaces attached to it, then these surfaces are destroyed too,
585 * regardless of their refcount. If any surface being destroyed has another
586 * surface attached to it (with a "soft" attachment, not complex), then
587 * this surface is detached with DeleteAttachedSurface.
589 * When the surface is a texture, the WineD3DTexture is released.
590 * If the surface is the Direct3D render target, then the D3D
591 * capabilities of the WineD3DDevice are uninitialized, which causes the
592 * swapchain to be released.
594 * When a complex sublevel falls to ref zero, then this is ignored.
599 *****************************************************************************/
600 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
602 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
603 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
605 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
609 ddraw_surface_release_iface(This
);
615 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
617 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
618 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
620 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
624 ddraw_surface_release_iface(This
);
630 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
632 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
633 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
635 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
639 ddraw_surface_release_iface(This
);
645 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
647 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
648 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
650 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
654 ddraw_surface_release_iface(This
);
660 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
662 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
663 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
665 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
669 ddraw_surface_release_iface(This
);
675 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
677 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
678 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
680 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
684 ddraw_surface_release_iface(This
);
690 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
692 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
694 TRACE("iface %p.\n", iface
);
696 return IUnknown_Release(surface
->texture_outer
);
699 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
701 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
703 TRACE("iface %p.\n", iface
);
705 return IUnknown_Release(surface
->texture_outer
);
708 /*****************************************************************************
709 * IDirectDrawSurface7::GetAttachedSurface
711 * Returns an attached surface with the requested caps. Surface attachment
712 * and complex surfaces are not clearly described by the MSDN or sdk,
713 * so this method is tricky and likely to contain problems.
714 * This implementation searches the complex list first, then the
717 * The chains are searched from This down to the last surface in the chain,
718 * not from the first element in the chain. The first surface found is
719 * returned. The MSDN says that this method fails if more than one surface
720 * matches the caps, but it is not sure if that is right. The attachment
721 * structure may not even allow two matching surfaces.
723 * The found surface is AddRef-ed before it is returned.
726 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
727 * Surface: Address to store the found surface
731 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
732 * DDERR_NOTFOUND if no surface was found
734 *****************************************************************************/
735 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
736 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
738 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
739 struct ddraw_surface
*surf
;
743 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
745 wined3d_mutex_lock();
747 if(This
->version
< 7)
749 /* Earlier dx apps put garbage into these members, clear them */
750 our_caps
.dwCaps
= Caps
->dwCaps
;
751 our_caps
.dwCaps2
= 0;
752 our_caps
.dwCaps3
= 0;
753 our_caps
.u1
.dwCaps4
= 0;
760 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 */
762 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
764 surf
= This
->complex_array
[i
];
767 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
768 surf
->surface_desc
.ddsCaps
.dwCaps
,
769 surf
->surface_desc
.ddsCaps
.dwCaps2
,
770 surf
->surface_desc
.ddsCaps
.dwCaps3
,
771 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
773 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
774 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
776 /* MSDN: "This method fails if more than one surface is attached
777 * that matches the capabilities requested."
779 * Not sure how to test this.
782 TRACE("(%p): Returning surface %p\n", This
, surf
);
783 *Surface
= &surf
->IDirectDrawSurface7_iface
;
784 ddraw_surface7_AddRef(*Surface
);
785 wined3d_mutex_unlock();
791 /* Next, look at the attachment chain */
794 while( (surf
= surf
->next_attached
) )
796 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
797 surf
->surface_desc
.ddsCaps
.dwCaps
,
798 surf
->surface_desc
.ddsCaps
.dwCaps2
,
799 surf
->surface_desc
.ddsCaps
.dwCaps3
,
800 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
802 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
803 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
805 TRACE("(%p): Returning surface %p\n", This
, surf
);
806 *Surface
= &surf
->IDirectDrawSurface7_iface
;
807 ddraw_surface7_AddRef(*Surface
);
808 wined3d_mutex_unlock();
813 TRACE("(%p) Didn't find a valid surface\n", This
);
815 wined3d_mutex_unlock();
818 return DDERR_NOTFOUND
;
821 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
822 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
824 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
825 struct ddraw_surface
*attachment_impl
;
826 IDirectDrawSurface7
*attachment7
;
829 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
831 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
838 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
839 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
840 ddraw_surface4_AddRef(*attachment
);
841 ddraw_surface7_Release(attachment7
);
846 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
847 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
849 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
850 struct ddraw_surface
*attachment_impl
;
851 IDirectDrawSurface7
*attachment7
;
855 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
857 caps2
.dwCaps
= caps
->dwCaps
;
860 caps2
.u1
.dwCaps4
= 0;
862 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
863 &caps2
, &attachment7
);
869 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
870 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
871 ddraw_surface3_AddRef(*attachment
);
872 ddraw_surface7_Release(attachment7
);
877 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
878 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
880 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
881 struct ddraw_surface
*attachment_impl
;
882 IDirectDrawSurface7
*attachment7
;
886 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
888 caps2
.dwCaps
= caps
->dwCaps
;
891 caps2
.u1
.dwCaps4
= 0;
893 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
894 &caps2
, &attachment7
);
900 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
901 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
902 ddraw_surface2_AddRef(*attachment
);
903 ddraw_surface7_Release(attachment7
);
908 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
909 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
911 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
912 struct ddraw_surface
*attachment_impl
;
913 IDirectDrawSurface7
*attachment7
;
917 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
919 caps2
.dwCaps
= caps
->dwCaps
;
922 caps2
.u1
.dwCaps4
= 0;
924 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
925 &caps2
, &attachment7
);
931 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
932 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
933 ddraw_surface1_AddRef(*attachment
);
934 ddraw_surface7_Release(attachment7
);
939 /*****************************************************************************
940 * IDirectDrawSurface7::Lock
942 * Locks the surface and returns a pointer to the surface's memory
945 * Rect: Rectangle to lock. If NULL, the whole surface is locked
946 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
947 * Flags: Locking flags, e.g Read only or write only
948 * h: An event handle that's not used and must be NULL
952 * DDERR_INVALIDPARAMS if DDSD is NULL
954 *****************************************************************************/
955 static HRESULT
surface_lock(struct ddraw_surface
*surface
,
956 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, unsigned int surface_desc_size
,
957 DWORD flags
, HANDLE h
)
959 struct wined3d_map_desc map_desc
;
960 struct wined3d_box box
;
963 TRACE("surface %p, rect %s, surface_desc %p, surface_desc_size %u, flags %#x, h %p.\n",
964 surface
, wine_dbgstr_rect(rect
), surface_desc
, surface_desc_size
, flags
, h
);
966 /* surface->surface_desc.dwWidth and dwHeight are changeable, thus lock */
967 wined3d_mutex_lock();
969 /* Should I check for the handle to be NULL?
971 * The DDLOCK flags and the D3DLOCK flags are equal
972 * for the supported values. The others are ignored by WineD3D
975 /* Windows zeroes this if the rect is invalid */
976 surface_desc
->lpSurface
= NULL
;
980 if ((rect
->left
< 0) || (rect
->top
< 0)
981 || (rect
->left
> rect
->right
) || (rect
->right
> surface
->surface_desc
.dwWidth
)
982 || (rect
->top
> rect
->bottom
) || (rect
->bottom
> surface
->surface_desc
.dwHeight
))
984 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
985 wined3d_mutex_unlock();
986 return DDERR_INVALIDPARAMS
;
988 wined3d_box_set(&box
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, 0, 1);
991 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
992 hr
= ddraw_surface_update_frontbuffer(surface
, rect
, TRUE
);
994 hr
= wined3d_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
),
995 surface
->sub_resource_idx
, &map_desc
, rect
? &box
: NULL
, flags
);
998 wined3d_mutex_unlock();
1001 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
1002 * specific error. But since wined3d returns that error in this only occasion,
1003 * keep d3d8 and d3d9 free from the return value override. There are many different
1004 * places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it is much easier
1005 * to do it in one place in ddraw.
1007 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1012 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1014 if (flags
& DDLOCK_READONLY
)
1015 SetRectEmpty(&surface
->ddraw
->primary_lock
);
1017 surface
->ddraw
->primary_lock
= *rect
;
1019 SetRect(&surface
->ddraw
->primary_lock
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
1022 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1023 DD_STRUCT_COPY_BYSIZE_(surface_desc
, &surface
->surface_desc
, surface_desc_size
, surface
->surface_desc
.dwSize
);
1024 surface_desc
->lpSurface
= map_desc
.data
;
1026 TRACE("locked surface returning description :\n");
1027 if (TRACE_ON(ddraw
))
1028 DDRAW_dump_surface_desc(surface_desc
);
1030 wined3d_mutex_unlock();
1035 static BOOL
surface_validate_lock_desc(struct ddraw_surface
*surface
,
1036 const DDSURFACEDESC
*desc
, unsigned int *size
)
1041 if (desc
->dwSize
== sizeof(DDSURFACEDESC
) || desc
->dwSize
== sizeof(DDSURFACEDESC2
))
1043 *size
= desc
->dwSize
;
1047 if (surface
->version
== 7
1048 && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
1049 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1051 if (desc
->dwSize
>= sizeof(DDSURFACEDESC2
))
1052 *size
= sizeof(DDSURFACEDESC2
);
1054 *size
= sizeof(DDSURFACEDESC
);
1058 WARN("Invalid structure size %u.\n", desc
->dwSize
);
1062 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1063 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1065 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1066 unsigned int surface_desc_size
;
1068 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1069 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1071 if (!surface_validate_lock_desc(surface
, (DDSURFACEDESC
*)surface_desc
, &surface_desc_size
))
1072 return DDERR_INVALIDPARAMS
;
1074 return surface_lock(surface
, rect
, surface_desc
, surface_desc_size
, flags
, h
);
1077 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1078 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1080 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1081 unsigned int surface_desc_size
;
1083 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1084 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1086 if (!surface_validate_lock_desc(surface
, (DDSURFACEDESC
*)surface_desc
, &surface_desc_size
))
1087 return DDERR_INVALIDPARAMS
;
1089 return surface_lock(surface
, rect
, surface_desc
, surface_desc_size
, flags
, h
);
1092 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1093 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1095 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1096 unsigned int surface_desc_size
;
1097 DDSURFACEDESC2 surface_desc2
;
1100 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1101 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1103 if (!surface_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1104 return DDERR_INVALIDPARAMS
;
1106 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1107 surface_desc2
.dwFlags
= 0;
1108 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1109 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1110 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1114 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1115 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1117 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1118 unsigned int surface_desc_size
;
1119 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_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1126 return DDERR_INVALIDPARAMS
;
1128 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1129 surface_desc2
.dwFlags
= 0;
1130 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1131 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1132 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1136 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1137 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1139 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1140 unsigned int surface_desc_size
;
1141 DDSURFACEDESC2 surface_desc2
;
1144 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1145 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1147 if (!surface_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1148 return DDERR_INVALIDPARAMS
;
1150 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1151 surface_desc2
.dwFlags
= 0;
1152 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1153 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1154 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1158 /*****************************************************************************
1159 * IDirectDrawSurface7::Unlock
1161 * Unlocks an locked surface
1164 * Rect: Not used by this implementation
1167 * D3D_OK on success, error code otherwise.
1169 *****************************************************************************/
1170 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1172 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1175 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1177 wined3d_mutex_lock();
1178 hr
= wined3d_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), surface
->sub_resource_idx
);
1179 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1180 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1181 wined3d_mutex_unlock();
1186 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1188 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1190 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1192 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1195 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1197 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1199 TRACE("iface %p, data %p.\n", iface
, data
);
1201 /* data might not be the LPRECT of later versions, so drop it. */
1202 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1205 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1207 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1209 TRACE("iface %p, data %p.\n", iface
, data
);
1211 /* data might not be the LPRECT of later versions, so drop it. */
1212 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1215 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1217 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1219 TRACE("iface %p, data %p.\n", iface
, data
);
1221 /* data might not be the LPRECT of later versions, so drop it. */
1222 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1225 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1226 IDirectDrawSurface7
*src
, DWORD flags
)
1228 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1229 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1230 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1231 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1232 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1233 struct wined3d_texture
*texture
;
1234 IDirectDrawSurface7
*current
;
1237 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1239 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1240 return DDERR_NOTFLIPPABLE
;
1242 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1243 return DDERR_SURFACELOST
;
1245 wined3d_mutex_lock();
1247 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1248 && !(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1250 WARN("Not in exclusive mode.\n");
1251 wined3d_mutex_unlock();
1252 return DDERR_NOEXCLUSIVEMODE
;
1255 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1256 if (dst_impl
->sub_resource_idx
)
1257 ERR("Invalid sub-resource index %u on surface %p.\n", dst_impl
->sub_resource_idx
, dst_impl
);
1258 texture
= dst_impl
->wined3d_texture
;
1259 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1260 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1264 for (current
= iface
; current
!= src
;)
1266 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1268 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1269 wined3d_mutex_unlock();
1270 return DDERR_NOTFLIPPABLE
;
1272 ddraw_surface7_Release(current
);
1273 if (current
== iface
)
1275 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1276 wined3d_mutex_unlock();
1277 return DDERR_NOTFLIPPABLE
;
1281 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1282 if (rtv
== dst_impl
->wined3d_rtv
)
1283 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1284 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1285 dst_impl
->wined3d_rtv
= src_rtv
;
1286 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1287 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1288 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1289 if (src_impl
->sub_resource_idx
)
1290 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1291 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1292 ddraw_texture
= prev_ddraw_texture
;
1296 for (current
= iface
;;)
1298 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1300 ERR("Can't find a flip target\n");
1301 wined3d_mutex_unlock();
1302 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1304 ddraw_surface7_Release(current
);
1305 if (current
== iface
)
1307 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1311 src_impl
= impl_from_IDirectDrawSurface7(current
);
1312 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1313 if (rtv
== dst_impl
->wined3d_rtv
)
1314 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1315 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1316 dst_impl
->wined3d_rtv
= src_rtv
;
1317 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1318 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1319 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1320 ddraw_texture
= prev_ddraw_texture
;
1321 if (src_impl
->sub_resource_idx
)
1322 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1323 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1324 dst_impl
= src_impl
;
1328 /* We don't have to worry about potential texture bindings, since
1329 * flippable surfaces can never be textures. */
1330 if (rtv
== src_impl
->wined3d_rtv
)
1331 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1332 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1333 src_impl
->wined3d_rtv
= tmp_rtv
;
1334 wined3d_texture_set_sub_resource_parent(texture
, 0, src_impl
);
1335 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1336 src_impl
->wined3d_texture
= texture
;
1342 FIXME("Ignoring flags %#x.\n", flags
);
1344 WARN("Ignoring flags %#x.\n", flags
);
1347 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1348 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1352 wined3d_mutex_unlock();
1357 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1358 IDirectDrawSurface4
*src
, DWORD flags
)
1360 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1361 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
1363 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1365 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1366 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1369 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1370 IDirectDrawSurface3
*src
, DWORD flags
)
1372 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1373 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src
);
1375 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1377 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1378 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1381 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1382 IDirectDrawSurface2
*src
, DWORD flags
)
1384 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1385 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src
);
1387 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1389 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1390 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1393 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1394 IDirectDrawSurface
*src
, DWORD flags
)
1396 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1397 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
1399 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1401 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1402 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1405 static HRESULT
ddraw_surface_blt(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect
,
1406 struct ddraw_surface
*src_surface
, const RECT
*src_rect
, DWORD flags
, DWORD fill_colour
,
1407 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1409 struct wined3d_device
*wined3d_device
= dst_surface
->ddraw
->wined3d_device
;
1410 struct wined3d_color colour
;
1411 DWORD wined3d_flags
;
1413 if (flags
& DDBLT_COLORFILL
)
1415 if (!wined3d_colour_from_ddraw_colour(&dst_surface
->surface_desc
.u4
.ddpfPixelFormat
,
1416 dst_surface
->palette
, fill_colour
, &colour
))
1417 return DDERR_INVALIDPARAMS
;
1419 return wined3d_device_clear_rendertarget_view(wined3d_device
,
1420 ddraw_surface_get_rendertarget_view(dst_surface
),
1421 dst_rect
, WINED3DCLEAR_TARGET
, &colour
, 0.0f
, 0);
1424 if (flags
& DDBLT_DEPTHFILL
)
1426 if (!wined3d_colour_from_ddraw_colour(&dst_surface
->surface_desc
.u4
.ddpfPixelFormat
,
1427 dst_surface
->palette
, fill_colour
, &colour
))
1428 return DDERR_INVALIDPARAMS
;
1430 return wined3d_device_clear_rendertarget_view(wined3d_device
,
1431 ddraw_surface_get_rendertarget_view(dst_surface
),
1432 dst_rect
, WINED3DCLEAR_ZBUFFER
, NULL
, colour
.r
, 0);
1435 wined3d_flags
= flags
& ~DDBLT_ASYNC
;
1436 if (wined3d_flags
& ~WINED3D_BLT_MASK
)
1438 FIXME("Unhandled flags %#x.\n", flags
);
1442 if (!(flags
& DDBLT_ASYNC
))
1443 wined3d_flags
|= WINED3D_BLT_SYNCHRONOUS
;
1445 return wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
, dst_rect
,
1446 src_surface
->wined3d_texture
, src_surface
->sub_resource_idx
, src_rect
, wined3d_flags
, fx
, filter
);
1449 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1450 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
, DWORD fill_colour
,
1451 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1453 RECT src_rect
, dst_rect
;
1454 float scale_x
, scale_y
;
1455 const RECT
*clip_rect
;
1456 UINT clip_list_size
;
1462 SetRect(&dst_rect
, 0, 0, dst_surface
->surface_desc
.dwWidth
,
1463 dst_surface
->surface_desc
.dwHeight
);
1465 dst_rect
= *dst_rect_in
;
1467 if (IsRectEmpty(&dst_rect
))
1468 return DDERR_INVALIDRECT
;
1473 SetRect(&src_rect
, 0, 0, src_surface
->surface_desc
.dwWidth
,
1474 src_surface
->surface_desc
.dwHeight
);
1476 src_rect
= *src_rect_in
;
1478 if (IsRectEmpty(&src_rect
))
1479 return DDERR_INVALIDRECT
;
1483 SetRectEmpty(&src_rect
);
1486 if (!dst_surface
->clipper
)
1488 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1489 hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect
, TRUE
);
1491 hr
= ddraw_surface_blt(dst_surface
, &dst_rect
, src_surface
, &src_rect
, flags
, fill_colour
, fx
, filter
);
1492 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1493 hr
= ddraw_surface_update_frontbuffer(dst_surface
, &dst_rect
, FALSE
);
1498 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1499 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1501 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1502 &dst_rect
, NULL
, &clip_list_size
)))
1504 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1508 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1510 WARN("Failed to allocate clip list.\n");
1511 return E_OUTOFMEMORY
;
1514 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1515 &dst_rect
, clip_list
, &clip_list_size
)))
1517 WARN("Failed to get clip list, hr %#x.\n", hr
);
1518 HeapFree(GetProcessHeap(), 0, clip_list
);
1522 clip_rect
= (RECT
*)clip_list
->Buffer
;
1523 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1525 RECT src_rect_clipped
= src_rect
;
1529 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1530 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1531 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1532 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1534 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1536 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1541 if (FAILED(hr
= ddraw_surface_blt(dst_surface
, &clip_rect
[i
],
1542 src_surface
, &src_rect_clipped
, flags
, fill_colour
, fx
, filter
)))
1545 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1547 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1552 HeapFree(GetProcessHeap(), 0, clip_list
);
1556 /*****************************************************************************
1557 * IDirectDrawSurface7::Blt
1559 * Performs a blit on the surface
1562 * DestRect: Destination rectangle, can be NULL
1563 * SrcSurface: Source surface, can be NULL
1564 * SrcRect: Source rectangle, can be NULL
1566 * DDBltFx: Some extended blt parameters, connected to the flags
1569 * D3D_OK on success, error code otherwise.
1571 *****************************************************************************/
1572 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*dst_rect
,
1573 IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1575 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1576 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
1577 struct wined3d_blt_fx wined3d_fx
;
1578 DWORD unsupported_flags
;
1579 DWORD fill_colour
= 0;
1583 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1584 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1586 unsupported_flags
= DDBLT_ALPHADEST
1587 | DDBLT_ALPHADESTCONSTOVERRIDE
1588 | DDBLT_ALPHADESTNEG
1589 | DDBLT_ALPHADESTSURFACEOVERRIDE
1590 | DDBLT_ALPHAEDGEBLEND
1592 | DDBLT_ALPHASRCCONSTOVERRIDE
1594 | DDBLT_ALPHASRCSURFACEOVERRIDE
1596 | DDBLT_ZBUFFERDESTCONSTOVERRIDE
1597 | DDBLT_ZBUFFERDESTOVERRIDE
1598 | DDBLT_ZBUFFERSRCCONSTOVERRIDE
1599 | DDBLT_ZBUFFERSRCOVERRIDE
;
1600 if (flags
& unsupported_flags
)
1602 WARN("Ignoring unsupported flags %#x.\n", flags
& unsupported_flags
);
1603 flags
&= ~unsupported_flags
;
1606 if ((flags
& DDBLT_KEYSRCOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYSRC
))
1608 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1609 return DDERR_INVALIDPARAMS
;
1612 if ((flags
& DDBLT_KEYDESTOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYDEST
))
1614 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1615 return DDERR_INVALIDPARAMS
;
1618 if (flags
& DDBLT_DDROPS
)
1620 FIXME("DDBLT_DDROPS not implemented.\n");
1622 FIXME(" rop %#x, pattern %p.\n", fx
->dwDDROP
, fx
->u5
.lpDDSPattern
);
1623 return DDERR_NORASTEROPHW
;
1626 wined3d_mutex_lock();
1628 if (flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1630 if (flags
& DDBLT_ROP
)
1632 wined3d_mutex_unlock();
1633 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1634 return DDERR_INVALIDPARAMS
;
1638 wined3d_mutex_unlock();
1639 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1640 return DDERR_INVALIDPARAMS
;
1644 wined3d_mutex_unlock();
1645 WARN("Depth or colorfill used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1646 return DDERR_INVALIDPARAMS
;
1649 if ((flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1650 flags
&= ~DDBLT_DEPTHFILL
;
1652 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_COLORFILL
))
1654 wined3d_mutex_unlock();
1655 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1656 return DDERR_INVALIDPARAMS
;
1658 if (!(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_DEPTHFILL
))
1660 wined3d_mutex_unlock();
1661 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1662 return DDERR_INVALIDPARAMS
;
1666 if (flags
& DDBLT_ROP
)
1670 wined3d_mutex_unlock();
1671 WARN("DDBLT_ROP used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1672 return DDERR_INVALIDPARAMS
;
1675 if (src_impl
&& src_rect
1676 && ((ULONG
)src_rect
->left
>= src_rect
->right
|| src_rect
->right
> src_impl
->surface_desc
.dwWidth
1677 || (ULONG
)src_rect
->top
>= src_rect
->bottom
|| src_rect
->bottom
> src_impl
->surface_desc
.dwHeight
))
1679 WARN("Invalid source rectangle.\n");
1680 return DDERR_INVALIDRECT
;
1683 flags
&= ~DDBLT_ROP
;
1693 if (fx
->dwROP
== WHITENESS
)
1694 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1696 rop_fx
.u5
.dwFillColor
= 0;
1698 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1699 flags
|= DDBLT_DEPTHFILL
;
1701 flags
|= DDBLT_COLORFILL
;
1707 wined3d_mutex_unlock();
1708 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", fx
->dwROP
);
1709 return DDERR_NORASTEROPHW
;
1713 if (!(flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) && !src_impl
)
1715 WARN("No source surface.\n");
1716 return DDERR_INVALIDPARAMS
;
1719 if (flags
& DDBLT_KEYSRC
&& (!src_impl
|| !(src_impl
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1721 WARN("DDBLT_KEYSRC blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1722 wined3d_mutex_unlock();
1723 return DDERR_INVALIDPARAMS
;
1725 if (flags
& DDBLT_KEYDEST
&& !(dst_impl
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1727 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1728 wined3d_mutex_unlock();
1729 return DDERR_INVALIDPARAMS
;
1734 wined3d_fx
.fx
= fx
->dwDDFX
;
1735 fill_colour
= fx
->u5
.dwFillColor
;
1736 wined3d_fx
.dst_color_key
.color_space_low_value
= fx
->ddckDestColorkey
.dwColorSpaceLowValue
;
1737 wined3d_fx
.dst_color_key
.color_space_high_value
= fx
->ddckDestColorkey
.dwColorSpaceHighValue
;
1738 wined3d_fx
.src_color_key
.color_space_low_value
= fx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
1739 wined3d_fx
.src_color_key
.color_space_high_value
= fx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
1742 hr
= ddraw_surface_blt_clipped(dst_impl
, dst_rect
, src_impl
,
1743 src_rect
, flags
, fill_colour
, fx
? &wined3d_fx
: NULL
, WINED3D_TEXF_LINEAR
);
1745 wined3d_mutex_unlock();
1748 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1753 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1754 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1756 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1757 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1759 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1760 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1762 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1763 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1766 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1767 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1769 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1770 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1772 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1773 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1775 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1776 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1779 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1780 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1782 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1783 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1785 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1786 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1788 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1789 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1792 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1793 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1795 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1796 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1798 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1799 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1801 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1802 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1805 /*****************************************************************************
1806 * IDirectDrawSurface7::AddAttachedSurface
1808 * Attaches a surface to another surface. How the surface attachments work
1809 * is not totally understood yet, and this method is prone to problems.
1810 * The surface that is attached is AddRef-ed.
1812 * Tests with complex surfaces suggest that the surface attachments form a
1813 * tree, but no method to test this has been found yet.
1815 * The attachment list consists of a first surface (first_attached) and
1816 * for each surface a pointer to the next attached surface (next_attached).
1817 * For the first surface, and a surface that has no attachments
1818 * first_attached points to the surface itself. A surface that has
1819 * no successors in the chain has next_attached set to NULL.
1821 * Newly attached surfaces are attached right after the root surface.
1822 * If a surface is attached to a complex surface compound, it's attached to
1823 * the surface that the app requested, not the complex root. See
1824 * GetAttachedSurface for a description how surfaces are found.
1826 * This is how the current implementation works, and it was coded by looking
1827 * at the needs of the applications.
1829 * So far only Z-Buffer attachments are tested, and they are activated in
1830 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1831 * Back buffers should work in 2D mode, but they are not tested(They can be
1832 * attached in older iface versions). Rendering to the front buffer and
1833 * switching between that and double buffering is not yet implemented in
1834 * WineD3D, so for 3D it might have unexpected results.
1836 * ddraw_surface_attach_surface is the real thing,
1837 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1838 * performs additional checks. Version 7 of this interface is much more restrictive
1839 * than its predecessors.
1842 * Attach: Surface to attach to iface
1846 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1848 *****************************************************************************/
1849 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1851 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1854 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1856 wined3d_mutex_lock();
1858 /* Check if the surface is already attached somewhere */
1859 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1861 /* TODO: Test for the structure of the manual attachment. Is it a
1862 * chain or a list? What happens if one surface is attached to 2
1863 * different surfaces? */
1864 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1865 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1867 wined3d_mutex_unlock();
1868 return DDERR_SURFACEALREADYATTACHED
;
1871 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1872 Surf
->next_attached
= This
->next_attached
;
1873 Surf
->first_attached
= This
->first_attached
;
1874 This
->next_attached
= Surf
;
1876 /* Check if the WineD3D depth stencil needs updating */
1877 if (This
->ddraw
->d3ddevice
)
1878 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1880 wined3d_mutex_unlock();
1885 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1887 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1888 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1891 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1893 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1894 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1897 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1898 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1899 return DDERR_CANNOTATTACHSURFACE
;
1902 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1907 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1908 IUnknown_AddRef(attachment_impl
->attached_iface
);
1912 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1914 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1915 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1918 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1920 /* Tests suggest that
1921 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1922 * -> offscreen plain surfaces can be attached to primaries
1923 * -> primaries can be attached to offscreen plain surfaces
1924 * -> z buffers can be attached to primaries */
1925 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1926 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1928 /* Sizes have to match */
1929 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1930 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1932 WARN("Surface sizes do not match.\n");
1933 return DDERR_CANNOTATTACHSURFACE
;
1936 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1937 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1939 WARN("Invalid attachment combination.\n");
1940 return DDERR_CANNOTATTACHSURFACE
;
1943 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1946 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1947 IUnknown_AddRef(attachment_impl
->attached_iface
);
1951 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1953 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1954 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1957 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1959 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1960 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1963 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1964 IUnknown_AddRef(attachment_impl
->attached_iface
);
1965 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1969 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1971 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1972 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1975 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1977 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1978 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1981 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1982 IUnknown_AddRef(attachment_impl
->attached_iface
);
1983 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1987 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1989 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1990 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1993 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1995 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1996 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1999 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
2000 IUnknown_AddRef(attachment_impl
->attached_iface
);
2001 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
2005 /*****************************************************************************
2006 * IDirectDrawSurface7::DeleteAttachedSurface
2008 * Removes a surface from the attachment chain. The surface's refcount
2009 * is decreased by one after it has been removed
2012 * Flags: Some flags, not used by this implementation
2013 * Attach: Surface to detach
2017 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
2019 *****************************************************************************/
2020 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
2021 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
2023 struct ddraw_surface
*prev
= surface
;
2025 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
2027 wined3d_mutex_lock();
2028 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
2030 wined3d_mutex_unlock();
2031 return DDERR_CANNOTDETACHSURFACE
;
2034 if (attachment
->attached_iface
!= detach_iface
)
2036 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
2037 wined3d_mutex_unlock();
2038 return DDERR_SURFACENOTATTACHED
;
2041 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
2042 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2044 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2045 /* FIXME: we should probably also subtract from dwMipMapCount of this
2046 * and all parent surfaces */
2049 /* Find the predecessor of the detached surface */
2050 while (prev
->next_attached
!= attachment
)
2052 if (!(prev
= prev
->next_attached
))
2054 ERR("Failed to find predecessor of %p.\n", attachment
);
2055 wined3d_mutex_unlock();
2056 return DDERR_SURFACENOTATTACHED
;
2060 /* Unchain the surface */
2061 prev
->next_attached
= attachment
->next_attached
;
2062 attachment
->next_attached
= NULL
;
2063 attachment
->first_attached
= attachment
;
2065 /* Check if the wined3d depth stencil needs updating. Note that we don't
2066 * just call d3d_device_update_depth_stencil() here since it uses
2067 * QueryInterface(). Some applications, SCP - Containment Breach in
2068 * particular, modify the QueryInterface() pointer in the surface vtbl
2069 * but don't cleanup properly after the relevant dll is unloaded. */
2070 if (attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
2071 && wined3d_device_get_depth_stencil_view(surface
->ddraw
->wined3d_device
) == surface
->wined3d_rtv
)
2072 wined3d_device_set_depth_stencil_view(surface
->ddraw
->wined3d_device
, NULL
);
2073 wined3d_mutex_unlock();
2075 /* Set attached_iface to NULL before releasing it, the surface may go
2077 attachment
->attached_iface
= NULL
;
2078 IUnknown_Release(detach_iface
);
2083 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
2084 DWORD flags
, IDirectDrawSurface7
*attachment
)
2086 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2087 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2089 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2091 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2094 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2095 DWORD flags
, IDirectDrawSurface4
*attachment
)
2097 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2098 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2100 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2102 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2105 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2106 DWORD flags
, IDirectDrawSurface3
*attachment
)
2108 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2109 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2111 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2113 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2116 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2117 DWORD flags
, IDirectDrawSurface2
*attachment
)
2119 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2120 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2122 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2124 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2127 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2128 DWORD flags
, IDirectDrawSurface
*attachment
)
2130 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2131 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2133 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2135 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2138 /*****************************************************************************
2139 * IDirectDrawSurface7::AddOverlayDirtyRect
2141 * "This method is not currently implemented"
2149 *****************************************************************************/
2150 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2152 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2154 return DDERR_UNSUPPORTED
; /* unchecked */
2157 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2159 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2161 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2163 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2166 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2168 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2170 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2172 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2175 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2177 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2179 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2181 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2184 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2188 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2190 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2193 /*****************************************************************************
2194 * IDirectDrawSurface7::GetDC
2196 * Returns a GDI device context for the surface
2199 * hdc: Address of a HDC variable to store the dc to
2203 * DDERR_INVALIDPARAMS if hdc is NULL
2205 *****************************************************************************/
2206 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2208 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2211 TRACE("iface %p, dc %p.\n", iface
, dc
);
2214 return DDERR_INVALIDPARAMS
;
2216 wined3d_mutex_lock();
2218 hr
= DDERR_DCALREADYCREATED
;
2219 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2220 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2222 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, dc
);
2228 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2230 const struct ddraw_palette
*palette
;
2232 if (surface
->palette
)
2233 palette
= surface
->palette
;
2234 else if (surface
->ddraw
->primary
)
2235 palette
= surface
->ddraw
->primary
->palette
;
2240 wined3d_palette_apply_to_dc(palette
->wined3d_palette
, *dc
);
2244 wined3d_mutex_unlock();
2247 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2248 * does not touch *dc. */
2249 case WINED3DERR_INVALIDCALL
:
2251 return DDERR_CANTCREATEDC
;
2258 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2262 TRACE("iface %p, dc %p.\n", iface
, dc
);
2264 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2267 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2269 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2271 TRACE("iface %p, dc %p.\n", iface
, dc
);
2273 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2276 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2278 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2280 TRACE("iface %p, dc %p.\n", iface
, dc
);
2282 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2285 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2287 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2289 TRACE("iface %p, dc %p.\n", iface
, dc
);
2291 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2294 /*****************************************************************************
2295 * IDirectDrawSurface7::ReleaseDC
2297 * Releases the DC that was constructed with GetDC
2300 * hdc: HDC to release
2303 * DD_OK on success, error code otherwise.
2305 *****************************************************************************/
2306 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2308 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2311 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2313 wined3d_mutex_lock();
2318 else if (SUCCEEDED(hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, hdc
)))
2321 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2322 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2324 wined3d_mutex_unlock();
2330 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2332 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2334 TRACE("iface %p, dc %p.\n", iface
, dc
);
2336 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2339 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2341 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2343 TRACE("iface %p, dc %p.\n", iface
, dc
);
2345 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2348 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2350 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2352 TRACE("iface %p, dc %p.\n", iface
, dc
);
2354 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2357 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2359 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2361 TRACE("iface %p, dc %p.\n", iface
, dc
);
2363 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2366 /*****************************************************************************
2367 * IDirectDrawSurface7::GetCaps
2369 * Returns the surface's caps
2372 * Caps: Address to write the caps to
2376 * DDERR_INVALIDPARAMS if Caps is NULL
2378 *****************************************************************************/
2379 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2381 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2383 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2386 return DDERR_INVALIDPARAMS
;
2388 *Caps
= surface
->surface_desc
.ddsCaps
;
2393 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2395 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2397 TRACE("iface %p, caps %p.\n", iface
, caps
);
2399 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2402 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2404 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2408 TRACE("iface %p, caps %p.\n", iface
, caps
);
2410 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2411 if (FAILED(hr
)) return hr
;
2413 caps
->dwCaps
= caps2
.dwCaps
;
2417 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2419 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2423 TRACE("iface %p, caps %p.\n", iface
, caps
);
2425 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2426 if (FAILED(hr
)) return hr
;
2428 caps
->dwCaps
= caps2
.dwCaps
;
2432 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2434 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2438 TRACE("iface %p, caps %p.\n", iface
, caps
);
2440 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2441 if (FAILED(hr
)) return hr
;
2443 caps
->dwCaps
= caps2
.dwCaps
;
2447 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2449 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2450 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2452 struct wined3d_resource
*resource
;
2454 TRACE("iface %p, priority %u.\n", iface
, priority
);
2456 wined3d_mutex_lock();
2457 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2458 * calls on such surfaces segfault on Windows. */
2459 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2461 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2462 hr
= DDERR_INVALIDPARAMS
;
2466 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2467 wined3d_resource_set_priority(resource
, priority
);
2470 wined3d_mutex_unlock();
2475 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2477 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2478 const struct wined3d_resource
*resource
;
2479 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2482 TRACE("iface %p, priority %p.\n", iface
, priority
);
2484 wined3d_mutex_lock();
2485 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2487 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2488 hr
= DDERR_INVALIDOBJECT
;
2490 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2492 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2493 hr
= DDERR_INVALIDPARAMS
;
2497 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2498 *priority
= wined3d_resource_get_priority(resource
);
2501 wined3d_mutex_unlock();
2506 /*****************************************************************************
2507 * IDirectDrawSurface7::SetPrivateData
2509 * Stores some data in the surface that is intended for the application's
2513 * tag: GUID that identifies the data
2514 * Data: Pointer to the private data
2515 * Size: Size of the private data
2519 * D3D_OK on success, error code otherwise.
2521 *****************************************************************************/
2522 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2523 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2525 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2528 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2529 iface
, debugstr_guid(tag
), data
, size
, flags
);
2533 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2534 return DDERR_INVALIDPARAMS
;
2537 wined3d_mutex_lock();
2538 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2539 wined3d_mutex_unlock();
2540 return hr_ddraw_from_wined3d(hr
);
2543 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2544 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2546 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2548 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2549 iface
, debugstr_guid(tag
), data
, size
, flags
);
2551 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2554 /*****************************************************************************
2555 * IDirectDrawSurface7::GetPrivateData
2557 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2560 * tag: GUID of the data to return
2561 * Data: Address where to write the data to
2562 * Size: Size of the buffer at Data
2566 * DDERR_INVALIDPARAMS if Data is NULL
2568 *****************************************************************************/
2569 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2571 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2572 const struct wined3d_private_data
*stored_data
;
2575 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2576 iface
, debugstr_guid(tag
), data
, size
);
2578 wined3d_mutex_lock();
2579 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2582 hr
= DDERR_NOTFOUND
;
2587 hr
= DDERR_INVALIDPARAMS
;
2590 if (*size
< stored_data
->size
)
2592 *size
= stored_data
->size
;
2593 hr
= DDERR_MOREDATA
;
2598 hr
= DDERR_INVALIDPARAMS
;
2602 *size
= stored_data
->size
;
2603 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2607 wined3d_mutex_unlock();
2611 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2613 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2615 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2616 iface
, debugstr_guid(tag
), data
, size
);
2618 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2621 /*****************************************************************************
2622 * IDirectDrawSurface7::FreePrivateData
2624 * Frees private data stored in the surface
2627 * tag: Tag of the data to free
2630 * D3D_OK on success, error code otherwise.
2632 *****************************************************************************/
2633 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2635 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2636 struct wined3d_private_data
*entry
;
2638 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2640 wined3d_mutex_lock();
2641 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2644 wined3d_mutex_unlock();
2645 return DDERR_NOTFOUND
;
2648 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2649 wined3d_mutex_unlock();
2654 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2656 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2658 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2660 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2663 /*****************************************************************************
2664 * IDirectDrawSurface7::PageLock
2666 * Prevents a sysmem surface from being paged out
2669 * Flags: Not used, must be 0(unchecked)
2672 * DD_OK, because it's a stub
2674 *****************************************************************************/
2675 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2677 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2679 /* This is Windows memory management related - we don't need this */
2683 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2685 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2687 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2689 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2692 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2694 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2696 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2698 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2701 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2703 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2705 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2707 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2710 /*****************************************************************************
2711 * IDirectDrawSurface7::PageUnlock
2713 * Allows a sysmem surface to be paged out
2716 * Flags: Not used, must be 0(unchecked)
2719 * DD_OK, because it's a stub
2721 *****************************************************************************/
2722 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2724 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2729 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2731 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2733 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2735 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2738 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2740 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2742 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2744 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2747 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2749 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2751 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2753 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2756 /*****************************************************************************
2757 * IDirectDrawSurface7::BltBatch
2759 * An unimplemented function
2767 *****************************************************************************/
2768 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2770 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2772 /* MSDN: "not currently implemented" */
2773 return DDERR_UNSUPPORTED
;
2776 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2778 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2780 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2782 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2785 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2787 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2789 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2791 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2794 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2796 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2798 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2800 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2803 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2805 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2807 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2809 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2812 /*****************************************************************************
2813 * IDirectDrawSurface7::EnumAttachedSurfaces
2815 * Enumerates all surfaces attached to this surface
2818 * context: Pointer to pass unmodified to the callback
2819 * cb: Callback function to call for each surface
2823 * DDERR_INVALIDPARAMS if cb is NULL
2825 *****************************************************************************/
2826 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2827 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2829 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2830 struct ddraw_surface
*surf
;
2831 DDSURFACEDESC2 desc
;
2834 /* Attached surfaces aren't handled in WineD3D */
2835 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2838 return DDERR_INVALIDPARAMS
;
2840 wined3d_mutex_lock();
2842 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2844 surf
= surface
->complex_array
[i
];
2847 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2848 desc
= surf
->surface_desc
;
2849 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2850 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2852 wined3d_mutex_unlock();
2857 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2859 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2860 desc
= surf
->surface_desc
;
2861 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2862 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2864 wined3d_mutex_unlock();
2869 TRACE(" end of enumeration.\n");
2871 wined3d_mutex_unlock();
2876 struct callback_info2
2878 LPDDENUMSURFACESCALLBACK2 callback
;
2882 struct callback_info
2884 LPDDENUMSURFACESCALLBACK callback
;
2888 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2890 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2891 const struct callback_info2
*info
= context
;
2893 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2894 ddraw_surface7_Release(surface
);
2896 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2899 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2901 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2902 const struct callback_info
*info
= context
;
2904 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2905 ddraw_surface7_Release(surface
);
2907 /* FIXME: Check surface_test.dwSize */
2908 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2909 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2912 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2913 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2915 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2916 struct callback_info2 info
;
2918 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2920 info
.callback
= callback
;
2921 info
.context
= context
;
2923 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2924 &info
, EnumCallback2
);
2927 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2928 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2930 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2931 struct callback_info info
;
2933 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2935 info
.callback
= callback
;
2936 info
.context
= context
;
2938 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2939 &info
, EnumCallback
);
2942 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2943 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2945 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2946 struct callback_info info
;
2948 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2950 info
.callback
= callback
;
2951 info
.context
= context
;
2953 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2954 &info
, EnumCallback
);
2957 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2958 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2960 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2961 struct callback_info info
;
2963 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2965 info
.callback
= callback
;
2966 info
.context
= context
;
2968 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2969 &info
, EnumCallback
);
2972 /*****************************************************************************
2973 * IDirectDrawSurface7::EnumOverlayZOrders
2975 * "Enumerates the overlay surfaces on the specified destination"
2978 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2979 * context: context to pass back to the callback
2980 * cb: callback function to call for each enumerated surface
2983 * DD_OK, because it's a stub
2985 *****************************************************************************/
2986 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2987 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2989 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2994 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2995 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2997 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2998 struct callback_info2 info
;
3000 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3002 info
.callback
= callback
;
3003 info
.context
= context
;
3005 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3006 flags
, &info
, EnumCallback2
);
3009 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
3010 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3012 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3013 struct callback_info info
;
3015 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3017 info
.callback
= callback
;
3018 info
.context
= context
;
3020 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3021 flags
, &info
, EnumCallback
);
3024 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
3025 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3027 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3028 struct callback_info info
;
3030 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3032 info
.callback
= callback
;
3033 info
.context
= context
;
3035 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3036 flags
, &info
, EnumCallback
);
3039 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
3040 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3042 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3043 struct callback_info info
;
3045 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
3047 info
.callback
= callback
;
3048 info
.context
= context
;
3050 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
3051 flags
, &info
, EnumCallback
);
3054 /*****************************************************************************
3055 * IDirectDrawSurface7::GetBltStatus
3057 * Returns the blitting status
3060 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
3062 *****************************************************************************/
3063 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3065 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3069 case WINEDDGBS_CANBLT
:
3070 case WINEDDGBS_ISBLTDONE
:
3074 return DDERR_INVALIDPARAMS
;
3078 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3080 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3082 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3084 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3087 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3089 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3091 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3093 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3096 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3098 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3100 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3102 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3105 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3107 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3109 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3111 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3114 /*****************************************************************************
3115 * IDirectDrawSurface7::GetColorKey
3117 * Returns the color key assigned to the surface
3121 * CKey: Address to store the key to
3125 * DDERR_INVALIDPARAMS if CKey is NULL
3127 *****************************************************************************/
3128 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3130 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3132 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3135 return DDERR_INVALIDPARAMS
;
3137 wined3d_mutex_lock();
3141 case DDCKEY_DESTBLT
:
3142 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3144 wined3d_mutex_unlock();
3145 return DDERR_NOCOLORKEY
;
3147 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3150 case DDCKEY_DESTOVERLAY
:
3151 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3153 wined3d_mutex_unlock();
3154 return DDERR_NOCOLORKEY
;
3156 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3160 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3162 wined3d_mutex_unlock();
3163 return DDERR_NOCOLORKEY
;
3165 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3168 case DDCKEY_SRCOVERLAY
:
3169 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3171 wined3d_mutex_unlock();
3172 return DDERR_NOCOLORKEY
;
3174 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3178 wined3d_mutex_unlock();
3179 return DDERR_INVALIDPARAMS
;
3182 wined3d_mutex_unlock();
3187 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3189 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3191 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3193 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3196 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3198 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3200 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3202 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3205 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3207 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3209 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3211 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3214 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3216 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3218 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3220 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3223 /*****************************************************************************
3224 * IDirectDrawSurface7::GetFlipStatus
3226 * Returns the flipping status of the surface
3229 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3231 *****************************************************************************/
3232 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3234 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3236 /* XXX: DDERR_INVALIDSURFACETYPE */
3240 case WINEDDGFS_CANFLIP
:
3241 case WINEDDGFS_ISFLIPDONE
:
3245 return DDERR_INVALIDPARAMS
;
3249 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3253 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3255 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3258 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3260 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3262 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3264 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3267 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3269 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3271 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3273 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3276 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3278 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3280 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3282 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3285 /*****************************************************************************
3286 * IDirectDrawSurface7::GetOverlayPosition
3288 * Returns the display coordinates of a visible and active overlay surface
3295 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3296 *****************************************************************************/
3297 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3299 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3302 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3304 wined3d_mutex_lock();
3305 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3306 surface
->sub_resource_idx
, x
, y
);
3307 wined3d_mutex_unlock();
3312 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3314 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3316 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3318 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3321 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3323 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3325 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3327 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3330 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3332 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3334 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3336 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3339 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3341 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3343 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3345 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3348 /*****************************************************************************
3349 * IDirectDrawSurface7::GetPixelFormat
3351 * Returns the pixel format of the Surface
3354 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3355 * format should be written
3359 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3361 *****************************************************************************/
3362 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3364 /* What is DDERR_INVALIDSURFACETYPE for here? */
3365 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3367 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3370 return DDERR_INVALIDPARAMS
;
3372 wined3d_mutex_lock();
3373 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3374 wined3d_mutex_unlock();
3379 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3381 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3383 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3385 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3388 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3390 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3392 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3394 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3397 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3399 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3401 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3403 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3406 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3408 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3410 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3412 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3415 /*****************************************************************************
3416 * IDirectDrawSurface7::GetSurfaceDesc
3418 * Returns the description of this surface
3421 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3426 * DDERR_INVALIDPARAMS if DDSD is NULL
3428 *****************************************************************************/
3429 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3431 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3433 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3436 return DDERR_INVALIDPARAMS
;
3438 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3440 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3441 return DDERR_INVALIDPARAMS
;
3444 wined3d_mutex_lock();
3445 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3446 TRACE("Returning surface desc:\n");
3447 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3448 wined3d_mutex_unlock();
3453 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3455 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3457 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3459 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3462 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3464 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3466 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3468 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3470 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3472 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3473 return DDERR_INVALIDPARAMS
;
3476 wined3d_mutex_lock();
3477 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3478 TRACE("Returning surface desc:\n");
3479 if (TRACE_ON(ddraw
))
3481 /* DDRAW_dump_surface_desc handles the smaller size */
3482 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3484 wined3d_mutex_unlock();
3489 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3491 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3493 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3495 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3498 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3500 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3502 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3504 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3507 /*****************************************************************************
3508 * IDirectDrawSurface7::Initialize
3510 * Initializes the surface. This is a no-op in Wine
3513 * DD: Pointer to an DirectDraw interface
3514 * DDSD: Surface description for initialization
3517 * DDERR_ALREADYINITIALIZED
3519 *****************************************************************************/
3520 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3521 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3523 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3525 return DDERR_ALREADYINITIALIZED
;
3528 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3529 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3531 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3533 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3535 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3536 ddraw
, surface_desc
);
3539 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3540 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3542 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3543 DDSURFACEDESC2 surface_desc2
;
3545 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3547 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3548 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3549 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3552 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3553 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3555 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3556 DDSURFACEDESC2 surface_desc2
;
3558 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3560 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3561 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3562 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3565 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3566 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3568 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3569 DDSURFACEDESC2 surface_desc2
;
3571 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3573 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3574 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3575 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3578 /*****************************************************************************
3579 * IDirect3DTexture1::Initialize
3581 * The sdk says it's not implemented
3589 *****************************************************************************/
3590 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3591 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3593 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3595 return DDERR_UNSUPPORTED
; /* Unchecked */
3598 /*****************************************************************************
3599 * IDirectDrawSurface7::IsLost
3601 * Checks if the surface is lost
3604 * DD_OK, if the surface is usable
3605 * DDERR_ISLOST if the surface is lost
3607 *****************************************************************************/
3608 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3610 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3612 TRACE("iface %p.\n", iface
);
3614 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3615 return DDERR_SURFACELOST
;
3620 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3622 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3624 TRACE("iface %p.\n", iface
);
3626 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3629 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3631 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3633 TRACE("iface %p.\n", iface
);
3635 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3638 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3640 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3642 TRACE("iface %p.\n", iface
);
3644 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3647 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3649 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3651 TRACE("iface %p.\n", iface
);
3653 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3656 /*****************************************************************************
3657 * IDirectDrawSurface7::Restore
3659 * Restores a lost surface. This makes the surface usable again, but
3660 * doesn't reload its old contents
3663 * DD_OK on success, error code otherwise.
3665 *****************************************************************************/
3666 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3668 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3670 TRACE("iface %p.\n", iface
);
3672 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3674 struct wined3d_swapchain
*swapchain
= surface
->ddraw
->wined3d_swapchain
;
3675 struct wined3d_sub_resource_desc wined3d_desc
;
3676 struct wined3d_display_mode mode
;
3679 if (FAILED(hr
= wined3d_swapchain_get_display_mode(swapchain
, &mode
, NULL
)))
3681 WARN("Failed to get display mode, hr %#x.\n", hr
);
3685 if (FAILED(hr
= wined3d_texture_get_sub_resource_desc(surface
->wined3d_texture
, 0, &wined3d_desc
)))
3687 WARN("Failed to get resource desc, hr %#x.\n", hr
);
3691 if (mode
.width
!= wined3d_desc
.width
|| mode
.height
!= wined3d_desc
.height
)
3693 WARN("Display mode dimensions %ux%u don't match surface dimensions %ux%u.\n",
3694 mode
.width
, mode
.height
, wined3d_desc
.width
, wined3d_desc
.height
);
3695 return DDERR_WRONGMODE
;
3698 if (mode
.format_id
!= wined3d_desc
.format
)
3700 WARN("Display mode format %#x doesn't match surface format %#x.\n",
3701 mode
.format_id
, wined3d_desc
.format
);
3702 return DDERR_WRONGMODE
;
3706 ddraw_update_lost_surfaces(surface
->ddraw
);
3707 surface
->is_lost
= FALSE
;
3712 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3714 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3716 TRACE("iface %p.\n", iface
);
3718 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3721 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3723 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3725 TRACE("iface %p.\n", iface
);
3727 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3730 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3732 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3734 TRACE("iface %p.\n", iface
);
3736 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3739 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3741 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3743 TRACE("iface %p.\n", iface
);
3745 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3748 /*****************************************************************************
3749 * IDirectDrawSurface7::SetOverlayPosition
3751 * Changes the display coordinates of an overlay surface
3758 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3759 *****************************************************************************/
3760 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3762 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3765 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3767 wined3d_mutex_lock();
3768 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3769 surface
->sub_resource_idx
, x
, y
);
3770 wined3d_mutex_unlock();
3775 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3777 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3779 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3781 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3784 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3786 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3788 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3790 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3793 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3795 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3797 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3799 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3802 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3804 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3806 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3808 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3811 /*****************************************************************************
3812 * IDirectDrawSurface7::UpdateOverlay
3814 * Modifies the attributes of an overlay surface.
3817 * SrcRect: The section of the source being used for the overlay
3818 * DstSurface: Address of the surface that is overlaid
3819 * DstRect: Place of the overlay
3820 * Flags: some DDOVER_* flags
3823 * DDERR_UNSUPPORTED, because we don't support overlays
3825 *****************************************************************************/
3826 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3827 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3829 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3830 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3831 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3832 unsigned int dst_sub_resource_idx
= 0;
3835 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3836 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3839 FIXME("Ignoring fx %p.\n", fx
);
3841 wined3d_mutex_lock();
3844 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3845 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3847 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3848 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3849 wined3d_mutex_unlock();
3853 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3854 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3855 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3861 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3862 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3864 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3865 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3867 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3868 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3870 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3871 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3874 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3875 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3877 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3878 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3880 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3881 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3883 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3884 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3887 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3888 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3890 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3891 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3893 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3894 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3896 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3897 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3900 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3901 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3903 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3904 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3906 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3907 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3909 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3910 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3913 /*****************************************************************************
3914 * IDirectDrawSurface7::UpdateOverlayDisplay
3916 * The DX7 sdk says that it's not implemented
3921 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3923 *****************************************************************************/
3924 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3926 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3928 return DDERR_UNSUPPORTED
;
3931 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3933 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3935 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3937 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3940 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3942 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3944 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3946 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3949 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3951 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3953 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3955 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3958 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3960 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3962 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3964 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3967 /*****************************************************************************
3968 * IDirectDrawSurface7::UpdateOverlayZOrder
3970 * Sets an overlay's Z order
3973 * Flags: DDOVERZ_* flags
3974 * DDSRef: Defines the relative position in the overlay chain
3977 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3979 *****************************************************************************/
3980 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3981 DWORD flags
, IDirectDrawSurface7
*reference
)
3983 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3985 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
3987 wined3d_mutex_lock();
3988 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
3990 WARN("Not an overlay surface.\n");
3991 wined3d_mutex_unlock();
3992 return DDERR_NOTAOVERLAYSURFACE
;
3994 wined3d_mutex_unlock();
3999 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
4000 DWORD flags
, IDirectDrawSurface4
*reference
)
4002 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4003 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
4005 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4007 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4008 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4011 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
4012 DWORD flags
, IDirectDrawSurface3
*reference
)
4014 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4015 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
4017 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4019 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4020 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4023 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
4024 DWORD flags
, IDirectDrawSurface2
*reference
)
4026 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4027 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
4029 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4031 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4032 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4035 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
4036 DWORD flags
, IDirectDrawSurface
*reference
)
4038 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4039 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
4041 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
4043 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
4044 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
4047 /*****************************************************************************
4048 * IDirectDrawSurface7::GetDDInterface
4050 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
4051 * surface belongs to
4054 * DD: Address to write the interface pointer to
4058 * DDERR_INVALIDPARAMS if DD is NULL
4060 *****************************************************************************/
4061 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
4063 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4065 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
4068 return DDERR_INVALIDPARAMS
;
4070 switch(This
->version
)
4073 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
4077 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
4081 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
4085 *DD
= &This
->ddraw
->IDirectDraw_iface
;
4089 IUnknown_AddRef((IUnknown
*)*DD
);
4094 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
4096 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4098 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4100 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4103 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
4105 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4107 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4109 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4112 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4114 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4116 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4118 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4121 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4123 TRACE("iface %p.\n", iface
);
4128 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4130 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4132 TRACE("iface %p.\n", iface
);
4134 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4137 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4139 TRACE("iface %p, value %p.\n", iface
, pValue
);
4146 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4148 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4150 TRACE("iface %p, value %p.\n", iface
, pValue
);
4152 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4155 /*****************************************************************************
4156 * IDirectDrawSurface7::SetLOD
4158 * Sets the level of detail of a texture
4161 * MaxLOD: LOD to set
4165 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4167 *****************************************************************************/
4168 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4170 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4173 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4175 wined3d_mutex_lock();
4176 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4178 wined3d_mutex_unlock();
4179 return DDERR_INVALIDOBJECT
;
4182 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4183 wined3d_mutex_unlock();
4188 /*****************************************************************************
4189 * IDirectDrawSurface7::GetLOD
4191 * Returns the level of detail of a Direct3D texture
4194 * MaxLOD: Address to write the LOD to
4198 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4199 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4201 *****************************************************************************/
4202 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4204 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4206 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4209 return DDERR_INVALIDPARAMS
;
4211 wined3d_mutex_lock();
4212 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4214 wined3d_mutex_unlock();
4215 return DDERR_INVALIDOBJECT
;
4218 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4219 wined3d_mutex_unlock();
4224 /*****************************************************************************
4225 * IDirectDrawSurface7::BltFast
4227 * Performs a fast Blit.
4230 * dstx: The x coordinate to blit to on the destination
4231 * dsty: The y coordinate to blit to on the destination
4232 * Source: The source surface
4233 * rsrc: The source rectangle
4234 * trans: Type of transfer. Some DDBLTFAST_* flags
4237 * DD_OK on success, error code otherwise.
4239 *****************************************************************************/
4240 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4241 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4243 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4244 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4245 DWORD flags
= WINED3D_BLT_SYNCHRONOUS
;
4246 DWORD src_w
, src_h
, dst_w
, dst_h
;
4250 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4251 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4253 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4254 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4258 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4262 src_w
= src_rect
->right
- src_rect
->left
;
4263 src_h
= src_rect
->bottom
- src_rect
->top
;
4264 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4265 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4267 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4268 return DDERR_INVALIDRECT
;
4271 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4272 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4273 flags
|= WINED3D_BLT_SRC_CKEY
;
4274 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4275 flags
|= WINED3D_BLT_DST_CKEY
;
4276 if (trans
& DDBLTFAST_WAIT
)
4277 flags
|= WINED3D_BLT_WAIT
;
4278 if (trans
& DDBLTFAST_DONOTWAIT
)
4279 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4281 wined3d_mutex_lock();
4282 if (dst_impl
->clipper
)
4284 wined3d_mutex_unlock();
4285 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4286 return DDERR_BLTFASTCANTCLIP
;
4289 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4290 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
);
4292 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
4293 src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4294 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4295 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
);
4296 wined3d_mutex_unlock();
4300 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4305 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4306 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4308 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4309 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4311 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4312 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4314 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4315 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4318 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4319 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4321 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4322 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4324 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4325 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4327 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4328 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4331 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4332 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4334 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4335 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4337 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4338 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4340 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4341 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4344 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4345 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4347 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4348 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4350 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4351 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4353 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4354 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4357 /*****************************************************************************
4358 * IDirectDrawSurface7::GetClipper
4360 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4364 * Clipper: Address to store the interface pointer at
4368 * DDERR_INVALIDPARAMS if Clipper is NULL
4369 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4371 *****************************************************************************/
4372 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4376 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4379 return DDERR_INVALIDPARAMS
;
4381 wined3d_mutex_lock();
4382 if (!surface
->clipper
)
4384 wined3d_mutex_unlock();
4385 return DDERR_NOCLIPPERATTACHED
;
4388 *Clipper
= &surface
->clipper
->IDirectDrawClipper_iface
;
4389 IDirectDrawClipper_AddRef(*Clipper
);
4390 wined3d_mutex_unlock();
4395 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4397 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4399 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4401 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4404 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4406 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4408 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4410 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4413 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4415 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4417 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4419 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4422 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4424 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4426 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4428 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4431 /*****************************************************************************
4432 * IDirectDrawSurface7::SetClipper
4434 * Sets a clipper for the surface
4437 * Clipper: IDirectDrawClipper interface of the clipper to set
4442 *****************************************************************************/
4443 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4444 IDirectDrawClipper
*iclipper
)
4446 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4447 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4448 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4451 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4453 wined3d_mutex_lock();
4454 if (clipper
== This
->clipper
)
4456 wined3d_mutex_unlock();
4460 This
->clipper
= clipper
;
4462 if (clipper
!= NULL
)
4463 IDirectDrawClipper_AddRef(iclipper
);
4465 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4467 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4471 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4476 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4477 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4481 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4482 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4486 wined3d_mutex_unlock();
4491 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4493 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4495 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4497 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4500 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4502 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4504 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4506 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4509 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4511 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4513 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4515 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4518 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4520 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4522 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4524 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4527 /*****************************************************************************
4528 * IDirectDrawSurface7::SetSurfaceDesc
4530 * Sets the surface description. It can override the pixel format, the surface
4532 * It's not really tested.
4535 * DDSD: Pointer to the new surface description to set
4540 * DDERR_INVALIDPARAMS if DDSD is NULL
4542 *****************************************************************************/
4543 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4545 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4547 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4548 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4549 enum wined3d_format_id format_id
;
4550 UINT pitch
, width
, height
;
4552 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4556 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4557 return DDERR_INVALIDPARAMS
;
4561 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4562 return DDERR_INVALIDPARAMS
;
4564 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4565 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4566 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4568 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4569 return DDERR_INVALIDSURFACETYPE
;
4572 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4573 * for PIXELFORMAT to work */
4574 if (DDSD
->dwFlags
& ~allowed_flags
)
4576 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4577 return DDERR_INVALIDPARAMS
;
4579 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4581 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4582 return DDERR_INVALIDPARAMS
;
4584 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4586 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4587 return DDERR_INVALIDCAPS
;
4589 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4591 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4593 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4594 return DDERR_INVALIDPARAMS
;
4596 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4598 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4599 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4600 return DDERR_INVALIDPARAMS
;
4602 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4603 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4604 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4605 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4606 pitch
= DDSD
->u1
.lPitch
;
4607 width
= DDSD
->dwWidth
;
4609 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4611 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4612 return DDERR_INVALIDPARAMS
;
4616 pitch
= This
->surface_desc
.u1
.lPitch
;
4617 width
= This
->surface_desc
.dwWidth
;
4620 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4622 if (!DDSD
->dwHeight
)
4624 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4625 return DDERR_INVALIDPARAMS
;
4627 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4628 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4629 height
= DDSD
->dwHeight
;
4633 height
= This
->surface_desc
.dwHeight
;
4636 wined3d_mutex_lock();
4637 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4639 enum wined3d_format_id current_format_id
;
4640 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4642 if (format_id
== WINED3DFMT_UNKNOWN
)
4644 ERR("Requested to set an unknown pixelformat\n");
4645 wined3d_mutex_unlock();
4646 return DDERR_INVALIDPARAMS
;
4648 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4649 if (format_id
!= current_format_id
)
4650 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4654 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4657 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4658 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4660 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4661 wined3d_mutex_unlock();
4662 return hr_ddraw_from_wined3d(hr
);
4665 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4666 This
->surface_desc
.dwWidth
= width
;
4667 if (DDSD
->dwFlags
& DDSD_PITCH
)
4668 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4669 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4670 This
->surface_desc
.dwHeight
= height
;
4671 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4672 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4674 wined3d_mutex_unlock();
4679 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4680 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4682 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4684 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4686 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4687 surface_desc
, flags
);
4690 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4691 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4693 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4694 DDSURFACEDESC2 surface_desc2
;
4696 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4698 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4699 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4700 surface_desc
? &surface_desc2
: NULL
, flags
);
4703 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4705 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4706 struct ddraw_palette
*palette_impl
;
4709 TRACE("iface %p, palette %p.\n", iface
, palette
);
4712 return DDERR_INVALIDPARAMS
;
4713 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4715 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4716 return DDERR_SURFACELOST
;
4719 wined3d_mutex_lock();
4720 if ((palette_impl
= surface
->palette
))
4722 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4723 IDirectDrawPalette_AddRef(*palette
);
4728 hr
= DDERR_NOPALETTEATTACHED
;
4730 wined3d_mutex_unlock();
4735 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4737 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4739 TRACE("iface %p, palette %p.\n", iface
, palette
);
4741 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4744 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4746 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4748 TRACE("iface %p, palette %p.\n", iface
, palette
);
4750 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4753 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4755 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4757 TRACE("iface %p, palette %p.\n", iface
, palette
);
4759 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4762 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4764 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4766 TRACE("iface %p, palette %p.\n", iface
, palette
);
4768 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4771 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4773 DDCOLORKEY fixed_color_key
;
4774 HRESULT hr
= WINED3D_OK
;
4776 if (flags
& DDCKEY_COLORSPACE
)
4778 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4780 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4781 return DDERR_NOCOLORKEYHW
;
4783 flags
&= ~DDCKEY_COLORSPACE
;
4786 wined3d_mutex_lock();
4790 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4791 switch (flags
& ~DDCKEY_COLORSPACE
)
4793 case DDCKEY_DESTBLT
:
4794 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4795 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4798 case DDCKEY_DESTOVERLAY
:
4799 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4800 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4803 case DDCKEY_SRCOVERLAY
:
4804 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4805 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4809 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4810 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4814 wined3d_mutex_unlock();
4815 return DDERR_INVALIDPARAMS
;
4820 switch (flags
& ~DDCKEY_COLORSPACE
)
4822 case DDCKEY_DESTBLT
:
4823 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4826 case DDCKEY_DESTOVERLAY
:
4827 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4830 case DDCKEY_SRCOVERLAY
:
4831 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4835 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4839 wined3d_mutex_unlock();
4840 return DDERR_INVALIDPARAMS
;
4844 if (surface
->is_complex_root
)
4845 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4846 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4848 wined3d_mutex_unlock();
4850 return hr_ddraw_from_wined3d(hr
);
4853 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4855 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4857 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4859 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4860 return DDERR_NOTONMIPMAPSUBLEVEL
;
4862 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4865 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4867 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4869 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4871 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4874 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4876 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4878 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4880 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4883 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4885 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4887 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4889 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4892 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4896 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4898 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4901 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4903 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4905 TRACE("iface %p, palette %p.\n", iface
, palette
);
4907 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4908 return DDERR_NOTONMIPMAPSUBLEVEL
;
4909 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4911 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4912 return DDERR_SURFACELOST
;
4915 return ddraw_surface_set_palette(surface
, palette
);
4918 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4920 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4922 TRACE("iface %p, palette %p.\n", iface
, palette
);
4924 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4926 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4927 return DDERR_SURFACELOST
;
4930 return ddraw_surface_set_palette(surface
, palette
);
4933 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4935 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4937 TRACE("iface %p, palette %p.\n", iface
, palette
);
4939 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4941 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4942 return DDERR_SURFACELOST
;
4945 return ddraw_surface_set_palette(surface
, palette
);
4948 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4950 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4952 TRACE("iface %p, palette %p.\n", iface
, palette
);
4954 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4956 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4957 return DDERR_SURFACELOST
;
4960 return ddraw_surface_set_palette(surface
, palette
);
4963 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4965 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4967 TRACE("iface %p, palette %p.\n", iface
, palette
);
4969 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4971 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4972 return DDERR_SURFACELOST
;
4975 return ddraw_surface_set_palette(surface
, palette
);
4978 /**********************************************************
4979 * IDirectDrawGammaControl::GetGammaRamp
4981 * Returns the current gamma ramp for a surface
4985 * gamma_ramp: Address to write the ramp to
4989 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4991 **********************************************************/
4992 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4993 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4995 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4997 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
5001 WARN("Invalid gamma_ramp passed.\n");
5002 return DDERR_INVALIDPARAMS
;
5005 wined3d_mutex_lock();
5006 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5008 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
5009 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
5013 ERR("Not implemented for non-primary surfaces.\n");
5015 wined3d_mutex_unlock();
5020 /**********************************************************
5021 * IDirectDrawGammaControl::SetGammaRamp
5023 * Sets the red, green and blue gamma ramps for
5026 * flags: Can be DDSGR_CALIBRATE to request calibration
5027 * gamma_ramp: Structure containing the new gamma ramp
5031 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
5033 **********************************************************/
5034 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
5035 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
5037 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
5039 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
5043 WARN("Invalid gamma_ramp passed.\n");
5044 return DDERR_INVALIDPARAMS
;
5047 wined3d_mutex_lock();
5048 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5050 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
5051 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
5052 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
5056 ERR("Not implemented for non-primary surfaces.\n");
5058 wined3d_mutex_unlock();
5063 /*****************************************************************************
5064 * IDirect3DTexture2::PaletteChanged
5066 * Informs the texture about a palette change
5069 * start: Start index of the change
5070 * count: The number of changed entries
5073 * D3D_OK, because it's a stub
5075 *****************************************************************************/
5076 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
5078 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
5083 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
5085 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5087 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
5089 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
5092 /*****************************************************************************
5093 * IDirect3DTexture::Unload
5095 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
5101 *****************************************************************************/
5102 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
5104 WARN("iface %p. Not implemented.\n", iface
);
5106 return DDERR_UNSUPPORTED
;
5109 /*****************************************************************************
5110 * IDirect3DTexture2::GetHandle
5112 * Returns handle for the texture.
5115 * device: Device this handle is assigned to
5116 * handle: Address to store the handle at.
5121 *****************************************************************************/
5122 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5123 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5125 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5126 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5128 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5130 wined3d_mutex_lock();
5132 if (!surface
->Handle
)
5134 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5135 if (h
== DDRAW_INVALID_HANDLE
)
5137 ERR("Failed to allocate a texture handle.\n");
5138 wined3d_mutex_unlock();
5139 return DDERR_OUTOFMEMORY
;
5142 surface
->Handle
= h
+ 1;
5145 TRACE("Returning handle %08x.\n", surface
->Handle
);
5146 *handle
= surface
->Handle
;
5148 wined3d_mutex_unlock();
5153 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5154 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5156 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5157 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5159 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5161 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5162 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5165 /*****************************************************************************
5166 * get_sub_mimaplevel
5168 * Helper function that returns the next mipmap level
5170 * tex_ptr: Surface of which to return the next level
5172 *****************************************************************************/
5173 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5175 /* Now go down the mipmap chain to the next surface */
5176 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5177 IDirectDrawSurface7
*next_level
;
5180 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5181 if (FAILED(hr
)) return NULL
;
5183 ddraw_surface7_Release(next_level
);
5185 return impl_from_IDirectDrawSurface7(next_level
);
5188 /*****************************************************************************
5189 * IDirect3DTexture2::Load
5191 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5193 * This function isn't relayed to WineD3D because the whole interface is
5194 * implemented in DDraw only. For speed improvements an implementation which
5195 * takes OpenGL more into account could be placed into WineD3D.
5198 * src_texture: Address of the texture to load
5202 * D3DERR_TEXTURE_LOAD_FAILED.
5204 *****************************************************************************/
5205 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5207 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5208 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5209 struct wined3d_resource
*dst_resource
, *src_resource
;
5212 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5214 if (src_surface
== dst_surface
)
5216 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5220 wined3d_mutex_lock();
5222 dst_resource
= wined3d_texture_get_resource(dst_surface
->wined3d_texture
);
5223 src_resource
= wined3d_texture_get_resource(src_surface
->wined3d_texture
);
5225 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5226 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5227 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5229 ERR("Trying to load surfaces with different mip-map counts.\n");
5234 struct ddraw_palette
*dst_pal
, *src_pal
;
5235 DDSURFACEDESC
*src_desc
, *dst_desc
;
5237 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5239 /* Suppress the ALLOCONLOAD flag */
5240 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5242 /* Get the palettes */
5243 dst_pal
= dst_surface
->palette
;
5244 src_pal
= src_surface
->palette
;
5248 PALETTEENTRY palent
[256];
5252 wined3d_mutex_unlock();
5253 return DDERR_NOPALETTEATTACHED
;
5255 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5256 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5259 /* Copy one surface on the other */
5260 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5261 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5263 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5265 /* Should also check for same pixel format, u1.lPitch, ... */
5266 ERR("Error in surface sizes.\n");
5267 wined3d_mutex_unlock();
5268 return D3DERR_TEXTURE_LOAD_FAILED
;
5272 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5274 /* Copy the src blit color key if the source has one, don't erase
5275 * the destination's ckey if the source has none */
5276 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5278 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5279 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5282 if (FAILED(hr
= wined3d_resource_map(src_resource
,
5283 src_surface
->sub_resource_idx
, &src_map_desc
, NULL
, 0)))
5285 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5286 wined3d_mutex_unlock();
5287 return D3DERR_TEXTURE_LOAD_FAILED
;
5290 if (FAILED(hr
= wined3d_resource_map(dst_resource
,
5291 dst_surface
->sub_resource_idx
, &dst_map_desc
, NULL
, 0)))
5293 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5294 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5295 wined3d_mutex_unlock();
5296 return D3DERR_TEXTURE_LOAD_FAILED
;
5299 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5300 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5302 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5304 wined3d_resource_unmap(dst_resource
, dst_surface
->sub_resource_idx
);
5305 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5308 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5309 src_surface
= get_sub_mimaplevel(src_surface
);
5313 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5314 dst_surface
= get_sub_mimaplevel(dst_surface
);
5318 if (!src_surface
|| !dst_surface
)
5320 if (src_surface
!= dst_surface
)
5321 ERR("Loading surface with different mipmap structure.\n");
5326 wined3d_mutex_unlock();
5331 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5333 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5334 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5336 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5338 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5339 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5342 /*****************************************************************************
5344 *****************************************************************************/
5346 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5349 ddraw_surface7_QueryInterface
,
5350 ddraw_surface7_AddRef
,
5351 ddraw_surface7_Release
,
5352 /* IDirectDrawSurface */
5353 ddraw_surface7_AddAttachedSurface
,
5354 ddraw_surface7_AddOverlayDirtyRect
,
5356 ddraw_surface7_BltBatch
,
5357 ddraw_surface7_BltFast
,
5358 ddraw_surface7_DeleteAttachedSurface
,
5359 ddraw_surface7_EnumAttachedSurfaces
,
5360 ddraw_surface7_EnumOverlayZOrders
,
5361 ddraw_surface7_Flip
,
5362 ddraw_surface7_GetAttachedSurface
,
5363 ddraw_surface7_GetBltStatus
,
5364 ddraw_surface7_GetCaps
,
5365 ddraw_surface7_GetClipper
,
5366 ddraw_surface7_GetColorKey
,
5367 ddraw_surface7_GetDC
,
5368 ddraw_surface7_GetFlipStatus
,
5369 ddraw_surface7_GetOverlayPosition
,
5370 ddraw_surface7_GetPalette
,
5371 ddraw_surface7_GetPixelFormat
,
5372 ddraw_surface7_GetSurfaceDesc
,
5373 ddraw_surface7_Initialize
,
5374 ddraw_surface7_IsLost
,
5375 ddraw_surface7_Lock
,
5376 ddraw_surface7_ReleaseDC
,
5377 ddraw_surface7_Restore
,
5378 ddraw_surface7_SetClipper
,
5379 ddraw_surface7_SetColorKey
,
5380 ddraw_surface7_SetOverlayPosition
,
5381 ddraw_surface7_SetPalette
,
5382 ddraw_surface7_Unlock
,
5383 ddraw_surface7_UpdateOverlay
,
5384 ddraw_surface7_UpdateOverlayDisplay
,
5385 ddraw_surface7_UpdateOverlayZOrder
,
5386 /* IDirectDrawSurface2 */
5387 ddraw_surface7_GetDDInterface
,
5388 ddraw_surface7_PageLock
,
5389 ddraw_surface7_PageUnlock
,
5390 /* IDirectDrawSurface3 */
5391 ddraw_surface7_SetSurfaceDesc
,
5392 /* IDirectDrawSurface4 */
5393 ddraw_surface7_SetPrivateData
,
5394 ddraw_surface7_GetPrivateData
,
5395 ddraw_surface7_FreePrivateData
,
5396 ddraw_surface7_GetUniquenessValue
,
5397 ddraw_surface7_ChangeUniquenessValue
,
5398 /* IDirectDrawSurface7 */
5399 ddraw_surface7_SetPriority
,
5400 ddraw_surface7_GetPriority
,
5401 ddraw_surface7_SetLOD
,
5402 ddraw_surface7_GetLOD
,
5405 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5408 ddraw_surface4_QueryInterface
,
5409 ddraw_surface4_AddRef
,
5410 ddraw_surface4_Release
,
5411 /* IDirectDrawSurface */
5412 ddraw_surface4_AddAttachedSurface
,
5413 ddraw_surface4_AddOverlayDirtyRect
,
5415 ddraw_surface4_BltBatch
,
5416 ddraw_surface4_BltFast
,
5417 ddraw_surface4_DeleteAttachedSurface
,
5418 ddraw_surface4_EnumAttachedSurfaces
,
5419 ddraw_surface4_EnumOverlayZOrders
,
5420 ddraw_surface4_Flip
,
5421 ddraw_surface4_GetAttachedSurface
,
5422 ddraw_surface4_GetBltStatus
,
5423 ddraw_surface4_GetCaps
,
5424 ddraw_surface4_GetClipper
,
5425 ddraw_surface4_GetColorKey
,
5426 ddraw_surface4_GetDC
,
5427 ddraw_surface4_GetFlipStatus
,
5428 ddraw_surface4_GetOverlayPosition
,
5429 ddraw_surface4_GetPalette
,
5430 ddraw_surface4_GetPixelFormat
,
5431 ddraw_surface4_GetSurfaceDesc
,
5432 ddraw_surface4_Initialize
,
5433 ddraw_surface4_IsLost
,
5434 ddraw_surface4_Lock
,
5435 ddraw_surface4_ReleaseDC
,
5436 ddraw_surface4_Restore
,
5437 ddraw_surface4_SetClipper
,
5438 ddraw_surface4_SetColorKey
,
5439 ddraw_surface4_SetOverlayPosition
,
5440 ddraw_surface4_SetPalette
,
5441 ddraw_surface4_Unlock
,
5442 ddraw_surface4_UpdateOverlay
,
5443 ddraw_surface4_UpdateOverlayDisplay
,
5444 ddraw_surface4_UpdateOverlayZOrder
,
5445 /* IDirectDrawSurface2 */
5446 ddraw_surface4_GetDDInterface
,
5447 ddraw_surface4_PageLock
,
5448 ddraw_surface4_PageUnlock
,
5449 /* IDirectDrawSurface3 */
5450 ddraw_surface4_SetSurfaceDesc
,
5451 /* IDirectDrawSurface4 */
5452 ddraw_surface4_SetPrivateData
,
5453 ddraw_surface4_GetPrivateData
,
5454 ddraw_surface4_FreePrivateData
,
5455 ddraw_surface4_GetUniquenessValue
,
5456 ddraw_surface4_ChangeUniquenessValue
,
5459 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5462 ddraw_surface3_QueryInterface
,
5463 ddraw_surface3_AddRef
,
5464 ddraw_surface3_Release
,
5465 /* IDirectDrawSurface */
5466 ddraw_surface3_AddAttachedSurface
,
5467 ddraw_surface3_AddOverlayDirtyRect
,
5469 ddraw_surface3_BltBatch
,
5470 ddraw_surface3_BltFast
,
5471 ddraw_surface3_DeleteAttachedSurface
,
5472 ddraw_surface3_EnumAttachedSurfaces
,
5473 ddraw_surface3_EnumOverlayZOrders
,
5474 ddraw_surface3_Flip
,
5475 ddraw_surface3_GetAttachedSurface
,
5476 ddraw_surface3_GetBltStatus
,
5477 ddraw_surface3_GetCaps
,
5478 ddraw_surface3_GetClipper
,
5479 ddraw_surface3_GetColorKey
,
5480 ddraw_surface3_GetDC
,
5481 ddraw_surface3_GetFlipStatus
,
5482 ddraw_surface3_GetOverlayPosition
,
5483 ddraw_surface3_GetPalette
,
5484 ddraw_surface3_GetPixelFormat
,
5485 ddraw_surface3_GetSurfaceDesc
,
5486 ddraw_surface3_Initialize
,
5487 ddraw_surface3_IsLost
,
5488 ddraw_surface3_Lock
,
5489 ddraw_surface3_ReleaseDC
,
5490 ddraw_surface3_Restore
,
5491 ddraw_surface3_SetClipper
,
5492 ddraw_surface3_SetColorKey
,
5493 ddraw_surface3_SetOverlayPosition
,
5494 ddraw_surface3_SetPalette
,
5495 ddraw_surface3_Unlock
,
5496 ddraw_surface3_UpdateOverlay
,
5497 ddraw_surface3_UpdateOverlayDisplay
,
5498 ddraw_surface3_UpdateOverlayZOrder
,
5499 /* IDirectDrawSurface2 */
5500 ddraw_surface3_GetDDInterface
,
5501 ddraw_surface3_PageLock
,
5502 ddraw_surface3_PageUnlock
,
5503 /* IDirectDrawSurface3 */
5504 ddraw_surface3_SetSurfaceDesc
,
5507 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5510 ddraw_surface2_QueryInterface
,
5511 ddraw_surface2_AddRef
,
5512 ddraw_surface2_Release
,
5513 /* IDirectDrawSurface */
5514 ddraw_surface2_AddAttachedSurface
,
5515 ddraw_surface2_AddOverlayDirtyRect
,
5517 ddraw_surface2_BltBatch
,
5518 ddraw_surface2_BltFast
,
5519 ddraw_surface2_DeleteAttachedSurface
,
5520 ddraw_surface2_EnumAttachedSurfaces
,
5521 ddraw_surface2_EnumOverlayZOrders
,
5522 ddraw_surface2_Flip
,
5523 ddraw_surface2_GetAttachedSurface
,
5524 ddraw_surface2_GetBltStatus
,
5525 ddraw_surface2_GetCaps
,
5526 ddraw_surface2_GetClipper
,
5527 ddraw_surface2_GetColorKey
,
5528 ddraw_surface2_GetDC
,
5529 ddraw_surface2_GetFlipStatus
,
5530 ddraw_surface2_GetOverlayPosition
,
5531 ddraw_surface2_GetPalette
,
5532 ddraw_surface2_GetPixelFormat
,
5533 ddraw_surface2_GetSurfaceDesc
,
5534 ddraw_surface2_Initialize
,
5535 ddraw_surface2_IsLost
,
5536 ddraw_surface2_Lock
,
5537 ddraw_surface2_ReleaseDC
,
5538 ddraw_surface2_Restore
,
5539 ddraw_surface2_SetClipper
,
5540 ddraw_surface2_SetColorKey
,
5541 ddraw_surface2_SetOverlayPosition
,
5542 ddraw_surface2_SetPalette
,
5543 ddraw_surface2_Unlock
,
5544 ddraw_surface2_UpdateOverlay
,
5545 ddraw_surface2_UpdateOverlayDisplay
,
5546 ddraw_surface2_UpdateOverlayZOrder
,
5547 /* IDirectDrawSurface2 */
5548 ddraw_surface2_GetDDInterface
,
5549 ddraw_surface2_PageLock
,
5550 ddraw_surface2_PageUnlock
,
5553 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5556 ddraw_surface1_QueryInterface
,
5557 ddraw_surface1_AddRef
,
5558 ddraw_surface1_Release
,
5559 /* IDirectDrawSurface */
5560 ddraw_surface1_AddAttachedSurface
,
5561 ddraw_surface1_AddOverlayDirtyRect
,
5563 ddraw_surface1_BltBatch
,
5564 ddraw_surface1_BltFast
,
5565 ddraw_surface1_DeleteAttachedSurface
,
5566 ddraw_surface1_EnumAttachedSurfaces
,
5567 ddraw_surface1_EnumOverlayZOrders
,
5568 ddraw_surface1_Flip
,
5569 ddraw_surface1_GetAttachedSurface
,
5570 ddraw_surface1_GetBltStatus
,
5571 ddraw_surface1_GetCaps
,
5572 ddraw_surface1_GetClipper
,
5573 ddraw_surface1_GetColorKey
,
5574 ddraw_surface1_GetDC
,
5575 ddraw_surface1_GetFlipStatus
,
5576 ddraw_surface1_GetOverlayPosition
,
5577 ddraw_surface1_GetPalette
,
5578 ddraw_surface1_GetPixelFormat
,
5579 ddraw_surface1_GetSurfaceDesc
,
5580 ddraw_surface1_Initialize
,
5581 ddraw_surface1_IsLost
,
5582 ddraw_surface1_Lock
,
5583 ddraw_surface1_ReleaseDC
,
5584 ddraw_surface1_Restore
,
5585 ddraw_surface1_SetClipper
,
5586 ddraw_surface1_SetColorKey
,
5587 ddraw_surface1_SetOverlayPosition
,
5588 ddraw_surface1_SetPalette
,
5589 ddraw_surface1_Unlock
,
5590 ddraw_surface1_UpdateOverlay
,
5591 ddraw_surface1_UpdateOverlayDisplay
,
5592 ddraw_surface1_UpdateOverlayZOrder
,
5595 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5597 ddraw_gamma_control_QueryInterface
,
5598 ddraw_gamma_control_AddRef
,
5599 ddraw_gamma_control_Release
,
5600 ddraw_gamma_control_GetGammaRamp
,
5601 ddraw_gamma_control_SetGammaRamp
,
5604 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5606 d3d_texture2_QueryInterface
,
5607 d3d_texture2_AddRef
,
5608 d3d_texture2_Release
,
5609 d3d_texture2_GetHandle
,
5610 d3d_texture2_PaletteChanged
,
5614 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5616 d3d_texture1_QueryInterface
,
5617 d3d_texture1_AddRef
,
5618 d3d_texture1_Release
,
5619 d3d_texture1_Initialize
,
5620 d3d_texture1_GetHandle
,
5621 d3d_texture1_PaletteChanged
,
5623 d3d_texture1_Unload
,
5626 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5627 * IDirectDrawSurface interface to ddraw methods. */
5628 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5630 if (!iface
) return NULL
;
5631 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5633 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5636 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5639 IDirectDrawSurface7_Release(iface
);
5641 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5644 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5646 if (!iface
) return NULL
;
5647 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5649 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5652 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5655 IDirectDrawSurface4_Release(iface
);
5657 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5660 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5662 if (!iface
) return NULL
;
5663 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5665 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5668 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5671 IDirectDrawSurface3_Release(iface
);
5673 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5676 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5678 if (!iface
) return NULL
;
5679 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5681 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5684 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5687 IDirectDrawSurface2_Release(iface
);
5689 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5692 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5694 if (!iface
) return NULL
;
5695 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5697 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5700 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5703 IDirectDrawSurface_Release(iface
);
5705 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5708 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5710 if (!iface
) return NULL
;
5711 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5712 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5715 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5717 if (!iface
) return NULL
;
5718 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5719 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5722 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5724 struct ddraw_surface
*surface
= parent
;
5726 TRACE("surface %p.\n", surface
);
5728 /* This shouldn't happen, ddraw_surface_release_iface() should prevent the
5729 * surface from being destroyed in this case. */
5730 if (surface
->first_attached
!= surface
)
5731 ERR("Surface is still attached to surface %p.\n", surface
->first_attached
);
5733 while (surface
->next_attached
)
5734 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5735 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5736 ERR("DeleteAttachedSurface failed.\n");
5738 /* Having a texture handle set implies that the device still exists. */
5739 if (surface
->Handle
)
5740 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5742 /* Reduce the ddraw surface count. */
5743 list_remove(&surface
->surface_list_entry
);
5745 if (surface
->clipper
)
5746 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5748 if (surface
== surface
->ddraw
->primary
)
5749 surface
->ddraw
->primary
= NULL
;
5751 wined3d_private_store_cleanup(&surface
->private_store
);
5753 HeapFree(GetProcessHeap(), 0, surface
);
5756 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5758 ddraw_surface_wined3d_object_destroyed
,
5761 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5763 TRACE("parent %p.\n", parent
);
5765 HeapFree(GetProcessHeap(), 0, parent
);
5768 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5770 ddraw_texture_wined3d_object_destroyed
,
5773 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5778 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5779 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5781 struct wined3d_sub_resource_desc wined3d_mip_desc
;
5782 struct ddraw_surface
*root
, *mip
, **attach
;
5783 struct wined3d_resource_desc wined3d_desc
;
5784 struct wined3d_texture
*wined3d_texture
;
5785 struct wined3d_display_mode mode
;
5786 DDSURFACEDESC2
*desc
, *mip_desc
;
5787 struct ddraw_texture
*texture
;
5788 unsigned int layers
= 1;
5789 unsigned int pitch
= 0;
5793 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5794 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5795 if (TRACE_ON(ddraw
))
5797 TRACE("Requesting surface desc:\n");
5798 DDRAW_dump_surface_desc(surface_desc
);
5802 return CLASS_E_NOAGGREGATION
;
5807 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5808 return E_OUTOFMEMORY
;
5810 texture
->version
= version
;
5811 texture
->surface_desc
= *surface_desc
;
5812 desc
= &texture
->surface_desc
;
5814 /* Ensure DDSD_CAPS is always set. */
5815 desc
->dwFlags
|= DDSD_CAPS
;
5817 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5819 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5821 WARN("Tried to create a flippable surface without any back buffers.\n");
5822 HeapFree(GetProcessHeap(), 0, texture
);
5823 return DDERR_INVALIDCAPS
;
5826 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
))
5828 WARN("Tried to create a flippable surface without DDSCAPS_COMPLEX.\n");
5829 HeapFree(GetProcessHeap(), 0, texture
);
5830 return DDERR_INVALIDCAPS
;
5833 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5835 WARN("Tried to create a flippable cubemap.\n");
5836 HeapFree(GetProcessHeap(), 0, texture
);
5837 return DDERR_INVALIDPARAMS
;
5840 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5842 FIXME("Flippable textures not implemented.\n");
5843 HeapFree(GetProcessHeap(), 0, texture
);
5844 return DDERR_INVALIDCAPS
;
5849 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
5851 WARN("Tried to specify a back buffer count for a non-flippable surface.\n");
5852 hr
= desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
? DDERR_INVALIDPARAMS
: DDERR_INVALIDCAPS
;
5853 HeapFree(GetProcessHeap(), 0, texture
);
5858 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5860 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5862 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5863 HeapFree(GetProcessHeap(), 0, texture
);
5864 return DDERR_INVALIDCAPS
;
5867 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
))
5869 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5870 HeapFree(GetProcessHeap(), 0, texture
);
5871 return DDERR_INVALIDCAPS
;
5874 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
) && !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5876 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5877 HeapFree(GetProcessHeap(), 0, texture
);
5878 return DDERR_NOEXCLUSIVEMODE
;
5882 /* This is a special case in ddrawex, but not allowed in ddraw. */
5883 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5884 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5886 WARN("Tried to create a surface in both system and video memory.\n");
5887 HeapFree(GetProcessHeap(), 0, texture
);
5888 return DDERR_INVALIDCAPS
;
5891 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
5892 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5894 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
5895 HeapFree(GetProcessHeap(), 0, texture
);
5896 return DDERR_INVALIDCAPS
;
5899 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5900 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5902 WARN("Cube map faces requested without cube map flag.\n");
5903 HeapFree(GetProcessHeap(), 0, texture
);
5904 return DDERR_INVALIDCAPS
;
5907 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5908 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5910 WARN("Cube map without faces requested.\n");
5911 HeapFree(GetProcessHeap(), 0, texture
);
5912 return DDERR_INVALIDPARAMS
;
5915 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5916 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5917 FIXME("Partial cube maps not implemented.\n");
5919 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5921 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5923 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5924 HeapFree(GetProcessHeap(), 0, texture
);
5925 return DDERR_INVALIDCAPS
;
5927 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5929 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5930 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5931 HeapFree(GetProcessHeap(), 0, texture
);
5932 return DDERR_INVALIDCAPS
;
5936 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5938 ERR("Failed to get display mode, hr %#x.\n", hr
);
5939 HeapFree(GetProcessHeap(), 0, texture
);
5940 return hr_ddraw_from_wined3d(hr
);
5943 /* No pixelformat given? Use the current screen format. */
5944 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5946 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5947 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5948 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5951 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
5952 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5953 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5955 WARN("Unsupported / unknown pixelformat.\n");
5956 HeapFree(GetProcessHeap(), 0, texture
);
5957 return DDERR_INVALIDPIXELFORMAT
;
5960 /* No width or no height? Use the screen size. */
5961 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5963 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5965 WARN("No width / height specified.\n");
5966 HeapFree(GetProcessHeap(), 0, texture
);
5967 return DDERR_INVALIDPARAMS
;
5970 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5971 desc
->dwWidth
= mode
.width
;
5972 desc
->dwHeight
= mode
.height
;
5975 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5977 HeapFree(GetProcessHeap(), 0, texture
);
5978 return DDERR_INVALIDPARAMS
;
5981 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5982 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5984 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5986 /* The first surface is a front buffer, the back buffers are created
5988 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5989 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5991 struct wined3d_swapchain_desc swapchain_desc
;
5993 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5994 swapchain_desc
.backbuffer_width
= mode
.width
;
5995 swapchain_desc
.backbuffer_height
= mode
.height
;
5996 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5998 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5999 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
6001 ERR("Failed to reset device.\n");
6002 HeapFree(GetProcessHeap(), 0, texture
);
6003 return hr_ddraw_from_wined3d(hr
);
6008 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
6009 wined3d_desc
.multisample_quality
= 0;
6010 wined3d_desc
.usage
= 0;
6011 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
6012 wined3d_desc
.width
= desc
->dwWidth
;
6013 wined3d_desc
.height
= desc
->dwHeight
;
6014 wined3d_desc
.depth
= 1;
6015 wined3d_desc
.size
= 0;
6017 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
6019 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
6020 /* Do not fail surface creation, only fail 3D device creation. */
6023 /* Mipmap count fixes */
6024 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
6026 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
6028 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
6030 /* Mipmap count is given, should not be 0. */
6031 if (!desc
->u2
.dwMipMapCount
)
6033 HeapFree(GetProcessHeap(), 0, texture
);
6034 return DDERR_INVALIDPARAMS
;
6039 /* Undocumented feature: Create sublevels until either the
6040 * width or the height is 1. */
6042 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
6044 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
6049 desc
->u2
.dwMipMapCount
= 1;
6052 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
6053 levels
= desc
->u2
.dwMipMapCount
;
6060 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
6062 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
6066 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6067 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
| WINED3DUSAGE_TEXTURE
;
6068 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6069 usage
|= WINED3DUSAGE_TEXTURE
;
6071 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6072 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
6073 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6074 usage
= WINED3DUSAGE_RENDERTARGET
;
6076 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6077 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, WINED3D_RTYPE_TEXTURE_2D
, wined3d_desc
.format
)))
6078 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
6080 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6082 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
6084 /* Tests show surfaces without memory flags get these flags added
6085 * right after creation. */
6086 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
6090 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
6091 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
6093 WARN("System memory overlays are not allowed.\n");
6094 HeapFree(GetProcessHeap(), 0, texture
);
6095 return DDERR_NOOVERLAYHW
;
6098 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
6100 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
6104 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6105 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
6106 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6107 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
6108 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6109 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
6111 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
6113 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
6114 /* Managed textures have the system memory flag set. */
6115 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6117 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
6119 /* Videomemory adds localvidmem. This is mutually exclusive with
6120 * systemmemory and texturemanage. */
6121 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
6122 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
6126 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6128 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
6130 WARN("User memory surfaces should be in the system memory pool.\n");
6131 HeapFree(GetProcessHeap(), 0, texture
);
6132 return DDERR_INVALIDCAPS
;
6137 WARN("User memory surfaces not supported before version 4.\n");
6138 HeapFree(GetProcessHeap(), 0, texture
);
6139 return DDERR_INVALIDPARAMS
;
6142 if (!desc
->lpSurface
)
6144 WARN("NULL surface memory pointer specified.\n");
6145 HeapFree(GetProcessHeap(), 0, texture
);
6146 return DDERR_INVALIDPARAMS
;
6149 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6151 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6153 WARN("Pitch specified on a compressed user memory surface.\n");
6154 HeapFree(GetProcessHeap(), 0, texture
);
6155 return DDERR_INVALIDPARAMS
;
6158 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6160 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6161 HeapFree(GetProcessHeap(), 0, texture
);
6162 return DDERR_INVALIDPARAMS
;
6165 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6166 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6167 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6169 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6170 HeapFree(GetProcessHeap(), 0, texture
);
6171 return DDERR_INVALIDPARAMS
;
6176 if (!(desc
->dwFlags
& DDSD_PITCH
))
6178 WARN("User memory surfaces should explicitly specify the pitch.\n");
6179 HeapFree(GetProcessHeap(), 0, texture
);
6180 return DDERR_INVALIDPARAMS
;
6183 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6184 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6186 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6187 HeapFree(GetProcessHeap(), 0, texture
);
6188 return DDERR_INVALIDPARAMS
;
6191 pitch
= desc
->u1
.lPitch
;
6195 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6196 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6197 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6198 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6199 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6200 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6201 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6202 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6204 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6205 HeapFree(GetProcessHeap(), 0, texture
);
6206 return DDERR_NOCOLORKEYHW
;
6209 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6210 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6212 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6213 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6215 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6217 wined3d_desc
.usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6221 /* Some applications assume surfaces will always be mapped at the same
6222 * address. Some of those also assume that this address is valid even when
6223 * the surface isn't mapped, and that updates done this way will be
6224 * visible on the screen. The game Nox is such an application,
6225 * Commandos: Behind Enemy Lines is another. Setting
6226 * WINED3D_TEXTURE_CREATE_GET_DC_LENIENT will ensure this. */
6227 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, layers
, levels
,
6228 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
,
6229 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6231 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6232 HeapFree(GetProcessHeap(), 0, texture
);
6233 return hr_ddraw_from_wined3d(hr
);
6236 root
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6237 wined3d_texture_decref(wined3d_texture
);
6238 root
->is_complex_root
= TRUE
;
6239 texture
->root
= root
;
6240 wined3d_device_incref(texture
->wined3d_device
= ddraw
->wined3d_device
);
6242 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6243 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6244 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6245 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6246 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6247 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6248 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6249 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6250 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6251 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6252 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6253 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6255 for (i
= 0; i
< layers
; ++i
)
6257 attach
= &root
->complex_array
[layers
- 1 - i
];
6259 for (j
= 0; j
< levels
; ++j
)
6261 mip
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, i
* levels
+ j
);
6262 mip_desc
= &mip
->surface_desc
;
6266 wined3d_texture_get_sub_resource_desc(wined3d_texture
, i
* levels
+ j
, &wined3d_mip_desc
);
6267 mip_desc
->dwWidth
= wined3d_mip_desc
.width
;
6268 mip_desc
->dwHeight
= wined3d_mip_desc
.height
;
6270 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6274 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6277 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6279 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6283 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6284 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6286 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6287 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6289 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6290 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6292 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6293 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6295 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6296 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6298 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6299 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6309 attach
= &mip
->complex_array
[0];
6313 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6314 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6315 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6317 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6321 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6323 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6324 struct ddraw_surface
*last
= root
;
6326 attach
= &last
->complex_array
[0];
6327 for (i
= 0; i
< count
; ++i
)
6329 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6335 texture
->version
= version
;
6336 texture
->surface_desc
= root
->surface_desc
;
6337 desc
= &texture
->surface_desc
;
6339 /* Only one surface in the flipping chain is a back buffer, one is
6340 * a front buffer, the others are just flippable surfaces. */
6341 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6342 | DDSCAPS_BACKBUFFER
);
6344 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6345 desc
->u5
.dwBackBufferCount
= 0;
6347 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1, 1,
6348 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
,
6349 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6351 HeapFree(GetProcessHeap(), 0, texture
);
6352 hr
= hr_ddraw_from_wined3d(hr
);
6356 last
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6357 wined3d_texture_decref(wined3d_texture
);
6358 texture
->root
= last
;
6359 wined3d_device_incref(texture
->wined3d_device
= ddraw
->wined3d_device
);
6361 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6362 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6363 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6364 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6365 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6366 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6367 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6368 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6369 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6370 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6371 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6372 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6375 attach
= &last
->complex_array
[0];
6380 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6381 ddraw
->primary
= root
;
6388 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6389 else if (version
== 4)
6390 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6392 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6397 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
6398 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
6399 const struct wined3d_parent_ops
**parent_ops
)
6401 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
6402 unsigned int texture_level
, row_pitch
, slice_pitch
;
6403 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6404 unsigned int version
= texture
->version
;
6406 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6407 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6408 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6409 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6410 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6411 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6412 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6413 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6414 surface
->iface_count
= 1;
6415 surface
->version
= version
;
6416 surface
->ddraw
= ddraw
;
6421 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6423 else if (version
== 4)
6426 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6431 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6434 *desc
= texture
->surface_desc
;
6435 surface
->first_attached
= surface
;
6437 texture_level
= desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
? sub_resource_idx
% desc
->u2
.dwMipMapCount
: 0;
6438 wined3d_texture_get_pitch(wined3d_texture
, texture_level
, &row_pitch
, &slice_pitch
);
6439 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6441 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6442 desc
->u1
.dwLinearSize
= ~0u;
6444 desc
->u1
.dwLinearSize
= slice_pitch
;
6445 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6446 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6450 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6451 desc
->u1
.lPitch
= row_pitch
;
6452 desc
->dwFlags
|= DDSD_PITCH
;
6453 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6455 desc
->lpSurface
= NULL
;
6457 wined3d_texture_incref(surface
->wined3d_texture
= wined3d_texture
);
6458 surface
->sub_resource_idx
= sub_resource_idx
;
6459 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6461 wined3d_private_store_init(&surface
->private_store
);
6464 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6466 struct ddraw_surface
*surface
= parent
;
6468 /* If the surface reference count drops to zero, we release our reference
6469 * to the view, but don't clear the pointer yet, in case e.g. a
6470 * GetRenderTarget() call brings the surface back before the view is
6471 * actually destroyed. When the view is destroyed, we need to clear the
6472 * pointer, or a subsequent surface AddRef() would reference it again.
6474 * This is safe because as long as the view still has a reference to the
6475 * texture, the surface is also still alive, and we're called before the
6476 * view releases that reference. */
6477 surface
->wined3d_rtv
= NULL
;
6480 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6482 view_wined3d_object_destroyed
,
6485 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6489 if (surface
->wined3d_rtv
)
6490 return surface
->wined3d_rtv
;
6492 if (FAILED(hr
= wined3d_rendertarget_view_create_from_sub_resource(surface
->wined3d_texture
,
6493 surface
->sub_resource_idx
, surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6495 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6499 return surface
->wined3d_rtv
;