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
8 * This file contains the (internal) driver registration functions,
9 * driver enumeration APIs and DirectDraw creation functions.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/port.h"
29 #include "ddraw_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
33 static inline IDirectDrawSurfaceImpl
*surface_from_gamma_control(IDirectDrawGammaControl
*iface
)
35 return (IDirectDrawSurfaceImpl
*)((char*)iface
36 - FIELD_OFFSET(IDirectDrawSurfaceImpl
, IDirectDrawGammaControl_vtbl
));
39 /*****************************************************************************
40 * IUnknown parts follow
41 *****************************************************************************/
43 /*****************************************************************************
44 * IDirectDrawSurface7::QueryInterface
46 * A normal QueryInterface implementation. For QueryInterface rules
47 * see ddraw.c, IDirectDraw7::QueryInterface. This method
48 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
49 * in all versions, the IDirectDrawGammaControl interface and it can
50 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
53 * riid: The interface id queried for
54 * obj: Address to write the pointer to
58 * E_NOINTERFACE if the requested interface wasn't found
60 *****************************************************************************/
61 static HRESULT WINAPI
ddraw_surface7_QueryInterface(IDirectDrawSurface7
*iface
, REFIID riid
, void **obj
)
63 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
65 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
69 return DDERR_INVALIDPARAMS
;
71 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),obj
);
72 if (IsEqualGUID(riid
, &IID_IUnknown
)
73 || IsEqualGUID(riid
, &IID_IDirectDrawSurface7
)
74 || IsEqualGUID(riid
, &IID_IDirectDrawSurface4
) )
76 IUnknown_AddRef(iface
);
78 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This
, *obj
);
81 else if( IsEqualGUID(riid
, &IID_IDirectDrawSurface3
)
82 || IsEqualGUID(riid
, &IID_IDirectDrawSurface2
)
83 || IsEqualGUID(riid
, &IID_IDirectDrawSurface
) )
85 IUnknown_AddRef(iface
);
86 *obj
= &This
->IDirectDrawSurface3_vtbl
;
87 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This
, *obj
);
90 else if( IsEqualGUID(riid
, &IID_IDirectDrawGammaControl
) )
92 IUnknown_AddRef(iface
);
93 *obj
= &This
->IDirectDrawGammaControl_vtbl
;
94 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This
, *obj
);
97 else if( IsEqualGUID(riid
, &IID_D3DDEVICE_WineD3D
) ||
98 IsEqualGUID(riid
, &IID_IDirect3DHALDevice
)||
99 IsEqualGUID(riid
, &IID_IDirect3DRGBDevice
) )
101 IDirect3DDevice7
*d3d
;
103 /* Call into IDirect3D7 for creation */
104 IDirect3D7_CreateDevice((IDirect3D7
*)&This
->ddraw
->IDirect3D7_vtbl
, riid
, (IDirectDrawSurface7
*)This
, &d3d
);
108 *obj
= (IDirect3DDevice
*)&((IDirect3DDeviceImpl
*)d3d
)->IDirect3DDevice_vtbl
;
109 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This
, *obj
);
113 WARN("Unable to create a IDirect3DDevice instance, returning E_NOINTERFACE\n");
114 return E_NOINTERFACE
;
116 else if (IsEqualGUID( &IID_IDirect3DTexture
, riid
) ||
117 IsEqualGUID( &IID_IDirect3DTexture2
, riid
))
119 if (IsEqualGUID( &IID_IDirect3DTexture
, riid
))
121 *obj
= &This
->IDirect3DTexture_vtbl
;
122 TRACE(" returning Direct3DTexture interface at %p.\n", *obj
);
126 *obj
= &This
->IDirect3DTexture2_vtbl
;
127 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj
);
129 IUnknown_AddRef( (IUnknown
*) *obj
);
133 ERR("No interface\n");
134 return E_NOINTERFACE
;
137 static HRESULT WINAPI
ddraw_surface3_QueryInterface(IDirectDrawSurface3
*iface
, REFIID riid
, void **object
)
139 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
141 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_surface3(iface
), riid
, object
);
144 static HRESULT WINAPI
ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl
*iface
, REFIID riid
, void **object
)
146 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
148 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_gamma_control(iface
), riid
, object
);
151 static HRESULT WINAPI
d3d_texture2_QueryInterface(IDirect3DTexture2
*iface
, REFIID riid
, void **object
)
153 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
155 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_texture2(iface
), riid
, object
);
158 static HRESULT WINAPI
d3d_texture1_QueryInterface(IDirect3DTexture
*iface
, REFIID riid
, void **object
)
160 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
162 return ddraw_surface7_QueryInterface((IDirectDrawSurface7
*)surface_from_texture1(iface
), riid
, object
);
165 /*****************************************************************************
166 * IDirectDrawSurface7::AddRef
168 * A normal addref implementation
173 *****************************************************************************/
174 static ULONG WINAPI
ddraw_surface7_AddRef(IDirectDrawSurface7
*iface
)
176 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
177 ULONG refCount
= InterlockedIncrement(&This
->ref
);
179 if (refCount
== 1 && This
->WineD3DSurface
)
181 EnterCriticalSection(&ddraw_cs
);
182 IWineD3DSurface_AddRef(This
->WineD3DSurface
);
183 LeaveCriticalSection(&ddraw_cs
);
186 TRACE("(%p) : AddRef increasing from %d\n", This
, refCount
- 1);
190 static ULONG WINAPI
ddraw_surface3_AddRef(IDirectDrawSurface3
*iface
)
192 TRACE("iface %p.\n", iface
);
194 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_surface3(iface
));
197 static ULONG WINAPI
ddraw_gamma_control_AddRef(IDirectDrawGammaControl
*iface
)
199 TRACE("iface %p.\n", iface
);
201 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_gamma_control(iface
));
204 static ULONG WINAPI
d3d_texture2_AddRef(IDirect3DTexture2
*iface
)
206 TRACE("iface %p.\n", iface
);
208 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_texture2(iface
));
211 static ULONG WINAPI
d3d_texture1_AddRef(IDirect3DTexture
*iface
)
213 TRACE("iface %p.\n", iface
);
215 return ddraw_surface7_AddRef((IDirectDrawSurface7
*)surface_from_texture1(iface
));
218 /*****************************************************************************
219 * ddraw_surface_destroy
221 * A helper function for IDirectDrawSurface7::Release
223 * Frees the surface, regardless of its refcount.
224 * See IDirectDrawSurface7::Release for more information
227 * This: Surface to free
229 *****************************************************************************/
230 void ddraw_surface_destroy(IDirectDrawSurfaceImpl
*This
)
232 TRACE("(%p)\n", This
);
234 /* Check the refcount and give a warning */
237 /* This can happen when a complex surface is destroyed,
238 * because the 2nd surface was addref()ed when the app
239 * called GetAttachedSurface
241 WARN("(%p): Destroying surface with refount %d\n", This
, This
->ref
);
244 /* Check for attached surfaces and detach them */
245 if(This
->first_attached
!= This
)
247 /* Well, this shouldn't happen: The surface being attached is addref()ed
248 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
249 * is called, because the refcount is held. It looks like the app released()
250 * it often enough to force this
252 IDirectDrawSurface7
*root
= (IDirectDrawSurface7
*)This
->first_attached
;
253 IDirectDrawSurface7
*detach
= (IDirectDrawSurface7
*)This
;
255 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This
, This
->first_attached
);
257 /* The refcount will drop to -1 here */
258 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
260 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
264 while(This
->next_attached
!= NULL
)
266 IDirectDrawSurface7
*root
= (IDirectDrawSurface7
*)This
;
267 IDirectDrawSurface7
*detach
= (IDirectDrawSurface7
*)This
->next_attached
;
269 if(IDirectDrawSurface7_DeleteAttachedSurface(root
, 0, detach
) != DD_OK
)
271 ERR("(%p) DeleteAttachedSurface failed!\n", This
);
276 /* Now destroy the surface. Wait: It could have been released if we are a texture */
277 if(This
->WineD3DSurface
)
278 IWineD3DSurface_Release(This
->WineD3DSurface
);
280 /* Having a texture handle set implies that the device still exists */
283 ddraw_free_handle(&This
->ddraw
->d3ddevice
->handle_table
, This
->Handle
- 1, DDRAW_HANDLE_SURFACE
);
286 /* Reduce the ddraw surface count */
287 InterlockedDecrement(&This
->ddraw
->surfaces
);
288 list_remove(&This
->surface_list_entry
);
290 HeapFree(GetProcessHeap(), 0, This
);
293 /*****************************************************************************
294 * IDirectDrawSurface7::Release
296 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
297 * surface is destroyed.
299 * Destroying the surface is a bit tricky. For the connection between
300 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
301 * It has a nice graph explaining the connection.
303 * What happens here is basically this:
304 * When a surface is destroyed, its WineD3DSurface is released,
305 * and the refcount of the DirectDraw interface is reduced by 1. If it has
306 * complex surfaces attached to it, then these surfaces are destroyed too,
307 * regardless of their refcount. If any surface being destroyed has another
308 * surface attached to it (with a "soft" attachment, not complex), then
309 * this surface is detached with DeleteAttachedSurface.
311 * When the surface is a texture, the WineD3DTexture is released.
312 * If the surface is the Direct3D render target, then the D3D
313 * capabilities of the WineD3DDevice are uninitialized, which causes the
314 * swapchain to be released.
316 * When a complex sublevel falls to ref zero, then this is ignored.
321 *****************************************************************************/
322 static ULONG WINAPI
ddraw_surface7_Release(IDirectDrawSurface7
*iface
)
324 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
326 TRACE("(%p) : Releasing from %d\n", This
, This
->ref
);
327 ref
= InterlockedDecrement(&This
->ref
);
332 IDirectDrawSurfaceImpl
*surf
;
333 IDirectDrawImpl
*ddraw
;
334 IUnknown
*ifaceToRelease
= This
->ifaceToRelease
;
337 /* Complex attached surfaces are destroyed implicitly when the root is released */
338 EnterCriticalSection(&ddraw_cs
);
339 if(!This
->is_complex_root
)
341 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This
);
342 LeaveCriticalSection(&ddraw_cs
);
347 /* If it's a texture, destroy the WineD3DTexture.
348 * WineD3D will destroy the IParent interfaces
349 * of the sublevels, which destroys the WineD3DSurfaces.
350 * Set the surfaces to NULL to avoid destroying them again later
352 if(This
->wineD3DTexture
)
354 IWineD3DBaseTexture_Release(This
->wineD3DTexture
);
356 /* If it's the RenderTarget, destroy the d3ddevice */
357 else if(This
->wineD3DSwapChain
)
359 if((ddraw
->d3d_initialized
) && (This
== ddraw
->d3d_target
)) {
360 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This
);
362 /* Unset any index buffer, just to be sure */
363 IWineD3DDevice_SetIndexBuffer(ddraw
->wineD3DDevice
, NULL
, WINED3DFMT_UNKNOWN
);
364 IWineD3DDevice_SetDepthStencilSurface(ddraw
->wineD3DDevice
, NULL
);
365 IWineD3DDevice_SetVertexDeclaration(ddraw
->wineD3DDevice
, NULL
);
366 for(i
= 0; i
< ddraw
->numConvertedDecls
; i
++)
368 IWineD3DVertexDeclaration_Release(ddraw
->decls
[i
].decl
);
370 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
371 ddraw
->numConvertedDecls
= 0;
373 if (FAILED(IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
)))
376 ERR("(%p) Failed to uninit 3D\n", This
);
380 /* Free the d3d window if one was created */
381 if(ddraw
->d3d_window
!= 0 && ddraw
->d3d_window
!= ddraw
->dest_window
)
383 TRACE(" (%p) Destroying the hidden render window %p\n", This
, ddraw
->d3d_window
);
384 DestroyWindow(ddraw
->d3d_window
);
385 ddraw
->d3d_window
= 0;
387 /* Unset the pointers */
390 This
->wineD3DSwapChain
= NULL
; /* Uninit3D releases the swapchain */
391 ddraw
->d3d_initialized
= FALSE
;
392 ddraw
->d3d_target
= NULL
;
394 IWineD3DDevice_UninitGDI(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
395 This
->wineD3DSwapChain
= NULL
;
398 /* Reset to the default surface implementation type. This is needed if apps use
399 * non render target surfaces and expect blits to work after destroying the render
402 * TODO: Recreate existing offscreen surfaces
404 ddraw
->ImplType
= DefaultSurfaceType
;
406 /* Write a trace because D3D unloading was the reason for many
407 * crashes during development.
409 TRACE("(%p) D3D unloaded\n", This
);
412 /* The refcount test shows that the palette is detached when the surface is destroyed */
413 IDirectDrawSurface7_SetPalette((IDirectDrawSurface7
*)This
, NULL
);
415 /* Loop through all complex attached surfaces,
418 * Yet again, only the root can have more than one complexly attached surface, all the others
419 * have a total of one;
421 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
423 if(!This
->complex_array
[i
]) break;
425 surf
= This
->complex_array
[i
];
426 This
->complex_array
[i
] = NULL
;
429 IDirectDrawSurfaceImpl
*destroy
= surf
;
430 surf
= surf
->complex_array
[0]; /* Iterate through the "tree" */
431 ddraw_surface_destroy(destroy
); /* Destroy it */
435 /* Destroy the root surface. */
436 ddraw_surface_destroy(This
);
438 /* Reduce the ddraw refcount */
439 if(ifaceToRelease
) IUnknown_Release(ifaceToRelease
);
440 LeaveCriticalSection(&ddraw_cs
);
446 static ULONG WINAPI
ddraw_surface3_Release(IDirectDrawSurface3
*iface
)
448 TRACE("iface %p.\n", iface
);
450 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_surface3(iface
));
453 static ULONG WINAPI
ddraw_gamma_control_Release(IDirectDrawGammaControl
*iface
)
455 TRACE("iface %p.\n", iface
);
457 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_gamma_control(iface
));
460 static ULONG WINAPI
d3d_texture2_Release(IDirect3DTexture2
*iface
)
462 TRACE("iface %p.\n", iface
);
464 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_texture2(iface
));
467 static ULONG WINAPI
d3d_texture1_Release(IDirect3DTexture
*iface
)
469 TRACE("iface %p.\n", iface
);
471 return ddraw_surface7_Release((IDirectDrawSurface7
*)surface_from_texture1(iface
));
474 /*****************************************************************************
475 * IDirectDrawSurface7::GetAttachedSurface
477 * Returns an attached surface with the requested caps. Surface attachment
478 * and complex surfaces are not clearly described by the MSDN or sdk,
479 * so this method is tricky and likely to contain problems.
480 * This implementation searches the complex list first, then the
483 * The chains are searched from This down to the last surface in the chain,
484 * not from the first element in the chain. The first surface found is
485 * returned. The MSDN says that this method fails if more than one surface
486 * matches the caps, but it is not sure if that is right. The attachment
487 * structure may not even allow two matching surfaces.
489 * The found surface is AddRef-ed before it is returned.
492 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
493 * Surface: Address to store the found surface
497 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
498 * DDERR_NOTFOUND if no surface was found
500 *****************************************************************************/
501 static HRESULT WINAPI
ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7
*iface
,
502 DDSCAPS2
*Caps
, IDirectDrawSurface7
**Surface
)
504 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
505 IDirectDrawSurfaceImpl
*surf
;
509 TRACE("(%p)->(%p,%p)\n", This
, Caps
, Surface
);
510 EnterCriticalSection(&ddraw_cs
);
512 if(This
->version
< 7)
514 /* Earlier dx apps put garbage into these members, clear them */
515 our_caps
.dwCaps
= Caps
->dwCaps
;
516 our_caps
.dwCaps2
= 0;
517 our_caps
.dwCaps3
= 0;
518 our_caps
.dwCaps4
= 0;
525 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 */
527 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
529 surf
= This
->complex_array
[i
];
534 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
535 surf
->surface_desc
.ddsCaps
.dwCaps
,
536 surf
->surface_desc
.ddsCaps
.dwCaps2
,
537 surf
->surface_desc
.ddsCaps
.dwCaps3
,
538 surf
->surface_desc
.ddsCaps
.dwCaps4
);
541 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
542 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
544 /* MSDN: "This method fails if more than one surface is attached
545 * that matches the capabilities requested."
547 * Not sure how to test this.
550 TRACE("(%p): Returning surface %p\n", This
, surf
);
551 TRACE("(%p): mipmapcount=%d\n", This
, surf
->mipmap_level
);
552 *Surface
= (IDirectDrawSurface7
*)surf
;
553 ddraw_surface7_AddRef(*Surface
);
554 LeaveCriticalSection(&ddraw_cs
);
559 /* Next, look at the attachment chain */
562 while( (surf
= surf
->next_attached
) )
566 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf
,
567 surf
->surface_desc
.ddsCaps
.dwCaps
,
568 surf
->surface_desc
.ddsCaps
.dwCaps2
,
569 surf
->surface_desc
.ddsCaps
.dwCaps3
,
570 surf
->surface_desc
.ddsCaps
.dwCaps4
);
573 if (((surf
->surface_desc
.ddsCaps
.dwCaps
& our_caps
.dwCaps
) == our_caps
.dwCaps
) &&
574 ((surf
->surface_desc
.ddsCaps
.dwCaps2
& our_caps
.dwCaps2
) == our_caps
.dwCaps2
)) {
576 TRACE("(%p): Returning surface %p\n", This
, surf
);
577 *Surface
= (IDirectDrawSurface7
*)surf
;
578 ddraw_surface7_AddRef(*Surface
);
579 LeaveCriticalSection(&ddraw_cs
);
584 TRACE("(%p) Didn't find a valid surface\n", This
);
585 LeaveCriticalSection(&ddraw_cs
);
588 return DDERR_NOTFOUND
;
591 static HRESULT WINAPI
ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3
*iface
,
592 DDSCAPS
*caps
, IDirectDrawSurface3
**attachment
)
594 IDirectDrawSurface7
*attachment7
;
598 TRACE("iface %p, caps %p, attachment %p.\n", iface
, caps
, attachment
);
600 caps2
.dwCaps
= caps
->dwCaps
;
605 hr
= ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7
*)surface_from_surface3(iface
),
606 &caps2
, &attachment7
);
607 if (FAILED(hr
)) *attachment
= NULL
;
608 else *attachment
= attachment7
?
609 (IDirectDrawSurface3
*)&((IDirectDrawSurfaceImpl
*)attachment7
)->IDirectDrawSurface3_vtbl
: NULL
;
614 /*****************************************************************************
615 * IDirectDrawSurface7::Lock
617 * Locks the surface and returns a pointer to the surface's memory
620 * Rect: Rectangle to lock. If NULL, the whole surface is locked
621 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
622 * Flags: Locking flags, e.g Read only or write only
623 * h: An event handle that's not used and must be NULL
627 * DDERR_INVALIDPARAMS if DDSD is NULL
628 * For more details, see IWineD3DSurface::LockRect
630 *****************************************************************************/
631 static HRESULT WINAPI
ddraw_surface7_Lock(IDirectDrawSurface7
*iface
,
632 RECT
*Rect
, DDSURFACEDESC2
*DDSD
, DWORD Flags
, HANDLE h
)
634 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
635 WINED3DLOCKED_RECT LockedRect
;
637 TRACE("(%p)->(%p,%p,%x,%p)\n", This
, Rect
, DDSD
, Flags
, h
);
640 return DDERR_INVALIDPARAMS
;
642 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
643 EnterCriticalSection(&ddraw_cs
);
645 /* Should I check for the handle to be NULL?
647 * The DDLOCK flags and the D3DLOCK flags are equal
648 * for the supported values. The others are ignored by WineD3D
651 if(DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) &&
652 DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
654 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS
);
655 LeaveCriticalSection(&ddraw_cs
);
656 return DDERR_INVALIDPARAMS
;
659 /* Windows zeroes this if the rect is invalid */
666 || (Rect
->left
> Rect
->right
)
667 || (Rect
->top
> Rect
->bottom
)
668 || (Rect
->right
> This
->surface_desc
.dwWidth
)
669 || (Rect
->bottom
> This
->surface_desc
.dwHeight
))
671 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
672 LeaveCriticalSection(&ddraw_cs
);
673 return DDERR_INVALIDPARAMS
;
677 hr
= IWineD3DSurface_LockRect(This
->WineD3DSurface
,
683 LeaveCriticalSection(&ddraw_cs
);
686 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
687 * specific error. But since IWineD3DSurface::LockRect returns that error in this
688 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
689 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
690 * is much easier to do it in one place in ddraw
692 case WINED3DERR_INVALIDCALL
: return DDERR_SURFACEBUSY
;
697 /* Override the memory area. The pitch should be set already. Strangely windows
698 * does not set the LPSURFACE flag on locked surfaces !?!.
699 * DDSD->dwFlags |= DDSD_LPSURFACE;
701 This
->surface_desc
.lpSurface
= LockedRect
.pBits
;
702 DD_STRUCT_COPY_BYSIZE(DDSD
,&(This
->surface_desc
));
704 TRACE("locked surface returning description :\n");
705 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
707 LeaveCriticalSection(&ddraw_cs
);
711 static HRESULT WINAPI
ddraw_surface3_Lock(IDirectDrawSurface3
*iface
, RECT
*rect
,
712 DDSURFACEDESC
*surface_desc
, DWORD flags
, HANDLE h
)
714 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
715 iface
, wine_dbgstr_rect(rect
), surface_desc
, flags
, h
);
717 return ddraw_surface7_Lock((IDirectDrawSurface7
*)surface_from_surface3(iface
),
718 rect
, (DDSURFACEDESC2
*)surface_desc
, flags
, h
);
721 /*****************************************************************************
722 * IDirectDrawSurface7::Unlock
724 * Unlocks an locked surface
727 * Rect: Not used by this implementation
731 * For more details, see IWineD3DSurface::UnlockRect
733 *****************************************************************************/
734 static HRESULT WINAPI
ddraw_surface7_Unlock(IDirectDrawSurface7
*iface
, RECT
*pRect
)
736 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
738 TRACE("(%p)->(%p)\n", This
, pRect
);
740 EnterCriticalSection(&ddraw_cs
);
741 hr
= IWineD3DSurface_UnlockRect(This
->WineD3DSurface
);
744 This
->surface_desc
.lpSurface
= NULL
;
746 LeaveCriticalSection(&ddraw_cs
);
750 static HRESULT WINAPI
ddraw_surface3_Unlock(IDirectDrawSurface3
*iface
, void *data
)
752 TRACE("iface %p, data %p.\n", iface
, data
);
754 /* data might not be the LPRECT of later versions, so drop it. */
755 return ddraw_surface7_Unlock((IDirectDrawSurface7
*)surface_from_surface3(iface
), NULL
);
758 /*****************************************************************************
759 * IDirectDrawSurface7::Flip
761 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
762 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
763 * the flip target is passed to WineD3D, even if the app didn't specify one
766 * DestOverride: Specifies the surface that will become the new front
767 * buffer. If NULL, the current back buffer is used
768 * Flags: some DirectDraw flags, see include/ddraw.h
772 * DDERR_NOTFLIPPABLE if no flip target could be found
773 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
774 * For more details, see IWineD3DSurface::Flip
776 *****************************************************************************/
777 static HRESULT WINAPI
ddraw_surface7_Flip(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*DestOverride
, DWORD Flags
)
779 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
780 IDirectDrawSurfaceImpl
*Override
= (IDirectDrawSurfaceImpl
*)DestOverride
;
781 IDirectDrawSurface7
*Override7
;
783 TRACE("(%p)->(%p,%x)\n", This
, DestOverride
, Flags
);
785 /* Flip has to be called from a front buffer
786 * What about overlay surfaces, AFAIK they can flip too?
788 if( !(This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_OVERLAY
)) )
789 return DDERR_INVALIDOBJECT
; /* Unchecked */
791 EnterCriticalSection(&ddraw_cs
);
793 /* WineD3D doesn't keep track of attached surface, so find the target */
798 memset(&Caps
, 0, sizeof(Caps
));
799 Caps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
800 hr
= ddraw_surface7_GetAttachedSurface(iface
, &Caps
, &Override7
);
803 ERR("Can't find a flip target\n");
804 LeaveCriticalSection(&ddraw_cs
);
805 return DDERR_NOTFLIPPABLE
; /* Unchecked */
807 Override
= (IDirectDrawSurfaceImpl
*)Override7
;
809 /* For the GetAttachedSurface */
810 ddraw_surface7_Release(Override7
);
813 hr
= IWineD3DSurface_Flip(This
->WineD3DSurface
,
814 Override
->WineD3DSurface
,
816 LeaveCriticalSection(&ddraw_cs
);
820 static HRESULT WINAPI
ddraw_surface3_Flip(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*dst
, DWORD flags
)
822 TRACE("iface %p, dst %p, flags %#x.\n", iface
, dst
, flags
);
824 return ddraw_surface7_Flip((IDirectDrawSurface7
*)surface_from_surface3(iface
),
825 dst
? (IDirectDrawSurface7
*)surface_from_surface3(dst
) : NULL
, flags
);
828 /*****************************************************************************
829 * IDirectDrawSurface7::Blt
831 * Performs a blit on the surface
834 * DestRect: Destination rectangle, can be NULL
835 * SrcSurface: Source surface, can be NULL
836 * SrcRect: Source rectangle, can be NULL
838 * DDBltFx: Some extended blt parameters, connected to the flags
842 * See IWineD3DSurface::Blt for more details
844 *****************************************************************************/
845 static HRESULT WINAPI
ddraw_surface7_Blt(IDirectDrawSurface7
*iface
, RECT
*DestRect
,
846 IDirectDrawSurface7
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, DDBLTFX
*DDBltFx
)
848 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
849 IDirectDrawSurfaceImpl
*Src
= (IDirectDrawSurfaceImpl
*)SrcSurface
;
851 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This
, DestRect
, Src
, SrcRect
, Flags
, DDBltFx
);
853 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
854 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
856 if((Flags
& DDBLT_KEYSRCOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYSRC
)) {
857 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
858 return DDERR_INVALIDPARAMS
;
861 if((Flags
& DDBLT_KEYDESTOVERRIDE
) && (!DDBltFx
|| Flags
& DDBLT_KEYDEST
)) {
862 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
863 return DDERR_INVALIDPARAMS
;
866 /* Sizes can change, therefore hold the lock when testing the rectangles */
867 EnterCriticalSection(&ddraw_cs
);
870 if(DestRect
->top
>= DestRect
->bottom
|| DestRect
->left
>= DestRect
->right
||
871 DestRect
->right
> This
->surface_desc
.dwWidth
||
872 DestRect
->bottom
> This
->surface_desc
.dwHeight
)
874 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
875 LeaveCriticalSection(&ddraw_cs
);
876 return DDERR_INVALIDRECT
;
881 if(SrcRect
->top
>= SrcRect
->bottom
|| SrcRect
->left
>=SrcRect
->right
||
882 SrcRect
->right
> Src
->surface_desc
.dwWidth
||
883 SrcRect
->bottom
> Src
->surface_desc
.dwHeight
)
885 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
886 LeaveCriticalSection(&ddraw_cs
);
887 return DDERR_INVALIDRECT
;
891 if(Flags
& DDBLT_KEYSRC
&& (!Src
|| !(Src
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))) {
892 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
893 LeaveCriticalSection(&ddraw_cs
);
894 return DDERR_INVALIDPARAMS
;
897 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
898 * and replace the ddraw surfaces with the wined3d surfaces
899 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
901 hr
= IWineD3DSurface_Blt(This
->WineD3DSurface
,
903 Src
? Src
->WineD3DSurface
: NULL
,
906 (WINEDDBLTFX
*) DDBltFx
,
909 LeaveCriticalSection(&ddraw_cs
);
912 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
913 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
918 static HRESULT WINAPI
ddraw_surface3_Blt(IDirectDrawSurface3
*iface
, RECT
*dst_rect
,
919 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
, DDBLTFX
*fx
)
921 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %p, flags %#x, fx %p.\n",
922 iface
, wine_dbgstr_rect(dst_rect
), src_surface
, wine_dbgstr_rect(src_rect
), flags
, fx
);
924 return ddraw_surface7_Blt((IDirectDrawSurface7
*)surface_from_surface3(iface
), dst_rect
,
925 src_surface
? (IDirectDrawSurface7
*)surface_from_surface3(src_surface
) : NULL
, src_rect
, flags
, fx
);
928 /*****************************************************************************
929 * IDirectDrawSurface7::AddAttachedSurface
931 * Attaches a surface to another surface. How the surface attachments work
932 * is not totally understood yet, and this method is prone to problems.
933 * he surface that is attached is AddRef-ed.
935 * Tests with complex surfaces suggest that the surface attachments form a
936 * tree, but no method to test this has been found yet.
938 * The attachment list consists of a first surface (first_attached) and
939 * for each surface a pointer to the next attached surface (next_attached).
940 * For the first surface, and a surface that has no attachments
941 * first_attached points to the surface itself. A surface that has
942 * no successors in the chain has next_attached set to NULL.
944 * Newly attached surfaces are attached right after the root surface.
945 * If a surface is attached to a complex surface compound, it's attached to
946 * the surface that the app requested, not the complex root. See
947 * GetAttachedSurface for a description how surfaces are found.
949 * This is how the current implementation works, and it was coded by looking
950 * at the needs of the applications.
952 * So far only Z-Buffer attachments are tested, and they are activated in
953 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
954 * Back buffers should work in 2D mode, but they are not tested(They can be
955 * attached in older iface versions). Rendering to the front buffer and
956 * switching between that and double buffering is not yet implemented in
957 * WineD3D, so for 3D it might have unexpected results.
959 * ddraw_surface_attach_surface is the real thing,
960 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
961 * performs additional checks. Version 7 of this interface is much more restrictive
962 * than its predecessors.
965 * Attach: Surface to attach to iface
969 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
971 *****************************************************************************/
972 static HRESULT WINAPI
ddraw_surface_attach_surface(IDirectDrawSurfaceImpl
*This
, IDirectDrawSurfaceImpl
*Surf
)
974 TRACE("(%p)->(%p)\n", This
, Surf
);
977 return DDERR_CANNOTATTACHSURFACE
; /* unchecked */
979 EnterCriticalSection(&ddraw_cs
);
981 /* Check if the surface is already attached somewhere */
982 if( (Surf
->next_attached
!= NULL
) ||
983 (Surf
->first_attached
!= Surf
) )
985 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
986 * What happens if one surface is attached to 2 different surfaces?
988 FIXME("(%p) The Surface %p is already attached somewhere else: next_attached = %p, first_attached = %p, can't handle by now\n", This
, Surf
, Surf
->next_attached
, Surf
->first_attached
);
989 LeaveCriticalSection(&ddraw_cs
);
990 return DDERR_SURFACEALREADYATTACHED
;
993 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
994 Surf
->next_attached
= This
->next_attached
;
995 Surf
->first_attached
= This
->first_attached
;
996 This
->next_attached
= Surf
;
998 /* Check if the WineD3D depth stencil needs updating */
999 if(This
->ddraw
->d3ddevice
)
1001 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1004 ddraw_surface7_AddRef((IDirectDrawSurface7
*)Surf
);
1005 LeaveCriticalSection(&ddraw_cs
);
1009 static HRESULT WINAPI
ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7
*iface
, IDirectDrawSurface7
*Attach
)
1011 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1012 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Attach
;
1014 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1015 if(!(Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
1018 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1019 Surf
->surface_desc
.ddsCaps
.dwCaps
);
1020 return DDERR_CANNOTATTACHSURFACE
;
1023 return ddraw_surface_attach_surface(This
, Surf
);
1026 static HRESULT WINAPI
ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3
*iface
, IDirectDrawSurface3
*attachment
)
1028 IDirectDrawSurfaceImpl
*surface
= surface_from_surface3(iface
);
1029 IDirectDrawSurfaceImpl
*attach_impl
= surface_from_surface3(attachment
);
1031 TRACE("iface %p, attachment %p.\n", iface
, attachment
);
1033 /* Tests suggest that
1034 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1035 * -> offscreen plain surfaces can be attached to primaries
1036 * -> primaries can be attached to offscreen plain surfaces
1037 * -> z buffers can be attached to primaries */
1038 if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
)
1039 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_OFFSCREENPLAIN
))
1041 /* Sizes have to match */
1042 if (attach_impl
->surface_desc
.dwWidth
!= surface
->surface_desc
.dwWidth
1043 || attach_impl
->surface_desc
.dwHeight
!= surface
->surface_desc
.dwHeight
)
1045 WARN("Surface sizes do not match.\n");
1046 return DDERR_CANNOTATTACHSURFACE
;
1050 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
)
1051 && attach_impl
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_ZBUFFER
))
1057 WARN("Invalid attachment combination.\n");
1058 return DDERR_CANNOTATTACHSURFACE
;
1061 return ddraw_surface_attach_surface(surface
, attach_impl
);
1064 /*****************************************************************************
1065 * IDirectDrawSurface7::DeleteAttachedSurface
1067 * Removes a surface from the attachment chain. The surface's refcount
1068 * is decreased by one after it has been removed
1071 * Flags: Some flags, not used by this implementation
1072 * Attach: Surface to detach
1076 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1078 *****************************************************************************/
1079 static HRESULT WINAPI
ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7
*iface
,
1080 DWORD Flags
, IDirectDrawSurface7
*Attach
)
1082 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1083 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Attach
;
1084 IDirectDrawSurfaceImpl
*Prev
= This
;
1085 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, Surf
);
1087 EnterCriticalSection(&ddraw_cs
);
1088 if (!Surf
|| (Surf
->first_attached
!= This
) || (Surf
== This
) )
1090 LeaveCriticalSection(&ddraw_cs
);
1091 return DDERR_CANNOTDETACHSURFACE
;
1094 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1095 if (This
->surface_desc
.ddsCaps
.dwCaps
&
1096 Surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
1098 Surf
->surface_desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
1099 /* FIXME: we should probably also subtract from dwMipMapCount of this
1100 * and all parent surfaces */
1103 /* Find the predecessor of the detached surface */
1106 if(Prev
->next_attached
== Surf
) break;
1107 Prev
= Prev
->next_attached
;
1110 /* There must be a surface, otherwise there's a bug */
1111 assert(Prev
!= NULL
);
1113 /* Unchain the surface */
1114 Prev
->next_attached
= Surf
->next_attached
;
1115 Surf
->next_attached
= NULL
;
1116 Surf
->first_attached
= Surf
;
1118 /* Check if the WineD3D depth stencil needs updating */
1119 if(This
->ddraw
->d3ddevice
)
1121 IDirect3DDeviceImpl_UpdateDepthStencil(This
->ddraw
->d3ddevice
);
1124 ddraw_surface7_Release(Attach
);
1125 LeaveCriticalSection(&ddraw_cs
);
1129 static HRESULT WINAPI
ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3
*iface
,
1130 DWORD flags
, IDirectDrawSurface3
*attachment
)
1132 TRACE("iface %p, flags %#x, attachment %p.\n", iface
, flags
, attachment
);
1134 return ddraw_surface7_DeleteAttachedSurface((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
,
1135 attachment
? (IDirectDrawSurface7
*)surface_from_surface3(attachment
) : NULL
);
1138 /*****************************************************************************
1139 * IDirectDrawSurface7::AddOverlayDirtyRect
1141 * "This method is not currently implemented"
1149 *****************************************************************************/
1150 static HRESULT WINAPI
ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7
*iface
, RECT
*Rect
)
1152 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1153 TRACE("(%p)->(%p)\n",This
,Rect
);
1155 /* MSDN says it's not implemented. I could forward it to WineD3D,
1156 * then we'd implement it, but I don't think that's a good idea
1157 * (Stefan Dösinger)
1160 return IWineD3DSurface_AddOverlayDirtyRect(This
->WineD3DSurface
, pRect
);
1162 return DDERR_UNSUPPORTED
; /* unchecked */
1165 static HRESULT WINAPI
ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3
*iface
, RECT
*rect
)
1167 TRACE("iface %p, rect %s.\n", iface
, wine_dbgstr_rect(rect
));
1169 return ddraw_surface7_AddOverlayDirtyRect((IDirectDrawSurface7
*)surface_from_surface3(iface
), rect
);
1172 /*****************************************************************************
1173 * IDirectDrawSurface7::GetDC
1175 * Returns a GDI device context for the surface
1178 * hdc: Address of a HDC variable to store the dc to
1182 * DDERR_INVALIDPARAMS if hdc is NULL
1183 * For details, see IWineD3DSurface::GetDC
1185 *****************************************************************************/
1186 static HRESULT WINAPI
ddraw_surface7_GetDC(IDirectDrawSurface7
*iface
, HDC
*hdc
)
1188 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1190 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1193 return DDERR_INVALIDPARAMS
;
1195 EnterCriticalSection(&ddraw_cs
);
1196 hr
= IWineD3DSurface_GetDC(This
->WineD3DSurface
,
1198 LeaveCriticalSection(&ddraw_cs
);
1201 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1204 case WINED3DERR_INVALIDCALL
:
1205 if(hdc
) *hdc
= NULL
;
1206 return DDERR_INVALIDPARAMS
;
1212 static HRESULT WINAPI
ddraw_surface3_GetDC(IDirectDrawSurface3
*iface
, HDC
*dc
)
1214 TRACE("iface %p, dc %p.\n", iface
, dc
);
1216 return ddraw_surface7_GetDC((IDirectDrawSurface7
*)surface_from_surface3(iface
), dc
);
1219 /*****************************************************************************
1220 * IDirectDrawSurface7::ReleaseDC
1222 * Releases the DC that was constructed with GetDC
1225 * hdc: HDC to release
1229 * For more details, see IWineD3DSurface::ReleaseDC
1231 *****************************************************************************/
1232 static HRESULT WINAPI
ddraw_surface7_ReleaseDC(IDirectDrawSurface7
*iface
, HDC hdc
)
1234 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1236 TRACE("(%p)->(%p): Relay\n", This
, hdc
);
1238 EnterCriticalSection(&ddraw_cs
);
1239 hr
= IWineD3DSurface_ReleaseDC(This
->WineD3DSurface
, hdc
);
1240 LeaveCriticalSection(&ddraw_cs
);
1244 static HRESULT WINAPI
ddraw_surface3_ReleaseDC(IDirectDrawSurface3
*iface
, HDC dc
)
1246 TRACE("iface %p, dc %p.\n", iface
, dc
);
1248 return ddraw_surface7_ReleaseDC((IDirectDrawSurface7
*)surface_from_surface3(iface
), dc
);
1251 /*****************************************************************************
1252 * IDirectDrawSurface7::GetCaps
1254 * Returns the surface's caps
1257 * Caps: Address to write the caps to
1261 * DDERR_INVALIDPARAMS if Caps is NULL
1263 *****************************************************************************/
1264 static HRESULT WINAPI
ddraw_surface7_GetCaps(IDirectDrawSurface7
*iface
, DDSCAPS2
*Caps
)
1266 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1267 TRACE("(%p)->(%p)\n",This
,Caps
);
1270 return DDERR_INVALIDPARAMS
;
1272 *Caps
= This
->surface_desc
.ddsCaps
;
1276 static HRESULT WINAPI
ddraw_surface3_GetCaps(IDirectDrawSurface3
*iface
, DDSCAPS
*caps
)
1281 TRACE("iface %p, caps %p.\n", iface
, caps
);
1283 hr
= ddraw_surface7_GetCaps((IDirectDrawSurface7
*)surface_from_surface3(iface
), &caps2
);
1284 if (FAILED(hr
)) return hr
;
1286 caps
->dwCaps
= caps2
.dwCaps
;
1290 /*****************************************************************************
1291 * IDirectDrawSurface7::SetPriority
1293 * Sets a texture priority for managed textures.
1296 * Priority: The new priority
1300 * For more details, see IWineD3DSurface::SetPriority
1302 *****************************************************************************/
1303 static HRESULT WINAPI
ddraw_surface7_SetPriority(IDirectDrawSurface7
*iface
, DWORD Priority
)
1305 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1307 TRACE("(%p)->(%d): Relay!\n",This
,Priority
);
1309 EnterCriticalSection(&ddraw_cs
);
1310 hr
= IWineD3DSurface_SetPriority(This
->WineD3DSurface
, Priority
);
1311 LeaveCriticalSection(&ddraw_cs
);
1315 /*****************************************************************************
1316 * IDirectDrawSurface7::GetPriority
1318 * Returns the surface's priority
1321 * Priority: Address of a variable to write the priority to
1325 * DDERR_INVALIDPARAMS if Priority == NULL
1326 * For more details, see IWineD3DSurface::GetPriority
1328 *****************************************************************************/
1329 static HRESULT WINAPI
ddraw_surface7_GetPriority(IDirectDrawSurface7
*iface
, DWORD
*Priority
)
1331 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1332 TRACE("(%p)->(%p): Relay\n",This
,Priority
);
1336 return DDERR_INVALIDPARAMS
;
1339 EnterCriticalSection(&ddraw_cs
);
1340 *Priority
= IWineD3DSurface_GetPriority(This
->WineD3DSurface
);
1341 LeaveCriticalSection(&ddraw_cs
);
1345 /*****************************************************************************
1346 * IDirectDrawSurface7::SetPrivateData
1348 * Stores some data in the surface that is intended for the application's
1352 * tag: GUID that identifies the data
1353 * Data: Pointer to the private data
1354 * Size: Size of the private data
1359 * For more details, see IWineD3DSurface::SetPrivateData
1361 *****************************************************************************/
1362 static HRESULT WINAPI
ddraw_surface7_SetPrivateData(IDirectDrawSurface7
*iface
,
1363 REFGUID tag
, void *Data
, DWORD Size
, DWORD Flags
)
1365 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1367 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This
, debugstr_guid(tag
), Data
, Size
, Flags
);
1369 EnterCriticalSection(&ddraw_cs
);
1370 hr
= IWineD3DSurface_SetPrivateData(This
->WineD3DSurface
,
1375 LeaveCriticalSection(&ddraw_cs
);
1378 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1383 /*****************************************************************************
1384 * IDirectDrawSurface7::GetPrivateData
1386 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1389 * tag: GUID of the data to return
1390 * Data: Address where to write the data to
1391 * Size: Size of the buffer at Data
1395 * DDERR_INVALIDPARAMS if Data is NULL
1396 * For more details, see IWineD3DSurface::GetPrivateData
1398 *****************************************************************************/
1399 static HRESULT WINAPI
ddraw_surface7_GetPrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
, void *Data
, DWORD
*Size
)
1401 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1403 TRACE("(%p)->(%s,%p,%p): Relay\n", This
, debugstr_guid(tag
), Data
, Size
);
1406 return DDERR_INVALIDPARAMS
;
1408 EnterCriticalSection(&ddraw_cs
);
1409 hr
= IWineD3DSurface_GetPrivateData(This
->WineD3DSurface
,
1413 LeaveCriticalSection(&ddraw_cs
);
1417 /*****************************************************************************
1418 * IDirectDrawSurface7::FreePrivateData
1420 * Frees private data stored in the surface
1423 * tag: Tag of the data to free
1427 * For more details, see IWineD3DSurface::FreePrivateData
1429 *****************************************************************************/
1430 static HRESULT WINAPI
ddraw_surface7_FreePrivateData(IDirectDrawSurface7
*iface
, REFGUID tag
)
1432 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1434 TRACE("(%p)->(%s): Relay\n", This
, debugstr_guid(tag
));
1436 EnterCriticalSection(&ddraw_cs
);
1437 hr
= IWineD3DSurface_FreePrivateData(This
->WineD3DSurface
, tag
);
1438 LeaveCriticalSection(&ddraw_cs
);
1442 /*****************************************************************************
1443 * IDirectDrawSurface7::PageLock
1445 * Prevents a sysmem surface from being paged out
1448 * Flags: Not used, must be 0(unchecked)
1451 * DD_OK, because it's a stub
1453 *****************************************************************************/
1454 static HRESULT WINAPI
ddraw_surface7_PageLock(IDirectDrawSurface7
*iface
, DWORD Flags
)
1456 TRACE("(%p)->(%x)\n", iface
, Flags
);
1458 /* This is Windows memory management related - we don't need this */
1462 static HRESULT WINAPI
ddraw_surface3_PageLock(IDirectDrawSurface3
*iface
, DWORD flags
)
1464 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1466 return ddraw_surface7_PageLock((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1469 /*****************************************************************************
1470 * IDirectDrawSurface7::PageUnlock
1472 * Allows a sysmem surface to be paged out
1475 * Flags: Not used, must be 0(unchecked)
1478 * DD_OK, because it's a stub
1480 *****************************************************************************/
1481 static HRESULT WINAPI
ddraw_surface7_PageUnlock(IDirectDrawSurface7
*iface
, DWORD Flags
)
1483 TRACE("(%p)->(%x)\n", iface
, Flags
);
1488 static HRESULT WINAPI
ddraw_surface3_PageUnlock(IDirectDrawSurface3
*iface
, DWORD flags
)
1490 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1492 return ddraw_surface7_PageUnlock((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1495 /*****************************************************************************
1496 * IDirectDrawSurface7::BltBatch
1498 * An unimplemented function
1506 *****************************************************************************/
1507 static HRESULT WINAPI
ddraw_surface7_BltBatch(IDirectDrawSurface7
*iface
, DDBLTBATCH
*Batch
, DWORD Count
, DWORD Flags
)
1509 TRACE("(%p)->(%p,%d,%08x)\n",iface
,Batch
,Count
,Flags
);
1511 /* MSDN: "not currently implemented" */
1512 return DDERR_UNSUPPORTED
;
1515 static HRESULT WINAPI
ddraw_surface3_BltBatch(IDirectDrawSurface3
*iface
, DDBLTBATCH
*batch
, DWORD count
, DWORD flags
)
1517 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface
, batch
, count
, flags
);
1519 return ddraw_surface7_BltBatch((IDirectDrawSurface7
*)surface_from_surface3(iface
), batch
, count
, flags
);
1522 /*****************************************************************************
1523 * IDirectDrawSurface7::EnumAttachedSurfaces
1525 * Enumerates all surfaces attached to this surface
1528 * context: Pointer to pass unmodified to the callback
1529 * cb: Callback function to call for each surface
1533 * DDERR_INVALIDPARAMS if cb is NULL
1535 *****************************************************************************/
1536 static HRESULT WINAPI
ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7
*iface
,
1537 void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
1539 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1540 IDirectDrawSurfaceImpl
*surf
;
1541 DDSURFACEDESC2 desc
;
1544 /* Attached surfaces aren't handled in WineD3D */
1545 TRACE("(%p)->(%p,%p)\n",This
,context
,cb
);
1548 return DDERR_INVALIDPARAMS
;
1550 EnterCriticalSection(&ddraw_cs
);
1551 for(i
= 0; i
< MAX_COMPLEX_ATTACHED
; i
++)
1553 surf
= This
->complex_array
[i
];
1556 ddraw_surface7_AddRef((IDirectDrawSurface7
*)surf
);
1557 desc
= surf
->surface_desc
;
1558 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1559 if (cb((IDirectDrawSurface7
*)surf
, &desc
, context
) == DDENUMRET_CANCEL
)
1561 LeaveCriticalSection(&ddraw_cs
);
1566 for (surf
= This
->next_attached
; surf
!= NULL
; surf
= surf
->next_attached
)
1568 ddraw_surface7_AddRef((IDirectDrawSurface7
*)surf
);
1569 desc
= surf
->surface_desc
;
1570 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1571 if (cb((IDirectDrawSurface7
*)surf
, &desc
, context
) == DDENUMRET_CANCEL
)
1573 LeaveCriticalSection(&ddraw_cs
);
1578 TRACE(" end of enumeration.\n");
1580 LeaveCriticalSection(&ddraw_cs
);
1584 struct callback_info
1586 LPDDENUMSURFACESCALLBACK callback
;
1590 static HRESULT CALLBACK
EnumCallback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *context
)
1592 const struct callback_info
*info
= context
;
1594 return info
->callback((IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface
)->IDirectDrawSurface3_vtbl
,
1595 (DDSURFACEDESC
*)surface_desc
, info
->context
);
1598 static HRESULT WINAPI
ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3
*iface
,
1599 void *context
, LPDDENUMSURFACESCALLBACK callback
)
1601 struct callback_info info
;
1603 TRACE("iface %p, context %p, callback %p.\n", iface
, context
, callback
);
1605 info
.callback
= callback
;
1606 info
.context
= context
;
1608 return ddraw_surface7_EnumAttachedSurfaces((IDirectDrawSurface7
*)surface_from_surface3(iface
),
1609 &info
, EnumCallback
);
1612 /*****************************************************************************
1613 * IDirectDrawSurface7::EnumOverlayZOrders
1615 * "Enumerates the overlay surfaces on the specified destination"
1618 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1619 * context: context to pass back to the callback
1620 * cb: callback function to call for each enumerated surface
1623 * DD_OK, because it's a stub
1625 *****************************************************************************/
1626 static HRESULT WINAPI
ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7
*iface
,
1627 DWORD Flags
, void *context
, LPDDENUMSURFACESCALLBACK7 cb
)
1629 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface
, Flags
, context
, cb
);
1634 static HRESULT WINAPI
ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3
*iface
,
1635 DWORD flags
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
1637 struct callback_info info
;
1639 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface
, flags
, context
, callback
);
1641 info
.callback
= callback
;
1642 info
.context
= context
;
1644 return ddraw_surface7_EnumOverlayZOrders((IDirectDrawSurface7
*)surface_from_surface3(iface
),
1645 flags
, &info
, EnumCallback
);
1648 /*****************************************************************************
1649 * IDirectDrawSurface7::GetBltStatus
1651 * Returns the blitting status
1654 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1657 * See IWineD3DSurface::Blt
1659 *****************************************************************************/
1660 static HRESULT WINAPI
ddraw_surface7_GetBltStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
1662 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1664 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1666 EnterCriticalSection(&ddraw_cs
);
1667 hr
= IWineD3DSurface_GetBltStatus(This
->WineD3DSurface
, Flags
);
1668 LeaveCriticalSection(&ddraw_cs
);
1671 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1676 static HRESULT WINAPI
ddraw_surface3_GetBltStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
1678 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1680 return ddraw_surface7_GetBltStatus((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1683 /*****************************************************************************
1684 * IDirectDrawSurface7::GetColorKey
1686 * Returns the color key assigned to the surface
1690 * CKey: Address to store the key to
1694 * DDERR_INVALIDPARAMS if CKey is NULL
1696 *****************************************************************************/
1697 static HRESULT WINAPI
ddraw_surface7_GetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
1699 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1700 TRACE("(%p)->(%08x,%p)\n", This
, Flags
, CKey
);
1703 return DDERR_INVALIDPARAMS
;
1705 EnterCriticalSection(&ddraw_cs
);
1709 case DDCKEY_DESTBLT
:
1710 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTBLT
))
1712 LeaveCriticalSection(&ddraw_cs
);
1713 return DDERR_NOCOLORKEY
;
1715 *CKey
= This
->surface_desc
.ddckCKDestBlt
;
1718 case DDCKEY_DESTOVERLAY
:
1719 if (!(This
->surface_desc
.dwFlags
& DDSD_CKDESTOVERLAY
))
1721 LeaveCriticalSection(&ddraw_cs
);
1722 return DDERR_NOCOLORKEY
;
1724 *CKey
= This
->surface_desc
.u3
.ddckCKDestOverlay
;
1728 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCBLT
))
1730 LeaveCriticalSection(&ddraw_cs
);
1731 return DDERR_NOCOLORKEY
;
1733 *CKey
= This
->surface_desc
.ddckCKSrcBlt
;
1736 case DDCKEY_SRCOVERLAY
:
1737 if (!(This
->surface_desc
.dwFlags
& DDSD_CKSRCOVERLAY
))
1739 LeaveCriticalSection(&ddraw_cs
);
1740 return DDERR_NOCOLORKEY
;
1742 *CKey
= This
->surface_desc
.ddckCKSrcOverlay
;
1746 LeaveCriticalSection(&ddraw_cs
);
1747 return DDERR_INVALIDPARAMS
;
1750 LeaveCriticalSection(&ddraw_cs
);
1754 static HRESULT WINAPI
ddraw_surface3_GetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
1756 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
1758 return ddraw_surface7_GetColorKey((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
, color_key
);
1761 /*****************************************************************************
1762 * IDirectDrawSurface7::GetFlipStatus
1764 * Returns the flipping status of the surface
1767 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1770 * See IWineD3DSurface::GetFlipStatus
1772 *****************************************************************************/
1773 static HRESULT WINAPI
ddraw_surface7_GetFlipStatus(IDirectDrawSurface7
*iface
, DWORD Flags
)
1775 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1777 TRACE("(%p)->(%x): Relay\n", This
, Flags
);
1779 EnterCriticalSection(&ddraw_cs
);
1780 hr
= IWineD3DSurface_GetFlipStatus(This
->WineD3DSurface
, Flags
);
1781 LeaveCriticalSection(&ddraw_cs
);
1784 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
1789 static HRESULT WINAPI
ddraw_surface3_GetFlipStatus(IDirectDrawSurface3
*iface
, DWORD flags
)
1791 TRACE("iface %p, flags %#x.\n", iface
, flags
);
1793 return ddraw_surface7_GetFlipStatus((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
1796 /*****************************************************************************
1797 * IDirectDrawSurface7::GetOverlayPosition
1799 * Returns the display coordinates of a visible and active overlay surface
1806 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1807 *****************************************************************************/
1808 static HRESULT WINAPI
ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7
*iface
, LONG
*X
, LONG
*Y
)
1810 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1812 TRACE("(%p)->(%p,%p): Relay\n", This
, X
, Y
);
1814 EnterCriticalSection(&ddraw_cs
);
1815 hr
= IWineD3DSurface_GetOverlayPosition(This
->WineD3DSurface
,
1818 LeaveCriticalSection(&ddraw_cs
);
1822 static HRESULT WINAPI
ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3
*iface
, LONG
*x
, LONG
*y
)
1824 TRACE("iface %p, x %p, y %p.\n", iface
, x
, y
);
1826 return ddraw_surface7_GetOverlayPosition((IDirectDrawSurface7
*)surface_from_surface3(iface
), x
, y
);
1829 /*****************************************************************************
1830 * IDirectDrawSurface7::GetPixelFormat
1832 * Returns the pixel format of the Surface
1835 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1836 * format should be written
1840 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1842 *****************************************************************************/
1843 static HRESULT WINAPI
ddraw_surface7_GetPixelFormat(IDirectDrawSurface7
*iface
, DDPIXELFORMAT
*PixelFormat
)
1845 /* What is DDERR_INVALIDSURFACETYPE for here? */
1846 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1847 TRACE("(%p)->(%p)\n",This
,PixelFormat
);
1850 return DDERR_INVALIDPARAMS
;
1852 EnterCriticalSection(&ddraw_cs
);
1853 DD_STRUCT_COPY_BYSIZE(PixelFormat
,&This
->surface_desc
.u4
.ddpfPixelFormat
);
1854 LeaveCriticalSection(&ddraw_cs
);
1859 static HRESULT WINAPI
ddraw_surface3_GetPixelFormat(IDirectDrawSurface3
*iface
, DDPIXELFORMAT
*pixel_format
)
1861 TRACE("iface %p, pixel_format %p.\n", iface
, pixel_format
);
1863 return ddraw_surface7_GetPixelFormat((IDirectDrawSurface7
*)surface_from_surface3(iface
), pixel_format
);
1866 /*****************************************************************************
1867 * IDirectDrawSurface7::GetSurfaceDesc
1869 * Returns the description of this surface
1872 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1877 * DDERR_INVALIDPARAMS if DDSD is NULL
1879 *****************************************************************************/
1880 static HRESULT WINAPI
ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
)
1882 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1884 TRACE("(%p)->(%p)\n",This
,DDSD
);
1887 return DDERR_INVALIDPARAMS
;
1889 if (DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
))
1891 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD
->dwSize
);
1892 return DDERR_INVALIDPARAMS
;
1895 EnterCriticalSection(&ddraw_cs
);
1896 DD_STRUCT_COPY_BYSIZE(DDSD
,&This
->surface_desc
);
1897 TRACE("Returning surface desc:\n");
1898 if (TRACE_ON(ddraw
)) DDRAW_dump_surface_desc(DDSD
);
1900 LeaveCriticalSection(&ddraw_cs
);
1904 static HRESULT WINAPI
ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3
*iface
, DDSURFACEDESC
*surface_desc
)
1906 IDirectDrawSurfaceImpl
*surface
= surface_from_surface3(iface
);
1908 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1910 if (!surface_desc
) return DDERR_INVALIDPARAMS
;
1912 if (surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
1914 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc
->dwSize
);
1915 return DDERR_INVALIDPARAMS
;
1918 EnterCriticalSection(&ddraw_cs
);
1919 DD_STRUCT_COPY_BYSIZE(surface_desc
, (DDSURFACEDESC
*)&surface
->surface_desc
);
1920 TRACE("Returning surface desc:\n");
1921 if (TRACE_ON(ddraw
))
1923 /* DDRAW_dump_surface_desc handles the smaller size */
1924 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
1927 LeaveCriticalSection(&ddraw_cs
);
1931 /*****************************************************************************
1932 * IDirectDrawSurface7::Initialize
1934 * Initializes the surface. This is a no-op in Wine
1937 * DD: Pointer to an DirectDraw interface
1938 * DDSD: Surface description for initialization
1941 * DDERR_ALREADYINITIALIZED
1943 *****************************************************************************/
1944 static HRESULT WINAPI
ddraw_surface7_Initialize(IDirectDrawSurface7
*iface
,
1945 IDirectDraw
*ddraw
, DDSURFACEDESC2
*surface_desc
)
1947 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
1949 return DDERR_ALREADYINITIALIZED
;
1952 static HRESULT WINAPI
ddraw_surface3_Initialize(IDirectDrawSurface3
*iface
,
1953 IDirectDraw
*ddraw
, DDSURFACEDESC
*surface_desc
)
1955 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface
, ddraw
, surface_desc
);
1957 return ddraw_surface7_Initialize((IDirectDrawSurface7
*)surface_from_surface3(iface
),
1958 ddraw
, (DDSURFACEDESC2
*)surface_desc
);
1961 /*****************************************************************************
1962 * IDirect3DTexture1::Initialize
1964 * The sdk says it's not implemented
1972 *****************************************************************************/
1973 static HRESULT WINAPI
d3d_texture1_Initialize(IDirect3DTexture
*iface
,
1974 IDirect3DDevice
*device
, IDirectDrawSurface
*surface
)
1976 TRACE("iface %p, device %p, surface %p.\n", iface
, device
, surface
);
1978 return DDERR_UNSUPPORTED
; /* Unchecked */
1981 /*****************************************************************************
1982 * IDirectDrawSurface7::IsLost
1984 * Checks if the surface is lost
1987 * DD_OK, if the surface is usable
1988 * DDERR_ISLOST if the surface is lost
1989 * See IWineD3DSurface::IsLost for more details
1991 *****************************************************************************/
1992 static HRESULT WINAPI
ddraw_surface7_IsLost(IDirectDrawSurface7
*iface
)
1994 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1996 TRACE("(%p)\n", This
);
1998 EnterCriticalSection(&ddraw_cs
);
1999 /* We lose the surface if the implementation was changed */
2000 if(This
->ImplType
!= This
->ddraw
->ImplType
)
2002 /* But this shouldn't happen. When we change the implementation,
2003 * all surfaces are re-created automatically, and their content
2006 ERR(" (%p) Implementation was changed from %d to %d\n", This
, This
->ImplType
, This
->ddraw
->ImplType
);
2007 LeaveCriticalSection(&ddraw_cs
);
2008 return DDERR_SURFACELOST
;
2011 hr
= IWineD3DSurface_IsLost(This
->WineD3DSurface
);
2012 LeaveCriticalSection(&ddraw_cs
);
2015 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
2016 * WineD3D uses the same error for surfaces
2018 case WINED3DERR_DEVICELOST
: return DDERR_SURFACELOST
;
2023 static HRESULT WINAPI
ddraw_surface3_IsLost(IDirectDrawSurface3
*iface
)
2025 TRACE("iface %p.\n", iface
);
2027 return ddraw_surface7_IsLost((IDirectDrawSurface7
*)surface_from_surface3(iface
));
2030 /*****************************************************************************
2031 * IDirectDrawSurface7::Restore
2033 * Restores a lost surface. This makes the surface usable again, but
2034 * doesn't reload its old contents
2038 * See IWineD3DSurface::Restore for more details
2040 *****************************************************************************/
2041 static HRESULT WINAPI
ddraw_surface7_Restore(IDirectDrawSurface7
*iface
)
2043 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2045 TRACE("(%p)\n", This
);
2047 EnterCriticalSection(&ddraw_cs
);
2048 if(This
->ImplType
!= This
->ddraw
->ImplType
)
2050 /* Call the recreation callback. Make sure to AddRef first */
2051 IDirectDrawSurface_AddRef(iface
);
2052 ddraw_recreate_surfaces_cb(iface
, &This
->surface_desc
, NULL
/* Not needed */);
2054 hr
= IWineD3DSurface_Restore(This
->WineD3DSurface
);
2055 LeaveCriticalSection(&ddraw_cs
);
2059 static HRESULT WINAPI
ddraw_surface3_Restore(IDirectDrawSurface3
*iface
)
2061 TRACE("iface %p.\n", iface
);
2063 return ddraw_surface7_Restore((IDirectDrawSurface7
*)surface_from_surface3(iface
));
2066 /*****************************************************************************
2067 * IDirectDrawSurface7::SetOverlayPosition
2069 * Changes the display coordinates of an overlay surface
2076 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
2077 *****************************************************************************/
2078 static HRESULT WINAPI
ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7
*iface
, LONG X
, LONG Y
)
2080 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2082 TRACE("(%p)->(%d,%d): Relay\n", This
, X
, Y
);
2084 EnterCriticalSection(&ddraw_cs
);
2085 hr
= IWineD3DSurface_SetOverlayPosition(This
->WineD3DSurface
,
2088 LeaveCriticalSection(&ddraw_cs
);
2092 static HRESULT WINAPI
ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3
*iface
, LONG x
, LONG y
)
2094 TRACE("iface %p, x %d, y %d.\n", iface
, x
, y
);
2096 return ddraw_surface7_SetOverlayPosition((IDirectDrawSurface7
*)surface_from_surface3(iface
), x
, y
);
2099 /*****************************************************************************
2100 * IDirectDrawSurface7::UpdateOverlay
2102 * Modifies the attributes of an overlay surface.
2105 * SrcRect: The section of the source being used for the overlay
2106 * DstSurface: Address of the surface that is overlaid
2107 * DstRect: Place of the overlay
2108 * Flags: some DDOVER_* flags
2111 * DDERR_UNSUPPORTED, because we don't support overlays
2113 *****************************************************************************/
2114 static HRESULT WINAPI
ddraw_surface7_UpdateOverlay(IDirectDrawSurface7
*iface
, RECT
*SrcRect
,
2115 IDirectDrawSurface7
*DstSurface
, RECT
*DstRect
, DWORD Flags
, DDOVERLAYFX
*FX
)
2117 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2118 IDirectDrawSurfaceImpl
*Dst
= (IDirectDrawSurfaceImpl
*)DstSurface
;
2120 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This
, SrcRect
, Dst
, DstRect
, Flags
, FX
);
2122 EnterCriticalSection(&ddraw_cs
);
2123 hr
= IWineD3DSurface_UpdateOverlay(This
->WineD3DSurface
,
2125 Dst
? Dst
->WineD3DSurface
: NULL
,
2128 (WINEDDOVERLAYFX
*) FX
);
2129 LeaveCriticalSection(&ddraw_cs
);
2131 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2132 case WINEDDERR_NOTAOVERLAYSURFACE
: return DDERR_NOTAOVERLAYSURFACE
;
2133 case WINEDDERR_OVERLAYNOTVISIBLE
: return DDERR_OVERLAYNOTVISIBLE
;
2139 static HRESULT WINAPI
ddraw_surface3_UpdateOverlay(IDirectDrawSurface3
*iface
, RECT
*src_rect
,
2140 IDirectDrawSurface3
*dst_surface
, RECT
*dst_rect
, DWORD flags
, DDOVERLAYFX
*fx
)
2142 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
2143 iface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), flags
, fx
);
2145 return ddraw_surface7_UpdateOverlay((IDirectDrawSurface7
*)surface_from_surface3(iface
), src_rect
,
2146 dst_surface
? (IDirectDrawSurface7
*)surface_from_surface3(dst_surface
) : NULL
, dst_rect
, flags
, fx
);
2149 /*****************************************************************************
2150 * IDirectDrawSurface7::UpdateOverlayDisplay
2152 * The DX7 sdk says that it's not implemented
2157 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
2159 *****************************************************************************/
2160 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7
*iface
, DWORD Flags
)
2162 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2163 TRACE("(%p)->(%x)\n", This
, Flags
);
2164 return DDERR_UNSUPPORTED
;
2167 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3
*iface
, DWORD flags
)
2169 TRACE("iface %p, flags %#x.\n", iface
, flags
);
2171 return ddraw_surface7_UpdateOverlayDisplay((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
);
2174 /*****************************************************************************
2175 * IDirectDrawSurface7::UpdateOverlayZOrder
2177 * Sets an overlay's Z order
2180 * Flags: DDOVERZ_* flags
2181 * DDSRef: Defines the relative position in the overlay chain
2184 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
2186 *****************************************************************************/
2187 static HRESULT WINAPI
ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7
*iface
,
2188 DWORD Flags
, IDirectDrawSurface7
*DDSRef
)
2190 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2191 IDirectDrawSurfaceImpl
*Ref
= (IDirectDrawSurfaceImpl
*)DDSRef
;
2194 TRACE("(%p)->(%x,%p): Relay\n", This
, Flags
, Ref
);
2195 EnterCriticalSection(&ddraw_cs
);
2196 hr
= IWineD3DSurface_UpdateOverlayZOrder(This
->WineD3DSurface
,
2198 Ref
? Ref
->WineD3DSurface
: NULL
);
2199 LeaveCriticalSection(&ddraw_cs
);
2203 static HRESULT WINAPI
ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3
*iface
,
2204 DWORD flags
, IDirectDrawSurface3
*reference
)
2206 TRACE("iface %p, flags %#x, reference %p.\n", iface
, flags
, reference
);
2208 return ddraw_surface7_UpdateOverlayZOrder((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
,
2209 reference
? (IDirectDrawSurface7
*)surface_from_surface3(reference
) : NULL
);
2212 /*****************************************************************************
2213 * IDirectDrawSurface7::GetDDInterface
2215 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
2216 * surface belongs to
2219 * DD: Address to write the interface pointer to
2223 * DDERR_INVALIDPARAMS if DD is NULL
2225 *****************************************************************************/
2226 static HRESULT WINAPI
ddraw_surface7_GetDDInterface(IDirectDrawSurface7
*iface
, void **DD
)
2228 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2230 TRACE("(%p)->(%p)\n",This
,DD
);
2233 return DDERR_INVALIDPARAMS
;
2235 switch(This
->version
)
2242 *DD
= &This
->ddraw
->IDirectDraw4_vtbl
;
2246 *DD
= &This
->ddraw
->IDirectDraw2_vtbl
;
2250 *DD
= &This
->ddraw
->IDirectDraw_vtbl
;
2254 IUnknown_AddRef((IUnknown
*)*DD
);
2259 static HRESULT WINAPI
ddraw_surface3_GetDDInterface(IDirectDrawSurface3
*iface
, void **ddraw
)
2261 TRACE("iface %p, ddraw %p.\n", iface
, ddraw
);
2263 return ddraw_surface7_GetDDInterface((IDirectDrawSurface7
*)surface_from_surface3(iface
), ddraw
);
2266 /* This seems also windows implementation specific - I don't think WineD3D needs this */
2267 static HRESULT WINAPI
ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7
*iface
)
2269 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2270 volatile IDirectDrawSurfaceImpl
* vThis
= This
;
2272 TRACE("(%p)\n",This
);
2273 EnterCriticalSection(&ddraw_cs
);
2274 /* A uniqueness value of 0 is apparently special.
2275 * This needs to be checked.
2276 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
2279 DWORD old_uniqueness_value
= vThis
->uniqueness_value
;
2280 DWORD new_uniqueness_value
= old_uniqueness_value
+1;
2282 if (old_uniqueness_value
== 0) break;
2283 if (new_uniqueness_value
== 0) new_uniqueness_value
= 1;
2285 if (InterlockedCompareExchange((LONG
*)&vThis
->uniqueness_value
,
2286 old_uniqueness_value
,
2287 new_uniqueness_value
)
2288 == old_uniqueness_value
)
2292 LeaveCriticalSection(&ddraw_cs
);
2296 static HRESULT WINAPI
ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7
*iface
, DWORD
*pValue
)
2298 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2300 TRACE("(%p)->(%p)\n",This
,pValue
);
2301 EnterCriticalSection(&ddraw_cs
);
2302 *pValue
= This
->uniqueness_value
;
2303 LeaveCriticalSection(&ddraw_cs
);
2307 /*****************************************************************************
2308 * IDirectDrawSurface7::SetLOD
2310 * Sets the level of detail of a texture
2313 * MaxLOD: LOD to set
2317 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2319 *****************************************************************************/
2320 static HRESULT WINAPI
ddraw_surface7_SetLOD(IDirectDrawSurface7
*iface
, DWORD MaxLOD
)
2322 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2324 TRACE("(%p)->(%d)\n", This
, MaxLOD
);
2326 EnterCriticalSection(&ddraw_cs
);
2327 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2329 LeaveCriticalSection(&ddraw_cs
);
2330 return DDERR_INVALIDOBJECT
;
2333 if(!This
->wineD3DTexture
)
2335 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This
);
2336 LeaveCriticalSection(&ddraw_cs
);
2337 return DDERR_INVALIDOBJECT
;
2340 hr
= IWineD3DBaseTexture_SetLOD(This
->wineD3DTexture
,
2342 LeaveCriticalSection(&ddraw_cs
);
2346 /*****************************************************************************
2347 * IDirectDrawSurface7::GetLOD
2349 * Returns the level of detail of a Direct3D texture
2352 * MaxLOD: Address to write the LOD to
2356 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2357 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2359 *****************************************************************************/
2360 static HRESULT WINAPI
ddraw_surface7_GetLOD(IDirectDrawSurface7
*iface
, DWORD
*MaxLOD
)
2362 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2363 TRACE("(%p)->(%p)\n", This
, MaxLOD
);
2366 return DDERR_INVALIDPARAMS
;
2368 EnterCriticalSection(&ddraw_cs
);
2369 if (!(This
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
))
2371 LeaveCriticalSection(&ddraw_cs
);
2372 return DDERR_INVALIDOBJECT
;
2375 *MaxLOD
= IWineD3DBaseTexture_GetLOD(This
->wineD3DTexture
);
2376 LeaveCriticalSection(&ddraw_cs
);
2380 /*****************************************************************************
2381 * IDirectDrawSurface7::BltFast
2383 * Performs a fast Blit.
2386 * dstx: The x coordinate to blit to on the destination
2387 * dsty: The y coordinate to blit to on the destination
2388 * Source: The source surface
2389 * rsrc: The source rectangle
2390 * trans: Type of transfer. Some DDBLTFAST_* flags
2394 * For more details, see IWineD3DSurface::BltFast
2396 *****************************************************************************/
2397 static HRESULT WINAPI
ddraw_surface7_BltFast(IDirectDrawSurface7
*iface
, DWORD dstx
, DWORD dsty
,
2398 IDirectDrawSurface7
*Source
, RECT
*rsrc
, DWORD trans
)
2400 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2401 IDirectDrawSurfaceImpl
*src
= (IDirectDrawSurfaceImpl
*)Source
;
2402 DWORD src_w
, src_h
, dst_w
, dst_h
;
2404 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This
, dstx
, dsty
, Source
, rsrc
, trans
);
2406 dst_w
= This
->surface_desc
.dwWidth
;
2407 dst_h
= This
->surface_desc
.dwHeight
;
2409 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2414 if(rsrc
->top
> rsrc
->bottom
|| rsrc
->left
> rsrc
->right
||
2415 rsrc
->right
> src
->surface_desc
.dwWidth
||
2416 rsrc
->bottom
> src
->surface_desc
.dwHeight
)
2418 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2419 return DDERR_INVALIDRECT
;
2422 src_w
= rsrc
->right
- rsrc
->left
;
2423 src_h
= rsrc
->bottom
- rsrc
->top
;
2427 src_w
= src
->surface_desc
.dwWidth
;
2428 src_h
= src
->surface_desc
.dwHeight
;
2431 if (src_w
> dst_w
|| dstx
> dst_w
- src_w
2432 || src_h
> dst_h
|| dsty
> dst_h
- src_h
)
2434 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
2435 return DDERR_INVALIDRECT
;
2438 EnterCriticalSection(&ddraw_cs
);
2439 hr
= IWineD3DSurface_BltFast(This
->WineD3DSurface
,
2441 src
? src
->WineD3DSurface
: NULL
,
2444 LeaveCriticalSection(&ddraw_cs
);
2447 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
2448 case WINED3DERR_WRONGTEXTUREFORMAT
: return DDERR_INVALIDPIXELFORMAT
;
2453 static HRESULT WINAPI
ddraw_surface3_BltFast(IDirectDrawSurface3
*iface
, DWORD dst_x
, DWORD dst_y
,
2454 IDirectDrawSurface3
*src_surface
, RECT
*src_rect
, DWORD flags
)
2456 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
2457 iface
, dst_x
, dst_y
, src_surface
, wine_dbgstr_rect(src_rect
), flags
);
2459 return ddraw_surface7_BltFast((IDirectDrawSurface7
*)surface_from_surface3(iface
), dst_x
, dst_y
,
2460 src_surface
? (IDirectDrawSurface7
*)surface_from_surface3(src_surface
) : NULL
, src_rect
, flags
);
2463 /*****************************************************************************
2464 * IDirectDrawSurface7::GetClipper
2466 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2470 * Clipper: Address to store the interface pointer at
2474 * DDERR_INVALIDPARAMS if Clipper is NULL
2475 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2477 *****************************************************************************/
2478 static HRESULT WINAPI
ddraw_surface7_GetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
**Clipper
)
2480 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2481 TRACE("(%p)->(%p)\n", This
, Clipper
);
2485 LeaveCriticalSection(&ddraw_cs
);
2486 return DDERR_INVALIDPARAMS
;
2489 EnterCriticalSection(&ddraw_cs
);
2490 if(This
->clipper
== NULL
)
2492 LeaveCriticalSection(&ddraw_cs
);
2493 return DDERR_NOCLIPPERATTACHED
;
2496 *Clipper
= (IDirectDrawClipper
*)This
->clipper
;
2497 IDirectDrawClipper_AddRef(*Clipper
);
2498 LeaveCriticalSection(&ddraw_cs
);
2502 static HRESULT WINAPI
ddraw_surface3_GetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
**clipper
)
2504 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
2506 return ddraw_surface7_GetClipper((IDirectDrawSurface7
*)surface_from_surface3(iface
), clipper
);
2509 /*****************************************************************************
2510 * IDirectDrawSurface7::SetClipper
2512 * Sets a clipper for the surface
2515 * Clipper: IDirectDrawClipper interface of the clipper to set
2520 *****************************************************************************/
2521 static HRESULT WINAPI
ddraw_surface7_SetClipper(IDirectDrawSurface7
*iface
, IDirectDrawClipper
*Clipper
)
2523 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2524 IDirectDrawClipperImpl
*oldClipper
= This
->clipper
;
2527 TRACE("(%p)->(%p)\n",This
,Clipper
);
2529 EnterCriticalSection(&ddraw_cs
);
2530 if ((IDirectDrawClipperImpl
*)Clipper
== This
->clipper
)
2532 LeaveCriticalSection(&ddraw_cs
);
2536 This
->clipper
= (IDirectDrawClipperImpl
*)Clipper
;
2538 if (Clipper
!= NULL
)
2539 IDirectDrawClipper_AddRef(Clipper
);
2541 IDirectDrawClipper_Release((IDirectDrawClipper
*)oldClipper
);
2543 hr
= IWineD3DSurface_SetClipper(This
->WineD3DSurface
, This
->clipper
? This
->clipper
->wineD3DClipper
: NULL
);
2545 if(This
->wineD3DSwapChain
) {
2548 IDirectDrawClipper_GetHWnd(Clipper
, &clipWindow
);
2552 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2555 IWineD3DSwapChain_SetDestWindowOverride(This
->wineD3DSwapChain
,
2556 This
->ddraw
->d3d_window
);
2560 LeaveCriticalSection(&ddraw_cs
);
2564 static HRESULT WINAPI
ddraw_surface3_SetClipper(IDirectDrawSurface3
*iface
, IDirectDrawClipper
*clipper
)
2566 TRACE("iface %p, clipper %p.\n", iface
, clipper
);
2568 return ddraw_surface7_SetClipper((IDirectDrawSurface7
*)surface_from_surface3(iface
), clipper
);
2571 /*****************************************************************************
2572 * IDirectDrawSurface7::SetSurfaceDesc
2574 * Sets the surface description. It can override the pixel format, the surface
2576 * It's not really tested.
2579 * DDSD: Pointer to the new surface description to set
2584 * DDERR_INVALIDPARAMS if DDSD is NULL
2586 *****************************************************************************/
2587 static HRESULT WINAPI
ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7
*iface
, DDSURFACEDESC2
*DDSD
, DWORD Flags
)
2589 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2590 WINED3DFORMAT newFormat
= WINED3DFMT_UNKNOWN
;
2592 TRACE("(%p)->(%p,%x)\n", This
, DDSD
, Flags
);
2595 return DDERR_INVALIDPARAMS
;
2597 EnterCriticalSection(&ddraw_cs
);
2598 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
)
2600 newFormat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2602 if(newFormat
== WINED3DFMT_UNKNOWN
)
2604 ERR("Requested to set an unknown pixelformat\n");
2605 LeaveCriticalSection(&ddraw_cs
);
2606 return DDERR_INVALIDPARAMS
;
2608 if(newFormat
!= PixelFormat_DD2WineD3D(&This
->surface_desc
.u4
.ddpfPixelFormat
) )
2610 hr
= IWineD3DSurface_SetFormat(This
->WineD3DSurface
,
2614 LeaveCriticalSection(&ddraw_cs
);
2619 if (DDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2621 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2623 (WINEDDCOLORKEY
*) &DDSD
->u3
.ddckCKDestOverlay
);
2625 if (DDSD
->dwFlags
& DDSD_CKDESTBLT
)
2627 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2629 (WINEDDCOLORKEY
*) &DDSD
->ddckCKDestBlt
);
2631 if (DDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2633 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2635 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcOverlay
);
2637 if (DDSD
->dwFlags
& DDSD_CKSRCBLT
)
2639 IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2641 (WINEDDCOLORKEY
*) &DDSD
->ddckCKSrcBlt
);
2643 if (DDSD
->dwFlags
& DDSD_LPSURFACE
&& DDSD
->lpSurface
)
2645 hr
= IWineD3DSurface_SetMem(This
->WineD3DSurface
, DDSD
->lpSurface
);
2646 if(hr
!= WINED3D_OK
)
2648 /* No need for a trace here, wined3d does that for us */
2651 case WINED3DERR_INVALIDCALL
:
2652 LeaveCriticalSection(&ddraw_cs
);
2653 return DDERR_INVALIDPARAMS
;
2660 This
->surface_desc
= *DDSD
;
2662 LeaveCriticalSection(&ddraw_cs
);
2666 static HRESULT WINAPI
ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3
*iface
,
2667 DDSURFACEDESC
*surface_desc
, DWORD flags
)
2669 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface
, surface_desc
, flags
);
2671 return ddraw_surface7_SetSurfaceDesc((IDirectDrawSurface7
*)surface_from_surface3(iface
),
2672 (DDSURFACEDESC2
*)surface_desc
, flags
);
2675 /*****************************************************************************
2676 * IDirectDrawSurface7::GetPalette
2678 * Returns the IDirectDrawPalette interface of the palette currently assigned
2682 * Pal: Address to write the interface pointer to
2686 * DDERR_INVALIDPARAMS if Pal is NULL
2688 *****************************************************************************/
2689 static HRESULT WINAPI
ddraw_surface7_GetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
**Pal
)
2691 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2692 IWineD3DPalette
*wPal
;
2694 TRACE("(%p)->(%p): Relay\n", This
, Pal
);
2697 return DDERR_INVALIDPARAMS
;
2699 EnterCriticalSection(&ddraw_cs
);
2700 hr
= IWineD3DSurface_GetPalette(This
->WineD3DSurface
, &wPal
);
2703 LeaveCriticalSection(&ddraw_cs
);
2709 hr
= IWineD3DPalette_GetParent(wPal
, (IUnknown
**) Pal
);
2714 hr
= DDERR_NOPALETTEATTACHED
;
2717 LeaveCriticalSection(&ddraw_cs
);
2721 static HRESULT WINAPI
ddraw_surface3_GetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
**palette
)
2723 TRACE("iface %p, palette %p.\n", iface
, palette
);
2725 return ddraw_surface7_GetPalette((IDirectDrawSurface7
*)surface_from_surface3(iface
), palette
);
2728 /*****************************************************************************
2731 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2732 * recursively in the surface tree
2734 *****************************************************************************/
2738 WINEDDCOLORKEY
*CKey
;
2742 static HRESULT WINAPI
2743 SetColorKeyEnum(IDirectDrawSurface7
*surface
,
2744 DDSURFACEDESC2
*desc
,
2747 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)surface
;
2748 struct SCKContext
*ctx
= context
;
2751 hr
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
,
2756 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr
);
2760 ddraw_surface7_EnumAttachedSurfaces(surface
, context
, SetColorKeyEnum
);
2761 ddraw_surface7_Release(surface
);
2763 return DDENUMRET_OK
;
2766 /*****************************************************************************
2767 * IDirectDrawSurface7::SetColorKey
2769 * Sets the color keying options for the surface. Observations showed that
2770 * in case of complex surfaces the color key has to be assigned to all
2775 * CKey: The new color key
2779 * See IWineD3DSurface::SetColorKey for details
2781 *****************************************************************************/
2782 static HRESULT WINAPI
ddraw_surface7_SetColorKey(IDirectDrawSurface7
*iface
, DWORD Flags
, DDCOLORKEY
*CKey
)
2784 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2785 DDCOLORKEY FixedCKey
;
2786 struct SCKContext ctx
= { DD_OK
, (WINEDDCOLORKEY
*) (CKey
? &FixedCKey
: NULL
), Flags
};
2787 TRACE("(%p)->(%x,%p)\n", This
, Flags
, CKey
);
2789 EnterCriticalSection(&ddraw_cs
);
2793 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
2794 if (FixedCKey
.dwColorSpaceHighValue
< FixedCKey
.dwColorSpaceLowValue
)
2795 FixedCKey
.dwColorSpaceHighValue
= FixedCKey
.dwColorSpaceLowValue
;
2797 switch (Flags
& ~DDCKEY_COLORSPACE
)
2799 case DDCKEY_DESTBLT
:
2800 This
->surface_desc
.ddckCKDestBlt
= FixedCKey
;
2801 This
->surface_desc
.dwFlags
|= DDSD_CKDESTBLT
;
2804 case DDCKEY_DESTOVERLAY
:
2805 This
->surface_desc
.u3
.ddckCKDestOverlay
= FixedCKey
;
2806 This
->surface_desc
.dwFlags
|= DDSD_CKDESTOVERLAY
;
2809 case DDCKEY_SRCOVERLAY
:
2810 This
->surface_desc
.ddckCKSrcOverlay
= FixedCKey
;
2811 This
->surface_desc
.dwFlags
|= DDSD_CKSRCOVERLAY
;
2815 This
->surface_desc
.ddckCKSrcBlt
= FixedCKey
;
2816 This
->surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
2820 LeaveCriticalSection(&ddraw_cs
);
2821 return DDERR_INVALIDPARAMS
;
2826 switch (Flags
& ~DDCKEY_COLORSPACE
)
2828 case DDCKEY_DESTBLT
:
2829 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTBLT
;
2832 case DDCKEY_DESTOVERLAY
:
2833 This
->surface_desc
.dwFlags
&= ~DDSD_CKDESTOVERLAY
;
2836 case DDCKEY_SRCOVERLAY
:
2837 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCOVERLAY
;
2841 This
->surface_desc
.dwFlags
&= ~DDSD_CKSRCBLT
;
2845 LeaveCriticalSection(&ddraw_cs
);
2846 return DDERR_INVALIDPARAMS
;
2849 ctx
.ret
= IWineD3DSurface_SetColorKey(This
->WineD3DSurface
, Flags
, ctx
.CKey
);
2850 ddraw_surface7_EnumAttachedSurfaces(iface
, &ctx
, SetColorKeyEnum
);
2851 LeaveCriticalSection(&ddraw_cs
);
2854 case WINED3DERR_INVALIDCALL
: return DDERR_INVALIDPARAMS
;
2855 default: return ctx
.ret
;
2859 static HRESULT WINAPI
ddraw_surface3_SetColorKey(IDirectDrawSurface3
*iface
, DWORD flags
, DDCOLORKEY
*color_key
)
2861 TRACE("iface %p, flags %#x, color_key %p.\n", iface
, flags
, color_key
);
2863 return ddraw_surface7_SetColorKey((IDirectDrawSurface7
*)surface_from_surface3(iface
), flags
, color_key
);
2866 /*****************************************************************************
2867 * IDirectDrawSurface7::SetPalette
2869 * Assigns a DirectDrawPalette object to the surface
2872 * Pal: Interface to the palette to set
2877 *****************************************************************************/
2878 static HRESULT WINAPI
ddraw_surface7_SetPalette(IDirectDrawSurface7
*iface
, IDirectDrawPalette
*Pal
)
2880 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
2881 IDirectDrawPalette
*oldPal
;
2882 IDirectDrawSurfaceImpl
*surf
;
2883 IDirectDrawPaletteImpl
*PalImpl
= (IDirectDrawPaletteImpl
*)Pal
;
2885 TRACE("(%p)->(%p)\n", This
, Pal
);
2887 if (!(This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
|
2888 DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_PALETTEINDEXEDTO8
))) {
2889 return DDERR_INVALIDPIXELFORMAT
;
2892 /* Find the old palette */
2893 EnterCriticalSection(&ddraw_cs
);
2894 hr
= IDirectDrawSurface_GetPalette(iface
, &oldPal
);
2895 if(hr
!= DD_OK
&& hr
!= DDERR_NOPALETTEATTACHED
)
2897 LeaveCriticalSection(&ddraw_cs
);
2900 if(oldPal
) IDirectDrawPalette_Release(oldPal
); /* For the GetPalette */
2902 /* Set the new Palette */
2903 IWineD3DSurface_SetPalette(This
->WineD3DSurface
,
2904 PalImpl
? PalImpl
->wineD3DPalette
: NULL
);
2905 /* AddRef the Palette */
2906 if(Pal
) IDirectDrawPalette_AddRef(Pal
);
2908 /* Release the old palette */
2909 if(oldPal
) IDirectDrawPalette_Release(oldPal
);
2911 /* If this is a front buffer, also update the back buffers
2912 * TODO: How do things work for palettized cube textures?
2914 if(This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2916 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2917 DDSCAPS2 caps2
= { DDSCAPS_PRIMARYSURFACE
, 0, 0, 0 };
2922 IDirectDrawSurface7
*attach
;
2924 hr
= ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7
*)surf
, &caps2
, &attach
);
2930 TRACE("Setting palette on %p\n", attach
);
2931 ddraw_surface7_SetPalette(attach
, Pal
);
2932 surf
= (IDirectDrawSurfaceImpl
*)attach
;
2933 ddraw_surface7_Release(attach
);
2937 LeaveCriticalSection(&ddraw_cs
);
2941 static HRESULT WINAPI
ddraw_surface3_SetPalette(IDirectDrawSurface3
*iface
, IDirectDrawPalette
*palette
)
2943 TRACE("iface %p, palette %p.\n", iface
, palette
);
2945 return ddraw_surface7_SetPalette((IDirectDrawSurface7
*)surface_from_surface3(iface
), palette
);
2948 /**********************************************************
2949 * IDirectDrawGammaControl::GetGammaRamp
2951 * Returns the current gamma ramp for a surface
2955 * gamma_ramp: Address to write the ramp to
2959 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
2961 **********************************************************/
2962 static HRESULT WINAPI
ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl
*iface
,
2963 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
2965 IDirectDrawSurfaceImpl
*surface
= surface_from_gamma_control(iface
);
2967 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
2971 WARN("Invalid gamma_ramp passed.\n");
2972 return DDERR_INVALIDPARAMS
;
2975 EnterCriticalSection(&ddraw_cs
);
2976 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2978 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */
2979 IWineD3DDevice_GetGammaRamp(surface
->ddraw
->wineD3DDevice
, 0, (WINED3DGAMMARAMP
*)gamma_ramp
);
2983 ERR("Not implemented for non-primary surfaces.\n");
2985 LeaveCriticalSection(&ddraw_cs
);
2990 /**********************************************************
2991 * IDirectDrawGammaControl::SetGammaRamp
2993 * Sets the red, green and blue gamma ramps for
2996 * flags: Can be DDSGR_CALIBRATE to request calibration
2997 * gamma_ramp: Structure containing the new gamma ramp
3001 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
3003 **********************************************************/
3004 static HRESULT WINAPI
ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl
*iface
,
3005 DWORD flags
, DDGAMMARAMP
*gamma_ramp
)
3007 IDirectDrawSurfaceImpl
*surface
= surface_from_gamma_control(iface
);
3009 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface
, flags
, gamma_ramp
);
3013 WARN("Invalid gamma_ramp passed.\n");
3014 return DDERR_INVALIDPARAMS
;
3017 EnterCriticalSection(&ddraw_cs
);
3018 if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3020 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
3021 IWineD3DDevice_SetGammaRamp(surface
->ddraw
->wineD3DDevice
, 0, flags
, (WINED3DGAMMARAMP
*)gamma_ramp
);
3025 ERR("Not implemented for non-primary surfaces.\n");
3027 LeaveCriticalSection(&ddraw_cs
);
3032 /*****************************************************************************
3033 * IDirect3DTexture2::PaletteChanged
3035 * Informs the texture about a palette change
3038 * start: Start index of the change
3039 * count: The number of changed entries
3042 * D3D_OK, because it's a stub
3044 *****************************************************************************/
3045 static HRESULT WINAPI
d3d_texture2_PaletteChanged(IDirect3DTexture2
*iface
, DWORD start
, DWORD count
)
3047 FIXME("iface %p, start %u, count %u stub!\n", iface
, start
, count
);
3052 static HRESULT WINAPI
d3d_texture1_PaletteChanged(IDirect3DTexture
*iface
, DWORD start
, DWORD count
)
3054 IDirectDrawSurfaceImpl
*surface
= surface_from_texture1(iface
);
3056 TRACE("iface %p, start %u, count %u.\n", iface
, start
, count
);
3058 return d3d_texture2_PaletteChanged((IDirect3DTexture2
*)&surface
->IDirect3DTexture2_vtbl
, start
, count
);
3061 /*****************************************************************************
3062 * IDirect3DTexture::Unload
3064 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
3070 *****************************************************************************/
3071 static HRESULT WINAPI
d3d_texture1_Unload(IDirect3DTexture
*iface
)
3073 WARN("iface %p. Not implemented.\n", iface
);
3075 return DDERR_UNSUPPORTED
;
3078 /*****************************************************************************
3079 * IDirect3DTexture2::GetHandle
3081 * Returns handle for the texture. At the moment, the interface
3082 * to the IWineD3DTexture is used.
3085 * device: Device this handle is assigned to
3086 * handle: Address to store the handle at.
3091 *****************************************************************************/
3092 static HRESULT WINAPI
d3d_texture2_GetHandle(IDirect3DTexture2
*iface
,
3093 IDirect3DDevice2
*device
, D3DTEXTUREHANDLE
*handle
)
3095 IDirectDrawSurfaceImpl
*surface
= surface_from_texture2(iface
);
3097 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
3099 EnterCriticalSection(&ddraw_cs
);
3101 if (!surface
->Handle
)
3103 DWORD h
= ddraw_allocate_handle(&device_from_device2(device
)->handle_table
, surface
, DDRAW_HANDLE_SURFACE
);
3104 if (h
== DDRAW_INVALID_HANDLE
)
3106 ERR("Failed to allocate a texture handle.\n");
3107 LeaveCriticalSection(&ddraw_cs
);
3108 return DDERR_OUTOFMEMORY
;
3111 surface
->Handle
= h
+ 1;
3114 TRACE("Returning handle %08x.\n", surface
->Handle
);
3115 *handle
= surface
->Handle
;
3117 LeaveCriticalSection(&ddraw_cs
);
3122 static HRESULT WINAPI
d3d_texture1_GetHandle(IDirect3DTexture
*iface
,
3123 IDirect3DDevice
*device
, D3DTEXTUREHANDLE
*handle
)
3125 IDirect3DTexture2
*texture2
= (IDirect3DTexture2
*)&surface_from_texture1(iface
)->IDirect3DTexture2_vtbl
;
3126 IDirect3DDevice2
*device2
= (IDirect3DDevice2
*)&device_from_device1(device
)->IDirect3DDevice2_vtbl
;
3128 TRACE("iface %p, device %p, handle %p.\n", iface
, device
, handle
);
3130 return d3d_texture2_GetHandle(texture2
, device2
, handle
);
3133 /*****************************************************************************
3134 * get_sub_mimaplevel
3136 * Helper function that returns the next mipmap level
3138 * tex_ptr: Surface of which to return the next level
3140 *****************************************************************************/
3141 static IDirectDrawSurfaceImpl
*get_sub_mimaplevel(IDirectDrawSurfaceImpl
*surface
)
3143 /* Now go down the mipmap chain to the next surface */
3144 static DDSCAPS2 mipmap_caps
= { DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
, 0, 0, 0 };
3145 IDirectDrawSurface7
*next_level
;
3148 hr
= ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7
*)surface
, &mipmap_caps
, &next_level
);
3149 if (FAILED(hr
)) return NULL
;
3151 ddraw_surface7_Release(next_level
);
3153 return (IDirectDrawSurfaceImpl
*)next_level
;
3156 /*****************************************************************************
3157 * IDirect3DTexture2::Load
3159 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
3161 * This function isn't relayed to WineD3D because the whole interface is
3162 * implemented in DDraw only. For speed improvements a implementation which
3163 * takes OpenGL more into account could be placed into WineD3D.
3166 * src_texture: Address of the texture to load
3170 * D3DERR_TEXTURE_LOAD_FAILED.
3172 *****************************************************************************/
3173 static HRESULT WINAPI
d3d_texture2_Load(IDirect3DTexture2
*iface
, IDirect3DTexture2
*src_texture
)
3175 IDirectDrawSurfaceImpl
*dst_surface
= surface_from_texture2(iface
);
3176 IDirectDrawSurfaceImpl
*src_surface
= surface_from_texture2(src_texture
);
3179 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
3181 if (src_surface
== dst_surface
)
3183 TRACE("copying surface %p to surface %p, why?\n", src_surface
, dst_surface
);
3187 EnterCriticalSection(&ddraw_cs
);
3189 if (((src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3190 != (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
))
3191 || (src_surface
->surface_desc
.u2
.dwMipMapCount
!= dst_surface
->surface_desc
.u2
.dwMipMapCount
))
3193 ERR("Trying to load surfaces with different mip-map counts.\n");
3198 IWineD3DPalette
*wined3d_dst_pal
, *wined3d_src_pal
;
3199 IDirectDrawPalette
*dst_pal
= NULL
, *src_pal
= NULL
;
3200 DDSURFACEDESC
*src_desc
, *dst_desc
;
3202 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
3203 src_surface
, dst_surface
, src_surface
->mipmap_level
);
3205 /* Suppress the ALLOCONLOAD flag */
3206 dst_surface
->surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_ALLOCONLOAD
;
3208 /* Get the palettes */
3209 hr
= IWineD3DSurface_GetPalette(dst_surface
->WineD3DSurface
, &wined3d_dst_pal
);
3212 ERR("Failed to get destination palette, hr %#x.\n", hr
);
3213 LeaveCriticalSection(&ddraw_cs
);
3214 return D3DERR_TEXTURE_LOAD_FAILED
;
3216 if (wined3d_dst_pal
)
3218 hr
= IWineD3DPalette_GetParent(wined3d_dst_pal
, (IUnknown
**)&dst_pal
);
3221 ERR("Failed to get destination palette parent, hr %#x.\n", hr
);
3222 LeaveCriticalSection(&ddraw_cs
);
3223 return D3DERR_TEXTURE_LOAD_FAILED
;
3227 hr
= IWineD3DSurface_GetPalette(src_surface
->WineD3DSurface
, &wined3d_src_pal
);
3230 ERR("Failed to get source palette, hr %#x.\n", hr
);
3231 LeaveCriticalSection(&ddraw_cs
);
3232 return D3DERR_TEXTURE_LOAD_FAILED
;
3234 if (wined3d_src_pal
)
3236 hr
= IWineD3DPalette_GetParent(wined3d_src_pal
, (IUnknown
**)&src_pal
);
3239 ERR("Failed to get source palette parent, hr %#x.\n", hr
);
3240 if (dst_pal
) IDirectDrawPalette_Release(dst_pal
);
3241 LeaveCriticalSection(&ddraw_cs
);
3242 return D3DERR_TEXTURE_LOAD_FAILED
;
3248 PALETTEENTRY palent
[256];
3252 IDirectDrawPalette_Release(src_pal
);
3253 LeaveCriticalSection(&ddraw_cs
);
3254 return DDERR_NOPALETTEATTACHED
;
3256 IDirectDrawPalette_GetEntries(src_pal
, 0, 0, 256, palent
);
3257 IDirectDrawPalette_SetEntries(dst_pal
, 0, 0, 256, palent
);
3260 if (dst_pal
) IDirectDrawPalette_Release(dst_pal
);
3261 if (src_pal
) IDirectDrawPalette_Release(src_pal
);
3263 /* Copy one surface on the other */
3264 dst_desc
= (DDSURFACEDESC
*)&(dst_surface
->surface_desc
);
3265 src_desc
= (DDSURFACEDESC
*)&(src_surface
->surface_desc
);
3267 if ((src_desc
->dwWidth
!= dst_desc
->dwWidth
) || (src_desc
->dwHeight
!= dst_desc
->dwHeight
))
3269 /* Should also check for same pixel format, u1.lPitch, ... */
3270 ERR("Error in surface sizes.\n");
3271 LeaveCriticalSection(&ddraw_cs
);
3272 return D3DERR_TEXTURE_LOAD_FAILED
;
3276 WINED3DLOCKED_RECT src_rect
, dst_rect
;
3278 /* Copy also the ColorKeying stuff */
3279 if (src_desc
->dwFlags
& DDSD_CKSRCBLT
)
3281 dst_desc
->dwFlags
|= DDSD_CKSRCBLT
;
3282 dst_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceLowValue
;
3283 dst_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
= src_desc
->ddckCKSrcBlt
.dwColorSpaceHighValue
;
3286 /* Copy the main memory texture into the surface that corresponds
3287 * to the OpenGL texture object. */
3289 hr
= IWineD3DSurface_LockRect(src_surface
->WineD3DSurface
, &src_rect
, NULL
, 0);
3292 ERR("Failed to lock source surface, hr %#x.\n", hr
);
3293 LeaveCriticalSection(&ddraw_cs
);
3294 return D3DERR_TEXTURE_LOAD_FAILED
;
3297 hr
= IWineD3DSurface_LockRect(dst_surface
->WineD3DSurface
, &dst_rect
, NULL
, 0);
3300 ERR("Failed to lock destination surface, hr %#x.\n", hr
);
3301 IWineD3DSurface_UnlockRect(src_surface
->WineD3DSurface
);
3302 LeaveCriticalSection(&ddraw_cs
);
3303 return D3DERR_TEXTURE_LOAD_FAILED
;
3306 if (dst_surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
3307 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_surface
->surface_desc
.u1
.dwLinearSize
);
3309 memcpy(dst_rect
.pBits
, src_rect
.pBits
, src_rect
.Pitch
* src_desc
->dwHeight
);
3311 IWineD3DSurface_UnlockRect(src_surface
->WineD3DSurface
);
3312 IWineD3DSurface_UnlockRect(dst_surface
->WineD3DSurface
);
3315 if (src_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3316 src_surface
= get_sub_mimaplevel(src_surface
);
3320 if (dst_surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3321 dst_surface
= get_sub_mimaplevel(dst_surface
);
3325 if (!src_surface
|| !dst_surface
)
3327 if (src_surface
!= dst_surface
)
3328 ERR("Loading surface with different mipmap structure.\n");
3333 LeaveCriticalSection(&ddraw_cs
);
3338 static HRESULT WINAPI
d3d_texture1_Load(IDirect3DTexture
*iface
, IDirect3DTexture
*src_texture
)
3340 TRACE("iface %p, src_texture %p.\n", iface
, src_texture
);
3342 return d3d_texture2_Load((IDirect3DTexture2
*)&surface_from_texture1(iface
)->IDirect3DTexture2_vtbl
,
3343 src_texture
? (IDirect3DTexture2
*)&surface_from_texture1(src_texture
)->IDirect3DTexture2_vtbl
: NULL
);
3346 /*****************************************************************************
3348 *****************************************************************************/
3350 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
=
3353 ddraw_surface7_QueryInterface
,
3354 ddraw_surface7_AddRef
,
3355 ddraw_surface7_Release
,
3356 /* IDirectDrawSurface */
3357 ddraw_surface7_AddAttachedSurface
,
3358 ddraw_surface7_AddOverlayDirtyRect
,
3360 ddraw_surface7_BltBatch
,
3361 ddraw_surface7_BltFast
,
3362 ddraw_surface7_DeleteAttachedSurface
,
3363 ddraw_surface7_EnumAttachedSurfaces
,
3364 ddraw_surface7_EnumOverlayZOrders
,
3365 ddraw_surface7_Flip
,
3366 ddraw_surface7_GetAttachedSurface
,
3367 ddraw_surface7_GetBltStatus
,
3368 ddraw_surface7_GetCaps
,
3369 ddraw_surface7_GetClipper
,
3370 ddraw_surface7_GetColorKey
,
3371 ddraw_surface7_GetDC
,
3372 ddraw_surface7_GetFlipStatus
,
3373 ddraw_surface7_GetOverlayPosition
,
3374 ddraw_surface7_GetPalette
,
3375 ddraw_surface7_GetPixelFormat
,
3376 ddraw_surface7_GetSurfaceDesc
,
3377 ddraw_surface7_Initialize
,
3378 ddraw_surface7_IsLost
,
3379 ddraw_surface7_Lock
,
3380 ddraw_surface7_ReleaseDC
,
3381 ddraw_surface7_Restore
,
3382 ddraw_surface7_SetClipper
,
3383 ddraw_surface7_SetColorKey
,
3384 ddraw_surface7_SetOverlayPosition
,
3385 ddraw_surface7_SetPalette
,
3386 ddraw_surface7_Unlock
,
3387 ddraw_surface7_UpdateOverlay
,
3388 ddraw_surface7_UpdateOverlayDisplay
,
3389 ddraw_surface7_UpdateOverlayZOrder
,
3390 /* IDirectDrawSurface2 */
3391 ddraw_surface7_GetDDInterface
,
3392 ddraw_surface7_PageLock
,
3393 ddraw_surface7_PageUnlock
,
3394 /* IDirectDrawSurface3 */
3395 ddraw_surface7_SetSurfaceDesc
,
3396 /* IDirectDrawSurface4 */
3397 ddraw_surface7_SetPrivateData
,
3398 ddraw_surface7_GetPrivateData
,
3399 ddraw_surface7_FreePrivateData
,
3400 ddraw_surface7_GetUniquenessValue
,
3401 ddraw_surface7_ChangeUniquenessValue
,
3402 /* IDirectDrawSurface7 */
3403 ddraw_surface7_SetPriority
,
3404 ddraw_surface7_GetPriority
,
3405 ddraw_surface7_SetLOD
,
3406 ddraw_surface7_GetLOD
,
3409 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl
=
3412 ddraw_surface3_QueryInterface
,
3413 ddraw_surface3_AddRef
,
3414 ddraw_surface3_Release
,
3415 /* IDirectDrawSurface */
3416 ddraw_surface3_AddAttachedSurface
,
3417 ddraw_surface3_AddOverlayDirtyRect
,
3419 ddraw_surface3_BltBatch
,
3420 ddraw_surface3_BltFast
,
3421 ddraw_surface3_DeleteAttachedSurface
,
3422 ddraw_surface3_EnumAttachedSurfaces
,
3423 ddraw_surface3_EnumOverlayZOrders
,
3424 ddraw_surface3_Flip
,
3425 ddraw_surface3_GetAttachedSurface
,
3426 ddraw_surface3_GetBltStatus
,
3427 ddraw_surface3_GetCaps
,
3428 ddraw_surface3_GetClipper
,
3429 ddraw_surface3_GetColorKey
,
3430 ddraw_surface3_GetDC
,
3431 ddraw_surface3_GetFlipStatus
,
3432 ddraw_surface3_GetOverlayPosition
,
3433 ddraw_surface3_GetPalette
,
3434 ddraw_surface3_GetPixelFormat
,
3435 ddraw_surface3_GetSurfaceDesc
,
3436 ddraw_surface3_Initialize
,
3437 ddraw_surface3_IsLost
,
3438 ddraw_surface3_Lock
,
3439 ddraw_surface3_ReleaseDC
,
3440 ddraw_surface3_Restore
,
3441 ddraw_surface3_SetClipper
,
3442 ddraw_surface3_SetColorKey
,
3443 ddraw_surface3_SetOverlayPosition
,
3444 ddraw_surface3_SetPalette
,
3445 ddraw_surface3_Unlock
,
3446 ddraw_surface3_UpdateOverlay
,
3447 ddraw_surface3_UpdateOverlayDisplay
,
3448 ddraw_surface3_UpdateOverlayZOrder
,
3449 /* IDirectDrawSurface2 */
3450 ddraw_surface3_GetDDInterface
,
3451 ddraw_surface3_PageLock
,
3452 ddraw_surface3_PageUnlock
,
3453 /* IDirectDrawSurface3 */
3454 ddraw_surface3_SetSurfaceDesc
,
3457 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl
=
3459 ddraw_gamma_control_QueryInterface
,
3460 ddraw_gamma_control_AddRef
,
3461 ddraw_gamma_control_Release
,
3462 ddraw_gamma_control_GetGammaRamp
,
3463 ddraw_gamma_control_SetGammaRamp
,
3466 const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl
=
3468 d3d_texture2_QueryInterface
,
3469 d3d_texture2_AddRef
,
3470 d3d_texture2_Release
,
3471 d3d_texture2_GetHandle
,
3472 d3d_texture2_PaletteChanged
,
3476 const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl
=
3478 d3d_texture1_QueryInterface
,
3479 d3d_texture1_AddRef
,
3480 d3d_texture1_Release
,
3481 d3d_texture1_Initialize
,
3482 d3d_texture1_GetHandle
,
3483 d3d_texture1_PaletteChanged
,
3485 d3d_texture1_Unload
,