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 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 box
.left
= rect
->left
;
990 box
.right
= rect
->right
;
991 box
.bottom
= rect
->bottom
;
996 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
997 hr
= ddraw_surface_update_frontbuffer(surface
, rect
, TRUE
);
999 hr
= wined3d_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
),
1000 surface
->sub_resource_idx
, &map_desc
, rect
? &box
: NULL
, flags
);
1003 wined3d_mutex_unlock();
1006 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
1007 * specific error. But since wined3d returns that error in this only occasion,
1008 * keep d3d8 and d3d9 free from the return value override. There are many different
1009 * places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it is much easier
1010 * to do it in one place in ddraw.
1012 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1017 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1019 if (flags
& DDLOCK_READONLY
)
1020 SetRectEmpty(&surface
->ddraw
->primary_lock
);
1022 surface
->ddraw
->primary_lock
= *rect
;
1024 SetRect(&surface
->ddraw
->primary_lock
, 0, 0, surface
->surface_desc
.dwWidth
, surface
->surface_desc
.dwHeight
);
1027 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1028 DD_STRUCT_COPY_BYSIZE_(surface_desc
, &surface
->surface_desc
, surface_desc_size
, surface
->surface_desc
.dwSize
);
1029 surface_desc
->lpSurface
= map_desc
.data
;
1031 TRACE("locked surface returning description :\n");
1032 if (TRACE_ON(ddraw
))
1033 DDRAW_dump_surface_desc(surface_desc
);
1035 wined3d_mutex_unlock();
1040 static BOOL
surface_validate_lock_desc(struct ddraw_surface
*surface
,
1041 const DDSURFACEDESC
*desc
, unsigned int *size
)
1046 if (desc
->dwSize
== sizeof(DDSURFACEDESC
) || desc
->dwSize
== sizeof(DDSURFACEDESC2
))
1048 *size
= desc
->dwSize
;
1052 if (surface
->version
== 7
1053 && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
1054 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1056 if (desc
->dwSize
>= sizeof(DDSURFACEDESC2
))
1057 *size
= sizeof(DDSURFACEDESC2
);
1059 *size
= sizeof(DDSURFACEDESC
);
1063 WARN("Invalid structure size %u.\n", desc
->dwSize
);
1067 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1068 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1070 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1071 unsigned int surface_desc_size
;
1073 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1074 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1076 if (!surface_validate_lock_desc(surface
, (DDSURFACEDESC
*)surface_desc
, &surface_desc_size
))
1077 return DDERR_INVALIDPARAMS
;
1079 return surface_lock(surface
, rect
, surface_desc
, surface_desc_size
, flags
, h
);
1082 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1083 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1085 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1086 unsigned int surface_desc_size
;
1088 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1089 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1091 if (!surface_validate_lock_desc(surface
, (DDSURFACEDESC
*)surface_desc
, &surface_desc_size
))
1092 return DDERR_INVALIDPARAMS
;
1094 return surface_lock(surface
, rect
, surface_desc
, surface_desc_size
, flags
, h
);
1097 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1098 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1101 unsigned int surface_desc_size
;
1102 DDSURFACEDESC2 surface_desc2
;
1105 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1106 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1108 if (!surface_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1109 return DDERR_INVALIDPARAMS
;
1111 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1112 surface_desc2
.dwFlags
= 0;
1113 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1114 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1115 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1119 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1120 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1122 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1123 unsigned int surface_desc_size
;
1124 DDSURFACEDESC2 surface_desc2
;
1127 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1128 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1130 if (!surface_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1131 return DDERR_INVALIDPARAMS
;
1133 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1134 surface_desc2
.dwFlags
= 0;
1135 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1136 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1137 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1141 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1142 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1144 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1145 unsigned int surface_desc_size
;
1146 DDSURFACEDESC2 surface_desc2
;
1149 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1150 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1152 if (!surface_validate_lock_desc(surface
, surface_desc
, &surface_desc_size
))
1153 return DDERR_INVALIDPARAMS
;
1155 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1156 surface_desc2
.dwFlags
= 0;
1157 hr
= surface_lock(surface
, rect
, &surface_desc2
, surface_desc_size
, flags
, h
);
1158 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1159 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1163 /*****************************************************************************
1164 * IDirectDrawSurface7::Unlock
1166 * Unlocks an locked surface
1169 * Rect: Not used by this implementation
1172 * D3D_OK on success, error code otherwise.
1174 *****************************************************************************/
1175 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1177 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1180 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1182 wined3d_mutex_lock();
1183 hr
= wined3d_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), surface
->sub_resource_idx
);
1184 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1185 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1186 wined3d_mutex_unlock();
1191 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1193 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1195 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1197 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1200 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1202 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1204 TRACE("iface %p, data %p.\n", iface
, data
);
1206 /* data might not be the LPRECT of later versions, so drop it. */
1207 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1210 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1212 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1214 TRACE("iface %p, data %p.\n", iface
, data
);
1216 /* data might not be the LPRECT of later versions, so drop it. */
1217 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1220 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1222 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1224 TRACE("iface %p, data %p.\n", iface
, data
);
1226 /* data might not be the LPRECT of later versions, so drop it. */
1227 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1230 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1231 IDirectDrawSurface7
*src
, DWORD flags
)
1233 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1234 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1235 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1236 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1237 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1238 struct wined3d_texture
*texture
;
1239 IDirectDrawSurface7
*current
;
1242 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1244 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1245 return DDERR_NOTFLIPPABLE
;
1247 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1248 return DDERR_SURFACELOST
;
1250 wined3d_mutex_lock();
1252 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1253 && !(dst_impl
->ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
1255 WARN("Not in exclusive mode.\n");
1256 wined3d_mutex_unlock();
1257 return DDERR_NOEXCLUSIVEMODE
;
1260 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1261 if (dst_impl
->sub_resource_idx
)
1262 ERR("Invalid sub-resource index %u on surface %p.\n", dst_impl
->sub_resource_idx
, dst_impl
);
1263 texture
= dst_impl
->wined3d_texture
;
1264 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1265 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1269 for (current
= iface
; current
!= src
;)
1271 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1273 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1274 wined3d_mutex_unlock();
1275 return DDERR_NOTFLIPPABLE
;
1277 ddraw_surface7_Release(current
);
1278 if (current
== iface
)
1280 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1281 wined3d_mutex_unlock();
1282 return DDERR_NOTFLIPPABLE
;
1286 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1287 if (rtv
== dst_impl
->wined3d_rtv
)
1288 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1289 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1290 dst_impl
->wined3d_rtv
= src_rtv
;
1291 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1292 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1293 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1294 if (src_impl
->sub_resource_idx
)
1295 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1296 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1297 ddraw_texture
= prev_ddraw_texture
;
1301 for (current
= iface
;;)
1303 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1305 ERR("Can't find a flip target\n");
1306 wined3d_mutex_unlock();
1307 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1309 ddraw_surface7_Release(current
);
1310 if (current
== iface
)
1312 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1316 src_impl
= impl_from_IDirectDrawSurface7(current
);
1317 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1318 if (rtv
== dst_impl
->wined3d_rtv
)
1319 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1320 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1321 dst_impl
->wined3d_rtv
= src_rtv
;
1322 wined3d_texture_set_sub_resource_parent(src_impl
->wined3d_texture
, 0, dst_impl
);
1323 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1324 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1325 ddraw_texture
= prev_ddraw_texture
;
1326 if (src_impl
->sub_resource_idx
)
1327 ERR("Invalid sub-resource index %u on surface %p.\n", src_impl
->sub_resource_idx
, src_impl
);
1328 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1329 dst_impl
= src_impl
;
1333 /* We don't have to worry about potential texture bindings, since
1334 * flippable surfaces can never be textures. */
1335 if (rtv
== src_impl
->wined3d_rtv
)
1336 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1337 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1338 src_impl
->wined3d_rtv
= tmp_rtv
;
1339 wined3d_texture_set_sub_resource_parent(texture
, 0, src_impl
);
1340 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1341 src_impl
->wined3d_texture
= texture
;
1347 FIXME("Ignoring flags %#x.\n", flags
);
1349 WARN("Ignoring flags %#x.\n", flags
);
1352 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1353 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1357 wined3d_mutex_unlock();
1362 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1363 IDirectDrawSurface4
*src
, DWORD flags
)
1365 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1366 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
1368 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1370 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1371 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1374 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1375 IDirectDrawSurface3
*src
, DWORD flags
)
1377 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1378 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src
);
1380 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1382 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1383 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1386 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1387 IDirectDrawSurface2
*src
, DWORD flags
)
1389 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1390 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src
);
1392 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1394 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1395 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1398 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1399 IDirectDrawSurface
*src
, DWORD flags
)
1401 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1402 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
1404 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1406 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1407 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1410 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1411 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1412 const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
1414 struct wined3d_texture
*wined3d_src_texture
;
1415 unsigned int src_sub_resource_idx
;
1416 RECT src_rect
, dst_rect
;
1417 float scale_x
, scale_y
;
1418 const RECT
*clip_rect
;
1419 UINT clip_list_size
;
1425 SetRect(&dst_rect
, 0, 0, dst_surface
->surface_desc
.dwWidth
,
1426 dst_surface
->surface_desc
.dwHeight
);
1428 dst_rect
= *dst_rect_in
;
1430 if (IsRectEmpty(&dst_rect
))
1431 return DDERR_INVALIDRECT
;
1436 SetRect(&src_rect
, 0, 0, src_surface
->surface_desc
.dwWidth
,
1437 src_surface
->surface_desc
.dwHeight
);
1439 src_rect
= *src_rect_in
;
1441 if (IsRectEmpty(&src_rect
))
1442 return DDERR_INVALIDRECT
;
1444 wined3d_src_texture
= src_surface
->wined3d_texture
;
1445 src_sub_resource_idx
= src_surface
->sub_resource_idx
;
1449 SetRectEmpty(&src_rect
);
1450 wined3d_src_texture
= NULL
;
1451 src_sub_resource_idx
= 0;
1454 if (!dst_surface
->clipper
)
1456 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1457 hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect
, TRUE
);
1459 hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
, &dst_rect
,
1460 wined3d_src_texture
, src_sub_resource_idx
, &src_rect
, flags
, fx
, filter
);
1461 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1462 hr
= ddraw_surface_update_frontbuffer(dst_surface
, &dst_rect
, FALSE
);
1467 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1468 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1470 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1471 &dst_rect
, NULL
, &clip_list_size
)))
1473 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1477 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1479 WARN("Failed to allocate clip list.\n");
1480 return E_OUTOFMEMORY
;
1483 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1484 &dst_rect
, clip_list
, &clip_list_size
)))
1486 WARN("Failed to get clip list, hr %#x.\n", hr
);
1487 HeapFree(GetProcessHeap(), 0, clip_list
);
1491 clip_rect
= (RECT
*)clip_list
->Buffer
;
1492 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1494 RECT src_rect_clipped
= src_rect
;
1498 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1499 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1500 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1501 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1503 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1505 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1510 if (FAILED(hr
= wined3d_texture_blt(dst_surface
->wined3d_texture
, dst_surface
->sub_resource_idx
,
1511 &clip_rect
[i
], wined3d_src_texture
, src_sub_resource_idx
, &src_rect_clipped
, flags
, fx
, filter
)))
1514 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1516 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1521 HeapFree(GetProcessHeap(), 0, clip_list
);
1525 /*****************************************************************************
1526 * IDirectDrawSurface7::Blt
1528 * Performs a blit on the surface
1531 * DestRect: Destination rectangle, can be NULL
1532 * SrcSurface: Source surface, can be NULL
1533 * SrcRect: Source rectangle, can be NULL
1535 * DDBltFx: Some extended blt parameters, connected to the flags
1538 * D3D_OK on success, error code otherwise.
1540 *****************************************************************************/
1541 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*dst_rect
,
1542 IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1544 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1545 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
1546 struct wined3d_blt_fx wined3d_fx
;
1550 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1551 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1553 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1554 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1556 if ((flags
& DDBLT_KEYSRCOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYSRC
))
1558 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1559 return DDERR_INVALIDPARAMS
;
1562 if ((flags
& DDBLT_KEYDESTOVERRIDE
) && (!fx
|| flags
& DDBLT_KEYDEST
))
1564 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1565 return DDERR_INVALIDPARAMS
;
1568 if (flags
& DDBLT_DDROPS
)
1570 FIXME("DDBLT_DDROPS not implemented.\n");
1572 FIXME(" rop %#x, pattern %p.\n", fx
->dwDDROP
, fx
->u5
.lpDDSPattern
);
1573 return DDERR_NORASTEROPHW
;
1576 wined3d_mutex_lock();
1578 if (flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1580 if (flags
& DDBLT_ROP
)
1582 wined3d_mutex_unlock();
1583 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1584 return DDERR_INVALIDPARAMS
;
1588 wined3d_mutex_unlock();
1589 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1590 return DDERR_INVALIDPARAMS
;
1594 wined3d_mutex_unlock();
1595 WARN("Depth or colorfill used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1596 return DDERR_INVALIDPARAMS
;
1599 if ((flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1600 flags
&= ~DDBLT_DEPTHFILL
;
1602 if ((dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_COLORFILL
))
1604 wined3d_mutex_unlock();
1605 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1606 return DDERR_INVALIDPARAMS
;
1608 if (!(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (flags
& DDBLT_DEPTHFILL
))
1610 wined3d_mutex_unlock();
1611 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1612 return DDERR_INVALIDPARAMS
;
1616 if (flags
& DDBLT_ROP
)
1620 wined3d_mutex_unlock();
1621 WARN("DDBLT_ROP used with NULL fx, returning DDERR_INVALIDPARAMS.\n");
1622 return DDERR_INVALIDPARAMS
;
1625 flags
&= ~DDBLT_ROP
;
1635 if (fx
->dwROP
== WHITENESS
)
1636 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1638 rop_fx
.u5
.dwFillColor
= 0;
1640 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1641 flags
|= DDBLT_DEPTHFILL
;
1643 flags
|= DDBLT_COLORFILL
;
1649 wined3d_mutex_unlock();
1650 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", fx
->dwROP
);
1651 return DDERR_NORASTEROPHW
;
1655 if (flags
& DDBLT_KEYSRC
&& (!src_impl
|| !(src_impl
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1657 WARN("DDBLT_KEYSRC blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1658 wined3d_mutex_unlock();
1659 return DDERR_INVALIDPARAMS
;
1661 if (flags
& DDBLT_KEYDEST
&& !(dst_impl
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1663 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1664 wined3d_mutex_unlock();
1665 return DDERR_INVALIDPARAMS
;
1668 if (flags
& ~WINED3D_BLT_MASK
)
1670 wined3d_mutex_unlock();
1671 FIXME("Unhandled flags %#x.\n", flags
);
1677 wined3d_fx
.fx
= fx
->dwDDFX
;
1678 wined3d_fx
.fill_color
= fx
->u5
.dwFillColor
;
1679 wined3d_fx
.dst_color_key
.color_space_low_value
= fx
->ddckDestColorkey
.dwColorSpaceLowValue
;
1680 wined3d_fx
.dst_color_key
.color_space_high_value
= fx
->ddckDestColorkey
.dwColorSpaceHighValue
;
1681 wined3d_fx
.src_color_key
.color_space_low_value
= fx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
1682 wined3d_fx
.src_color_key
.color_space_high_value
= fx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
1685 hr
= ddraw_surface_blt_clipped(dst_impl
, dst_rect
, src_impl
,
1686 src_rect
, flags
, fx
? &wined3d_fx
: NULL
, WINED3D_TEXF_LINEAR
);
1688 wined3d_mutex_unlock();
1691 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1696 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1697 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1699 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1700 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1702 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1703 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1705 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1706 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1709 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1710 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1712 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1713 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1715 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1716 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1718 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1719 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1722 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1723 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1725 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1726 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1728 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1729 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1731 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1732 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1735 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1736 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1738 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1739 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1741 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1742 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1744 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1745 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1748 /*****************************************************************************
1749 * IDirectDrawSurface7::AddAttachedSurface
1751 * Attaches a surface to another surface. How the surface attachments work
1752 * is not totally understood yet, and this method is prone to problems.
1753 * The surface that is attached is AddRef-ed.
1755 * Tests with complex surfaces suggest that the surface attachments form a
1756 * tree, but no method to test this has been found yet.
1758 * The attachment list consists of a first surface (first_attached) and
1759 * for each surface a pointer to the next attached surface (next_attached).
1760 * For the first surface, and a surface that has no attachments
1761 * first_attached points to the surface itself. A surface that has
1762 * no successors in the chain has next_attached set to NULL.
1764 * Newly attached surfaces are attached right after the root surface.
1765 * If a surface is attached to a complex surface compound, it's attached to
1766 * the surface that the app requested, not the complex root. See
1767 * GetAttachedSurface for a description how surfaces are found.
1769 * This is how the current implementation works, and it was coded by looking
1770 * at the needs of the applications.
1772 * So far only Z-Buffer attachments are tested, and they are activated in
1773 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1774 * Back buffers should work in 2D mode, but they are not tested(They can be
1775 * attached in older iface versions). Rendering to the front buffer and
1776 * switching between that and double buffering is not yet implemented in
1777 * WineD3D, so for 3D it might have unexpected results.
1779 * ddraw_surface_attach_surface is the real thing,
1780 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1781 * performs additional checks. Version 7 of this interface is much more restrictive
1782 * than its predecessors.
1785 * Attach: Surface to attach to iface
1789 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1791 *****************************************************************************/
1792 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1794 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1797 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1799 wined3d_mutex_lock();
1801 /* Check if the surface is already attached somewhere */
1802 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1804 /* TODO: Test for the structure of the manual attachment. Is it a
1805 * chain or a list? What happens if one surface is attached to 2
1806 * different surfaces? */
1807 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1808 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1810 wined3d_mutex_unlock();
1811 return DDERR_SURFACEALREADYATTACHED
;
1814 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1815 Surf
->next_attached
= This
->next_attached
;
1816 Surf
->first_attached
= This
->first_attached
;
1817 This
->next_attached
= Surf
;
1819 /* Check if the WineD3D depth stencil needs updating */
1820 if (This
->ddraw
->d3ddevice
)
1821 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1823 wined3d_mutex_unlock();
1828 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1830 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1831 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1834 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1836 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1837 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1840 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1841 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1842 return DDERR_CANNOTATTACHSURFACE
;
1845 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1850 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1851 IUnknown_AddRef(attachment_impl
->attached_iface
);
1855 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1857 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1858 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1861 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1863 /* Tests suggest that
1864 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1865 * -> offscreen plain surfaces can be attached to primaries
1866 * -> primaries can be attached to offscreen plain surfaces
1867 * -> z buffers can be attached to primaries */
1868 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1869 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1871 /* Sizes have to match */
1872 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1873 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1875 WARN("Surface sizes do not match.\n");
1876 return DDERR_CANNOTATTACHSURFACE
;
1879 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1880 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1882 WARN("Invalid attachment combination.\n");
1883 return DDERR_CANNOTATTACHSURFACE
;
1886 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1889 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1890 IUnknown_AddRef(attachment_impl
->attached_iface
);
1894 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1896 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1897 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1900 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1902 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1903 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1906 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1907 IUnknown_AddRef(attachment_impl
->attached_iface
);
1908 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1912 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1914 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1915 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1918 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1920 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1921 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1924 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1925 IUnknown_AddRef(attachment_impl
->attached_iface
);
1926 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1930 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1932 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1933 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1936 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1938 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1939 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1942 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1943 IUnknown_AddRef(attachment_impl
->attached_iface
);
1944 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1948 /*****************************************************************************
1949 * IDirectDrawSurface7::DeleteAttachedSurface
1951 * Removes a surface from the attachment chain. The surface's refcount
1952 * is decreased by one after it has been removed
1955 * Flags: Some flags, not used by this implementation
1956 * Attach: Surface to detach
1960 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1962 *****************************************************************************/
1963 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1964 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1966 struct ddraw_surface
*prev
= surface
;
1968 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1970 wined3d_mutex_lock();
1971 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1973 wined3d_mutex_unlock();
1974 return DDERR_CANNOTDETACHSURFACE
;
1977 if (attachment
->attached_iface
!= detach_iface
)
1979 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1980 wined3d_mutex_unlock();
1981 return DDERR_SURFACENOTATTACHED
;
1984 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1985 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1987 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1988 /* FIXME: we should probably also subtract from dwMipMapCount of this
1989 * and all parent surfaces */
1992 /* Find the predecessor of the detached surface */
1993 while (prev
->next_attached
!= attachment
)
1995 if (!(prev
= prev
->next_attached
))
1997 ERR("Failed to find predecessor of %p.\n", attachment
);
1998 wined3d_mutex_unlock();
1999 return DDERR_SURFACENOTATTACHED
;
2003 /* Unchain the surface */
2004 prev
->next_attached
= attachment
->next_attached
;
2005 attachment
->next_attached
= NULL
;
2006 attachment
->first_attached
= attachment
;
2008 /* Check if the wined3d depth stencil needs updating. Note that we don't
2009 * just call d3d_device_update_depth_stencil() here since it uses
2010 * QueryInterface(). Some applications, SCP - Containment Breach in
2011 * particular, modify the QueryInterface() pointer in the surface vtbl
2012 * but don't cleanup properly after the relevant dll is unloaded. */
2013 if (attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
2014 && wined3d_device_get_depth_stencil_view(surface
->ddraw
->wined3d_device
) == surface
->wined3d_rtv
)
2015 wined3d_device_set_depth_stencil_view(surface
->ddraw
->wined3d_device
, NULL
);
2016 wined3d_mutex_unlock();
2018 /* Set attached_iface to NULL before releasing it, the surface may go
2020 attachment
->attached_iface
= NULL
;
2021 IUnknown_Release(detach_iface
);
2026 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
2027 DWORD flags
, IDirectDrawSurface7
*attachment
)
2029 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2030 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
2032 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2034 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2037 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
2038 DWORD flags
, IDirectDrawSurface4
*attachment
)
2040 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2041 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
2043 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2045 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2048 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
2049 DWORD flags
, IDirectDrawSurface3
*attachment
)
2051 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2052 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2054 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2056 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2059 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2060 DWORD flags
, IDirectDrawSurface2
*attachment
)
2062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2063 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2065 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2067 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2070 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2071 DWORD flags
, IDirectDrawSurface
*attachment
)
2073 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2074 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2076 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2078 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2081 /*****************************************************************************
2082 * IDirectDrawSurface7::AddOverlayDirtyRect
2084 * "This method is not currently implemented"
2092 *****************************************************************************/
2093 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2095 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2097 return DDERR_UNSUPPORTED
; /* unchecked */
2100 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2102 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2104 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2106 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2109 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2111 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2113 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2115 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2118 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2120 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2122 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2124 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2127 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2129 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2131 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2133 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2136 /*****************************************************************************
2137 * IDirectDrawSurface7::GetDC
2139 * Returns a GDI device context for the surface
2142 * hdc: Address of a HDC variable to store the dc to
2146 * DDERR_INVALIDPARAMS if hdc is NULL
2148 *****************************************************************************/
2149 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*dc
)
2151 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2154 TRACE("iface %p, dc %p.\n", iface
, dc
);
2157 return DDERR_INVALIDPARAMS
;
2159 wined3d_mutex_lock();
2161 hr
= DDERR_DCALREADYCREATED
;
2162 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2163 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2165 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, dc
);
2171 if (format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2173 const struct ddraw_palette
*palette
;
2175 if (surface
->palette
)
2176 palette
= surface
->palette
;
2177 else if (surface
->ddraw
->primary
)
2178 palette
= surface
->ddraw
->primary
->palette
;
2183 wined3d_palette_apply_to_dc(palette
->wined3d_palette
, *dc
);
2187 wined3d_mutex_unlock();
2190 /* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
2191 * does not touch *dc. */
2192 case WINED3DERR_INVALIDCALL
:
2194 return DDERR_CANTCREATEDC
;
2201 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2203 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2205 TRACE("iface %p, dc %p.\n", iface
, dc
);
2207 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2210 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2212 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2214 TRACE("iface %p, dc %p.\n", iface
, dc
);
2216 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2219 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2221 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2223 TRACE("iface %p, dc %p.\n", iface
, dc
);
2225 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2228 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2230 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2232 TRACE("iface %p, dc %p.\n", iface
, dc
);
2234 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2237 /*****************************************************************************
2238 * IDirectDrawSurface7::ReleaseDC
2240 * Releases the DC that was constructed with GetDC
2243 * hdc: HDC to release
2246 * DD_OK on success, error code otherwise.
2248 *****************************************************************************/
2249 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2254 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2256 wined3d_mutex_lock();
2261 else if (SUCCEEDED(hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, surface
->sub_resource_idx
, hdc
)))
2264 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2265 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2267 wined3d_mutex_unlock();
2273 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2275 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2277 TRACE("iface %p, dc %p.\n", iface
, dc
);
2279 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2282 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2284 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2286 TRACE("iface %p, dc %p.\n", iface
, dc
);
2288 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2291 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2293 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2295 TRACE("iface %p, dc %p.\n", iface
, dc
);
2297 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2300 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2302 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2304 TRACE("iface %p, dc %p.\n", iface
, dc
);
2306 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2309 /*****************************************************************************
2310 * IDirectDrawSurface7::GetCaps
2312 * Returns the surface's caps
2315 * Caps: Address to write the caps to
2319 * DDERR_INVALIDPARAMS if Caps is NULL
2321 *****************************************************************************/
2322 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2324 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2326 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2329 return DDERR_INVALIDPARAMS
;
2331 *Caps
= surface
->surface_desc
.ddsCaps
;
2336 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2338 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2340 TRACE("iface %p, caps %p.\n", iface
, caps
);
2342 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2345 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2347 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2351 TRACE("iface %p, caps %p.\n", iface
, caps
);
2353 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2354 if (FAILED(hr
)) return hr
;
2356 caps
->dwCaps
= caps2
.dwCaps
;
2360 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2362 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2366 TRACE("iface %p, caps %p.\n", iface
, caps
);
2368 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2369 if (FAILED(hr
)) return hr
;
2371 caps
->dwCaps
= caps2
.dwCaps
;
2375 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2377 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2381 TRACE("iface %p, caps %p.\n", iface
, caps
);
2383 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2384 if (FAILED(hr
)) return hr
;
2386 caps
->dwCaps
= caps2
.dwCaps
;
2390 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2392 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2393 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2395 struct wined3d_resource
*resource
;
2397 TRACE("iface %p, priority %u.\n", iface
, priority
);
2399 wined3d_mutex_lock();
2400 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2401 * calls on such surfaces segfault on Windows. */
2402 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2404 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2405 hr
= DDERR_INVALIDPARAMS
;
2409 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2410 wined3d_resource_set_priority(resource
, priority
);
2413 wined3d_mutex_unlock();
2418 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2420 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2421 const struct wined3d_resource
*resource
;
2422 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2425 TRACE("iface %p, priority %p.\n", iface
, priority
);
2427 wined3d_mutex_lock();
2428 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2430 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2431 hr
= DDERR_INVALIDOBJECT
;
2433 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->is_complex_root
)
2435 WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
2436 hr
= DDERR_INVALIDPARAMS
;
2440 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2441 *priority
= wined3d_resource_get_priority(resource
);
2444 wined3d_mutex_unlock();
2449 /*****************************************************************************
2450 * IDirectDrawSurface7::SetPrivateData
2452 * Stores some data in the surface that is intended for the application's
2456 * tag: GUID that identifies the data
2457 * Data: Pointer to the private data
2458 * Size: Size of the private data
2462 * D3D_OK on success, error code otherwise.
2464 *****************************************************************************/
2465 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2466 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2468 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2471 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2472 iface
, debugstr_guid(tag
), data
, size
, flags
);
2476 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2477 return DDERR_INVALIDPARAMS
;
2480 wined3d_mutex_lock();
2481 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2482 wined3d_mutex_unlock();
2483 return hr_ddraw_from_wined3d(hr
);
2486 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2487 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2489 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2491 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2492 iface
, debugstr_guid(tag
), data
, size
, flags
);
2494 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2497 /*****************************************************************************
2498 * IDirectDrawSurface7::GetPrivateData
2500 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2503 * tag: GUID of the data to return
2504 * Data: Address where to write the data to
2505 * Size: Size of the buffer at Data
2509 * DDERR_INVALIDPARAMS if Data is NULL
2511 *****************************************************************************/
2512 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2514 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2515 const struct wined3d_private_data
*stored_data
;
2518 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2519 iface
, debugstr_guid(tag
), data
, size
);
2521 wined3d_mutex_lock();
2522 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2525 hr
= DDERR_NOTFOUND
;
2530 hr
= DDERR_INVALIDPARAMS
;
2533 if (*size
< stored_data
->size
)
2535 *size
= stored_data
->size
;
2536 hr
= DDERR_MOREDATA
;
2541 hr
= DDERR_INVALIDPARAMS
;
2545 *size
= stored_data
->size
;
2546 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2550 wined3d_mutex_unlock();
2554 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2556 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2558 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2559 iface
, debugstr_guid(tag
), data
, size
);
2561 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2564 /*****************************************************************************
2565 * IDirectDrawSurface7::FreePrivateData
2567 * Frees private data stored in the surface
2570 * tag: Tag of the data to free
2573 * D3D_OK on success, error code otherwise.
2575 *****************************************************************************/
2576 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2578 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2579 struct wined3d_private_data
*entry
;
2581 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2583 wined3d_mutex_lock();
2584 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2587 wined3d_mutex_unlock();
2588 return DDERR_NOTFOUND
;
2591 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2592 wined3d_mutex_unlock();
2597 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2599 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2601 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2603 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2606 /*****************************************************************************
2607 * IDirectDrawSurface7::PageLock
2609 * Prevents a sysmem surface from being paged out
2612 * Flags: Not used, must be 0(unchecked)
2615 * DD_OK, because it's a stub
2617 *****************************************************************************/
2618 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2620 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2622 /* This is Windows memory management related - we don't need this */
2626 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2628 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2630 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2632 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2635 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2637 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2639 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2641 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2644 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2646 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2648 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2650 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2653 /*****************************************************************************
2654 * IDirectDrawSurface7::PageUnlock
2656 * Allows a sysmem surface to be paged out
2659 * Flags: Not used, must be 0(unchecked)
2662 * DD_OK, because it's a stub
2664 *****************************************************************************/
2665 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2667 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2672 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2674 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2676 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2678 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2681 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2683 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2685 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2687 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2690 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2692 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2694 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2696 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2699 /*****************************************************************************
2700 * IDirectDrawSurface7::BltBatch
2702 * An unimplemented function
2710 *****************************************************************************/
2711 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2713 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2715 /* MSDN: "not currently implemented" */
2716 return DDERR_UNSUPPORTED
;
2719 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2721 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2723 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2725 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2728 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2730 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2732 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2734 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2737 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2739 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2741 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2743 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2746 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2748 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2750 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2752 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2755 /*****************************************************************************
2756 * IDirectDrawSurface7::EnumAttachedSurfaces
2758 * Enumerates all surfaces attached to this surface
2761 * context: Pointer to pass unmodified to the callback
2762 * cb: Callback function to call for each surface
2766 * DDERR_INVALIDPARAMS if cb is NULL
2768 *****************************************************************************/
2769 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2770 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2772 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2773 struct ddraw_surface
*surf
;
2774 DDSURFACEDESC2 desc
;
2777 /* Attached surfaces aren't handled in WineD3D */
2778 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2781 return DDERR_INVALIDPARAMS
;
2783 wined3d_mutex_lock();
2785 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2787 surf
= surface
->complex_array
[i
];
2790 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2791 desc
= surf
->surface_desc
;
2792 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2793 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2795 wined3d_mutex_unlock();
2800 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2802 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2803 desc
= surf
->surface_desc
;
2804 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2805 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2807 wined3d_mutex_unlock();
2812 TRACE(" end of enumeration.\n");
2814 wined3d_mutex_unlock();
2819 struct callback_info2
2821 LPDDENUMSURFACESCALLBACK2 callback
;
2825 struct callback_info
2827 LPDDENUMSURFACESCALLBACK callback
;
2831 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2833 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2834 const struct callback_info2
*info
= context
;
2836 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2837 ddraw_surface7_Release(surface
);
2839 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2842 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2844 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2845 const struct callback_info
*info
= context
;
2847 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2848 ddraw_surface7_Release(surface
);
2850 /* FIXME: Check surface_test.dwSize */
2851 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2852 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2855 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2856 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2858 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2859 struct callback_info2 info
;
2861 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2863 info
.callback
= callback
;
2864 info
.context
= context
;
2866 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2867 &info
, EnumCallback2
);
2870 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2871 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2873 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2874 struct callback_info info
;
2876 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2878 info
.callback
= callback
;
2879 info
.context
= context
;
2881 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2882 &info
, EnumCallback
);
2885 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2886 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2888 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2889 struct callback_info info
;
2891 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2893 info
.callback
= callback
;
2894 info
.context
= context
;
2896 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2897 &info
, EnumCallback
);
2900 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2901 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2903 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2904 struct callback_info info
;
2906 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2908 info
.callback
= callback
;
2909 info
.context
= context
;
2911 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2912 &info
, EnumCallback
);
2915 /*****************************************************************************
2916 * IDirectDrawSurface7::EnumOverlayZOrders
2918 * "Enumerates the overlay surfaces on the specified destination"
2921 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2922 * context: context to pass back to the callback
2923 * cb: callback function to call for each enumerated surface
2926 * DD_OK, because it's a stub
2928 *****************************************************************************/
2929 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2930 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2932 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2937 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2938 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2940 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2941 struct callback_info2 info
;
2943 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2945 info
.callback
= callback
;
2946 info
.context
= context
;
2948 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2949 flags
, &info
, EnumCallback2
);
2952 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2953 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2955 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2956 struct callback_info info
;
2958 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2960 info
.callback
= callback
;
2961 info
.context
= context
;
2963 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2964 flags
, &info
, EnumCallback
);
2967 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2968 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2970 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2971 struct callback_info info
;
2973 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2975 info
.callback
= callback
;
2976 info
.context
= context
;
2978 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2979 flags
, &info
, EnumCallback
);
2982 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2983 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2985 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2986 struct callback_info info
;
2988 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2990 info
.callback
= callback
;
2991 info
.context
= context
;
2993 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2994 flags
, &info
, EnumCallback
);
2997 /*****************************************************************************
2998 * IDirectDrawSurface7::GetBltStatus
3000 * Returns the blitting status
3003 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
3005 *****************************************************************************/
3006 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3008 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3012 case WINEDDGBS_CANBLT
:
3013 case WINEDDGBS_ISBLTDONE
:
3017 return DDERR_INVALIDPARAMS
;
3021 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3023 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3025 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3027 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3030 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3032 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3034 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3036 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3039 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3041 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3043 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3045 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3048 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3050 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3052 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3054 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3057 /*****************************************************************************
3058 * IDirectDrawSurface7::GetColorKey
3060 * Returns the color key assigned to the surface
3064 * CKey: Address to store the key to
3068 * DDERR_INVALIDPARAMS if CKey is NULL
3070 *****************************************************************************/
3071 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3073 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3075 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3078 return DDERR_INVALIDPARAMS
;
3080 wined3d_mutex_lock();
3084 case DDCKEY_DESTBLT
:
3085 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3087 wined3d_mutex_unlock();
3088 return DDERR_NOCOLORKEY
;
3090 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3093 case DDCKEY_DESTOVERLAY
:
3094 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3096 wined3d_mutex_unlock();
3097 return DDERR_NOCOLORKEY
;
3099 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3103 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3105 wined3d_mutex_unlock();
3106 return DDERR_NOCOLORKEY
;
3108 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3111 case DDCKEY_SRCOVERLAY
:
3112 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3114 wined3d_mutex_unlock();
3115 return DDERR_NOCOLORKEY
;
3117 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3121 wined3d_mutex_unlock();
3122 return DDERR_INVALIDPARAMS
;
3125 wined3d_mutex_unlock();
3130 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3132 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3134 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3136 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3139 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3141 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3143 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3145 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3148 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3150 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3152 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3154 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3157 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3159 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3161 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3163 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3166 /*****************************************************************************
3167 * IDirectDrawSurface7::GetFlipStatus
3169 * Returns the flipping status of the surface
3172 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3174 *****************************************************************************/
3175 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3177 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3179 /* XXX: DDERR_INVALIDSURFACETYPE */
3183 case WINEDDGFS_CANFLIP
:
3184 case WINEDDGFS_ISFLIPDONE
:
3188 return DDERR_INVALIDPARAMS
;
3192 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3194 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3196 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3198 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3201 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3203 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3205 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3207 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3210 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3212 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3214 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3216 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3219 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3221 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3223 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3225 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3228 /*****************************************************************************
3229 * IDirectDrawSurface7::GetOverlayPosition
3231 * Returns the display coordinates of a visible and active overlay surface
3238 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3239 *****************************************************************************/
3240 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*x
, LONG
*y
)
3242 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3245 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3247 wined3d_mutex_lock();
3248 hr
= wined3d_texture_get_overlay_position(surface
->wined3d_texture
,
3249 surface
->sub_resource_idx
, x
, y
);
3250 wined3d_mutex_unlock();
3255 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3257 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3259 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3261 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3264 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3266 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3268 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3270 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3273 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3275 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3277 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3279 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3282 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3284 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3286 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3288 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3291 /*****************************************************************************
3292 * IDirectDrawSurface7::GetPixelFormat
3294 * Returns the pixel format of the Surface
3297 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3298 * format should be written
3302 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3304 *****************************************************************************/
3305 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3307 /* What is DDERR_INVALIDSURFACETYPE for here? */
3308 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3310 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3313 return DDERR_INVALIDPARAMS
;
3315 wined3d_mutex_lock();
3316 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3317 wined3d_mutex_unlock();
3322 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3324 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3326 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3328 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3331 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3333 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3335 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3337 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3340 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3342 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3344 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3346 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3349 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3351 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3353 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3355 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3358 /*****************************************************************************
3359 * IDirectDrawSurface7::GetSurfaceDesc
3361 * Returns the description of this surface
3364 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3369 * DDERR_INVALIDPARAMS if DDSD is NULL
3371 *****************************************************************************/
3372 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3376 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3379 return DDERR_INVALIDPARAMS
;
3381 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3383 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3384 return DDERR_INVALIDPARAMS
;
3387 wined3d_mutex_lock();
3388 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3389 TRACE("Returning surface desc:\n");
3390 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3391 wined3d_mutex_unlock();
3396 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3398 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3400 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3402 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3405 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3407 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3409 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3411 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3413 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3415 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3416 return DDERR_INVALIDPARAMS
;
3419 wined3d_mutex_lock();
3420 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3421 TRACE("Returning surface desc:\n");
3422 if (TRACE_ON(ddraw
))
3424 /* DDRAW_dump_surface_desc handles the smaller size */
3425 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3427 wined3d_mutex_unlock();
3432 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3434 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3436 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3438 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3441 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3443 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3445 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3447 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3450 /*****************************************************************************
3451 * IDirectDrawSurface7::Initialize
3453 * Initializes the surface. This is a no-op in Wine
3456 * DD: Pointer to an DirectDraw interface
3457 * DDSD: Surface description for initialization
3460 * DDERR_ALREADYINITIALIZED
3462 *****************************************************************************/
3463 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3464 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3466 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3468 return DDERR_ALREADYINITIALIZED
;
3471 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3472 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3474 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3476 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3478 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3479 ddraw
, surface_desc
);
3482 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3483 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3485 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3486 DDSURFACEDESC2 surface_desc2
;
3488 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3490 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3491 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3492 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3495 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3496 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3498 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3499 DDSURFACEDESC2 surface_desc2
;
3501 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3503 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3504 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3505 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3508 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3509 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3511 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3512 DDSURFACEDESC2 surface_desc2
;
3514 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3516 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3517 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3518 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3521 /*****************************************************************************
3522 * IDirect3DTexture1::Initialize
3524 * The sdk says it's not implemented
3532 *****************************************************************************/
3533 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3534 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3536 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3538 return DDERR_UNSUPPORTED
; /* Unchecked */
3541 /*****************************************************************************
3542 * IDirectDrawSurface7::IsLost
3544 * Checks if the surface is lost
3547 * DD_OK, if the surface is usable
3548 * DDERR_ISLOST if the surface is lost
3550 *****************************************************************************/
3551 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3553 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3555 TRACE("iface %p.\n", iface
);
3557 if (surface
->ddraw
->device_state
!= DDRAW_DEVICE_STATE_OK
|| surface
->is_lost
)
3558 return DDERR_SURFACELOST
;
3563 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3565 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3567 TRACE("iface %p.\n", iface
);
3569 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3572 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3574 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3576 TRACE("iface %p.\n", iface
);
3578 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3581 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3583 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3585 TRACE("iface %p.\n", iface
);
3587 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3590 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3592 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3594 TRACE("iface %p.\n", iface
);
3596 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3599 /*****************************************************************************
3600 * IDirectDrawSurface7::Restore
3602 * Restores a lost surface. This makes the surface usable again, but
3603 * doesn't reload its old contents
3606 * DD_OK on success, error code otherwise.
3608 *****************************************************************************/
3609 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3611 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3613 TRACE("iface %p.\n", iface
);
3615 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3617 struct wined3d_swapchain
*swapchain
= surface
->ddraw
->wined3d_swapchain
;
3618 struct wined3d_sub_resource_desc wined3d_desc
;
3619 struct wined3d_display_mode mode
;
3622 if (FAILED(hr
= wined3d_swapchain_get_display_mode(swapchain
, &mode
, NULL
)))
3624 WARN("Failed to get display mode, hr %#x.\n", hr
);
3628 if (FAILED(hr
= wined3d_texture_get_sub_resource_desc(surface
->wined3d_texture
, 0, &wined3d_desc
)))
3630 WARN("Failed to get resource desc, hr %#x.\n", hr
);
3634 if (mode
.width
!= wined3d_desc
.width
|| mode
.height
!= wined3d_desc
.height
)
3636 WARN("Display mode dimensions %ux%u don't match surface dimensions %ux%u.\n",
3637 mode
.width
, mode
.height
, wined3d_desc
.width
, wined3d_desc
.height
);
3638 return DDERR_WRONGMODE
;
3641 if (mode
.format_id
!= wined3d_desc
.format
)
3643 WARN("Display mode format %#x doesn't match surface format %#x.\n",
3644 mode
.format_id
, wined3d_desc
.format
);
3645 return DDERR_WRONGMODE
;
3649 ddraw_update_lost_surfaces(surface
->ddraw
);
3650 surface
->is_lost
= FALSE
;
3655 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3657 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3659 TRACE("iface %p.\n", iface
);
3661 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3664 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3666 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3668 TRACE("iface %p.\n", iface
);
3670 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3673 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3675 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3677 TRACE("iface %p.\n", iface
);
3679 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3682 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3684 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3686 TRACE("iface %p.\n", iface
);
3688 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3691 /*****************************************************************************
3692 * IDirectDrawSurface7::SetOverlayPosition
3694 * Changes the display coordinates of an overlay surface
3701 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3702 *****************************************************************************/
3703 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG x
, LONG y
)
3705 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3708 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3710 wined3d_mutex_lock();
3711 hr
= wined3d_texture_set_overlay_position(surface
->wined3d_texture
,
3712 surface
->sub_resource_idx
, x
, y
);
3713 wined3d_mutex_unlock();
3718 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3720 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3722 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3724 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3727 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3729 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3731 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3733 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3736 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3738 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3740 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3742 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3745 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3747 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3749 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3751 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3754 /*****************************************************************************
3755 * IDirectDrawSurface7::UpdateOverlay
3757 * Modifies the attributes of an overlay surface.
3760 * SrcRect: The section of the source being used for the overlay
3761 * DstSurface: Address of the surface that is overlaid
3762 * DstRect: Place of the overlay
3763 * Flags: some DDOVER_* flags
3766 * DDERR_UNSUPPORTED, because we don't support overlays
3768 *****************************************************************************/
3769 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*src_rect
,
3770 IDirectDrawSurface7
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3772 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3773 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(dst_surface
);
3774 struct wined3d_texture
*dst_wined3d_texture
= NULL
;
3775 unsigned int dst_sub_resource_idx
= 0;
3778 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3779 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3782 FIXME("Ignoring fx %p.\n", fx
);
3784 wined3d_mutex_lock();
3787 dst_wined3d_texture
= dst_impl
->wined3d_texture
;
3788 dst_sub_resource_idx
= dst_impl
->sub_resource_idx
;
3790 hr
= wined3d_texture_update_overlay(src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
,
3791 src_rect
, dst_wined3d_texture
, dst_sub_resource_idx
, dst_rect
, flags
);
3792 wined3d_mutex_unlock();
3796 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3797 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3798 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3804 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3805 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3807 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3808 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3810 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3811 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3813 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3814 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3817 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3818 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3820 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3821 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3823 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3824 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3826 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3827 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3830 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3831 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3833 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3834 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3836 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3837 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3839 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3840 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3843 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3844 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3846 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3847 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3849 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3850 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3852 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3853 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3856 /*****************************************************************************
3857 * IDirectDrawSurface7::UpdateOverlayDisplay
3859 * The DX7 sdk says that it's not implemented
3864 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3866 *****************************************************************************/
3867 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3869 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3871 return DDERR_UNSUPPORTED
;
3874 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3876 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3878 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3880 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3883 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3885 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3887 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3889 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3892 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3894 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3896 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3898 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3901 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3903 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3905 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3907 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3910 /*****************************************************************************
3911 * IDirectDrawSurface7::UpdateOverlayZOrder
3913 * Sets an overlay's Z order
3916 * Flags: DDOVERZ_* flags
3917 * DDSRef: Defines the relative position in the overlay chain
3920 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3922 *****************************************************************************/
3923 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3924 DWORD flags
, IDirectDrawSurface7
*reference
)
3926 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3928 FIXME("iface %p, flags %#x, reference %p stub!\n", iface
, flags
, reference
);
3930 wined3d_mutex_lock();
3931 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OVERLAY
))
3933 WARN("Not an overlay surface.\n");
3934 wined3d_mutex_unlock();
3935 return DDERR_NOTAOVERLAYSURFACE
;
3937 wined3d_mutex_unlock();
3942 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3943 DWORD flags
, IDirectDrawSurface4
*reference
)
3945 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3946 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3948 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3950 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3951 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3954 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3955 DWORD flags
, IDirectDrawSurface3
*reference
)
3957 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3958 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3960 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3962 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3963 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3966 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3967 DWORD flags
, IDirectDrawSurface2
*reference
)
3969 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3970 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3972 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3974 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3975 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3978 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3979 DWORD flags
, IDirectDrawSurface
*reference
)
3981 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3982 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3984 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3986 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3987 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3990 /*****************************************************************************
3991 * IDirectDrawSurface7::GetDDInterface
3993 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3994 * surface belongs to
3997 * DD: Address to write the interface pointer to
4001 * DDERR_INVALIDPARAMS if DD is NULL
4003 *****************************************************************************/
4004 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
4006 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4008 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
4011 return DDERR_INVALIDPARAMS
;
4013 switch(This
->version
)
4016 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
4020 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
4024 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
4028 *DD
= &This
->ddraw
->IDirectDraw_iface
;
4032 IUnknown_AddRef((IUnknown
*)*DD
);
4037 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
4039 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4041 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4043 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4046 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
4048 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4050 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4052 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4055 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
4057 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4059 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
4061 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
4064 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
4066 TRACE("iface %p.\n", iface
);
4071 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
4073 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4075 TRACE("iface %p.\n", iface
);
4077 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
4080 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
4082 TRACE("iface %p, value %p.\n", iface
, pValue
);
4089 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
4091 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4093 TRACE("iface %p, value %p.\n", iface
, pValue
);
4095 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4098 /*****************************************************************************
4099 * IDirectDrawSurface7::SetLOD
4101 * Sets the level of detail of a texture
4104 * MaxLOD: LOD to set
4108 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4110 *****************************************************************************/
4111 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4113 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4116 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4118 wined3d_mutex_lock();
4119 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4121 wined3d_mutex_unlock();
4122 return DDERR_INVALIDOBJECT
;
4125 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4126 wined3d_mutex_unlock();
4131 /*****************************************************************************
4132 * IDirectDrawSurface7::GetLOD
4134 * Returns the level of detail of a Direct3D texture
4137 * MaxLOD: Address to write the LOD to
4141 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4142 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4144 *****************************************************************************/
4145 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4147 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4149 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4152 return DDERR_INVALIDPARAMS
;
4154 wined3d_mutex_lock();
4155 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4157 wined3d_mutex_unlock();
4158 return DDERR_INVALIDOBJECT
;
4161 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4162 wined3d_mutex_unlock();
4167 /*****************************************************************************
4168 * IDirectDrawSurface7::BltFast
4170 * Performs a fast Blit.
4173 * dstx: The x coordinate to blit to on the destination
4174 * dsty: The y coordinate to blit to on the destination
4175 * Source: The source surface
4176 * rsrc: The source rectangle
4177 * trans: Type of transfer. Some DDBLTFAST_* flags
4180 * DD_OK on success, error code otherwise.
4182 *****************************************************************************/
4183 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
,
4184 DWORD dst_x
, DWORD dst_y
, IDirectDrawSurface7
*src_surface
, RECT
*src_rect
, DWORD trans
)
4186 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
4187 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src_surface
);
4188 DWORD src_w
, src_h
, dst_w
, dst_h
;
4193 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4194 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), trans
);
4196 dst_w
= dst_impl
->surface_desc
.dwWidth
;
4197 dst_h
= dst_impl
->surface_desc
.dwHeight
;
4201 SetRect(&s
, 0, 0, src_impl
->surface_desc
.dwWidth
, src_impl
->surface_desc
.dwHeight
);
4205 src_w
= src_rect
->right
- src_rect
->left
;
4206 src_h
= src_rect
->bottom
- src_rect
->top
;
4207 if (src_w
> dst_w
|| dst_x
> dst_w
- src_w
4208 || src_h
> dst_h
|| dst_y
> dst_h
- src_h
)
4210 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4211 return DDERR_INVALIDRECT
;
4214 SetRect(&dst_rect
, dst_x
, dst_y
, dst_x
+ src_w
, dst_y
+ src_h
);
4215 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4216 flags
|= WINED3D_BLT_SRC_CKEY
;
4217 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4218 flags
|= WINED3D_BLT_DST_CKEY
;
4219 if (trans
& DDBLTFAST_WAIT
)
4220 flags
|= WINED3D_BLT_WAIT
;
4221 if (trans
& DDBLTFAST_DONOTWAIT
)
4222 flags
|= WINED3D_BLT_DO_NOT_WAIT
;
4224 wined3d_mutex_lock();
4225 if (dst_impl
->clipper
)
4227 wined3d_mutex_unlock();
4228 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4229 return DDERR_BLTFASTCANTCLIP
;
4232 if (src_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4233 hr
= ddraw_surface_update_frontbuffer(src_impl
, src_rect
, TRUE
);
4235 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
4236 src_impl
->wined3d_texture
, src_impl
->sub_resource_idx
, src_rect
, flags
, NULL
, WINED3D_TEXF_POINT
);
4237 if (SUCCEEDED(hr
) && (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4238 hr
= ddraw_surface_update_frontbuffer(dst_impl
, &dst_rect
, FALSE
);
4239 wined3d_mutex_unlock();
4243 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4248 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4249 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4251 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4252 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4254 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4255 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4257 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4258 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4261 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4262 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4264 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4265 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4267 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4268 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4270 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4271 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4274 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4275 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4277 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4278 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4280 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4281 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4283 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4284 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4287 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4288 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4290 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4291 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4293 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4294 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4296 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4297 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4300 /*****************************************************************************
4301 * IDirectDrawSurface7::GetClipper
4303 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4307 * Clipper: Address to store the interface pointer at
4311 * DDERR_INVALIDPARAMS if Clipper is NULL
4312 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4314 *****************************************************************************/
4315 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4317 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4319 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4322 return DDERR_INVALIDPARAMS
;
4324 wined3d_mutex_lock();
4325 if (!surface
->clipper
)
4327 wined3d_mutex_unlock();
4328 return DDERR_NOCLIPPERATTACHED
;
4331 *Clipper
= &surface
->clipper
->IDirectDrawClipper_iface
;
4332 IDirectDrawClipper_AddRef(*Clipper
);
4333 wined3d_mutex_unlock();
4338 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4340 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4342 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4344 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4347 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4349 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4351 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4353 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4356 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4358 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4360 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4362 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4365 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4367 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4369 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4371 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4374 /*****************************************************************************
4375 * IDirectDrawSurface7::SetClipper
4377 * Sets a clipper for the surface
4380 * Clipper: IDirectDrawClipper interface of the clipper to set
4385 *****************************************************************************/
4386 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4387 IDirectDrawClipper
*iclipper
)
4389 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4390 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4391 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4394 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4396 wined3d_mutex_lock();
4397 if (clipper
== This
->clipper
)
4399 wined3d_mutex_unlock();
4403 This
->clipper
= clipper
;
4405 if (clipper
!= NULL
)
4406 IDirectDrawClipper_AddRef(iclipper
);
4408 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4410 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4414 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4419 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4420 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4424 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4425 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4429 wined3d_mutex_unlock();
4434 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4436 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4438 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4440 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4443 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4445 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4447 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4449 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4452 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4454 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4456 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4458 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4461 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4463 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4465 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4467 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4470 /*****************************************************************************
4471 * IDirectDrawSurface7::SetSurfaceDesc
4473 * Sets the surface description. It can override the pixel format, the surface
4475 * It's not really tested.
4478 * DDSD: Pointer to the new surface description to set
4483 * DDERR_INVALIDPARAMS if DDSD is NULL
4485 *****************************************************************************/
4486 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4488 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4490 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4491 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4492 enum wined3d_format_id format_id
;
4493 UINT pitch
, width
, height
;
4495 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4499 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4500 return DDERR_INVALIDPARAMS
;
4504 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4505 return DDERR_INVALIDPARAMS
;
4507 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4508 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4509 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4511 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4512 return DDERR_INVALIDSURFACETYPE
;
4515 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4516 * for PIXELFORMAT to work */
4517 if (DDSD
->dwFlags
& ~allowed_flags
)
4519 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4520 return DDERR_INVALIDPARAMS
;
4522 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4524 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4525 return DDERR_INVALIDPARAMS
;
4527 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4529 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4530 return DDERR_INVALIDCAPS
;
4532 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4534 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4536 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4537 return DDERR_INVALIDPARAMS
;
4539 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4541 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4542 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4543 return DDERR_INVALIDPARAMS
;
4545 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4546 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4547 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4548 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4549 pitch
= DDSD
->u1
.lPitch
;
4550 width
= DDSD
->dwWidth
;
4552 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4554 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4555 return DDERR_INVALIDPARAMS
;
4559 pitch
= This
->surface_desc
.u1
.lPitch
;
4560 width
= This
->surface_desc
.dwWidth
;
4563 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4565 if (!DDSD
->dwHeight
)
4567 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4568 return DDERR_INVALIDPARAMS
;
4570 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4571 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4572 height
= DDSD
->dwHeight
;
4576 height
= This
->surface_desc
.dwHeight
;
4579 wined3d_mutex_lock();
4580 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4582 enum wined3d_format_id current_format_id
;
4583 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4585 if (format_id
== WINED3DFMT_UNKNOWN
)
4587 ERR("Requested to set an unknown pixelformat\n");
4588 wined3d_mutex_unlock();
4589 return DDERR_INVALIDPARAMS
;
4591 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4592 if (format_id
!= current_format_id
)
4593 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4597 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4600 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4601 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4603 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4604 wined3d_mutex_unlock();
4605 return hr_ddraw_from_wined3d(hr
);
4608 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4609 This
->surface_desc
.dwWidth
= width
;
4610 if (DDSD
->dwFlags
& DDSD_PITCH
)
4611 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4612 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4613 This
->surface_desc
.dwHeight
= height
;
4614 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4615 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4617 wined3d_mutex_unlock();
4622 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4623 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4625 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4627 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4629 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4630 surface_desc
, flags
);
4633 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4634 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4636 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4637 DDSURFACEDESC2 surface_desc2
;
4639 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4641 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4642 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4643 surface_desc
? &surface_desc2
: NULL
, flags
);
4646 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4648 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4649 struct ddraw_palette
*palette_impl
;
4652 TRACE("iface %p, palette %p.\n", iface
, palette
);
4655 return DDERR_INVALIDPARAMS
;
4656 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4658 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4659 return DDERR_SURFACELOST
;
4662 wined3d_mutex_lock();
4663 if ((palette_impl
= surface
->palette
))
4665 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4666 IDirectDrawPalette_AddRef(*palette
);
4671 hr
= DDERR_NOPALETTEATTACHED
;
4673 wined3d_mutex_unlock();
4678 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4680 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4682 TRACE("iface %p, palette %p.\n", iface
, palette
);
4684 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4687 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4689 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4691 TRACE("iface %p, palette %p.\n", iface
, palette
);
4693 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4696 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4698 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4700 TRACE("iface %p, palette %p.\n", iface
, palette
);
4702 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4705 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4707 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4709 TRACE("iface %p, palette %p.\n", iface
, palette
);
4711 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4714 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4716 DDCOLORKEY fixed_color_key
;
4717 HRESULT hr
= WINED3D_OK
;
4719 if (flags
& DDCKEY_COLORSPACE
)
4721 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4723 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4724 return DDERR_NOCOLORKEYHW
;
4726 flags
&= ~DDCKEY_COLORSPACE
;
4729 wined3d_mutex_lock();
4733 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4734 switch (flags
& ~DDCKEY_COLORSPACE
)
4736 case DDCKEY_DESTBLT
:
4737 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4738 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4741 case DDCKEY_DESTOVERLAY
:
4742 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4743 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4746 case DDCKEY_SRCOVERLAY
:
4747 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4748 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4752 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4753 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4757 wined3d_mutex_unlock();
4758 return DDERR_INVALIDPARAMS
;
4763 switch (flags
& ~DDCKEY_COLORSPACE
)
4765 case DDCKEY_DESTBLT
:
4766 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4769 case DDCKEY_DESTOVERLAY
:
4770 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4773 case DDCKEY_SRCOVERLAY
:
4774 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4778 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4782 wined3d_mutex_unlock();
4783 return DDERR_INVALIDPARAMS
;
4787 if (surface
->is_complex_root
)
4788 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4789 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4791 wined3d_mutex_unlock();
4793 return hr_ddraw_from_wined3d(hr
);
4796 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4798 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4800 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4802 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4803 return DDERR_NOTONMIPMAPSUBLEVEL
;
4805 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4808 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4810 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4812 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4814 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4817 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4819 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4821 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4823 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4826 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4828 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4830 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4832 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4835 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4837 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4839 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4841 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4844 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4846 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4848 TRACE("iface %p, palette %p.\n", iface
, palette
);
4850 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4851 return DDERR_NOTONMIPMAPSUBLEVEL
;
4852 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4854 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4855 return DDERR_SURFACELOST
;
4858 return ddraw_surface_set_palette(surface
, palette
);
4861 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4863 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4865 TRACE("iface %p, palette %p.\n", iface
, palette
);
4867 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4869 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4870 return DDERR_SURFACELOST
;
4873 return ddraw_surface_set_palette(surface
, palette
);
4876 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4878 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4880 TRACE("iface %p, palette %p.\n", iface
, palette
);
4882 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4884 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4885 return DDERR_SURFACELOST
;
4888 return ddraw_surface_set_palette(surface
, palette
);
4891 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4893 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4895 TRACE("iface %p, palette %p.\n", iface
, palette
);
4897 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4899 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4900 return DDERR_SURFACELOST
;
4903 return ddraw_surface_set_palette(surface
, palette
);
4906 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4908 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4910 TRACE("iface %p, palette %p.\n", iface
, palette
);
4912 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4914 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4915 return DDERR_SURFACELOST
;
4918 return ddraw_surface_set_palette(surface
, palette
);
4921 /**********************************************************
4922 * IDirectDrawGammaControl::GetGammaRamp
4924 * Returns the current gamma ramp for a surface
4928 * gamma_ramp: Address to write the ramp to
4932 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4934 **********************************************************/
4935 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4936 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4938 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4940 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4944 WARN("Invalid gamma_ramp passed.\n");
4945 return DDERR_INVALIDPARAMS
;
4948 wined3d_mutex_lock();
4949 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4951 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4952 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4956 ERR("Not implemented for non-primary surfaces.\n");
4958 wined3d_mutex_unlock();
4963 /**********************************************************
4964 * IDirectDrawGammaControl::SetGammaRamp
4966 * Sets the red, green and blue gamma ramps for
4969 * flags: Can be DDSGR_CALIBRATE to request calibration
4970 * gamma_ramp: Structure containing the new gamma ramp
4974 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4976 **********************************************************/
4977 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4978 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4980 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4982 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4986 WARN("Invalid gamma_ramp passed.\n");
4987 return DDERR_INVALIDPARAMS
;
4990 wined3d_mutex_lock();
4991 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4993 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4994 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4995 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4999 ERR("Not implemented for non-primary surfaces.\n");
5001 wined3d_mutex_unlock();
5006 /*****************************************************************************
5007 * IDirect3DTexture2::PaletteChanged
5009 * Informs the texture about a palette change
5012 * start: Start index of the change
5013 * count: The number of changed entries
5016 * D3D_OK, because it's a stub
5018 *****************************************************************************/
5019 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
5021 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
5026 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
5028 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5030 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
5032 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
5035 /*****************************************************************************
5036 * IDirect3DTexture::Unload
5038 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
5044 *****************************************************************************/
5045 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
5047 WARN("iface %p. Not implemented.\n", iface
);
5049 return DDERR_UNSUPPORTED
;
5052 /*****************************************************************************
5053 * IDirect3DTexture2::GetHandle
5055 * Returns handle for the texture.
5058 * device: Device this handle is assigned to
5059 * handle: Address to store the handle at.
5064 *****************************************************************************/
5065 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
5066 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
5068 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
5069 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5071 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5073 wined3d_mutex_lock();
5075 if (!surface
->Handle
)
5077 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5078 if (h
== DDRAW_INVALID_HANDLE
)
5080 ERR("Failed to allocate a texture handle.\n");
5081 wined3d_mutex_unlock();
5082 return DDERR_OUTOFMEMORY
;
5085 surface
->Handle
= h
+ 1;
5088 TRACE("Returning handle %08x.\n", surface
->Handle
);
5089 *handle
= surface
->Handle
;
5091 wined3d_mutex_unlock();
5096 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5097 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5099 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5100 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5102 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5104 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5105 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5108 /*****************************************************************************
5109 * get_sub_mimaplevel
5111 * Helper function that returns the next mipmap level
5113 * tex_ptr: Surface of which to return the next level
5115 *****************************************************************************/
5116 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5118 /* Now go down the mipmap chain to the next surface */
5119 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5120 IDirectDrawSurface7
*next_level
;
5123 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5124 if (FAILED(hr
)) return NULL
;
5126 ddraw_surface7_Release(next_level
);
5128 return impl_from_IDirectDrawSurface7(next_level
);
5131 /*****************************************************************************
5132 * IDirect3DTexture2::Load
5134 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5136 * This function isn't relayed to WineD3D because the whole interface is
5137 * implemented in DDraw only. For speed improvements an implementation which
5138 * takes OpenGL more into account could be placed into WineD3D.
5141 * src_texture: Address of the texture to load
5145 * D3DERR_TEXTURE_LOAD_FAILED.
5147 *****************************************************************************/
5148 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5150 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5151 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5152 struct wined3d_resource
*dst_resource
, *src_resource
;
5155 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5157 if (src_surface
== dst_surface
)
5159 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5163 wined3d_mutex_lock();
5165 dst_resource
= wined3d_texture_get_resource(dst_surface
->wined3d_texture
);
5166 src_resource
= wined3d_texture_get_resource(src_surface
->wined3d_texture
);
5168 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5169 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5170 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5172 ERR("Trying to load surfaces with different mip-map counts.\n");
5177 struct ddraw_palette
*dst_pal
, *src_pal
;
5178 DDSURFACEDESC
*src_desc
, *dst_desc
;
5180 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5182 /* Suppress the ALLOCONLOAD flag */
5183 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5185 /* Get the palettes */
5186 dst_pal
= dst_surface
->palette
;
5187 src_pal
= src_surface
->palette
;
5191 PALETTEENTRY palent
[256];
5195 wined3d_mutex_unlock();
5196 return DDERR_NOPALETTEATTACHED
;
5198 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5199 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5202 /* Copy one surface on the other */
5203 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5204 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5206 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5208 /* Should also check for same pixel format, u1.lPitch, ... */
5209 ERR("Error in surface sizes.\n");
5210 wined3d_mutex_unlock();
5211 return D3DERR_TEXTURE_LOAD_FAILED
;
5215 struct wined3d_map_desc src_map_desc
, dst_map_desc
;
5217 /* Copy the src blit color key if the source has one, don't erase
5218 * the destination's ckey if the source has none */
5219 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5221 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5222 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5225 if (FAILED(hr
= wined3d_resource_map(src_resource
,
5226 src_surface
->sub_resource_idx
, &src_map_desc
, NULL
, 0)))
5228 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5229 wined3d_mutex_unlock();
5230 return D3DERR_TEXTURE_LOAD_FAILED
;
5233 if (FAILED(hr
= wined3d_resource_map(dst_resource
,
5234 dst_surface
->sub_resource_idx
, &dst_map_desc
, NULL
, 0)))
5236 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5237 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5238 wined3d_mutex_unlock();
5239 return D3DERR_TEXTURE_LOAD_FAILED
;
5242 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5243 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5245 memcpy(dst_map_desc
.data
, src_map_desc
.data
, src_map_desc
.row_pitch
* src_desc
->dwHeight
);
5247 wined3d_resource_unmap(dst_resource
, dst_surface
->sub_resource_idx
);
5248 wined3d_resource_unmap(src_resource
, src_surface
->sub_resource_idx
);
5251 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5252 src_surface
= get_sub_mimaplevel(src_surface
);
5256 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5257 dst_surface
= get_sub_mimaplevel(dst_surface
);
5261 if (!src_surface
|| !dst_surface
)
5263 if (src_surface
!= dst_surface
)
5264 ERR("Loading surface with different mipmap structure.\n");
5269 wined3d_mutex_unlock();
5274 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5276 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5277 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5279 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5281 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5282 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5285 /*****************************************************************************
5287 *****************************************************************************/
5289 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5292 ddraw_surface7_QueryInterface
,
5293 ddraw_surface7_AddRef
,
5294 ddraw_surface7_Release
,
5295 /* IDirectDrawSurface */
5296 ddraw_surface7_AddAttachedSurface
,
5297 ddraw_surface7_AddOverlayDirtyRect
,
5299 ddraw_surface7_BltBatch
,
5300 ddraw_surface7_BltFast
,
5301 ddraw_surface7_DeleteAttachedSurface
,
5302 ddraw_surface7_EnumAttachedSurfaces
,
5303 ddraw_surface7_EnumOverlayZOrders
,
5304 ddraw_surface7_Flip
,
5305 ddraw_surface7_GetAttachedSurface
,
5306 ddraw_surface7_GetBltStatus
,
5307 ddraw_surface7_GetCaps
,
5308 ddraw_surface7_GetClipper
,
5309 ddraw_surface7_GetColorKey
,
5310 ddraw_surface7_GetDC
,
5311 ddraw_surface7_GetFlipStatus
,
5312 ddraw_surface7_GetOverlayPosition
,
5313 ddraw_surface7_GetPalette
,
5314 ddraw_surface7_GetPixelFormat
,
5315 ddraw_surface7_GetSurfaceDesc
,
5316 ddraw_surface7_Initialize
,
5317 ddraw_surface7_IsLost
,
5318 ddraw_surface7_Lock
,
5319 ddraw_surface7_ReleaseDC
,
5320 ddraw_surface7_Restore
,
5321 ddraw_surface7_SetClipper
,
5322 ddraw_surface7_SetColorKey
,
5323 ddraw_surface7_SetOverlayPosition
,
5324 ddraw_surface7_SetPalette
,
5325 ddraw_surface7_Unlock
,
5326 ddraw_surface7_UpdateOverlay
,
5327 ddraw_surface7_UpdateOverlayDisplay
,
5328 ddraw_surface7_UpdateOverlayZOrder
,
5329 /* IDirectDrawSurface2 */
5330 ddraw_surface7_GetDDInterface
,
5331 ddraw_surface7_PageLock
,
5332 ddraw_surface7_PageUnlock
,
5333 /* IDirectDrawSurface3 */
5334 ddraw_surface7_SetSurfaceDesc
,
5335 /* IDirectDrawSurface4 */
5336 ddraw_surface7_SetPrivateData
,
5337 ddraw_surface7_GetPrivateData
,
5338 ddraw_surface7_FreePrivateData
,
5339 ddraw_surface7_GetUniquenessValue
,
5340 ddraw_surface7_ChangeUniquenessValue
,
5341 /* IDirectDrawSurface7 */
5342 ddraw_surface7_SetPriority
,
5343 ddraw_surface7_GetPriority
,
5344 ddraw_surface7_SetLOD
,
5345 ddraw_surface7_GetLOD
,
5348 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5351 ddraw_surface4_QueryInterface
,
5352 ddraw_surface4_AddRef
,
5353 ddraw_surface4_Release
,
5354 /* IDirectDrawSurface */
5355 ddraw_surface4_AddAttachedSurface
,
5356 ddraw_surface4_AddOverlayDirtyRect
,
5358 ddraw_surface4_BltBatch
,
5359 ddraw_surface4_BltFast
,
5360 ddraw_surface4_DeleteAttachedSurface
,
5361 ddraw_surface4_EnumAttachedSurfaces
,
5362 ddraw_surface4_EnumOverlayZOrders
,
5363 ddraw_surface4_Flip
,
5364 ddraw_surface4_GetAttachedSurface
,
5365 ddraw_surface4_GetBltStatus
,
5366 ddraw_surface4_GetCaps
,
5367 ddraw_surface4_GetClipper
,
5368 ddraw_surface4_GetColorKey
,
5369 ddraw_surface4_GetDC
,
5370 ddraw_surface4_GetFlipStatus
,
5371 ddraw_surface4_GetOverlayPosition
,
5372 ddraw_surface4_GetPalette
,
5373 ddraw_surface4_GetPixelFormat
,
5374 ddraw_surface4_GetSurfaceDesc
,
5375 ddraw_surface4_Initialize
,
5376 ddraw_surface4_IsLost
,
5377 ddraw_surface4_Lock
,
5378 ddraw_surface4_ReleaseDC
,
5379 ddraw_surface4_Restore
,
5380 ddraw_surface4_SetClipper
,
5381 ddraw_surface4_SetColorKey
,
5382 ddraw_surface4_SetOverlayPosition
,
5383 ddraw_surface4_SetPalette
,
5384 ddraw_surface4_Unlock
,
5385 ddraw_surface4_UpdateOverlay
,
5386 ddraw_surface4_UpdateOverlayDisplay
,
5387 ddraw_surface4_UpdateOverlayZOrder
,
5388 /* IDirectDrawSurface2 */
5389 ddraw_surface4_GetDDInterface
,
5390 ddraw_surface4_PageLock
,
5391 ddraw_surface4_PageUnlock
,
5392 /* IDirectDrawSurface3 */
5393 ddraw_surface4_SetSurfaceDesc
,
5394 /* IDirectDrawSurface4 */
5395 ddraw_surface4_SetPrivateData
,
5396 ddraw_surface4_GetPrivateData
,
5397 ddraw_surface4_FreePrivateData
,
5398 ddraw_surface4_GetUniquenessValue
,
5399 ddraw_surface4_ChangeUniquenessValue
,
5402 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5405 ddraw_surface3_QueryInterface
,
5406 ddraw_surface3_AddRef
,
5407 ddraw_surface3_Release
,
5408 /* IDirectDrawSurface */
5409 ddraw_surface3_AddAttachedSurface
,
5410 ddraw_surface3_AddOverlayDirtyRect
,
5412 ddraw_surface3_BltBatch
,
5413 ddraw_surface3_BltFast
,
5414 ddraw_surface3_DeleteAttachedSurface
,
5415 ddraw_surface3_EnumAttachedSurfaces
,
5416 ddraw_surface3_EnumOverlayZOrders
,
5417 ddraw_surface3_Flip
,
5418 ddraw_surface3_GetAttachedSurface
,
5419 ddraw_surface3_GetBltStatus
,
5420 ddraw_surface3_GetCaps
,
5421 ddraw_surface3_GetClipper
,
5422 ddraw_surface3_GetColorKey
,
5423 ddraw_surface3_GetDC
,
5424 ddraw_surface3_GetFlipStatus
,
5425 ddraw_surface3_GetOverlayPosition
,
5426 ddraw_surface3_GetPalette
,
5427 ddraw_surface3_GetPixelFormat
,
5428 ddraw_surface3_GetSurfaceDesc
,
5429 ddraw_surface3_Initialize
,
5430 ddraw_surface3_IsLost
,
5431 ddraw_surface3_Lock
,
5432 ddraw_surface3_ReleaseDC
,
5433 ddraw_surface3_Restore
,
5434 ddraw_surface3_SetClipper
,
5435 ddraw_surface3_SetColorKey
,
5436 ddraw_surface3_SetOverlayPosition
,
5437 ddraw_surface3_SetPalette
,
5438 ddraw_surface3_Unlock
,
5439 ddraw_surface3_UpdateOverlay
,
5440 ddraw_surface3_UpdateOverlayDisplay
,
5441 ddraw_surface3_UpdateOverlayZOrder
,
5442 /* IDirectDrawSurface2 */
5443 ddraw_surface3_GetDDInterface
,
5444 ddraw_surface3_PageLock
,
5445 ddraw_surface3_PageUnlock
,
5446 /* IDirectDrawSurface3 */
5447 ddraw_surface3_SetSurfaceDesc
,
5450 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5453 ddraw_surface2_QueryInterface
,
5454 ddraw_surface2_AddRef
,
5455 ddraw_surface2_Release
,
5456 /* IDirectDrawSurface */
5457 ddraw_surface2_AddAttachedSurface
,
5458 ddraw_surface2_AddOverlayDirtyRect
,
5460 ddraw_surface2_BltBatch
,
5461 ddraw_surface2_BltFast
,
5462 ddraw_surface2_DeleteAttachedSurface
,
5463 ddraw_surface2_EnumAttachedSurfaces
,
5464 ddraw_surface2_EnumOverlayZOrders
,
5465 ddraw_surface2_Flip
,
5466 ddraw_surface2_GetAttachedSurface
,
5467 ddraw_surface2_GetBltStatus
,
5468 ddraw_surface2_GetCaps
,
5469 ddraw_surface2_GetClipper
,
5470 ddraw_surface2_GetColorKey
,
5471 ddraw_surface2_GetDC
,
5472 ddraw_surface2_GetFlipStatus
,
5473 ddraw_surface2_GetOverlayPosition
,
5474 ddraw_surface2_GetPalette
,
5475 ddraw_surface2_GetPixelFormat
,
5476 ddraw_surface2_GetSurfaceDesc
,
5477 ddraw_surface2_Initialize
,
5478 ddraw_surface2_IsLost
,
5479 ddraw_surface2_Lock
,
5480 ddraw_surface2_ReleaseDC
,
5481 ddraw_surface2_Restore
,
5482 ddraw_surface2_SetClipper
,
5483 ddraw_surface2_SetColorKey
,
5484 ddraw_surface2_SetOverlayPosition
,
5485 ddraw_surface2_SetPalette
,
5486 ddraw_surface2_Unlock
,
5487 ddraw_surface2_UpdateOverlay
,
5488 ddraw_surface2_UpdateOverlayDisplay
,
5489 ddraw_surface2_UpdateOverlayZOrder
,
5490 /* IDirectDrawSurface2 */
5491 ddraw_surface2_GetDDInterface
,
5492 ddraw_surface2_PageLock
,
5493 ddraw_surface2_PageUnlock
,
5496 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5499 ddraw_surface1_QueryInterface
,
5500 ddraw_surface1_AddRef
,
5501 ddraw_surface1_Release
,
5502 /* IDirectDrawSurface */
5503 ddraw_surface1_AddAttachedSurface
,
5504 ddraw_surface1_AddOverlayDirtyRect
,
5506 ddraw_surface1_BltBatch
,
5507 ddraw_surface1_BltFast
,
5508 ddraw_surface1_DeleteAttachedSurface
,
5509 ddraw_surface1_EnumAttachedSurfaces
,
5510 ddraw_surface1_EnumOverlayZOrders
,
5511 ddraw_surface1_Flip
,
5512 ddraw_surface1_GetAttachedSurface
,
5513 ddraw_surface1_GetBltStatus
,
5514 ddraw_surface1_GetCaps
,
5515 ddraw_surface1_GetClipper
,
5516 ddraw_surface1_GetColorKey
,
5517 ddraw_surface1_GetDC
,
5518 ddraw_surface1_GetFlipStatus
,
5519 ddraw_surface1_GetOverlayPosition
,
5520 ddraw_surface1_GetPalette
,
5521 ddraw_surface1_GetPixelFormat
,
5522 ddraw_surface1_GetSurfaceDesc
,
5523 ddraw_surface1_Initialize
,
5524 ddraw_surface1_IsLost
,
5525 ddraw_surface1_Lock
,
5526 ddraw_surface1_ReleaseDC
,
5527 ddraw_surface1_Restore
,
5528 ddraw_surface1_SetClipper
,
5529 ddraw_surface1_SetColorKey
,
5530 ddraw_surface1_SetOverlayPosition
,
5531 ddraw_surface1_SetPalette
,
5532 ddraw_surface1_Unlock
,
5533 ddraw_surface1_UpdateOverlay
,
5534 ddraw_surface1_UpdateOverlayDisplay
,
5535 ddraw_surface1_UpdateOverlayZOrder
,
5538 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5540 ddraw_gamma_control_QueryInterface
,
5541 ddraw_gamma_control_AddRef
,
5542 ddraw_gamma_control_Release
,
5543 ddraw_gamma_control_GetGammaRamp
,
5544 ddraw_gamma_control_SetGammaRamp
,
5547 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5549 d3d_texture2_QueryInterface
,
5550 d3d_texture2_AddRef
,
5551 d3d_texture2_Release
,
5552 d3d_texture2_GetHandle
,
5553 d3d_texture2_PaletteChanged
,
5557 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5559 d3d_texture1_QueryInterface
,
5560 d3d_texture1_AddRef
,
5561 d3d_texture1_Release
,
5562 d3d_texture1_Initialize
,
5563 d3d_texture1_GetHandle
,
5564 d3d_texture1_PaletteChanged
,
5566 d3d_texture1_Unload
,
5569 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5570 * IDirectDrawSurface interface to ddraw methods. */
5571 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5573 if (!iface
) return NULL
;
5574 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5576 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5579 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5582 IDirectDrawSurface7_Release(iface
);
5584 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5587 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5589 if (!iface
) return NULL
;
5590 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5592 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5595 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5598 IDirectDrawSurface4_Release(iface
);
5600 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5603 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5605 if (!iface
) return NULL
;
5606 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5608 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5611 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5614 IDirectDrawSurface3_Release(iface
);
5616 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5619 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5621 if (!iface
) return NULL
;
5622 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5624 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5627 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5630 IDirectDrawSurface2_Release(iface
);
5632 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5635 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5637 if (!iface
) return NULL
;
5638 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5640 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5643 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5646 IDirectDrawSurface_Release(iface
);
5648 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5651 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5653 if (!iface
) return NULL
;
5654 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5655 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5658 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5660 if (!iface
) return NULL
;
5661 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5662 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5665 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5667 struct ddraw_surface
*surface
= parent
;
5669 TRACE("surface %p.\n", surface
);
5671 /* This shouldn't happen, ddraw_surface_release_iface() should prevent the
5672 * surface from being destroyed in this case. */
5673 if (surface
->first_attached
!= surface
)
5674 ERR("Surface is still attached to surface %p.\n", surface
->first_attached
);
5676 while (surface
->next_attached
)
5677 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5678 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5679 ERR("DeleteAttachedSurface failed.\n");
5681 /* Having a texture handle set implies that the device still exists. */
5682 if (surface
->Handle
)
5683 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5685 /* Reduce the ddraw surface count. */
5686 list_remove(&surface
->surface_list_entry
);
5688 if (surface
->clipper
)
5689 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5691 if (surface
== surface
->ddraw
->primary
)
5692 surface
->ddraw
->primary
= NULL
;
5694 wined3d_private_store_cleanup(&surface
->private_store
);
5696 HeapFree(GetProcessHeap(), 0, surface
);
5699 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5701 ddraw_surface_wined3d_object_destroyed
,
5704 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5706 TRACE("parent %p.\n", parent
);
5708 HeapFree(GetProcessHeap(), 0, parent
);
5711 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5713 ddraw_texture_wined3d_object_destroyed
,
5716 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5721 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5722 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5724 struct wined3d_sub_resource_desc wined3d_mip_desc
;
5725 struct ddraw_surface
*root
, *mip
, **attach
;
5726 struct wined3d_resource_desc wined3d_desc
;
5727 struct wined3d_texture
*wined3d_texture
;
5728 struct wined3d_display_mode mode
;
5729 DDSURFACEDESC2
*desc
, *mip_desc
;
5730 struct ddraw_texture
*texture
;
5731 unsigned int layers
= 1;
5732 unsigned int pitch
= 0;
5736 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5737 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5738 if (TRACE_ON(ddraw
))
5740 TRACE("Requesting surface desc:\n");
5741 DDRAW_dump_surface_desc(surface_desc
);
5745 return CLASS_E_NOAGGREGATION
;
5750 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5751 return E_OUTOFMEMORY
;
5753 texture
->version
= version
;
5754 texture
->surface_desc
= *surface_desc
;
5755 desc
= &texture
->surface_desc
;
5757 /* Ensure DDSD_CAPS is always set. */
5758 desc
->dwFlags
|= DDSD_CAPS
;
5760 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5762 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5764 WARN("Tried to create a flippable surface without any back buffers.\n");
5765 HeapFree(GetProcessHeap(), 0, texture
);
5766 return DDERR_INVALIDCAPS
;
5769 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
))
5771 WARN("Tried to create a flippable surface without DDSCAPS_COMPLEX.\n");
5772 HeapFree(GetProcessHeap(), 0, texture
);
5773 return DDERR_INVALIDCAPS
;
5776 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5778 WARN("Tried to create a flippable cubemap.\n");
5779 HeapFree(GetProcessHeap(), 0, texture
);
5780 return DDERR_INVALIDPARAMS
;
5783 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5785 FIXME("Flippable textures not implemented.\n");
5786 HeapFree(GetProcessHeap(), 0, texture
);
5787 return DDERR_INVALIDCAPS
;
5792 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
5794 WARN("Tried to specify a back buffer count for a non-flippable surface.\n");
5795 hr
= desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
? DDERR_INVALIDPARAMS
: DDERR_INVALIDCAPS
;
5796 HeapFree(GetProcessHeap(), 0, texture
);
5801 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5803 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5805 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5806 HeapFree(GetProcessHeap(), 0, texture
);
5807 return DDERR_INVALIDCAPS
;
5810 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
))
5812 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5813 HeapFree(GetProcessHeap(), 0, texture
);
5814 return DDERR_INVALIDCAPS
;
5817 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
) && !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5819 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5820 HeapFree(GetProcessHeap(), 0, texture
);
5821 return DDERR_NOEXCLUSIVEMODE
;
5825 /* This is a special case in ddrawex, but not allowed in ddraw. */
5826 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5827 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5829 WARN("Tried to create a surface in both system and video memory.\n");
5830 HeapFree(GetProcessHeap(), 0, texture
);
5831 return DDERR_INVALIDCAPS
;
5834 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_ALLOCONLOAD
| DDSCAPS_MIPMAP
))
5835 && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5837 WARN("Caps %#x require DDSCAPS_TEXTURE.\n", desc
->ddsCaps
.dwCaps
);
5838 HeapFree(GetProcessHeap(), 0, texture
);
5839 return DDERR_INVALIDCAPS
;
5842 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5843 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5845 WARN("Cube map faces requested without cube map flag.\n");
5846 HeapFree(GetProcessHeap(), 0, texture
);
5847 return DDERR_INVALIDCAPS
;
5850 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5851 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5853 WARN("Cube map without faces requested.\n");
5854 HeapFree(GetProcessHeap(), 0, texture
);
5855 return DDERR_INVALIDPARAMS
;
5858 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5859 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5860 FIXME("Partial cube maps not implemented.\n");
5862 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5864 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5866 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5867 HeapFree(GetProcessHeap(), 0, texture
);
5868 return DDERR_INVALIDCAPS
;
5870 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5872 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5873 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5874 HeapFree(GetProcessHeap(), 0, texture
);
5875 return DDERR_INVALIDCAPS
;
5879 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5881 ERR("Failed to get display mode, hr %#x.\n", hr
);
5882 HeapFree(GetProcessHeap(), 0, texture
);
5883 return hr_ddraw_from_wined3d(hr
);
5886 /* No pixelformat given? Use the current screen format. */
5887 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5889 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5890 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5891 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5894 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
5895 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5896 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5898 WARN("Unsupported / unknown pixelformat.\n");
5899 HeapFree(GetProcessHeap(), 0, texture
);
5900 return DDERR_INVALIDPIXELFORMAT
;
5903 /* No width or no height? Use the screen size. */
5904 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5906 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5908 WARN("No width / height specified.\n");
5909 HeapFree(GetProcessHeap(), 0, texture
);
5910 return DDERR_INVALIDPARAMS
;
5913 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5914 desc
->dwWidth
= mode
.width
;
5915 desc
->dwHeight
= mode
.height
;
5918 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5920 HeapFree(GetProcessHeap(), 0, texture
);
5921 return DDERR_INVALIDPARAMS
;
5924 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5925 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5927 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5929 /* The first surface is a front buffer, the back buffers are created
5931 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5932 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5934 struct wined3d_swapchain_desc swapchain_desc
;
5936 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5937 swapchain_desc
.backbuffer_width
= mode
.width
;
5938 swapchain_desc
.backbuffer_height
= mode
.height
;
5939 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5941 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5942 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5944 ERR("Failed to reset device.\n");
5945 HeapFree(GetProcessHeap(), 0, texture
);
5946 return hr_ddraw_from_wined3d(hr
);
5951 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5952 wined3d_desc
.multisample_quality
= 0;
5953 wined3d_desc
.usage
= 0;
5954 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5955 wined3d_desc
.width
= desc
->dwWidth
;
5956 wined3d_desc
.height
= desc
->dwHeight
;
5957 wined3d_desc
.depth
= 1;
5958 wined3d_desc
.size
= 0;
5960 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5962 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5963 /* Do not fail surface creation, only fail 3D device creation. */
5966 /* Mipmap count fixes */
5967 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5969 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5971 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5973 /* Mipmap count is given, should not be 0. */
5974 if (!desc
->u2
.dwMipMapCount
)
5976 HeapFree(GetProcessHeap(), 0, texture
);
5977 return DDERR_INVALIDPARAMS
;
5982 /* Undocumented feature: Create sublevels until either the
5983 * width or the height is 1. */
5985 desc
->u2
.dwMipMapCount
= wined3d_log2i(max(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5987 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5992 desc
->u2
.dwMipMapCount
= 1;
5995 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5996 levels
= desc
->u2
.dwMipMapCount
;
6003 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
6005 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
6009 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6010 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
| WINED3DUSAGE_TEXTURE
;
6011 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6012 usage
|= WINED3DUSAGE_TEXTURE
;
6014 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6015 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
6016 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6017 usage
= WINED3DUSAGE_RENDERTARGET
;
6019 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6020 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, WINED3D_RTYPE_TEXTURE_2D
, wined3d_desc
.format
)))
6021 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
6023 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6025 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
6027 /* Tests show surfaces without memory flags get these flags added
6028 * right after creation. */
6029 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
6033 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
6034 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
6036 WARN("System memory overlays are not allowed.\n");
6037 HeapFree(GetProcessHeap(), 0, texture
);
6038 return DDERR_NOOVERLAYHW
;
6041 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
6043 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
6047 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
6048 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
6049 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
6050 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
6051 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6052 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
6054 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
6056 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
6057 /* Managed textures have the system memory flag set. */
6058 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
6060 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
6062 /* Videomemory adds localvidmem. This is mutually exclusive with
6063 * systemmemory and texturemanage. */
6064 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
6065 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
6069 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6071 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
6073 WARN("User memory surfaces should be in the system memory pool.\n");
6074 HeapFree(GetProcessHeap(), 0, texture
);
6075 return DDERR_INVALIDCAPS
;
6080 WARN("User memory surfaces not supported before version 4.\n");
6081 HeapFree(GetProcessHeap(), 0, texture
);
6082 return DDERR_INVALIDPARAMS
;
6085 if (!desc
->lpSurface
)
6087 WARN("NULL surface memory pointer specified.\n");
6088 HeapFree(GetProcessHeap(), 0, texture
);
6089 return DDERR_INVALIDPARAMS
;
6092 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6094 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6096 WARN("Pitch specified on a compressed user memory surface.\n");
6097 HeapFree(GetProcessHeap(), 0, texture
);
6098 return DDERR_INVALIDPARAMS
;
6101 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6103 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6104 HeapFree(GetProcessHeap(), 0, texture
);
6105 return DDERR_INVALIDPARAMS
;
6108 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6109 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6110 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6112 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6113 HeapFree(GetProcessHeap(), 0, texture
);
6114 return DDERR_INVALIDPARAMS
;
6119 if (!(desc
->dwFlags
& DDSD_PITCH
))
6121 WARN("User memory surfaces should explicitly specify the pitch.\n");
6122 HeapFree(GetProcessHeap(), 0, texture
);
6123 return DDERR_INVALIDPARAMS
;
6126 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6127 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6129 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6130 HeapFree(GetProcessHeap(), 0, texture
);
6131 return DDERR_INVALIDPARAMS
;
6134 pitch
= desc
->u1
.lPitch
;
6138 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6139 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6140 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6141 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6142 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6143 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6144 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6145 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6147 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6148 HeapFree(GetProcessHeap(), 0, texture
);
6149 return DDERR_NOCOLORKEYHW
;
6152 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6153 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6155 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6156 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6158 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6160 wined3d_desc
.usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
6164 /* Some applications assume surfaces will always be mapped at the same
6165 * address. Some of those also assume that this address is valid even when
6166 * the surface isn't mapped, and that updates done this way will be
6167 * visible on the screen. The game Nox is such an application,
6168 * Commandos: Behind Enemy Lines is another. Setting
6169 * WINED3D_TEXTURE_CREATE_GET_DC_LENIENT will ensure this. */
6170 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, layers
, levels
,
6171 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
,
6172 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6174 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6175 HeapFree(GetProcessHeap(), 0, texture
);
6176 return hr_ddraw_from_wined3d(hr
);
6179 root
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6180 wined3d_texture_decref(wined3d_texture
);
6181 root
->is_complex_root
= TRUE
;
6182 texture
->root
= root
;
6183 wined3d_device_incref(texture
->wined3d_device
= ddraw
->wined3d_device
);
6185 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6186 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6187 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6188 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6189 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6190 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6191 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6192 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6193 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6194 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6195 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6196 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6198 for (i
= 0; i
< layers
; ++i
)
6200 attach
= &root
->complex_array
[layers
- 1 - i
];
6202 for (j
= 0; j
< levels
; ++j
)
6204 mip
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, i
* levels
+ j
);
6205 mip_desc
= &mip
->surface_desc
;
6209 wined3d_texture_get_sub_resource_desc(wined3d_texture
, i
* levels
+ j
, &wined3d_mip_desc
);
6210 mip_desc
->dwWidth
= wined3d_mip_desc
.width
;
6211 mip_desc
->dwHeight
= wined3d_mip_desc
.height
;
6213 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6217 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6220 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6222 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6226 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6227 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6229 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6230 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6232 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6233 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6235 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6236 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6238 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6239 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6241 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6242 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6252 attach
= &mip
->complex_array
[0];
6256 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6257 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6258 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6260 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6264 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6266 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6267 struct ddraw_surface
*last
= root
;
6269 attach
= &last
->complex_array
[0];
6270 for (i
= 0; i
< count
; ++i
)
6272 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6278 texture
->version
= version
;
6279 texture
->surface_desc
= root
->surface_desc
;
6280 desc
= &texture
->surface_desc
;
6282 /* Only one surface in the flipping chain is a back buffer, one is
6283 * a front buffer, the others are just flippable surfaces. */
6284 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6285 | DDSCAPS_BACKBUFFER
);
6287 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6288 desc
->u5
.dwBackBufferCount
= 0;
6290 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1, 1,
6291 WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
, NULL
, texture
,
6292 &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6294 HeapFree(GetProcessHeap(), 0, texture
);
6295 hr
= hr_ddraw_from_wined3d(hr
);
6299 last
= wined3d_texture_get_sub_resource_parent(wined3d_texture
, 0);
6300 wined3d_texture_decref(wined3d_texture
);
6301 texture
->root
= last
;
6302 wined3d_device_incref(texture
->wined3d_device
= ddraw
->wined3d_device
);
6304 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6305 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6306 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6307 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6308 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6309 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6310 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6311 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6312 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6313 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6314 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6315 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6318 attach
= &last
->complex_array
[0];
6323 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6324 ddraw
->primary
= root
;
6331 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6332 else if (version
== 4)
6333 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6335 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6340 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
6341 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
6342 const struct wined3d_parent_ops
**parent_ops
)
6344 struct ddraw_texture
*texture
= wined3d_texture_get_parent(wined3d_texture
);
6345 unsigned int texture_level
, row_pitch
, slice_pitch
;
6346 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6347 unsigned int version
= texture
->version
;
6349 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6350 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6351 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6352 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6353 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6354 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6355 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6356 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6357 surface
->iface_count
= 1;
6358 surface
->version
= version
;
6359 surface
->ddraw
= ddraw
;
6364 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6366 else if (version
== 4)
6369 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6374 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6377 *desc
= texture
->surface_desc
;
6378 surface
->first_attached
= surface
;
6380 texture_level
= desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
? sub_resource_idx
% desc
->u2
.dwMipMapCount
: 0;
6381 wined3d_texture_get_pitch(wined3d_texture
, texture_level
, &row_pitch
, &slice_pitch
);
6382 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6384 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6385 desc
->u1
.dwLinearSize
= ~0u;
6387 desc
->u1
.dwLinearSize
= slice_pitch
;
6388 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6389 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6393 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6394 desc
->u1
.lPitch
= row_pitch
;
6395 desc
->dwFlags
|= DDSD_PITCH
;
6396 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6398 desc
->lpSurface
= NULL
;
6400 wined3d_texture_incref(surface
->wined3d_texture
= wined3d_texture
);
6401 surface
->sub_resource_idx
= sub_resource_idx
;
6402 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6404 wined3d_private_store_init(&surface
->private_store
);
6407 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6409 struct ddraw_surface
*surface
= parent
;
6411 /* If the surface reference count drops to zero, we release our reference
6412 * to the view, but don't clear the pointer yet, in case e.g. a
6413 * GetRenderTarget() call brings the surface back before the view is
6414 * actually destroyed. When the view is destroyed, we need to clear the
6415 * pointer, or a subsequent surface AddRef() would reference it again.
6417 * This is safe because as long as the view still has a reference to the
6418 * texture, the surface is also still alive, and we're called before the
6419 * view releases that reference. */
6420 surface
->wined3d_rtv
= NULL
;
6423 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6425 view_wined3d_object_destroyed
,
6428 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6432 if (surface
->wined3d_rtv
)
6433 return surface
->wined3d_rtv
;
6435 if (FAILED(hr
= wined3d_rendertarget_view_create_from_sub_resource(surface
->wined3d_texture
,
6436 surface
->sub_resource_idx
, surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6438 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6442 return surface
->wined3d_rtv
;