Ričardas Barkauskas : ddraw: Separate IDirectDrawSurface3 reference count.

Alexandre Julliard julliard at winehq.org
Tue Jun 21 12:25:42 CDT 2011


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

Author: Ričardas Barkauskas <rbarkauskas at codeweavers.com>
Date:   Mon Jun 20 23:51:01 2011 +0300

ddraw: Separate IDirectDrawSurface3 reference count.

---

 dlls/ddraw/ddraw_private.h  |    2 +-
 dlls/ddraw/main.c           |    7 +++++--
 dlls/ddraw/surface.c        |   29 +++++++++++++++++++++++------
 dlls/ddraw/tests/dsurface.c |    4 ++--
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 5d74715..e15219d 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -161,7 +161,7 @@ struct IDirectDrawSurfaceImpl
     const IDirect3DTexture2Vtbl *IDirect3DTexture2_vtbl;
     const IDirect3DTextureVtbl *IDirect3DTexture_vtbl;
 
-    LONG                     ref, ref2, iface_count;
+    LONG                     ref, ref3, ref2, iface_count;
     IUnknown                *ifaceToRelease;
 
     int                     version;
diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index 863c5b0..36c0ef7 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -752,12 +752,14 @@ DestroyCallback(IDirectDrawSurface7 *surf,
                 void *context)
 {
     IDirectDrawSurfaceImpl *Impl = impl_from_IDirectDrawSurface7(surf);
-    ULONG ref, ref2;
+    ULONG ref, ref3, ref2;
 
     ref = IDirectDrawSurface7_Release(surf);  /* For the EnumSurfaces */
+    IDirectDrawSurface3_AddRef(&Impl->IDirectDrawSurface3_iface);
+    ref3 = IDirectDrawSurface3_Release(&Impl->IDirectDrawSurface3_iface);
     IDirectDrawSurface2_AddRef(&Impl->IDirectDrawSurface2_iface);
     ref2 = IDirectDrawSurface2_Release(&Impl->IDirectDrawSurface2_iface);
-    WARN("Surface %p has an reference counts of %d 2: %d\n", Impl, ref, ref2);
+    WARN("Surface %p has an reference counts of %d 3: %d 2: %d\n", Impl, ref, ref3, ref2);
 
     /* Skip surfaces which are attached somewhere or which are
      * part of a complex compound. They will get released when destroying
@@ -768,6 +770,7 @@ DestroyCallback(IDirectDrawSurface7 *surf,
 
     /* Destroy the surface */
     while (ref) ref = IDirectDrawSurface7_Release(surf);
+    while (ref3) ref3 = IDirectDrawSurface3_Release(&Impl->IDirectDrawSurface3_iface);
     while (ref2) ref2 = IDirectDrawSurface2_Release(&Impl->IDirectDrawSurface2_iface);
 
     return DDENUMRET_OK;
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 6204703..412bc29 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -90,7 +90,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface,
     }
     else if (IsEqualGUID(riid, &IID_IDirectDrawSurface3))
     {
-        IUnknown_AddRef(iface);
+        IDirectDrawSurface3_AddRef(&This->IDirectDrawSurface3_iface);
         *obj = &This->IDirectDrawSurface3_iface;
         TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
         return S_OK;
@@ -266,9 +266,16 @@ static ULONG WINAPI ddraw_surface4_AddRef(IDirectDrawSurface4 *iface)
 static ULONG WINAPI ddraw_surface3_AddRef(IDirectDrawSurface3 *iface)
 {
     IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface);
-    TRACE("iface %p.\n", iface);
+    ULONG refcount = InterlockedIncrement(&This->ref3);
 
-    return ddraw_surface7_AddRef(&This->IDirectDrawSurface7_iface);
+    TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
+
+    if (refcount == 1)
+    {
+        ddraw_surface_add_iface(This);
+    }
+
+    return refcount;
 }
 
 static ULONG WINAPI ddraw_surface2_AddRef(IDirectDrawSurface2 *iface)
@@ -342,7 +349,8 @@ void ddraw_surface_destroy(IDirectDrawSurfaceImpl *This)
          * because the 2nd surface was addref()ed when the app
          * called GetAttachedSurface
          */
-        WARN("(%p): Destroying surface with refcounts %d 2: %d\n", This, This->ref, This->ref2);
+        WARN("(%p): Destroying surface with refcounts %d 3: %d 2: %d\n", This, This->ref,
+			This->ref3, This->ref2);
     }
 
     if (This->wined3d_surface)
@@ -521,9 +529,16 @@ static ULONG WINAPI ddraw_surface4_Release(IDirectDrawSurface4 *iface)
 static ULONG WINAPI ddraw_surface3_Release(IDirectDrawSurface3 *iface)
 {
     IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface);
-    TRACE("iface %p.\n", iface);
+    ULONG refcount = InterlockedDecrement(&This->ref3);
 
-    return ddraw_surface7_Release(&This->IDirectDrawSurface7_iface);
+    TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
+
+    if (refcount == 0)
+    {
+        ddraw_surface_release_iface(This);
+    }
+
+    return refcount;
 }
 
 static ULONG WINAPI ddraw_surface2_Release(IDirectDrawSurface2 *iface)
@@ -740,6 +755,8 @@ static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *ifa
     }
     attachment_impl = impl_from_IDirectDrawSurface7(attachment7);
     *attachment = &attachment_impl->IDirectDrawSurface3_iface;
+    ddraw_surface3_AddRef(*attachment);
+    ddraw_surface7_Release(attachment7);
 
     return hr;
 }
diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index 99058ab..4cfe469 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -1092,7 +1092,7 @@ static void IFaceRefCount(void)
 
     IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface3, (void **) &surf3);
     ref = getRefcount((IUnknown *) surf3);
-    todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
+    ok(ref == 1, "Refcount is %u, expected 1\n", ref);
 
     IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface4, (void **) &surf4);
     ref = getRefcount((IUnknown *) surf4);
@@ -1148,7 +1148,7 @@ static void IFaceRefCount(void)
     ok(ref == 0, "Refcount is %u, expected 0\n", ref);
 
     ref = IDirectDrawSurface3_Release(surf3);
-    todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);
+    ok(ref == 0, "Refcount is %u, expected 0\n", ref);
 
     ref = IDirectDrawSurface4_Release(surf4);
     todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);




More information about the wine-cvs mailing list