1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "ddraw_private.h"
26 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
27 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
29 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
31 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
34 /* This is slow, of course. Also, in case of locks, we can't prevent other
35 * applications from drawing to the screen while we've locked the frontbuffer.
36 * We'd like to do this in wined3d instead, but for that to work wined3d needs
37 * to support windowless rendering first. */
38 HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
, const RECT
*rect
, BOOL read
)
40 HDC surface_dc
, screen_dc
;
49 w
= surface
->surface_desc
.dwWidth
;
50 h
= surface
->surface_desc
.dwHeight
;
56 w
= rect
->right
- rect
->left
;
57 h
= rect
->bottom
- rect
->top
;
63 if (surface
->ddraw
->swapchain_window
)
65 /* Nothing to do, we control the frontbuffer, or at least the parts we
70 return wined3d_surface_blt(surface
->ddraw
->wined3d_frontbuffer
, rect
,
71 surface
->wined3d_surface
, rect
, 0, NULL
, WINED3D_TEXF_POINT
);
74 if (FAILED(hr
= wined3d_surface_getdc(surface
->wined3d_surface
, &surface_dc
)))
76 ERR("Failed to get surface DC, hr %#x.\n", hr
);
80 wined3d_palette_apply_to_dc(surface
->palette
->wineD3DPalette
, surface_dc
);
82 if (!(screen_dc
= GetDC(NULL
)))
84 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
85 ERR("Failed to get screen DC.\n");
90 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
91 screen_dc
, x
, y
, SRCCOPY
);
93 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
94 surface_dc
, x
, y
, SRCCOPY
);
96 ReleaseDC(NULL
, screen_dc
);
97 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
101 ERR("Failed to blit to/from screen.\n");
108 /*****************************************************************************
109 * IUnknown parts follow
110 *****************************************************************************/
112 /*****************************************************************************
113 * IDirectDrawSurface7::QueryInterface
115 * A normal QueryInterface implementation. For QueryInterface rules
116 * see ddraw.c, IDirectDraw7::QueryInterface. This method
117 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
118 * in all versions, the IDirectDrawGammaControl interface and it can
119 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
122 * riid: The interface id queried for
123 * obj: Address to write the pointer to
127 * E_NOINTERFACE if the requested interface wasn't found
129 *****************************************************************************/
130 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
132 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
134 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
136 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
140 return DDERR_INVALIDPARAMS
;
142 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface7
))
144 IDirectDrawSurface7_AddRef(iface
);
146 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
150 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
152 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
153 *obj
= &This
->IDirectDrawSurface4_iface
;
154 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
158 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
160 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
161 *obj
= &This
->IDirectDrawSurface3_iface
;
162 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
166 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
168 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
169 *obj
= &This
->IDirectDrawSurface2_iface
;
170 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
174 if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
)
175 || IsEqualGUID(riid
, &IID_IUnknown
))
177 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
178 *obj
= &This
->IDirectDrawSurface_iface
;
179 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
183 if (IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
))
185 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
186 *obj
= &This
->IDirectDrawGammaControl_iface
;
187 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
191 if (IsEqualGUID(riid
, &IID_IDirectDrawColorControl
))
193 WARN("Color control not implemented.\n");
195 return E_NOINTERFACE
;
198 if (This
->version
!= 7)
200 if (IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
)
201 || IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)
202 || IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
))
204 wined3d_mutex_lock();
209 if (FAILED(hr
= d3d_device_create(This
->ddraw
, riid
, This
, (IUnknown
*)&This
->IDirectDrawSurface_iface
,
210 1, &This
->device1
, (IUnknown
*)&This
->IDirectDrawSurface_iface
)))
212 This
->device1
= NULL
;
213 wined3d_mutex_unlock();
214 WARN("Failed to create device, hr %#x.\n", hr
);
218 wined3d_mutex_unlock();
220 IDirect3DDevice_AddRef(&This
->device1
->IDirect3DDevice_iface
);
221 *obj
= &This
->device1
->IDirect3DDevice_iface
;
225 if (IsEqualGUID(&IID_IDirect3DTexture2
, riid
))
227 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture2_iface
);
228 *obj
= &This
->IDirect3DTexture2_iface
;
232 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
234 IDirect3DTexture2_AddRef(&This
->IDirect3DTexture_iface
);
235 *obj
= &This
->IDirect3DTexture_iface
;
240 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
242 if (This
->version
!= 7)
245 return E_NOINTERFACE
;
248 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
250 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
252 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
254 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
257 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
259 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
261 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
263 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
266 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
268 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
270 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
272 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
275 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
277 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
279 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
281 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
284 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
285 REFIID riid
, void **object
)
287 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
289 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
291 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
294 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
296 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
298 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
300 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
303 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
305 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
307 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
309 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
312 static void ddraw_surface_add_iface(struct ddraw_surface
*surface
)
314 ULONG iface_count
= InterlockedIncrement(&surface
->iface_count
);
315 TRACE("%p increasing iface count to %u.\n", surface
, iface_count
);
317 if (iface_count
== 1)
319 if (surface
->ifaceToRelease
)
320 IUnknown_AddRef(surface
->ifaceToRelease
);
321 wined3d_mutex_lock();
322 if (surface
->wined3d_rtv
)
323 wined3d_rendertarget_view_incref(surface
->wined3d_rtv
);
324 if (surface
->wined3d_surface
)
325 wined3d_surface_incref(surface
->wined3d_surface
);
326 if (surface
->wined3d_texture
)
327 wined3d_texture_incref(surface
->wined3d_texture
);
328 wined3d_mutex_unlock();
332 /*****************************************************************************
333 * IDirectDrawSurface7::AddRef
335 * A normal addref implementation
340 *****************************************************************************/
341 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
343 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
344 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
346 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
350 ddraw_surface_add_iface(This
);
356 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
358 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
359 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
361 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
365 ddraw_surface_add_iface(This
);
371 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
373 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
374 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
376 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
380 ddraw_surface_add_iface(This
);
386 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
388 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
389 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
391 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
395 ddraw_surface_add_iface(This
);
401 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
403 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
404 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
406 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
410 ddraw_surface_add_iface(This
);
416 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
418 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
419 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
421 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
425 ddraw_surface_add_iface(This
);
431 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
433 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
435 TRACE("iface %p.\n", iface
);
437 return IUnknown_AddRef(surface
->texture_outer
);
440 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
442 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
444 TRACE("iface %p.\n", iface
);
446 return IUnknown_AddRef(surface
->texture_outer
);
449 static HRESULT
ddraw_surface_set_palette(struct ddraw_surface
*surface
, IDirectDrawPalette
*palette
)
451 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(palette
);
452 struct ddraw_palette
*prev
;
454 TRACE("iface %p, palette %p.\n", surface
, palette
);
456 if (palette_impl
&& palette_impl
->flags
& DDPCAPS_ALPHA
457 && !(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
459 WARN("Alpha palette set on non-texture surface, returning DDERR_INVALIDSURFACETYPE.\n");
460 return DDERR_INVALIDSURFACETYPE
;
463 if (!format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
464 return DDERR_INVALIDPIXELFORMAT
;
466 wined3d_mutex_lock();
468 prev
= surface
->palette
;
469 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
472 prev
->flags
&= ~DDPCAPS_PRIMARYSURFACE
;
474 palette_impl
->flags
|= DDPCAPS_PRIMARYSURFACE
;
475 wined3d_swapchain_set_palette(surface
->ddraw
->wined3d_swapchain
,
476 palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
477 ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
480 IDirectDrawPalette_AddRef(&palette_impl
->IDirectDrawPalette_iface
);
482 IDirectDrawPalette_Release(&prev
->IDirectDrawPalette_iface
);
483 surface
->palette
= palette_impl
;
485 wined3d_mutex_unlock();
490 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
492 struct ddraw_surface
*surf
;
495 TRACE("surface %p.\n", surface
);
497 /* The refcount test shows that the palette is detached when the surface
499 ddraw_surface_set_palette(surface
, NULL
);
501 /* Loop through all complex attached surfaces and destroy them.
503 * Yet again, only the root can have more than one complexly attached
504 * surface, all the others have a total of one. */
505 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
507 if (!surface
->complex_array
[i
])
510 surf
= surface
->complex_array
[i
];
511 surface
->complex_array
[i
] = NULL
;
512 if (!surf
->is_complex_root
)
513 ddraw_surface_cleanup(surf
);
516 if (surface
->device1
)
517 IUnknown_Release(&surface
->device1
->IUnknown_inner
);
519 if (surface
->iface_count
> 1)
521 /* This can happen when a complex surface is destroyed, because the
522 * 2nd surface was addref()ed when the app called
523 * GetAttachedSurface(). */
524 WARN("Destroying surface %p with refcounts 7: %u 4: %u 3: %u 2: %u 1: %u.\n",
525 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
, surface
->ref2
, surface
->ref1
);
528 if (surface
->wined3d_rtv
)
529 wined3d_rendertarget_view_decref(surface
->wined3d_rtv
);
530 if (surface
->wined3d_texture
)
531 wined3d_texture_decref(surface
->wined3d_texture
);
532 if (surface
->wined3d_surface
)
533 wined3d_surface_decref(surface
->wined3d_surface
);
536 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
538 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
539 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
541 if (iface_count
== 0)
543 IUnknown
*release_iface
= This
->ifaceToRelease
;
545 /* Complex attached surfaces are destroyed implicitly when the root is released */
546 wined3d_mutex_lock();
547 if(!This
->is_complex_root
)
549 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
550 wined3d_mutex_unlock();
553 ddraw_surface_cleanup(This
);
554 wined3d_mutex_unlock();
557 IUnknown_Release(release_iface
);
563 /*****************************************************************************
564 * IDirectDrawSurface7::Release
566 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
567 * surface is destroyed.
569 * Destroying the surface is a bit tricky. For the connection between
570 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
571 * It has a nice graph explaining the connection.
573 * What happens here is basically this:
574 * When a surface is destroyed, its WineD3DSurface is released,
575 * and the refcount of the DirectDraw interface is reduced by 1. If it has
576 * complex surfaces attached to it, then these surfaces are destroyed too,
577 * regardless of their refcount. If any surface being destroyed has another
578 * surface attached to it (with a "soft" attachment, not complex), then
579 * this surface is detached with DeleteAttachedSurface.
581 * When the surface is a texture, the WineD3DTexture is released.
582 * If the surface is the Direct3D render target, then the D3D
583 * capabilities of the WineD3DDevice are uninitialized, which causes the
584 * swapchain to be released.
586 * When a complex sublevel falls to ref zero, then this is ignored.
591 *****************************************************************************/
592 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
594 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
595 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
597 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
601 ddraw_surface_release_iface(This
);
607 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
609 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
610 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
612 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
616 ddraw_surface_release_iface(This
);
622 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
624 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
625 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
627 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
631 ddraw_surface_release_iface(This
);
637 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
639 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
640 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
642 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
646 ddraw_surface_release_iface(This
);
652 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
654 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
655 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
657 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
661 ddraw_surface_release_iface(This
);
667 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
669 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
670 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
672 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
676 ddraw_surface_release_iface(This
);
682 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
684 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
686 TRACE("iface %p.\n", iface
);
688 return IUnknown_Release(surface
->texture_outer
);
691 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
693 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
695 TRACE("iface %p.\n", iface
);
697 return IUnknown_Release(surface
->texture_outer
);
700 /*****************************************************************************
701 * IDirectDrawSurface7::GetAttachedSurface
703 * Returns an attached surface with the requested caps. Surface attachment
704 * and complex surfaces are not clearly described by the MSDN or sdk,
705 * so this method is tricky and likely to contain problems.
706 * This implementation searches the complex list first, then the
709 * The chains are searched from This down to the last surface in the chain,
710 * not from the first element in the chain. The first surface found is
711 * returned. The MSDN says that this method fails if more than one surface
712 * matches the caps, but it is not sure if that is right. The attachment
713 * structure may not even allow two matching surfaces.
715 * The found surface is AddRef-ed before it is returned.
718 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
719 * Surface: Address to store the found surface
723 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
724 * DDERR_NOTFOUND if no surface was found
726 *****************************************************************************/
727 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
728 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
730 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
731 struct ddraw_surface
*surf
;
735 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
737 wined3d_mutex_lock();
739 if(This
->version
< 7)
741 /* Earlier dx apps put garbage into these members, clear them */
742 our_caps
.dwCaps
= Caps
->dwCaps
;
743 our_caps
.dwCaps2
= 0;
744 our_caps
.dwCaps3
= 0;
745 our_caps
.u1
.dwCaps4
= 0;
752 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 */
754 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
756 surf
= This
->complex_array
[i
];
759 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
760 surf
->surface_desc
.ddsCaps
.dwCaps
,
761 surf
->surface_desc
.ddsCaps
.dwCaps2
,
762 surf
->surface_desc
.ddsCaps
.dwCaps3
,
763 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
765 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
766 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
768 /* MSDN: "This method fails if more than one surface is attached
769 * that matches the capabilities requested."
771 * Not sure how to test this.
774 TRACE("(%p): Returning surface %p\n", This
, surf
);
775 *Surface
= &surf
->IDirectDrawSurface7_iface
;
776 ddraw_surface7_AddRef(*Surface
);
777 wined3d_mutex_unlock();
783 /* Next, look at the attachment chain */
786 while( (surf
= surf
->next_attached
) )
788 TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf
,
789 surf
->surface_desc
.ddsCaps
.dwCaps
,
790 surf
->surface_desc
.ddsCaps
.dwCaps2
,
791 surf
->surface_desc
.ddsCaps
.dwCaps3
,
792 surf
->surface_desc
.ddsCaps
.u1
.dwCaps4
);
794 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
795 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
797 TRACE("(%p): Returning surface %p\n", This
, surf
);
798 *Surface
= &surf
->IDirectDrawSurface7_iface
;
799 ddraw_surface7_AddRef(*Surface
);
800 wined3d_mutex_unlock();
805 TRACE("(%p) Didn't find a valid surface\n", This
);
807 wined3d_mutex_unlock();
810 return DDERR_NOTFOUND
;
813 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
814 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
816 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
817 struct ddraw_surface
*attachment_impl
;
818 IDirectDrawSurface7
*attachment7
;
821 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
823 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
830 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
831 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
832 ddraw_surface4_AddRef(*attachment
);
833 ddraw_surface7_Release(attachment7
);
838 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
839 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
841 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
842 struct ddraw_surface
*attachment_impl
;
843 IDirectDrawSurface7
*attachment7
;
847 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
849 caps2
.dwCaps
= caps
->dwCaps
;
852 caps2
.u1
.dwCaps4
= 0;
854 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
855 &caps2
, &attachment7
);
861 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
862 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
863 ddraw_surface3_AddRef(*attachment
);
864 ddraw_surface7_Release(attachment7
);
869 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
870 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
872 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
873 struct ddraw_surface
*attachment_impl
;
874 IDirectDrawSurface7
*attachment7
;
878 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
880 caps2
.dwCaps
= caps
->dwCaps
;
883 caps2
.u1
.dwCaps4
= 0;
885 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
886 &caps2
, &attachment7
);
892 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
893 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
894 ddraw_surface2_AddRef(*attachment
);
895 ddraw_surface7_Release(attachment7
);
900 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
901 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
903 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
904 struct ddraw_surface
*attachment_impl
;
905 IDirectDrawSurface7
*attachment7
;
909 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
911 caps2
.dwCaps
= caps
->dwCaps
;
914 caps2
.u1
.dwCaps4
= 0;
916 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
917 &caps2
, &attachment7
);
923 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
924 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
925 ddraw_surface1_AddRef(*attachment
);
926 ddraw_surface7_Release(attachment7
);
931 /*****************************************************************************
932 * IDirectDrawSurface7::Lock
934 * Locks the surface and returns a pointer to the surface's memory
937 * Rect: Rectangle to lock. If NULL, the whole surface is locked
938 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
939 * Flags: Locking flags, e.g Read only or write only
940 * h: An event handle that's not used and must be NULL
944 * DDERR_INVALIDPARAMS if DDSD is NULL
945 * For more details, see IWineD3DSurface::LockRect
947 *****************************************************************************/
948 static HRESULT
surface_lock(struct ddraw_surface
*This
,
949 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
951 struct wined3d_box box
;
952 struct wined3d_map_desc map_desc
;
955 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
956 This
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
958 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
959 wined3d_mutex_lock();
961 /* Should I check for the handle to be NULL?
963 * The DDLOCK flags and the D3DLOCK flags are equal
964 * for the supported values. The others are ignored by WineD3D
967 /* Windows zeroes this if the rect is invalid */
974 || (Rect
->left
> Rect
->right
)
975 || (Rect
->top
> Rect
->bottom
)
976 || (Rect
->right
> This
->surface_desc
.dwWidth
)
977 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
979 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
980 wined3d_mutex_unlock();
981 return DDERR_INVALIDPARAMS
;
983 box
.left
= Rect
->left
;
985 box
.right
= Rect
->right
;
986 box
.bottom
= Rect
->bottom
;
991 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
992 hr
= ddraw_surface_update_frontbuffer(This
, Rect
, TRUE
);
994 hr
= wined3d_surface_map(This
->wined3d_surface
, &map_desc
, Rect
? &box
: NULL
, Flags
);
997 wined3d_mutex_unlock();
1000 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
1001 * specific error. But since IWineD3DSurface::LockRect returns that error in this
1002 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
1003 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
1004 * is much easier to do it in one place in ddraw
1006 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
1011 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1013 if (Flags
& DDLOCK_READONLY
)
1014 memset(&This
->ddraw
->primary_lock
, 0, sizeof(This
->ddraw
->primary_lock
));
1016 This
->ddraw
->primary_lock
= *Rect
;
1018 SetRect(&This
->ddraw
->primary_lock
, 0, 0, This
->surface_desc
.dwWidth
, This
->surface_desc
.dwHeight
);
1021 /* Windows does not set DDSD_LPSURFACE on locked surfaces. */
1022 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
1023 DDSD
->lpSurface
= map_desc
.data
;
1025 TRACE("locked surface returning description :\n");
1026 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1028 wined3d_mutex_unlock();
1033 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
1034 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1036 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1038 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1039 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1041 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1042 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1043 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1045 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1046 return DDERR_INVALIDPARAMS
;
1048 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1051 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1052 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1054 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1056 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1057 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1059 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1060 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1061 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1063 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1064 return DDERR_INVALIDPARAMS
;
1066 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1069 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1070 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1072 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1073 DDSURFACEDESC2 surface_desc2
;
1076 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1077 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1079 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1080 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1081 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1083 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1084 return DDERR_INVALIDPARAMS
;
1087 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1088 surface_desc2
.dwFlags
= 0;
1089 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1090 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1091 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1095 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1096 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1098 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1099 DDSURFACEDESC2 surface_desc2
;
1102 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1103 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1105 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1106 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1107 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1109 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1110 return DDERR_INVALIDPARAMS
;
1113 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1114 surface_desc2
.dwFlags
= 0;
1115 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1116 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1117 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1121 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1122 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1124 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1125 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_desc
) return DDERR_INVALIDPARAMS
;
1131 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1132 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1134 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1135 return DDERR_INVALIDPARAMS
;
1138 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1139 surface_desc2
.dwFlags
= 0;
1140 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1141 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1142 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1146 /*****************************************************************************
1147 * IDirectDrawSurface7::Unlock
1149 * Unlocks an locked surface
1152 * Rect: Not used by this implementation
1156 * For more details, see IWineD3DSurface::UnlockRect
1158 *****************************************************************************/
1159 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1161 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1164 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1166 wined3d_mutex_lock();
1167 hr
= wined3d_surface_unmap(surface
->wined3d_surface
);
1168 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1169 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1170 wined3d_mutex_unlock();
1175 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1177 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1179 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1181 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1184 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1188 TRACE("iface %p, data %p.\n", iface
, data
);
1190 /* data might not be the LPRECT of later versions, so drop it. */
1191 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1194 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1196 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1198 TRACE("iface %p, data %p.\n", iface
, data
);
1200 /* data might not be the LPRECT of later versions, so drop it. */
1201 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1204 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1206 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1208 TRACE("iface %p, data %p.\n", iface
, data
);
1210 /* data might not be the LPRECT of later versions, so drop it. */
1211 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1214 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
,
1215 IDirectDrawSurface7
*src
, DWORD flags
)
1217 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1218 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface7(src
);
1219 struct wined3d_rendertarget_view
*tmp_rtv
, *src_rtv
, *rtv
;
1220 struct ddraw_texture
*ddraw_texture
, *prev_ddraw_texture
;
1221 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
1222 struct wined3d_texture
*texture
;
1223 IDirectDrawSurface7
*current
;
1224 struct wined3d_surface
*tmp
;
1227 TRACE("iface %p, src %p, flags %#x.\n", iface
, src
, flags
);
1229 if (src
== iface
|| !(dst_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1230 return DDERR_NOTFLIPPABLE
;
1232 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
1233 return DDERR_SURFACELOST
;
1235 wined3d_mutex_lock();
1237 tmp_rtv
= ddraw_surface_get_rendertarget_view(dst_impl
);
1238 tmp
= dst_impl
->wined3d_surface
;
1239 texture
= dst_impl
->wined3d_texture
;
1240 rtv
= wined3d_device_get_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0);
1241 ddraw_texture
= wined3d_texture_get_parent(dst_impl
->wined3d_texture
);
1245 for (current
= iface
; current
!= src
;)
1247 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1249 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1250 wined3d_mutex_unlock();
1251 return DDERR_NOTFLIPPABLE
;
1253 ddraw_surface7_Release(current
);
1254 if (current
== iface
)
1256 WARN("Surface %p is not on the same flip chain as surface %p.\n", src
, iface
);
1257 wined3d_mutex_unlock();
1258 return DDERR_NOTFLIPPABLE
;
1262 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1263 if (rtv
== dst_impl
->wined3d_rtv
)
1264 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1265 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1266 dst_impl
->wined3d_rtv
= src_rtv
;
1267 wined3d_resource_set_parent(wined3d_surface_get_resource(src_impl
->wined3d_surface
), dst_impl
);
1268 dst_impl
->wined3d_surface
= src_impl
->wined3d_surface
;
1269 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1270 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1271 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1272 ddraw_texture
= prev_ddraw_texture
;
1276 for (current
= iface
;;)
1278 if (FAILED(hr
= ddraw_surface7_GetAttachedSurface(current
, &caps
, ¤t
)))
1280 ERR("Can't find a flip target\n");
1281 wined3d_mutex_unlock();
1282 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1284 ddraw_surface7_Release(current
);
1285 if (current
== iface
)
1287 dst_impl
= impl_from_IDirectDrawSurface7(iface
);
1291 src_impl
= impl_from_IDirectDrawSurface7(current
);
1292 src_rtv
= ddraw_surface_get_rendertarget_view(src_impl
);
1293 if (rtv
== dst_impl
->wined3d_rtv
)
1294 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, src_rtv
, FALSE
);
1295 wined3d_rendertarget_view_set_parent(src_rtv
, dst_impl
);
1296 dst_impl
->wined3d_rtv
= src_rtv
;
1297 wined3d_resource_set_parent(wined3d_surface_get_resource(src_impl
->wined3d_surface
), dst_impl
);
1298 dst_impl
->wined3d_surface
= src_impl
->wined3d_surface
;
1299 prev_ddraw_texture
= wined3d_texture_get_parent(src_impl
->wined3d_texture
);
1300 wined3d_resource_set_parent(wined3d_texture_get_resource(src_impl
->wined3d_texture
), ddraw_texture
);
1301 ddraw_texture
= prev_ddraw_texture
;
1302 dst_impl
->wined3d_texture
= src_impl
->wined3d_texture
;
1303 dst_impl
= src_impl
;
1307 /* We don't have to worry about potential texture bindings, since
1308 * flippable surfaces can never be textures. */
1309 if (rtv
== src_impl
->wined3d_rtv
)
1310 wined3d_device_set_rendertarget_view(dst_impl
->ddraw
->wined3d_device
, 0, tmp_rtv
, FALSE
);
1311 wined3d_rendertarget_view_set_parent(tmp_rtv
, src_impl
);
1312 src_impl
->wined3d_rtv
= tmp_rtv
;
1313 wined3d_resource_set_parent(wined3d_surface_get_resource(tmp
), src_impl
);
1314 src_impl
->wined3d_surface
= tmp
;
1315 wined3d_resource_set_parent(wined3d_texture_get_resource(texture
), ddraw_texture
);
1316 src_impl
->wined3d_texture
= texture
;
1322 FIXME("Ignoring flags %#x.\n", flags
);
1324 WARN("Ignoring flags %#x.\n", flags
);
1327 if (dst_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1328 hr
= ddraw_surface_update_frontbuffer(dst_impl
, NULL
, FALSE
);
1332 wined3d_mutex_unlock();
1337 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
,
1338 IDirectDrawSurface4
*dst
, DWORD flags
)
1340 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1341 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1343 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1345 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1346 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1349 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
,
1350 IDirectDrawSurface3
*dst
, DWORD flags
)
1352 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1353 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1355 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1357 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1358 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1361 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
,
1362 IDirectDrawSurface2
*dst
, DWORD flags
)
1364 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1365 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1367 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1369 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1370 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1373 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Flip(IDirectDrawSurface
*iface
,
1374 IDirectDrawSurface
*dst
, DWORD flags
)
1376 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1377 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1379 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1381 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1382 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1385 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1386 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1387 const WINEDDBLTFX
*fx
, enum wined3d_texture_filter_type filter
)
1389 struct wined3d_surface
*wined3d_src_surface
= src_surface
? src_surface
->wined3d_surface
: NULL
;
1390 RECT src_rect
, dst_rect
;
1391 float scale_x
, scale_y
;
1392 const RECT
*clip_rect
;
1393 UINT clip_list_size
;
1398 if (!dst_surface
->clipper
)
1400 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1401 hr
= ddraw_surface_update_frontbuffer(src_surface
, src_rect_in
, TRUE
);
1403 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, dst_rect_in
,
1404 wined3d_src_surface
, src_rect_in
, flags
, fx
, filter
);
1405 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
1406 hr
= ddraw_surface_update_frontbuffer(dst_surface
, dst_rect_in
, FALSE
);
1415 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1416 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1420 dst_rect
= *dst_rect_in
;
1423 if (IsRectEmpty(&dst_rect
))
1424 return DDERR_INVALIDRECT
;
1432 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1433 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1437 src_rect
= *src_rect_in
;
1440 if (IsRectEmpty(&src_rect
))
1441 return DDERR_INVALIDRECT
;
1445 SetRect(&src_rect
, 0, 0, 0, 0);
1448 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1449 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1451 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1452 &dst_rect
, NULL
, &clip_list_size
)))
1454 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1458 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1460 WARN("Failed to allocate clip list.\n");
1461 return E_OUTOFMEMORY
;
1464 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1465 &dst_rect
, clip_list
, &clip_list_size
)))
1467 WARN("Failed to get clip list, hr %#x.\n", hr
);
1468 HeapFree(GetProcessHeap(), 0, clip_list
);
1472 clip_rect
= (RECT
*)clip_list
->Buffer
;
1473 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1475 RECT src_rect_clipped
= src_rect
;
1479 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1480 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1481 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1482 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1484 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1486 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1491 if (FAILED(hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, &clip_rect
[i
],
1492 wined3d_src_surface
, &src_rect_clipped
, flags
, fx
, filter
)))
1495 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1497 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1502 HeapFree(GetProcessHeap(), 0, clip_list
);
1506 /*****************************************************************************
1507 * IDirectDrawSurface7::Blt
1509 * Performs a blit on the surface
1512 * DestRect: Destination rectangle, can be NULL
1513 * SrcSurface: Source surface, can be NULL
1514 * SrcRect: Source rectangle, can be NULL
1516 * DDBltFx: Some extended blt parameters, connected to the flags
1520 * See IWineD3DSurface::Blt for more details
1522 *****************************************************************************/
1523 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1524 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1526 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1527 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1531 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1532 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1534 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1535 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1537 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1538 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1539 return DDERR_INVALIDPARAMS
;
1542 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1543 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1544 return DDERR_INVALIDPARAMS
;
1547 wined3d_mutex_lock();
1549 if (Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1551 if (Flags
& DDBLT_ROP
)
1553 wined3d_mutex_unlock();
1554 WARN("DDBLT_ROP used with DDBLT_COLORFILL or DDBLT_DEPTHFILL, returning DDERR_INVALIDPARAMS.\n");
1555 return DDERR_INVALIDPARAMS
;
1559 wined3d_mutex_unlock();
1560 WARN("Depth or colorfill is not compatible with source surfaces, returning DDERR_INVALIDPARAMS\n");
1561 return DDERR_INVALIDPARAMS
;
1565 wined3d_mutex_unlock();
1566 WARN("Depth or colorfill used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1567 return DDERR_INVALIDPARAMS
;
1570 if ((Flags
& (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
)) == (DDBLT_COLORFILL
| DDBLT_DEPTHFILL
))
1571 Flags
&= ~DDBLT_DEPTHFILL
;
1573 if ((dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_COLORFILL
))
1575 wined3d_mutex_unlock();
1576 WARN("DDBLT_COLORFILL used on a depth buffer, returning DDERR_INVALIDPARAMS.\n");
1577 return DDERR_INVALIDPARAMS
;
1579 if (!(dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) && (Flags
& DDBLT_DEPTHFILL
))
1581 wined3d_mutex_unlock();
1582 WARN("DDBLT_DEPTHFILL used on a color buffer, returning DDERR_INVALIDPARAMS.\n");
1583 return DDERR_INVALIDPARAMS
;
1587 if (Flags
& DDBLT_ROP
)
1591 wined3d_mutex_unlock();
1592 WARN("DDBLT_ROP used with DDBltFx = NULL, returning DDERR_INVALIDPARAMS.\n");
1593 return DDERR_INVALIDPARAMS
;
1596 Flags
&= ~DDBLT_ROP
;
1597 switch (DDBltFx
->dwROP
)
1606 if (DDBltFx
->dwROP
== WHITENESS
)
1607 rop_fx
.u5
.dwFillColor
= 0xffffffff;
1609 rop_fx
.u5
.dwFillColor
= 0;
1611 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1612 Flags
|= DDBLT_DEPTHFILL
;
1614 Flags
|= DDBLT_COLORFILL
;
1620 wined3d_mutex_unlock();
1621 WARN("Unsupported ROP %#x used, returning DDERR_NORASTEROPHW.\n", DDBltFx
->dwROP
);
1622 return DDERR_NORASTEROPHW
;
1626 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1628 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1629 wined3d_mutex_unlock();
1630 return DDERR_INVALIDPARAMS
;
1633 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1634 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1635 * surfaces. So far no blitting operations using surfaces in the bltfx
1636 * struct are supported anyway. */
1637 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1638 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1640 wined3d_mutex_unlock();
1643 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1644 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1649 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1650 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1652 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1653 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1655 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1656 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1658 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1659 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1662 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1663 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1665 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1666 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1668 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1669 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1671 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1672 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1675 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1676 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1678 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1679 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1681 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1682 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1684 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1685 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1688 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1689 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1691 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1692 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1694 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1695 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1697 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1698 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1701 /*****************************************************************************
1702 * IDirectDrawSurface7::AddAttachedSurface
1704 * Attaches a surface to another surface. How the surface attachments work
1705 * is not totally understood yet, and this method is prone to problems.
1706 * The surface that is attached is AddRef-ed.
1708 * Tests with complex surfaces suggest that the surface attachments form a
1709 * tree, but no method to test this has been found yet.
1711 * The attachment list consists of a first surface (first_attached) and
1712 * for each surface a pointer to the next attached surface (next_attached).
1713 * For the first surface, and a surface that has no attachments
1714 * first_attached points to the surface itself. A surface that has
1715 * no successors in the chain has next_attached set to NULL.
1717 * Newly attached surfaces are attached right after the root surface.
1718 * If a surface is attached to a complex surface compound, it's attached to
1719 * the surface that the app requested, not the complex root. See
1720 * GetAttachedSurface for a description how surfaces are found.
1722 * This is how the current implementation works, and it was coded by looking
1723 * at the needs of the applications.
1725 * So far only Z-Buffer attachments are tested, and they are activated in
1726 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1727 * Back buffers should work in 2D mode, but they are not tested(They can be
1728 * attached in older iface versions). Rendering to the front buffer and
1729 * switching between that and double buffering is not yet implemented in
1730 * WineD3D, so for 3D it might have unexpected results.
1732 * ddraw_surface_attach_surface is the real thing,
1733 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1734 * performs additional checks. Version 7 of this interface is much more restrictive
1735 * than its predecessors.
1738 * Attach: Surface to attach to iface
1742 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1744 *****************************************************************************/
1745 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1747 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1750 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1752 wined3d_mutex_lock();
1754 /* Check if the surface is already attached somewhere */
1755 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1757 /* TODO: Test for the structure of the manual attachment. Is it a
1758 * chain or a list? What happens if one surface is attached to 2
1759 * different surfaces? */
1760 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1761 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1763 wined3d_mutex_unlock();
1764 return DDERR_SURFACEALREADYATTACHED
;
1767 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1768 Surf
->next_attached
= This
->next_attached
;
1769 Surf
->first_attached
= This
->first_attached
;
1770 This
->next_attached
= Surf
;
1772 /* Check if the WineD3D depth stencil needs updating */
1773 if (This
->ddraw
->d3ddevice
)
1774 d3d_device_update_depth_stencil(This
->ddraw
->d3ddevice
);
1776 wined3d_mutex_unlock();
1781 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1783 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1784 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1787 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1789 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1790 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1793 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1794 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1795 return DDERR_CANNOTATTACHSURFACE
;
1798 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1803 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1804 IUnknown_AddRef(attachment_impl
->attached_iface
);
1808 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1810 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1811 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1814 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1816 /* Tests suggest that
1817 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1818 * -> offscreen plain surfaces can be attached to primaries
1819 * -> primaries can be attached to offscreen plain surfaces
1820 * -> z buffers can be attached to primaries */
1821 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1822 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1824 /* Sizes have to match */
1825 if (attachment_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1826 || attachment_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1828 WARN("Surface sizes do not match.\n");
1829 return DDERR_CANNOTATTACHSURFACE
;
1832 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
1833 || !(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
)))
1835 WARN("Invalid attachment combination.\n");
1836 return DDERR_CANNOTATTACHSURFACE
;
1839 if (FAILED(hr
= ddraw_surface_attach_surface(surface
, attachment_impl
)))
1842 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1843 IUnknown_AddRef(attachment_impl
->attached_iface
);
1847 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1849 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1850 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1853 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1855 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1856 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1859 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1860 IUnknown_AddRef(attachment_impl
->attached_iface
);
1861 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1865 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1867 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1868 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1871 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1873 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1874 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1877 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1878 IUnknown_AddRef(attachment_impl
->attached_iface
);
1879 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1883 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1885 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1886 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1889 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1891 if (FAILED(hr
= ddraw_surface4_AddAttachedSurface(&surface
->IDirectDrawSurface4_iface
,
1892 attachment_impl
? &attachment_impl
->IDirectDrawSurface4_iface
: NULL
)))
1895 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1896 IUnknown_AddRef(attachment_impl
->attached_iface
);
1897 ddraw_surface4_Release(&attachment_impl
->IDirectDrawSurface4_iface
);
1901 /*****************************************************************************
1902 * IDirectDrawSurface7::DeleteAttachedSurface
1904 * Removes a surface from the attachment chain. The surface's refcount
1905 * is decreased by one after it has been removed
1908 * Flags: Some flags, not used by this implementation
1909 * Attach: Surface to detach
1913 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1915 *****************************************************************************/
1916 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1917 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1919 struct ddraw_surface
*prev
= surface
;
1921 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1923 wined3d_mutex_lock();
1924 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1926 wined3d_mutex_unlock();
1927 return DDERR_CANNOTDETACHSURFACE
;
1930 if (attachment
->attached_iface
!= detach_iface
)
1932 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1933 wined3d_mutex_unlock();
1934 return DDERR_SURFACENOTATTACHED
;
1937 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1938 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1940 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1941 /* FIXME: we should probably also subtract from dwMipMapCount of this
1942 * and all parent surfaces */
1945 /* Find the predecessor of the detached surface */
1948 if (prev
->next_attached
== attachment
)
1950 prev
= prev
->next_attached
;
1953 /* There must be a surface, otherwise there's a bug */
1956 /* Unchain the surface */
1957 prev
->next_attached
= attachment
->next_attached
;
1958 attachment
->next_attached
= NULL
;
1959 attachment
->first_attached
= attachment
;
1961 /* Check if the wined3d depth stencil needs updating. */
1962 if (surface
->ddraw
->d3ddevice
)
1963 d3d_device_update_depth_stencil(surface
->ddraw
->d3ddevice
);
1964 wined3d_mutex_unlock();
1966 /* Set attached_iface to NULL before releasing it, the surface may go
1968 attachment
->attached_iface
= NULL
;
1969 IUnknown_Release(detach_iface
);
1974 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1975 DWORD flags
, IDirectDrawSurface7
*attachment
)
1977 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1978 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1980 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1982 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1985 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1986 DWORD flags
, IDirectDrawSurface4
*attachment
)
1988 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1989 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1991 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1993 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1996 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1997 DWORD flags
, IDirectDrawSurface3
*attachment
)
1999 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2000 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
2002 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2004 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2007 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
2008 DWORD flags
, IDirectDrawSurface2
*attachment
)
2010 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2011 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
2013 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2015 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2018 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
2019 DWORD flags
, IDirectDrawSurface
*attachment
)
2021 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2022 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
2024 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
2026 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
2029 /*****************************************************************************
2030 * IDirectDrawSurface7::AddOverlayDirtyRect
2032 * "This method is not currently implemented"
2040 *****************************************************************************/
2041 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
2043 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
2045 return DDERR_UNSUPPORTED
; /* unchecked */
2048 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
2050 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2052 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2054 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2057 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
2059 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2061 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2063 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2066 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
2068 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2070 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2072 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2075 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
2077 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2079 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
2081 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
2084 /*****************************************************************************
2085 * IDirectDrawSurface7::GetDC
2087 * Returns a GDI device context for the surface
2090 * hdc: Address of a HDC variable to store the dc to
2094 * DDERR_INVALIDPARAMS if hdc is NULL
2095 * For details, see IWineD3DSurface::GetDC
2097 *****************************************************************************/
2098 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
2100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2103 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2106 return DDERR_INVALIDPARAMS
;
2108 wined3d_mutex_lock();
2109 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2110 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
2112 hr
= wined3d_surface_getdc(surface
->wined3d_surface
, hdc
);
2114 if (SUCCEEDED(hr
) && format_is_paletteindexed(&surface
->surface_desc
.u4
.ddpfPixelFormat
))
2116 const struct ddraw_palette
*palette
;
2118 if (surface
->palette
)
2119 palette
= surface
->palette
;
2120 else if (surface
->ddraw
->primary
)
2121 palette
= surface
->ddraw
->primary
->palette
;
2126 wined3d_palette_apply_to_dc(palette
->wineD3DPalette
, *hdc
);
2129 wined3d_mutex_unlock();
2132 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
2135 case WINED3DERR_INVALIDCALL
:
2136 if(hdc
) *hdc
= NULL
;
2137 return DDERR_INVALIDPARAMS
;
2143 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
2145 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2147 TRACE("iface %p, dc %p.\n", iface
, dc
);
2149 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2152 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
2154 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2156 TRACE("iface %p, dc %p.\n", iface
, dc
);
2158 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2161 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
2163 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2165 TRACE("iface %p, dc %p.\n", iface
, dc
);
2167 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2170 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
2172 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2174 TRACE("iface %p, dc %p.\n", iface
, dc
);
2176 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2179 /*****************************************************************************
2180 * IDirectDrawSurface7::ReleaseDC
2182 * Releases the DC that was constructed with GetDC
2185 * hdc: HDC to release
2189 * For more details, see IWineD3DSurface::ReleaseDC
2191 *****************************************************************************/
2192 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2194 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2197 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2199 wined3d_mutex_lock();
2200 hr
= wined3d_surface_releasedc(surface
->wined3d_surface
, hdc
);
2201 if (SUCCEEDED(hr
) && (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2202 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2203 wined3d_mutex_unlock();
2208 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2210 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2212 TRACE("iface %p, dc %p.\n", iface
, dc
);
2214 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2217 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2219 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2221 TRACE("iface %p, dc %p.\n", iface
, dc
);
2223 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2226 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2228 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2230 TRACE("iface %p, dc %p.\n", iface
, dc
);
2232 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2235 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2237 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2239 TRACE("iface %p, dc %p.\n", iface
, dc
);
2241 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2244 /*****************************************************************************
2245 * IDirectDrawSurface7::GetCaps
2247 * Returns the surface's caps
2250 * Caps: Address to write the caps to
2254 * DDERR_INVALIDPARAMS if Caps is NULL
2256 *****************************************************************************/
2257 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2259 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2261 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2264 return DDERR_INVALIDPARAMS
;
2266 *Caps
= surface
->surface_desc
.ddsCaps
;
2271 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2273 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2275 TRACE("iface %p, caps %p.\n", iface
, caps
);
2277 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2280 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2282 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2286 TRACE("iface %p, caps %p.\n", iface
, caps
);
2288 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2289 if (FAILED(hr
)) return hr
;
2291 caps
->dwCaps
= caps2
.dwCaps
;
2295 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2297 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2301 TRACE("iface %p, caps %p.\n", iface
, caps
);
2303 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2304 if (FAILED(hr
)) return hr
;
2306 caps
->dwCaps
= caps2
.dwCaps
;
2310 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2312 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2316 TRACE("iface %p, caps %p.\n", iface
, caps
);
2318 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2319 if (FAILED(hr
)) return hr
;
2321 caps
->dwCaps
= caps2
.dwCaps
;
2325 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD priority
)
2327 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2328 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2330 struct wined3d_resource
*resource
;
2332 TRACE("iface %p, priority %u.\n", iface
, priority
);
2334 wined3d_mutex_lock();
2335 /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority
2336 * calls on such surfaces segfault on Windows. */
2337 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
))
2339 WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n");
2340 hr
= DDERR_INVALIDPARAMS
;
2344 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2345 wined3d_resource_set_priority(resource
, priority
);
2348 wined3d_mutex_unlock();
2353 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*priority
)
2355 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2356 const struct wined3d_resource
*resource
;
2357 DWORD managed
= DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
;
2360 TRACE("iface %p, priority %p.\n", iface
, priority
);
2362 wined3d_mutex_lock();
2363 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
2365 WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
2366 hr
= DDERR_INVALIDOBJECT
;
2368 else if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& managed
) || !surface
->wined3d_texture
)
2370 WARN("Called on non-managed texture or mipmap sublevel, returning DDERR_INVALIDPARAMS.\n");
2371 hr
= DDERR_INVALIDPARAMS
;
2375 resource
= wined3d_texture_get_resource(surface
->wined3d_texture
);
2376 *priority
= wined3d_resource_get_priority(resource
);
2379 wined3d_mutex_unlock();
2384 /*****************************************************************************
2385 * IDirectDrawSurface7::SetPrivateData
2387 * Stores some data in the surface that is intended for the application's
2391 * tag: GUID that identifies the data
2392 * Data: Pointer to the private data
2393 * Size: Size of the private data
2398 * For more details, see IWineD3DSurface::SetPrivateData
2400 *****************************************************************************/
2401 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2402 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2404 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2407 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2408 iface
, debugstr_guid(tag
), data
, size
, flags
);
2412 WARN("data is NULL, returning DDERR_INVALIDPARAMS.\n");
2413 return DDERR_INVALIDPARAMS
;
2416 wined3d_mutex_lock();
2417 hr
= wined3d_private_store_set_private_data(&surface
->private_store
, tag
, data
, size
, flags
);
2418 wined3d_mutex_unlock();
2419 return hr_ddraw_from_wined3d(hr
);
2422 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2423 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2425 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2427 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2428 iface
, debugstr_guid(tag
), data
, size
, flags
);
2430 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2433 /*****************************************************************************
2434 * IDirectDrawSurface7::GetPrivateData
2436 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2439 * tag: GUID of the data to return
2440 * Data: Address where to write the data to
2441 * Size: Size of the buffer at Data
2445 * DDERR_INVALIDPARAMS if Data is NULL
2446 * For more details, see IWineD3DSurface::GetPrivateData
2448 *****************************************************************************/
2449 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2451 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2452 const struct wined3d_private_data
*stored_data
;
2455 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2456 iface
, debugstr_guid(tag
), data
, size
);
2458 wined3d_mutex_lock();
2459 stored_data
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2462 hr
= DDERR_NOTFOUND
;
2467 hr
= DDERR_INVALIDPARAMS
;
2470 if (*size
< stored_data
->size
)
2472 *size
= stored_data
->size
;
2473 hr
= DDERR_MOREDATA
;
2478 hr
= DDERR_INVALIDPARAMS
;
2482 *size
= stored_data
->size
;
2483 memcpy(data
, stored_data
->content
.data
, stored_data
->size
);
2487 wined3d_mutex_unlock();
2491 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2493 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2495 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2496 iface
, debugstr_guid(tag
), data
, size
);
2498 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2501 /*****************************************************************************
2502 * IDirectDrawSurface7::FreePrivateData
2504 * Frees private data stored in the surface
2507 * tag: Tag of the data to free
2511 * For more details, see IWineD3DSurface::FreePrivateData
2513 *****************************************************************************/
2514 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2516 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2517 struct wined3d_private_data
*entry
;
2519 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2521 wined3d_mutex_lock();
2522 entry
= wined3d_private_store_get_private_data(&surface
->private_store
, tag
);
2525 wined3d_mutex_unlock();
2526 return DDERR_NOTFOUND
;
2529 wined3d_private_store_free_private_data(&surface
->private_store
, entry
);
2530 wined3d_mutex_unlock();
2535 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2537 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2539 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2541 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2544 /*****************************************************************************
2545 * IDirectDrawSurface7::PageLock
2547 * Prevents a sysmem surface from being paged out
2550 * Flags: Not used, must be 0(unchecked)
2553 * DD_OK, because it's a stub
2555 *****************************************************************************/
2556 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2558 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2560 /* This is Windows memory management related - we don't need this */
2564 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2566 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2568 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2570 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2573 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2575 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2577 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2579 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2582 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2584 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2586 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2588 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2591 /*****************************************************************************
2592 * IDirectDrawSurface7::PageUnlock
2594 * Allows a sysmem surface to be paged out
2597 * Flags: Not used, must be 0(unchecked)
2600 * DD_OK, because it's a stub
2602 *****************************************************************************/
2603 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2605 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2610 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2612 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2614 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2616 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2619 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2621 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2623 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2625 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2628 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2630 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2632 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2634 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2637 /*****************************************************************************
2638 * IDirectDrawSurface7::BltBatch
2640 * An unimplemented function
2648 *****************************************************************************/
2649 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2651 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2653 /* MSDN: "not currently implemented" */
2654 return DDERR_UNSUPPORTED
;
2657 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2659 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2661 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2663 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2666 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2668 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2670 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2672 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2675 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2677 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2679 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2681 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2684 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2686 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2688 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2690 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2693 /*****************************************************************************
2694 * IDirectDrawSurface7::EnumAttachedSurfaces
2696 * Enumerates all surfaces attached to this surface
2699 * context: Pointer to pass unmodified to the callback
2700 * cb: Callback function to call for each surface
2704 * DDERR_INVALIDPARAMS if cb is NULL
2706 *****************************************************************************/
2707 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2708 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2710 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2711 struct ddraw_surface
*surf
;
2712 DDSURFACEDESC2 desc
;
2715 /* Attached surfaces aren't handled in WineD3D */
2716 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2719 return DDERR_INVALIDPARAMS
;
2721 wined3d_mutex_lock();
2723 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2725 surf
= surface
->complex_array
[i
];
2728 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2729 desc
= surf
->surface_desc
;
2730 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2731 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2733 wined3d_mutex_unlock();
2738 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2740 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2741 desc
= surf
->surface_desc
;
2742 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2743 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2745 wined3d_mutex_unlock();
2750 TRACE(" end of enumeration.\n");
2752 wined3d_mutex_unlock();
2757 struct callback_info2
2759 LPDDENUMSURFACESCALLBACK2 callback
;
2763 struct callback_info
2765 LPDDENUMSURFACESCALLBACK callback
;
2769 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2771 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2772 const struct callback_info2
*info
= context
;
2774 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2775 ddraw_surface7_Release(surface
);
2777 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2780 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2782 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2783 const struct callback_info
*info
= context
;
2785 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2786 ddraw_surface7_Release(surface
);
2788 /* FIXME: Check surface_test.dwSize */
2789 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2790 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2793 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2794 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2796 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2797 struct callback_info2 info
;
2799 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2801 info
.callback
= callback
;
2802 info
.context
= context
;
2804 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2805 &info
, EnumCallback2
);
2808 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2809 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2811 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2812 struct callback_info info
;
2814 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2816 info
.callback
= callback
;
2817 info
.context
= context
;
2819 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2820 &info
, EnumCallback
);
2823 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2824 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2826 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2827 struct callback_info info
;
2829 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2831 info
.callback
= callback
;
2832 info
.context
= context
;
2834 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2835 &info
, EnumCallback
);
2838 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2839 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2841 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2842 struct callback_info info
;
2844 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2846 info
.callback
= callback
;
2847 info
.context
= context
;
2849 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2850 &info
, EnumCallback
);
2853 /*****************************************************************************
2854 * IDirectDrawSurface7::EnumOverlayZOrders
2856 * "Enumerates the overlay surfaces on the specified destination"
2859 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2860 * context: context to pass back to the callback
2861 * cb: callback function to call for each enumerated surface
2864 * DD_OK, because it's a stub
2866 *****************************************************************************/
2867 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2868 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2870 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2875 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2876 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2878 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2879 struct callback_info2 info
;
2881 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2883 info
.callback
= callback
;
2884 info
.context
= context
;
2886 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2887 flags
, &info
, EnumCallback2
);
2890 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2891 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2893 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2894 struct callback_info info
;
2896 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2898 info
.callback
= callback
;
2899 info
.context
= context
;
2901 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2902 flags
, &info
, EnumCallback
);
2905 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2906 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2908 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2909 struct callback_info info
;
2911 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2913 info
.callback
= callback
;
2914 info
.context
= context
;
2916 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2917 flags
, &info
, EnumCallback
);
2920 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2921 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2923 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2924 struct callback_info info
;
2926 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2928 info
.callback
= callback
;
2929 info
.context
= context
;
2931 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2932 flags
, &info
, EnumCallback
);
2935 /*****************************************************************************
2936 * IDirectDrawSurface7::GetBltStatus
2938 * Returns the blitting status
2941 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2944 * See IWineD3DSurface::Blt
2946 *****************************************************************************/
2947 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2949 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2953 case WINEDDGBS_CANBLT
:
2954 case WINEDDGBS_ISBLTDONE
:
2958 return DDERR_INVALIDPARAMS
;
2962 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2964 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2966 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2968 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2971 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2973 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2975 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2977 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2980 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2982 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2984 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2986 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2989 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2991 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2993 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2995 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2998 /*****************************************************************************
2999 * IDirectDrawSurface7::GetColorKey
3001 * Returns the color key assigned to the surface
3005 * CKey: Address to store the key to
3009 * DDERR_INVALIDPARAMS if CKey is NULL
3011 *****************************************************************************/
3012 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
3014 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3016 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
3019 return DDERR_INVALIDPARAMS
;
3021 wined3d_mutex_lock();
3025 case DDCKEY_DESTBLT
:
3026 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
3028 wined3d_mutex_unlock();
3029 return DDERR_NOCOLORKEY
;
3031 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
3034 case DDCKEY_DESTOVERLAY
:
3035 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
3037 wined3d_mutex_unlock();
3038 return DDERR_NOCOLORKEY
;
3040 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
3044 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
3046 wined3d_mutex_unlock();
3047 return DDERR_NOCOLORKEY
;
3049 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
3052 case DDCKEY_SRCOVERLAY
:
3053 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
3055 wined3d_mutex_unlock();
3056 return DDERR_NOCOLORKEY
;
3058 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
3062 wined3d_mutex_unlock();
3063 return DDERR_INVALIDPARAMS
;
3066 wined3d_mutex_unlock();
3071 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3073 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3075 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3077 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3080 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3082 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3084 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3086 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3089 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3091 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3093 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3095 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3098 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
3100 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3102 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
3104 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
3107 /*****************************************************************************
3108 * IDirectDrawSurface7::GetFlipStatus
3110 * Returns the flipping status of the surface
3113 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
3116 * See IWineD3DSurface::GetFlipStatus
3118 *****************************************************************************/
3119 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
3121 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3123 /* XXX: DDERR_INVALIDSURFACETYPE */
3127 case WINEDDGFS_CANFLIP
:
3128 case WINEDDGFS_ISFLIPDONE
:
3132 return DDERR_INVALIDPARAMS
;
3136 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
3138 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3140 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3142 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3145 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
3147 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3149 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3151 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3154 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
3156 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3158 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3160 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3163 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
3165 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3167 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3169 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
3172 /*****************************************************************************
3173 * IDirectDrawSurface7::GetOverlayPosition
3175 * Returns the display coordinates of a visible and active overlay surface
3182 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3183 *****************************************************************************/
3184 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
3186 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3189 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
3191 wined3d_mutex_lock();
3192 hr
= wined3d_surface_get_overlay_position(surface
->wined3d_surface
, X
, Y
);
3193 wined3d_mutex_unlock();
3198 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3200 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3202 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3204 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3207 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3209 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3211 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3213 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3216 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3218 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3220 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3222 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3225 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3227 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3229 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3231 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3234 /*****************************************************************************
3235 * IDirectDrawSurface7::GetPixelFormat
3237 * Returns the pixel format of the Surface
3240 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3241 * format should be written
3245 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3247 *****************************************************************************/
3248 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3250 /* What is DDERR_INVALIDSURFACETYPE for here? */
3251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3253 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3256 return DDERR_INVALIDPARAMS
;
3258 wined3d_mutex_lock();
3259 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3260 wined3d_mutex_unlock();
3265 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3267 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3269 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3271 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3274 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3276 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3278 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3280 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3283 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3285 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3287 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3289 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3292 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3294 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3296 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3298 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3301 /*****************************************************************************
3302 * IDirectDrawSurface7::GetSurfaceDesc
3304 * Returns the description of this surface
3307 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3312 * DDERR_INVALIDPARAMS if DDSD is NULL
3314 *****************************************************************************/
3315 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3317 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3319 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3322 return DDERR_INVALIDPARAMS
;
3324 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3326 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3327 return DDERR_INVALIDPARAMS
;
3330 wined3d_mutex_lock();
3331 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3332 TRACE("Returning surface desc:\n");
3333 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3334 wined3d_mutex_unlock();
3339 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3341 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3343 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3345 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3348 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3350 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3352 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3354 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3356 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3358 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3359 return DDERR_INVALIDPARAMS
;
3362 wined3d_mutex_lock();
3363 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3364 TRACE("Returning surface desc:\n");
3365 if (TRACE_ON(ddraw
))
3367 /* DDRAW_dump_surface_desc handles the smaller size */
3368 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3370 wined3d_mutex_unlock();
3375 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3377 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3379 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3381 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3384 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3386 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3388 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3390 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3393 /*****************************************************************************
3394 * IDirectDrawSurface7::Initialize
3396 * Initializes the surface. This is a no-op in Wine
3399 * DD: Pointer to an DirectDraw interface
3400 * DDSD: Surface description for initialization
3403 * DDERR_ALREADYINITIALIZED
3405 *****************************************************************************/
3406 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3407 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3409 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3411 return DDERR_ALREADYINITIALIZED
;
3414 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3415 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3417 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3419 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3421 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3422 ddraw
, surface_desc
);
3425 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3426 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3428 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3429 DDSURFACEDESC2 surface_desc2
;
3431 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3433 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3434 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3435 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3438 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3439 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3441 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3442 DDSURFACEDESC2 surface_desc2
;
3444 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3446 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3447 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3448 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3451 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3452 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3454 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3455 DDSURFACEDESC2 surface_desc2
;
3457 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3459 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3460 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3461 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3464 /*****************************************************************************
3465 * IDirect3DTexture1::Initialize
3467 * The sdk says it's not implemented
3475 *****************************************************************************/
3476 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3477 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3479 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3481 return DDERR_UNSUPPORTED
; /* Unchecked */
3484 /*****************************************************************************
3485 * IDirectDrawSurface7::IsLost
3487 * Checks if the surface is lost
3490 * DD_OK, if the surface is usable
3491 * DDERR_ISLOST if the surface is lost
3492 * See IWineD3DSurface::IsLost for more details
3494 *****************************************************************************/
3495 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3497 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3500 TRACE("iface %p.\n", iface
);
3502 wined3d_mutex_lock();
3503 hr
= wined3d_surface_is_lost(surface
->wined3d_surface
);
3504 wined3d_mutex_unlock();
3508 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3509 * WineD3D uses the same error for surfaces
3511 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3516 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3518 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3520 TRACE("iface %p.\n", iface
);
3522 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3525 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3527 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3529 TRACE("iface %p.\n", iface
);
3531 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3534 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3536 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3538 TRACE("iface %p.\n", iface
);
3540 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3543 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3545 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3547 TRACE("iface %p.\n", iface
);
3549 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3552 /*****************************************************************************
3553 * IDirectDrawSurface7::Restore
3555 * Restores a lost surface. This makes the surface usable again, but
3556 * doesn't reload its old contents
3560 * See IWineD3DSurface::Restore for more details
3562 *****************************************************************************/
3563 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3565 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3568 TRACE("iface %p.\n", iface
);
3570 wined3d_mutex_lock();
3571 hr
= wined3d_surface_restore(surface
->wined3d_surface
);
3572 wined3d_mutex_unlock();
3577 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3579 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3581 TRACE("iface %p.\n", iface
);
3583 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3586 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3588 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3590 TRACE("iface %p.\n", iface
);
3592 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3595 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3597 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3599 TRACE("iface %p.\n", iface
);
3601 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3604 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3606 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3608 TRACE("iface %p.\n", iface
);
3610 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3613 /*****************************************************************************
3614 * IDirectDrawSurface7::SetOverlayPosition
3616 * Changes the display coordinates of an overlay surface
3623 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3624 *****************************************************************************/
3625 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3627 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3630 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3632 wined3d_mutex_lock();
3633 hr
= wined3d_surface_set_overlay_position(surface
->wined3d_surface
, X
, Y
);
3634 wined3d_mutex_unlock();
3639 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3641 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3643 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3645 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3648 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3650 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3652 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3654 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3657 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3659 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3661 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3663 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3666 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3668 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3670 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3672 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3675 /*****************************************************************************
3676 * IDirectDrawSurface7::UpdateOverlay
3678 * Modifies the attributes of an overlay surface.
3681 * SrcRect: The section of the source being used for the overlay
3682 * DstSurface: Address of the surface that is overlaid
3683 * DstRect: Place of the overlay
3684 * Flags: some DDOVER_* flags
3687 * DDERR_UNSUPPORTED, because we don't support overlays
3689 *****************************************************************************/
3690 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3691 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3693 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3694 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3697 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3698 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3700 wined3d_mutex_lock();
3701 hr
= wined3d_surface_update_overlay(src_impl
->wined3d_surface
, SrcRect
,
3702 dst_impl
? dst_impl
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3703 wined3d_mutex_unlock();
3706 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3707 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3708 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3714 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3715 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3717 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3718 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3720 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3721 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3723 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3724 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3727 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3728 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3730 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3731 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3733 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3734 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3736 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3737 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3740 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3741 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3743 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3744 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3746 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3747 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3749 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3750 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3753 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3754 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3756 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3757 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3759 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3760 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3762 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3763 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3766 /*****************************************************************************
3767 * IDirectDrawSurface7::UpdateOverlayDisplay
3769 * The DX7 sdk says that it's not implemented
3774 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3776 *****************************************************************************/
3777 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3779 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3781 return DDERR_UNSUPPORTED
;
3784 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3786 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3788 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3790 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3793 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3795 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3797 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3799 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3802 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3804 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3806 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3808 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3811 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3813 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3815 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3817 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3820 /*****************************************************************************
3821 * IDirectDrawSurface7::UpdateOverlayZOrder
3823 * Sets an overlay's Z order
3826 * Flags: DDOVERZ_* flags
3827 * DDSRef: Defines the relative position in the overlay chain
3830 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3832 *****************************************************************************/
3833 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3834 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3836 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3837 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3840 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3842 wined3d_mutex_lock();
3843 hr
= wined3d_surface_update_overlay_z_order(surface
->wined3d_surface
,
3844 Flags
, reference_impl
? reference_impl
->wined3d_surface
: NULL
);
3845 wined3d_mutex_unlock();
3850 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3851 DWORD flags
, IDirectDrawSurface4
*reference
)
3853 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3854 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3856 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3858 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3859 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3862 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3863 DWORD flags
, IDirectDrawSurface3
*reference
)
3865 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3866 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3868 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3870 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3871 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3874 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3875 DWORD flags
, IDirectDrawSurface2
*reference
)
3877 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3878 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3880 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3882 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3883 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3886 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3887 DWORD flags
, IDirectDrawSurface
*reference
)
3889 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3890 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3892 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3894 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3895 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3898 /*****************************************************************************
3899 * IDirectDrawSurface7::GetDDInterface
3901 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3902 * surface belongs to
3905 * DD: Address to write the interface pointer to
3909 * DDERR_INVALIDPARAMS if DD is NULL
3911 *****************************************************************************/
3912 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3914 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3916 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3919 return DDERR_INVALIDPARAMS
;
3921 switch(This
->version
)
3924 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3928 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3932 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3936 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3940 IUnknown_AddRef((IUnknown
*)*DD
);
3945 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3947 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3949 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3951 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3954 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3956 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3958 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3960 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3963 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3965 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3967 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3969 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3972 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3974 TRACE("iface %p.\n", iface
);
3979 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3981 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3983 TRACE("iface %p.\n", iface
);
3985 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
3988 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3990 TRACE("iface %p, value %p.\n", iface
, pValue
);
3997 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3999 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4001 TRACE("iface %p, value %p.\n", iface
, pValue
);
4003 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
4006 /*****************************************************************************
4007 * IDirectDrawSurface7::SetLOD
4009 * Sets the level of detail of a texture
4012 * MaxLOD: LOD to set
4016 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4018 *****************************************************************************/
4019 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
4021 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4024 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
4026 wined3d_mutex_lock();
4027 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4029 wined3d_mutex_unlock();
4030 return DDERR_INVALIDOBJECT
;
4033 if (!surface
->wined3d_texture
)
4035 ERR("The ddraw surface has no wined3d texture.\n");
4036 wined3d_mutex_unlock();
4037 return DDERR_INVALIDOBJECT
;
4040 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
4041 wined3d_mutex_unlock();
4046 /*****************************************************************************
4047 * IDirectDrawSurface7::GetLOD
4049 * Returns the level of detail of a Direct3D texture
4052 * MaxLOD: Address to write the LOD to
4056 * DDERR_INVALIDPARAMS if MaxLOD is NULL
4057 * DDERR_INVALIDOBJECT if the surface is invalid for this method
4059 *****************************************************************************/
4060 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
4062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4064 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
4067 return DDERR_INVALIDPARAMS
;
4069 wined3d_mutex_lock();
4070 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
4072 wined3d_mutex_unlock();
4073 return DDERR_INVALIDOBJECT
;
4076 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
4077 wined3d_mutex_unlock();
4082 /*****************************************************************************
4083 * IDirectDrawSurface7::BltFast
4085 * Performs a fast Blit.
4088 * dstx: The x coordinate to blit to on the destination
4089 * dsty: The y coordinate to blit to on the destination
4090 * Source: The source surface
4091 * rsrc: The source rectangle
4092 * trans: Type of transfer. Some DDBLTFAST_* flags
4096 * For more details, see IWineD3DSurface::BltFast
4098 *****************************************************************************/
4099 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
4100 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
4102 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4103 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
4104 DWORD src_w
, src_h
, dst_w
, dst_h
;
4109 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4110 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
4112 dst_w
= This
->surface_desc
.dwWidth
;
4113 dst_h
= This
->surface_desc
.dwHeight
;
4115 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
4120 src_w
= rsrc
->right
- rsrc
->left
;
4121 src_h
= rsrc
->bottom
- rsrc
->top
;
4125 src_w
= src
->surface_desc
.dwWidth
;
4126 src_h
= src
->surface_desc
.dwHeight
;
4129 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
4130 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
4132 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
4133 return DDERR_INVALIDRECT
;
4136 SetRect(&dst_rect
, dstx
, dsty
, dstx
+ src_w
, dsty
+ src_h
);
4137 if (trans
& DDBLTFAST_SRCCOLORKEY
)
4138 flags
|= WINEDDBLT_KEYSRC
;
4139 if (trans
& DDBLTFAST_DESTCOLORKEY
)
4140 flags
|= WINEDDBLT_KEYDEST
;
4141 if (trans
& DDBLTFAST_WAIT
)
4142 flags
|= WINEDDBLT_WAIT
;
4143 if (trans
& DDBLTFAST_DONOTWAIT
)
4144 flags
|= WINEDDBLT_DONOTWAIT
;
4146 wined3d_mutex_lock();
4149 wined3d_mutex_unlock();
4150 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4151 return DDERR_BLTFASTCANTCLIP
;
4154 if (src
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4155 hr
= ddraw_surface_update_frontbuffer(src
, rsrc
, TRUE
);
4157 hr
= wined3d_surface_blt(This
->wined3d_surface
, &dst_rect
,
4158 src
->wined3d_surface
, rsrc
, flags
, NULL
, WINED3D_TEXF_POINT
);
4159 if (SUCCEEDED(hr
) && (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
4160 hr
= ddraw_surface_update_frontbuffer(This
, &dst_rect
, FALSE
);
4161 wined3d_mutex_unlock();
4165 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
4166 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
4171 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4172 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4174 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4175 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4177 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4178 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4180 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4181 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4184 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4185 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4187 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4188 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4190 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4191 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4193 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4194 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4197 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4198 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4200 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4201 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4203 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4204 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4206 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4207 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4210 static HRESULT WINAPI DECLSPEC_HOTPATCH
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4211 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4213 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4214 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4216 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4217 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4219 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4220 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4223 /*****************************************************************************
4224 * IDirectDrawSurface7::GetClipper
4226 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4230 * Clipper: Address to store the interface pointer at
4234 * DDERR_INVALIDPARAMS if Clipper is NULL
4235 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4237 *****************************************************************************/
4238 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4240 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4242 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4245 return DDERR_INVALIDPARAMS
;
4247 wined3d_mutex_lock();
4248 if (!surface
->clipper
)
4250 wined3d_mutex_unlock();
4251 return DDERR_NOCLIPPERATTACHED
;
4254 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4255 IDirectDrawClipper_AddRef(*Clipper
);
4256 wined3d_mutex_unlock();
4261 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4263 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4265 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4267 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4270 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4272 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4274 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4276 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4279 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4281 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4283 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4285 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4288 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4290 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4292 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4294 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4297 /*****************************************************************************
4298 * IDirectDrawSurface7::SetClipper
4300 * Sets a clipper for the surface
4303 * Clipper: IDirectDrawClipper interface of the clipper to set
4308 *****************************************************************************/
4309 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4310 IDirectDrawClipper
*iclipper
)
4312 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4313 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4314 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4317 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4319 wined3d_mutex_lock();
4320 if (clipper
== This
->clipper
)
4322 wined3d_mutex_unlock();
4326 This
->clipper
= clipper
;
4328 if (clipper
!= NULL
)
4329 IDirectDrawClipper_AddRef(iclipper
);
4331 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4333 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4337 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4342 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4343 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4347 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4348 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4352 wined3d_mutex_unlock();
4357 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4359 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4361 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4363 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4366 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4368 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4370 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4372 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4375 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4377 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4379 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4381 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4384 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4386 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4388 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4390 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4393 /*****************************************************************************
4394 * IDirectDrawSurface7::SetSurfaceDesc
4396 * Sets the surface description. It can override the pixel format, the surface
4398 * It's not really tested.
4401 * DDSD: Pointer to the new surface description to set
4406 * DDERR_INVALIDPARAMS if DDSD is NULL
4408 *****************************************************************************/
4409 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4411 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4413 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4414 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4415 enum wined3d_format_id format_id
;
4416 UINT pitch
, width
, height
;
4418 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4422 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4423 return DDERR_INVALIDPARAMS
;
4427 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4428 return DDERR_INVALIDPARAMS
;
4430 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
4431 || This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
4432 || This
->surface_desc
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
4434 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4435 return DDERR_INVALIDSURFACETYPE
;
4438 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4439 * for PIXELFORMAT to work */
4440 if (DDSD
->dwFlags
& ~allowed_flags
)
4442 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4443 return DDERR_INVALIDPARAMS
;
4445 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
) || !DDSD
->lpSurface
)
4447 WARN("DDSD_LPSURFACE is not set or lpSurface is NULL, returning DDERR_INVALIDPARAMS\n");
4448 return DDERR_INVALIDPARAMS
;
4450 if ((DDSD
->dwFlags
& DDSD_CAPS
) && DDSD
->ddsCaps
.dwCaps
)
4452 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4453 return DDERR_INVALIDCAPS
;
4455 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4457 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4459 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4460 return DDERR_INVALIDPARAMS
;
4462 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4464 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4465 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4466 return DDERR_INVALIDPARAMS
;
4468 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4469 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4470 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4471 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4472 pitch
= DDSD
->u1
.lPitch
;
4473 width
= DDSD
->dwWidth
;
4475 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4477 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4478 return DDERR_INVALIDPARAMS
;
4482 pitch
= This
->surface_desc
.u1
.lPitch
;
4483 width
= This
->surface_desc
.dwWidth
;
4486 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4488 if (!DDSD
->dwHeight
)
4490 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4491 return DDERR_INVALIDPARAMS
;
4493 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4494 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4495 height
= DDSD
->dwHeight
;
4499 height
= This
->surface_desc
.dwHeight
;
4502 wined3d_mutex_lock();
4503 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4505 enum wined3d_format_id current_format_id
;
4506 format_id
= wined3dformat_from_ddrawformat(&DDSD
->u4
.ddpfPixelFormat
);
4508 if (format_id
== WINED3DFMT_UNKNOWN
)
4510 ERR("Requested to set an unknown pixelformat\n");
4511 wined3d_mutex_unlock();
4512 return DDERR_INVALIDPARAMS
;
4514 current_format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4515 if (format_id
!= current_format_id
)
4516 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4520 format_id
= wined3dformat_from_ddrawformat(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4523 if (FAILED(hr
= wined3d_texture_update_desc(This
->wined3d_texture
, width
, height
,
4524 format_id
, WINED3D_MULTISAMPLE_NONE
, 0, DDSD
->lpSurface
, pitch
)))
4526 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4527 wined3d_mutex_unlock();
4528 return hr_ddraw_from_wined3d(hr
);
4531 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4532 This
->surface_desc
.dwWidth
= width
;
4533 if (DDSD
->dwFlags
& DDSD_PITCH
)
4534 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4535 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4536 This
->surface_desc
.dwHeight
= height
;
4537 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4538 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4540 wined3d_mutex_unlock();
4545 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4546 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4548 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4550 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4552 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4553 surface_desc
, flags
);
4556 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4557 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4559 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4560 DDSURFACEDESC2 surface_desc2
;
4562 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4564 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4565 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4566 surface_desc
? &surface_desc2
: NULL
, flags
);
4569 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**palette
)
4571 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4572 struct ddraw_palette
*palette_impl
;
4575 TRACE("iface %p, palette %p.\n", iface
, palette
);
4578 return DDERR_INVALIDPARAMS
;
4579 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4581 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4582 return DDERR_SURFACELOST
;
4585 wined3d_mutex_lock();
4586 if ((palette_impl
= surface
->palette
))
4588 *palette
= &palette_impl
->IDirectDrawPalette_iface
;
4589 IDirectDrawPalette_AddRef(*palette
);
4594 hr
= DDERR_NOPALETTEATTACHED
;
4596 wined3d_mutex_unlock();
4601 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4603 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4605 TRACE("iface %p, palette %p.\n", iface
, palette
);
4607 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4610 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4612 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4614 TRACE("iface %p, palette %p.\n", iface
, palette
);
4616 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4619 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4621 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4623 TRACE("iface %p, palette %p.\n", iface
, palette
);
4625 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4628 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4630 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4632 TRACE("iface %p, palette %p.\n", iface
, palette
);
4634 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4637 static HRESULT
ddraw_surface_set_color_key(struct ddraw_surface
*surface
, DWORD flags
, DDCOLORKEY
*color_key
)
4639 DDCOLORKEY fixed_color_key
;
4640 HRESULT hr
= WINED3D_OK
;
4642 if (flags
& DDCKEY_COLORSPACE
)
4644 if (color_key
&& color_key
->dwColorSpaceLowValue
!= color_key
->dwColorSpaceHighValue
)
4646 WARN("Range color keys are not supported, returning DDERR_NOCOLORKEYHW.\n");
4647 return DDERR_NOCOLORKEYHW
;
4649 flags
&= ~DDCKEY_COLORSPACE
;
4652 wined3d_mutex_lock();
4656 fixed_color_key
.dwColorSpaceLowValue
= fixed_color_key
.dwColorSpaceHighValue
= color_key
->dwColorSpaceLowValue
;
4657 switch (flags
& ~DDCKEY_COLORSPACE
)
4659 case DDCKEY_DESTBLT
:
4660 surface
->surface_desc
.ddckCKDestBlt
= fixed_color_key
;
4661 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4664 case DDCKEY_DESTOVERLAY
:
4665 surface
->surface_desc
.u3
.ddckCKDestOverlay
= fixed_color_key
;
4666 surface
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4669 case DDCKEY_SRCOVERLAY
:
4670 surface
->surface_desc
.ddckCKSrcOverlay
= fixed_color_key
;
4671 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4675 surface
->surface_desc
.ddckCKSrcBlt
= fixed_color_key
;
4676 surface
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4680 wined3d_mutex_unlock();
4681 return DDERR_INVALIDPARAMS
;
4686 switch (flags
& ~DDCKEY_COLORSPACE
)
4688 case DDCKEY_DESTBLT
:
4689 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4692 case DDCKEY_DESTOVERLAY
:
4693 surface
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4696 case DDCKEY_SRCOVERLAY
:
4697 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4701 surface
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4705 wined3d_mutex_unlock();
4706 return DDERR_INVALIDPARAMS
;
4710 if (surface
->wined3d_texture
)
4711 hr
= wined3d_texture_set_color_key(surface
->wined3d_texture
, flags
,
4712 color_key
? (struct wined3d_color_key
*)&fixed_color_key
: NULL
);
4714 wined3d_mutex_unlock();
4716 return hr_ddraw_from_wined3d(hr
);
4719 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4721 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4723 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4725 wined3d_mutex_lock();
4726 if (!surface
->wined3d_texture
)
4728 wined3d_mutex_unlock();
4729 return DDERR_NOTONMIPMAPSUBLEVEL
;
4731 wined3d_mutex_unlock();
4733 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4736 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4738 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4740 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4742 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4745 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4747 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4749 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4751 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4754 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4756 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4758 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4760 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4763 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4765 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4767 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4769 return ddraw_surface_set_color_key(surface
, flags
, color_key
);
4772 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*palette
)
4774 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4776 TRACE("iface %p, palette %p.\n", iface
, palette
);
4778 if (surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4779 return DDERR_NOTONMIPMAPSUBLEVEL
;
4780 if (IDirectDrawSurface7_IsLost(iface
) == DDERR_SURFACELOST
)
4782 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4783 return DDERR_SURFACELOST
;
4786 return ddraw_surface_set_palette(surface
, palette
);
4789 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4791 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4793 TRACE("iface %p, palette %p.\n", iface
, palette
);
4795 if (IDirectDrawSurface4_IsLost(iface
) == DDERR_SURFACELOST
)
4797 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4798 return DDERR_SURFACELOST
;
4801 return ddraw_surface_set_palette(surface
, palette
);
4804 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4806 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4808 TRACE("iface %p, palette %p.\n", iface
, palette
);
4810 if (IDirectDrawSurface3_IsLost(iface
) == DDERR_SURFACELOST
)
4812 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4813 return DDERR_SURFACELOST
;
4816 return ddraw_surface_set_palette(surface
, palette
);
4819 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4821 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4823 TRACE("iface %p, palette %p.\n", iface
, palette
);
4825 if (IDirectDrawSurface2_IsLost(iface
) == DDERR_SURFACELOST
)
4827 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4828 return DDERR_SURFACELOST
;
4831 return ddraw_surface_set_palette(surface
, palette
);
4834 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4836 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4838 TRACE("iface %p, palette %p.\n", iface
, palette
);
4840 if (IDirectDrawSurface_IsLost(iface
) == DDERR_SURFACELOST
)
4842 WARN("Surface lost, returning DDERR_SURFACELOST.\n");
4843 return DDERR_SURFACELOST
;
4846 return ddraw_surface_set_palette(surface
, palette
);
4849 /**********************************************************
4850 * IDirectDrawGammaControl::GetGammaRamp
4852 * Returns the current gamma ramp for a surface
4856 * gamma_ramp: Address to write the ramp to
4860 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4862 **********************************************************/
4863 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4864 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4866 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4868 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4872 WARN("Invalid gamma_ramp passed.\n");
4873 return DDERR_INVALIDPARAMS
;
4876 wined3d_mutex_lock();
4877 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4879 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4880 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4884 ERR("Not implemented for non-primary surfaces.\n");
4886 wined3d_mutex_unlock();
4891 /**********************************************************
4892 * IDirectDrawGammaControl::SetGammaRamp
4894 * Sets the red, green and blue gamma ramps for
4897 * flags: Can be DDSGR_CALIBRATE to request calibration
4898 * gamma_ramp: Structure containing the new gamma ramp
4902 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4904 **********************************************************/
4905 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4906 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4908 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4910 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4914 WARN("Invalid gamma_ramp passed.\n");
4915 return DDERR_INVALIDPARAMS
;
4918 wined3d_mutex_lock();
4919 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4921 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4922 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4923 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4927 ERR("Not implemented for non-primary surfaces.\n");
4929 wined3d_mutex_unlock();
4934 /*****************************************************************************
4935 * IDirect3DTexture2::PaletteChanged
4937 * Informs the texture about a palette change
4940 * start: Start index of the change
4941 * count: The number of changed entries
4944 * D3D_OK, because it's a stub
4946 *****************************************************************************/
4947 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4949 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4954 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4956 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4958 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4960 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4963 /*****************************************************************************
4964 * IDirect3DTexture::Unload
4966 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4972 *****************************************************************************/
4973 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4975 WARN("iface %p. Not implemented.\n", iface
);
4977 return DDERR_UNSUPPORTED
;
4980 /*****************************************************************************
4981 * IDirect3DTexture2::GetHandle
4983 * Returns handle for the texture. At the moment, the interface
4984 * to the IWineD3DTexture is used.
4987 * device: Device this handle is assigned to
4988 * handle: Address to store the handle at.
4993 *****************************************************************************/
4994 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4995 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4997 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
4998 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
5000 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5002 wined3d_mutex_lock();
5004 if (!surface
->Handle
)
5006 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
5007 if (h
== DDRAW_INVALID_HANDLE
)
5009 ERR("Failed to allocate a texture handle.\n");
5010 wined3d_mutex_unlock();
5011 return DDERR_OUTOFMEMORY
;
5014 surface
->Handle
= h
+ 1;
5017 TRACE("Returning handle %08x.\n", surface
->Handle
);
5018 *handle
= surface
->Handle
;
5020 wined3d_mutex_unlock();
5025 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
5026 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
5028 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
5029 struct d3d_device
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
5031 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
5033 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
5034 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
5037 /*****************************************************************************
5038 * get_sub_mimaplevel
5040 * Helper function that returns the next mipmap level
5042 * tex_ptr: Surface of which to return the next level
5044 *****************************************************************************/
5045 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
5047 /* Now go down the mipmap chain to the next surface */
5048 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, {0} };
5049 IDirectDrawSurface7
*next_level
;
5052 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5053 if (FAILED(hr
)) return NULL
;
5055 ddraw_surface7_Release(next_level
);
5057 return impl_from_IDirectDrawSurface7(next_level
);
5060 static BOOL
compare_format(DDPIXELFORMAT
*format1
, DDPIXELFORMAT
*format2
)
5062 if ((format1
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_FOURCC
)) !=
5063 (format2
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_FOURCC
)))
5066 if (format1
->dwFlags
& (DDPF_RGB
|DDPF_YUV
))
5068 if (!(format1
->dwFlags
& DDPF_ALPHA
))
5070 /* The RGB and YUV bits are stored in the same fields */
5071 if (format1
->u1
.dwRGBBitCount
!= format2
->u1
.dwRGBBitCount
)
5074 if (format1
->u2
.dwRBitMask
!= format2
->u2
.dwRBitMask
)
5077 if (format1
->u3
.dwGBitMask
!= format2
->u3
.dwGBitMask
)
5080 if (format1
->u4
.dwBBitMask
!= format2
->u4
.dwBBitMask
)
5084 if (format1
->dwFlags
& (DDPF_ALPHAPIXELS
| DDPF_ALPHA
))
5086 if (format1
->u5
.dwRGBAlphaBitMask
!= format2
->u5
.dwRGBAlphaBitMask
)
5091 if (format1
->dwFlags
& DDPF_FOURCC
)
5093 if (format1
->dwFourCC
!= format2
->dwFourCC
)
5100 /*****************************************************************************
5101 * IDirect3DTexture2::Load
5103 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5105 * This function isn't relayed to WineD3D because the whole interface is
5106 * implemented in DDraw only. For speed improvements an implementation which
5107 * takes OpenGL more into account could be placed into WineD3D.
5110 * src_texture: Address of the texture to load
5114 * D3DERR_TEXTURE_LOAD_FAILED.
5116 *****************************************************************************/
5117 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5119 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5120 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5123 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5125 if (src_surface
== dst_surface
)
5127 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5131 wined3d_mutex_lock();
5135 DDSURFACEDESC
*src_desc
= (DDSURFACEDESC
*)&src_surface
->surface_desc
;
5137 TRACE("Copying surface %p to surface %p.\n", src_surface
, dst_surface
);
5139 if (compare_format(&src_surface
->surface_desc
.u4
.ddpfPixelFormat
,
5140 &dst_surface
->surface_desc
.u4
.ddpfPixelFormat
))
5142 struct ddraw_palette
*dst_pal
, *src_pal
;
5144 /* Get the palettes */
5145 dst_pal
= dst_surface
->palette
;
5146 src_pal
= src_surface
->palette
;
5150 PALETTEENTRY palent
[256];
5154 wined3d_mutex_unlock();
5155 return DDERR_NOPALETTEATTACHED
;
5157 IDirectDrawPalette_GetEntries(&src_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5158 IDirectDrawPalette_SetEntries(&dst_pal
->IDirectDrawPalette_iface
, 0, 0, 256, palent
);
5161 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5163 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5164 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5169 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5173 /* Suppress the ALLOCONLOAD flag */
5174 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5176 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, NULL
, src_surface
->wined3d_surface
,
5177 NULL
, 0, NULL
, WINED3D_TEXF_LINEAR
);
5180 ERR("Failed to blit surface, hr %#x.\n", hr
);
5181 wined3d_mutex_unlock();
5185 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5186 src_surface
= get_sub_mimaplevel(src_surface
);
5190 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5191 dst_surface
= get_sub_mimaplevel(dst_surface
);
5195 if (src_surface
&& !dst_surface
)
5196 return DDERR_NOTFOUND
;
5198 if (!src_surface
|| !dst_surface
)
5202 wined3d_mutex_unlock();
5207 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5209 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5210 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5212 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5214 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5215 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5218 /*****************************************************************************
5220 *****************************************************************************/
5222 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5225 ddraw_surface7_QueryInterface
,
5226 ddraw_surface7_AddRef
,
5227 ddraw_surface7_Release
,
5228 /* IDirectDrawSurface */
5229 ddraw_surface7_AddAttachedSurface
,
5230 ddraw_surface7_AddOverlayDirtyRect
,
5232 ddraw_surface7_BltBatch
,
5233 ddraw_surface7_BltFast
,
5234 ddraw_surface7_DeleteAttachedSurface
,
5235 ddraw_surface7_EnumAttachedSurfaces
,
5236 ddraw_surface7_EnumOverlayZOrders
,
5237 ddraw_surface7_Flip
,
5238 ddraw_surface7_GetAttachedSurface
,
5239 ddraw_surface7_GetBltStatus
,
5240 ddraw_surface7_GetCaps
,
5241 ddraw_surface7_GetClipper
,
5242 ddraw_surface7_GetColorKey
,
5243 ddraw_surface7_GetDC
,
5244 ddraw_surface7_GetFlipStatus
,
5245 ddraw_surface7_GetOverlayPosition
,
5246 ddraw_surface7_GetPalette
,
5247 ddraw_surface7_GetPixelFormat
,
5248 ddraw_surface7_GetSurfaceDesc
,
5249 ddraw_surface7_Initialize
,
5250 ddraw_surface7_IsLost
,
5251 ddraw_surface7_Lock
,
5252 ddraw_surface7_ReleaseDC
,
5253 ddraw_surface7_Restore
,
5254 ddraw_surface7_SetClipper
,
5255 ddraw_surface7_SetColorKey
,
5256 ddraw_surface7_SetOverlayPosition
,
5257 ddraw_surface7_SetPalette
,
5258 ddraw_surface7_Unlock
,
5259 ddraw_surface7_UpdateOverlay
,
5260 ddraw_surface7_UpdateOverlayDisplay
,
5261 ddraw_surface7_UpdateOverlayZOrder
,
5262 /* IDirectDrawSurface2 */
5263 ddraw_surface7_GetDDInterface
,
5264 ddraw_surface7_PageLock
,
5265 ddraw_surface7_PageUnlock
,
5266 /* IDirectDrawSurface3 */
5267 ddraw_surface7_SetSurfaceDesc
,
5268 /* IDirectDrawSurface4 */
5269 ddraw_surface7_SetPrivateData
,
5270 ddraw_surface7_GetPrivateData
,
5271 ddraw_surface7_FreePrivateData
,
5272 ddraw_surface7_GetUniquenessValue
,
5273 ddraw_surface7_ChangeUniquenessValue
,
5274 /* IDirectDrawSurface7 */
5275 ddraw_surface7_SetPriority
,
5276 ddraw_surface7_GetPriority
,
5277 ddraw_surface7_SetLOD
,
5278 ddraw_surface7_GetLOD
,
5281 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5284 ddraw_surface4_QueryInterface
,
5285 ddraw_surface4_AddRef
,
5286 ddraw_surface4_Release
,
5287 /* IDirectDrawSurface */
5288 ddraw_surface4_AddAttachedSurface
,
5289 ddraw_surface4_AddOverlayDirtyRect
,
5291 ddraw_surface4_BltBatch
,
5292 ddraw_surface4_BltFast
,
5293 ddraw_surface4_DeleteAttachedSurface
,
5294 ddraw_surface4_EnumAttachedSurfaces
,
5295 ddraw_surface4_EnumOverlayZOrders
,
5296 ddraw_surface4_Flip
,
5297 ddraw_surface4_GetAttachedSurface
,
5298 ddraw_surface4_GetBltStatus
,
5299 ddraw_surface4_GetCaps
,
5300 ddraw_surface4_GetClipper
,
5301 ddraw_surface4_GetColorKey
,
5302 ddraw_surface4_GetDC
,
5303 ddraw_surface4_GetFlipStatus
,
5304 ddraw_surface4_GetOverlayPosition
,
5305 ddraw_surface4_GetPalette
,
5306 ddraw_surface4_GetPixelFormat
,
5307 ddraw_surface4_GetSurfaceDesc
,
5308 ddraw_surface4_Initialize
,
5309 ddraw_surface4_IsLost
,
5310 ddraw_surface4_Lock
,
5311 ddraw_surface4_ReleaseDC
,
5312 ddraw_surface4_Restore
,
5313 ddraw_surface4_SetClipper
,
5314 ddraw_surface4_SetColorKey
,
5315 ddraw_surface4_SetOverlayPosition
,
5316 ddraw_surface4_SetPalette
,
5317 ddraw_surface4_Unlock
,
5318 ddraw_surface4_UpdateOverlay
,
5319 ddraw_surface4_UpdateOverlayDisplay
,
5320 ddraw_surface4_UpdateOverlayZOrder
,
5321 /* IDirectDrawSurface2 */
5322 ddraw_surface4_GetDDInterface
,
5323 ddraw_surface4_PageLock
,
5324 ddraw_surface4_PageUnlock
,
5325 /* IDirectDrawSurface3 */
5326 ddraw_surface4_SetSurfaceDesc
,
5327 /* IDirectDrawSurface4 */
5328 ddraw_surface4_SetPrivateData
,
5329 ddraw_surface4_GetPrivateData
,
5330 ddraw_surface4_FreePrivateData
,
5331 ddraw_surface4_GetUniquenessValue
,
5332 ddraw_surface4_ChangeUniquenessValue
,
5335 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5338 ddraw_surface3_QueryInterface
,
5339 ddraw_surface3_AddRef
,
5340 ddraw_surface3_Release
,
5341 /* IDirectDrawSurface */
5342 ddraw_surface3_AddAttachedSurface
,
5343 ddraw_surface3_AddOverlayDirtyRect
,
5345 ddraw_surface3_BltBatch
,
5346 ddraw_surface3_BltFast
,
5347 ddraw_surface3_DeleteAttachedSurface
,
5348 ddraw_surface3_EnumAttachedSurfaces
,
5349 ddraw_surface3_EnumOverlayZOrders
,
5350 ddraw_surface3_Flip
,
5351 ddraw_surface3_GetAttachedSurface
,
5352 ddraw_surface3_GetBltStatus
,
5353 ddraw_surface3_GetCaps
,
5354 ddraw_surface3_GetClipper
,
5355 ddraw_surface3_GetColorKey
,
5356 ddraw_surface3_GetDC
,
5357 ddraw_surface3_GetFlipStatus
,
5358 ddraw_surface3_GetOverlayPosition
,
5359 ddraw_surface3_GetPalette
,
5360 ddraw_surface3_GetPixelFormat
,
5361 ddraw_surface3_GetSurfaceDesc
,
5362 ddraw_surface3_Initialize
,
5363 ddraw_surface3_IsLost
,
5364 ddraw_surface3_Lock
,
5365 ddraw_surface3_ReleaseDC
,
5366 ddraw_surface3_Restore
,
5367 ddraw_surface3_SetClipper
,
5368 ddraw_surface3_SetColorKey
,
5369 ddraw_surface3_SetOverlayPosition
,
5370 ddraw_surface3_SetPalette
,
5371 ddraw_surface3_Unlock
,
5372 ddraw_surface3_UpdateOverlay
,
5373 ddraw_surface3_UpdateOverlayDisplay
,
5374 ddraw_surface3_UpdateOverlayZOrder
,
5375 /* IDirectDrawSurface2 */
5376 ddraw_surface3_GetDDInterface
,
5377 ddraw_surface3_PageLock
,
5378 ddraw_surface3_PageUnlock
,
5379 /* IDirectDrawSurface3 */
5380 ddraw_surface3_SetSurfaceDesc
,
5383 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5386 ddraw_surface2_QueryInterface
,
5387 ddraw_surface2_AddRef
,
5388 ddraw_surface2_Release
,
5389 /* IDirectDrawSurface */
5390 ddraw_surface2_AddAttachedSurface
,
5391 ddraw_surface2_AddOverlayDirtyRect
,
5393 ddraw_surface2_BltBatch
,
5394 ddraw_surface2_BltFast
,
5395 ddraw_surface2_DeleteAttachedSurface
,
5396 ddraw_surface2_EnumAttachedSurfaces
,
5397 ddraw_surface2_EnumOverlayZOrders
,
5398 ddraw_surface2_Flip
,
5399 ddraw_surface2_GetAttachedSurface
,
5400 ddraw_surface2_GetBltStatus
,
5401 ddraw_surface2_GetCaps
,
5402 ddraw_surface2_GetClipper
,
5403 ddraw_surface2_GetColorKey
,
5404 ddraw_surface2_GetDC
,
5405 ddraw_surface2_GetFlipStatus
,
5406 ddraw_surface2_GetOverlayPosition
,
5407 ddraw_surface2_GetPalette
,
5408 ddraw_surface2_GetPixelFormat
,
5409 ddraw_surface2_GetSurfaceDesc
,
5410 ddraw_surface2_Initialize
,
5411 ddraw_surface2_IsLost
,
5412 ddraw_surface2_Lock
,
5413 ddraw_surface2_ReleaseDC
,
5414 ddraw_surface2_Restore
,
5415 ddraw_surface2_SetClipper
,
5416 ddraw_surface2_SetColorKey
,
5417 ddraw_surface2_SetOverlayPosition
,
5418 ddraw_surface2_SetPalette
,
5419 ddraw_surface2_Unlock
,
5420 ddraw_surface2_UpdateOverlay
,
5421 ddraw_surface2_UpdateOverlayDisplay
,
5422 ddraw_surface2_UpdateOverlayZOrder
,
5423 /* IDirectDrawSurface2 */
5424 ddraw_surface2_GetDDInterface
,
5425 ddraw_surface2_PageLock
,
5426 ddraw_surface2_PageUnlock
,
5429 static struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5432 ddraw_surface1_QueryInterface
,
5433 ddraw_surface1_AddRef
,
5434 ddraw_surface1_Release
,
5435 /* IDirectDrawSurface */
5436 ddraw_surface1_AddAttachedSurface
,
5437 ddraw_surface1_AddOverlayDirtyRect
,
5439 ddraw_surface1_BltBatch
,
5440 ddraw_surface1_BltFast
,
5441 ddraw_surface1_DeleteAttachedSurface
,
5442 ddraw_surface1_EnumAttachedSurfaces
,
5443 ddraw_surface1_EnumOverlayZOrders
,
5444 ddraw_surface1_Flip
,
5445 ddraw_surface1_GetAttachedSurface
,
5446 ddraw_surface1_GetBltStatus
,
5447 ddraw_surface1_GetCaps
,
5448 ddraw_surface1_GetClipper
,
5449 ddraw_surface1_GetColorKey
,
5450 ddraw_surface1_GetDC
,
5451 ddraw_surface1_GetFlipStatus
,
5452 ddraw_surface1_GetOverlayPosition
,
5453 ddraw_surface1_GetPalette
,
5454 ddraw_surface1_GetPixelFormat
,
5455 ddraw_surface1_GetSurfaceDesc
,
5456 ddraw_surface1_Initialize
,
5457 ddraw_surface1_IsLost
,
5458 ddraw_surface1_Lock
,
5459 ddraw_surface1_ReleaseDC
,
5460 ddraw_surface1_Restore
,
5461 ddraw_surface1_SetClipper
,
5462 ddraw_surface1_SetColorKey
,
5463 ddraw_surface1_SetOverlayPosition
,
5464 ddraw_surface1_SetPalette
,
5465 ddraw_surface1_Unlock
,
5466 ddraw_surface1_UpdateOverlay
,
5467 ddraw_surface1_UpdateOverlayDisplay
,
5468 ddraw_surface1_UpdateOverlayZOrder
,
5471 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5473 ddraw_gamma_control_QueryInterface
,
5474 ddraw_gamma_control_AddRef
,
5475 ddraw_gamma_control_Release
,
5476 ddraw_gamma_control_GetGammaRamp
,
5477 ddraw_gamma_control_SetGammaRamp
,
5480 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5482 d3d_texture2_QueryInterface
,
5483 d3d_texture2_AddRef
,
5484 d3d_texture2_Release
,
5485 d3d_texture2_GetHandle
,
5486 d3d_texture2_PaletteChanged
,
5490 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5492 d3d_texture1_QueryInterface
,
5493 d3d_texture1_AddRef
,
5494 d3d_texture1_Release
,
5495 d3d_texture1_Initialize
,
5496 d3d_texture1_GetHandle
,
5497 d3d_texture1_PaletteChanged
,
5499 d3d_texture1_Unload
,
5502 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5503 * IDirectDrawSurface interface to ddraw methods. */
5504 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5506 if (!iface
) return NULL
;
5507 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5509 HRESULT hr
= IDirectDrawSurface7_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5512 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5515 IDirectDrawSurface7_Release(iface
);
5517 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5520 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5522 if (!iface
) return NULL
;
5523 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5525 HRESULT hr
= IDirectDrawSurface4_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5528 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5531 IDirectDrawSurface4_Release(iface
);
5533 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5536 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5538 if (!iface
) return NULL
;
5539 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5541 HRESULT hr
= IDirectDrawSurface3_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5544 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5547 IDirectDrawSurface3_Release(iface
);
5549 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5552 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5554 if (!iface
) return NULL
;
5555 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5557 HRESULT hr
= IDirectDrawSurface2_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5560 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5563 IDirectDrawSurface2_Release(iface
);
5565 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5568 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5570 if (!iface
) return NULL
;
5571 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5573 HRESULT hr
= IDirectDrawSurface_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5576 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5579 IDirectDrawSurface_Release(iface
);
5581 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5584 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5586 if (!iface
) return NULL
;
5587 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5588 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5591 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5593 if (!iface
) return NULL
;
5594 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5595 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5598 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5600 struct ddraw_surface
*surface
= parent
;
5602 TRACE("surface %p.\n", surface
);
5604 /* Check for attached surfaces and detach them. */
5605 if (surface
->first_attached
!= surface
)
5607 /* Well, this shouldn't happen: The surface being attached is
5608 * referenced in AddAttachedSurface(), so it shouldn't be released
5609 * until DeleteAttachedSurface() is called, because the refcount is
5610 * held. It looks like the application released it often enough to
5612 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5614 /* The refcount will drop to -1 here */
5615 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5616 ERR("DeleteAttachedSurface failed.\n");
5619 while (surface
->next_attached
)
5620 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5621 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5622 ERR("DeleteAttachedSurface failed.\n");
5624 /* Having a texture handle set implies that the device still exists. */
5625 if (surface
->Handle
)
5626 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5628 /* Reduce the ddraw surface count. */
5629 list_remove(&surface
->surface_list_entry
);
5631 if (surface
->clipper
)
5632 IDirectDrawClipper_Release(&surface
->clipper
->IDirectDrawClipper_iface
);
5634 if (surface
== surface
->ddraw
->primary
)
5635 surface
->ddraw
->primary
= NULL
;
5637 wined3d_private_store_cleanup(&surface
->private_store
);
5639 HeapFree(GetProcessHeap(), 0, surface
);
5642 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5644 ddraw_surface_wined3d_object_destroyed
,
5647 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5649 TRACE("parent %p.\n", parent
);
5651 HeapFree(GetProcessHeap(), 0, parent
);
5654 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5656 ddraw_texture_wined3d_object_destroyed
,
5659 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
5664 HRESULT
ddraw_surface_create(struct ddraw
*ddraw
, const DDSURFACEDESC2
*surface_desc
,
5665 struct ddraw_surface
**surface
, IUnknown
*outer_unknown
, unsigned int version
)
5667 struct ddraw_surface
*root
, *mip
, **attach
;
5668 struct wined3d_resource_desc wined3d_desc
;
5669 struct wined3d_texture
*wined3d_texture
;
5670 struct wined3d_resource
*resource
;
5671 struct wined3d_display_mode mode
;
5672 DDSURFACEDESC2
*desc
, *mip_desc
;
5673 struct ddraw_texture
*texture
;
5674 UINT layers
, levels
, i
, j
;
5675 unsigned int pitch
= 0;
5678 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p, version %u.\n",
5679 ddraw
, surface_desc
, surface
, outer_unknown
, version
);
5680 if (TRACE_ON(ddraw
))
5682 TRACE("Requesting surface desc:\n");
5683 DDRAW_dump_surface_desc(surface_desc
);
5687 return CLASS_E_NOAGGREGATION
;
5692 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
5693 return E_OUTOFMEMORY
;
5695 texture
->version
= version
;
5696 texture
->surface_desc
= *surface_desc
;
5697 desc
= &texture
->surface_desc
;
5699 /* Ensure DDSD_CAPS is always set. */
5700 desc
->dwFlags
|= DDSD_CAPS
;
5702 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5704 DWORD flippable
= desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
);
5706 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5708 WARN("Tried to create a primary surface with DDSCAPS_TEXTURE.\n");
5709 HeapFree(GetProcessHeap(), 0, texture
);
5710 return DDERR_INVALIDCAPS
;
5715 if (flippable
!= (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
))
5717 WARN("Tried to create a flippable primary surface without both DDSCAPS_FLIP and DDSCAPS_COMPLEX.\n");
5718 HeapFree(GetProcessHeap(), 0, texture
);
5719 return DDERR_INVALIDCAPS
;
5722 if (!(desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
) || !desc
->u5
.dwBackBufferCount
)
5724 WARN("Tried to create a flippable primary surface without any back buffers.\n");
5725 HeapFree(GetProcessHeap(), 0, texture
);
5726 return DDERR_INVALIDCAPS
;
5729 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
5731 WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
5732 HeapFree(GetProcessHeap(), 0, texture
);
5733 return DDERR_NOEXCLUSIVEMODE
;
5738 /* This is a special case in ddrawex, but not allowed in ddraw. */
5739 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5740 == (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5742 WARN("Tried to create a surface in both system and video memory.\n");
5743 HeapFree(GetProcessHeap(), 0, texture
);
5744 return DDERR_INVALIDCAPS
;
5747 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
)
5748 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
5750 WARN("Cube map faces requested without cube map flag.\n");
5751 HeapFree(GetProcessHeap(), 0, texture
);
5752 return DDERR_INVALIDCAPS
;
5755 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5756 && !(desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
))
5758 WARN("Cube map without faces requested.\n");
5759 HeapFree(GetProcessHeap(), 0, texture
);
5760 return DDERR_INVALIDPARAMS
;
5763 if ((desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5764 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
5765 FIXME("Partial cube maps not implemented.\n");
5767 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5769 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5771 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
5772 HeapFree(GetProcessHeap(), 0, texture
);
5773 return DDERR_INVALIDCAPS
;
5775 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5777 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
5778 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
5779 HeapFree(GetProcessHeap(), 0, texture
);
5780 return DDERR_INVALIDCAPS
;
5784 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
5786 ERR("Failed to get display mode, hr %#x.\n", hr
);
5787 HeapFree(GetProcessHeap(), 0, texture
);
5788 return hr_ddraw_from_wined3d(hr
);
5791 /* No pixelformat given? Use the current screen format. */
5792 if (!(desc
->dwFlags
& DDSD_PIXELFORMAT
))
5794 desc
->dwFlags
|= DDSD_PIXELFORMAT
;
5795 desc
->u4
.ddpfPixelFormat
.dwSize
= sizeof(desc
->u4
.ddpfPixelFormat
);
5796 ddrawformat_from_wined3dformat(&desc
->u4
.ddpfPixelFormat
, mode
.format_id
);
5799 wined3d_desc
.format
= wined3dformat_from_ddrawformat(&desc
->u4
.ddpfPixelFormat
);
5800 if (wined3d_desc
.format
== WINED3DFMT_UNKNOWN
)
5802 WARN("Unsupported / unknown pixelformat.\n");
5803 HeapFree(GetProcessHeap(), 0, texture
);
5804 return DDERR_INVALIDPIXELFORMAT
;
5807 /* No width or no height? Use the screen size. */
5808 if (!(desc
->dwFlags
& DDSD_WIDTH
) || !(desc
->dwFlags
& DDSD_HEIGHT
))
5810 if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
5812 WARN("No width / height specified.\n");
5813 HeapFree(GetProcessHeap(), 0, texture
);
5814 return DDERR_INVALIDPARAMS
;
5817 desc
->dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5818 desc
->dwWidth
= mode
.width
;
5819 desc
->dwHeight
= mode
.height
;
5822 if (!desc
->dwWidth
|| !desc
->dwHeight
)
5824 HeapFree(GetProcessHeap(), 0, texture
);
5825 return DDERR_INVALIDPARAMS
;
5828 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5830 /* The first surface is a front buffer, the back buffers are created
5832 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_FLIP
)
5833 desc
->ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
5834 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5835 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
5837 struct wined3d_swapchain_desc swapchain_desc
;
5839 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
5840 swapchain_desc
.backbuffer_width
= mode
.width
;
5841 swapchain_desc
.backbuffer_height
= mode
.height
;
5842 swapchain_desc
.backbuffer_format
= mode
.format_id
;
5844 if (FAILED(hr
= wined3d_device_reset(ddraw
->wined3d_device
,
5845 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
)))
5847 ERR("Failed to reset device.\n");
5848 HeapFree(GetProcessHeap(), 0, texture
);
5849 return hr_ddraw_from_wined3d(hr
);
5854 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
5855 wined3d_desc
.multisample_quality
= 0;
5856 wined3d_desc
.usage
= 0;
5857 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
5858 wined3d_desc
.width
= desc
->dwWidth
;
5859 wined3d_desc
.height
= desc
->dwHeight
;
5860 wined3d_desc
.depth
= 1;
5861 wined3d_desc
.size
= 0;
5863 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
5865 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
5866 /* Do not fail surface creation, only fail 3D device creation. */
5869 /* Mipmap count fixes */
5870 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5872 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
5874 if (desc
->dwFlags
& DDSD_MIPMAPCOUNT
)
5876 /* Mipmap count is given, should not be 0. */
5877 if (!desc
->u2
.dwMipMapCount
)
5879 HeapFree(GetProcessHeap(), 0, texture
);
5880 return DDERR_INVALIDPARAMS
;
5885 /* Undocumented feature: Create sublevels until either the
5886 * width or the height is 1. */
5887 desc
->u2
.dwMipMapCount
= wined3d_log2i(min(desc
->dwWidth
, desc
->dwHeight
)) + 1;
5892 desc
->u2
.dwMipMapCount
= 1;
5895 desc
->dwFlags
|= DDSD_MIPMAPCOUNT
;
5896 levels
= desc
->u2
.dwMipMapCount
;
5903 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
)))
5905 if (!(desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
5907 enum wined3d_resource_type rtype
;
5910 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5911 rtype
= WINED3D_RTYPE_CUBE_TEXTURE
;
5912 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5913 rtype
= WINED3D_RTYPE_TEXTURE
;
5915 rtype
= WINED3D_RTYPE_SURFACE
;
5917 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5918 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
5919 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5920 usage
= WINED3DUSAGE_RENDERTARGET
;
5922 if (SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5923 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, usage
, rtype
, wined3d_desc
.format
)))
5924 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
5926 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5928 else if (!(desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
5930 /* Tests show surfaces without memory flags get these flags added
5931 * right after creation. */
5932 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5936 if ((desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5937 == (DDSCAPS_OVERLAY
| DDSCAPS_SYSTEMMEMORY
))
5939 WARN("System memory overlays are not allowed.\n");
5940 HeapFree(GetProcessHeap(), 0, texture
);
5941 return DDERR_NOOVERLAYHW
;
5944 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5947 * The ddraw RGB device allows to use system memory surfaces as rendering target.
5948 * This does not cause problems because the RGB device does software rasterization
5949 * though it will fail with hardware accelerated ddraw. In order to be partially
5950 * compatible with games requesting explicitly the RGB device, we ignore the
5951 * specified location and try to create rendering targets in video memory if
5954 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
5955 SUCCEEDED(hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
5956 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, WINED3DUSAGE_RENDERTARGET
,
5957 WINED3D_RTYPE_SURFACE
, wined3d_desc
.format
)))
5959 FIXME("Application wants to create rendering target in system memory, using video memory instead\n");
5960 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
5963 wined3d_desc
.pool
= WINED3D_POOL_SYSTEM_MEM
;
5967 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5968 wined3d_desc
.usage
|= WINED3DUSAGE_TEXTURE
;
5969 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5970 wined3d_desc
.usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5971 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
5972 wined3d_desc
.usage
|= WINED3DUSAGE_RENDERTARGET
;
5974 if (desc
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
5976 wined3d_desc
.pool
= WINED3D_POOL_MANAGED
;
5977 /* Managed textures have the system memory flag set. */
5978 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5980 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5982 /* Videomemory adds localvidmem. This is mutually exclusive with
5983 * systemmemory and texturemanage. */
5984 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5985 wined3d_desc
.usage
|= WINED3DUSAGE_DYNAMIC
;
5989 /* If the surface is of the 'ALLOCONLOAD' type, ignore the LPSURFACE
5990 * field. Frank Herbert's Dune specifies a NULL pointer for lpSurface. */
5991 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
) || !desc
->lpSurface
)
5992 desc
->dwFlags
&= ~DDSD_LPSURFACE
;
5993 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5995 if (wined3d_desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
5997 WARN("User memory surfaces should be in the system memory pool.\n");
5998 HeapFree(GetProcessHeap(), 0, texture
);
5999 return DDERR_INVALIDCAPS
;
6004 WARN("User memory surfaces not supported before version 4.\n");
6005 HeapFree(GetProcessHeap(), 0, texture
);
6006 return DDERR_INVALIDPARAMS
;
6009 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6011 if (version
!= 4 && (desc
->dwFlags
& DDSD_PITCH
))
6013 WARN("Pitch specified on a compressed user memory surface.\n");
6014 HeapFree(GetProcessHeap(), 0, texture
);
6015 return DDERR_INVALIDPARAMS
;
6018 if (!(desc
->dwFlags
& (DDSD_LINEARSIZE
| DDSD_PITCH
)))
6020 WARN("Compressed user memory surfaces should explicitly specify the linear size.\n");
6021 HeapFree(GetProcessHeap(), 0, texture
);
6022 return DDERR_INVALIDPARAMS
;
6025 if ((desc
->dwFlags
& DDSD_LINEARSIZE
)
6026 && desc
->u1
.dwLinearSize
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6027 wined3d_desc
.format
, wined3d_desc
.width
) * ((desc
->dwHeight
+ 3) / 4))
6029 WARN("Invalid linear size %u specified.\n", desc
->u1
.dwLinearSize
);
6030 HeapFree(GetProcessHeap(), 0, texture
);
6031 return DDERR_INVALIDPARAMS
;
6036 if (!(desc
->dwFlags
& DDSD_PITCH
))
6038 WARN("User memory surfaces should explicitly specify the pitch.\n");
6039 HeapFree(GetProcessHeap(), 0, texture
);
6040 return DDERR_INVALIDPARAMS
;
6043 if (desc
->u1
.lPitch
< wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
6044 wined3d_desc
.format
, wined3d_desc
.width
) || desc
->u1
.lPitch
& 3)
6046 WARN("Invalid pitch %u specified.\n", desc
->u1
.lPitch
);
6047 HeapFree(GetProcessHeap(), 0, texture
);
6048 return DDERR_INVALIDPARAMS
;
6051 pitch
= desc
->u1
.lPitch
;
6055 if (((desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6056 && desc
->u3
.ddckCKDestOverlay
.dwColorSpaceLowValue
!= desc
->u3
.ddckCKDestOverlay
.dwColorSpaceHighValue
)
6057 || ((desc
->dwFlags
& DDSD_CKDESTBLT
)
6058 && desc
->ddckCKDestBlt
.dwColorSpaceLowValue
!= desc
->ddckCKDestBlt
.dwColorSpaceHighValue
)
6059 || ((desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6060 && desc
->ddckCKSrcOverlay
.dwColorSpaceLowValue
!= desc
->ddckCKSrcOverlay
.dwColorSpaceHighValue
)
6061 || ((desc
->dwFlags
& DDSD_CKSRCBLT
)
6062 && desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
!= desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
))
6064 WARN("Range color keys not supported, returning DDERR_NOCOLORKEYHW.\n");
6065 HeapFree(GetProcessHeap(), 0, texture
);
6066 return DDERR_NOCOLORKEYHW
;
6069 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
6070 wined3d_desc
.usage
|= WINED3DUSAGE_OVERLAY
;
6072 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
6073 wined3d_desc
.usage
|= WINED3DUSAGE_OWNDC
;
6075 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6077 wined3d_desc
.resource_type
= WINED3D_RTYPE_CUBE_TEXTURE
;
6082 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
6086 /* Some applications assume surfaces will always be mapped at the same
6087 * address. Some of those also assume that this address is valid even when
6088 * the surface isn't mapped, and that updates done this way will be
6089 * visible on the screen. The game Nox is such an application,
6090 * Commandos: Behind Enemy Lines is another. We set
6091 * WINED3D_SURFACE_PIN_SYSMEM because of this. */
6092 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, levels
,
6093 WINED3D_SURFACE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6095 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
6096 HeapFree(GetProcessHeap(), 0, texture
);
6097 return hr_ddraw_from_wined3d(hr
);
6100 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6101 root
= wined3d_resource_get_parent(resource
);
6102 root
->wined3d_texture
= wined3d_texture
;
6103 root
->is_complex_root
= TRUE
;
6104 texture
->root
= root
;
6106 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6107 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6108 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6109 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6110 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6111 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6112 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6113 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6114 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6115 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6116 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6117 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6119 for (i
= 0; i
< layers
; ++i
)
6121 attach
= &root
->complex_array
[layers
- 1 - i
];
6123 for (j
= 0; j
< levels
; ++j
)
6125 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, i
* levels
+ j
);
6126 mip
= wined3d_resource_get_parent(resource
);
6127 mip_desc
= &mip
->surface_desc
;
6130 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
6132 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
6134 if (mip_desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6136 mip_desc
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
6140 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
6141 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
6143 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
6144 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
6146 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
6147 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
6149 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
6150 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
6152 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
6153 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
6155 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
6156 mip_desc
->ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
6166 attach
= &mip
->complex_array
[0];
6170 if ((desc
->dwFlags
& DDSD_LPSURFACE
) && FAILED(hr
= wined3d_texture_update_desc(wined3d_texture
,
6171 wined3d_desc
.width
, wined3d_desc
.height
, wined3d_desc
.format
,
6172 WINED3D_MULTISAMPLE_NONE
, 0, desc
->lpSurface
, pitch
)))
6174 ERR("Failed to set surface memory, hr %#x.\n", hr
);
6178 if (desc
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
6180 unsigned int count
= desc
->u5
.dwBackBufferCount
;
6181 struct ddraw_surface
*last
= root
;
6183 attach
= &last
->complex_array
[0];
6184 for (i
= 0; i
< count
; ++i
)
6186 if (!(texture
= HeapAlloc(GetProcessHeap(), 0, sizeof(*texture
))))
6192 texture
->version
= version
;
6193 texture
->surface_desc
= root
->surface_desc
;
6194 desc
= &texture
->surface_desc
;
6196 /* Only one surface in the flipping chain is a back buffer, one is
6197 * a front buffer, the others are just flippable surfaces. */
6198 desc
->ddsCaps
.dwCaps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
6199 | DDSCAPS_BACKBUFFER
);
6201 desc
->ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
6202 desc
->u5
.dwBackBufferCount
= 0;
6204 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &wined3d_desc
, 1,
6205 WINED3D_SURFACE_PIN_SYSMEM
, NULL
, texture
, &ddraw_texture_wined3d_parent_ops
, &wined3d_texture
)))
6207 HeapFree(GetProcessHeap(), 0, texture
);
6208 hr
= hr_ddraw_from_wined3d(hr
);
6212 resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
6213 last
= wined3d_resource_get_parent(resource
);
6214 last
->wined3d_texture
= wined3d_texture
;
6215 texture
->root
= last
;
6217 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
6218 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTOVERLAY
,
6219 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
6220 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
6221 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_DESTBLT
,
6222 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
6223 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
6224 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCOVERLAY
,
6225 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
6226 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
6227 wined3d_texture_set_color_key(wined3d_texture
, DDCKEY_SRCBLT
,
6228 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
6231 attach
= &last
->complex_array
[0];
6236 if (surface_desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
6237 ddraw
->primary
= root
;
6244 IDirectDrawSurface7_Release(&root
->IDirectDrawSurface7_iface
);
6245 else if (version
== 4)
6246 IDirectDrawSurface4_Release(&root
->IDirectDrawSurface4_iface
);
6248 IDirectDrawSurface_Release(&root
->IDirectDrawSurface_iface
);
6253 void ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
, struct ddraw_texture
*texture
,
6254 struct wined3d_surface
*wined3d_surface
, const struct wined3d_parent_ops
**parent_ops
)
6256 DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
6257 struct wined3d_resource_desc wined3d_desc
;
6258 unsigned int version
= texture
->version
;
6260 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
6261 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
6262 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
6263 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
6264 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
6265 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
6266 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
6267 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
6268 surface
->iface_count
= 1;
6269 surface
->version
= version
;
6270 surface
->ddraw
= ddraw
;
6275 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface7_iface
;
6277 else if (version
== 4)
6280 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface4_iface
;
6285 surface
->texture_outer
= (IUnknown
*)&surface
->IDirectDrawSurface_iface
;
6288 *desc
= texture
->surface_desc
;
6289 wined3d_resource_get_desc(wined3d_surface_get_resource(wined3d_surface
), &wined3d_desc
);
6290 desc
->dwWidth
= wined3d_desc
.width
;
6291 desc
->dwHeight
= wined3d_desc
.height
;
6292 surface
->first_attached
= surface
;
6294 if (format_is_compressed(&desc
->u4
.ddpfPixelFormat
))
6296 if (desc
->dwFlags
& DDSD_LPSURFACE
)
6297 desc
->u1
.dwLinearSize
= ~0u;
6299 desc
->u1
.dwLinearSize
= wined3d_surface_get_pitch(wined3d_surface
) * ((desc
->dwHeight
+ 3) / 4);
6300 desc
->dwFlags
|= DDSD_LINEARSIZE
;
6301 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_PITCH
);
6305 if (!(desc
->dwFlags
& DDSD_LPSURFACE
))
6306 desc
->u1
.lPitch
= wined3d_surface_get_pitch(wined3d_surface
);
6307 desc
->dwFlags
|= DDSD_PITCH
;
6308 desc
->dwFlags
&= ~(DDSD_LPSURFACE
| DDSD_LINEARSIZE
);
6310 desc
->lpSurface
= NULL
;
6312 wined3d_surface_incref(wined3d_surface
);
6313 surface
->wined3d_surface
= wined3d_surface
;
6314 *parent_ops
= &ddraw_surface_wined3d_parent_ops
;
6316 wined3d_private_store_init(&surface
->private_store
);
6319 static void STDMETHODCALLTYPE
view_wined3d_object_destroyed(void *parent
)
6321 struct ddraw_surface
*surface
= parent
;
6323 /* If the surface reference count drops to zero, we release our reference
6324 * to the view, but don't clear the pointer yet, in case e.g. a
6325 * GetRenderTarget() call brings the surface back before the view is
6326 * actually destroyed. When the view is destroyed, we need to clear the
6327 * pointer, or a subsequent surface AddRef() would reference it again.
6329 * This is safe because as long as the view still has a reference to the
6330 * texture, the surface is also still alive, and we're called before the
6331 * view releases that reference. */
6332 surface
->wined3d_rtv
= NULL
;
6335 static const struct wined3d_parent_ops ddraw_view_wined3d_parent_ops
=
6337 view_wined3d_object_destroyed
,
6340 struct wined3d_rendertarget_view
*ddraw_surface_get_rendertarget_view(struct ddraw_surface
*surface
)
6344 if (surface
->wined3d_rtv
)
6345 return surface
->wined3d_rtv
;
6347 if (FAILED(hr
= wined3d_rendertarget_view_create_from_surface(surface
->wined3d_surface
,
6348 surface
, &ddraw_view_wined3d_parent_ops
, &surface
->wined3d_rtv
)))
6350 ERR("Failed to create rendertarget view, hr %#x.\n", hr
);
6354 return surface
->wined3d_rtv
;