shell32: Remove the unused shell allocator.
[wine/wine64.git] / dlls / ddraw / surface.c
blob74987bfa0995b891384a60cc45ac6b95b5cc8eba
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 "winnls.h"
40 #include "winerror.h"
41 #include "wingdi.h"
42 #include "wine/exception.h"
43 #include "excpt.h"
45 #include "ddraw.h"
46 #include "d3d.h"
48 #include "ddraw_private.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
53 /*****************************************************************************
54 * IUnknown parts follow
55 *****************************************************************************/
57 /*****************************************************************************
58 * IDirectDrawSurface7::QueryInterface
60 * A normal QueryInterface implementation. For QueryInterface rules
61 * see ddraw.c, IDirectDraw7::QueryInterface. This method
62 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
63 * in all versions, the IDirectDrawGammaControl interface and it can
64 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
66 * Params:
67 * riid: The interface id queried for
68 * obj: Address to write the pointer to
70 * Returns:
71 * S_OK on success
72 * E_NOINTERFACE if the requested interface wasn't found
74 *****************************************************************************/
75 static HRESULT WINAPI
76 IDirectDrawSurfaceImpl_QueryInterface(IDirectDrawSurface7 *iface,
77 REFIID riid,
78 void **obj)
80 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
82 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
83 *obj = NULL;
85 if(!riid)
86 return DDERR_INVALIDPARAMS;
88 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),obj);
89 if (IsEqualGUID(riid, &IID_IUnknown)
90 || IsEqualGUID(riid, &IID_IDirectDrawSurface7)
91 || IsEqualGUID(riid, &IID_IDirectDrawSurface4) )
93 IUnknown_AddRef(iface);
94 *obj = ICOM_INTERFACE(This, IDirectDrawSurface7);
95 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
96 return S_OK;
98 else if( IsEqualGUID(riid, &IID_IDirectDrawSurface3)
99 || IsEqualGUID(riid, &IID_IDirectDrawSurface2)
100 || IsEqualGUID(riid, &IID_IDirectDrawSurface) )
102 IUnknown_AddRef(iface);
103 *obj = ICOM_INTERFACE(This, IDirectDrawSurface3);
104 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
105 return S_OK;
107 else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) )
109 IUnknown_AddRef(iface);
110 *obj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
111 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
112 return S_OK;
114 else if( IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D) ||
115 IsEqualGUID(riid, &IID_IDirect3DHALDevice) )
117 IDirect3DDevice7 *d3d;
119 /* Call into IDirect3D7 for creation */
120 IDirect3D7_CreateDevice(ICOM_INTERFACE(This->ddraw, IDirect3D7),
121 riid,
122 ICOM_INTERFACE(This, IDirectDrawSurface7),
123 &d3d);
125 *obj = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice, d3d);
126 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
128 return S_OK;
130 else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
131 IsEqualGUID( &IID_IDirect3DTexture2, riid ))
133 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
135 *obj = ICOM_INTERFACE(This, IDirect3DTexture);
136 TRACE(" returning Direct3DTexture interface at %p.\n", *obj);
138 else
140 *obj = ICOM_INTERFACE(This, IDirect3DTexture2);
141 TRACE(" returning Direct3DTexture2 interface at %p.\n", *obj);
143 IUnknown_AddRef( (IUnknown *) *obj);
144 return S_OK;
147 ERR("No interface\n");
148 return E_NOINTERFACE;
151 /*****************************************************************************
152 * IDirectDrawSurface7::AddRef
154 * A normal addref implementation
156 * Returns:
157 * The new refcount
159 *****************************************************************************/
160 static ULONG WINAPI
161 IDirectDrawSurfaceImpl_AddRef(IDirectDrawSurface7 *iface)
163 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
164 ULONG refCount = InterlockedIncrement(&This->ref);
166 TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1);
167 return refCount;
170 /*****************************************************************************
171 * IDirectDrawSurfaceImpl_Destroy
173 * A helper function for IDirectDrawSurface7::Release
175 * Frees the surface, regardless of its refcount.
176 * See IDirectDrawSurface7::Release for more information
178 * Params:
179 * This: Surface to free
181 *****************************************************************************/
182 static void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This)
184 TRACE("(%p)\n", This);
186 /* Check the refcount and give a warning */
187 if(This->ref > 1)
189 /* This can happen when a complex surface is destroyed,
190 * because the 2nd surface was addref()ed when the app
191 * called GetAttachedSurface
193 WARN("(%p): Destroying surface with refount %ld\n", This, This->ref);
196 /* Check for attached surfaces and detach them */
197 if(This->first_attached != This)
199 /* Well, this shouldn't happen: The surface being attached is addref()ed
200 * in AddAttachedSurface, so it shouldn't be released until DeleteAttachedSurface
201 * is called, because the refcount is held. It looks like the app released()
202 * it often enough to force this
204 IDirectDrawSurface7 *root = ICOM_INTERFACE(This->first_attached, IDirectDrawSurface7);
205 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This, IDirectDrawSurface7);
207 FIXME("(%p) Freeing a surface that is attached to surface %p\n", This, This->first_attached);
209 /* The refcount will drop to -1 here */
210 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
212 ERR("(%p) DeleteAttachedSurface failed!\n", This);
216 while(This->next_attached != NULL)
218 IDirectDrawSurface7 *root = ICOM_INTERFACE(This, IDirectDrawSurface7);
219 IDirectDrawSurface7 *detach = ICOM_INTERFACE(This->next_attached, IDirectDrawSurface7);
221 if(IDirectDrawSurface7_DeleteAttachedSurface(root, 0, detach) != DD_OK)
223 ERR("(%p) DeleteAttachedSurface failed!\n", This);
224 assert(0);
228 /* Now destroy the surface. Wait: It could have been released if we are a texture */
229 if(This->WineD3DSurface)
230 IWineD3DSurface_Release(This->WineD3DSurface);
232 /* Having a texture handle set implies that the device still exists */
233 if(This->Handle)
235 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
236 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
239 /* Reduce the ddraw surface count */
240 InterlockedDecrement(&This->ddraw->surfaces);
241 if(This->prev)
242 This->prev->next = This->next;
243 else
245 assert(This->ddraw->surface_list == This);
246 This->ddraw->surface_list = This->next;
248 if(This->next)
249 This->next->prev = This->prev;
251 HeapFree(GetProcessHeap(), 0, This);
254 /*****************************************************************************
255 * IDirectDrawSurface7::Release
257 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
258 * surface is destroyed.
260 * Destroying the surface is a bit tricky. For the connection between
261 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
262 * It has a nice graph explaining the connection.
264 * What happens here is basically this:
265 * When a surface is destroyed, its WineD3DSurface is released,
266 * and the refcount of the DirectDraw interface is reduced by 1. If it has
267 * complex surfaces attached to it, then these surfaces are destroyed too,
268 * regardless of their refcount. If any surface being destroyed has another
269 * surface attached to it (with a "soft" attachment, not complex), then
270 * this surface is detached with DeleteAttachedSurface.
272 * When the surface is a texture, the WineD3DTexture is released.
273 * If the surface is the Direct3D render target, then the D3D
274 * capabilities of the WineD3DDevice are uninitialized, which causes the
275 * swapchain to be released.
277 * Returns:
278 * The new refcount
280 *****************************************************************************/
281 static ULONG WINAPI
282 IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
284 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
285 ULONG ref;
286 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
287 ref = InterlockedDecrement(&This->ref);
289 if (ref == 0)
292 IDirectDrawSurfaceImpl *surf;
293 IDirectDrawImpl *ddraw;
294 IUnknown *ifaceToRelease = This->ifaceToRelease;
296 /* Destroy all complex attached surfaces
297 * Therefore, start with the first surface,
298 * except for textures. Not entirely sure what has
299 * to happen exactly in this case
301 if( (This->first_complex != This) && !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE))
303 FIXME("(%p) Destroying a surface which is a attached to a complex root %p\n", This, This->first_complex);
305 ddraw = This->ddraw;
307 /* If it's a texture, destroy the WineD3DTexture.
308 * WineD3D will destroy the IParent interfaces
309 * of the sublevels, which destroys the WineD3DSurfaces.
310 * Set the surfaces to NULL to avoid destroying them again later
312 if(This->wineD3DTexture)
314 IWineD3DTexture_Release(This->wineD3DTexture);
316 /* If it's the RenderTarget, destroy the d3ddevice */
317 else if( (ddraw->d3d_initialized) && (This == ddraw->d3d_target))
319 TRACE("(%p) Destroying the render target, uninitializing D3D\n", This);
321 /* Unset any index buffer, just to be sure */
322 IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, 0);
324 if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
326 /* Not good */
327 ERR("(%p) Failed to uninit 3D\n", This);
329 else
331 /* Free the d3d window if one was created */
332 if(ddraw->d3d_window != 0)
334 TRACE(" (%p) Destroying the hidden render window %p\n", This, ddraw->d3d_window);
335 DestroyWindow(ddraw->d3d_window);
336 ddraw->d3d_window = 0;
338 /* Unset the pointers */
341 ddraw->d3d_initialized = FALSE;
342 ddraw->d3d_target = NULL;
344 /* Write a trace because D3D unloading was the reason for many
345 * crashes during development.
347 TRACE("(%p) D3D unloaded\n", This);
349 else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
350 DDSCAPS_3DDEVICE |
351 DDSCAPS_TEXTURE ) )
353 /* It's a render target, but no swapchain was created.
354 * The IParent interfaces have to be released manually.
355 * The same applies for textures without an
356 * IWineD3DTexture object attached
358 surf = This;
359 while(surf)
361 IParent *Parent;
363 IWineD3DSurface_GetParent(surf->WineD3DSurface,
364 (IUnknown **) &Parent);
365 IParent_Release(Parent); /* For the getParent */
366 IParent_Release(Parent); /* To release it */
367 surf = surf->next_complex;
371 /* The refcount test shows that the palette is detached when the surface is destroyed */
372 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
373 NULL);
375 /* Loop through all complex attached surfaces,
376 * and destroy them
378 while( (surf = This->next_complex) )
380 This->next_complex = surf->next_complex; /* Unchain it from the complex listing */
381 IDirectDrawSurfaceImpl_Destroy(surf); /* Destroy it */
384 /* Destroy the surface.
386 IDirectDrawSurfaceImpl_Destroy(This);
388 /* Reduce the ddraw refcount */
389 IUnknown_Release(ifaceToRelease);
392 return ref;
395 /*****************************************************************************
396 * IDirectDrawSurface7::GetAttachedSurface
398 * Returns an attached surface with the requested caps. Surface attachment
399 * and complex surfaces are not clearly described by the MSDN or sdk,
400 * so this method is tricky and likely to contain problems.
401 * This implementation searches the complex chain first, then the
402 * attachment chain, and then it checks if the caps match to itself.
404 * The chains are searched from This down to the last surface in the chain,
405 * not from the first element in the chain. The first surface found is
406 * returned. The MSDN says that this method fails if more than one surface
407 * matches the caps, but apparently this is incorrect.
409 * The found surface is AddRef-ed before it is returned.
411 * Params:
412 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
413 * Surface: Address to store the found surface
415 * Returns:
416 * DD_OK on success
417 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
418 * DDERR_NOTFOUND if no surface was found
420 *****************************************************************************/
421 static HRESULT WINAPI
422 IDirectDrawSurfaceImpl_GetAttachedSurface(IDirectDrawSurface7 *iface,
423 DDSCAPS2 *Caps,
424 IDirectDrawSurface7 **Surface)
426 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
427 IDirectDrawSurfaceImpl *surf;
428 DDSCAPS2 our_caps;
430 TRACE("(%p)->(%p,%p)\n", This, Caps, Surface);
432 our_caps = *Caps;
434 if(This->version < 7)
436 /* Earlier dx apps put garbage into these members, clear them */
437 our_caps.dwCaps2 = 0;
438 our_caps.dwCaps3 = 0;
439 our_caps.dwCaps4 = 0;
442 TRACE("(%p): Looking for caps: %lx,%lx,%lx,%lx\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.dwCaps4); /* FIXME: Better debugging */
444 /* First, look at the complex chain */
445 surf = This;
447 while( (surf = surf->next_complex) )
449 if (TRACE_ON(ddraw))
451 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx\n", surf,
452 surf->surface_desc.ddsCaps.dwCaps,
453 surf->surface_desc.ddsCaps.dwCaps2,
454 surf->surface_desc.ddsCaps.dwCaps3,
455 surf->surface_desc.ddsCaps.dwCaps4);
458 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
459 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
461 /* MSDN: "This method fails if more than one surface is attached
462 * that matches the capabilities requested."
464 * The mipmap demo of the DirectX7 sdk shows what to do here:
465 * apparently apps expect the first found surface to be returned.
468 TRACE("(%p): Returning surface %p\n", This, surf);
469 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
470 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
471 IDirectDrawSurface7_AddRef(*Surface);
472 return DD_OK;
476 /* Next, look at the attachment chain */
477 surf = This;
479 while( (surf = surf->next_attached) )
481 if (TRACE_ON(ddraw))
483 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx\n", surf,
484 surf->surface_desc.ddsCaps.dwCaps,
485 surf->surface_desc.ddsCaps.dwCaps2,
486 surf->surface_desc.ddsCaps.dwCaps3,
487 surf->surface_desc.ddsCaps.dwCaps4);
490 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
491 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
493 /* MSDN: "This method fails if more than one surface is attached
494 * that matches the capabilities requested."
496 * The mipmap demo of the DirectX7 sdk shows what to do here:
497 * apparently apps expect the first found surface to be returned.
500 TRACE("(%p): Returning surface %p\n", This, surf);
501 *Surface = ICOM_INTERFACE(surf, IDirectDrawSurface7);
502 IDirectDrawSurface7_AddRef(*Surface);
503 return DD_OK;
507 /* Is this valid? */
508 #if 0
509 if (((This->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
510 ((This->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2) &&
511 This == This->first_complex)
514 TRACE("(%p): Returning surface %p\n", This, This);
515 *Surface = ICOM_INTERFACE(This, IDirectDrawSurface7);
516 IDirectDrawSurface7_AddRef(*Surface);
517 return DD_OK;
519 #endif
521 /* What to do here? Continue with the surface root?? */
523 TRACE("(%p) Didn't find a valid surface\n", This);
524 return DDERR_NOTFOUND;
527 /*****************************************************************************
528 * IDirectDrawSurface7::Lock
530 * Locks the surface and returns a pointer to the surface's memory
532 * Params:
533 * Rect: Rectangle to lock. If NULL, the whole surface is locked
534 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
535 * Flags: Locking flags, e.g Read only or write only
536 * h: An event handle that's not used and must be NULL
538 * Returns:
539 * DD_OK on success
540 * DDERR_INVALIDPARAMS if DDSD is NULL
541 * For more details, see IWineD3DSurface::LockRect
543 *****************************************************************************/
544 static HRESULT WINAPI
545 IDirectDrawSurfaceImpl_Lock(IDirectDrawSurface7 *iface,
546 RECT *Rect,
547 DDSURFACEDESC2 *DDSD,
548 DWORD Flags,
549 HANDLE h)
551 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
552 WINED3DLOCKED_RECT LockedRect;
553 HRESULT hr;
554 TRACE("(%p)->(%p,%p,%lx,%p)\n", This, Rect, DDSD, Flags, h);
556 if(!DDSD)
557 return DDERR_INVALIDPARAMS;
559 /* Should I check for the handle to be NULL?
561 * The DDLOCK flags and the D3DLOCK flags are equal
562 * for the supported values. The others are ignored by WineD3D
565 /* Hmm. Anarchy online passes an uninitialized surface descriptor,
566 * that means it doesn't have dwSize set. Init it to some sane
567 * value
569 if(DDSD->dwSize <= sizeof(DDSURFACEDESC))
571 DDSD->dwSize = sizeof(DDSURFACEDESC);
573 else
575 DDSD->dwSize = sizeof(DDSURFACEDESC2);
578 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
579 hr = IWineD3DSurface_LockRect(This->WineD3DSurface,
580 &LockedRect,
581 Rect,
582 Flags);
583 if(hr != D3D_OK) return hr;
585 /* Override the memory area and the pitch */
586 DDSD->dwFlags |= DDSD_LPSURFACE;
587 DDSD->lpSurface = LockedRect.pBits;
588 DDSD->dwFlags |= DDSD_PITCH;
589 DDSD->u1.lPitch = LockedRect.Pitch;
591 TRACE("locked surface returning description :\n");
592 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
594 return DD_OK;
597 /*****************************************************************************
598 * IDirectDrawSurface7::Unlock
600 * Unlocks an locked surface
602 * Params:
603 * Rect: Not used by this implementation
605 * Returns:
606 * D3D_OK on success
607 * For more details, see IWineD3DSurface::UnlockRect
609 *****************************************************************************/
610 static HRESULT WINAPI
611 IDirectDrawSurfaceImpl_Unlock(IDirectDrawSurface7 *iface,
612 RECT *pRect)
614 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
615 TRACE("(%p)->(%p)\n", This, pRect);
617 return IWineD3DSurface_UnlockRect(This->WineD3DSurface);
620 /*****************************************************************************
621 * IDirectDrawSurface7::Flip
623 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
624 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
625 * the flip target is passed to WineD3D, even if the app didn't specify one
627 * Params:
628 * DestOverride: Specifies the surface that will become the new front
629 * buffer. If NULL, the current back buffer is used
630 * Flags: some DirectDraw flags, see include/ddraw.h
632 * Returns:
633 * DD_OK on success
634 * DDERR_NOTFLIPPABLE if no flip target could be found
635 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
636 * For more details, see IWineD3DSurface::Flip
638 *****************************************************************************/
639 static HRESULT WINAPI
640 IDirectDrawSurfaceImpl_Flip(IDirectDrawSurface7 *iface,
641 IDirectDrawSurface7 *DestOverride,
642 DWORD Flags)
644 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
645 IDirectDrawSurfaceImpl *Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestOverride);
646 IDirectDrawSurface7 *Override7;
647 HRESULT hr;
648 TRACE("(%p)->(%p,%lx)\n", This, DestOverride, Flags);
650 /* Flip has to be called from a front buffer
651 * What about overlay surfaces, AFAIK they can flip too?
653 if( !(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) )
654 return DDERR_INVALIDOBJECT; /* Unckecked */
656 /* WineD3D doesn't keep track of attached surface, so find the target */
657 if(!Override)
659 DDSCAPS2 Caps;
661 memset(&Caps, 0, sizeof(Caps));
662 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
663 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &Caps, &Override7);
664 if(hr != DD_OK)
666 ERR("Can't find a flip target\n");
667 return DDERR_NOTFLIPPABLE; /* Unchecked */
669 Override = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Override7);
671 /* For the GetAttachedSurface */
672 IDirectDrawSurface7_Release(Override7);
675 return IWineD3DSurface_Flip(This->WineD3DSurface,
676 Override->WineD3DSurface,
677 Flags);
680 /*****************************************************************************
681 * IDirectDrawSurface7::Blt
683 * Performs a blit on the surface
685 * Params:
686 * DestRect: Destination rectangle, can be NULL
687 * SrcSurface: Source surface, can be NULL
688 * SrcRect: Source rectange, can be NULL
689 * Flags: Blt flags
690 * DDBltFx: Some extended blt parameters, connected to the flags
692 * Returns:
693 * D3D_OK on success
694 * See IWineD3DSurface::Blt for more details
696 *****************************************************************************/
697 static HRESULT WINAPI
698 IDirectDrawSurfaceImpl_Blt(IDirectDrawSurface7 *iface,
699 RECT *DestRect,
700 IDirectDrawSurface7 *SrcSurface,
701 RECT *SrcRect,
702 DWORD Flags,
703 DDBLTFX *DDBltFx)
705 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
706 IDirectDrawSurfaceImpl *Src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcSurface);
707 TRACE("(%p)->(%p,%p,%p,%lx,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
709 return IWineD3DSurface_Blt(This->WineD3DSurface,
710 DestRect,
711 Src ? Src->WineD3DSurface : NULL,
712 SrcRect,
713 Flags,
714 DDBltFx);
717 /*****************************************************************************
718 * IDirectDrawSurface7::AddAttachedSurface
720 * Attaches a surface to another surface. Surface attachments are
721 * incorrectly described in the SDK and the MSDN, and this method
722 * is prone to bugs. The surface that is attached is AddRef-ed.
724 * The attachment list consists of a first surface (first_attached) and
725 * for each surface a pointer to the next attached surface (next_attached).
726 * For the first surface, and a surface that has no attachments
727 * first_attached points to the surface itself. A surface that has
728 * no successors in the chain has next_attached set to NULL.
730 * Newly attached surfaces are attached right after the root surface. The
731 * complex chains are handled separately in a similar chain, with
732 * first_complex and next_complex. If a surface is attached to a complex
733 * surface compound, it's attached to the surface that the app requested,
734 * not the complex root. See GetAttachedSurface for a description
735 * how surfaces are found.
737 * This is how the current implementation works, and it was coded by looking
738 * at the needs of the applications.
740 * So far only Z-Buffer attachments are tested, but there's no code yet
741 * to activate them. Mipmaps could be tricky to activate in WineD3D.
742 * Back buffers should work in 2D mode, but they are not tested.
743 * Rendering to the primary surface and switching between that and
744 * double buffering is not yet implemented in WineD3D, so for 3D it might
745 * have unexpected results.
747 * Params:
748 * Attach: Surface to attach to iface
750 * Returns:
751 * DD_OK on success
752 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
754 *****************************************************************************/
755 static HRESULT WINAPI
756 IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
757 IDirectDrawSurface7 *Attach)
759 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
760 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
761 TRACE("(%p)->(%p)\n", This, Surf);
763 /* Should I make sure to add it to the first complex surface? */
765 if(Surf == This)
766 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
768 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
769 * But apparently backbuffers and mipmaps can be attached too. */
771 /* Set MIPMAPSUBLEVEL if this seems to be one */
772 if (This->surface_desc.ddsCaps.dwCaps &
773 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
775 Surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
776 /* FIXME: we should probably also add to dwMipMapCount of this
777 * and all parent surfaces (update create_texture if you do) */
780 /* Check if the surface is already attached somewhere */
781 if( (Surf->next_attached != NULL) ||
782 (Surf->first_attached != Surf) )
784 ERR("(%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);
785 return DDERR_CANNOTATTACHSURFACE;
788 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
789 Surf->next_attached = This->next_attached;
790 Surf->first_attached = This->first_attached;
791 This->next_attached = Surf;
793 /* MSDN:
794 * "This method increments the reference count of the surface being attached."
796 IDirectDrawSurface7_AddRef(Attach);
797 return DD_OK;
800 /*****************************************************************************
801 * IDirectDrawSurface7::DeleteAttachedSurface
803 * Removes a surface from the attachment chain. The surface's refcount
804 * is decreased by one after it has been removed
806 * Params:
807 * Flags: Some flags, not used by this implementation
808 * Attach: Surface to detach
810 * Returns:
811 * DD_OK on success
812 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
814 *****************************************************************************/
815 static HRESULT WINAPI
816 IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
817 DWORD Flags,
818 IDirectDrawSurface7 *Attach)
820 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
821 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Attach);
822 IDirectDrawSurfaceImpl *Prev = This;
823 TRACE("(%p)->(%08lx,%p)\n", This, Flags, Surf);
825 if (!Surf || (Surf->first_attached != This) || (Surf == This) )
826 return DDERR_SURFACENOTATTACHED; /* unchecked */
828 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
829 if (This->surface_desc.ddsCaps.dwCaps &
830 Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
832 Surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
833 /* FIXME: we should probably also subtract from dwMipMapCount of this
834 * and all parent surfaces */
837 /* Find the predecessor of the detached surface */
838 while(Prev)
840 if(Prev->next_attached == Surf) break;
841 Prev = Prev->next_attached;
844 /* There must be a surface, otherwise there's a bug */
845 assert(Prev != NULL);
847 /* Unchain the surface */
848 Prev->next_attached = Surf->next_attached;
849 Surf->next_attached = NULL;
850 Surf->first_attached = Surf;
852 IDirectDrawSurface7_Release(Attach);
853 return DD_OK;
856 /*****************************************************************************
857 * IDirectDrawSurface7::AddOverlayDirtyRect
859 * "This method is not currently implemented"
861 * Params:
862 * Rect: ?
864 * Returns:
865 * DDERR_UNSUPPORTED
867 *****************************************************************************/
868 static HRESULT WINAPI
869 IDirectDrawSurfaceImpl_AddOverlayDirtyRect(IDirectDrawSurface7 *iface,
870 LPRECT Rect)
872 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
873 TRACE("(%p)->(%p)\n",This,Rect);
875 /* MSDN says it's not implemented. I could forward it to WineD3D,
876 * then we'd implement it, but I don't think that's a good idea
877 * (Stefan Dösinger)
879 #if 0
880 return IWineD3DSurface_AddOverlayDirtyRect(This->WineD3DSurface, pRect);
881 #endif
882 return DDERR_UNSUPPORTED; /* unchecked */
885 /*****************************************************************************
886 * IDirectDrawSurface7::GetDC
888 * Returns a GDI device context for the surface
890 * Params:
891 * hdc: Address of a HDC variable to store the dc to
893 * Returns:
894 * DD_OK on success
895 * DDERR_INVALIDPARAMS if hdc is NULL
896 * For details, see IWineD3DSurface::GetDC
898 *****************************************************************************/
899 static HRESULT WINAPI
900 IDirectDrawSurfaceImpl_GetDC(IDirectDrawSurface7 *iface,
901 HDC *hdc)
903 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
904 TRACE("(%p)->(%p): Relay\n", This, hdc);
906 if(!hdc)
907 return DDERR_INVALIDPARAMS;
909 return IWineD3DSurface_GetDC(This->WineD3DSurface,
910 hdc);
913 /*****************************************************************************
914 * IDirectDrawSurface7::ReleaseDC
916 * Releases the DC that was constructed with GetDC
918 * Params:
919 * hdc: HDC to release
921 * Returns:
922 * DD_OK on success
923 * For more details, see IWineD3DSurface::ReleaseDC
925 *****************************************************************************/
926 static HRESULT WINAPI
927 IDirectDrawSurfaceImpl_ReleaseDC(IDirectDrawSurface7 *iface,
928 HDC hdc)
930 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
931 TRACE("(%p)->(%p): Relay\n", This, hdc);
933 return IWineD3DSurface_ReleaseDC(This->WineD3DSurface, hdc);
936 /*****************************************************************************
937 * IDirectDrawSurface7::GetCaps
939 * Returns the surface's caps
941 * Params:
942 * Caps: Address to write the caps to
944 * Returns:
945 * DD_OK on success
946 * DDERR_INVALIDPARAMS if Caps is NULL
948 *****************************************************************************/
949 static HRESULT WINAPI
950 IDirectDrawSurfaceImpl_GetCaps(IDirectDrawSurface7 *iface,
951 DDSCAPS2 *Caps)
953 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
954 TRACE("(%p)->(%p)\n",This,Caps);
956 if(!Caps)
957 return DDERR_INVALIDPARAMS;
959 *Caps = This->surface_desc.ddsCaps;
960 return DD_OK;
963 /*****************************************************************************
964 * IDirectDrawSurface7::SetPriority
966 * Sets a texture priority for managed textures.
968 * Params:
969 * Priority: The new priority
971 * Returns:
972 * DD_OK on success
973 * For more details, see IWineD3DSurface::SetPriority
975 *****************************************************************************/
976 static HRESULT WINAPI
977 IDirectDrawSurfaceImpl_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
979 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
980 TRACE("(%p)->(%ld): Relay!\n",This,Priority);
982 return IWineD3DSurface_SetPriority(This->WineD3DSurface, Priority);
985 /*****************************************************************************
986 * IDirectDrawSurface7::GetPriority
988 * Returns the surface's priority
990 * Params:
991 * Priority: Address of a variable to write the priority to
993 * Returns:
994 * D3D_OK on success
995 * DDERR_INVALIDPARAMS if Priority == NULL
996 * For more details, see IWineD3DSurface::GetPriority
998 *****************************************************************************/
999 static HRESULT WINAPI
1000 IDirectDrawSurfaceImpl_GetPriority(IDirectDrawSurface7 *iface,
1001 DWORD *Priority)
1003 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1004 TRACE("(%p)->(%p): Relay\n",This,Priority);
1006 if(!Priority)
1007 return DDERR_INVALIDPARAMS;
1009 *Priority = IWineD3DSurface_GetPriority(This->WineD3DSurface);
1010 return DD_OK;
1013 /*****************************************************************************
1014 * IDirectDrawSurface7::SetPrivateData
1016 * Stores some data in the surface that is intended for the application's
1017 * use.
1019 * Params:
1020 * tag: GUID that identifies the data
1021 * Data: Pointer to the private data
1022 * Size: Size of the private data
1023 * Flags: Some flags
1025 * Returns:
1026 * D3D_OK on success
1027 * For more details, see IWineD3DSurface::SetPrivateData
1029 *****************************************************************************/
1030 static HRESULT WINAPI
1031 IDirectDrawSurfaceImpl_SetPrivateData(IDirectDrawSurface7 *iface,
1032 REFGUID tag,
1033 void *Data,
1034 DWORD Size,
1035 DWORD Flags)
1037 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1038 TRACE("(%p)->(%s,%p,%ld,%lx): Relay\n", This, debugstr_guid(tag), Data, Size, Flags);
1040 return IWineD3DSurface_SetPrivateData(This->WineD3DSurface,
1041 tag,
1042 Data,
1043 Size,
1044 Flags);
1047 /*****************************************************************************
1048 * IDirectDrawSurface7::GetPrivateData
1050 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
1052 * Params:
1053 * tag: GUID of the data to return
1054 * Data: Address where to write the data to
1055 * Size: Size of the buffer at Data
1057 * Returns:
1058 * DD_OK on success
1059 * DDERR_INVALIDPARAMS if Data is NULL
1060 * For more details, see IWineD3DSurface::GetPrivateData
1062 *****************************************************************************/
1063 static HRESULT WINAPI
1064 IDirectDrawSurfaceImpl_GetPrivateData(IDirectDrawSurface7 *iface,
1065 REFGUID tag,
1066 void *Data,
1067 DWORD *Size)
1069 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1070 TRACE("(%p)->(%s,%p,%p): Relay\n", This, debugstr_guid(tag), Data, Size);
1072 if(!Data)
1073 return DDERR_INVALIDPARAMS;
1075 return IWineD3DSurface_GetPrivateData(This->WineD3DSurface,
1076 tag,
1077 Data,
1078 Size);
1081 /*****************************************************************************
1082 * IDirectDrawSurface7::FreePrivateData
1084 * Frees private data stored in the surface
1086 * Params:
1087 * tag: Tag of the data to free
1089 * Returns:
1090 * D3D_OK on success
1091 * For more details, see IWineD3DSurface::FreePrivateData
1093 *****************************************************************************/
1094 static HRESULT WINAPI
1095 IDirectDrawSurfaceImpl_FreePrivateData(IDirectDrawSurface7 *iface,
1096 REFGUID tag)
1098 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1099 TRACE("(%p)->(%s): Relay\n", This, debugstr_guid(tag));
1101 return IWineD3DSurface_FreePrivateData(This->WineD3DSurface, tag);
1104 /*****************************************************************************
1105 * IDirectDrawSurface7::PageLock
1107 * Prevents a sysmem surface from being paged out
1109 * Params:
1110 * Flags: Not used, must be 0(unchecked)
1112 * Returns:
1113 * DD_OK, because it's a stub
1115 *****************************************************************************/
1116 static HRESULT WINAPI
1117 IDirectDrawSurfaceImpl_PageLock(IDirectDrawSurface7 *iface,
1118 DWORD Flags)
1120 TRACE("(%p)->(%lx)\n", iface, Flags);
1122 /* This is Windows memory management related - we don't need this */
1123 return DD_OK;
1126 /*****************************************************************************
1127 * IDirectDrawSurface7::PageUnlock
1129 * Allows a sysmem surface to be paged out
1131 * Params:
1132 * Flags: Not used, must be 0(unckeched)
1134 * Returns:
1135 * DD_OK, because it's a stub
1137 *****************************************************************************/
1138 static HRESULT WINAPI
1139 IDirectDrawSurfaceImpl_PageUnlock(IDirectDrawSurface7 *iface,
1140 DWORD Flags)
1142 TRACE("(%p)->(%lx)\n", iface, Flags);
1144 return DD_OK;
1147 /*****************************************************************************
1148 * IDirectDrawSurface7::BltBatch
1150 * An unimplemented function
1152 * Params:
1155 * Returns:
1156 * DDERR_UNSUPPORTED
1158 *****************************************************************************/
1159 static HRESULT WINAPI IDirectDrawSurfaceImpl_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
1161 TRACE("(%p)->(%p,%ld,%08lx)\n",iface,Batch,Count,Flags);
1163 /* MSDN: "not currently implemented" */
1164 return DDERR_UNSUPPORTED;
1167 /*****************************************************************************
1168 * IDirectDrawSurface7::EnumAttachedSurfaces
1170 * Enumerates all surfaces attached to this surface
1172 * Params:
1173 * context: Pointer to pass unmodified to the callback
1174 * cb: Callback function to call for each surface
1176 * Returns:
1177 * DD_OK on success
1178 * DDERR_INVALIDPARAMS if cb is NULL
1180 *****************************************************************************/
1181 static HRESULT WINAPI
1182 IDirectDrawSurfaceImpl_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
1183 void *context,
1184 LPDDENUMSURFACESCALLBACK7 cb)
1186 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1187 IDirectDrawSurfaceImpl *surf;
1188 DDSURFACEDESC2 desc;
1190 /* Attached surfaces aren't handled in WineD3D */
1191 TRACE("(%p)->(%p,%p)\n",This,context,cb);
1193 if(!cb)
1194 return DDERR_INVALIDPARAMS;
1196 for (surf = This->next_complex; surf != NULL; surf = surf->next_complex)
1198 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1199 desc = surf->surface_desc;
1200 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1201 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1202 return DD_OK;
1205 for (surf = This->next_attached; surf != NULL; surf = surf->next_attached)
1207 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
1208 desc = surf->surface_desc;
1209 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
1210 if (cb( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, context) == DDENUMRET_CANCEL)
1211 return DD_OK;
1214 TRACE(" end of enumeration.\n");
1216 return DD_OK;
1219 /*****************************************************************************
1220 * IDirectDrawSurface7::EnumOverlayZOrders
1222 * "Enumerates the overlay surfaces on the specified destination"
1224 * Params:
1225 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
1226 * context: context to pass back to the callback
1227 * cb: callback function to call for each enumerated surface
1229 * Returns:
1230 * DD_OK, because it's a stub
1232 *****************************************************************************/
1233 static HRESULT WINAPI
1234 IDirectDrawSurfaceImpl_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
1235 DWORD Flags,
1236 void *context,
1237 LPDDENUMSURFACESCALLBACK7 cb)
1239 FIXME("(%p)->(%lx,%p,%p): Stub!\n", iface, Flags, context, cb);
1241 return DD_OK;
1244 /*****************************************************************************
1245 * IDirectDrawSurface7::GetBltStatus
1247 * Returns the blitting status
1249 * Params:
1250 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
1252 * Returns:
1253 * See IWineD3DSurface::Blt
1255 *****************************************************************************/
1256 static HRESULT WINAPI
1257 IDirectDrawSurfaceImpl_GetBltStatus(IDirectDrawSurface7 *iface,
1258 DWORD Flags)
1260 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1261 TRACE("(%p)->(%lx): Relay\n", This, Flags);
1263 return IWineD3DSurface_GetBltStatus(This->WineD3DSurface, Flags);
1266 /*****************************************************************************
1267 * IDirectDrawSurface7::GetColorKey
1269 * Returns the color key assigned to the surface
1271 * Params:
1272 * Flags: Some flags
1273 * CKey: Address to store the key to
1275 * Returns:
1276 * DD_OK on success
1277 * DDERR_INVALIDPARAMS if CKey is NULL
1279 *****************************************************************************/
1280 static HRESULT WINAPI
1281 IDirectDrawSurfaceImpl_GetColorKey(IDirectDrawSurface7 *iface,
1282 DWORD Flags,
1283 DDCOLORKEY *CKey)
1285 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
1286 * isn't there? That's like saying that an int isn't there. (Which MS
1287 * has done in other docs.) */
1289 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1291 if(!CKey)
1292 return DDERR_INVALIDPARAMS;
1294 switch (Flags)
1296 case DDCKEY_DESTBLT:
1297 *CKey = This->surface_desc.ddckCKDestBlt;
1298 break;
1300 case DDCKEY_DESTOVERLAY:
1301 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
1302 break;
1304 case DDCKEY_SRCBLT:
1305 *CKey = This->surface_desc.ddckCKSrcBlt;
1306 break;
1308 case DDCKEY_SRCOVERLAY:
1309 *CKey = This->surface_desc.ddckCKSrcOverlay;
1310 break;
1312 default:
1313 return DDERR_INVALIDPARAMS;
1316 return DD_OK;
1319 /*****************************************************************************
1320 * IDirectDrawSurface7::GetFlipStatus
1322 * Returns the flipping status of the surface
1324 * Params:
1325 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
1327 * Returns:
1328 * See IWineD3DSurface::GetFlipStatus
1330 *****************************************************************************/
1331 static HRESULT WINAPI
1332 IDirectDrawSurfaceImpl_GetFlipStatus(IDirectDrawSurface7 *iface,
1333 DWORD Flags)
1335 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1336 TRACE("(%p)->(%lx): Relay\n", This, Flags);
1338 return IWineD3DSurface_GetFlipStatus(This->WineD3DSurface, Flags);
1341 /*****************************************************************************
1342 * IDirectDrawSurface7::GetOverlayPosition
1344 * Returns the display coordinates of a visible and active overlay surface
1346 * Params:
1350 * Returns:
1351 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
1352 *****************************************************************************/
1353 static HRESULT WINAPI
1354 IDirectDrawSurfaceImpl_GetOverlayPosition(IDirectDrawSurface7 *iface,
1355 LONG *X,
1356 LONG *Y) {
1357 FIXME("(%p)->(%p,%p): Stub!\n", iface, X, Y);
1359 return DDERR_NOTAOVERLAYSURFACE;
1362 /*****************************************************************************
1363 * IDirectDrawSurface7::GetPixelFormat
1365 * Returns the pixel format of the Surface
1367 * Params:
1368 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
1369 * format should be written
1371 * Returns:
1372 * DD_OK on success
1373 * DDERR_INVALIDPARAMS if PixelFormat is NULL
1375 *****************************************************************************/
1376 static HRESULT WINAPI
1377 IDirectDrawSurfaceImpl_GetPixelFormat(IDirectDrawSurface7 *iface,
1378 DDPIXELFORMAT *PixelFormat)
1380 /* What is DDERR_INVALIDSURFACETYPE for here? */
1381 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1382 TRACE("(%p)->(%p)\n",This,PixelFormat);
1384 if(!PixelFormat)
1385 return DDERR_INVALIDPARAMS;
1387 DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
1389 return DD_OK;
1393 /*****************************************************************************
1394 * IDirectDrawSurface7::GetSurfaceDesc
1396 * Returns the description of this surface
1398 * Params:
1399 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
1400 * surface desc
1402 * Returns:
1403 * DD_OK on success
1404 * DDERR_INVALIDPARAMS if DDSD is NULL
1406 *****************************************************************************/
1407 static HRESULT WINAPI
1408 IDirectDrawSurfaceImpl_GetSurfaceDesc(IDirectDrawSurface7 *iface,
1409 DDSURFACEDESC2 *DDSD)
1411 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1413 TRACE("(%p)->(%p)\n",This,DDSD);
1415 if(!DDSD)
1416 return DDERR_INVALIDPARAMS;
1418 if ((DDSD->dwSize < sizeof(DDSURFACEDESC)) ||
1419 (DDSD->dwSize > sizeof(DDSURFACEDESC2)))
1421 ERR("Impossible/Strange struct size %ld.\n",DDSD->dwSize);
1422 return DDERR_GENERIC;
1425 DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
1426 TRACE("Returning surface desc:\n");
1427 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1429 return DD_OK;
1432 /*****************************************************************************
1433 * IDirectDrawSurface7::Initialize
1435 * Initializes the surface. This is a no-op in Wine
1437 * Params:
1438 * DD: Pointer to an DirectDraw interface
1439 * DDSD: Surface description for initialization
1441 * Returns:
1442 * DDERR_ALREADYINITIALIZED
1444 *****************************************************************************/
1445 static HRESULT WINAPI
1446 IDirectDrawSurfaceImpl_Initialize(IDirectDrawSurface7 *iface,
1447 IDirectDraw *DD,
1448 DDSURFACEDESC2 *DDSD)
1450 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1451 IDirectDrawImpl *ddimpl = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, DD);
1452 TRACE("(%p)->(%p,%p)\n",This,ddimpl,DDSD);
1454 return DDERR_ALREADYINITIALIZED;
1457 /*****************************************************************************
1458 * IDirectDrawSurface7::IsLost
1460 * Checks if the surface is lost
1462 * Returns:
1463 * DD_OK, if the surface is useable
1464 * DDERR_ISLOST if the surface is lost
1465 * See IWineD3DSurface::IsLost for more details
1467 *****************************************************************************/
1468 static HRESULT WINAPI
1469 IDirectDrawSurfaceImpl_IsLost(IDirectDrawSurface7 *iface)
1471 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1472 TRACE("(%p)\n", This);
1474 /* We lose the surface if the implementation was changed */
1475 if(This->ImplType != This->ddraw->ImplType)
1477 /* But this shouldn't happen. When we change the implementation,
1478 * all surfaces are re-created automatically, and their content
1479 * is copied
1481 ERR(" (%p) Implementation was changed from %d to %d\n", This, This->ImplType, This->ddraw->ImplType);
1482 return DDERR_SURFACELOST;
1485 return IWineD3DSurface_IsLost(This->WineD3DSurface);
1488 /*****************************************************************************
1489 * IDirectDrawSurface7::Restore
1491 * Restores a lost surface. This makes the surface usable again, but
1492 * doesn't reload its old contents
1494 * Returns:
1495 * DD_OK on success
1496 * See IWineD3DSurface::Restore for more details
1498 *****************************************************************************/
1499 static HRESULT WINAPI
1500 IDirectDrawSurfaceImpl_Restore(IDirectDrawSurface7 *iface)
1502 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1503 TRACE("(%p)\n", This);
1505 if(This->ImplType != This->ddraw->ImplType)
1507 /* Call the recreation callback. Make sure to AddRef first */
1508 IDirectDrawSurface_AddRef(iface);
1509 IDirectDrawImpl_RecreateSurfacesCallback(iface,
1510 &This->surface_desc,
1511 NULL /* Not needed */);
1513 return IWineD3DSurface_Restore(This->WineD3DSurface);
1516 /*****************************************************************************
1517 * IDirectDrawSurface7::SetOverlayPosition
1519 * Changes the display coordinates of an overlay surface
1521 * Params:
1522 * X:
1523 * Y:
1525 * Returns:
1526 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
1527 *****************************************************************************/
1528 static HRESULT WINAPI
1529 IDirectDrawSurfaceImpl_SetOverlayPosition(IDirectDrawSurface7 *iface,
1530 LONG X,
1531 LONG Y)
1533 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1534 FIXME("(%p)->(%ld,%ld): Stub!\n", This, X, Y);
1535 return DDERR_NOTAOVERLAYSURFACE;
1538 /*****************************************************************************
1539 * IDirectDrawSurface7::UpdateOverlay
1541 * Modifies the attributes of an overlay surface.
1543 * Params:
1544 * SrcRect: The section of the source being used for the overlay
1545 * DstSurface: Address of the surface that is overlaid
1546 * DstRect: Place of the overlay
1547 * Flags: some DDOVER_* flags
1549 * Returns:
1550 * DDERR_UNSUPPORTED, because we don't support overlays
1552 *****************************************************************************/
1553 static HRESULT WINAPI
1554 IDirectDrawSurfaceImpl_UpdateOverlay(IDirectDrawSurface7 *iface,
1555 LPRECT SrcRect,
1556 IDirectDrawSurface7 *DstSurface,
1557 LPRECT DstRect,
1558 DWORD Flags,
1559 LPDDOVERLAYFX FX)
1561 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1562 IDirectDrawSurfaceImpl *Dst = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DstSurface);
1563 FIXME("(%p)->(%p,%p,%p,%lx,%p): Stub!\n", This, SrcRect, Dst, DstRect, Flags, FX);
1564 return DDERR_UNSUPPORTED;
1567 /*****************************************************************************
1568 * IDirectDrawSurface7::UpdateOverlayDisplay
1570 * The DX7 sdk says that it's not implemented
1572 * Params:
1573 * Flags: ?
1575 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
1577 *****************************************************************************/
1578 static HRESULT WINAPI
1579 IDirectDrawSurfaceImpl_UpdateOverlayDisplay(IDirectDrawSurface7 *iface,
1580 DWORD Flags)
1582 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1583 TRACE("(%p)->(%lx)\n", This, Flags);
1584 return DDERR_UNSUPPORTED;
1587 /*****************************************************************************
1588 * IDirectDrawSurface7::UpdateOverlayZOrder
1590 * Sets an overlay's Z order
1592 * Params:
1593 * Flags: DDOVERZ_* flags
1594 * DDSRef: Defines the relative position in the overlay chain
1596 * Returns:
1597 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
1599 *****************************************************************************/
1600 static HRESULT WINAPI
1601 IDirectDrawSurfaceImpl_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
1602 DWORD Flags,
1603 IDirectDrawSurface7 *DDSRef)
1605 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1606 IDirectDrawSurfaceImpl *Ref = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DDSRef);
1607 FIXME("(%p)->(%lx,%p)\n", This, Flags, Ref);
1608 return DDERR_NOTAOVERLAYSURFACE;
1611 /*****************************************************************************
1612 * IDirectDrawSurface7::GetDDInterface
1614 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
1615 * surface belongs to
1617 * Params:
1618 * DD: Address to write the interface pointer to
1620 * Returns:
1621 * DD_OK on success
1622 * DDERR_INVALIDPARAMS if DD is NULL
1624 *****************************************************************************/
1625 static HRESULT WINAPI
1626 IDirectDrawSurfaceImpl_GetDDInterface(IDirectDrawSurface7 *iface,
1627 void **DD)
1629 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1631 /* It is not quite correct to use the same lpVtable for the different
1632 * IDirectDrawSurface versions because the GetDDInterface return different interfaces
1634 FIXME("(%p)->(%p)\n",This,DD);
1636 if(!DD)
1637 return DDERR_INVALIDPARAMS;
1639 switch(This->version)
1641 case 7:
1642 *((IDirectDraw7 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
1643 IDirectDraw7_AddRef(*(IDirectDraw7 **) DD);
1644 break;
1646 case 4:
1647 *((IDirectDraw4 **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
1648 IDirectDraw4_AddRef(*(IDirectDraw4 **) DD);
1650 case 2:
1651 case 1:
1652 *((IDirectDraw **) DD) = ICOM_INTERFACE(This->ddraw, IDirectDraw);
1653 IDirectDraw_AddRef( *(IDirectDraw **) DD);
1654 break;
1658 return DD_OK;
1661 /* This seems also windows implementation specific - I don't think WineD3D needs this */
1662 static HRESULT WINAPI IDirectDrawSurfaceImpl_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
1664 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1665 volatile IDirectDrawSurfaceImpl* vThis = This;
1667 TRACE("(%p)\n",This);
1668 /* A uniqueness value of 0 is apparently special.
1669 * This needs to be checked. */
1670 while (1) {
1671 DWORD old_uniqueness_value = vThis->uniqueness_value;
1672 DWORD new_uniqueness_value = old_uniqueness_value+1;
1674 if (old_uniqueness_value == 0) break;
1675 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
1677 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
1678 old_uniqueness_value,
1679 new_uniqueness_value)
1680 == old_uniqueness_value)
1681 break;
1684 return DD_OK;
1687 static HRESULT WINAPI IDirectDrawSurfaceImpl_GetUniquenessValue(IDirectDrawSurface7 *iface, LPDWORD pValue)
1689 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1691 TRACE("(%p)->(%p)\n",This,pValue);
1692 *pValue = This->uniqueness_value;
1693 return DD_OK;
1696 /*****************************************************************************
1697 * IDirectDrawSurface7::SetLOD
1699 * Sets the level of detail of a texture
1701 * Params:
1702 * MaxLOD: LOD to set
1704 * Returns:
1705 * DD_OK on success
1706 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1708 *****************************************************************************/
1709 static HRESULT WINAPI
1710 IDirectDrawSurfaceImpl_SetLOD(IDirectDrawSurface7 *iface,
1711 DWORD MaxLOD)
1713 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1714 TRACE("(%p)->(%ld)\n", This, MaxLOD);
1716 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1717 return DDERR_INVALIDOBJECT;
1719 if(!This->wineD3DTexture)
1721 ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
1722 return DDERR_INVALIDOBJECT;
1725 return IWineD3DTexture_SetLOD(This->wineD3DTexture,
1726 MaxLOD);
1729 /*****************************************************************************
1730 * IDirectDrawSurface7::GetLOD
1732 * Returns the level of detail of a Direct3D texture
1734 * Params:
1735 * MaxLOD: Address to write the LOD to
1737 * Returns:
1738 * DD_OK on success
1739 * DDERR_INVALIDPARAMS if MaxLOD is NULL
1740 * DDERR_INVALIDOBJECT if the surface is invalid for this method
1742 *****************************************************************************/
1743 static HRESULT WINAPI
1744 IDirectDrawSurfaceImpl_GetLOD(IDirectDrawSurface7 *iface,
1745 DWORD *MaxLOD)
1747 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1748 TRACE("(%p)->(%p)\n", This, MaxLOD);
1750 if(!MaxLOD)
1751 return DDERR_INVALIDPARAMS;
1753 if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
1754 return DDERR_INVALIDOBJECT;
1756 *MaxLOD = IWineD3DTexture_GetLOD(This->wineD3DTexture);
1757 return DD_OK;
1760 /*****************************************************************************
1761 * IDirectDrawSurface7::BltFast
1763 * Performs a fast Blit.
1765 * Params:
1766 * dstx: The x coordinate to blit to on the destination
1767 * dsty: The y coordinate to blit to on the destination
1768 * Source: The source surface
1769 * rsrc: The source rectangle
1770 * trans: Type of transfer. Some DDBLTFAST_* flags
1772 * Returns:
1773 * DD_OK on success
1774 * For more details, see IWineD3DSurface::BltFast
1776 *****************************************************************************/
1777 static HRESULT WINAPI
1778 IDirectDrawSurfaceImpl_BltFast(IDirectDrawSurface7 *iface,
1779 DWORD dstx,
1780 DWORD dsty,
1781 IDirectDrawSurface7 *Source,
1782 RECT *rsrc,
1783 DWORD trans)
1785 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1786 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Source);
1787 TRACE("(%p)->(%ld,%ld,%p,%p,%ld): Relay\n", This, dstx, dsty, Source, rsrc, trans);
1789 return IWineD3DSurface_BltFast(This->WineD3DSurface,
1790 dstx, dsty,
1791 src ? src->WineD3DSurface : NULL,
1792 rsrc,
1793 trans);
1796 /*****************************************************************************
1797 * IDirectDrawSurface7::GetClipper
1799 * Returns the IDirectDrawClipper interface of the clipper assigned to this
1800 * surface
1802 * Params:
1803 * Clipper: Address to store the interface pointer at
1805 * Returns:
1806 * DD_OK on success
1807 * DDERR_INVALIDPARAMS if Clipper is NULL
1808 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
1810 *****************************************************************************/
1811 static HRESULT WINAPI
1812 IDirectDrawSurfaceImpl_GetClipper(IDirectDrawSurface7 *iface,
1813 IDirectDrawClipper **Clipper)
1815 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1816 TRACE("(%p)->(%p)\n", This, Clipper);
1818 if(!Clipper)
1819 return DDERR_INVALIDPARAMS;
1821 if(This->clipper == NULL)
1822 return DDERR_NOCLIPPERATTACHED;
1824 *Clipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
1825 IDirectDrawClipper_AddRef(*Clipper);
1826 return DD_OK;
1829 /*****************************************************************************
1830 * IDirectDrawSurface7::SetClipper
1832 * Sets a clipper for the surface
1834 * Params:
1835 * Clipper: IDirectDrawClipper interface of the clipper to set
1837 * Returns:
1838 * DD_OK on success
1840 *****************************************************************************/
1841 static HRESULT WINAPI
1842 IDirectDrawSurfaceImpl_SetClipper(IDirectDrawSurface7 *iface,
1843 IDirectDrawClipper *Clipper)
1845 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1847 TRACE("(%p)->(%p)\n",This,Clipper);
1848 if (ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper) == This->clipper)
1849 return DD_OK;
1851 if (This->clipper != NULL)
1852 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper, IDirectDrawClipper) );
1854 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper, Clipper);
1855 if (Clipper != NULL)
1856 IDirectDrawClipper_AddRef(Clipper);
1858 return DD_OK;
1861 /*****************************************************************************
1862 * IDirectDrawSurface7::SetSurfaceDesc
1864 * Sets the surface description. It can override the pixel format, the surface
1865 * memory, ...
1866 * It's not really tested.
1868 * Params:
1869 * DDSD: Pointer to the new surface description to set
1870 * Flags: Some flags
1872 * Returns:
1873 * DD_OK on success
1874 * DDERR_INVALIDPARAMS if DDSD is NULL
1876 *****************************************************************************/
1877 static HRESULT WINAPI
1878 IDirectDrawSurfaceImpl_SetSurfaceDesc(IDirectDrawSurface7 *iface,
1879 DDSURFACEDESC2 *DDSD,
1880 DWORD Flags)
1882 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1883 WINED3DFORMAT newFormat = WINED3DFMT_UNKNOWN;
1884 HRESULT hr;
1885 TRACE("(%p)->(%p,%lx)\n", This, DDSD, Flags);
1887 if(!DDSD)
1888 return DDERR_INVALIDPARAMS;
1890 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
1892 ERR("Setting the surface memory isn't supported yet\n");
1893 return DDERR_INVALIDPARAMS;
1896 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
1898 newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1900 if(newFormat == WINED3DFMT_UNKNOWN)
1902 ERR("Requested to set an unknown pixelformat\n");
1903 return DDERR_INVALIDPARAMS;
1905 if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
1907 hr = IWineD3DSurface_SetFormat(This->WineD3DSurface,
1908 newFormat);
1909 if(hr != DD_OK) return hr;
1912 if (DDSD->dwFlags & DDSD_CKDESTOVERLAY)
1914 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1915 DDCKEY_DESTOVERLAY,
1916 &DDSD->u3.ddckCKDestOverlay);
1918 if (DDSD->dwFlags & DDSD_CKDESTBLT)
1920 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1921 DDCKEY_DESTBLT,
1922 &DDSD->ddckCKDestBlt);
1924 if (DDSD->dwFlags & DDSD_CKSRCOVERLAY)
1926 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1927 DDCKEY_SRCOVERLAY,
1928 &DDSD->ddckCKSrcOverlay);
1930 if (DDSD->dwFlags & DDSD_CKSRCBLT)
1932 IWineD3DSurface_SetColorKey(This->WineD3DSurface,
1933 DDCKEY_SRCBLT,
1934 &DDSD->ddckCKSrcBlt);
1936 if (DDSD->dwFlags & DDSD_LPSURFACE)
1938 hr = IWineD3DSurface_SetMem(This->WineD3DSurface, DDSD->lpSurface);
1939 if(hr != WINED3D_OK)
1941 /* No need for a trace here, wined3d does that for us */
1942 return hr;
1946 This->surface_desc = *DDSD;
1948 return DD_OK;
1951 /*****************************************************************************
1952 * IDirectDrawSurface7::GetPalette
1954 * Returns the IDirectDrawPalette interface of the palette currently assigned
1955 * to the surface
1957 * Params:
1958 * Pal: Address to write the interface pointer to
1960 * Returns:
1961 * DD_OK on success
1962 * DDERR_INVALIDPARAMS if Pal is NULL
1964 *****************************************************************************/
1965 static HRESULT WINAPI
1966 IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
1967 IDirectDrawPalette **Pal)
1969 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
1970 IWineD3DPalette *wPal;
1971 HRESULT hr;
1972 TRACE("(%p)->(%p): Relay\n", This, Pal);
1974 if(!Pal)
1975 return DDERR_INVALIDPARAMS;
1977 hr = IWineD3DSurface_GetPalette(This->WineD3DSurface, &wPal);
1978 if(hr != DD_OK) return hr;
1980 if(wPal)
1982 hr = IWineD3DPalette_GetParent(wPal, (IUnknown **) Pal);
1984 else
1986 *Pal = NULL;
1987 hr = DDERR_NOPALETTEATTACHED;
1990 return hr;
1993 /*****************************************************************************
1994 * IDirectDrawSurface7::SetColorKey
1996 * Sets the color keying options for the surface. Observations showed that
1997 * in case of complex surfaces the color key has to be assigned to all
1998 * sublevels.
2000 * Params:
2001 * Flags: DDCKEY_*
2002 * CKey: The new color key
2004 * Returns:
2005 * DD_OK on success
2006 * See IWineD3DSurface::SetColorKey for details
2008 *****************************************************************************/
2009 static HRESULT WINAPI
2010 IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
2011 DWORD Flags,
2012 DDCOLORKEY *CKey)
2014 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2015 IDirectDrawSurfaceImpl *surf;
2016 HRESULT hr;
2017 TRACE("(%p)->(%lx,%p)\n", This, Flags, CKey);
2019 for(surf = This->first_complex; surf; surf = surf->next_complex)
2021 hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
2022 Flags,
2023 CKey);
2024 if(FAILED(hr))
2026 WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08lx\n",
2027 surf->WineD3DSurface, hr);
2028 return hr;
2031 return DD_OK;
2034 /*****************************************************************************
2035 * IDirectDrawSurface7::SetPalette
2037 * Assigns a DirectDrawPalette object to the surface
2039 * Params:
2040 * Pal: Interface to the palette to set
2042 * Returns:
2043 * DD_OK on success
2045 *****************************************************************************/
2046 static HRESULT WINAPI
2047 IDirectDrawSurfaceImpl_SetPalette(IDirectDrawSurface7 *iface,
2048 IDirectDrawPalette *Pal)
2050 ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
2051 IDirectDrawPalette *oldPal;
2052 IDirectDrawSurfaceImpl *surf;
2053 IDirectDrawPaletteImpl *PalImpl = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette, Pal);
2054 HRESULT hr;
2055 TRACE("(%p)->(%p)\n", This, Pal);
2057 /* Find the old palette */
2058 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
2059 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED) return hr;
2060 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
2062 /* Set the new Palette */
2063 IWineD3DSurface_SetPalette(This->WineD3DSurface,
2064 PalImpl ? PalImpl->wineD3DPalette : NULL);
2065 /* AddRef the Palette */
2066 if(Pal) IDirectDrawPalette_AddRef(Pal);
2068 /* Release the old palette */
2069 if(oldPal) IDirectDrawPalette_Release(oldPal);
2071 /* If this is a front buffer, also update the back buffers */
2072 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
2074 for(surf = This->next_complex; surf != NULL; surf = surf->next_complex)
2076 IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(surf, IDirectDrawSurface7),
2077 Pal);
2081 return DD_OK;
2084 /*****************************************************************************
2085 * The VTable
2086 *****************************************************************************/
2088 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl =
2090 /*** IUnknown ***/
2091 IDirectDrawSurfaceImpl_QueryInterface,
2092 IDirectDrawSurfaceImpl_AddRef,
2093 IDirectDrawSurfaceImpl_Release,
2094 /*** IDirectDrawSurface ***/
2095 IDirectDrawSurfaceImpl_AddAttachedSurface,
2096 IDirectDrawSurfaceImpl_AddOverlayDirtyRect,
2097 IDirectDrawSurfaceImpl_Blt,
2098 IDirectDrawSurfaceImpl_BltBatch,
2099 IDirectDrawSurfaceImpl_BltFast,
2100 IDirectDrawSurfaceImpl_DeleteAttachedSurface,
2101 IDirectDrawSurfaceImpl_EnumAttachedSurfaces,
2102 IDirectDrawSurfaceImpl_EnumOverlayZOrders,
2103 IDirectDrawSurfaceImpl_Flip,
2104 IDirectDrawSurfaceImpl_GetAttachedSurface,
2105 IDirectDrawSurfaceImpl_GetBltStatus,
2106 IDirectDrawSurfaceImpl_GetCaps,
2107 IDirectDrawSurfaceImpl_GetClipper,
2108 IDirectDrawSurfaceImpl_GetColorKey,
2109 IDirectDrawSurfaceImpl_GetDC,
2110 IDirectDrawSurfaceImpl_GetFlipStatus,
2111 IDirectDrawSurfaceImpl_GetOverlayPosition,
2112 IDirectDrawSurfaceImpl_GetPalette,
2113 IDirectDrawSurfaceImpl_GetPixelFormat,
2114 IDirectDrawSurfaceImpl_GetSurfaceDesc,
2115 IDirectDrawSurfaceImpl_Initialize,
2116 IDirectDrawSurfaceImpl_IsLost,
2117 IDirectDrawSurfaceImpl_Lock,
2118 IDirectDrawSurfaceImpl_ReleaseDC,
2119 IDirectDrawSurfaceImpl_Restore,
2120 IDirectDrawSurfaceImpl_SetClipper,
2121 IDirectDrawSurfaceImpl_SetColorKey,
2122 IDirectDrawSurfaceImpl_SetOverlayPosition,
2123 IDirectDrawSurfaceImpl_SetPalette,
2124 IDirectDrawSurfaceImpl_Unlock,
2125 IDirectDrawSurfaceImpl_UpdateOverlay,
2126 IDirectDrawSurfaceImpl_UpdateOverlayDisplay,
2127 IDirectDrawSurfaceImpl_UpdateOverlayZOrder,
2128 /*** IDirectDrawSurface2 ***/
2129 IDirectDrawSurfaceImpl_GetDDInterface,
2130 IDirectDrawSurfaceImpl_PageLock,
2131 IDirectDrawSurfaceImpl_PageUnlock,
2132 /*** IDirectDrawSurface3 ***/
2133 IDirectDrawSurfaceImpl_SetSurfaceDesc,
2134 /*** IDirectDrawSurface4 ***/
2135 IDirectDrawSurfaceImpl_SetPrivateData,
2136 IDirectDrawSurfaceImpl_GetPrivateData,
2137 IDirectDrawSurfaceImpl_FreePrivateData,
2138 IDirectDrawSurfaceImpl_GetUniquenessValue,
2139 IDirectDrawSurfaceImpl_ChangeUniquenessValue,
2140 /*** IDirectDrawSurface7 ***/
2141 IDirectDrawSurfaceImpl_SetPriority,
2142 IDirectDrawSurfaceImpl_GetPriority,
2143 IDirectDrawSurfaceImpl_SetLOD,
2144 IDirectDrawSurfaceImpl_GetLOD