Stefan Dösinger : ddraw: Use EnumAttachedSurfaces for SetColorKey.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Apr 27 06:43:56 CDT 2007


Module: wine
Branch: master
Commit: 88af9702f161849702d8f138f9e14e63f951bf64
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=88af9702f161849702d8f138f9e14e63f951bf64

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Sun Apr 22 21:15:30 2007 +0200

ddraw: Use EnumAttachedSurfaces for SetColorKey.

---

 dlls/ddraw/surface.c |   66 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index e374f98..4d62362 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -2073,6 +2073,45 @@ IDirectDrawSurfaceImpl_GetPalette(IDirectDrawSurface7 *iface,
 }
 
 /*****************************************************************************
+ * SetColorKeyEnum
+ *
+ * EnumAttachedSurface callback for SetColorKey. Used to set color keys
+ * recursively in the surface tree
+ *
+ *****************************************************************************/
+struct SCKContext
+{
+    HRESULT ret;
+    WINEDDCOLORKEY *CKey;
+    DWORD Flags;
+};
+
+static HRESULT WINAPI
+SetColorKeyEnum(IDirectDrawSurface7 *surface,
+                DDSURFACEDESC2 *desc,
+                void *context)
+{
+    ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, surface);
+    struct SCKContext *ctx = context;
+    HRESULT hr;
+
+    hr = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
+                                     ctx->Flags,
+                                     ctx->CKey);
+    if(hr != DD_OK)
+    {
+        WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
+        ctx->ret = hr;
+    }
+
+    IDirectDrawSurface7_EnumAttachedSurfaces(surface,
+                                             context,
+                                             SetColorKeyEnum);
+    IDirectDrawSurface7_Release(surface);
+    return DDENUMRET_OK;
+}
+
+/*****************************************************************************
  * IDirectDrawSurface7::SetColorKey
  *
  * Sets the color keying options for the surface. Observations showed that
@@ -2094,8 +2133,7 @@ IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
                                    DDCOLORKEY *CKey)
 {
     ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirectDrawSurface7, iface);
-    IDirectDrawSurfaceImpl *surf;
-    HRESULT hr;
+    struct SCKContext ctx = { DD_OK, (WINEDDCOLORKEY *) CKey, Flags };
     TRACE("(%p)->(%x,%p)\n", This, Flags, CKey);
 
     if (CKey)
@@ -2150,23 +2188,17 @@ IDirectDrawSurfaceImpl_SetColorKey(IDirectDrawSurface7 *iface,
             return DDERR_INVALIDPARAMS;
         }
     }
-    for(surf = This->first_complex; surf; surf = surf->next_complex)
+    ctx.ret = IWineD3DSurface_SetColorKey(This->WineD3DSurface,
+                                          Flags,
+                                          ctx.CKey);
+    IDirectDrawSurface7_EnumAttachedSurfaces(iface,
+                                             (void *) &ctx,
+                                             SetColorKeyEnum);
+    switch(ctx.ret)
     {
-        hr = IWineD3DSurface_SetColorKey(surf->WineD3DSurface,
-                                         Flags,
-                                         (WINEDDCOLORKEY *) CKey);
-        if(FAILED(hr))
-        {
-            WARN("IWineD3DSurface::SetColorKey for surface %p failed with hr=%08x\n",
-                 surf->WineD3DSurface, hr);
-            switch(hr)
-            {
-                case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
-                default:                            return hr;
-            }
-        }
+        case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
+        default:                            return ctx.ret;
     }
-    return DD_OK;
 }
 
 /*****************************************************************************




More information about the wine-cvs mailing list