1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
);
32 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
);
34 static inline struct ddraw_surface
*impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl
*iface
)
36 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawGammaControl_iface
);
39 /* This is slow, of course. Also, in case of locks, we can't prevent other
40 * applications from drawing to the screen while we've locked the frontbuffer.
41 * We'd like to do this in wined3d instead, but for that to work wined3d needs
42 * to support windowless rendering first. */
43 static HRESULT
ddraw_surface_update_frontbuffer(struct ddraw_surface
*surface
, const RECT
*rect
, BOOL read
)
45 HDC surface_dc
, screen_dc
;
54 w
= surface
->surface_desc
.dwWidth
;
55 h
= surface
->surface_desc
.dwHeight
;
61 w
= rect
->right
- rect
->left
;
62 h
= rect
->bottom
- rect
->top
;
68 if (surface
->ddraw
->swapchain_window
)
70 /* Nothing to do, we control the frontbuffer, or at least the parts we
75 return wined3d_surface_blt(surface
->ddraw
->wined3d_frontbuffer
, rect
,
76 surface
->wined3d_surface
, rect
, 0, NULL
, WINED3D_TEXF_POINT
);
79 if (FAILED(hr
= wined3d_surface_getdc(surface
->wined3d_surface
, &surface_dc
)))
81 ERR("Failed to get surface DC, hr %#x.\n", hr
);
85 if (!(screen_dc
= GetDC(NULL
)))
87 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
88 ERR("Failed to get screen DC.\n");
93 ret
= BitBlt(surface_dc
, x
, y
, w
, h
,
94 screen_dc
, x
, y
, SRCCOPY
);
96 ret
= BitBlt(screen_dc
, x
, y
, w
, h
,
97 surface_dc
, x
, y
, SRCCOPY
);
99 ReleaseDC(NULL
, screen_dc
);
100 wined3d_surface_releasedc(surface
->wined3d_surface
, surface_dc
);
104 ERR("Failed to blit to/from screen.\n");
111 /*****************************************************************************
112 * IUnknown parts follow
113 *****************************************************************************/
115 /*****************************************************************************
116 * IDirectDrawSurface7::QueryInterface
118 * A normal QueryInterface implementation. For QueryInterface rules
119 * see ddraw.c, IDirectDraw7::QueryInterface. This method
120 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
121 * in all versions, the IDirectDrawGammaControl interface and it can
122 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
125 * riid: The interface id queried for
126 * obj: Address to write the pointer to
130 * E_NOINTERFACE if the requested interface wasn't found
132 *****************************************************************************/
133 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
135 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
137 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
139 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
143 return DDERR_INVALIDPARAMS
;
145 if (IsEqualGUID(riid
, &IID_IUnknown
)
146 || IsEqualGUID(riid
, &IID_IDirectDrawSurface7
) )
148 IDirectDrawSurface7_AddRef(iface
);
150 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
153 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface4
))
155 IDirectDrawSurface4_AddRef(&This
->IDirectDrawSurface4_iface
);
156 *obj
= &This
->IDirectDrawSurface4_iface
;
157 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This
, *obj
);
160 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface3
))
162 IDirectDrawSurface3_AddRef(&This
->IDirectDrawSurface3_iface
);
163 *obj
= &This
->IDirectDrawSurface3_iface
;
164 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
167 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface2
))
169 IDirectDrawSurface2_AddRef(&This
->IDirectDrawSurface2_iface
);
170 *obj
= &This
->IDirectDrawSurface2_iface
;
171 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This
, *obj
);
174 else if (IsEqualGUID(riid
, &IID_IDirectDrawSurface
))
176 IDirectDrawSurface_AddRef(&This
->IDirectDrawSurface_iface
);
177 *obj
= &This
->IDirectDrawSurface_iface
;
178 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This
, *obj
);
181 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
183 IDirectDrawGammaControl_AddRef(&This
->IDirectDrawGammaControl_iface
);
184 *obj
= &This
->IDirectDrawGammaControl_iface
;
185 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
188 else if( IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
) ||
189 IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)||
190 IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
) )
192 IDirect3DDevice7
*d3d
;
193 IDirect3DDeviceImpl
*device_impl
;
195 /* Call into IDirect3D7 for creation */
196 IDirect3D7_CreateDevice(&This
->ddraw
->IDirect3D7_iface
, riid
, &This
->IDirectDrawSurface7_iface
,
201 device_impl
= impl_from_IDirect3DDevice7(d3d
);
202 device_impl
->from_surface
= TRUE
;
203 *obj
= &device_impl
->IDirect3DDevice_iface
;
204 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
208 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
209 return E_NOINTERFACE
;
211 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
212 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
214 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
216 *obj
= &This
->IDirect3DTexture_iface
;
217 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
221 *obj
= &This
->IDirect3DTexture2_iface
;
222 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
224 IUnknown_AddRef( (IUnknown
*) *obj
);
228 ERR("No interface\n");
229 return E_NOINTERFACE
;
232 static HRESULT WINAPI
ddraw_surface4_QueryInterface(IDirectDrawSurface4
*iface
, REFIID riid
, void **object
)
234 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
236 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
238 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
241 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
243 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
245 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
247 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
250 static HRESULT WINAPI
ddraw_surface2_QueryInterface(IDirectDrawSurface2
*iface
, REFIID riid
, void **object
)
252 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
254 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
256 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
259 static HRESULT WINAPI
ddraw_surface1_QueryInterface(IDirectDrawSurface
*iface
, REFIID riid
, void **object
)
261 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
263 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
265 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
268 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
,
269 REFIID riid
, void **object
)
271 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
273 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
275 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
278 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
280 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
282 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
284 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
287 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
289 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
291 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
293 return ddraw_surface7_QueryInterface(&surface
->IDirectDrawSurface7_iface
, riid
, object
);
296 static void ddraw_surface_add_iface(struct ddraw_surface
*This
)
298 ULONG iface_count
= InterlockedIncrement(&This
->iface_count
);
299 TRACE("%p increasing iface count to %u.\n", This
, iface_count
);
301 if (iface_count
== 1)
303 wined3d_mutex_lock();
304 if (This
->wined3d_surface
)
305 wined3d_surface_incref(This
->wined3d_surface
);
306 if (This
->wined3d_texture
)
307 wined3d_texture_incref(This
->wined3d_texture
);
308 wined3d_mutex_unlock();
312 /*****************************************************************************
313 * IDirectDrawSurface7::AddRef
315 * A normal addref implementation
320 *****************************************************************************/
321 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
323 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
324 ULONG refcount
= InterlockedIncrement(&This
->ref7
);
326 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
330 ddraw_surface_add_iface(This
);
336 static ULONG WINAPI
ddraw_surface4_AddRef(IDirectDrawSurface4
*iface
)
338 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
339 ULONG refcount
= InterlockedIncrement(&This
->ref4
);
341 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
345 ddraw_surface_add_iface(This
);
351 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
353 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
354 ULONG refcount
= InterlockedIncrement(&This
->ref3
);
356 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
360 ddraw_surface_add_iface(This
);
366 static ULONG WINAPI
ddraw_surface2_AddRef(IDirectDrawSurface2
*iface
)
368 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
369 ULONG refcount
= InterlockedIncrement(&This
->ref2
);
371 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
375 ddraw_surface_add_iface(This
);
381 static ULONG WINAPI
ddraw_surface1_AddRef(IDirectDrawSurface
*iface
)
383 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
384 ULONG refcount
= InterlockedIncrement(&This
->ref1
);
386 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
390 ddraw_surface_add_iface(This
);
396 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
398 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
399 ULONG refcount
= InterlockedIncrement(&This
->gamma_count
);
401 TRACE("iface %p increasing refcount to %u.\n", iface
, refcount
);
405 ddraw_surface_add_iface(This
);
411 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
413 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
415 TRACE("iface %p.\n", iface
);
417 return ddraw_surface1_AddRef(&surface
->IDirectDrawSurface_iface
);
420 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
422 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
424 TRACE("iface %p.\n", iface
);
426 return ddraw_surface1_AddRef(&surface
->IDirectDrawSurface_iface
);
429 /*****************************************************************************
430 * ddraw_surface_destroy
432 * A helper function for IDirectDrawSurface7::Release
434 * Frees the surface, regardless of its refcount.
435 * See IDirectDrawSurface7::Release for more information
438 * This: Surface to free
440 *****************************************************************************/
441 static void ddraw_surface_destroy(struct ddraw_surface
*This
)
443 TRACE("surface %p.\n", This
);
445 /* Check the iface count and give a warning */
446 if(This
->iface_count
> 1)
448 /* This can happen when a complex surface is destroyed,
449 * because the 2nd surface was addref()ed when the app
450 * called GetAttachedSurface
452 WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n",
453 This
, This
->ref7
, This
->ref4
, This
->ref3
, This
->ref2
, This
->ref1
);
456 if (This
->wined3d_surface
)
457 wined3d_surface_decref(This
->wined3d_surface
);
460 static void ddraw_surface_cleanup(struct ddraw_surface
*surface
)
462 struct ddraw_surface
*surf
;
463 IUnknown
*ifaceToRelease
;
466 TRACE("surface %p.\n", surface
);
468 /* The refcount test shows that the palette is detached when the surface
470 IDirectDrawSurface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, NULL
);
472 /* Loop through all complex attached surfaces and destroy them.
474 * Yet again, only the root can have more than one complexly attached
475 * surface, all the others have a total of one. */
476 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
478 if (!surface
->complex_array
[i
])
481 surf
= surface
->complex_array
[i
];
482 surface
->complex_array
[i
] = NULL
;
485 struct ddraw_surface
*destroy
= surf
;
486 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
487 ddraw_surface_destroy(destroy
); /* Destroy it */
491 ifaceToRelease
= surface
->ifaceToRelease
;
493 /* Destroy the root surface. */
494 ddraw_surface_destroy(surface
);
496 /* Reduce the ddraw refcount */
498 IUnknown_Release(ifaceToRelease
);
501 ULONG
ddraw_surface_release_iface(struct ddraw_surface
*This
)
503 ULONG iface_count
= InterlockedDecrement(&This
->iface_count
);
504 TRACE("%p decreasing iface count to %u.\n", This
, iface_count
);
506 if (iface_count
== 0)
508 /* Complex attached surfaces are destroyed implicitly when the root is released */
509 wined3d_mutex_lock();
510 if(!This
->is_complex_root
)
512 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
513 wined3d_mutex_unlock();
516 if (This
->wined3d_texture
) /* If it's a texture, destroy the wined3d texture. */
517 wined3d_texture_decref(This
->wined3d_texture
);
519 ddraw_surface_cleanup(This
);
520 wined3d_mutex_unlock();
526 /*****************************************************************************
527 * IDirectDrawSurface7::Release
529 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
530 * surface is destroyed.
532 * Destroying the surface is a bit tricky. For the connection between
533 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
534 * It has a nice graph explaining the connection.
536 * What happens here is basically this:
537 * When a surface is destroyed, its WineD3DSurface is released,
538 * and the refcount of the DirectDraw interface is reduced by 1. If it has
539 * complex surfaces attached to it, then these surfaces are destroyed too,
540 * regardless of their refcount. If any surface being destroyed has another
541 * surface attached to it (with a "soft" attachment, not complex), then
542 * this surface is detached with DeleteAttachedSurface.
544 * When the surface is a texture, the WineD3DTexture is released.
545 * If the surface is the Direct3D render target, then the D3D
546 * capabilities of the WineD3DDevice are uninitialized, which causes the
547 * swapchain to be released.
549 * When a complex sublevel falls to ref zero, then this is ignored.
554 *****************************************************************************/
555 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
557 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
558 ULONG refcount
= InterlockedDecrement(&This
->ref7
);
560 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
564 ddraw_surface_release_iface(This
);
570 static ULONG WINAPI
ddraw_surface4_Release(IDirectDrawSurface4
*iface
)
572 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
573 ULONG refcount
= InterlockedDecrement(&This
->ref4
);
575 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
579 ddraw_surface_release_iface(This
);
585 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
587 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
588 ULONG refcount
= InterlockedDecrement(&This
->ref3
);
590 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
594 ddraw_surface_release_iface(This
);
600 static ULONG WINAPI
ddraw_surface2_Release(IDirectDrawSurface2
*iface
)
602 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
603 ULONG refcount
= InterlockedDecrement(&This
->ref2
);
605 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
609 ddraw_surface_release_iface(This
);
615 static ULONG WINAPI
ddraw_surface1_Release(IDirectDrawSurface
*iface
)
617 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
618 ULONG refcount
= InterlockedDecrement(&This
->ref1
);
620 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
624 ddraw_surface_release_iface(This
);
630 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
632 struct ddraw_surface
*This
= impl_from_IDirectDrawGammaControl(iface
);
633 ULONG refcount
= InterlockedDecrement(&This
->gamma_count
);
635 TRACE("iface %p decreasing refcount to %u.\n", iface
, refcount
);
639 ddraw_surface_release_iface(This
);
645 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
647 struct ddraw_surface
*This
= impl_from_IDirect3DTexture2(iface
);
648 TRACE("iface %p.\n", iface
);
650 return ddraw_surface1_Release(&This
->IDirectDrawSurface_iface
);
653 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
655 struct ddraw_surface
*This
= impl_from_IDirect3DTexture(iface
);
656 TRACE("iface %p.\n", iface
);
658 return ddraw_surface1_Release(&This
->IDirectDrawSurface_iface
);
661 /*****************************************************************************
662 * IDirectDrawSurface7::GetAttachedSurface
664 * Returns an attached surface with the requested caps. Surface attachment
665 * and complex surfaces are not clearly described by the MSDN or sdk,
666 * so this method is tricky and likely to contain problems.
667 * This implementation searches the complex list first, then the
670 * The chains are searched from This down to the last surface in the chain,
671 * not from the first element in the chain. The first surface found is
672 * returned. The MSDN says that this method fails if more than one surface
673 * matches the caps, but it is not sure if that is right. The attachment
674 * structure may not even allow two matching surfaces.
676 * The found surface is AddRef-ed before it is returned.
679 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
680 * Surface: Address to store the found surface
684 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
685 * DDERR_NOTFOUND if no surface was found
687 *****************************************************************************/
688 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
689 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
691 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
692 struct ddraw_surface
*surf
;
696 TRACE("iface %p, caps %p, attachment %p.\n", iface
, Caps
, Surface
);
698 wined3d_mutex_lock();
700 if(This
->version
< 7)
702 /* Earlier dx apps put garbage into these members, clear them */
703 our_caps
.dwCaps
= Caps
->dwCaps
;
704 our_caps
.dwCaps2
= 0;
705 our_caps
.dwCaps3
= 0;
706 our_caps
.dwCaps4
= 0;
713 TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This
, our_caps
.dwCaps
, our_caps
.dwCaps2
, our_caps
.dwCaps3
, our_caps
.dwCaps4
); /* FIXME: Better debugging */
715 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
717 surf
= This
->complex_array
[i
];
722 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
723 surf
->surface_desc
.ddsCaps
.dwCaps
,
724 surf
->surface_desc
.ddsCaps
.dwCaps2
,
725 surf
->surface_desc
.ddsCaps
.dwCaps3
,
726 surf
->surface_desc
.ddsCaps
.dwCaps4
);
729 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
730 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
732 /* MSDN: "This method fails if more than one surface is attached
733 * that matches the capabilities requested."
735 * Not sure how to test this.
738 TRACE("(%p): Returning surface %p\n", This
, surf
);
739 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
740 *Surface
= &surf
->IDirectDrawSurface7_iface
;
741 ddraw_surface7_AddRef(*Surface
);
742 wined3d_mutex_unlock();
748 /* Next, look at the attachment chain */
751 while( (surf
= surf
->next_attached
) )
755 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
756 surf
->surface_desc
.ddsCaps
.dwCaps
,
757 surf
->surface_desc
.ddsCaps
.dwCaps2
,
758 surf
->surface_desc
.ddsCaps
.dwCaps3
,
759 surf
->surface_desc
.ddsCaps
.dwCaps4
);
762 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
763 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
765 TRACE("(%p): Returning surface %p\n", This
, surf
);
766 *Surface
= &surf
->IDirectDrawSurface7_iface
;
767 ddraw_surface7_AddRef(*Surface
);
768 wined3d_mutex_unlock();
773 TRACE("(%p) Didn't find a valid surface\n", This
);
775 wined3d_mutex_unlock();
778 return DDERR_NOTFOUND
;
781 static HRESULT WINAPI
ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4
*iface
,
782 DDSCAPS2
*caps
, IDirectDrawSurface4
**attachment
)
784 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
785 struct ddraw_surface
*attachment_impl
;
786 IDirectDrawSurface7
*attachment7
;
789 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
791 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
798 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
799 *attachment
= &attachment_impl
->IDirectDrawSurface4_iface
;
800 ddraw_surface4_AddRef(*attachment
);
801 ddraw_surface7_Release(attachment7
);
806 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
807 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
809 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
810 struct ddraw_surface
*attachment_impl
;
811 IDirectDrawSurface7
*attachment7
;
815 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
817 caps2
.dwCaps
= caps
->dwCaps
;
822 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
823 &caps2
, &attachment7
);
829 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
830 *attachment
= &attachment_impl
->IDirectDrawSurface3_iface
;
831 ddraw_surface3_AddRef(*attachment
);
832 ddraw_surface7_Release(attachment7
);
837 static HRESULT WINAPI
ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2
*iface
,
838 DDSCAPS
*caps
, IDirectDrawSurface2
**attachment
)
840 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
841 struct ddraw_surface
*attachment_impl
;
842 IDirectDrawSurface7
*attachment7
;
846 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
848 caps2
.dwCaps
= caps
->dwCaps
;
853 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
854 &caps2
, &attachment7
);
860 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
861 *attachment
= &attachment_impl
->IDirectDrawSurface2_iface
;
862 ddraw_surface2_AddRef(*attachment
);
863 ddraw_surface7_Release(attachment7
);
868 static HRESULT WINAPI
ddraw_surface1_GetAttachedSurface(IDirectDrawSurface
*iface
,
869 DDSCAPS
*caps
, IDirectDrawSurface
**attachment
)
871 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
872 struct ddraw_surface
*attachment_impl
;
873 IDirectDrawSurface7
*attachment7
;
877 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
879 caps2
.dwCaps
= caps
->dwCaps
;
884 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
,
885 &caps2
, &attachment7
);
891 attachment_impl
= impl_from_IDirectDrawSurface7(attachment7
);
892 *attachment
= &attachment_impl
->IDirectDrawSurface_iface
;
893 ddraw_surface1_AddRef(*attachment
);
894 ddraw_surface7_Release(attachment7
);
899 /*****************************************************************************
900 * IDirectDrawSurface7::Lock
902 * Locks the surface and returns a pointer to the surface's memory
905 * Rect: Rectangle to lock. If NULL, the whole surface is locked
906 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
907 * Flags: Locking flags, e.g Read only or write only
908 * h: An event handle that's not used and must be NULL
912 * DDERR_INVALIDPARAMS if DDSD is NULL
913 * For more details, see IWineD3DSurface::LockRect
915 *****************************************************************************/
916 static HRESULT
surface_lock(struct ddraw_surface
*This
,
917 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
919 struct wined3d_mapped_rect mapped_rect
;
922 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
923 This
, wine_dbgstr_rect(Rect
), DDSD
, Flags
, h
);
925 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
926 wined3d_mutex_lock();
928 /* Should I check for the handle to be NULL?
930 * The DDLOCK flags and the D3DLOCK flags are equal
931 * for the supported values. The others are ignored by WineD3D
934 /* Windows zeroes this if the rect is invalid */
941 || (Rect
->left
> Rect
->right
)
942 || (Rect
->top
> Rect
->bottom
)
943 || (Rect
->right
> This
->surface_desc
.dwWidth
)
944 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
946 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
947 wined3d_mutex_unlock();
948 return DDERR_INVALIDPARAMS
;
952 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
953 hr
= ddraw_surface_update_frontbuffer(This
, Rect
, TRUE
);
955 hr
= wined3d_surface_map(This
->wined3d_surface
, &mapped_rect
, Rect
, Flags
);
958 wined3d_mutex_unlock();
961 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
962 * specific error. But since IWineD3DSurface::LockRect returns that error in this
963 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
964 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
965 * is much easier to do it in one place in ddraw
967 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
972 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
974 if (Flags
& DDLOCK_READONLY
)
975 memset(&This
->ddraw
->primary_lock
, 0, sizeof(This
->ddraw
->primary_lock
));
977 This
->ddraw
->primary_lock
= *Rect
;
979 SetRect(&This
->ddraw
->primary_lock
, 0, 0, This
->surface_desc
.dwWidth
, This
->surface_desc
.dwHeight
);
982 /* Override the memory area. The pitch should be set already. Strangely windows
983 * does not set the LPSURFACE flag on locked surfaces !?!.
984 * DDSD->dwFlags |= DDSD_LPSURFACE;
986 This
->surface_desc
.lpSurface
= mapped_rect
.data
;
987 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
989 TRACE("locked surface returning description :\n");
990 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
992 wined3d_mutex_unlock();
997 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
998 RECT
*rect
, DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1000 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1002 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1003 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1005 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1006 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1007 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1009 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1010 return DDERR_INVALIDPARAMS
;
1012 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1015 static HRESULT WINAPI
ddraw_surface4_Lock(IDirectDrawSurface4
*iface
, RECT
*rect
,
1016 DDSURFACEDESC2
*surface_desc
, DWORD flags
, HANDLE h
)
1018 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1020 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1021 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1023 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1024 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1025 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1027 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1028 return DDERR_INVALIDPARAMS
;
1030 return surface_lock(surface
, rect
, surface_desc
, flags
, h
);
1033 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
1034 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1036 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1037 DDSURFACEDESC2 surface_desc2
;
1040 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1041 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1043 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1044 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1045 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1047 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1048 return DDERR_INVALIDPARAMS
;
1051 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1052 surface_desc2
.dwFlags
= 0;
1053 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1054 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1055 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1059 static HRESULT WINAPI
ddraw_surface2_Lock(IDirectDrawSurface2
*iface
, RECT
*rect
,
1060 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1063 DDSURFACEDESC2 surface_desc2
;
1066 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1067 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1069 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1070 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1071 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1073 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1074 return DDERR_INVALIDPARAMS
;
1077 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1078 surface_desc2
.dwFlags
= 0;
1079 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1080 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1081 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1085 static HRESULT WINAPI
ddraw_surface1_Lock(IDirectDrawSurface
*iface
, RECT
*rect
,
1086 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
1088 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1089 DDSURFACEDESC2 surface_desc2
;
1091 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1092 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
1094 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1095 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
) &&
1096 surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
1098 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc
->dwSize
);
1099 return DDERR_INVALIDPARAMS
;
1102 surface_desc2
.dwSize
= surface_desc
->dwSize
;
1103 surface_desc2
.dwFlags
= 0;
1104 hr
= surface_lock(surface
, rect
, &surface_desc2
, flags
, h
);
1105 DDSD2_to_DDSD(&surface_desc2
, surface_desc
);
1106 surface_desc
->dwSize
= surface_desc2
.dwSize
;
1110 /*****************************************************************************
1111 * IDirectDrawSurface7::Unlock
1113 * Unlocks an locked surface
1116 * Rect: Not used by this implementation
1120 * For more details, see IWineD3DSurface::UnlockRect
1122 *****************************************************************************/
1123 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
1125 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1128 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(pRect
));
1130 wined3d_mutex_lock();
1131 hr
= wined3d_surface_unmap(surface
->wined3d_surface
);
1134 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1135 hr
= ddraw_surface_update_frontbuffer(surface
, &surface
->ddraw
->primary_lock
, FALSE
);
1136 surface
->surface_desc
.lpSurface
= NULL
;
1138 wined3d_mutex_unlock();
1143 static HRESULT WINAPI
ddraw_surface4_Unlock(IDirectDrawSurface4
*iface
, RECT
*pRect
)
1145 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1147 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1149 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, pRect
);
1152 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
1154 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1156 TRACE("iface %p, data %p.\n", iface
, data
);
1158 /* data might not be the LPRECT of later versions, so drop it. */
1159 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1162 static HRESULT WINAPI
ddraw_surface2_Unlock(IDirectDrawSurface2
*iface
, void *data
)
1164 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1166 TRACE("iface %p, data %p.\n", iface
, data
);
1168 /* data might not be the LPRECT of later versions, so drop it. */
1169 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1172 static HRESULT WINAPI
ddraw_surface1_Unlock(IDirectDrawSurface
*iface
, void *data
)
1174 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1176 TRACE("iface %p, data %p.\n", iface
, data
);
1178 /* data might not be the LPRECT of later versions, so drop it. */
1179 return ddraw_surface7_Unlock(&surface
->IDirectDrawSurface7_iface
, NULL
);
1182 /*****************************************************************************
1183 * IDirectDrawSurface7::Flip
1185 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
1186 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
1187 * the flip target is passed to WineD3D, even if the app didn't specify one
1190 * DestOverride: Specifies the surface that will become the new front
1191 * buffer. If NULL, the current back buffer is used
1192 * Flags: some DirectDraw flags, see include/ddraw.h
1196 * DDERR_NOTFLIPPABLE if no flip target could be found
1197 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
1198 * For more details, see IWineD3DSurface::Flip
1200 *****************************************************************************/
1201 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
1203 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1204 struct ddraw_surface
*Override
= unsafe_impl_from_IDirectDrawSurface7(DestOverride
);
1205 IDirectDrawSurface7
*Override7
;
1208 TRACE("iface %p, dst %p, flags %#x.\n", iface
, DestOverride
, Flags
);
1210 /* Flip has to be called from a front buffer
1211 * What about overlay surfaces, AFAIK they can flip too? */
1212 if (!(surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)))
1213 return DDERR_INVALIDOBJECT
; /* Unchecked */
1215 wined3d_mutex_lock();
1217 /* WineD3D doesn't keep track of attached surface, so find the target */
1222 memset(&Caps
, 0, sizeof(Caps
));
1223 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
1224 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
1227 ERR("Can't find a flip target\n");
1228 wined3d_mutex_unlock();
1229 return DDERR_NOTFLIPPABLE
; /* Unchecked */
1231 Override
= impl_from_IDirectDrawSurface7(Override7
);
1233 /* For the GetAttachedSurface */
1234 ddraw_surface7_Release(Override7
);
1237 hr
= wined3d_surface_flip(surface
->wined3d_surface
, Override
->wined3d_surface
, Flags
);
1238 if (SUCCEEDED(hr
) && surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1239 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
1241 wined3d_mutex_unlock();
1246 static HRESULT WINAPI
ddraw_surface4_Flip(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*dst
, DWORD flags
)
1248 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1249 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst
);
1251 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1253 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1254 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1257 static HRESULT WINAPI
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
1259 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1260 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst
);
1262 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1264 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1265 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1268 static HRESULT WINAPI
ddraw_surface2_Flip(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*dst
, DWORD flags
)
1270 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1271 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst
);
1273 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1275 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1276 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1279 static HRESULT WINAPI
ddraw_surface1_Flip(IDirectDrawSurface
*iface
, IDirectDrawSurface
*dst
, DWORD flags
)
1281 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1282 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst
);
1284 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
1286 return ddraw_surface7_Flip(&surface
->IDirectDrawSurface7_iface
,
1287 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, flags
);
1290 static HRESULT
ddraw_surface_blt_clipped(struct ddraw_surface
*dst_surface
, const RECT
*dst_rect_in
,
1291 struct ddraw_surface
*src_surface
, const RECT
*src_rect_in
, DWORD flags
,
1292 const WINEDDBLTFX
*fx
, enum wined3d_texture_filter_type filter
)
1294 struct wined3d_surface
*wined3d_src_surface
= src_surface
? src_surface
->wined3d_surface
: NULL
;
1295 RECT src_rect
, dst_rect
;
1296 float scale_x
, scale_y
;
1297 const RECT
*clip_rect
;
1298 UINT clip_list_size
;
1303 if (!dst_surface
->clipper
)
1305 if (src_surface
&& src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1306 hr
= ddraw_surface_update_frontbuffer(src_surface
, src_rect_in
, TRUE
);
1308 hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, dst_rect_in
,
1309 wined3d_src_surface
, src_rect_in
, flags
, fx
, filter
);
1310 if (SUCCEEDED(hr
) && (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
1311 hr
= ddraw_surface_update_frontbuffer(dst_surface
, dst_rect_in
, FALSE
);
1320 dst_rect
.right
= dst_surface
->surface_desc
.dwWidth
;
1321 dst_rect
.bottom
= dst_surface
->surface_desc
.dwHeight
;
1325 dst_rect
= *dst_rect_in
;
1328 if (IsRectEmpty(&dst_rect
))
1329 return DDERR_INVALIDRECT
;
1337 src_rect
.right
= src_surface
->surface_desc
.dwWidth
;
1338 src_rect
.bottom
= src_surface
->surface_desc
.dwHeight
;
1342 src_rect
= *src_rect_in
;
1345 if (IsRectEmpty(&src_rect
))
1346 return DDERR_INVALIDRECT
;
1350 SetRect(&src_rect
, 0, 0, 0, 0);
1353 scale_x
= (float)(src_rect
.right
- src_rect
.left
) / (float)(dst_rect
.right
- dst_rect
.left
);
1354 scale_y
= (float)(src_rect
.bottom
- src_rect
.top
) / (float)(dst_rect
.bottom
- dst_rect
.top
);
1356 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1357 &dst_rect
, NULL
, &clip_list_size
)))
1359 WARN("Failed to get clip list size, hr %#x.\n", hr
);
1363 if (!(clip_list
= HeapAlloc(GetProcessHeap(), 0, clip_list_size
)))
1365 WARN("Failed to allocate clip list.\n");
1366 return E_OUTOFMEMORY
;
1369 if (FAILED(hr
= IDirectDrawClipper_GetClipList(&dst_surface
->clipper
->IDirectDrawClipper_iface
,
1370 &dst_rect
, clip_list
, &clip_list_size
)))
1372 WARN("Failed to get clip list, hr %#x.\n", hr
);
1373 HeapFree(GetProcessHeap(), 0, clip_list
);
1377 clip_rect
= (RECT
*)clip_list
->Buffer
;
1378 for (i
= 0; i
< clip_list
->rdh
.nCount
; ++i
)
1380 RECT src_rect_clipped
= src_rect
;
1384 src_rect_clipped
.left
+= (LONG
)((clip_rect
[i
].left
- dst_rect
.left
) * scale_x
);
1385 src_rect_clipped
.top
+= (LONG
)((clip_rect
[i
].top
- dst_rect
.top
) * scale_y
);
1386 src_rect_clipped
.right
-= (LONG
)((dst_rect
.right
- clip_rect
[i
].right
) * scale_x
);
1387 src_rect_clipped
.bottom
-= (LONG
)((dst_rect
.bottom
- clip_rect
[i
].bottom
) * scale_y
);
1389 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1391 if (FAILED(hr
= ddraw_surface_update_frontbuffer(src_surface
, &src_rect_clipped
, TRUE
)))
1396 if (FAILED(hr
= wined3d_surface_blt(dst_surface
->wined3d_surface
, &clip_rect
[i
],
1397 wined3d_src_surface
, &src_rect_clipped
, flags
, fx
, filter
)))
1400 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1402 if (FAILED(hr
= ddraw_surface_update_frontbuffer(dst_surface
, &clip_rect
[i
], FALSE
)))
1407 HeapFree(GetProcessHeap(), 0, clip_list
);
1411 /*****************************************************************************
1412 * IDirectDrawSurface7::Blt
1414 * Performs a blit on the surface
1417 * DestRect: Destination rectangle, can be NULL
1418 * SrcSurface: Source surface, can be NULL
1419 * SrcRect: Source rectangle, can be NULL
1421 * DDBltFx: Some extended blt parameters, connected to the flags
1425 * See IWineD3DSurface::Blt for more details
1427 *****************************************************************************/
1428 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
1429 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
1431 struct ddraw_surface
*dst_surface
= impl_from_IDirectDrawSurface7(iface
);
1432 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(SrcSurface
);
1435 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1436 iface
, wine_dbgstr_rect(DestRect
), SrcSurface
, wine_dbgstr_rect(SrcRect
), Flags
, DDBltFx
);
1438 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1439 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1441 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
1442 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1443 return DDERR_INVALIDPARAMS
;
1446 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
1447 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1448 return DDERR_INVALIDPARAMS
;
1451 wined3d_mutex_lock();
1453 if (Flags
& DDBLT_KEYSRC
&& (!src_surface
|| !(src_surface
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
)))
1455 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1456 wined3d_mutex_unlock();
1457 return DDERR_INVALIDPARAMS
;
1460 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1461 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1462 * surfaces. So far no blitting operations using surfaces in the bltfx
1463 * struct are supported anyway. */
1464 hr
= ddraw_surface_blt_clipped(dst_surface
, DestRect
, src_surface
, SrcRect
,
1465 Flags
, (WINEDDBLTFX
*)DDBltFx
, WINED3D_TEXF_LINEAR
);
1467 wined3d_mutex_unlock();
1470 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1471 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
1476 static HRESULT WINAPI
ddraw_surface4_Blt(IDirectDrawSurface4
*iface
, RECT
*dst_rect
,
1477 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1479 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface4(iface
);
1480 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
1482 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1483 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1485 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1486 src
? &src
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1489 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
1490 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1492 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface3(iface
);
1493 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
1495 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1496 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1498 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1499 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1502 static HRESULT WINAPI
ddraw_surface2_Blt(IDirectDrawSurface2
*iface
, RECT
*dst_rect
,
1503 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1505 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface2(iface
);
1506 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
1508 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1509 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1511 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1512 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1515 static HRESULT WINAPI
ddraw_surface1_Blt(IDirectDrawSurface
*iface
, RECT
*dst_rect
,
1516 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
1518 struct ddraw_surface
*dst
= impl_from_IDirectDrawSurface(iface
);
1519 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
1521 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1522 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
1524 return ddraw_surface7_Blt(&dst
->IDirectDrawSurface7_iface
, dst_rect
,
1525 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
, fx
);
1528 /*****************************************************************************
1529 * IDirectDrawSurface7::AddAttachedSurface
1531 * Attaches a surface to another surface. How the surface attachments work
1532 * is not totally understood yet, and this method is prone to problems.
1533 * The surface that is attached is AddRef-ed.
1535 * Tests with complex surfaces suggest that the surface attachments form a
1536 * tree, but no method to test this has been found yet.
1538 * The attachment list consists of a first surface (first_attached) and
1539 * for each surface a pointer to the next attached surface (next_attached).
1540 * For the first surface, and a surface that has no attachments
1541 * first_attached points to the surface itself. A surface that has
1542 * no successors in the chain has next_attached set to NULL.
1544 * Newly attached surfaces are attached right after the root surface.
1545 * If a surface is attached to a complex surface compound, it's attached to
1546 * the surface that the app requested, not the complex root. See
1547 * GetAttachedSurface for a description how surfaces are found.
1549 * This is how the current implementation works, and it was coded by looking
1550 * at the needs of the applications.
1552 * So far only Z-Buffer attachments are tested, and they are activated in
1553 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1554 * Back buffers should work in 2D mode, but they are not tested(They can be
1555 * attached in older iface versions). Rendering to the front buffer and
1556 * switching between that and double buffering is not yet implemented in
1557 * WineD3D, so for 3D it might have unexpected results.
1559 * ddraw_surface_attach_surface is the real thing,
1560 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1561 * performs additional checks. Version 7 of this interface is much more restrictive
1562 * than its predecessors.
1565 * Attach: Surface to attach to iface
1569 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1571 *****************************************************************************/
1572 static HRESULT
ddraw_surface_attach_surface(struct ddraw_surface
*This
, struct ddraw_surface
*Surf
)
1574 TRACE("surface %p, attachment %p.\n", This
, Surf
);
1577 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
1579 wined3d_mutex_lock();
1581 /* Check if the surface is already attached somewhere */
1582 if (Surf
->next_attached
|| Surf
->first_attached
!= Surf
)
1584 /* TODO: Test for the structure of the manual attachment. Is it a
1585 * chain or a list? What happens if one surface is attached to 2
1586 * different surfaces? */
1587 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1588 Surf
, Surf
->next_attached
, Surf
->first_attached
);
1590 wined3d_mutex_unlock();
1591 return DDERR_SURFACEALREADYATTACHED
;
1594 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1595 Surf
->next_attached
= This
->next_attached
;
1596 Surf
->first_attached
= This
->first_attached
;
1597 This
->next_attached
= Surf
;
1599 /* Check if the WineD3D depth stencil needs updating */
1600 if(This
->ddraw
->d3ddevice
)
1602 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1605 wined3d_mutex_unlock();
1610 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*attachment
)
1612 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
1613 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1616 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1618 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1619 if(!(attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1622 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1623 attachment_impl
->surface_desc
.ddsCaps
.dwCaps
);
1624 return DDERR_CANNOTATTACHSURFACE
;
1627 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1632 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1633 IUnknown_AddRef(attachment_impl
->attached_iface
);
1637 static HRESULT WINAPI
ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4
*iface
, IDirectDrawSurface4
*attachment
)
1639 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface4(iface
);
1640 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1643 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1645 hr
= ddraw_surface7_AddAttachedSurface(&This
->IDirectDrawSurface7_iface
,
1646 attachment_impl
? &attachment_impl
->IDirectDrawSurface7_iface
: NULL
);
1651 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1652 IUnknown_AddRef(attachment_impl
->attached_iface
);
1653 ddraw_surface7_Release(&attachment_impl
->IDirectDrawSurface7_iface
);
1656 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1658 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface3(iface
);
1659 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1662 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1664 /* Tests suggest that
1665 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1666 * -> offscreen plain surfaces can be attached to primaries
1667 * -> primaries can be attached to offscreen plain surfaces
1668 * -> z buffers can be attached to primaries */
1669 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1670 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1672 /* Sizes have to match */
1673 if (attachment_impl
->surface_desc
.dwWidth
!= This
->surface_desc
.dwWidth
1674 || attachment_impl
->surface_desc
.dwHeight
!= This
->surface_desc
.dwHeight
)
1676 WARN("Surface sizes do not match.\n");
1677 return DDERR_CANNOTATTACHSURFACE
;
1681 else if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1682 && attachment_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1688 WARN("Invalid attachment combination.\n");
1689 return DDERR_CANNOTATTACHSURFACE
;
1692 hr
= ddraw_surface_attach_surface(This
, attachment_impl
);
1697 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1698 IUnknown_AddRef(attachment_impl
->attached_iface
);
1702 static HRESULT WINAPI
ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2
*iface
, IDirectDrawSurface2
*attachment
)
1704 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface2(iface
);
1705 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1708 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1710 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1711 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1716 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1717 IUnknown_AddRef(attachment_impl
->attached_iface
);
1718 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1722 static HRESULT WINAPI
ddraw_surface1_AddAttachedSurface(IDirectDrawSurface
*iface
, IDirectDrawSurface
*attachment
)
1724 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface(iface
);
1725 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1728 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1730 hr
= ddraw_surface3_AddAttachedSurface(&This
->IDirectDrawSurface3_iface
,
1731 attachment_impl
? &attachment_impl
->IDirectDrawSurface3_iface
: NULL
);
1736 attachment_impl
->attached_iface
= (IUnknown
*)attachment
;
1737 IUnknown_AddRef(attachment_impl
->attached_iface
);
1738 ddraw_surface3_Release(&attachment_impl
->IDirectDrawSurface3_iface
);
1742 /*****************************************************************************
1743 * IDirectDrawSurface7::DeleteAttachedSurface
1745 * Removes a surface from the attachment chain. The surface's refcount
1746 * is decreased by one after it has been removed
1749 * Flags: Some flags, not used by this implementation
1750 * Attach: Surface to detach
1754 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1756 *****************************************************************************/
1757 static HRESULT
ddraw_surface_delete_attached_surface(struct ddraw_surface
*surface
,
1758 struct ddraw_surface
*attachment
, IUnknown
*detach_iface
)
1760 struct ddraw_surface
*prev
= surface
;
1762 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface
, attachment
, detach_iface
);
1764 wined3d_mutex_lock();
1765 if (!attachment
|| (attachment
->first_attached
!= surface
) || (attachment
== surface
) )
1767 wined3d_mutex_unlock();
1768 return DDERR_CANNOTDETACHSURFACE
;
1771 if (attachment
->attached_iface
!= detach_iface
)
1773 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment
->attached_iface
, detach_iface
);
1774 wined3d_mutex_unlock();
1775 return DDERR_SURFACENOTATTACHED
;
1778 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1779 if (surface
->surface_desc
.ddsCaps
.dwCaps
& attachment
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1781 attachment
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1782 /* FIXME: we should probably also subtract from dwMipMapCount of this
1783 * and all parent surfaces */
1786 /* Find the predecessor of the detached surface */
1789 if (prev
->next_attached
== attachment
)
1791 prev
= prev
->next_attached
;
1794 /* There must be a surface, otherwise there's a bug */
1797 /* Unchain the surface */
1798 prev
->next_attached
= attachment
->next_attached
;
1799 attachment
->next_attached
= NULL
;
1800 attachment
->first_attached
= attachment
;
1802 /* Check if the wined3d depth stencil needs updating. */
1803 if (surface
->ddraw
->d3ddevice
)
1804 IDirect3DDeviceImpl_UpdateDepthStencil(surface
->ddraw
->d3ddevice
);
1805 wined3d_mutex_unlock();
1807 /* Set attached_iface to NULL before releasing it, the surface may go
1809 attachment
->attached_iface
= NULL
;
1810 IUnknown_Release(detach_iface
);
1815 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1816 DWORD flags
, IDirectDrawSurface7
*attachment
)
1818 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1819 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface7(attachment
);
1821 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1823 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1826 static HRESULT WINAPI
ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4
*iface
,
1827 DWORD flags
, IDirectDrawSurface4
*attachment
)
1829 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1830 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface4(attachment
);
1832 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1834 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1837 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1838 DWORD flags
, IDirectDrawSurface3
*attachment
)
1840 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1841 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface3(attachment
);
1843 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1845 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1848 static HRESULT WINAPI
ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2
*iface
,
1849 DWORD flags
, IDirectDrawSurface2
*attachment
)
1851 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1852 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface2(attachment
);
1854 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1856 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1859 static HRESULT WINAPI
ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface
*iface
,
1860 DWORD flags
, IDirectDrawSurface
*attachment
)
1862 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1863 struct ddraw_surface
*attachment_impl
= unsafe_impl_from_IDirectDrawSurface(attachment
);
1865 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1867 return ddraw_surface_delete_attached_surface(surface
, attachment_impl
, (IUnknown
*)attachment
);
1870 /*****************************************************************************
1871 * IDirectDrawSurface7::AddOverlayDirtyRect
1873 * "This method is not currently implemented"
1881 *****************************************************************************/
1882 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1884 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(Rect
));
1886 return DDERR_UNSUPPORTED
; /* unchecked */
1889 static HRESULT WINAPI
ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4
*iface
, RECT
*rect
)
1891 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1893 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1895 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1898 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1900 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1902 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1904 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1907 static HRESULT WINAPI
ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2
*iface
, RECT
*rect
)
1909 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1911 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1913 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1916 static HRESULT WINAPI
ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface
*iface
, RECT
*rect
)
1918 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1920 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1922 return ddraw_surface7_AddOverlayDirtyRect(&surface
->IDirectDrawSurface7_iface
, rect
);
1925 /*****************************************************************************
1926 * IDirectDrawSurface7::GetDC
1928 * Returns a GDI device context for the surface
1931 * hdc: Address of a HDC variable to store the dc to
1935 * DDERR_INVALIDPARAMS if hdc is NULL
1936 * For details, see IWineD3DSurface::GetDC
1938 *****************************************************************************/
1939 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1941 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
1944 TRACE("iface %p, dc %p.\n", iface
, hdc
);
1947 return DDERR_INVALIDPARAMS
;
1949 wined3d_mutex_lock();
1950 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
1951 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, TRUE
);
1953 hr
= wined3d_surface_getdc(surface
->wined3d_surface
, hdc
);
1954 wined3d_mutex_unlock();
1957 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1960 case WINED3DERR_INVALIDCALL
:
1961 if(hdc
) *hdc
= NULL
;
1962 return DDERR_INVALIDPARAMS
;
1968 static HRESULT WINAPI
ddraw_surface4_GetDC(IDirectDrawSurface4
*iface
, HDC
*dc
)
1970 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
1972 TRACE("iface %p, dc %p.\n", iface
, dc
);
1974 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1977 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1979 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
1981 TRACE("iface %p, dc %p.\n", iface
, dc
);
1983 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1986 static HRESULT WINAPI
ddraw_surface2_GetDC(IDirectDrawSurface2
*iface
, HDC
*dc
)
1988 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
1990 TRACE("iface %p, dc %p.\n", iface
, dc
);
1992 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
1995 static HRESULT WINAPI
ddraw_surface1_GetDC(IDirectDrawSurface
*iface
, HDC
*dc
)
1997 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
1999 TRACE("iface %p, dc %p.\n", iface
, dc
);
2001 return ddraw_surface7_GetDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2004 /*****************************************************************************
2005 * IDirectDrawSurface7::ReleaseDC
2007 * Releases the DC that was constructed with GetDC
2010 * hdc: HDC to release
2014 * For more details, see IWineD3DSurface::ReleaseDC
2016 *****************************************************************************/
2017 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
2019 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2022 TRACE("iface %p, dc %p.\n", iface
, hdc
);
2024 wined3d_mutex_lock();
2025 hr
= wined3d_surface_releasedc(surface
->wined3d_surface
, hdc
);
2026 if (SUCCEEDED(hr
) && (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
2027 hr
= ddraw_surface_update_frontbuffer(surface
, NULL
, FALSE
);
2028 wined3d_mutex_unlock();
2033 static HRESULT WINAPI
ddraw_surface4_ReleaseDC(IDirectDrawSurface4
*iface
, HDC dc
)
2035 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2037 TRACE("iface %p, dc %p.\n", iface
, dc
);
2039 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2042 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
2044 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2046 TRACE("iface %p, dc %p.\n", iface
, dc
);
2048 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2051 static HRESULT WINAPI
ddraw_surface2_ReleaseDC(IDirectDrawSurface2
*iface
, HDC dc
)
2053 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2055 TRACE("iface %p, dc %p.\n", iface
, dc
);
2057 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2060 static HRESULT WINAPI
ddraw_surface1_ReleaseDC(IDirectDrawSurface
*iface
, HDC dc
)
2062 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2064 TRACE("iface %p, dc %p.\n", iface
, dc
);
2066 return ddraw_surface7_ReleaseDC(&surface
->IDirectDrawSurface7_iface
, dc
);
2069 /*****************************************************************************
2070 * IDirectDrawSurface7::GetCaps
2072 * Returns the surface's caps
2075 * Caps: Address to write the caps to
2079 * DDERR_INVALIDPARAMS if Caps is NULL
2081 *****************************************************************************/
2082 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
2084 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2086 TRACE("iface %p, caps %p.\n", iface
, Caps
);
2089 return DDERR_INVALIDPARAMS
;
2091 *Caps
= surface
->surface_desc
.ddsCaps
;
2096 static HRESULT WINAPI
ddraw_surface4_GetCaps(IDirectDrawSurface4
*iface
, DDSCAPS2
*caps
)
2098 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2100 TRACE("iface %p, caps %p.\n", iface
, caps
);
2102 return ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, caps
);
2105 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
2107 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2111 TRACE("iface %p, caps %p.\n", iface
, caps
);
2113 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2114 if (FAILED(hr
)) return hr
;
2116 caps
->dwCaps
= caps2
.dwCaps
;
2120 static HRESULT WINAPI
ddraw_surface2_GetCaps(IDirectDrawSurface2
*iface
, DDSCAPS
*caps
)
2122 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2126 TRACE("iface %p, caps %p.\n", iface
, caps
);
2128 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2129 if (FAILED(hr
)) return hr
;
2131 caps
->dwCaps
= caps2
.dwCaps
;
2135 static HRESULT WINAPI
ddraw_surface1_GetCaps(IDirectDrawSurface
*iface
, DDSCAPS
*caps
)
2137 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2141 TRACE("iface %p, caps %p.\n", iface
, caps
);
2143 hr
= ddraw_surface7_GetCaps(&surface
->IDirectDrawSurface7_iface
, &caps2
);
2144 if (FAILED(hr
)) return hr
;
2146 caps
->dwCaps
= caps2
.dwCaps
;
2150 /*****************************************************************************
2151 * IDirectDrawSurface7::SetPriority
2153 * Sets a texture priority for managed textures.
2156 * Priority: The new priority
2160 * For more details, see IWineD3DSurface::SetPriority
2162 *****************************************************************************/
2163 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
2165 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2168 TRACE("iface %p, priority %u.\n", iface
, Priority
);
2170 wined3d_mutex_lock();
2171 hr
= wined3d_surface_set_priority(surface
->wined3d_surface
, Priority
);
2172 wined3d_mutex_unlock();
2177 /*****************************************************************************
2178 * IDirectDrawSurface7::GetPriority
2180 * Returns the surface's priority
2183 * Priority: Address of a variable to write the priority to
2187 * DDERR_INVALIDPARAMS if Priority == NULL
2188 * For more details, see IWineD3DSurface::GetPriority
2190 *****************************************************************************/
2191 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
2193 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2195 TRACE("iface %p, priority %p.\n", iface
, Priority
);
2199 return DDERR_INVALIDPARAMS
;
2202 wined3d_mutex_lock();
2203 *Priority
= wined3d_surface_get_priority(surface
->wined3d_surface
);
2204 wined3d_mutex_unlock();
2209 /*****************************************************************************
2210 * IDirectDrawSurface7::SetPrivateData
2212 * Stores some data in the surface that is intended for the application's
2216 * tag: GUID that identifies the data
2217 * Data: Pointer to the private data
2218 * Size: Size of the private data
2223 * For more details, see IWineD3DSurface::SetPrivateData
2225 *****************************************************************************/
2226 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
2227 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
2229 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2230 struct wined3d_resource
*resource
;
2233 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2234 iface
, debugstr_guid(tag
), Data
, Size
, Flags
);
2236 wined3d_mutex_lock();
2237 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2238 hr
= wined3d_resource_set_private_data(resource
, tag
, Data
, Size
, Flags
);
2239 wined3d_mutex_unlock();
2243 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2248 static HRESULT WINAPI
ddraw_surface4_SetPrivateData(IDirectDrawSurface4
*iface
,
2249 REFGUID tag
, void *data
, DWORD size
, DWORD flags
)
2251 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2253 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2254 iface
, debugstr_guid(tag
), data
, size
, flags
);
2256 return ddraw_surface7_SetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
, flags
);
2259 /*****************************************************************************
2260 * IDirectDrawSurface7::GetPrivateData
2262 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2265 * tag: GUID of the data to return
2266 * Data: Address where to write the data to
2267 * Size: Size of the buffer at Data
2271 * DDERR_INVALIDPARAMS if Data is NULL
2272 * For more details, see IWineD3DSurface::GetPrivateData
2274 *****************************************************************************/
2275 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
2277 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2278 struct wined3d_resource
*resource
;
2281 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2282 iface
, debugstr_guid(tag
), Data
, Size
);
2285 return DDERR_INVALIDPARAMS
;
2287 wined3d_mutex_lock();
2288 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2289 hr
= wined3d_resource_get_private_data(resource
, tag
, Data
, Size
);
2290 wined3d_mutex_unlock();
2295 static HRESULT WINAPI
ddraw_surface4_GetPrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
, void *data
, DWORD
*size
)
2297 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2299 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2300 iface
, debugstr_guid(tag
), data
, size
);
2302 return ddraw_surface7_GetPrivateData(&surface
->IDirectDrawSurface7_iface
, tag
, data
, size
);
2305 /*****************************************************************************
2306 * IDirectDrawSurface7::FreePrivateData
2308 * Frees private data stored in the surface
2311 * tag: Tag of the data to free
2315 * For more details, see IWineD3DSurface::FreePrivateData
2317 *****************************************************************************/
2318 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
2320 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2321 struct wined3d_resource
*resource
;
2324 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2326 wined3d_mutex_lock();
2327 resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
2328 hr
= wined3d_resource_free_private_data(resource
, tag
);
2329 wined3d_mutex_unlock();
2334 static HRESULT WINAPI
ddraw_surface4_FreePrivateData(IDirectDrawSurface4
*iface
, REFGUID tag
)
2336 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2338 TRACE("iface %p, tag %s.\n", iface
, debugstr_guid(tag
));
2340 return ddraw_surface7_FreePrivateData(&surface
->IDirectDrawSurface7_iface
, tag
);
2343 /*****************************************************************************
2344 * IDirectDrawSurface7::PageLock
2346 * Prevents a sysmem surface from being paged out
2349 * Flags: Not used, must be 0(unchecked)
2352 * DD_OK, because it's a stub
2354 *****************************************************************************/
2355 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2357 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2359 /* This is Windows memory management related - we don't need this */
2363 static HRESULT WINAPI
ddraw_surface4_PageLock(IDirectDrawSurface4
*iface
, DWORD flags
)
2365 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2367 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2369 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2372 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
2374 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2376 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2378 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2381 static HRESULT WINAPI
ddraw_surface2_PageLock(IDirectDrawSurface2
*iface
, DWORD flags
)
2383 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2385 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2387 return ddraw_surface7_PageLock(&surface
->IDirectDrawSurface7_iface
, flags
);
2390 /*****************************************************************************
2391 * IDirectDrawSurface7::PageUnlock
2393 * Allows a sysmem surface to be paged out
2396 * Flags: Not used, must be 0(unchecked)
2399 * DD_OK, because it's a stub
2401 *****************************************************************************/
2402 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
2404 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2409 static HRESULT WINAPI
ddraw_surface4_PageUnlock(IDirectDrawSurface4
*iface
, DWORD flags
)
2411 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2413 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2415 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2418 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
2420 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2422 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2424 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2427 static HRESULT WINAPI
ddraw_surface2_PageUnlock(IDirectDrawSurface2
*iface
, DWORD flags
)
2429 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2431 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2433 return ddraw_surface7_PageUnlock(&surface
->IDirectDrawSurface7_iface
, flags
);
2436 /*****************************************************************************
2437 * IDirectDrawSurface7::BltBatch
2439 * An unimplemented function
2447 *****************************************************************************/
2448 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
2450 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, Batch
, Count
, Flags
);
2452 /* MSDN: "not currently implemented" */
2453 return DDERR_UNSUPPORTED
;
2456 static HRESULT WINAPI
ddraw_surface4_BltBatch(IDirectDrawSurface4
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2458 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2460 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2462 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2465 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2467 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2469 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2471 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2474 static HRESULT WINAPI
ddraw_surface2_BltBatch(IDirectDrawSurface2
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2476 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2478 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2480 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2483 static HRESULT WINAPI
ddraw_surface1_BltBatch(IDirectDrawSurface
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
2485 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2487 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
2489 return ddraw_surface7_BltBatch(&surface
->IDirectDrawSurface7_iface
, batch
, count
, flags
);
2492 /*****************************************************************************
2493 * IDirectDrawSurface7::EnumAttachedSurfaces
2495 * Enumerates all surfaces attached to this surface
2498 * context: Pointer to pass unmodified to the callback
2499 * cb: Callback function to call for each surface
2503 * DDERR_INVALIDPARAMS if cb is NULL
2505 *****************************************************************************/
2506 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
2507 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2509 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2510 struct ddraw_surface
*surf
;
2511 DDSURFACEDESC2 desc
;
2514 /* Attached surfaces aren't handled in WineD3D */
2515 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, cb
);
2518 return DDERR_INVALIDPARAMS
;
2520 wined3d_mutex_lock();
2522 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
2524 surf
= surface
->complex_array
[i
];
2527 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2528 desc
= surf
->surface_desc
;
2529 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2530 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2532 wined3d_mutex_unlock();
2537 for (surf
= surface
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
2539 ddraw_surface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
2540 desc
= surf
->surface_desc
;
2541 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2542 if (cb(&surf
->IDirectDrawSurface7_iface
, &desc
, context
) == DDENUMRET_CANCEL
)
2544 wined3d_mutex_unlock();
2549 TRACE(" end of enumeration.\n");
2551 wined3d_mutex_unlock();
2556 struct callback_info2
2558 LPDDENUMSURFACESCALLBACK2 callback
;
2562 struct callback_info
2564 LPDDENUMSURFACESCALLBACK callback
;
2568 static HRESULT CALLBACK
EnumCallback2(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2570 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2571 const struct callback_info2
*info
= context
;
2573 ddraw_surface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
2574 ddraw_surface7_Release(surface
);
2576 return info
->callback(&surface_impl
->IDirectDrawSurface4_iface
, surface_desc
, info
->context
);
2579 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
2581 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
2582 const struct callback_info
*info
= context
;
2584 ddraw_surface1_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2585 ddraw_surface7_Release(surface
);
2587 /* FIXME: Check surface_test.dwSize */
2588 return info
->callback(&surface_impl
->IDirectDrawSurface_iface
,
2589 (DDSURFACEDESC
*)surface_desc
, info
->context
);
2592 static HRESULT WINAPI
ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4
*iface
,
2593 void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2595 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2596 struct callback_info2 info
;
2598 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2600 info
.callback
= callback
;
2601 info
.context
= context
;
2603 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2604 &info
, EnumCallback2
);
2607 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
2608 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2610 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2611 struct callback_info info
;
2613 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2615 info
.callback
= callback
;
2616 info
.context
= context
;
2618 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2619 &info
, EnumCallback
);
2622 static HRESULT WINAPI
ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2
*iface
,
2623 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2625 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2626 struct callback_info info
;
2628 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2630 info
.callback
= callback
;
2631 info
.context
= context
;
2633 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2634 &info
, EnumCallback
);
2637 static HRESULT WINAPI
ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface
*iface
,
2638 void *context
, LPDDENUMSURFACESCALLBACK callback
)
2640 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2641 struct callback_info info
;
2643 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
2645 info
.callback
= callback
;
2646 info
.context
= context
;
2648 return ddraw_surface7_EnumAttachedSurfaces(&surface
->IDirectDrawSurface7_iface
,
2649 &info
, EnumCallback
);
2652 /*****************************************************************************
2653 * IDirectDrawSurface7::EnumOverlayZOrders
2655 * "Enumerates the overlay surfaces on the specified destination"
2658 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2659 * context: context to pass back to the callback
2660 * cb: callback function to call for each enumerated surface
2663 * DD_OK, because it's a stub
2665 *****************************************************************************/
2666 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
2667 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
2669 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface
, Flags
, context
, cb
);
2674 static HRESULT WINAPI
ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4
*iface
,
2675 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
2677 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2678 struct callback_info2 info
;
2680 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2682 info
.callback
= callback
;
2683 info
.context
= context
;
2685 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2686 flags
, &info
, EnumCallback2
);
2689 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
2690 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2692 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2693 struct callback_info info
;
2695 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2697 info
.callback
= callback
;
2698 info
.context
= context
;
2700 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2701 flags
, &info
, EnumCallback
);
2704 static HRESULT WINAPI
ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2
*iface
,
2705 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2707 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2708 struct callback_info info
;
2710 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2712 info
.callback
= callback
;
2713 info
.context
= context
;
2715 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2716 flags
, &info
, EnumCallback
);
2719 static HRESULT WINAPI
ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface
*iface
,
2720 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
2722 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2723 struct callback_info info
;
2725 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
2727 info
.callback
= callback
;
2728 info
.context
= context
;
2730 return ddraw_surface7_EnumOverlayZOrders(&surface
->IDirectDrawSurface7_iface
,
2731 flags
, &info
, EnumCallback
);
2734 /*****************************************************************************
2735 * IDirectDrawSurface7::GetBltStatus
2737 * Returns the blitting status
2740 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2743 * See IWineD3DSurface::Blt
2745 *****************************************************************************/
2746 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2748 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2751 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2753 wined3d_mutex_lock();
2754 hr
= wined3d_surface_get_blt_status(surface
->wined3d_surface
, Flags
);
2755 wined3d_mutex_unlock();
2758 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2763 static HRESULT WINAPI
ddraw_surface4_GetBltStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2765 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2767 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2769 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2772 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2774 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2776 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2778 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2781 static HRESULT WINAPI
ddraw_surface2_GetBltStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2783 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2785 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2787 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2790 static HRESULT WINAPI
ddraw_surface1_GetBltStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2792 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2794 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2796 return ddraw_surface7_GetBltStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2799 /*****************************************************************************
2800 * IDirectDrawSurface7::GetColorKey
2802 * Returns the color key assigned to the surface
2806 * CKey: Address to store the key to
2810 * DDERR_INVALIDPARAMS if CKey is NULL
2812 *****************************************************************************/
2813 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2815 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
2817 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
2820 return DDERR_INVALIDPARAMS
;
2822 wined3d_mutex_lock();
2826 case DDCKEY_DESTBLT
:
2827 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
2829 wined3d_mutex_unlock();
2830 return DDERR_NOCOLORKEY
;
2832 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
2835 case DDCKEY_DESTOVERLAY
:
2836 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
2838 wined3d_mutex_unlock();
2839 return DDERR_NOCOLORKEY
;
2841 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
2845 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
2847 wined3d_mutex_unlock();
2848 return DDERR_NOCOLORKEY
;
2850 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
2853 case DDCKEY_SRCOVERLAY
:
2854 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
2856 wined3d_mutex_unlock();
2857 return DDERR_NOCOLORKEY
;
2859 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
2863 wined3d_mutex_unlock();
2864 return DDERR_INVALIDPARAMS
;
2867 wined3d_mutex_unlock();
2872 static HRESULT WINAPI
ddraw_surface4_GetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2874 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2876 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2878 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2881 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2883 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2885 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2887 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2890 static HRESULT WINAPI
ddraw_surface2_GetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2892 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2894 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2896 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2899 static HRESULT WINAPI
ddraw_surface1_GetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2901 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2903 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2905 return ddraw_surface7_GetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
2908 /*****************************************************************************
2909 * IDirectDrawSurface7::GetFlipStatus
2911 * Returns the flipping status of the surface
2914 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2917 * See IWineD3DSurface::GetFlipStatus
2919 *****************************************************************************/
2920 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
2922 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2925 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
2927 wined3d_mutex_lock();
2928 hr
= wined3d_surface_get_flip_status(surface
->wined3d_surface
, Flags
);
2929 wined3d_mutex_unlock();
2933 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2938 static HRESULT WINAPI
ddraw_surface4_GetFlipStatus(IDirectDrawSurface4
*iface
, DWORD flags
)
2940 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
2942 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2944 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2947 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
2949 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
2951 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2953 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2956 static HRESULT WINAPI
ddraw_surface2_GetFlipStatus(IDirectDrawSurface2
*iface
, DWORD flags
)
2958 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
2960 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2962 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2965 static HRESULT WINAPI
ddraw_surface1_GetFlipStatus(IDirectDrawSurface
*iface
, DWORD flags
)
2967 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
2969 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2971 return ddraw_surface7_GetFlipStatus(&surface
->IDirectDrawSurface7_iface
, flags
);
2974 /*****************************************************************************
2975 * IDirectDrawSurface7::GetOverlayPosition
2977 * Returns the display coordinates of a visible and active overlay surface
2984 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
2985 *****************************************************************************/
2986 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
2988 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
2991 TRACE("iface %p, x %p, y %p.\n", iface
, X
, Y
);
2993 wined3d_mutex_lock();
2994 hr
= wined3d_surface_get_overlay_position(surface
->wined3d_surface
, X
, Y
);
2995 wined3d_mutex_unlock();
3000 static HRESULT WINAPI
ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4
*iface
, LONG
*x
, LONG
*y
)
3002 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3004 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3006 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3009 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
3011 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3013 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3015 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3018 static HRESULT WINAPI
ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2
*iface
, LONG
*x
, LONG
*y
)
3020 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3022 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3024 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3027 static HRESULT WINAPI
ddraw_surface1_GetOverlayPosition(IDirectDrawSurface
*iface
, LONG
*x
, LONG
*y
)
3029 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3031 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
3033 return ddraw_surface7_GetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3036 /*****************************************************************************
3037 * IDirectDrawSurface7::GetPixelFormat
3039 * Returns the pixel format of the Surface
3042 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3043 * format should be written
3047 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3049 *****************************************************************************/
3050 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
3052 /* What is DDERR_INVALIDSURFACETYPE for here? */
3053 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3055 TRACE("iface %p, pixel_format %p.\n", iface
, PixelFormat
);
3058 return DDERR_INVALIDPARAMS
;
3060 wined3d_mutex_lock();
3061 DD_STRUCT_COPY_BYSIZE(PixelFormat
, &surface
->surface_desc
.u4
.ddpfPixelFormat
);
3062 wined3d_mutex_unlock();
3067 static HRESULT WINAPI
ddraw_surface4_GetPixelFormat(IDirectDrawSurface4
*iface
, DDPIXELFORMAT
*pixel_format
)
3069 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3071 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3073 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3076 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
3078 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3080 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3082 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3085 static HRESULT WINAPI
ddraw_surface2_GetPixelFormat(IDirectDrawSurface2
*iface
, DDPIXELFORMAT
*pixel_format
)
3087 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3089 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3091 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3094 static HRESULT WINAPI
ddraw_surface1_GetPixelFormat(IDirectDrawSurface
*iface
, DDPIXELFORMAT
*pixel_format
)
3096 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3098 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
3100 return ddraw_surface7_GetPixelFormat(&surface
->IDirectDrawSurface7_iface
, pixel_format
);
3103 /*****************************************************************************
3104 * IDirectDrawSurface7::GetSurfaceDesc
3106 * Returns the description of this surface
3109 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3114 * DDERR_INVALIDPARAMS if DDSD is NULL
3116 *****************************************************************************/
3117 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
3119 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3121 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3124 return DDERR_INVALIDPARAMS
;
3126 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
3128 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
3129 return DDERR_INVALIDPARAMS
;
3132 wined3d_mutex_lock();
3133 DD_STRUCT_COPY_BYSIZE(DDSD
, &surface
->surface_desc
);
3134 TRACE("Returning surface desc:\n");
3135 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
3136 wined3d_mutex_unlock();
3141 static HRESULT WINAPI
ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4
*iface
, DDSURFACEDESC2
*DDSD
)
3143 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3145 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3147 return ddraw_surface7_GetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
, DDSD
);
3150 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
3152 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3154 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
3156 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
3158 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3160 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
3161 return DDERR_INVALIDPARAMS
;
3164 wined3d_mutex_lock();
3165 DDSD2_to_DDSD(&surface
->surface_desc
, surface_desc
);
3166 TRACE("Returning surface desc:\n");
3167 if (TRACE_ON(ddraw
))
3169 /* DDRAW_dump_surface_desc handles the smaller size */
3170 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3172 wined3d_mutex_unlock();
3177 static HRESULT WINAPI
ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2
*iface
, DDSURFACEDESC
*DDSD
)
3179 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3181 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3183 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3186 static HRESULT WINAPI
ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface
*iface
, DDSURFACEDESC
*DDSD
)
3188 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3190 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
3192 return ddraw_surface3_GetSurfaceDesc(&surface
->IDirectDrawSurface3_iface
, DDSD
);
3195 /*****************************************************************************
3196 * IDirectDrawSurface7::Initialize
3198 * Initializes the surface. This is a no-op in Wine
3201 * DD: Pointer to an DirectDraw interface
3202 * DDSD: Surface description for initialization
3205 * DDERR_ALREADYINITIALIZED
3207 *****************************************************************************/
3208 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
3209 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3211 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3213 return DDERR_ALREADYINITIALIZED
;
3216 static HRESULT WINAPI
ddraw_surface4_Initialize(IDirectDrawSurface4
*iface
,
3217 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
3219 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3221 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3223 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3224 ddraw
, surface_desc
);
3227 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
3228 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3230 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3231 DDSURFACEDESC2 surface_desc2
;
3233 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3235 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3236 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3237 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3240 static HRESULT WINAPI
ddraw_surface2_Initialize(IDirectDrawSurface2
*iface
,
3241 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3243 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3244 DDSURFACEDESC2 surface_desc2
;
3246 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3248 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3249 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3250 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3253 static HRESULT WINAPI
ddraw_surface1_Initialize(IDirectDrawSurface
*iface
,
3254 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
3256 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3257 DDSURFACEDESC2 surface_desc2
;
3259 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
3261 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3262 return ddraw_surface7_Initialize(&surface
->IDirectDrawSurface7_iface
,
3263 ddraw
, surface_desc
? &surface_desc2
: NULL
);
3266 /*****************************************************************************
3267 * IDirect3DTexture1::Initialize
3269 * The sdk says it's not implemented
3277 *****************************************************************************/
3278 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
3279 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
3281 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
3283 return DDERR_UNSUPPORTED
; /* Unchecked */
3286 /*****************************************************************************
3287 * IDirectDrawSurface7::IsLost
3289 * Checks if the surface is lost
3292 * DD_OK, if the surface is usable
3293 * DDERR_ISLOST if the surface is lost
3294 * See IWineD3DSurface::IsLost for more details
3296 *****************************************************************************/
3297 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
3299 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3302 TRACE("iface %p.\n", iface
);
3304 wined3d_mutex_lock();
3305 hr
= wined3d_surface_is_lost(surface
->wined3d_surface
);
3306 wined3d_mutex_unlock();
3310 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3311 * WineD3D uses the same error for surfaces
3313 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
3318 static HRESULT WINAPI
ddraw_surface4_IsLost(IDirectDrawSurface4
*iface
)
3320 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3322 TRACE("iface %p.\n", iface
);
3324 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3327 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
3329 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3331 TRACE("iface %p.\n", iface
);
3333 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3336 static HRESULT WINAPI
ddraw_surface2_IsLost(IDirectDrawSurface2
*iface
)
3338 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3340 TRACE("iface %p.\n", iface
);
3342 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3345 static HRESULT WINAPI
ddraw_surface1_IsLost(IDirectDrawSurface
*iface
)
3347 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3349 TRACE("iface %p.\n", iface
);
3351 return ddraw_surface7_IsLost(&surface
->IDirectDrawSurface7_iface
);
3354 /*****************************************************************************
3355 * IDirectDrawSurface7::Restore
3357 * Restores a lost surface. This makes the surface usable again, but
3358 * doesn't reload its old contents
3362 * See IWineD3DSurface::Restore for more details
3364 *****************************************************************************/
3365 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
3367 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3370 TRACE("iface %p.\n", iface
);
3372 wined3d_mutex_lock();
3373 hr
= wined3d_surface_restore(surface
->wined3d_surface
);
3374 wined3d_mutex_unlock();
3379 static HRESULT WINAPI
ddraw_surface4_Restore(IDirectDrawSurface4
*iface
)
3381 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3383 TRACE("iface %p.\n", iface
);
3385 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3388 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
3390 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3392 TRACE("iface %p.\n", iface
);
3394 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3397 static HRESULT WINAPI
ddraw_surface2_Restore(IDirectDrawSurface2
*iface
)
3399 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3401 TRACE("iface %p.\n", iface
);
3403 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3406 static HRESULT WINAPI
ddraw_surface1_Restore(IDirectDrawSurface
*iface
)
3408 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3410 TRACE("iface %p.\n", iface
);
3412 return ddraw_surface7_Restore(&surface
->IDirectDrawSurface7_iface
);
3415 /*****************************************************************************
3416 * IDirectDrawSurface7::SetOverlayPosition
3418 * Changes the display coordinates of an overlay surface
3425 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3426 *****************************************************************************/
3427 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
3429 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3432 TRACE("iface %p, x %d, y %d.\n", iface
, X
, Y
);
3434 wined3d_mutex_lock();
3435 hr
= wined3d_surface_set_overlay_position(surface
->wined3d_surface
, X
, Y
);
3436 wined3d_mutex_unlock();
3441 static HRESULT WINAPI
ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4
*iface
, LONG x
, LONG y
)
3443 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3445 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3447 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3450 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
3452 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3454 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3456 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3459 static HRESULT WINAPI
ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2
*iface
, LONG x
, LONG y
)
3461 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3463 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3465 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3468 static HRESULT WINAPI
ddraw_surface1_SetOverlayPosition(IDirectDrawSurface
*iface
, LONG x
, LONG y
)
3470 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3472 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
3474 return ddraw_surface7_SetOverlayPosition(&surface
->IDirectDrawSurface7_iface
, x
, y
);
3477 /*****************************************************************************
3478 * IDirectDrawSurface7::UpdateOverlay
3480 * Modifies the attributes of an overlay surface.
3483 * SrcRect: The section of the source being used for the overlay
3484 * DstSurface: Address of the surface that is overlaid
3485 * DstRect: Place of the overlay
3486 * Flags: some DDOVER_* flags
3489 * DDERR_UNSUPPORTED, because we don't support overlays
3491 *****************************************************************************/
3492 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
3493 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
3495 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface7(iface
);
3496 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface7(DstSurface
);
3499 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3500 iface
, wine_dbgstr_rect(SrcRect
), DstSurface
, wine_dbgstr_rect(DstRect
), Flags
, FX
);
3502 wined3d_mutex_lock();
3503 hr
= wined3d_surface_update_overlay(src_impl
->wined3d_surface
, SrcRect
,
3504 dst_impl
? dst_impl
->wined3d_surface
: NULL
, DstRect
, Flags
, (WINEDDOVERLAYFX
*)FX
);
3505 wined3d_mutex_unlock();
3508 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
3509 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
3510 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
3516 static HRESULT WINAPI
ddraw_surface4_UpdateOverlay(IDirectDrawSurface4
*iface
, RECT
*src_rect
,
3517 IDirectDrawSurface4
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3519 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface4(iface
);
3520 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface4(dst_surface
);
3522 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3523 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3525 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3526 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3529 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
3530 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3532 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface3(iface
);
3533 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface3(dst_surface
);
3535 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3536 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3538 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3539 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3542 static HRESULT WINAPI
ddraw_surface2_UpdateOverlay(IDirectDrawSurface2
*iface
, RECT
*src_rect
,
3543 IDirectDrawSurface2
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3545 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface2(iface
);
3546 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface2(dst_surface
);
3548 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3549 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3551 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3552 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3555 static HRESULT WINAPI
ddraw_surface1_UpdateOverlay(IDirectDrawSurface
*iface
, RECT
*src_rect
,
3556 IDirectDrawSurface
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
3558 struct ddraw_surface
*src_impl
= impl_from_IDirectDrawSurface(iface
);
3559 struct ddraw_surface
*dst_impl
= unsafe_impl_from_IDirectDrawSurface(dst_surface
);
3561 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3562 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
3564 return ddraw_surface7_UpdateOverlay(&src_impl
->IDirectDrawSurface7_iface
, src_rect
,
3565 dst_impl
? &dst_impl
->IDirectDrawSurface7_iface
: NULL
, dst_rect
, flags
, fx
);
3568 /*****************************************************************************
3569 * IDirectDrawSurface7::UpdateOverlayDisplay
3571 * The DX7 sdk says that it's not implemented
3576 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3578 *****************************************************************************/
3579 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
3581 TRACE("iface %p, flags %#x.\n", iface
, Flags
);
3583 return DDERR_UNSUPPORTED
;
3586 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4
*iface
, DWORD flags
)
3588 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3590 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3592 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3595 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
3597 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3599 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3601 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3604 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2
*iface
, DWORD flags
)
3606 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3608 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3610 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3613 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface
*iface
, DWORD flags
)
3615 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3617 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3619 return ddraw_surface7_UpdateOverlayDisplay(&surface
->IDirectDrawSurface7_iface
, flags
);
3622 /*****************************************************************************
3623 * IDirectDrawSurface7::UpdateOverlayZOrder
3625 * Sets an overlay's Z order
3628 * Flags: DDOVERZ_* flags
3629 * DDSRef: Defines the relative position in the overlay chain
3632 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3634 *****************************************************************************/
3635 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
3636 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
3638 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3639 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface7(DDSRef
);
3642 TRACE("iface %p, flags %#x, reference %p.\n", iface
, Flags
, DDSRef
);
3644 wined3d_mutex_lock();
3645 hr
= wined3d_surface_update_overlay_z_order(surface
->wined3d_surface
,
3646 Flags
, reference_impl
? reference_impl
->wined3d_surface
: NULL
);
3647 wined3d_mutex_unlock();
3652 static HRESULT WINAPI
ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4
*iface
,
3653 DWORD flags
, IDirectDrawSurface4
*reference
)
3655 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3656 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface4(reference
);
3658 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3660 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3661 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3664 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
3665 DWORD flags
, IDirectDrawSurface3
*reference
)
3667 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3668 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface3(reference
);
3670 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3672 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3673 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3676 static HRESULT WINAPI
ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2
*iface
,
3677 DWORD flags
, IDirectDrawSurface2
*reference
)
3679 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3680 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface2(reference
);
3682 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3684 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3685 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3688 static HRESULT WINAPI
ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface
*iface
,
3689 DWORD flags
, IDirectDrawSurface
*reference
)
3691 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
3692 struct ddraw_surface
*reference_impl
= unsafe_impl_from_IDirectDrawSurface(reference
);
3694 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
3696 return ddraw_surface7_UpdateOverlayZOrder(&surface
->IDirectDrawSurface7_iface
, flags
,
3697 reference_impl
? &reference_impl
->IDirectDrawSurface7_iface
: NULL
);
3700 /*****************************************************************************
3701 * IDirectDrawSurface7::GetDDInterface
3703 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3704 * surface belongs to
3707 * DD: Address to write the interface pointer to
3711 * DDERR_INVALIDPARAMS if DD is NULL
3713 *****************************************************************************/
3714 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
3716 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3718 TRACE("iface %p, ddraw %p.\n", iface
, DD
);
3721 return DDERR_INVALIDPARAMS
;
3723 switch(This
->version
)
3726 *DD
= &This
->ddraw
->IDirectDraw7_iface
;
3730 *DD
= &This
->ddraw
->IDirectDraw4_iface
;
3734 *DD
= &This
->ddraw
->IDirectDraw2_iface
;
3738 *DD
= &This
->ddraw
->IDirectDraw_iface
;
3742 IUnknown_AddRef((IUnknown
*)*DD
);
3747 static HRESULT WINAPI
ddraw_surface4_GetDDInterface(IDirectDrawSurface4
*iface
, void **ddraw
)
3749 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3751 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3753 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3756 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
3758 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
3760 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3762 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3765 static HRESULT WINAPI
ddraw_surface2_GetDDInterface(IDirectDrawSurface2
*iface
, void **ddraw
)
3767 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
3769 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
3771 return ddraw_surface7_GetDDInterface(&surface
->IDirectDrawSurface7_iface
, ddraw
);
3774 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3775 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
3777 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3778 volatile struct ddraw_surface
* vThis
= This
;
3780 TRACE("iface %p.\n", iface
);
3782 wined3d_mutex_lock();
3783 /* A uniqueness value of 0 is apparently special.
3784 * This needs to be checked.
3785 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3788 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
3789 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
3791 if (old_uniqueness_value
== 0) break;
3792 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
3794 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
3795 old_uniqueness_value
,
3796 new_uniqueness_value
)
3797 == old_uniqueness_value
)
3801 wined3d_mutex_unlock();
3806 static HRESULT WINAPI
ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4
*iface
)
3808 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3810 TRACE("iface %p.\n", iface
);
3812 return ddraw_surface7_ChangeUniquenessValue(&surface
->IDirectDrawSurface7_iface
);
3815 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
3817 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3819 TRACE("iface %p, value %p.\n", iface
, pValue
);
3821 wined3d_mutex_lock();
3822 *pValue
= surface
->uniqueness_value
;
3823 wined3d_mutex_unlock();
3828 static HRESULT WINAPI
ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4
*iface
, DWORD
*pValue
)
3830 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
3832 TRACE("iface %p, value %p.\n", iface
, pValue
);
3834 return ddraw_surface7_GetUniquenessValue(&surface
->IDirectDrawSurface7_iface
, pValue
);
3837 /*****************************************************************************
3838 * IDirectDrawSurface7::SetLOD
3840 * Sets the level of detail of a texture
3843 * MaxLOD: LOD to set
3847 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3849 *****************************************************************************/
3850 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
3852 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3855 TRACE("iface %p, lod %u.\n", iface
, MaxLOD
);
3857 wined3d_mutex_lock();
3858 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3860 wined3d_mutex_unlock();
3861 return DDERR_INVALIDOBJECT
;
3864 if (!surface
->wined3d_texture
)
3866 ERR("The ddraw surface has no wined3d texture.\n");
3867 wined3d_mutex_unlock();
3868 return DDERR_INVALIDOBJECT
;
3871 hr
= wined3d_texture_set_lod(surface
->wined3d_texture
, MaxLOD
);
3872 wined3d_mutex_unlock();
3877 /*****************************************************************************
3878 * IDirectDrawSurface7::GetLOD
3880 * Returns the level of detail of a Direct3D texture
3883 * MaxLOD: Address to write the LOD to
3887 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3888 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3890 *****************************************************************************/
3891 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
3893 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
3895 TRACE("iface %p, lod %p.\n", iface
, MaxLOD
);
3898 return DDERR_INVALIDPARAMS
;
3900 wined3d_mutex_lock();
3901 if (!(surface
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
3903 wined3d_mutex_unlock();
3904 return DDERR_INVALIDOBJECT
;
3907 *MaxLOD
= wined3d_texture_get_lod(surface
->wined3d_texture
);
3908 wined3d_mutex_unlock();
3913 /*****************************************************************************
3914 * IDirectDrawSurface7::BltFast
3916 * Performs a fast Blit.
3919 * dstx: The x coordinate to blit to on the destination
3920 * dsty: The y coordinate to blit to on the destination
3921 * Source: The source surface
3922 * rsrc: The source rectangle
3923 * trans: Type of transfer. Some DDBLTFAST_* flags
3927 * For more details, see IWineD3DSurface::BltFast
3929 *****************************************************************************/
3930 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
3931 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
3933 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
3934 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(Source
);
3935 DWORD src_w
, src_h
, dst_w
, dst_h
;
3940 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3941 iface
, dstx
, dsty
, Source
, wine_dbgstr_rect(rsrc
), trans
);
3943 dst_w
= This
->surface_desc
.dwWidth
;
3944 dst_h
= This
->surface_desc
.dwHeight
;
3946 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3951 src_w
= rsrc
->right
- rsrc
->left
;
3952 src_h
= rsrc
->bottom
- rsrc
->top
;
3956 src_w
= src
->surface_desc
.dwWidth
;
3957 src_h
= src
->surface_desc
.dwHeight
;
3960 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
3961 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
3963 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3964 return DDERR_INVALIDRECT
;
3967 SetRect(&dst_rect
, dstx
, dsty
, dstx
+ src_w
, dsty
+ src_h
);
3968 if (trans
& DDBLTFAST_SRCCOLORKEY
)
3969 flags
|= WINEDDBLT_KEYSRC
;
3970 if (trans
& DDBLTFAST_DESTCOLORKEY
)
3971 flags
|= WINEDDBLT_KEYDEST
;
3972 if (trans
& DDBLTFAST_WAIT
)
3973 flags
|= WINEDDBLT_WAIT
;
3974 if (trans
& DDBLTFAST_DONOTWAIT
)
3975 flags
|= WINEDDBLT_DONOTWAIT
;
3977 wined3d_mutex_lock();
3980 wined3d_mutex_unlock();
3981 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
3982 return DDERR_BLTFASTCANTCLIP
;
3985 if (src
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
3986 hr
= ddraw_surface_update_frontbuffer(src
, rsrc
, TRUE
);
3988 hr
= wined3d_surface_blt(This
->wined3d_surface
, &dst_rect
,
3989 src
->wined3d_surface
, rsrc
, flags
, NULL
, WINED3D_TEXF_POINT
);
3990 if (SUCCEEDED(hr
) && (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
))
3991 hr
= ddraw_surface_update_frontbuffer(This
, &dst_rect
, FALSE
);
3992 wined3d_mutex_unlock();
3996 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
3997 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
4002 static HRESULT WINAPI
ddraw_surface4_BltFast(IDirectDrawSurface4
*iface
, DWORD dst_x
, DWORD dst_y
,
4003 IDirectDrawSurface4
*src_surface
, RECT
*src_rect
, DWORD flags
)
4005 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface4(iface
);
4006 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src_surface
);
4008 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4009 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4011 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4012 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4015 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
4016 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
4018 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface3(iface
);
4019 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface3(src_surface
);
4021 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4022 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4024 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4025 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4028 static HRESULT WINAPI
ddraw_surface2_BltFast(IDirectDrawSurface2
*iface
, DWORD dst_x
, DWORD dst_y
,
4029 IDirectDrawSurface2
*src_surface
, RECT
*src_rect
, DWORD flags
)
4031 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface2(iface
);
4032 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface2(src_surface
);
4034 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4035 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4037 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4038 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4041 static HRESULT WINAPI
ddraw_surface1_BltFast(IDirectDrawSurface
*iface
, DWORD dst_x
, DWORD dst_y
,
4042 IDirectDrawSurface
*src_surface
, RECT
*src_rect
, DWORD flags
)
4044 struct ddraw_surface
*dst_impl
= impl_from_IDirectDrawSurface(iface
);
4045 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src_surface
);
4047 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4048 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
4050 return ddraw_surface7_BltFast(&dst_impl
->IDirectDrawSurface7_iface
, dst_x
, dst_y
,
4051 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, src_rect
, flags
);
4054 /*****************************************************************************
4055 * IDirectDrawSurface7::GetClipper
4057 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4061 * Clipper: Address to store the interface pointer at
4065 * DDERR_INVALIDPARAMS if Clipper is NULL
4066 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4068 *****************************************************************************/
4069 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
4071 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4073 TRACE("iface %p, clipper %p.\n", iface
, Clipper
);
4076 return DDERR_INVALIDPARAMS
;
4078 wined3d_mutex_lock();
4079 if (!surface
->clipper
)
4081 wined3d_mutex_unlock();
4082 return DDERR_NOCLIPPERATTACHED
;
4085 *Clipper
= (IDirectDrawClipper
*)surface
->clipper
;
4086 IDirectDrawClipper_AddRef(*Clipper
);
4087 wined3d_mutex_unlock();
4092 static HRESULT WINAPI
ddraw_surface4_GetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
**clipper
)
4094 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4096 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4098 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4101 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
4103 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4105 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4107 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4110 static HRESULT WINAPI
ddraw_surface2_GetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
**clipper
)
4112 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4114 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4116 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4119 static HRESULT WINAPI
ddraw_surface1_GetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
**clipper
)
4121 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4123 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4125 return ddraw_surface7_GetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4128 /*****************************************************************************
4129 * IDirectDrawSurface7::SetClipper
4131 * Sets a clipper for the surface
4134 * Clipper: IDirectDrawClipper interface of the clipper to set
4139 *****************************************************************************/
4140 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
,
4141 IDirectDrawClipper
*iclipper
)
4143 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4144 struct ddraw_clipper
*clipper
= unsafe_impl_from_IDirectDrawClipper(iclipper
);
4145 struct ddraw_clipper
*old_clipper
= This
->clipper
;
4148 TRACE("iface %p, clipper %p.\n", iface
, iclipper
);
4150 wined3d_mutex_lock();
4151 if (clipper
== This
->clipper
)
4153 wined3d_mutex_unlock();
4157 This
->clipper
= clipper
;
4159 if (clipper
!= NULL
)
4160 IDirectDrawClipper_AddRef(iclipper
);
4162 IDirectDrawClipper_Release(&old_clipper
->IDirectDrawClipper_iface
);
4164 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && This
->ddraw
->wined3d_swapchain
)
4168 IDirectDrawClipper_GetHWnd(iclipper
, &clipWindow
);
4173 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, clipWindow
);
4174 ddraw_set_swapchain_window(This
->ddraw
, clipWindow
);
4178 wined3d_swapchain_set_window(This
->ddraw
->wined3d_swapchain
, This
->ddraw
->d3d_window
);
4179 ddraw_set_swapchain_window(This
->ddraw
, This
->ddraw
->dest_window
);
4183 wined3d_mutex_unlock();
4188 static HRESULT WINAPI
ddraw_surface4_SetClipper(IDirectDrawSurface4
*iface
, IDirectDrawClipper
*clipper
)
4190 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4192 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4194 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4197 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
4199 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4201 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4203 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4206 static HRESULT WINAPI
ddraw_surface2_SetClipper(IDirectDrawSurface2
*iface
, IDirectDrawClipper
*clipper
)
4208 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4210 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4212 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4215 static HRESULT WINAPI
ddraw_surface1_SetClipper(IDirectDrawSurface
*iface
, IDirectDrawClipper
*clipper
)
4217 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4219 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
4221 return ddraw_surface7_SetClipper(&surface
->IDirectDrawSurface7_iface
, clipper
);
4224 /*****************************************************************************
4225 * IDirectDrawSurface7::SetSurfaceDesc
4227 * Sets the surface description. It can override the pixel format, the surface
4229 * It's not really tested.
4232 * DDSD: Pointer to the new surface description to set
4237 * DDERR_INVALIDPARAMS if DDSD is NULL
4239 *****************************************************************************/
4240 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
4242 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4244 const DWORD allowed_flags
= DDSD_LPSURFACE
| DDSD_PIXELFORMAT
| DDSD_WIDTH
4245 | DDSD_HEIGHT
| DDSD_PITCH
| DDSD_CAPS
;
4246 enum wined3d_format_id format_id
;
4247 BOOL update_wined3d
= FALSE
;
4250 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, DDSD
, Flags
);
4254 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4255 return DDERR_INVALIDPARAMS
;
4259 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags
);
4260 return DDERR_INVALIDPARAMS
;
4262 if (!(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
))
4264 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4265 return DDERR_INVALIDSURFACETYPE
;
4268 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4269 * for PIXELFORMAT to work */
4270 if (DDSD
->dwFlags
& ~allowed_flags
)
4272 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD
->dwFlags
);
4273 return DDERR_INVALIDPARAMS
;
4275 if (!(DDSD
->dwFlags
& DDSD_LPSURFACE
))
4277 WARN("DDSD_LPSURFACE is not set, returning DDERR_INVALIDPARAMS\n");
4278 return DDERR_INVALIDPARAMS
;
4280 if (DDSD
->dwFlags
& DDSD_CAPS
)
4282 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4283 return DDERR_INVALIDCAPS
;
4285 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4287 if (!(DDSD
->dwFlags
& DDSD_PITCH
))
4289 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4290 return DDERR_INVALIDPARAMS
;
4292 if (!DDSD
->dwWidth
|| DDSD
->u1
.lPitch
<= 0 || DDSD
->u1
.lPitch
& 0x3)
4294 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4295 DDSD
->u1
.lPitch
, DDSD
->dwWidth
);
4296 return DDERR_INVALIDPARAMS
;
4298 if (DDSD
->dwWidth
!= This
->surface_desc
.dwWidth
)
4300 TRACE("Surface width changed from %u to %u.\n", This
->surface_desc
.dwWidth
, DDSD
->dwWidth
);
4301 update_wined3d
= TRUE
;
4303 if (DDSD
->u1
.lPitch
!= This
->surface_desc
.u1
.lPitch
)
4305 TRACE("Surface pitch changed from %u to %u.\n", This
->surface_desc
.u1
.lPitch
, DDSD
->u1
.lPitch
);
4306 update_wined3d
= TRUE
;
4308 width
= DDSD
->dwWidth
;
4310 else if (DDSD
->dwFlags
& DDSD_PITCH
)
4312 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4313 return DDERR_INVALIDPARAMS
;
4317 width
= This
->surface_desc
.dwWidth
;
4320 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4322 if (!DDSD
->dwHeight
)
4324 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4325 return DDERR_INVALIDPARAMS
;
4327 if (DDSD
->dwHeight
!= This
->surface_desc
.dwHeight
)
4329 TRACE("Surface height changed from %u to %u.\n", This
->surface_desc
.dwHeight
, DDSD
->dwHeight
);
4330 update_wined3d
= TRUE
;
4332 height
= DDSD
->dwHeight
;
4336 height
= This
->surface_desc
.dwHeight
;
4339 wined3d_mutex_lock();
4340 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4342 enum wined3d_format_id current_format_id
;
4343 format_id
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
4345 if (format_id
== WINED3DFMT_UNKNOWN
)
4347 ERR("Requested to set an unknown pixelformat\n");
4348 wined3d_mutex_unlock();
4349 return DDERR_INVALIDPARAMS
;
4351 current_format_id
= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4352 if (format_id
!= current_format_id
)
4354 TRACE("Surface format changed from %#x to %#x.\n", current_format_id
, format_id
);
4355 update_wined3d
= TRUE
;
4360 format_id
= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
);
4365 if (FAILED(hr
= wined3d_surface_update_desc(This
->wined3d_surface
, width
, height
,
4366 format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
4368 WARN("Failed to update surface desc, hr %#x.\n", hr
);
4369 wined3d_mutex_unlock();
4373 if (DDSD
->dwFlags
& DDSD_WIDTH
)
4374 This
->surface_desc
.dwWidth
= width
;
4375 if (DDSD
->dwFlags
& DDSD_PITCH
)
4376 This
->surface_desc
.u1
.lPitch
= DDSD
->u1
.lPitch
;
4377 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
4378 This
->surface_desc
.dwHeight
= height
;
4379 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
4380 This
->surface_desc
.u4
.ddpfPixelFormat
= DDSD
->u4
.ddpfPixelFormat
;
4383 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
4385 hr
= wined3d_surface_set_mem(This
->wined3d_surface
, DDSD
->lpSurface
);
4388 /* No need for a trace here, wined3d does that for us */
4391 case WINED3DERR_INVALIDCALL
:
4392 wined3d_mutex_unlock();
4393 return DDERR_INVALIDPARAMS
;
4398 /* DDSD->lpSurface is set by Lock() */
4401 wined3d_mutex_unlock();
4406 static HRESULT WINAPI
ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4
*iface
,
4407 DDSURFACEDESC2
*surface_desc
, DWORD flags
)
4409 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4411 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4413 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4414 surface_desc
, flags
);
4417 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
4418 DDSURFACEDESC
*surface_desc
, DWORD flags
)
4420 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4421 DDSURFACEDESC2 surface_desc2
;
4423 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
4425 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
4426 return ddraw_surface7_SetSurfaceDesc(&surface
->IDirectDrawSurface7_iface
,
4427 surface_desc
? &surface_desc2
: NULL
, flags
);
4430 /*****************************************************************************
4431 * IDirectDrawSurface7::GetPalette
4433 * Returns the IDirectDrawPalette interface of the palette currently assigned
4437 * Pal: Address to write the interface pointer to
4441 * DDERR_INVALIDPARAMS if Pal is NULL
4443 *****************************************************************************/
4444 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
4446 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface7(iface
);
4447 struct wined3d_palette
*wined3d_palette
;
4450 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4453 return DDERR_INVALIDPARAMS
;
4455 wined3d_mutex_lock();
4456 wined3d_palette
= wined3d_surface_get_palette(surface
->wined3d_surface
);
4457 if (wined3d_palette
)
4459 *Pal
= wined3d_palette_get_parent(wined3d_palette
);
4460 IDirectDrawPalette_AddRef(*Pal
);
4465 hr
= DDERR_NOPALETTEATTACHED
;
4468 wined3d_mutex_unlock();
4473 static HRESULT WINAPI
ddraw_surface4_GetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
**palette
)
4475 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4477 TRACE("iface %p, palette %p.\n", iface
, palette
);
4479 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4482 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
4484 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4486 TRACE("iface %p, palette %p.\n", iface
, palette
);
4488 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4491 static HRESULT WINAPI
ddraw_surface2_GetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
**palette
)
4493 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4495 TRACE("iface %p, palette %p.\n", iface
, palette
);
4497 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4500 static HRESULT WINAPI
ddraw_surface1_GetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
**palette
)
4502 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4504 TRACE("iface %p, palette %p.\n", iface
, palette
);
4506 return ddraw_surface7_GetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4509 /*****************************************************************************
4512 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4513 * recursively in the surface tree
4515 *****************************************************************************/
4519 struct wined3d_color_key
*color_key
;
4523 static HRESULT WINAPI
SetColorKeyEnum(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
4525 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
4526 struct SCKContext
*ctx
= context
;
4529 hr
= wined3d_surface_set_color_key(surface_impl
->wined3d_surface
, ctx
->Flags
, ctx
->color_key
);
4532 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
4536 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
4537 ddraw_surface7_Release(surface
);
4539 return DDENUMRET_OK
;
4542 /*****************************************************************************
4543 * IDirectDrawSurface7::SetColorKey
4545 * Sets the color keying options for the surface. Observations showed that
4546 * in case of complex surfaces the color key has to be assigned to all
4551 * CKey: The new color key
4555 * See IWineD3DSurface::SetColorKey for details
4557 *****************************************************************************/
4558 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
4560 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4561 DDCOLORKEY FixedCKey
;
4562 struct SCKContext ctx
= { DD_OK
, (struct wined3d_color_key
*)(CKey
? &FixedCKey
: NULL
), Flags
};
4564 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, Flags
, CKey
);
4566 wined3d_mutex_lock();
4570 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4571 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
4572 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
4574 switch (Flags
& ~DDCKEY_COLORSPACE
)
4576 case DDCKEY_DESTBLT
:
4577 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
4578 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
4581 case DDCKEY_DESTOVERLAY
:
4582 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
4583 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
4586 case DDCKEY_SRCOVERLAY
:
4587 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
4588 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
4592 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
4593 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
4597 wined3d_mutex_unlock();
4598 return DDERR_INVALIDPARAMS
;
4603 switch (Flags
& ~DDCKEY_COLORSPACE
)
4605 case DDCKEY_DESTBLT
:
4606 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
4609 case DDCKEY_DESTOVERLAY
:
4610 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
4613 case DDCKEY_SRCOVERLAY
:
4614 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
4618 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
4622 wined3d_mutex_unlock();
4623 return DDERR_INVALIDPARAMS
;
4626 ctx
.ret
= wined3d_surface_set_color_key(This
->wined3d_surface
, Flags
, ctx
.color_key
);
4627 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
4628 wined3d_mutex_unlock();
4632 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
4633 default: return ctx
.ret
;
4637 static HRESULT WINAPI
ddraw_surface4_SetColorKey(IDirectDrawSurface4
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4639 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4641 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4643 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4646 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4648 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4650 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4652 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4655 static HRESULT WINAPI
ddraw_surface2_SetColorKey(IDirectDrawSurface2
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4657 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4659 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4661 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4664 static HRESULT WINAPI
ddraw_surface1_SetColorKey(IDirectDrawSurface
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
4666 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4668 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
4670 return ddraw_surface7_SetColorKey(&surface
->IDirectDrawSurface7_iface
, flags
, color_key
);
4673 /*****************************************************************************
4674 * IDirectDrawSurface7::SetPalette
4676 * Assigns a DirectDrawPalette object to the surface
4679 * Pal: Interface to the palette to set
4684 *****************************************************************************/
4685 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
4687 struct ddraw_surface
*This
= impl_from_IDirectDrawSurface7(iface
);
4688 struct ddraw_palette
*palette_impl
= unsafe_impl_from_IDirectDrawPalette(Pal
);
4689 IDirectDrawPalette
*oldPal
;
4690 struct ddraw_surface
*surf
;
4693 TRACE("iface %p, palette %p.\n", iface
, Pal
);
4695 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
4696 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
4697 return DDERR_INVALIDPIXELFORMAT
;
4700 if (This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
4702 return DDERR_NOTONMIPMAPSUBLEVEL
;
4705 /* Find the old palette */
4706 wined3d_mutex_lock();
4707 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
4708 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
4710 wined3d_mutex_unlock();
4713 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
4715 /* Set the new Palette */
4716 wined3d_surface_set_palette(This
->wined3d_surface
, palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
4717 /* AddRef the Palette */
4718 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
4720 /* Release the old palette */
4721 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
4723 /* Update the wined3d frontbuffer if this is the frontbuffer. */
4724 if ((This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
) && This
->ddraw
->wined3d_frontbuffer
)
4726 hr
= wined3d_surface_set_palette(This
->ddraw
->wined3d_frontbuffer
, palette_impl
? palette_impl
->wineD3DPalette
: NULL
);
4728 ERR("Failed to set frontbuffer palette, hr %#x.\n", hr
);
4731 /* If this is a front buffer, also update the back buffers
4732 * TODO: How do things work for palettized cube textures?
4734 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
4736 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4737 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
4742 IDirectDrawSurface7
*attach
;
4744 hr
= ddraw_surface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &caps2
, &attach
);
4750 TRACE("Setting palette on %p\n", attach
);
4751 ddraw_surface7_SetPalette(attach
, Pal
);
4752 surf
= impl_from_IDirectDrawSurface7(attach
);
4753 ddraw_surface7_Release(attach
);
4757 wined3d_mutex_unlock();
4762 static HRESULT WINAPI
ddraw_surface4_SetPalette(IDirectDrawSurface4
*iface
, IDirectDrawPalette
*palette
)
4764 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface4(iface
);
4766 TRACE("iface %p, palette %p.\n", iface
, palette
);
4768 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4771 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
4773 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface3(iface
);
4775 TRACE("iface %p, palette %p.\n", iface
, palette
);
4777 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4780 static HRESULT WINAPI
ddraw_surface2_SetPalette(IDirectDrawSurface2
*iface
, IDirectDrawPalette
*palette
)
4782 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface2(iface
);
4784 TRACE("iface %p, palette %p.\n", iface
, palette
);
4786 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4789 static HRESULT WINAPI
ddraw_surface1_SetPalette(IDirectDrawSurface
*iface
, IDirectDrawPalette
*palette
)
4791 struct ddraw_surface
*surface
= impl_from_IDirectDrawSurface(iface
);
4793 TRACE("iface %p, palette %p.\n", iface
, palette
);
4795 return ddraw_surface7_SetPalette(&surface
->IDirectDrawSurface7_iface
, palette
);
4798 /**********************************************************
4799 * IDirectDrawGammaControl::GetGammaRamp
4801 * Returns the current gamma ramp for a surface
4805 * gamma_ramp: Address to write the ramp to
4809 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4811 **********************************************************/
4812 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
4813 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4815 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4817 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4821 WARN("Invalid gamma_ramp passed.\n");
4822 return DDERR_INVALIDPARAMS
;
4825 wined3d_mutex_lock();
4826 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4828 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4829 wined3d_device_get_gamma_ramp(surface
->ddraw
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4833 ERR("Not implemented for non-primary surfaces.\n");
4835 wined3d_mutex_unlock();
4840 /**********************************************************
4841 * IDirectDrawGammaControl::SetGammaRamp
4843 * Sets the red, green and blue gamma ramps for
4846 * flags: Can be DDSGR_CALIBRATE to request calibration
4847 * gamma_ramp: Structure containing the new gamma ramp
4851 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4853 **********************************************************/
4854 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
4855 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
4857 struct ddraw_surface
*surface
= impl_from_IDirectDrawGammaControl(iface
);
4859 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
4863 WARN("Invalid gamma_ramp passed.\n");
4864 return DDERR_INVALIDPARAMS
;
4867 wined3d_mutex_lock();
4868 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
4870 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4871 wined3d_device_set_gamma_ramp(surface
->ddraw
->wined3d_device
,
4872 0, flags
, (struct wined3d_gamma_ramp
*)gamma_ramp
);
4876 ERR("Not implemented for non-primary surfaces.\n");
4878 wined3d_mutex_unlock();
4883 /*****************************************************************************
4884 * IDirect3DTexture2::PaletteChanged
4886 * Informs the texture about a palette change
4889 * start: Start index of the change
4890 * count: The number of changed entries
4893 * D3D_OK, because it's a stub
4895 *****************************************************************************/
4896 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
4898 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
4903 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
4905 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4907 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
4909 return d3d_texture2_PaletteChanged(&surface
->IDirect3DTexture2_iface
, start
, count
);
4912 /*****************************************************************************
4913 * IDirect3DTexture::Unload
4915 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4921 *****************************************************************************/
4922 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
4924 WARN("iface %p. Not implemented.\n", iface
);
4926 return DDERR_UNSUPPORTED
;
4929 /*****************************************************************************
4930 * IDirect3DTexture2::GetHandle
4932 * Returns handle for the texture. At the moment, the interface
4933 * to the IWineD3DTexture is used.
4936 * device: Device this handle is assigned to
4937 * handle: Address to store the handle at.
4942 *****************************************************************************/
4943 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
4944 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
4946 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture2(iface
);
4947 IDirect3DDeviceImpl
*device_impl
= unsafe_impl_from_IDirect3DDevice2(device
);
4949 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4951 wined3d_mutex_lock();
4953 if (!surface
->Handle
)
4955 DWORD h
= ddraw_allocate_handle(&device_impl
->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
4956 if (h
== DDRAW_INVALID_HANDLE
)
4958 ERR("Failed to allocate a texture handle.\n");
4959 wined3d_mutex_unlock();
4960 return DDERR_OUTOFMEMORY
;
4963 surface
->Handle
= h
+ 1;
4966 TRACE("Returning handle %08x.\n", surface
->Handle
);
4967 *handle
= surface
->Handle
;
4969 wined3d_mutex_unlock();
4974 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
4975 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
4977 struct ddraw_surface
*surface
= impl_from_IDirect3DTexture(iface
);
4978 IDirect3DDeviceImpl
*device_impl
= unsafe_impl_from_IDirect3DDevice(device
);
4980 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
4982 return d3d_texture2_GetHandle(&surface
->IDirect3DTexture2_iface
,
4983 device_impl
? &device_impl
->IDirect3DDevice2_iface
: NULL
, handle
);
4986 /*****************************************************************************
4987 * get_sub_mimaplevel
4989 * Helper function that returns the next mipmap level
4991 * tex_ptr: Surface of which to return the next level
4993 *****************************************************************************/
4994 static struct ddraw_surface
*get_sub_mimaplevel(struct ddraw_surface
*surface
)
4996 /* Now go down the mipmap chain to the next surface */
4997 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
4998 IDirectDrawSurface7
*next_level
;
5001 hr
= ddraw_surface7_GetAttachedSurface(&surface
->IDirectDrawSurface7_iface
, &mipmap_caps
, &next_level
);
5002 if (FAILED(hr
)) return NULL
;
5004 ddraw_surface7_Release(next_level
);
5006 return impl_from_IDirectDrawSurface7(next_level
);
5009 /*****************************************************************************
5010 * IDirect3DTexture2::Load
5012 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5014 * This function isn't relayed to WineD3D because the whole interface is
5015 * implemented in DDraw only. For speed improvements a implementation which
5016 * takes OpenGL more into account could be placed into WineD3D.
5019 * src_texture: Address of the texture to load
5023 * D3DERR_TEXTURE_LOAD_FAILED.
5025 *****************************************************************************/
5026 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
5028 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture2(iface
);
5029 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture2(src_texture
);
5032 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5034 if (src_surface
== dst_surface
)
5036 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
5040 wined3d_mutex_lock();
5042 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5043 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
5044 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
5046 ERR("Trying to load surfaces with different mip-map counts.\n");
5051 struct wined3d_palette
*wined3d_dst_pal
, *wined3d_src_pal
;
5052 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
5053 DDSURFACEDESC
*src_desc
, *dst_desc
;
5055 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
5056 src_surface
, dst_surface
, src_surface
->mipmap_level
);
5058 /* Suppress the ALLOCONLOAD flag */
5059 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
5061 /* Get the palettes */
5062 wined3d_dst_pal
= wined3d_surface_get_palette(dst_surface
->wined3d_surface
);
5063 if (wined3d_dst_pal
)
5064 dst_pal
= wined3d_palette_get_parent(wined3d_dst_pal
);
5066 wined3d_src_pal
= wined3d_surface_get_palette(src_surface
->wined3d_surface
);
5067 if (wined3d_src_pal
)
5068 src_pal
= wined3d_palette_get_parent(wined3d_src_pal
);
5072 PALETTEENTRY palent
[256];
5076 wined3d_mutex_unlock();
5077 return DDERR_NOPALETTEATTACHED
;
5079 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
5080 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
5083 /* Copy one surface on the other */
5084 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
5085 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
5087 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
5089 /* Should also check for same pixel format, u1.lPitch, ... */
5090 ERR("Error in surface sizes.\n");
5091 wined3d_mutex_unlock();
5092 return D3DERR_TEXTURE_LOAD_FAILED
;
5096 struct wined3d_mapped_rect src_rect
, dst_rect
;
5098 /* Copy the src blit color key if the source has one, don't erase
5099 * the destination's ckey if the source has none */
5100 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
5102 IDirectDrawSurface7_SetColorKey(&dst_surface
->IDirectDrawSurface7_iface
,
5103 DDCKEY_SRCBLT
, &src_desc
->ddckCKSrcBlt
);
5106 /* Copy the main memory texture into the surface that corresponds
5107 * to the OpenGL texture object. */
5109 hr
= wined3d_surface_map(src_surface
->wined3d_surface
, &src_rect
, NULL
, 0);
5112 ERR("Failed to lock source surface, hr %#x.\n", hr
);
5113 wined3d_mutex_unlock();
5114 return D3DERR_TEXTURE_LOAD_FAILED
;
5117 hr
= wined3d_surface_map(dst_surface
->wined3d_surface
, &dst_rect
, NULL
, 0);
5120 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
5121 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5122 wined3d_mutex_unlock();
5123 return D3DERR_TEXTURE_LOAD_FAILED
;
5126 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
5127 memcpy(dst_rect
.data
, src_rect
.data
, src_surface
->surface_desc
.u1
.dwLinearSize
);
5129 memcpy(dst_rect
.data
, src_rect
.data
, src_rect
.row_pitch
* src_desc
->dwHeight
);
5131 wined3d_surface_unmap(src_surface
->wined3d_surface
);
5132 wined3d_surface_unmap(dst_surface
->wined3d_surface
);
5135 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5136 src_surface
= get_sub_mimaplevel(src_surface
);
5140 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5141 dst_surface
= get_sub_mimaplevel(dst_surface
);
5145 if (!src_surface
|| !dst_surface
)
5147 if (src_surface
!= dst_surface
)
5148 ERR("Loading surface with different mipmap structure.\n");
5153 wined3d_mutex_unlock();
5158 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
5160 struct ddraw_surface
*dst_surface
= impl_from_IDirect3DTexture(iface
);
5161 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirect3DTexture(src_texture
);
5163 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
5165 return d3d_texture2_Load(&dst_surface
->IDirect3DTexture2_iface
,
5166 src_surface
? &src_surface
->IDirect3DTexture2_iface
: NULL
);
5169 /*****************************************************************************
5171 *****************************************************************************/
5173 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl
=
5176 ddraw_surface7_QueryInterface
,
5177 ddraw_surface7_AddRef
,
5178 ddraw_surface7_Release
,
5179 /* IDirectDrawSurface */
5180 ddraw_surface7_AddAttachedSurface
,
5181 ddraw_surface7_AddOverlayDirtyRect
,
5183 ddraw_surface7_BltBatch
,
5184 ddraw_surface7_BltFast
,
5185 ddraw_surface7_DeleteAttachedSurface
,
5186 ddraw_surface7_EnumAttachedSurfaces
,
5187 ddraw_surface7_EnumOverlayZOrders
,
5188 ddraw_surface7_Flip
,
5189 ddraw_surface7_GetAttachedSurface
,
5190 ddraw_surface7_GetBltStatus
,
5191 ddraw_surface7_GetCaps
,
5192 ddraw_surface7_GetClipper
,
5193 ddraw_surface7_GetColorKey
,
5194 ddraw_surface7_GetDC
,
5195 ddraw_surface7_GetFlipStatus
,
5196 ddraw_surface7_GetOverlayPosition
,
5197 ddraw_surface7_GetPalette
,
5198 ddraw_surface7_GetPixelFormat
,
5199 ddraw_surface7_GetSurfaceDesc
,
5200 ddraw_surface7_Initialize
,
5201 ddraw_surface7_IsLost
,
5202 ddraw_surface7_Lock
,
5203 ddraw_surface7_ReleaseDC
,
5204 ddraw_surface7_Restore
,
5205 ddraw_surface7_SetClipper
,
5206 ddraw_surface7_SetColorKey
,
5207 ddraw_surface7_SetOverlayPosition
,
5208 ddraw_surface7_SetPalette
,
5209 ddraw_surface7_Unlock
,
5210 ddraw_surface7_UpdateOverlay
,
5211 ddraw_surface7_UpdateOverlayDisplay
,
5212 ddraw_surface7_UpdateOverlayZOrder
,
5213 /* IDirectDrawSurface2 */
5214 ddraw_surface7_GetDDInterface
,
5215 ddraw_surface7_PageLock
,
5216 ddraw_surface7_PageUnlock
,
5217 /* IDirectDrawSurface3 */
5218 ddraw_surface7_SetSurfaceDesc
,
5219 /* IDirectDrawSurface4 */
5220 ddraw_surface7_SetPrivateData
,
5221 ddraw_surface7_GetPrivateData
,
5222 ddraw_surface7_FreePrivateData
,
5223 ddraw_surface7_GetUniquenessValue
,
5224 ddraw_surface7_ChangeUniquenessValue
,
5225 /* IDirectDrawSurface7 */
5226 ddraw_surface7_SetPriority
,
5227 ddraw_surface7_GetPriority
,
5228 ddraw_surface7_SetLOD
,
5229 ddraw_surface7_GetLOD
,
5232 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl
=
5235 ddraw_surface4_QueryInterface
,
5236 ddraw_surface4_AddRef
,
5237 ddraw_surface4_Release
,
5238 /* IDirectDrawSurface */
5239 ddraw_surface4_AddAttachedSurface
,
5240 ddraw_surface4_AddOverlayDirtyRect
,
5242 ddraw_surface4_BltBatch
,
5243 ddraw_surface4_BltFast
,
5244 ddraw_surface4_DeleteAttachedSurface
,
5245 ddraw_surface4_EnumAttachedSurfaces
,
5246 ddraw_surface4_EnumOverlayZOrders
,
5247 ddraw_surface4_Flip
,
5248 ddraw_surface4_GetAttachedSurface
,
5249 ddraw_surface4_GetBltStatus
,
5250 ddraw_surface4_GetCaps
,
5251 ddraw_surface4_GetClipper
,
5252 ddraw_surface4_GetColorKey
,
5253 ddraw_surface4_GetDC
,
5254 ddraw_surface4_GetFlipStatus
,
5255 ddraw_surface4_GetOverlayPosition
,
5256 ddraw_surface4_GetPalette
,
5257 ddraw_surface4_GetPixelFormat
,
5258 ddraw_surface4_GetSurfaceDesc
,
5259 ddraw_surface4_Initialize
,
5260 ddraw_surface4_IsLost
,
5261 ddraw_surface4_Lock
,
5262 ddraw_surface4_ReleaseDC
,
5263 ddraw_surface4_Restore
,
5264 ddraw_surface4_SetClipper
,
5265 ddraw_surface4_SetColorKey
,
5266 ddraw_surface4_SetOverlayPosition
,
5267 ddraw_surface4_SetPalette
,
5268 ddraw_surface4_Unlock
,
5269 ddraw_surface4_UpdateOverlay
,
5270 ddraw_surface4_UpdateOverlayDisplay
,
5271 ddraw_surface4_UpdateOverlayZOrder
,
5272 /* IDirectDrawSurface2 */
5273 ddraw_surface4_GetDDInterface
,
5274 ddraw_surface4_PageLock
,
5275 ddraw_surface4_PageUnlock
,
5276 /* IDirectDrawSurface3 */
5277 ddraw_surface4_SetSurfaceDesc
,
5278 /* IDirectDrawSurface4 */
5279 ddraw_surface4_SetPrivateData
,
5280 ddraw_surface4_GetPrivateData
,
5281 ddraw_surface4_FreePrivateData
,
5282 ddraw_surface4_GetUniquenessValue
,
5283 ddraw_surface4_ChangeUniquenessValue
,
5286 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl
=
5289 ddraw_surface3_QueryInterface
,
5290 ddraw_surface3_AddRef
,
5291 ddraw_surface3_Release
,
5292 /* IDirectDrawSurface */
5293 ddraw_surface3_AddAttachedSurface
,
5294 ddraw_surface3_AddOverlayDirtyRect
,
5296 ddraw_surface3_BltBatch
,
5297 ddraw_surface3_BltFast
,
5298 ddraw_surface3_DeleteAttachedSurface
,
5299 ddraw_surface3_EnumAttachedSurfaces
,
5300 ddraw_surface3_EnumOverlayZOrders
,
5301 ddraw_surface3_Flip
,
5302 ddraw_surface3_GetAttachedSurface
,
5303 ddraw_surface3_GetBltStatus
,
5304 ddraw_surface3_GetCaps
,
5305 ddraw_surface3_GetClipper
,
5306 ddraw_surface3_GetColorKey
,
5307 ddraw_surface3_GetDC
,
5308 ddraw_surface3_GetFlipStatus
,
5309 ddraw_surface3_GetOverlayPosition
,
5310 ddraw_surface3_GetPalette
,
5311 ddraw_surface3_GetPixelFormat
,
5312 ddraw_surface3_GetSurfaceDesc
,
5313 ddraw_surface3_Initialize
,
5314 ddraw_surface3_IsLost
,
5315 ddraw_surface3_Lock
,
5316 ddraw_surface3_ReleaseDC
,
5317 ddraw_surface3_Restore
,
5318 ddraw_surface3_SetClipper
,
5319 ddraw_surface3_SetColorKey
,
5320 ddraw_surface3_SetOverlayPosition
,
5321 ddraw_surface3_SetPalette
,
5322 ddraw_surface3_Unlock
,
5323 ddraw_surface3_UpdateOverlay
,
5324 ddraw_surface3_UpdateOverlayDisplay
,
5325 ddraw_surface3_UpdateOverlayZOrder
,
5326 /* IDirectDrawSurface2 */
5327 ddraw_surface3_GetDDInterface
,
5328 ddraw_surface3_PageLock
,
5329 ddraw_surface3_PageUnlock
,
5330 /* IDirectDrawSurface3 */
5331 ddraw_surface3_SetSurfaceDesc
,
5334 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl
=
5337 ddraw_surface2_QueryInterface
,
5338 ddraw_surface2_AddRef
,
5339 ddraw_surface2_Release
,
5340 /* IDirectDrawSurface */
5341 ddraw_surface2_AddAttachedSurface
,
5342 ddraw_surface2_AddOverlayDirtyRect
,
5344 ddraw_surface2_BltBatch
,
5345 ddraw_surface2_BltFast
,
5346 ddraw_surface2_DeleteAttachedSurface
,
5347 ddraw_surface2_EnumAttachedSurfaces
,
5348 ddraw_surface2_EnumOverlayZOrders
,
5349 ddraw_surface2_Flip
,
5350 ddraw_surface2_GetAttachedSurface
,
5351 ddraw_surface2_GetBltStatus
,
5352 ddraw_surface2_GetCaps
,
5353 ddraw_surface2_GetClipper
,
5354 ddraw_surface2_GetColorKey
,
5355 ddraw_surface2_GetDC
,
5356 ddraw_surface2_GetFlipStatus
,
5357 ddraw_surface2_GetOverlayPosition
,
5358 ddraw_surface2_GetPalette
,
5359 ddraw_surface2_GetPixelFormat
,
5360 ddraw_surface2_GetSurfaceDesc
,
5361 ddraw_surface2_Initialize
,
5362 ddraw_surface2_IsLost
,
5363 ddraw_surface2_Lock
,
5364 ddraw_surface2_ReleaseDC
,
5365 ddraw_surface2_Restore
,
5366 ddraw_surface2_SetClipper
,
5367 ddraw_surface2_SetColorKey
,
5368 ddraw_surface2_SetOverlayPosition
,
5369 ddraw_surface2_SetPalette
,
5370 ddraw_surface2_Unlock
,
5371 ddraw_surface2_UpdateOverlay
,
5372 ddraw_surface2_UpdateOverlayDisplay
,
5373 ddraw_surface2_UpdateOverlayZOrder
,
5374 /* IDirectDrawSurface2 */
5375 ddraw_surface2_GetDDInterface
,
5376 ddraw_surface2_PageLock
,
5377 ddraw_surface2_PageUnlock
,
5380 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl
=
5383 ddraw_surface1_QueryInterface
,
5384 ddraw_surface1_AddRef
,
5385 ddraw_surface1_Release
,
5386 /* IDirectDrawSurface */
5387 ddraw_surface1_AddAttachedSurface
,
5388 ddraw_surface1_AddOverlayDirtyRect
,
5390 ddraw_surface1_BltBatch
,
5391 ddraw_surface1_BltFast
,
5392 ddraw_surface1_DeleteAttachedSurface
,
5393 ddraw_surface1_EnumAttachedSurfaces
,
5394 ddraw_surface1_EnumOverlayZOrders
,
5395 ddraw_surface1_Flip
,
5396 ddraw_surface1_GetAttachedSurface
,
5397 ddraw_surface1_GetBltStatus
,
5398 ddraw_surface1_GetCaps
,
5399 ddraw_surface1_GetClipper
,
5400 ddraw_surface1_GetColorKey
,
5401 ddraw_surface1_GetDC
,
5402 ddraw_surface1_GetFlipStatus
,
5403 ddraw_surface1_GetOverlayPosition
,
5404 ddraw_surface1_GetPalette
,
5405 ddraw_surface1_GetPixelFormat
,
5406 ddraw_surface1_GetSurfaceDesc
,
5407 ddraw_surface1_Initialize
,
5408 ddraw_surface1_IsLost
,
5409 ddraw_surface1_Lock
,
5410 ddraw_surface1_ReleaseDC
,
5411 ddraw_surface1_Restore
,
5412 ddraw_surface1_SetClipper
,
5413 ddraw_surface1_SetColorKey
,
5414 ddraw_surface1_SetOverlayPosition
,
5415 ddraw_surface1_SetPalette
,
5416 ddraw_surface1_Unlock
,
5417 ddraw_surface1_UpdateOverlay
,
5418 ddraw_surface1_UpdateOverlayDisplay
,
5419 ddraw_surface1_UpdateOverlayZOrder
,
5422 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl
=
5424 ddraw_gamma_control_QueryInterface
,
5425 ddraw_gamma_control_AddRef
,
5426 ddraw_gamma_control_Release
,
5427 ddraw_gamma_control_GetGammaRamp
,
5428 ddraw_gamma_control_SetGammaRamp
,
5431 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl
=
5433 d3d_texture2_QueryInterface
,
5434 d3d_texture2_AddRef
,
5435 d3d_texture2_Release
,
5436 d3d_texture2_GetHandle
,
5437 d3d_texture2_PaletteChanged
,
5441 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl
=
5443 d3d_texture1_QueryInterface
,
5444 d3d_texture1_AddRef
,
5445 d3d_texture1_Release
,
5446 d3d_texture1_Initialize
,
5447 d3d_texture1_GetHandle
,
5448 d3d_texture1_PaletteChanged
,
5450 d3d_texture1_Unload
,
5453 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5454 * IDirectDrawSurface interface to ddraw methods. */
5455 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7
*iface
)
5457 if (!iface
) return NULL
;
5458 if (iface
->lpVtbl
!= &ddraw_surface7_vtbl
)
5460 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface7
, (void **)&iface
);
5463 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface
);
5466 IUnknown_Release(iface
);
5468 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface7_iface
);
5471 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4
*iface
)
5473 if (!iface
) return NULL
;
5474 if (iface
->lpVtbl
!= &ddraw_surface4_vtbl
)
5476 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface4
, (void **)&iface
);
5479 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface
);
5482 IUnknown_Release(iface
);
5484 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface4_iface
);
5487 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3
*iface
)
5489 if (!iface
) return NULL
;
5490 if (iface
->lpVtbl
!= &ddraw_surface3_vtbl
)
5492 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface3
, (void **)&iface
);
5495 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface
);
5498 IUnknown_Release(iface
);
5500 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface3_iface
);
5503 static struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2
*iface
)
5505 if (!iface
) return NULL
;
5506 if (iface
->lpVtbl
!= &ddraw_surface2_vtbl
)
5508 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface2
, (void **)&iface
);
5511 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface
);
5514 IUnknown_Release(iface
);
5516 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface2_iface
);
5519 struct ddraw_surface
*unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface
*iface
)
5521 if (!iface
) return NULL
;
5522 if (iface
->lpVtbl
!= &ddraw_surface1_vtbl
)
5524 HRESULT hr
= IUnknown_QueryInterface(iface
, &IID_IDirectDrawSurface
, (void **)&iface
);
5527 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface
);
5530 IUnknown_Release(iface
);
5532 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirectDrawSurface_iface
);
5535 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2
*iface
)
5537 if (!iface
) return NULL
;
5538 assert(iface
->lpVtbl
== &d3d_texture2_vtbl
);
5539 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture2_iface
);
5542 struct ddraw_surface
*unsafe_impl_from_IDirect3DTexture(IDirect3DTexture
*iface
)
5544 if (!iface
) return NULL
;
5545 assert(iface
->lpVtbl
== &d3d_texture1_vtbl
);
5546 return CONTAINING_RECORD(iface
, struct ddraw_surface
, IDirect3DTexture_iface
);
5549 static void STDMETHODCALLTYPE
ddraw_surface_wined3d_object_destroyed(void *parent
)
5551 struct ddraw_surface
*surface
= parent
;
5553 TRACE("surface %p.\n", surface
);
5555 /* Check for attached surfaces and detach them. */
5556 if (surface
->first_attached
!= surface
)
5558 /* Well, this shouldn't happen: The surface being attached is
5559 * referenced in AddAttachedSurface(), so it shouldn't be released
5560 * until DeleteAttachedSurface() is called, because the refcount is
5561 * held. It looks like the application released it often enough to
5563 WARN("Surface is still attached to surface %p.\n", surface
->first_attached
);
5565 /* The refcount will drop to -1 here */
5566 if (FAILED(ddraw_surface_delete_attached_surface(surface
->first_attached
, surface
, surface
->attached_iface
)))
5567 ERR("DeleteAttachedSurface failed.\n");
5570 while (surface
->next_attached
)
5571 if (FAILED(ddraw_surface_delete_attached_surface(surface
,
5572 surface
->next_attached
, surface
->next_attached
->attached_iface
)))
5573 ERR("DeleteAttachedSurface failed.\n");
5575 /* Having a texture handle set implies that the device still exists. */
5576 if (surface
->Handle
)
5577 ddraw_free_handle(&surface
->ddraw
->d3ddevice
->handle_table
, surface
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
5579 /* Reduce the ddraw surface count. */
5580 list_remove(&surface
->surface_list_entry
);
5582 if (surface
== surface
->ddraw
->primary
)
5583 surface
->ddraw
->primary
= NULL
;
5585 HeapFree(GetProcessHeap(), 0, surface
);
5588 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops
=
5590 ddraw_surface_wined3d_object_destroyed
,
5593 static void STDMETHODCALLTYPE
ddraw_texture_wined3d_object_destroyed(void *parent
)
5595 struct ddraw_surface
*surface
= parent
;
5597 TRACE("surface %p.\n", surface
);
5599 ddraw_surface_cleanup(surface
);
5602 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops
=
5604 ddraw_texture_wined3d_object_destroyed
,
5607 HRESULT
ddraw_surface_create_texture(struct ddraw_surface
*surface
)
5609 const DDSURFACEDESC2
*desc
= &surface
->surface_desc
;
5610 enum wined3d_format_id format
;
5611 enum wined3d_pool pool
;
5614 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
5615 levels
= desc
->u2
.dwMipMapCount
;
5619 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3D_POOL_SYSTEM_MEM.
5620 * Should I forward the MANAGED cap to the managed pool? */
5621 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5622 pool
= WINED3D_POOL_SYSTEM_MEM
;
5624 pool
= WINED3D_POOL_DEFAULT
;
5626 format
= PixelFormat_DD2WineD3D(&surface
->surface_desc
.u4
.ddpfPixelFormat
);
5627 if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5628 return wined3d_texture_create_cube(surface
->ddraw
->wined3d_device
, desc
->dwWidth
,
5629 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5631 return wined3d_texture_create_2d(surface
->ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
,
5632 levels
, 0, format
, pool
, surface
, &ddraw_texture_wined3d_parent_ops
, &surface
->wined3d_texture
);
5635 HRESULT
ddraw_surface_init(struct ddraw_surface
*surface
, struct ddraw
*ddraw
,
5636 DDSURFACEDESC2
*desc
, UINT mip_level
, UINT version
)
5638 enum wined3d_pool pool
= WINED3D_POOL_DEFAULT
;
5639 DWORD flags
= WINED3D_SURFACE_MAPPABLE
;
5640 enum wined3d_format_id format
;
5644 if (!(desc
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
5645 && !((desc
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
5646 && (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)))
5648 /* Tests show surfaces without memory flags get these flags added
5649 * right after creation. */
5650 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
5653 /* Some applications assume surfaces will always be mapped at the same
5654 * address. Some of those also assume that this address is valid even when
5655 * the surface isn't mapped, and that updates done this way will be
5656 * visible on the screen. The game Nox is such an application,
5657 * Commandos: Behind Enemy Lines is another. */
5658 flags
|= WINED3D_SURFACE_PIN_SYSMEM
;
5660 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
5662 usage
|= WINED3DUSAGE_RENDERTARGET
;
5663 desc
->ddsCaps
.dwCaps
|= DDSCAPS_VISIBLE
;
5666 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && !(desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
5668 usage
|= WINED3DUSAGE_RENDERTARGET
;
5671 if (desc
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
5673 usage
|= WINED3DUSAGE_OVERLAY
;
5676 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
5677 usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
5679 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_OWNDC
)
5680 usage
|= WINED3DUSAGE_OWNDC
;
5682 if (desc
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
5684 pool
= WINED3D_POOL_SYSTEM_MEM
;
5686 else if (desc
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
5688 pool
= WINED3D_POOL_MANAGED
;
5689 /* Managed textures have the system memory flag set. */
5690 desc
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
5692 else if (desc
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5694 /* Videomemory adds localvidmem. This is mutually exclusive with
5695 * systemmemory and texturemanage. */
5696 desc
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
5699 format
= PixelFormat_DD2WineD3D(&desc
->u4
.ddpfPixelFormat
);
5700 if (format
== WINED3DFMT_UNKNOWN
)
5702 WARN("Unsupported / unknown pixelformat.\n");
5703 return DDERR_INVALIDPIXELFORMAT
;
5706 surface
->IDirectDrawSurface7_iface
.lpVtbl
= &ddraw_surface7_vtbl
;
5707 surface
->IDirectDrawSurface4_iface
.lpVtbl
= &ddraw_surface4_vtbl
;
5708 surface
->IDirectDrawSurface3_iface
.lpVtbl
= &ddraw_surface3_vtbl
;
5709 surface
->IDirectDrawSurface2_iface
.lpVtbl
= &ddraw_surface2_vtbl
;
5710 surface
->IDirectDrawSurface_iface
.lpVtbl
= &ddraw_surface1_vtbl
;
5711 surface
->IDirectDrawGammaControl_iface
.lpVtbl
= &ddraw_gamma_control_vtbl
;
5712 surface
->IDirect3DTexture2_iface
.lpVtbl
= &d3d_texture2_vtbl
;
5713 surface
->IDirect3DTexture_iface
.lpVtbl
= &d3d_texture1_vtbl
;
5714 surface
->iface_count
= 1;
5715 surface
->version
= version
;
5716 surface
->ddraw
= ddraw
;
5722 else if (version
== 4)
5731 copy_to_surfacedesc2(&surface
->surface_desc
, desc
);
5733 surface
->first_attached
= surface
;
5735 hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->dwWidth
, desc
->dwHeight
, format
, mip_level
,
5736 usage
, pool
, WINED3D_MULTISAMPLE_NONE
, 0, DefaultSurfaceType
, flags
,
5737 surface
, &ddraw_surface_wined3d_parent_ops
, &surface
->wined3d_surface
);
5740 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
5744 /* Anno 1602 stores the pitch right after surface creation, so make sure
5745 * it's there. TODO: Test other fourcc formats. */
5746 if (format
== WINED3DFMT_DXT1
|| format
== WINED3DFMT_DXT2
|| format
== WINED3DFMT_DXT3
5747 || format
== WINED3DFMT_DXT4
|| format
== WINED3DFMT_DXT5
)
5749 surface
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
5750 if (format
== WINED3DFMT_DXT1
)
5752 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
) / 2;
5756 surface
->surface_desc
.u1
.dwLinearSize
= max(4, desc
->dwWidth
) * max(4, desc
->dwHeight
);
5761 surface
->surface_desc
.dwFlags
|= DDSD_PITCH
;
5762 surface
->surface_desc
.u1
.lPitch
= wined3d_surface_get_pitch(surface
->wined3d_surface
);
5765 if (desc
->dwFlags
& DDSD_CKDESTOVERLAY
)
5767 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTOVERLAY
,
5768 (struct wined3d_color_key
*)&desc
->u3
.ddckCKDestOverlay
);
5770 if (desc
->dwFlags
& DDSD_CKDESTBLT
)
5772 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_DESTBLT
,
5773 (struct wined3d_color_key
*)&desc
->ddckCKDestBlt
);
5775 if (desc
->dwFlags
& DDSD_CKSRCOVERLAY
)
5777 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCOVERLAY
,
5778 (struct wined3d_color_key
*)&desc
->ddckCKSrcOverlay
);
5780 if (desc
->dwFlags
& DDSD_CKSRCBLT
)
5782 wined3d_surface_set_color_key(surface
->wined3d_surface
, DDCKEY_SRCBLT
,
5783 (struct wined3d_color_key
*)&desc
->ddckCKSrcBlt
);
5785 if (desc
->dwFlags
& DDSD_LPSURFACE
)
5787 hr
= wined3d_surface_set_mem(surface
->wined3d_surface
, desc
->lpSurface
);
5790 ERR("Failed to set surface memory, hr %#x.\n", hr
);
5791 wined3d_surface_decref(surface
->wined3d_surface
);