Commit 5f6d7021 authored by Ričardas Barkauskas's avatar Ričardas Barkauskas Committed by Alexandre Julliard

ddraw: Separate IDirectDrawSurface and IDirectDrawSurface7 reference counts.

parent 9190d349
...@@ -2074,6 +2074,8 @@ static HRESULT WINAPI ddraw3_GetGDISurface(IDirectDraw3 *iface, IDirectDrawSurfa ...@@ -2074,6 +2074,8 @@ static HRESULT WINAPI ddraw3_GetGDISurface(IDirectDraw3 *iface, IDirectDrawSurfa
} }
surface_impl = impl_from_IDirectDrawSurface7(surface7); surface_impl = impl_from_IDirectDrawSurface7(surface7);
*surface = &surface_impl->IDirectDrawSurface_iface; *surface = &surface_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*surface);
IDirectDrawSurface7_Release(surface7);
return hr; return hr;
} }
...@@ -2095,6 +2097,8 @@ static HRESULT WINAPI ddraw2_GetGDISurface(IDirectDraw2 *iface, IDirectDrawSurfa ...@@ -2095,6 +2097,8 @@ static HRESULT WINAPI ddraw2_GetGDISurface(IDirectDraw2 *iface, IDirectDrawSurfa
} }
surface_impl = impl_from_IDirectDrawSurface7(surface7); surface_impl = impl_from_IDirectDrawSurface7(surface7);
*surface = &surface_impl->IDirectDrawSurface_iface; *surface = &surface_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*surface);
IDirectDrawSurface7_Release(surface7);
return hr; return hr;
} }
...@@ -2116,6 +2120,8 @@ static HRESULT WINAPI ddraw1_GetGDISurface(IDirectDraw *iface, IDirectDrawSurfac ...@@ -2116,6 +2120,8 @@ static HRESULT WINAPI ddraw1_GetGDISurface(IDirectDraw *iface, IDirectDrawSurfac
} }
surface_impl = impl_from_IDirectDrawSurface7(surface7); surface_impl = impl_from_IDirectDrawSurface7(surface7);
*surface = &surface_impl->IDirectDrawSurface_iface; *surface = &surface_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*surface);
IDirectDrawSurface7_Release(surface7);
return hr; return hr;
} }
...@@ -2489,6 +2495,8 @@ static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc, ...@@ -2489,6 +2495,8 @@ static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc,
surface_impl = impl_from_IDirectDrawSurface7(surface7); surface_impl = impl_from_IDirectDrawSurface7(surface7);
/* Tests say this is true */ /* Tests say this is true */
*surface = (IDirectDrawSurface4 *)&surface_impl->IDirectDrawSurface_iface; *surface = (IDirectDrawSurface4 *)&surface_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(&surface_impl->IDirectDrawSurface_iface);
IDirectDrawSurface7_Release(surface7);
return hr; return hr;
} }
...@@ -2514,6 +2522,8 @@ static HRESULT WINAPI ddraw3_GetSurfaceFromDC(IDirectDraw3 *iface, HDC dc, ...@@ -2514,6 +2522,8 @@ static HRESULT WINAPI ddraw3_GetSurfaceFromDC(IDirectDraw3 *iface, HDC dc,
surface_impl = impl_from_IDirectDrawSurface7(surface7); surface_impl = impl_from_IDirectDrawSurface7(surface7);
*surface = &surface_impl->IDirectDrawSurface_iface; *surface = &surface_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*surface);
IDirectDrawSurface7_Release(surface7);
return hr; return hr;
} }
...@@ -3824,6 +3834,9 @@ static HRESULT CALLBACK EnumSurfacesCallbackThunk(IDirectDrawSurface7 *surface, ...@@ -3824,6 +3834,9 @@ static HRESULT CALLBACK EnumSurfacesCallbackThunk(IDirectDrawSurface7 *surface,
IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface); IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface);
struct surfacescallback_context *cbcontext = context; struct surfacescallback_context *cbcontext = context;
IDirectDrawSurface_AddRef(&surface_impl->IDirectDrawSurface_iface);
IDirectDrawSurface7_Release(surface);
return cbcontext->func(&surface_impl->IDirectDrawSurface_iface, return cbcontext->func(&surface_impl->IDirectDrawSurface_iface,
(DDSURFACEDESC *)surface_desc, cbcontext->context); (DDSURFACEDESC *)surface_desc, cbcontext->context);
} }
...@@ -4293,6 +4306,8 @@ static HRESULT WINAPI ddraw3_DuplicateSurface(IDirectDraw3 *iface, IDirectDrawSu ...@@ -4293,6 +4306,8 @@ static HRESULT WINAPI ddraw3_DuplicateSurface(IDirectDraw3 *iface, IDirectDrawSu
return hr; return hr;
dst_impl = impl_from_IDirectDrawSurface7(dst7); dst_impl = impl_from_IDirectDrawSurface7(dst7);
*dst = &dst_impl->IDirectDrawSurface_iface; *dst = &dst_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*dst);
IDirectDrawSurface7_Release(dst7);
return hr; return hr;
} }
...@@ -4313,6 +4328,8 @@ static HRESULT WINAPI ddraw2_DuplicateSurface(IDirectDraw2 *iface, ...@@ -4313,6 +4328,8 @@ static HRESULT WINAPI ddraw2_DuplicateSurface(IDirectDraw2 *iface,
return hr; return hr;
dst_impl = impl_from_IDirectDrawSurface7(dst7); dst_impl = impl_from_IDirectDrawSurface7(dst7);
*dst = &dst_impl->IDirectDrawSurface_iface; *dst = &dst_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*dst);
IDirectDrawSurface7_Release(dst7);
return hr; return hr;
} }
...@@ -4333,6 +4350,8 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur ...@@ -4333,6 +4350,8 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur
return hr; return hr;
dst_impl = impl_from_IDirectDrawSurface7(dst7); dst_impl = impl_from_IDirectDrawSurface7(dst7);
*dst = &dst_impl->IDirectDrawSurface_iface; *dst = &dst_impl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*dst);
IDirectDrawSurface7_Release(dst7);
return hr; return hr;
} }
......
...@@ -161,7 +161,7 @@ struct IDirectDrawSurfaceImpl ...@@ -161,7 +161,7 @@ struct IDirectDrawSurfaceImpl
const IDirect3DTexture2Vtbl *IDirect3DTexture2_vtbl; const IDirect3DTexture2Vtbl *IDirect3DTexture2_vtbl;
const IDirect3DTextureVtbl *IDirect3DTexture_vtbl; const IDirect3DTextureVtbl *IDirect3DTexture_vtbl;
LONG ref, ref4, ref3, ref2, iface_count; LONG ref7, ref4, ref3, ref2, ref1, iface_count;
IUnknown *ifaceToRelease; IUnknown *ifaceToRelease;
int version; int version;
......
...@@ -1992,6 +1992,8 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *if ...@@ -1992,6 +1992,8 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *if
if(hr != D3D_OK) return hr; if(hr != D3D_OK) return hr;
RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7); RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7);
*RenderTarget = &RenderTargetImpl->IDirectDrawSurface_iface; *RenderTarget = &RenderTargetImpl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*RenderTarget);
IDirectDrawSurface7_Release(RenderTarget7);
return D3D_OK; return D3D_OK;
} }
......
...@@ -752,17 +752,19 @@ DestroyCallback(IDirectDrawSurface7 *surf, ...@@ -752,17 +752,19 @@ DestroyCallback(IDirectDrawSurface7 *surf,
void *context) void *context)
{ {
IDirectDrawSurfaceImpl *Impl = impl_from_IDirectDrawSurface7(surf); IDirectDrawSurfaceImpl *Impl = impl_from_IDirectDrawSurface7(surf);
ULONG ref, ref4, ref3, ref2, iface_count; ULONG ref7, ref4, ref3, ref2, ref1, iface_count;
ref = IDirectDrawSurface7_Release(surf); /* For the EnumSurfaces */ ref7 = IDirectDrawSurface7_Release(surf); /* For the EnumSurfaces */
IDirectDrawSurface4_AddRef(&Impl->IDirectDrawSurface4_iface); IDirectDrawSurface4_AddRef(&Impl->IDirectDrawSurface4_iface);
ref4 = IDirectDrawSurface4_Release(&Impl->IDirectDrawSurface4_iface); ref4 = IDirectDrawSurface4_Release(&Impl->IDirectDrawSurface4_iface);
IDirectDrawSurface3_AddRef(&Impl->IDirectDrawSurface3_iface); IDirectDrawSurface3_AddRef(&Impl->IDirectDrawSurface3_iface);
ref3 = IDirectDrawSurface3_Release(&Impl->IDirectDrawSurface3_iface); ref3 = IDirectDrawSurface3_Release(&Impl->IDirectDrawSurface3_iface);
IDirectDrawSurface2_AddRef(&Impl->IDirectDrawSurface2_iface); IDirectDrawSurface2_AddRef(&Impl->IDirectDrawSurface2_iface);
ref2 = IDirectDrawSurface2_Release(&Impl->IDirectDrawSurface2_iface); ref2 = IDirectDrawSurface2_Release(&Impl->IDirectDrawSurface2_iface);
WARN("Surface %p has an reference counts of %u 4: %u 3: %u 2: %u\n", IDirectDrawSurface_AddRef(&Impl->IDirectDrawSurface_iface);
Impl, ref, ref4, ref3, ref2); ref1 = IDirectDrawSurface_Release(&Impl->IDirectDrawSurface_iface);
WARN("Surface %p has an reference counts of 7: %u 4: %u 3: %u 2: %u 1: %u\n",
Impl, ref7, ref4, ref3, ref2, ref1);
/* Skip surfaces which are attached somewhere or which are /* Skip surfaces which are attached somewhere or which are
* part of a complex compound. They will get released when destroying * part of a complex compound. They will get released when destroying
......
...@@ -76,7 +76,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, ...@@ -76,7 +76,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface,
if (IsEqualGUID(riid, &IID_IUnknown) if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IDirectDrawSurface7) ) || IsEqualGUID(riid, &IID_IDirectDrawSurface7) )
{ {
IUnknown_AddRef(iface); IDirectDrawSurface7_AddRef(iface);
*obj = iface; *obj = iface;
TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj); TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
return S_OK; return S_OK;
...@@ -104,7 +104,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, ...@@ -104,7 +104,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface,
} }
else if (IsEqualGUID(riid, &IID_IDirectDrawSurface)) else if (IsEqualGUID(riid, &IID_IDirectDrawSurface))
{ {
IUnknown_AddRef(iface); IDirectDrawSurface_AddRef(&This->IDirectDrawSurface_iface);
*obj = &This->IDirectDrawSurface_iface; *obj = &This->IDirectDrawSurface_iface;
TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This, *obj); TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This, *obj);
return S_OK; return S_OK;
...@@ -243,7 +243,7 @@ static void ddraw_surface_add_iface(IDirectDrawSurfaceImpl *This) ...@@ -243,7 +243,7 @@ static void ddraw_surface_add_iface(IDirectDrawSurfaceImpl *This)
static ULONG WINAPI ddraw_surface7_AddRef(IDirectDrawSurface7 *iface) static ULONG WINAPI ddraw_surface7_AddRef(IDirectDrawSurface7 *iface)
{ {
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface);
ULONG refcount = InterlockedIncrement(&This->ref); ULONG refcount = InterlockedIncrement(&This->ref7);
TRACE("iface %p increasing refcount to %u.\n", iface, refcount); TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
...@@ -303,9 +303,16 @@ static ULONG WINAPI ddraw_surface2_AddRef(IDirectDrawSurface2 *iface) ...@@ -303,9 +303,16 @@ static ULONG WINAPI ddraw_surface2_AddRef(IDirectDrawSurface2 *iface)
static ULONG WINAPI ddraw_surface1_AddRef(IDirectDrawSurface *iface) static ULONG WINAPI ddraw_surface1_AddRef(IDirectDrawSurface *iface)
{ {
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface);
TRACE("iface %p.\n", iface); ULONG refcount = InterlockedIncrement(&This->ref1);
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_gamma_control_AddRef(IDirectDrawGammaControl *iface) static ULONG WINAPI ddraw_gamma_control_AddRef(IDirectDrawGammaControl *iface)
...@@ -356,8 +363,8 @@ void ddraw_surface_destroy(IDirectDrawSurfaceImpl *This) ...@@ -356,8 +363,8 @@ void ddraw_surface_destroy(IDirectDrawSurfaceImpl *This)
* because the 2nd surface was addref()ed when the app * because the 2nd surface was addref()ed when the app
* called GetAttachedSurface * called GetAttachedSurface
*/ */
WARN("(%p): Destroying surface with refcounts %d 4: %d 3: %d 2: %d\n", WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n",
This, This->ref, This->ref4, This->ref3, This->ref2); This, This->ref7, This->ref4, This->ref3, This->ref2, This->ref1);
} }
if (This->wined3d_surface) if (This->wined3d_surface)
...@@ -513,7 +520,7 @@ ULONG ddraw_surface_release_iface(IDirectDrawSurfaceImpl *This) ...@@ -513,7 +520,7 @@ ULONG ddraw_surface_release_iface(IDirectDrawSurfaceImpl *This)
static ULONG WINAPI ddraw_surface7_Release(IDirectDrawSurface7 *iface) static ULONG WINAPI ddraw_surface7_Release(IDirectDrawSurface7 *iface)
{ {
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface); IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface7(iface);
ULONG refcount = InterlockedDecrement(&This->ref); ULONG refcount = InterlockedDecrement(&This->ref7);
TRACE("iface %p decreasing refcount to %u.\n", iface, refcount); TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
...@@ -573,9 +580,16 @@ static ULONG WINAPI ddraw_surface2_Release(IDirectDrawSurface2 *iface) ...@@ -573,9 +580,16 @@ static ULONG WINAPI ddraw_surface2_Release(IDirectDrawSurface2 *iface)
static ULONG WINAPI ddraw_surface1_Release(IDirectDrawSurface *iface) static ULONG WINAPI ddraw_surface1_Release(IDirectDrawSurface *iface)
{ {
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface); IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface);
TRACE("iface %p.\n", iface); ULONG refcount = InterlockedDecrement(&This->ref1);
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_gamma_control_Release(IDirectDrawGammaControl *iface) static ULONG WINAPI ddraw_gamma_control_Release(IDirectDrawGammaControl *iface)
...@@ -833,6 +847,8 @@ static HRESULT WINAPI ddraw_surface1_GetAttachedSurface(IDirectDrawSurface *ifac ...@@ -833,6 +847,8 @@ static HRESULT WINAPI ddraw_surface1_GetAttachedSurface(IDirectDrawSurface *ifac
} }
attachment_impl = impl_from_IDirectDrawSurface7(attachment7); attachment_impl = impl_from_IDirectDrawSurface7(attachment7);
*attachment = &attachment_impl->IDirectDrawSurface_iface; *attachment = &attachment_impl->IDirectDrawSurface_iface;
ddraw_surface1_AddRef(*attachment);
ddraw_surface7_Release(attachment7);
return hr; return hr;
} }
...@@ -2309,6 +2325,9 @@ static HRESULT CALLBACK EnumCallback(IDirectDrawSurface7 *surface, DDSURFACEDESC ...@@ -2309,6 +2325,9 @@ static HRESULT CALLBACK EnumCallback(IDirectDrawSurface7 *surface, DDSURFACEDESC
IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface); IDirectDrawSurfaceImpl *surface_impl = impl_from_IDirectDrawSurface7(surface);
const struct callback_info *info = context; const struct callback_info *info = context;
ddraw_surface1_AddRef(&surface_impl->IDirectDrawSurface_iface);
ddraw_surface7_Release(surface);
return info->callback(&surface_impl->IDirectDrawSurface_iface, return info->callback(&surface_impl->IDirectDrawSurface_iface,
(DDSURFACEDESC *)surface_desc, info->context); (DDSURFACEDESC *)surface_desc, info->context);
} }
...@@ -5166,13 +5185,17 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr ...@@ -5166,13 +5185,17 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr
surface->version = version; surface->version = version;
surface->ddraw = ddraw; surface->ddraw = ddraw;
if (version == 4) if (version == 7)
{
surface->ref7 = 1;
}
else if (version == 4)
{ {
surface->ref4 = 1; surface->ref4 = 1;
} }
else else
{ {
surface->ref = 1; surface->ref1 = 1;
} }
copy_to_surfacedesc2(&surface->surface_desc, desc); copy_to_surfacedesc2(&surface->surface_desc, desc);
......
...@@ -1100,11 +1100,11 @@ static void IFaceRefCount(void) ...@@ -1100,11 +1100,11 @@ static void IFaceRefCount(void)
IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7a); IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7a);
ref = getRefcount((IUnknown *) surf7a); ref = getRefcount((IUnknown *) surf7a);
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_IDirectDrawSurface7, (void **) &surf7b); IDirectDrawSurface_QueryInterface(surf, &IID_IDirectDrawSurface7, (void **) &surf7b);
ref = getRefcount((IUnknown *) surf7b); ref = getRefcount((IUnknown *) surf7b);
todo_wine ok(ref == 2, "Refcount is %u, expected 2\n", ref); ok(ref == 2, "Refcount is %u, expected 2\n", ref);
/* IDirect3DTexture interface (unlike the others) alters the original IDirectDrawSurface ref count */ /* IDirect3DTexture interface (unlike the others) alters the original IDirectDrawSurface ref count */
ret = IDirectDrawSurface_QueryInterface(surf, &IID_IDirect3DTexture, (void **) &tex); ret = IDirectDrawSurface_QueryInterface(surf, &IID_IDirect3DTexture, (void **) &tex);
...@@ -1135,7 +1135,7 @@ static void IFaceRefCount(void) ...@@ -1135,7 +1135,7 @@ static void IFaceRefCount(void)
ref = IDirect3DTexture_Release(tex); /* Release the texture */ ref = IDirect3DTexture_Release(tex); /* Release the texture */
todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref); todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref);
ref = getRefcount((IUnknown *) surf); ref = getRefcount((IUnknown *) surf);
todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref); ok(ref == 1, "Refcount is %u, expected 1\n", ref);
ref = IDirectDrawGammaControl_Release(gamma); /* Release the gamma control */ ref = IDirectDrawGammaControl_Release(gamma); /* Release the gamma control */
todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref); todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref);
...@@ -1154,10 +1154,10 @@ static void IFaceRefCount(void) ...@@ -1154,10 +1154,10 @@ static void IFaceRefCount(void)
ok(ref == 0, "Refcount is %u, expected 0\n", ref); ok(ref == 0, "Refcount is %u, expected 0\n", ref);
ref = IDirectDrawSurface7_Release(surf7a); ref = IDirectDrawSurface7_Release(surf7a);
todo_wine ok(ref == 1, "Refcount is %u, expected 1\n", ref); ok(ref == 1, "Refcount is %u, expected 1\n", ref);
ref = IDirectDrawSurface7_Release(surf7b); ref = IDirectDrawSurface7_Release(surf7b);
todo_wine ok(ref == 0, "Refcount is %u, expected 0\n", ref); ok(ref == 0, "Refcount is %u, expected 0\n", ref);
ref = IDirectDrawSurface_Release(surf); ref = IDirectDrawSurface_Release(surf);
ok(ref == 0, "Refcount is %u, expected 0\n", ref); ok(ref == 0, "Refcount is %u, expected 0\n", ref);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment