From e43cfb1a688f529bc75f040987f48892bbd03cc8 Mon Sep 17 00:00:00 2001 From: "H. Verbeet" Date: Mon, 6 Feb 2006 11:30:48 +0100 Subject: [PATCH] wined3d: Fix SetContainer. Add/Release references to the container. Change the type of the container from IUnknown to IWineD3DBase. --- dlls/wined3d/device.c | 14 +++++++------- dlls/wined3d/surface.c | 13 ++++++++++++- dlls/wined3d/volume.c | 19 +++++++++++++++---- dlls/wined3d/wined3d_private.h | 4 ++-- include/wine/wined3d_interface.h | 4 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 775066ccbd3..ffd76176a2e 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -725,7 +725,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, UINT Wid /** Create and initialise the surface resource **/ D3DCREATERESOURCEOBJECTINSTANCE(object,Surface,D3DRTYPE_SURFACE, Size) - object->container = (IUnknown*) This; + IWineD3DSurface_SetContainer((IWineD3DSurface *)object, (IWineD3DBase *)This); object->currentDesc.Width = Width; object->currentDesc.Height = Height; @@ -888,7 +888,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, UINT Wid return hr; } - IWineD3DSurface_SetContainer(object->surfaces[i], (IUnknown *)object); + IWineD3DSurface_SetContainer(object->surfaces[i], (IWineD3DBase *)object); TRACE("Created surface level %d @ %p\n", i, object->surfaces[i]); /* calculate the next mipmap level */ tmpW = max(1, tmpW >> 1); @@ -958,7 +958,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *iface, (IWineD3DVolume **)&object->volumes[i], pSharedHandle); /* Set it's container to this object */ - IWineD3DVolume_SetContainer(object->volumes[i], (IUnknown *)object); + IWineD3DVolume_SetContainer(object->volumes[i], (IWineD3DBase *)object); /* calcualte the next mipmap level */ tmpW = max(1, tmpW >> 1); @@ -1076,7 +1076,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface, UINT *ppCubeTexture = NULL; return hr; } - IWineD3DSurface_SetContainer(object->surfaces[j][i], (IUnknown *)object); + IWineD3DSurface_SetContainer(object->surfaces[j][i], (IWineD3DBase *)object); TRACE("Created surface level %d @ %p,\n", i, object->surfaces[j][i]); } tmpW = max(1, tmpW >> 1); @@ -1402,7 +1402,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevice* ifac &object->frontBuffer, NULL /* pShared (always null)*/); if (object->frontBuffer != NULL) - IWineD3DSurface_SetContainer(object->frontBuffer, (IUnknown *)object); + IWineD3DSurface_SetContainer(object->frontBuffer, (IWineD3DBase *)object); TRACE("calling rendertarget CB\n"); hr = D3DCB_CreateRenderTarget((IUnknown *) This->parent, object->presentParms.BackBufferWidth, @@ -1414,7 +1414,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevice* ifac &object->backBuffer, NULL /* pShared (always null)*/); if (object->backBuffer != NULL) - IWineD3DSurface_SetContainer(object->backBuffer, (IUnknown *)object); + IWineD3DSurface_SetContainer(object->backBuffer, (IWineD3DBase *)object); /* Under directX swapchains share the depth stencil, so only create one depth-stencil */ if (pPresentationParameters->EnableAutoDepthStencil) { @@ -1430,7 +1430,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevice* ifac &This->depthStencilBuffer, NULL /* pShared (always null)*/ ); if (This->depthStencilBuffer != NULL) - IWineD3DSurface_SetContainer(This->depthStencilBuffer, (IUnknown *)iface); + IWineD3DSurface_SetContainer(This->depthStencilBuffer, (IWineD3DBase *)iface); } /** TODO: A check on width, height and multisample types diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 793f4e124dd..81079ae5c00 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -1334,10 +1334,21 @@ extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, C return D3D_OK; } -HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IUnknown *container) { +HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container) { IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface; + + TRACE("This %p, container %p\n", This, container); + + if (container) { + IWineD3DBase_AddRef(container); + } + if (This->container) { + IWineD3DBase_Release(This->container); + } + TRACE("Setting container to %p from %p\n", container, This->container); This->container = container; + return D3D_OK; } diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c index 1aec42d9334..826cef5e877 100644 --- a/dlls/wined3d/volume.c +++ b/dlls/wined3d/volume.c @@ -233,11 +233,22 @@ HRESULT WINAPI IWineD3DVolumeImpl_AddDirtyBox(IWineD3DVolume *iface, CONST D3DBO return D3D_OK; } -HRESULT WINAPI IWineD3DVolumeImpl_SetContainer(IWineD3DVolume *iface, IUnknown* container){ - IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface; +HRESULT WINAPI IWineD3DVolumeImpl_SetContainer(IWineD3DVolume *iface, IWineD3DBase* container) { + IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface; - This->container = container; - return D3D_OK; + TRACE("This %p, container %p\n", This, container); + + if (container) { + IWineD3DBase_AddRef(container); + } + if (This->container) { + IWineD3DBase_Release(This->container); + } + + TRACE("Setting container to %p from %p\n", container, This->container); + This->container = container; + + return D3D_OK; } HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, GLenum gl_level) { diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index fbc3f0bca40..9ba687c2d67 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -747,7 +747,7 @@ typedef struct IWineD3DVolumeImpl /* WineD3DVolume Information */ D3DVOLUME_DESC currentDesc; - IUnknown *container; + IWineD3DBase *container; UINT bytesPerPixel; BOOL lockable; @@ -799,7 +799,7 @@ struct IWineD3DSurfaceImpl IWineD3DResourceClass resource; /* IWineD3DSurface fields */ - IUnknown *container; + IWineD3DBase *container; WINED3DSURFACET_DESC currentDesc; UINT textureName; diff --git a/include/wine/wined3d_interface.h b/include/wine/wined3d_interface.h index c0a0e2d6b8e..dac1d3ae020 100644 --- a/include/wine/wined3d_interface.h +++ b/include/wine/wined3d_interface.h @@ -1054,7 +1054,7 @@ DECLARE_INTERFACE_(IWineD3DSurface,IWineD3DResource) STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pRect) PURE; STDMETHOD(LoadTexture)(THIS) PURE; STDMETHOD(SaveSnapshot)(THIS_ const char *filename) PURE; - STDMETHOD(SetContainer)(THIS_ IUnknown *container) PURE; + STDMETHOD(SetContainer)(THIS_ IWineD3DBase *container) PURE; STDMETHOD(SetPBufferState)(THIS_ BOOL inPBuffer, BOOL inTexture) PURE; STDMETHOD_(void,SetGlTextureDesc)(THIS_ UINT textureName, int target) PURE; STDMETHOD_(void,GetGlDesc)(THIS_ glDescriptor **glDescription) PURE; @@ -1128,7 +1128,7 @@ DECLARE_INTERFACE_(IWineD3DVolume,IWineD3DResource) STDMETHOD(AddDirtyBox)(THIS_ CONST D3DBOX* pDirtyBox) PURE; STDMETHOD(CleanDirtyBox)(THIS) PURE; STDMETHOD(LoadTexture)(THIS_ UINT gl_level) PURE; - STDMETHOD(SetContainer)(THIS_ IUnknown *container) PURE; + STDMETHOD(SetContainer)(THIS_ IWineD3DBase *container) PURE; }; #undef INTERFACE