wined3d: read_from_framebuffer_texture() isn't suitable for readback of onscreen...
[wine/testsucceed.git] / dlls / ddraw / surface.c
blobbfe83a4905ed29ae66e5fc7d03b8ca813e122d42
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
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <stdlib.h>
34 #define COBJMACROS
35 #define NONAMELESSUNION
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "wingdi.h"
41 #include "wine/exception.h"
43 #include "ddraw.h"
44 #include "d3d.h"
46 #include "ddraw_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
51 /*****************************************************************************
52 * IUnknown parts follow
53 *****************************************************************************/
55 /*****************************************************************************
56 * IDirectDrawSurface7::QueryInterface
58 * A normal QueryInterface implementation. For QueryInterface rules
59 * see ddraw.c, IDirectDraw7::QueryInterface. This method
60 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
61 * in all versions, the IDirectDrawGammaControl interface and it can
62 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
64 * Params:
65 * riid: The interface id queried for
66 * obj: Address to write the pointer to
68 * Returns:
69 * S_OK on success
70 * E_NOINTERFACE if the requested interface wasn't found
72 *****************************************************************************/
73 static HRESULT WINAPI
74 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
75 REFIID riid,
76 void **obj)
78 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
80 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
81 *obj = NULL;
83 if(!riid)
84 return DDERR_INVALIDPARAMS;
86 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
87 if (IsEqualGUID(riid, &IID_IUnknown)
88 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
89 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
91 IUnknown_AddRef(iface);
92 *obj = iface;
93 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
94 return S_OK;
96 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
97 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
98 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
100 IUnknown_AddRef(iface);
101 *obj = &This->IDirectDrawSurface3_vtbl;
102 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
103 return S_OK;
105 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
107 IUnknown_AddRef(iface);
108 *obj = &This->IDirectDrawGammaControl_vtbl;
109 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
110 return S_OK;
112 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
113 IsEqualGUID(riid, &IID_IDirect3DHALDevice)||
114 IsEqualGUID(riid, &IID_IDirect3DRGBDevice) )
116 IDirect3DDevice7 *d3d;
118 /* Call into IDirect3D7 for creation */
119 IDirect3D7_CreateDevice((IDirect3D7 *)&This->ddraw->IDirect3D7_vtbl, riid, (IDirectDrawSurface7 *)This, &d3d);
121 *obj = d3d ? (IDirect3DDevice *)&((IDirect3DDeviceImpl *)d3d)->IDirect3DDevice_vtbl : NULL;
122 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
124 return S_OK;
126 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
127 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
129 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
131 *obj = &This->IDirect3DTexture_vtbl;
132 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
134 else
136 *obj = &This->IDirect3DTexture2_vtbl;
137 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
139 IUnknown_AddRef( (IUnknown *) *obj);
140 return S_OK;
143 ERR("No interface\n");
144 return E_NOINTERFACE;
147 /*****************************************************************************
148 * IDirectDrawSurface7::AddRef
150 * A normal addref implementation
152 * Returns:
153 * The new refcount
155 *****************************************************************************/
156 static ULONG WINAPI
157 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
159 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
160 ULONG refCount = InterlockedIncrement(&This->ref);
162 if (refCount == 1 && This->WineD3DSurface)
164 EnterCriticalSection(&ddraw_cs);
165 IWineD3DSurface_AddRef(This->WineD3DSurface);
166 LeaveCriticalSection(&ddraw_cs);
169 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
170 return refCount;
173 /*****************************************************************************
174 * IDirectDrawSurfaceImpl_Destroy
176 * A helper function for IDirectDrawSurface7::Release
178 * Frees the surface, regardless of its refcount.
179 * See IDirectDrawSurface7::Release for more information
181 * Params:
182 * This: Surface to free
184 *****************************************************************************/
185 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
187 TRACE("(%p)\n", This);
189 /* Check the refcount and give a warning */
190 if(This->ref > 1)
192 /* This can happen when a complex surface is destroyed,
193 * because the 2nd surface was addref()ed when the app
194 * called GetAttachedSurface
196 WARN("(%p): Destroying surface with refount %d\n", This, This->ref);
199 /* Check for attached surfaces and detach them */
200 if(This->first_attached != This)
202 /* Well, this shouldn't happen: The surface being attached is addref()ed
203 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
204 * is called, because the refcount is held. It looks like the app released()
205 * it often enough to force this
207 IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)This->first_attached;
208 IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)This;
210 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
212 /* The refcount will drop to -1 here */
213 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
215 ERR("(%p) DeleteAttachedSurface failed!\n", This);
219 while(This->next_attached != NULL)
221 IDirectDrawSurface7 *root = (IDirectDrawSurface7 *)This;
222 IDirectDrawSurface7 *detach = (IDirectDrawSurface7 *)This->next_attached;
224 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
226 ERR("(%p) DeleteAttachedSurface failed!\n", This);
227 assert(0);
231 /* Now destroy the surface. Wait: It could have been released if we are a texture */
232 if(This->WineD3DSurface)
233 IWineD3DSurface_Release(This->WineD3DSurface);
235 /* Having a texture handle set implies that the device still exists */
236 if(This->Handle)
238 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
239 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
242 /* Reduce the ddraw surface count */
243 InterlockedDecrement(&This->ddraw->surfaces);
244 list_remove(&This->surface_list_entry);
246 HeapFree(GetProcessHeap(), 0, This);
249 /*****************************************************************************
250 * IDirectDrawSurface7::Release
252 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
253 * surface is destroyed.
255 * Destroying the surface is a bit tricky. For the connection between
256 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
257 * It has a nice graph explaining the connection.
259 * What happens here is basically this:
260 * When a surface is destroyed, its WineD3DSurface is released,
261 * and the refcount of the DirectDraw interface is reduced by 1. If it has
262 * complex surfaces attached to it, then these surfaces are destroyed too,
263 * regardless of their refcount. If any surface being destroyed has another
264 * surface attached to it (with a "soft" attachment, not complex), then
265 * this surface is detached with DeleteAttachedSurface.
267 * When the surface is a texture, the WineD3DTexture is released.
268 * If the surface is the Direct3D render target, then the D3D
269 * capabilities of the WineD3DDevice are uninitialized, which causes the
270 * swapchain to be released.
272 * When a complex sublevel falls to ref zero, then this is ignored.
274 * Returns:
275 * The new refcount
277 *****************************************************************************/
278 static ULONG WINAPI
279 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
281 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
282 ULONG ref;
283 TRACE("(%p) : Releasing from %d\n", This, This->ref);
284 ref = InterlockedDecrement(&This->ref);
286 if (ref == 0)
289 IDirectDrawSurfaceImpl *surf;
290 IDirectDrawImpl *ddraw;
291 IUnknown *ifaceToRelease = This->ifaceToRelease;
292 UINT i;
294 /* Complex attached surfaces are destroyed implicitly when the root is released */
295 EnterCriticalSection(&ddraw_cs);
296 if(!This->is_complex_root)
298 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
299 LeaveCriticalSection(&ddraw_cs);
300 return ref;
302 ddraw = This->ddraw;
304 /* If it's a texture, destroy the WineD3DTexture.
305 * WineD3D will destroy the IParent interfaces
306 * of the sublevels, which destroys the WineD3DSurfaces.
307 * Set the surfaces to NULL to avoid destroying them again later
309 if(This->wineD3DTexture)
311 IWineD3DBaseTexture_Release(This->wineD3DTexture);
313 /* If it's the RenderTarget, destroy the d3ddevice */
314 else if(This->wineD3DSwapChain)
316 if((ddraw->d3d_initialized) && (This == ddraw->d3d_target)) {
317 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
319 /* Unset any index buffer, just to be sure */
320 IWineD3DDevice_SetIndexBuffer(ddraw->wineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
321 IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
322 IWineD3DDevice_SetVertexDeclaration(ddraw->wineD3DDevice, NULL);
323 for(i = 0; i < ddraw->numConvertedDecls; i++)
325 IWineD3DVertexDeclaration_Release(ddraw->decls[i].decl);
327 HeapFree(GetProcessHeap(), 0, ddraw->decls);
328 ddraw->numConvertedDecls = 0;
330 if (FAILED(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice, D3D7CB_DestroySwapChain)))
332 /* Not good */
333 ERR("(%p) Failed to uninit 3D\n", This);
335 else
337 /* Free the d3d window if one was created */
338 if(ddraw->d3d_window != 0 && ddraw->d3d_window != ddraw->dest_window)
340 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
341 DestroyWindow(ddraw->d3d_window);
342 ddraw->d3d_window = 0;
344 /* Unset the pointers */
347 This->wineD3DSwapChain = NULL; /* Uninit3D releases the swapchain */
348 ddraw->d3d_initialized = FALSE;
349 ddraw->d3d_target = NULL;
350 } else {
351 IWineD3DDevice_UninitGDI(ddraw->wineD3DDevice, D3D7CB_DestroySwapChain);
352 This->wineD3DSwapChain = NULL;
355 /* Reset to the default surface implementation type. This is needed if apps use
356 * non render target surfaces and expect blits to work after destroying the render
357 * target.
359 * TODO: Recreate existing offscreen surfaces
361 ddraw->ImplType = DefaultSurfaceType;
363 /* Write a trace because D3D unloading was the reason for many
364 * crashes during development.
366 TRACE("(%p) D3D unloaded\n", This);
369 /* The refcount test shows that the palette is detached when the surface is destroyed */
370 IDirectDrawSurface7_SetPalette((IDirectDrawSurface7 *)This, NULL);
372 /* Loop through all complex attached surfaces,
373 * and destroy them.
375 * Yet again, only the root can have more than one complexly attached surface, all the others
376 * have a total of one;
378 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
380 if(!This->complex_array[i]) break;
382 surf = This->complex_array[i];
383 This->complex_array[i] = NULL;
384 while(surf)
386 IDirectDrawSurfaceImpl *destroy = surf;
387 surf = surf->complex_array[0]; /* Iterate through the "tree" */
388 IDirectDrawSurfaceImpl_Destroy(destroy); /* Destroy it */
392 /* Destroy the root surface.
394 IDirectDrawSurfaceImpl_Destroy(This);
396 /* Reduce the ddraw refcount */
397 if(ifaceToRelease) IUnknown_Release(ifaceToRelease);
398 LeaveCriticalSection(&ddraw_cs);
401 return ref;
404 /*****************************************************************************
405 * IDirectDrawSurface7::GetAttachedSurface
407 * Returns an attached surface with the requested caps. Surface attachment
408 * and complex surfaces are not clearly described by the MSDN or sdk,
409 * so this method is tricky and likely to contain problems.
410 * This implementation searches the complex list first, then the
411 * attachment chain.
413 * The chains are searched from This down to the last surface in the chain,
414 * not from the first element in the chain. The first surface found is
415 * returned. The MSDN says that this method fails if more than one surface
416 * matches the caps, but it is not sure if that is right. The attachment
417 * structure may not even allow two matching surfaces.
419 * The found surface is AddRef-ed before it is returned.
421 * Params:
422 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
423 * Surface: Address to store the found surface
425 * Returns:
426 * DD_OK on success
427 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
428 * DDERR_NOTFOUND if no surface was found
430 *****************************************************************************/
431 static HRESULT WINAPI
432 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
433 DDSCAPS2 *Caps,
434 IDirectDrawSurface7 **Surface)
436 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
437 IDirectDrawSurfaceImpl *surf;
438 DDSCAPS2 our_caps;
439 int i;
441 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
442 EnterCriticalSection(&ddraw_cs);
444 if(This->version < 7)
446 /* Earlier dx apps put garbage into these members, clear them */
447 our_caps.dwCaps = Caps->dwCaps;
448 our_caps.dwCaps2 = 0;
449 our_caps.dwCaps3 = 0;
450 our_caps.dwCaps4 = 0;
452 else
454 our_caps = *Caps;
457 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 */
459 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
461 surf = This->complex_array[i];
462 if(!surf) break;
464 if (TRACE_ON(ddraw))
466 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
467 surf->surface_desc.ddsCaps.dwCaps,
468 surf->surface_desc.ddsCaps.dwCaps2,
469 surf->surface_desc.ddsCaps.dwCaps3,
470 surf->surface_desc.ddsCaps.dwCaps4);
473 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
474 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
476 /* MSDN: "This method fails if more than one surface is attached
477 * that matches the capabilities requested."
479 * Not sure how to test this.
482 TRACE("(%p): Returning surface %p\n", This, surf);
483 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
484 *Surface = (IDirectDrawSurface7 *)surf;
485 IDirectDrawSurface7_AddRef(*Surface);
486 LeaveCriticalSection(&ddraw_cs);
487 return DD_OK;
491 /* Next, look at the attachment chain */
492 surf = This;
494 while( (surf = surf->next_attached) )
496 if (TRACE_ON(ddraw))
498 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
499 surf->surface_desc.ddsCaps.dwCaps,
500 surf->surface_desc.ddsCaps.dwCaps2,
501 surf->surface_desc.ddsCaps.dwCaps3,
502 surf->surface_desc.ddsCaps.dwCaps4);
505 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
506 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
508 TRACE("(%p): Returning surface %p\n", This, surf);
509 *Surface = (IDirectDrawSurface7 *)surf;
510 IDirectDrawSurface7_AddRef(*Surface);
511 LeaveCriticalSection(&ddraw_cs);
512 return DD_OK;
516 TRACE("(%p) Didn't find a valid surface\n", This);
517 LeaveCriticalSection(&ddraw_cs);
519 *Surface = NULL;
520 return DDERR_NOTFOUND;
523 /*****************************************************************************
524 * IDirectDrawSurface7::Lock
526 * Locks the surface and returns a pointer to the surface's memory
528 * Params:
529 * Rect: Rectangle to lock. If NULL, the whole surface is locked
530 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
531 * Flags: Locking flags, e.g Read only or write only
532 * h: An event handle that's not used and must be NULL
534 * Returns:
535 * DD_OK on success
536 * DDERR_INVALIDPARAMS if DDSD is NULL
537 * For more details, see IWineD3DSurface::LockRect
539 *****************************************************************************/
540 static HRESULT WINAPI
541 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
542 RECT *Rect,
543 DDSURFACEDESC2 *DDSD,
544 DWORD Flags,
545 HANDLE h)
547 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
548 WINED3DLOCKED_RECT LockedRect;
549 HRESULT hr;
550 TRACE("(%p)->(%p,%p,%x,%p)\n", This, Rect, DDSD, Flags, h);
552 if(!DDSD)
553 return DDERR_INVALIDPARAMS;
555 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
556 EnterCriticalSection(&ddraw_cs);
558 /* Should I check for the handle to be NULL?
560 * The DDLOCK flags and the D3DLOCK flags are equal
561 * for the supported values. The others are ignored by WineD3D
564 if(DDSD->dwSize != sizeof(DDSURFACEDESC) &&
565 DDSD->dwSize != sizeof(DDSURFACEDESC2))
567 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", DDERR_INVALIDPARAMS);
568 LeaveCriticalSection(&ddraw_cs);
569 return DDERR_INVALIDPARAMS;
572 /* Windows zeroes this if the rect is invalid */
573 DDSD->lpSurface = 0;
575 if (Rect)
577 if ((Rect->left < 0)
578 || (Rect->top < 0)
579 || (Rect->left > Rect->right)
580 || (Rect->top > Rect->bottom)
581 || (Rect->right > This->surface_desc.dwWidth)
582 || (Rect->bottom > This->surface_desc.dwHeight))
584 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
585 LeaveCriticalSection(&ddraw_cs);
586 return DDERR_INVALIDPARAMS;
590 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
591 &LockedRect,
592 Rect,
593 Flags);
594 if(hr != D3D_OK)
596 LeaveCriticalSection(&ddraw_cs);
597 switch(hr)
599 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
600 * specific error. But since IWineD3DSurface::LockRect returns that error in this
601 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
602 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
603 * is much easier to do it in one place in ddraw
605 case WINED3DERR_INVALIDCALL: return DDERR_SURFACEBUSY;
606 default: return hr;
610 /* Override the memory area. The pitch should be set already. Strangely windows
611 * does not set the LPSURFACE flag on locked surfaces !?!.
612 * DDSD->dwFlags |= DDSD_LPSURFACE;
614 This->surface_desc.lpSurface = LockedRect.pBits;
615 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
617 TRACE("locked surface returning description :\n");
618 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
620 LeaveCriticalSection(&ddraw_cs);
621 return DD_OK;
624 /*****************************************************************************
625 * IDirectDrawSurface7::Unlock
627 * Unlocks an locked surface
629 * Params:
630 * Rect: Not used by this implementation
632 * Returns:
633 * D3D_OK on success
634 * For more details, see IWineD3DSurface::UnlockRect
636 *****************************************************************************/
637 static HRESULT WINAPI
638 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
639 RECT *pRect)
641 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
642 HRESULT hr;
643 TRACE("(%p)->(%p)\n", This, pRect);
645 EnterCriticalSection(&ddraw_cs);
646 hr = IWineD3DSurface_UnlockRect(This->WineD3DSurface);
647 if(SUCCEEDED(hr))
649 This->surface_desc.lpSurface = NULL;
651 LeaveCriticalSection(&ddraw_cs);
652 return hr;
655 /*****************************************************************************
656 * IDirectDrawSurface7::Flip
658 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
659 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
660 * the flip target is passed to WineD3D, even if the app didn't specify one
662 * Params:
663 * DestOverride: Specifies the surface that will become the new front
664 * buffer. If NULL, the current back buffer is used
665 * Flags: some DirectDraw flags, see include/ddraw.h
667 * Returns:
668 * DD_OK on success
669 * DDERR_NOTFLIPPABLE if no flip target could be found
670 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
671 * For more details, see IWineD3DSurface::Flip
673 *****************************************************************************/
674 static HRESULT WINAPI
675 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
676 IDirectDrawSurface7 *DestOverride,
677 DWORD Flags)
679 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
680 IDirectDrawSurfaceImpl *Override = (IDirectDrawSurfaceImpl *)DestOverride;
681 IDirectDrawSurface7 *Override7;
682 HRESULT hr;
683 TRACE("(%p)->(%p,%x)\n", This, DestOverride, Flags);
685 /* Flip has to be called from a front buffer
686 * What about overlay surfaces, AFAIK they can flip too?
688 if( !(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_OVERLAY)) )
689 return DDERR_INVALIDOBJECT; /* Unchecked */
691 EnterCriticalSection(&ddraw_cs);
693 /* WineD3D doesn't keep track of attached surface, so find the target */
694 if(!Override)
696 DDSCAPS2 Caps;
698 memset(&Caps, 0, sizeof(Caps));
699 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
700 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
701 if(hr != DD_OK)
703 ERR("Can't find a flip target\n");
704 LeaveCriticalSection(&ddraw_cs);
705 return DDERR_NOTFLIPPABLE; /* Unchecked */
707 Override = (IDirectDrawSurfaceImpl *)Override7;
709 /* For the GetAttachedSurface */
710 IDirectDrawSurface7_Release(Override7);
713 hr = IWineD3DSurface_Flip(This->WineD3DSurface,
714 Override->WineD3DSurface,
715 Flags);
716 LeaveCriticalSection(&ddraw_cs);
717 return hr;
720 /*****************************************************************************
721 * IDirectDrawSurface7::Blt
723 * Performs a blit on the surface
725 * Params:
726 * DestRect: Destination rectangle, can be NULL
727 * SrcSurface: Source surface, can be NULL
728 * SrcRect: Source rectangle, can be NULL
729 * Flags: Blt flags
730 * DDBltFx: Some extended blt parameters, connected to the flags
732 * Returns:
733 * D3D_OK on success
734 * See IWineD3DSurface::Blt for more details
736 *****************************************************************************/
737 static HRESULT WINAPI
738 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
739 RECT *DestRect,
740 IDirectDrawSurface7 *SrcSurface,
741 RECT *SrcRect,
742 DWORD Flags,
743 DDBLTFX *DDBltFx)
745 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
746 IDirectDrawSurfaceImpl *Src = (IDirectDrawSurfaceImpl *)SrcSurface;
747 HRESULT hr;
748 TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
750 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
751 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
753 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
754 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
755 return DDERR_INVALIDPARAMS;
758 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
759 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
760 return DDERR_INVALIDPARAMS;
763 /* Sizes can change, therefore hold the lock when testing the rectangles */
764 EnterCriticalSection(&ddraw_cs);
765 if(DestRect)
767 if(DestRect->top >= DestRect->bottom || DestRect->left >= DestRect->right ||
768 DestRect->right > This->surface_desc.dwWidth ||
769 DestRect->bottom > This->surface_desc.dwHeight)
771 WARN("Destination rectangle is invalid, returning DDERR_INVALIDRECT\n");
772 LeaveCriticalSection(&ddraw_cs);
773 return DDERR_INVALIDRECT;
776 if(Src && SrcRect)
778 if(SrcRect->top >= SrcRect->bottom || SrcRect->left >=SrcRect->right ||
779 SrcRect->right > Src->surface_desc.dwWidth ||
780 SrcRect->bottom > Src->surface_desc.dwHeight)
782 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
783 LeaveCriticalSection(&ddraw_cs);
784 return DDERR_INVALIDRECT;
788 if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
789 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
790 LeaveCriticalSection(&ddraw_cs);
791 return DDERR_INVALIDPARAMS;
794 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it does, copy the struct,
795 * and replace the ddraw surfaces with the wined3d surfaces
796 * So far no blitting operations using surfaces in the bltfx struct are supported anyway.
798 hr = IWineD3DSurface_Blt(This->WineD3DSurface,
799 DestRect,
800 Src ? Src->WineD3DSurface : NULL,
801 SrcRect,
802 Flags,
803 (WINEDDBLTFX *) DDBltFx,
804 WINED3DTEXF_POINT);
806 LeaveCriticalSection(&ddraw_cs);
807 switch(hr)
809 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
810 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
811 default: return hr;
815 /*****************************************************************************
816 * IDirectDrawSurface7::AddAttachedSurface
818 * Attaches a surface to another surface. How the surface attachments work
819 * is not totally understood yet, and this method is prone to problems.
820 * he surface that is attached is AddRef-ed.
822 * Tests with complex surfaces suggest that the surface attachments form a
823 * tree, but no method to test this has been found yet.
825 * The attachment list consists of a first surface (first_attached) and
826 * for each surface a pointer to the next attached surface (next_attached).
827 * For the first surface, and a surface that has no attachments
828 * first_attached points to the surface itself. A surface that has
829 * no successors in the chain has next_attached set to NULL.
831 * Newly attached surfaces are attached right after the root surface.
832 * If a surface is attached to a complex surface compound, it's attached to
833 * the surface that the app requested, not the complex root. See
834 * GetAttachedSurface for a description how surfaces are found.
836 * This is how the current implementation works, and it was coded by looking
837 * at the needs of the applications.
839 * So far only Z-Buffer attachments are tested, and they are activated in
840 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
841 * Back buffers should work in 2D mode, but they are not tested(They can be
842 * attached in older iface versions). Rendering to the front buffer and
843 * switching between that and double buffering is not yet implemented in
844 * WineD3D, so for 3D it might have unexpected results.
846 * IDirectDrawSurfaceImpl_AddAttachedSurface is the real thing,
847 * IDirectDrawSurface7Impl_AddAttachedSurface is a wrapper around it that
848 * performs additional checks. Version 7 of this interface is much more restrictive
849 * than its predecessors.
851 * Params:
852 * Attach: Surface to attach to iface
854 * Returns:
855 * DD_OK on success
856 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
858 *****************************************************************************/
859 HRESULT WINAPI
860 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This,
861 IDirectDrawSurfaceImpl *Surf)
863 TRACE("(%p)->(%p)\n", This, Surf);
865 if(Surf == This)
866 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
868 EnterCriticalSection(&ddraw_cs);
870 /* Check if the surface is already attached somewhere */
871 if( (Surf->next_attached != NULL) ||
872 (Surf->first_attached != Surf) )
874 /* TODO: Test for the structure of the manual attachment. Is it a chain or a list?
875 * What happens if one surface is attached to 2 different surfaces?
877 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);
878 LeaveCriticalSection(&ddraw_cs);
879 return DDERR_SURFACEALREADYATTACHED;
882 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
883 Surf->next_attached = This->next_attached;
884 Surf->first_attached = This->first_attached;
885 This->next_attached = Surf;
887 /* Check if the WineD3D depth stencil needs updating */
888 if(This->ddraw->d3ddevice)
890 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
893 IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)Surf);
894 LeaveCriticalSection(&ddraw_cs);
895 return DD_OK;
898 static HRESULT WINAPI
899 IDirectDrawSurface7Impl_AddAttachedSurface(IDirectDrawSurface7 *iface,
900 IDirectDrawSurface7 *Attach)
902 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
903 IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach;
905 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
906 if(!(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
909 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
910 Surf->surface_desc.ddsCaps.dwCaps);
911 return DDERR_CANNOTATTACHSURFACE;
914 return IDirectDrawSurfaceImpl_AddAttachedSurface(This,
915 Surf);
917 /*****************************************************************************
918 * IDirectDrawSurface7::DeleteAttachedSurface
920 * Removes a surface from the attachment chain. The surface's refcount
921 * is decreased by one after it has been removed
923 * Params:
924 * Flags: Some flags, not used by this implementation
925 * Attach: Surface to detach
927 * Returns:
928 * DD_OK on success
929 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
931 *****************************************************************************/
932 static HRESULT WINAPI
933 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
934 DWORD Flags,
935 IDirectDrawSurface7 *Attach)
937 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
938 IDirectDrawSurfaceImpl *Surf = (IDirectDrawSurfaceImpl *)Attach;
939 IDirectDrawSurfaceImpl *Prev = This;
940 TRACE("(%p)->(%08x,%p)\n", This, Flags, Surf);
942 EnterCriticalSection(&ddraw_cs);
943 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
945 LeaveCriticalSection(&ddraw_cs);
946 return DDERR_CANNOTDETACHSURFACE;
949 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
950 if (This->surface_desc.ddsCaps.dwCaps &
951 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
953 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
954 /* FIXME: we should probably also subtract from dwMipMapCount of this
955 * and all parent surfaces */
958 /* Find the predecessor of the detached surface */
959 while(Prev)
961 if(Prev->next_attached == Surf) break;
962 Prev = Prev->next_attached;
965 /* There must be a surface, otherwise there's a bug */
966 assert(Prev != NULL);
968 /* Unchain the surface */
969 Prev->next_attached = Surf->next_attached;
970 Surf->next_attached = NULL;
971 Surf->first_attached = Surf;
973 /* Check if the WineD3D depth stencil needs updating */
974 if(This->ddraw->d3ddevice)
976 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
979 IDirectDrawSurface7_Release(Attach);
980 LeaveCriticalSection(&ddraw_cs);
981 return DD_OK;
984 /*****************************************************************************
985 * IDirectDrawSurface7::AddOverlayDirtyRect
987 * "This method is not currently implemented"
989 * Params:
990 * Rect: ?
992 * Returns:
993 * DDERR_UNSUPPORTED
995 *****************************************************************************/
996 static HRESULT WINAPI
997 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
998 LPRECT Rect)
1000 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1001 TRACE("(%p)->(%p)\n",This,Rect);
1003 /* MSDN says it's not implemented. I could forward it to WineD3D,
1004 * then we'd implement it, but I don't think that's a good idea
1005 * (Stefan Dösinger)
1007 #if 0
1008 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
1009 #endif
1010 return DDERR_UNSUPPORTED; /* unchecked */
1013 /*****************************************************************************
1014 * IDirectDrawSurface7::GetDC
1016 * Returns a GDI device context for the surface
1018 * Params:
1019 * hdc: Address of a HDC variable to store the dc to
1021 * Returns:
1022 * DD_OK on success
1023 * DDERR_INVALIDPARAMS if hdc is NULL
1024 * For details, see IWineD3DSurface::GetDC
1026 *****************************************************************************/
1027 static HRESULT WINAPI
1028 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
1029 HDC *hdc)
1031 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1032 HRESULT hr;
1033 TRACE("(%p)->(%p): Relay\n", This, hdc);
1035 if(!hdc)
1036 return DDERR_INVALIDPARAMS;
1038 EnterCriticalSection(&ddraw_cs);
1039 hr = IWineD3DSurface_GetDC(This->WineD3DSurface,
1040 hdc);
1041 LeaveCriticalSection(&ddraw_cs);
1042 switch(hr)
1044 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1045 * touch *hdc
1047 case WINED3DERR_INVALIDCALL:
1048 if(hdc) *hdc = NULL;
1049 return DDERR_INVALIDPARAMS;
1051 default: return hr;
1055 /*****************************************************************************
1056 * IDirectDrawSurface7::ReleaseDC
1058 * Releases the DC that was constructed with GetDC
1060 * Params:
1061 * hdc: HDC to release
1063 * Returns:
1064 * DD_OK on success
1065 * For more details, see IWineD3DSurface::ReleaseDC
1067 *****************************************************************************/
1068 static HRESULT WINAPI
1069 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
1070 HDC hdc)
1072 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1073 HRESULT hr;
1074 TRACE("(%p)->(%p): Relay\n", This, hdc);
1076 EnterCriticalSection(&ddraw_cs);
1077 hr = IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
1078 LeaveCriticalSection(&ddraw_cs);
1079 return hr;
1082 /*****************************************************************************
1083 * IDirectDrawSurface7::GetCaps
1085 * Returns the surface's caps
1087 * Params:
1088 * Caps: Address to write the caps to
1090 * Returns:
1091 * DD_OK on success
1092 * DDERR_INVALIDPARAMS if Caps is NULL
1094 *****************************************************************************/
1095 static HRESULT WINAPI
1096 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
1097 DDSCAPS2 *Caps)
1099 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1100 TRACE("(%p)->(%p)\n",This,Caps);
1102 if(!Caps)
1103 return DDERR_INVALIDPARAMS;
1105 *Caps = This->surface_desc.ddsCaps;
1106 return DD_OK;
1109 /*****************************************************************************
1110 * IDirectDrawSurface7::SetPriority
1112 * Sets a texture priority for managed textures.
1114 * Params:
1115 * Priority: The new priority
1117 * Returns:
1118 * DD_OK on success
1119 * For more details, see IWineD3DSurface::SetPriority
1121 *****************************************************************************/
1122 static HRESULT WINAPI
1123 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
1125 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1126 HRESULT hr;
1127 TRACE("(%p)->(%d): Relay!\n",This,Priority);
1129 EnterCriticalSection(&ddraw_cs);
1130 hr = IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
1131 LeaveCriticalSection(&ddraw_cs);
1132 return hr;
1135 /*****************************************************************************
1136 * IDirectDrawSurface7::GetPriority
1138 * Returns the surface's priority
1140 * Params:
1141 * Priority: Address of a variable to write the priority to
1143 * Returns:
1144 * D3D_OK on success
1145 * DDERR_INVALIDPARAMS if Priority == NULL
1146 * For more details, see IWineD3DSurface::GetPriority
1148 *****************************************************************************/
1149 static HRESULT WINAPI
1150 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1151 DWORD *Priority)
1153 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1154 TRACE("(%p)->(%p): Relay\n",This,Priority);
1156 if(!Priority)
1158 return DDERR_INVALIDPARAMS;
1161 EnterCriticalSection(&ddraw_cs);
1162 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1163 LeaveCriticalSection(&ddraw_cs);
1164 return DD_OK;
1167 /*****************************************************************************
1168 * IDirectDrawSurface7::SetPrivateData
1170 * Stores some data in the surface that is intended for the application's
1171 * use.
1173 * Params:
1174 * tag: GUID that identifies the data
1175 * Data: Pointer to the private data
1176 * Size: Size of the private data
1177 * Flags: Some flags
1179 * Returns:
1180 * D3D_OK on success
1181 * For more details, see IWineD3DSurface::SetPrivateData
1183 *****************************************************************************/
1184 static HRESULT WINAPI
1185 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1186 REFGUID tag,
1187 void *Data,
1188 DWORD Size,
1189 DWORD Flags)
1191 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1192 HRESULT hr;
1193 TRACE("(%p)->(%s,%p,%d,%x): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1195 EnterCriticalSection(&ddraw_cs);
1196 hr = IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1197 tag,
1198 Data,
1199 Size,
1200 Flags);
1201 LeaveCriticalSection(&ddraw_cs);
1202 switch(hr)
1204 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1205 default: return hr;
1209 /*****************************************************************************
1210 * IDirectDrawSurface7::GetPrivateData
1212 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1214 * Params:
1215 * tag: GUID of the data to return
1216 * Data: Address where to write the data to
1217 * Size: Size of the buffer at Data
1219 * Returns:
1220 * DD_OK on success
1221 * DDERR_INVALIDPARAMS if Data is NULL
1222 * For more details, see IWineD3DSurface::GetPrivateData
1224 *****************************************************************************/
1225 static HRESULT WINAPI
1226 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1227 REFGUID tag,
1228 void *Data,
1229 DWORD *Size)
1231 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1232 HRESULT hr;
1233 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1235 if(!Data)
1236 return DDERR_INVALIDPARAMS;
1238 EnterCriticalSection(&ddraw_cs);
1239 hr = IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1240 tag,
1241 Data,
1242 Size);
1243 LeaveCriticalSection(&ddraw_cs);
1244 return hr;
1247 /*****************************************************************************
1248 * IDirectDrawSurface7::FreePrivateData
1250 * Frees private data stored in the surface
1252 * Params:
1253 * tag: Tag of the data to free
1255 * Returns:
1256 * D3D_OK on success
1257 * For more details, see IWineD3DSurface::FreePrivateData
1259 *****************************************************************************/
1260 static HRESULT WINAPI
1261 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1262 REFGUID tag)
1264 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1265 HRESULT hr;
1266 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1268 EnterCriticalSection(&ddraw_cs);
1269 hr = IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1270 LeaveCriticalSection(&ddraw_cs);
1271 return hr;
1274 /*****************************************************************************
1275 * IDirectDrawSurface7::PageLock
1277 * Prevents a sysmem surface from being paged out
1279 * Params:
1280 * Flags: Not used, must be 0(unchecked)
1282 * Returns:
1283 * DD_OK, because it's a stub
1285 *****************************************************************************/
1286 static HRESULT WINAPI
1287 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1288 DWORD Flags)
1290 TRACE("(%p)->(%x)\n", iface, Flags);
1292 /* This is Windows memory management related - we don't need this */
1293 return DD_OK;
1296 /*****************************************************************************
1297 * IDirectDrawSurface7::PageUnlock
1299 * Allows a sysmem surface to be paged out
1301 * Params:
1302 * Flags: Not used, must be 0(unchecked)
1304 * Returns:
1305 * DD_OK, because it's a stub
1307 *****************************************************************************/
1308 static HRESULT WINAPI
1309 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1310 DWORD Flags)
1312 TRACE("(%p)->(%x)\n", iface, Flags);
1314 return DD_OK;
1317 /*****************************************************************************
1318 * IDirectDrawSurface7::BltBatch
1320 * An unimplemented function
1322 * Params:
1325 * Returns:
1326 * DDERR_UNSUPPORTED
1328 *****************************************************************************/
1329 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1331 TRACE("(%p)->(%p,%d,%08x)\n",iface,Batch,Count,Flags);
1333 /* MSDN: "not currently implemented" */
1334 return DDERR_UNSUPPORTED;
1337 /*****************************************************************************
1338 * IDirectDrawSurface7::EnumAttachedSurfaces
1340 * Enumerates all surfaces attached to this surface
1342 * Params:
1343 * context: Pointer to pass unmodified to the callback
1344 * cb: Callback function to call for each surface
1346 * Returns:
1347 * DD_OK on success
1348 * DDERR_INVALIDPARAMS if cb is NULL
1350 *****************************************************************************/
1351 static HRESULT WINAPI
1352 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1353 void *context,
1354 LPDDENUMSURFACESCALLBACK7 cb)
1356 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1357 IDirectDrawSurfaceImpl *surf;
1358 DDSURFACEDESC2 desc;
1359 int i;
1361 /* Attached surfaces aren't handled in WineD3D */
1362 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1364 if(!cb)
1365 return DDERR_INVALIDPARAMS;
1367 EnterCriticalSection(&ddraw_cs);
1368 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
1370 surf = This->complex_array[i];
1371 if(!surf) break;
1373 IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)surf);
1374 desc = surf->surface_desc;
1375 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1376 if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL)
1378 LeaveCriticalSection(&ddraw_cs);
1379 return DD_OK;
1383 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1385 IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)surf);
1386 desc = surf->surface_desc;
1387 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1388 if (cb((IDirectDrawSurface7 *)surf, &desc, context) == DDENUMRET_CANCEL)
1390 LeaveCriticalSection(&ddraw_cs);
1391 return DD_OK;
1395 TRACE(" end of enumeration.\n");
1397 LeaveCriticalSection(&ddraw_cs);
1398 return DD_OK;
1401 /*****************************************************************************
1402 * IDirectDrawSurface7::EnumOverlayZOrders
1404 * "Enumerates the overlay surfaces on the specified destination"
1406 * Params:
1407 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1408 * context: context to pass back to the callback
1409 * cb: callback function to call for each enumerated surface
1411 * Returns:
1412 * DD_OK, because it's a stub
1414 *****************************************************************************/
1415 static HRESULT WINAPI
1416 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1417 DWORD Flags,
1418 void *context,
1419 LPDDENUMSURFACESCALLBACK7 cb)
1421 FIXME("(%p)->(%x,%p,%p): Stub!\n", iface, Flags, context, cb);
1423 return DD_OK;
1426 /*****************************************************************************
1427 * IDirectDrawSurface7::GetBltStatus
1429 * Returns the blitting status
1431 * Params:
1432 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1434 * Returns:
1435 * See IWineD3DSurface::Blt
1437 *****************************************************************************/
1438 static HRESULT WINAPI
1439 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1440 DWORD Flags)
1442 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1443 HRESULT hr;
1444 TRACE("(%p)->(%x): Relay\n", This, Flags);
1446 EnterCriticalSection(&ddraw_cs);
1447 hr = IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1448 LeaveCriticalSection(&ddraw_cs);
1449 switch(hr)
1451 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1452 default: return hr;
1456 /*****************************************************************************
1457 * IDirectDrawSurface7::GetColorKey
1459 * Returns the color key assigned to the surface
1461 * Params:
1462 * Flags: Some flags
1463 * CKey: Address to store the key to
1465 * Returns:
1466 * DD_OK on success
1467 * DDERR_INVALIDPARAMS if CKey is NULL
1469 *****************************************************************************/
1470 static HRESULT WINAPI
1471 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1472 DWORD Flags,
1473 DDCOLORKEY *CKey)
1475 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1476 TRACE("(%p)->(%08x,%p)\n", This, Flags, CKey);
1478 if(!CKey)
1479 return DDERR_INVALIDPARAMS;
1481 EnterCriticalSection(&ddraw_cs);
1483 switch (Flags)
1485 case DDCKEY_DESTBLT:
1486 if (!(This->surface_desc.dwFlags & DDSD_CKDESTBLT))
1488 LeaveCriticalSection(&ddraw_cs);
1489 return DDERR_NOCOLORKEY;
1491 *CKey = This->surface_desc.ddckCKDestBlt;
1492 break;
1494 case DDCKEY_DESTOVERLAY:
1495 if (!(This->surface_desc.dwFlags & DDSD_CKDESTOVERLAY))
1497 LeaveCriticalSection(&ddraw_cs);
1498 return DDERR_NOCOLORKEY;
1500 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1501 break;
1503 case DDCKEY_SRCBLT:
1504 if (!(This->surface_desc.dwFlags & DDSD_CKSRCBLT))
1506 LeaveCriticalSection(&ddraw_cs);
1507 return DDERR_NOCOLORKEY;
1509 *CKey = This->surface_desc.ddckCKSrcBlt;
1510 break;
1512 case DDCKEY_SRCOVERLAY:
1513 if (!(This->surface_desc.dwFlags & DDSD_CKSRCOVERLAY))
1515 LeaveCriticalSection(&ddraw_cs);
1516 return DDERR_NOCOLORKEY;
1518 *CKey = This->surface_desc.ddckCKSrcOverlay;
1519 break;
1521 default:
1522 LeaveCriticalSection(&ddraw_cs);
1523 return DDERR_INVALIDPARAMS;
1526 LeaveCriticalSection(&ddraw_cs);
1527 return DD_OK;
1530 /*****************************************************************************
1531 * IDirectDrawSurface7::GetFlipStatus
1533 * Returns the flipping status of the surface
1535 * Params:
1536 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1538 * Returns:
1539 * See IWineD3DSurface::GetFlipStatus
1541 *****************************************************************************/
1542 static HRESULT WINAPI
1543 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1544 DWORD Flags)
1546 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1547 HRESULT hr;
1548 TRACE("(%p)->(%x): Relay\n", This, Flags);
1550 EnterCriticalSection(&ddraw_cs);
1551 hr = IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1552 LeaveCriticalSection(&ddraw_cs);
1553 switch(hr)
1555 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1556 default: return hr;
1560 /*****************************************************************************
1561 * IDirectDrawSurface7::GetOverlayPosition
1563 * Returns the display coordinates of a visible and active overlay surface
1565 * Params:
1569 * Returns:
1570 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1571 *****************************************************************************/
1572 static HRESULT WINAPI
1573 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1574 LONG *X,
1575 LONG *Y) {
1576 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1577 HRESULT hr;
1578 TRACE("(%p)->(%p,%p): Relay\n", This, X, Y);
1580 EnterCriticalSection(&ddraw_cs);
1581 hr = IWineD3DSurface_GetOverlayPosition(This->WineD3DSurface,
1584 LeaveCriticalSection(&ddraw_cs);
1585 return hr;
1588 /*****************************************************************************
1589 * IDirectDrawSurface7::GetPixelFormat
1591 * Returns the pixel format of the Surface
1593 * Params:
1594 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1595 * format should be written
1597 * Returns:
1598 * DD_OK on success
1599 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1601 *****************************************************************************/
1602 static HRESULT WINAPI
1603 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1604 DDPIXELFORMAT *PixelFormat)
1606 /* What is DDERR_INVALIDSURFACETYPE for here? */
1607 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1608 TRACE("(%p)->(%p)\n",This,PixelFormat);
1610 if(!PixelFormat)
1611 return DDERR_INVALIDPARAMS;
1613 EnterCriticalSection(&ddraw_cs);
1614 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1615 LeaveCriticalSection(&ddraw_cs);
1617 return DD_OK;
1621 /*****************************************************************************
1622 * IDirectDrawSurface7::GetSurfaceDesc
1624 * Returns the description of this surface
1626 * Params:
1627 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1628 * surface desc
1630 * Returns:
1631 * DD_OK on success
1632 * DDERR_INVALIDPARAMS if DDSD is NULL
1634 *****************************************************************************/
1635 static HRESULT WINAPI
1636 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1637 DDSURFACEDESC2 *DDSD)
1639 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1641 TRACE("(%p)->(%p)\n",This,DDSD);
1643 if(!DDSD)
1644 return DDERR_INVALIDPARAMS;
1646 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
1648 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
1649 return DDERR_INVALIDPARAMS;
1652 EnterCriticalSection(&ddraw_cs);
1653 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1654 TRACE("Returning surface desc:\n");
1655 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1657 LeaveCriticalSection(&ddraw_cs);
1658 return DD_OK;
1661 /*****************************************************************************
1662 * IDirectDrawSurface7::Initialize
1664 * Initializes the surface. This is a no-op in Wine
1666 * Params:
1667 * DD: Pointer to an DirectDraw interface
1668 * DDSD: Surface description for initialization
1670 * Returns:
1671 * DDERR_ALREADYINITIALIZED
1673 *****************************************************************************/
1674 static HRESULT WINAPI
1675 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1676 IDirectDraw *DD,
1677 DDSURFACEDESC2 *DDSD)
1679 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1680 IDirectDrawImpl *ddimpl = DD ? ddraw_from_ddraw1(DD) : NULL;
1681 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1683 return DDERR_ALREADYINITIALIZED;
1686 /*****************************************************************************
1687 * IDirectDrawSurface7::IsLost
1689 * Checks if the surface is lost
1691 * Returns:
1692 * DD_OK, if the surface is usable
1693 * DDERR_ISLOST if the surface is lost
1694 * See IWineD3DSurface::IsLost for more details
1696 *****************************************************************************/
1697 static HRESULT WINAPI
1698 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1700 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1701 HRESULT hr;
1702 TRACE("(%p)\n", This);
1704 EnterCriticalSection(&ddraw_cs);
1705 /* We lose the surface if the implementation was changed */
1706 if(This->ImplType != This->ddraw->ImplType)
1708 /* But this shouldn't happen. When we change the implementation,
1709 * all surfaces are re-created automatically, and their content
1710 * is copied
1712 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1713 LeaveCriticalSection(&ddraw_cs);
1714 return DDERR_SURFACELOST;
1717 hr = IWineD3DSurface_IsLost(This->WineD3DSurface);
1718 LeaveCriticalSection(&ddraw_cs);
1719 switch(hr)
1721 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
1722 * WineD3D uses the same error for surfaces
1724 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
1725 default: return hr;
1729 /*****************************************************************************
1730 * IDirectDrawSurface7::Restore
1732 * Restores a lost surface. This makes the surface usable again, but
1733 * doesn't reload its old contents
1735 * Returns:
1736 * DD_OK on success
1737 * See IWineD3DSurface::Restore for more details
1739 *****************************************************************************/
1740 static HRESULT WINAPI
1741 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1743 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1744 HRESULT hr;
1745 TRACE("(%p)\n", This);
1747 EnterCriticalSection(&ddraw_cs);
1748 if(This->ImplType != This->ddraw->ImplType)
1750 /* Call the recreation callback. Make sure to AddRef first */
1751 IDirectDrawSurface_AddRef(iface);
1752 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1753 &This->surface_desc,
1754 NULL /* Not needed */);
1756 hr = IWineD3DSurface_Restore(This->WineD3DSurface);
1757 LeaveCriticalSection(&ddraw_cs);
1758 return hr;
1761 /*****************************************************************************
1762 * IDirectDrawSurface7::SetOverlayPosition
1764 * Changes the display coordinates of an overlay surface
1766 * Params:
1767 * X:
1768 * Y:
1770 * Returns:
1771 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1772 *****************************************************************************/
1773 static HRESULT WINAPI
1774 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1775 LONG X,
1776 LONG Y)
1778 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1779 HRESULT hr;
1780 TRACE("(%p)->(%d,%d): Relay\n", This, X, Y);
1782 EnterCriticalSection(&ddraw_cs);
1783 hr = IWineD3DSurface_SetOverlayPosition(This->WineD3DSurface,
1786 LeaveCriticalSection(&ddraw_cs);
1787 return hr;
1790 /*****************************************************************************
1791 * IDirectDrawSurface7::UpdateOverlay
1793 * Modifies the attributes of an overlay surface.
1795 * Params:
1796 * SrcRect: The section of the source being used for the overlay
1797 * DstSurface: Address of the surface that is overlaid
1798 * DstRect: Place of the overlay
1799 * Flags: some DDOVER_* flags
1801 * Returns:
1802 * DDERR_UNSUPPORTED, because we don't support overlays
1804 *****************************************************************************/
1805 static HRESULT WINAPI
1806 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1807 LPRECT SrcRect,
1808 IDirectDrawSurface7 *DstSurface,
1809 LPRECT DstRect,
1810 DWORD Flags,
1811 LPDDOVERLAYFX FX)
1813 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1814 IDirectDrawSurfaceImpl *Dst = (IDirectDrawSurfaceImpl *)DstSurface;
1815 HRESULT hr;
1816 TRACE("(%p)->(%p,%p,%p,%x,%p): Relay\n", This, SrcRect, Dst, DstRect, Flags, FX);
1818 EnterCriticalSection(&ddraw_cs);
1819 hr = IWineD3DSurface_UpdateOverlay(This->WineD3DSurface,
1820 SrcRect,
1821 Dst ? Dst->WineD3DSurface : NULL,
1822 DstRect,
1823 Flags,
1824 (WINEDDOVERLAYFX *) FX);
1825 LeaveCriticalSection(&ddraw_cs);
1826 switch(hr) {
1827 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1828 case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE;
1829 case WINEDDERR_OVERLAYNOTVISIBLE: return DDERR_OVERLAYNOTVISIBLE;
1830 default:
1831 return hr;
1835 /*****************************************************************************
1836 * IDirectDrawSurface7::UpdateOverlayDisplay
1838 * The DX7 sdk says that it's not implemented
1840 * Params:
1841 * Flags: ?
1843 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1845 *****************************************************************************/
1846 static HRESULT WINAPI
1847 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1848 DWORD Flags)
1850 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1851 TRACE("(%p)->(%x)\n", This, Flags);
1852 return DDERR_UNSUPPORTED;
1855 /*****************************************************************************
1856 * IDirectDrawSurface7::UpdateOverlayZOrder
1858 * Sets an overlay's Z order
1860 * Params:
1861 * Flags: DDOVERZ_* flags
1862 * DDSRef: Defines the relative position in the overlay chain
1864 * Returns:
1865 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1867 *****************************************************************************/
1868 static HRESULT WINAPI
1869 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1870 DWORD Flags,
1871 IDirectDrawSurface7 *DDSRef)
1873 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1874 IDirectDrawSurfaceImpl *Ref = (IDirectDrawSurfaceImpl *)DDSRef;
1875 HRESULT hr;
1877 TRACE("(%p)->(%x,%p): Relay\n", This, Flags, Ref);
1878 EnterCriticalSection(&ddraw_cs);
1879 hr = IWineD3DSurface_UpdateOverlayZOrder(This->WineD3DSurface,
1880 Flags,
1881 Ref ? Ref->WineD3DSurface : NULL);
1882 LeaveCriticalSection(&ddraw_cs);
1883 return hr;
1886 /*****************************************************************************
1887 * IDirectDrawSurface7::GetDDInterface
1889 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1890 * surface belongs to
1892 * Params:
1893 * DD: Address to write the interface pointer to
1895 * Returns:
1896 * DD_OK on success
1897 * DDERR_INVALIDPARAMS if DD is NULL
1899 *****************************************************************************/
1900 static HRESULT WINAPI
1901 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1902 void **DD)
1904 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1906 TRACE("(%p)->(%p)\n",This,DD);
1908 if(!DD)
1909 return DDERR_INVALIDPARAMS;
1911 switch(This->version)
1913 case 7:
1914 *DD = This->ddraw;
1915 break;
1917 case 4:
1918 *DD = &This->ddraw->IDirectDraw4_vtbl;
1919 break;
1921 case 2:
1922 *DD = &This->ddraw->IDirectDraw2_vtbl;
1923 break;
1925 case 1:
1926 *DD = &This->ddraw->IDirectDraw_vtbl;
1927 break;
1930 IUnknown_AddRef((IUnknown *)*DD);
1932 return DD_OK;
1935 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1936 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1938 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1939 volatile IDirectDrawSurfaceImpl* vThis = This;
1941 TRACE("(%p)\n",This);
1942 EnterCriticalSection(&ddraw_cs);
1943 /* A uniqueness value of 0 is apparently special.
1944 * This needs to be checked.
1945 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
1947 while (1) {
1948 DWORD old_uniqueness_value = vThis->uniqueness_value;
1949 DWORD new_uniqueness_value = old_uniqueness_value+1;
1951 if (old_uniqueness_value == 0) break;
1952 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1954 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1955 old_uniqueness_value,
1956 new_uniqueness_value)
1957 == old_uniqueness_value)
1958 break;
1961 LeaveCriticalSection(&ddraw_cs);
1962 return DD_OK;
1965 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1967 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1969 TRACE("(%p)->(%p)\n",This,pValue);
1970 EnterCriticalSection(&ddraw_cs);
1971 *pValue = This->uniqueness_value;
1972 LeaveCriticalSection(&ddraw_cs);
1973 return DD_OK;
1976 /*****************************************************************************
1977 * IDirectDrawSurface7::SetLOD
1979 * Sets the level of detail of a texture
1981 * Params:
1982 * MaxLOD: LOD to set
1984 * Returns:
1985 * DD_OK on success
1986 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1988 *****************************************************************************/
1989 static HRESULT WINAPI
1990 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1991 DWORD MaxLOD)
1993 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1994 HRESULT hr;
1995 TRACE("(%p)->(%d)\n", This, MaxLOD);
1997 EnterCriticalSection(&ddraw_cs);
1998 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2000 LeaveCriticalSection(&ddraw_cs);
2001 return DDERR_INVALIDOBJECT;
2004 if(!This->wineD3DTexture)
2006 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
2007 LeaveCriticalSection(&ddraw_cs);
2008 return DDERR_INVALIDOBJECT;
2011 hr = IWineD3DBaseTexture_SetLOD(This->wineD3DTexture,
2012 MaxLOD);
2013 LeaveCriticalSection(&ddraw_cs);
2014 return hr;
2017 /*****************************************************************************
2018 * IDirectDrawSurface7::GetLOD
2020 * Returns the level of detail of a Direct3D texture
2022 * Params:
2023 * MaxLOD: Address to write the LOD to
2025 * Returns:
2026 * DD_OK on success
2027 * DDERR_INVALIDPARAMS if MaxLOD is NULL
2028 * DDERR_INVALIDOBJECT if the surface is invalid for this method
2030 *****************************************************************************/
2031 static HRESULT WINAPI
2032 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
2033 DWORD *MaxLOD)
2035 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2036 TRACE("(%p)->(%p)\n", This, MaxLOD);
2038 if(!MaxLOD)
2039 return DDERR_INVALIDPARAMS;
2041 EnterCriticalSection(&ddraw_cs);
2042 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
2044 LeaveCriticalSection(&ddraw_cs);
2045 return DDERR_INVALIDOBJECT;
2048 *MaxLOD = IWineD3DBaseTexture_GetLOD(This->wineD3DTexture);
2049 LeaveCriticalSection(&ddraw_cs);
2050 return DD_OK;
2053 /*****************************************************************************
2054 * IDirectDrawSurface7::BltFast
2056 * Performs a fast Blit.
2058 * Params:
2059 * dstx: The x coordinate to blit to on the destination
2060 * dsty: The y coordinate to blit to on the destination
2061 * Source: The source surface
2062 * rsrc: The source rectangle
2063 * trans: Type of transfer. Some DDBLTFAST_* flags
2065 * Returns:
2066 * DD_OK on success
2067 * For more details, see IWineD3DSurface::BltFast
2069 *****************************************************************************/
2070 static HRESULT WINAPI
2071 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
2072 DWORD dstx,
2073 DWORD dsty,
2074 IDirectDrawSurface7 *Source,
2075 RECT *rsrc,
2076 DWORD trans)
2078 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2079 IDirectDrawSurfaceImpl *src = (IDirectDrawSurfaceImpl *)Source;
2080 HRESULT hr;
2081 TRACE("(%p)->(%d,%d,%p,%p,%d): Relay\n", This, dstx, dsty, Source, rsrc, trans);
2083 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
2084 * in that case
2086 if(rsrc)
2088 if(rsrc->top > rsrc->bottom || rsrc->left > rsrc->right ||
2089 rsrc->right > src->surface_desc.dwWidth ||
2090 rsrc->bottom > src->surface_desc.dwHeight)
2092 WARN("Source rectangle is invalid, returning DDERR_INVALIDRECT\n");
2093 return DDERR_INVALIDRECT;
2095 if(dstx + rsrc->right - rsrc->left > This->surface_desc.dwWidth ||
2096 dsty + rsrc->bottom - rsrc->top > This->surface_desc.dwHeight)
2098 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2099 return DDERR_INVALIDRECT;
2102 else
2104 if(dstx + src->surface_desc.dwWidth > This->surface_desc.dwWidth ||
2105 dsty + src->surface_desc.dwHeight > This->surface_desc.dwHeight)
2107 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT\n");
2108 return DDERR_INVALIDRECT;
2112 EnterCriticalSection(&ddraw_cs);
2113 hr = IWineD3DSurface_BltFast(This->WineD3DSurface,
2114 dstx, dsty,
2115 src ? src->WineD3DSurface : NULL,
2116 rsrc,
2117 trans);
2118 LeaveCriticalSection(&ddraw_cs);
2119 switch(hr)
2121 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
2122 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
2123 default: return hr;
2127 /*****************************************************************************
2128 * IDirectDrawSurface7::GetClipper
2130 * Returns the IDirectDrawClipper interface of the clipper assigned to this
2131 * surface
2133 * Params:
2134 * Clipper: Address to store the interface pointer at
2136 * Returns:
2137 * DD_OK on success
2138 * DDERR_INVALIDPARAMS if Clipper is NULL
2139 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
2141 *****************************************************************************/
2142 static HRESULT WINAPI
2143 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
2144 IDirectDrawClipper **Clipper)
2146 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2147 TRACE("(%p)->(%p)\n", This, Clipper);
2149 if(!Clipper)
2151 LeaveCriticalSection(&ddraw_cs);
2152 return DDERR_INVALIDPARAMS;
2155 EnterCriticalSection(&ddraw_cs);
2156 if(This->clipper == NULL)
2158 LeaveCriticalSection(&ddraw_cs);
2159 return DDERR_NOCLIPPERATTACHED;
2162 *Clipper = (IDirectDrawClipper *)This->clipper;
2163 IDirectDrawClipper_AddRef(*Clipper);
2164 LeaveCriticalSection(&ddraw_cs);
2165 return DD_OK;
2168 /*****************************************************************************
2169 * IDirectDrawSurface7::SetClipper
2171 * Sets a clipper for the surface
2173 * Params:
2174 * Clipper: IDirectDrawClipper interface of the clipper to set
2176 * Returns:
2177 * DD_OK on success
2179 *****************************************************************************/
2180 static HRESULT WINAPI
2181 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
2182 IDirectDrawClipper *Clipper)
2184 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2185 IDirectDrawClipperImpl *oldClipper = This->clipper;
2186 HWND clipWindow;
2187 HRESULT hr;
2188 TRACE("(%p)->(%p)\n",This,Clipper);
2190 EnterCriticalSection(&ddraw_cs);
2191 if ((IDirectDrawClipperImpl *)Clipper == This->clipper)
2193 LeaveCriticalSection(&ddraw_cs);
2194 return DD_OK;
2197 This->clipper = (IDirectDrawClipperImpl *)Clipper;
2199 if (Clipper != NULL)
2200 IDirectDrawClipper_AddRef(Clipper);
2201 if(oldClipper)
2202 IDirectDrawClipper_Release((IDirectDrawClipper *)oldClipper);
2204 hr = IWineD3DSurface_SetClipper(This->WineD3DSurface, This->clipper ? This->clipper->wineD3DClipper : NULL);
2206 if(This->wineD3DSwapChain) {
2207 clipWindow = NULL;
2208 if(Clipper) {
2209 IDirectDrawClipper_GetHWnd(Clipper, &clipWindow);
2212 if(clipWindow) {
2213 IWineD3DSwapChain_SetDestWindowOverride(This->wineD3DSwapChain,
2214 clipWindow);
2215 } else {
2216 IWineD3DSwapChain_SetDestWindowOverride(This->wineD3DSwapChain,
2217 This->ddraw->d3d_window);
2221 LeaveCriticalSection(&ddraw_cs);
2222 return hr;
2225 /*****************************************************************************
2226 * IDirectDrawSurface7::SetSurfaceDesc
2228 * Sets the surface description. It can override the pixel format, the surface
2229 * memory, ...
2230 * It's not really tested.
2232 * Params:
2233 * DDSD: Pointer to the new surface description to set
2234 * Flags: Some flags
2236 * Returns:
2237 * DD_OK on success
2238 * DDERR_INVALIDPARAMS if DDSD is NULL
2240 *****************************************************************************/
2241 static HRESULT WINAPI
2242 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
2243 DDSURFACEDESC2 *DDSD,
2244 DWORD Flags)
2246 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2247 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
2248 HRESULT hr;
2249 TRACE("(%p)->(%p,%x)\n", This, DDSD, Flags);
2251 if(!DDSD)
2252 return DDERR_INVALIDPARAMS;
2254 EnterCriticalSection(&ddraw_cs);
2255 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
2257 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
2259 if(newFormat == WINED3DFMT_UNKNOWN)
2261 ERR("Requested to set an unknown pixelformat\n");
2262 LeaveCriticalSection(&ddraw_cs);
2263 return DDERR_INVALIDPARAMS;
2265 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
2267 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
2268 newFormat);
2269 if(hr != DD_OK)
2271 LeaveCriticalSection(&ddraw_cs);
2272 return hr;
2276 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
2278 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2279 DDCKEY_DESTOVERLAY,
2280 (WINEDDCOLORKEY *) &DDSD->u3.ddckCKDestOverlay);
2282 if (DDSD->dwFlags & DDSD_CKDESTBLT)
2284 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2285 DDCKEY_DESTBLT,
2286 (WINEDDCOLORKEY *) &DDSD->ddckCKDestBlt);
2288 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
2290 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2291 DDCKEY_SRCOVERLAY,
2292 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcOverlay);
2294 if (DDSD->dwFlags & DDSD_CKSRCBLT)
2296 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2297 DDCKEY_SRCBLT,
2298 (WINEDDCOLORKEY *) &DDSD->ddckCKSrcBlt);
2300 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
2302 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
2303 if(hr != WINED3D_OK)
2305 /* No need for a trace here, wined3d does that for us */
2306 switch(hr)
2308 case WINED3DERR_INVALIDCALL:
2309 LeaveCriticalSection(&ddraw_cs);
2310 return DDERR_INVALIDPARAMS;
2311 default:
2312 break; /* Go on */
2317 This->surface_desc = *DDSD;
2319 LeaveCriticalSection(&ddraw_cs);
2320 return DD_OK;
2323 /*****************************************************************************
2324 * IDirectDrawSurface7::GetPalette
2326 * Returns the IDirectDrawPalette interface of the palette currently assigned
2327 * to the surface
2329 * Params:
2330 * Pal: Address to write the interface pointer to
2332 * Returns:
2333 * DD_OK on success
2334 * DDERR_INVALIDPARAMS if Pal is NULL
2336 *****************************************************************************/
2337 static HRESULT WINAPI
2338 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
2339 IDirectDrawPalette **Pal)
2341 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2342 IWineD3DPalette *wPal;
2343 HRESULT hr;
2344 TRACE("(%p)->(%p): Relay\n", This, Pal);
2346 if(!Pal)
2347 return DDERR_INVALIDPARAMS;
2349 EnterCriticalSection(&ddraw_cs);
2350 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
2351 if(hr != DD_OK)
2353 LeaveCriticalSection(&ddraw_cs);
2354 return hr;
2357 if(wPal)
2359 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
2361 else
2363 *Pal = NULL;
2364 hr = DDERR_NOPALETTEATTACHED;
2367 LeaveCriticalSection(&ddraw_cs);
2368 return hr;
2371 /*****************************************************************************
2372 * SetColorKeyEnum
2374 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
2375 * recursively in the surface tree
2377 *****************************************************************************/
2378 struct SCKContext
2380 HRESULT ret;
2381 WINEDDCOLORKEY *CKey;
2382 DWORD Flags;
2385 static HRESULT WINAPI
2386 SetColorKeyEnum(IDirectDrawSurface7 *surface,
2387 DDSURFACEDESC2 *desc,
2388 void *context)
2390 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)surface;
2391 struct SCKContext *ctx = context;
2392 HRESULT hr;
2394 hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2395 ctx->Flags,
2396 ctx->CKey);
2397 if(hr != DD_OK)
2399 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
2400 ctx->ret = hr;
2403 IDirectDrawSurface7_EnumAttachedSurfaces(surface,
2404 context,
2405 SetColorKeyEnum);
2406 IDirectDrawSurface7_Release(surface);
2407 return DDENUMRET_OK;
2410 /*****************************************************************************
2411 * IDirectDrawSurface7::SetColorKey
2413 * Sets the color keying options for the surface. Observations showed that
2414 * in case of complex surfaces the color key has to be assigned to all
2415 * sublevels.
2417 * Params:
2418 * Flags: DDCKEY_*
2419 * CKey: The new color key
2421 * Returns:
2422 * DD_OK on success
2423 * See IWineD3DSurface::SetColorKey for details
2425 *****************************************************************************/
2426 static HRESULT WINAPI
2427 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2428 DWORD Flags,
2429 DDCOLORKEY *CKey)
2431 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2432 DDCOLORKEY FixedCKey;
2433 struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) (CKey ? &FixedCKey : NULL), Flags };
2434 TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
2436 EnterCriticalSection(&ddraw_cs);
2437 if (CKey)
2439 FixedCKey = *CKey;
2440 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
2441 if (FixedCKey.dwColorSpaceHighValue < FixedCKey.dwColorSpaceLowValue)
2442 FixedCKey.dwColorSpaceHighValue = FixedCKey.dwColorSpaceLowValue;
2444 switch (Flags & ~DDCKEY_COLORSPACE)
2446 case DDCKEY_DESTBLT:
2447 This->surface_desc.ddckCKDestBlt = FixedCKey;
2448 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
2449 break;
2451 case DDCKEY_DESTOVERLAY:
2452 This->surface_desc.u3.ddckCKDestOverlay = FixedCKey;
2453 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
2454 break;
2456 case DDCKEY_SRCOVERLAY:
2457 This->surface_desc.ddckCKSrcOverlay = FixedCKey;
2458 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
2459 break;
2461 case DDCKEY_SRCBLT:
2462 This->surface_desc.ddckCKSrcBlt = FixedCKey;
2463 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
2464 break;
2466 default:
2467 LeaveCriticalSection(&ddraw_cs);
2468 return DDERR_INVALIDPARAMS;
2471 else
2473 switch (Flags & ~DDCKEY_COLORSPACE)
2475 case DDCKEY_DESTBLT:
2476 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
2477 break;
2479 case DDCKEY_DESTOVERLAY:
2480 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
2481 break;
2483 case DDCKEY_SRCOVERLAY:
2484 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
2485 break;
2487 case DDCKEY_SRCBLT:
2488 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
2489 break;
2491 default:
2492 LeaveCriticalSection(&ddraw_cs);
2493 return DDERR_INVALIDPARAMS;
2496 ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
2497 Flags,
2498 ctx.CKey);
2499 IDirectDrawSurface7_EnumAttachedSurfaces(iface,
2500 &ctx,
2501 SetColorKeyEnum);
2502 LeaveCriticalSection(&ddraw_cs);
2503 switch(ctx.ret)
2505 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2506 default: return ctx.ret;
2510 /*****************************************************************************
2511 * IDirectDrawSurface7::SetPalette
2513 * Assigns a DirectDrawPalette object to the surface
2515 * Params:
2516 * Pal: Interface to the palette to set
2518 * Returns:
2519 * DD_OK on success
2521 *****************************************************************************/
2522 static HRESULT WINAPI
2523 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2524 IDirectDrawPalette *Pal)
2526 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
2527 IDirectDrawPalette *oldPal;
2528 IDirectDrawSurfaceImpl *surf;
2529 IDirectDrawPaletteImpl *PalImpl = (IDirectDrawPaletteImpl *)Pal;
2530 HRESULT hr;
2531 TRACE("(%p)->(%p)\n", This, Pal);
2533 if (!(This->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 |
2534 DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8))) {
2535 return DDERR_INVALIDPIXELFORMAT;
2538 /* Find the old palette */
2539 EnterCriticalSection(&ddraw_cs);
2540 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2541 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
2543 LeaveCriticalSection(&ddraw_cs);
2544 return hr;
2546 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2548 /* Set the new Palette */
2549 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2550 PalImpl ? PalImpl->wineD3DPalette : NULL);
2551 /* AddRef the Palette */
2552 if(Pal) IDirectDrawPalette_AddRef(Pal);
2554 /* Release the old palette */
2555 if(oldPal) IDirectDrawPalette_Release(oldPal);
2557 /* If this is a front buffer, also update the back buffers
2558 * TODO: How do things work for palettized cube textures?
2560 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2562 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
2563 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
2565 surf = This;
2566 while(1)
2568 IDirectDrawSurface7 *attach;
2569 HRESULT hr;
2570 hr = IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7 *)surf, &caps2, &attach);
2571 if(hr != DD_OK)
2573 break;
2576 TRACE("Setting palette on %p\n", attach);
2577 IDirectDrawSurface7_SetPalette(attach,
2578 Pal);
2579 surf = (IDirectDrawSurfaceImpl *)attach;
2580 IDirectDrawSurface7_Release(attach);
2584 LeaveCriticalSection(&ddraw_cs);
2585 return DD_OK;
2588 /*****************************************************************************
2589 * The VTable
2590 *****************************************************************************/
2592 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2594 /*** IUnknown ***/
2595 IDirectDrawSurfaceImpl_QueryInterface,
2596 IDirectDrawSurfaceImpl_AddRef,
2597 IDirectDrawSurfaceImpl_Release,
2598 /*** IDirectDrawSurface ***/
2599 IDirectDrawSurface7Impl_AddAttachedSurface,
2600 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2601 IDirectDrawSurfaceImpl_Blt,
2602 IDirectDrawSurfaceImpl_BltBatch,
2603 IDirectDrawSurfaceImpl_BltFast,
2604 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2605 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2606 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2607 IDirectDrawSurfaceImpl_Flip,
2608 IDirectDrawSurfaceImpl_GetAttachedSurface,
2609 IDirectDrawSurfaceImpl_GetBltStatus,
2610 IDirectDrawSurfaceImpl_GetCaps,
2611 IDirectDrawSurfaceImpl_GetClipper,
2612 IDirectDrawSurfaceImpl_GetColorKey,
2613 IDirectDrawSurfaceImpl_GetDC,
2614 IDirectDrawSurfaceImpl_GetFlipStatus,
2615 IDirectDrawSurfaceImpl_GetOverlayPosition,
2616 IDirectDrawSurfaceImpl_GetPalette,
2617 IDirectDrawSurfaceImpl_GetPixelFormat,
2618 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2619 IDirectDrawSurfaceImpl_Initialize,
2620 IDirectDrawSurfaceImpl_IsLost,
2621 IDirectDrawSurfaceImpl_Lock,
2622 IDirectDrawSurfaceImpl_ReleaseDC,
2623 IDirectDrawSurfaceImpl_Restore,
2624 IDirectDrawSurfaceImpl_SetClipper,
2625 IDirectDrawSurfaceImpl_SetColorKey,
2626 IDirectDrawSurfaceImpl_SetOverlayPosition,
2627 IDirectDrawSurfaceImpl_SetPalette,
2628 IDirectDrawSurfaceImpl_Unlock,
2629 IDirectDrawSurfaceImpl_UpdateOverlay,
2630 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2631 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2632 /*** IDirectDrawSurface2 ***/
2633 IDirectDrawSurfaceImpl_GetDDInterface,
2634 IDirectDrawSurfaceImpl_PageLock,
2635 IDirectDrawSurfaceImpl_PageUnlock,
2636 /*** IDirectDrawSurface3 ***/
2637 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2638 /*** IDirectDrawSurface4 ***/
2639 IDirectDrawSurfaceImpl_SetPrivateData,
2640 IDirectDrawSurfaceImpl_GetPrivateData,
2641 IDirectDrawSurfaceImpl_FreePrivateData,
2642 IDirectDrawSurfaceImpl_GetUniquenessValue,
2643 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2644 /*** IDirectDrawSurface7 ***/
2645 IDirectDrawSurfaceImpl_SetPriority,
2646 IDirectDrawSurfaceImpl_GetPriority,
2647 IDirectDrawSurfaceImpl_SetLOD,
2648 IDirectDrawSurfaceImpl_GetLOD