From 72fb7acf8dfd1514387198811c07951dd8a9d90a Mon Sep 17 00:00:00 2001 From: Raphael Junqueira Date: Tue, 14 Jan 2003 23:05:39 +0000 Subject: [PATCH] Beginning of more COM compliant behavior: - AddRef/Release where needed - use IUnknown* instead void* - fix many GetDevice using AddRef - fix IDirect3DSurface8Impl_GetContainer using QueryInterface --- dlls/d3d8/basetexture.c | 5 +++++ dlls/d3d8/cubetexture.c | 5 +++++ dlls/d3d8/d3d8_private.h | 2 +- dlls/d3d8/device.c | 27 +++++++++++++++++---------- dlls/d3d8/directx.c | 2 ++ dlls/d3d8/resource.c | 2 +- dlls/d3d8/surface.c | 34 ++++++++++++++++++++++------------ dlls/d3d8/texture.c | 7 ++++++- dlls/d3d8/volumetexture.c | 5 +++++ 9 files changed, 64 insertions(+), 25 deletions(-) diff --git a/dlls/d3d8/basetexture.c b/dlls/d3d8/basetexture.c index 1cffddce447..4691f07da74 100644 --- a/dlls/d3d8/basetexture.c +++ b/dlls/d3d8/basetexture.c @@ -65,6 +65,11 @@ HRESULT WINAPI IDirect3DBaseTexture8Impl_GetDevice(LPDIRECT3DBASETEXTURE ICOM_THIS(IDirect3DBaseTexture8Impl,iface); TRACE("(%p) : returning %p\n", This, This->Device); *ppDevice = (LPDIRECT3DDEVICE8) This->Device; + /** + * Note Calling this method will increase the internal reference count + * on the IDirect3DDevice8 interface. + */ + IDirect3DDevice8Impl_AddRef(*ppDevice); return D3D_OK; } HRESULT WINAPI IDirect3DBaseTexture8Impl_SetPrivateData(LPDIRECT3DBASETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) { diff --git a/dlls/d3d8/cubetexture.c b/dlls/d3d8/cubetexture.c index 9f53403196d..e8f4199fc58 100644 --- a/dlls/d3d8/cubetexture.c +++ b/dlls/d3d8/cubetexture.c @@ -75,6 +75,11 @@ HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE ICOM_THIS(IDirect3DCubeTexture8Impl,iface); TRACE("(%p) : returning %p\n", This, This->Device); *ppDevice = (LPDIRECT3DDEVICE8) This->Device; + /** + * Note Calling this method will increase the internal reference count + * on the IDirect3DDevice8 interface. + */ + IDirect3DDevice8Impl_AddRef(*ppDevice); return D3D_OK; } HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) { diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index b40da796bfe..b70bc4d20b5 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -559,7 +559,7 @@ struct IDirect3DSurface8Impl IDirect3DDevice8Impl *Device; D3DRESOURCETYPE ResourceType; - void *Container; + IUnknown *Container; D3DSURFACE_DESC myDesc; BYTE *allocatedMemory; diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 559ca27e473..b6bd0d6f902 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -18,6 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" + #include #define NONAMELESSUNION @@ -1079,7 +1081,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UIN TRACE("(%p) : W(%d) H(%d), Lvl(%d) Usage(%ld), Fmt(%d), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl)); object->lpVtbl = &Direct3DTexture8_Vtbl; - object->Device = This; + object->Device = This; /* FIXME: AddRef(This) */ object->ResourceType = D3DRTYPE_TEXTURE; object->ref = 1; object->width = Width; @@ -1108,12 +1110,12 @@ HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UIN for (i=0; ilevels; i++) { IDirect3DDevice8Impl_CreateImageSurface(iface, tmpW, tmpH, Format, (LPDIRECT3DSURFACE8*) &object->surfaces[i]); - object->surfaces[i]->Container = object; + object->surfaces[i]->Container = (IUnknown*) object; /* FIXME: AddRef(object) */ object->surfaces[i]->myDesc.Usage = Usage; object->surfaces[i]->myDesc.Pool = Pool ; TRACE("Created surface level %d @ %p, memory at %p\n", i, object->surfaces[i], object->surfaces[i]->allocatedMemory); - tmpW = max(1,tmpW / 2); + tmpW = max(1, tmpW / 2); tmpH = max(1, tmpH / 2); } @@ -1175,7 +1177,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 ifac object->volumes[i] = (IDirect3DVolume8Impl *) volume; volume->lpVtbl = &Direct3DVolume8_Vtbl; - volume->Device = This; + volume->Device = This; /* FIXME: AddRef(This) */ volume->ResourceType = D3DRTYPE_VOLUME; volume->Container = object; volume->ref = 1; @@ -1214,7 +1216,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DCubeTexture8Impl)); object->lpVtbl = &Direct3DCubeTexture8_Vtbl; object->ref = 1; - object->Device = This; + object->Device = This; /* FIXME: AddRef(This) */ object->ResourceType = D3DRTYPE_CUBETEXTURE; object->edgeLength = EdgeLength; @@ -1241,7 +1243,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, /* Create the 6 faces */ for (j=0;j<6;j++) { IDirect3DDevice8Impl_CreateImageSurface(iface, tmpW, tmpW, Format, (LPDIRECT3DSURFACE8*) &object->surfaces[j][i]); - object->surfaces[j][i]->Container = object; + object->surfaces[j][i]->Container = (IUnknown*) object; object->surfaces[j][i]->myDesc.Usage = Usage; object->surfaces[j][i]->myDesc.Pool = Pool ; @@ -1326,7 +1328,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface object->lpVtbl = &Direct3DSurface8_Vtbl; object->Device = This; object->ResourceType = D3DRTYPE_SURFACE; - object->Container = This; + object->Container = (IUnknown*) This; object->ref = 1; object->myDesc.Width = Width; @@ -1346,7 +1348,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect IDirect3DSurface8* pDestinationSurface,CONST POINT* pDestPointsArray) { HRESULT rc = D3D_OK; - void *texture = NULL; + IDirect3DBaseTexture8* texture = NULL; IDirect3DSurface8Impl *src = (IDirect3DSurface8Impl*) pSourceSurface; @@ -1367,7 +1369,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect dst->myDesc.Format = src->myDesc.Format; /* Convert container as well */ - IDirect3DSurface8Impl_GetContainer((LPDIRECT3DSURFACE8) dst, NULL, &texture); /* FIXME: Which refid? */ + IDirect3DSurface8Impl_GetContainer((LPDIRECT3DSURFACE8) dst, &IID_IDirect3DBaseTexture8, (void**) &texture); /* FIXME: Which refid? */ if (texture != NULL) { switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) texture)) { @@ -1384,6 +1386,8 @@ HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect FIXME("Unhandled texture type\n"); } + /** Releasing texture after GetContainer */ + IDirect3DBaseTexture8_Release(texture); } } @@ -1428,7 +1432,7 @@ HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect /* Set dirty */ if (rc == D3D_OK) { - IDirect3DSurface8Impl_GetContainer((LPDIRECT3DSURFACE8) dst, NULL, &texture); /* FIXME: Which refid? */ + IDirect3DSurface8Impl_GetContainer((LPDIRECT3DSURFACE8) dst, &IID_IDirect3DBaseTexture8, (void**) &texture); /* FIXME: Which refid? */ if (texture != NULL) { switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) texture)) { @@ -1453,6 +1457,9 @@ HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect default: FIXME("Unhandled texture type\n"); } + + /** Releasing texture after GetContainer */ + IDirect3DBaseTexture8_Release(texture); } } diff --git a/dlls/d3d8/directx.c b/dlls/d3d8/directx.c index d9f7d057745..dfdc6d69256 100644 --- a/dlls/d3d8/directx.c +++ b/dlls/d3d8/directx.c @@ -409,6 +409,8 @@ HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface, object->lpVtbl = &Direct3DDevice8_Vtbl; object->ref = 1; object->direct3d8 = This; + /** The device AddRef the direct3d8 Interface else crash in propers clients codes */ + IDirect3D8_AddRef((LPDIRECT3D8) object->direct3d8); object->UpdateStateBlock = &object->StateBlock; /* Save the creation parameters */ diff --git a/dlls/d3d8/resource.c b/dlls/d3d8/resource.c index cb8a2fae74c..8828b116b56 100644 --- a/dlls/d3d8/resource.c +++ b/dlls/d3d8/resource.c @@ -34,7 +34,7 @@ HRESULT WINAPI IDirect3DResource8Impl_QueryInterface(LPDIRECT3DRESOURCE8 iface,R ICOM_THIS(IDirect3DResource8Impl,iface); if (IsEqualGUID(riid, &IID_IUnknown) - || IsEqualGUID(riid, &IID_IClassFactory)) { + || IsEqualGUID(riid, &IID_IDirect3DResource8)) { IDirect3DResource8Impl_AddRef(iface); *ppobj = This; return D3D_OK; diff --git a/dlls/d3d8/surface.c b/dlls/d3d8/surface.c index 49b81b16e33..32abdd920e5 100644 --- a/dlls/d3d8/surface.c +++ b/dlls/d3d8/surface.c @@ -66,18 +66,18 @@ HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect ICOM_THIS(IDirect3DSurface8Impl,iface); TRACE("(%p) : returning %p\n", This, This->Device); *ppDevice = (LPDIRECT3DDEVICE8) This->Device; - - /* Note Calling this method will increase the internal reference count - on the IDirect3DDevice8 interface. */ + /** + * Note Calling this method will increase the internal reference count + * on the IDirect3DDevice8 interface. + */ IDirect3DDevice8Impl_AddRef(*ppDevice); - return D3D_OK; } -HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) { +HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) { ICOM_THIS(IDirect3DSurface8Impl,iface); FIXME("(%p) : stub\n", This); return D3D_OK; } -HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid,void* pData,DWORD* pSizeOfData) { +HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) { ICOM_THIS(IDirect3DSurface8Impl,iface); FIXME("(%p) : stub\n", This); return D3D_OK; } @@ -85,15 +85,25 @@ HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, R ICOM_THIS(IDirect3DSurface8Impl,iface); FIXME("(%p) : stub\n", This); return D3D_OK; } -HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid,void** ppContainer) { +HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void** ppContainer) { ICOM_THIS(IDirect3DSurface8Impl,iface); - - /* If the surface is created using CreateImageSurface, CreateRenderTarget, - or CreateDepthStencilSurface, the surface is considered stand alone. In this case, - GetContainer will return the Direct3D device used to create the surface. */ + HRESULT res; + /* TRACE("(%p) : returning %p\n", This, This->Container); *ppContainer = This->Container; return D3D_OK; + */ + res = IUnknown_QueryInterface(This->Container, riid, ppContainer); + if (E_NOINTERFACE == res) { + /** + * If the surface is created using CreateImageSurface, CreateRenderTarget, + * or CreateDepthStencilSurface, the surface is considered stand alone. In this case, + * GetContainer will return the Direct3D device used to create the surface. + */ + res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice8, ppContainer); + } + TRACE("(%p) : returning %p\n", This, *ppContainer); + return res; } HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) { ICOM_THIS(IDirect3DSurface8Impl,iface); @@ -121,7 +131,7 @@ HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) { ICOM_THIS(IDirect3DSurface8Impl,iface); TRACE("(%p) : stub\n", This); if (This->Container) { - IDirect3DBaseTexture8 *cont = This->Container; + IDirect3DBaseTexture8 *cont = (IDirect3DBaseTexture8*) This->Container; /* Now setup the texture appropraitly */ int containerType = IDirect3DBaseTexture8Impl_GetType(cont); diff --git a/dlls/d3d8/texture.c b/dlls/d3d8/texture.c index 85619268f2b..0a44841a87f 100644 --- a/dlls/d3d8/texture.c +++ b/dlls/d3d8/texture.c @@ -74,7 +74,12 @@ ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) { HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8** ppDevice) { ICOM_THIS(IDirect3DTexture8Impl,iface); TRACE("(%p) : returning %p\n", This, This->Device); - *ppDevice = (LPDIRECT3DDEVICE8) This->Device; + *ppDevice = (LPDIRECT3DDEVICE8) This->Device; + /** + * Note Calling this method will increase the internal reference count + * on the IDirect3DDevice8 interface. + */ + IDirect3DDevice8Impl_AddRef(*ppDevice); return D3D_OK; } HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) { diff --git a/dlls/d3d8/volumetexture.c b/dlls/d3d8/volumetexture.c index d283381075f..613a9dd30d1 100644 --- a/dlls/d3d8/volumetexture.c +++ b/dlls/d3d8/volumetexture.c @@ -77,6 +77,11 @@ HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(LPDIRECT3DVOLUMETEX ICOM_THIS(IDirect3DVolumeTexture8Impl,iface); TRACE("(%p) : returning %p\n", This, This->Device); *ppDevice = (LPDIRECT3DDEVICE8) This->Device; + /** + * Note Calling this method will increase the internal reference count + * on the IDirect3DDevice8 interface. + */ + IDirect3DDevice8Impl_AddRef(*ppDevice); return D3D_OK; } HRESULT WINAPI IDirect3DVolumeTexture8Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {