From ff8fd8eb98b86e71e30eb9b63e60f7beaefd1a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ri=C4=8Dardas=20Barkauskas?= Date: Tue, 28 Jun 2011 02:53:17 +0300 Subject: ddraw: Separate IDirectDrawGammaControl reference count. --- dlls/ddraw/ddraw_private.h | 2 +- dlls/ddraw/surface.c | 22 +++++++++++++++++----- dlls/ddraw/tests/dsurface.c | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index fe736b2..c73743a 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 ref7, ref4, ref3, ref2, ref1, iface_count; + LONG ref7, ref4, ref3, ref2, ref1, iface_count, gamma_count; IUnknown *ifaceToRelease; int version; diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index b027940..ffda68c 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -111,7 +111,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, } else if( IsEqualGUID(riid, &IID_IDirectDrawGammaControl) ) { - IUnknown_AddRef(iface); + IDirectDrawGammaControl_AddRef(&This->IDirectDrawGammaControl_iface); *obj = &This->IDirectDrawGammaControl_iface; TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj); return S_OK; @@ -318,10 +318,16 @@ static ULONG WINAPI ddraw_surface1_AddRef(IDirectDrawSurface *iface) static ULONG WINAPI ddraw_gamma_control_AddRef(IDirectDrawGammaControl *iface) { IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawGammaControl(iface); + ULONG refcount = InterlockedIncrement(&This->gamma_count); - TRACE("iface %p.\n", iface); + TRACE("iface %p increasing refcount to %u.\n", iface, refcount); + + if (refcount == 1) + { + ddraw_surface_add_iface(This); + } - return ddraw_surface7_AddRef(&This->IDirectDrawSurface7_iface); + return refcount; } static ULONG WINAPI d3d_texture2_AddRef(IDirect3DTexture2 *iface) @@ -595,10 +601,16 @@ static ULONG WINAPI ddraw_surface1_Release(IDirectDrawSurface *iface) static ULONG WINAPI ddraw_gamma_control_Release(IDirectDrawGammaControl *iface) { IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawGammaControl(iface); + ULONG refcount = InterlockedDecrement(&This->gamma_count); - TRACE("iface %p.\n", iface); + TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); + + if (refcount == 0) + { + ddraw_surface_release_iface(This); + } - return ddraw_surface7_Release(&This->IDirectDrawSurface7_iface); + return refcount; } static ULONG WINAPI d3d_texture2_Release(IDirect3DTexture2 *iface) diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c index 0c9cd16..b1a2940 100644 --- a/dlls/ddraw/tests/dsurface.c +++ b/dlls/ddraw/tests/dsurface.c @@ -1125,7 +1125,7 @@ static void IFaceRefCount(void) IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawGammaControl, (void **) &gamma); ref = getRefcount((IUnknown *) gamma); - todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref); + ok(ref == 1, "Refcount is %u, expected 1\n", ref); ref = IDirect3DTexture2_Release(tex2); /* Release the texture */ ok(ref == 2, "Refcount is %u, expected 2\n", ref); @@ -1138,7 +1138,7 @@ static void IFaceRefCount(void) ok(ref == 1, "Refcount is %u, expected 1\n", ref); ref = IDirectDrawGammaControl_Release(gamma); /* Release the gamma control */ - todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref); + ok(ref == 0, "Refcount is %u, expected 0\n", ref); } ref = IDirectDrawSurface2_Release(surf2); /* Release one of the 2 surf2 interfaces */ -- 1.7.5.4