Commit 72fb7acf authored by Raphael Junqueira's avatar Raphael Junqueira Committed by Alexandre Julliard

Beginning of more COM compliant behavior:

- AddRef/Release where needed - use IUnknown* instead void* - fix many GetDevice using AddRef - fix IDirect3DSurface8Impl_GetContainer using QueryInterface
parent 7472d72e
......@@ -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) {
......
......@@ -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) {
......
......@@ -559,7 +559,7 @@ struct IDirect3DSurface8Impl
IDirect3DDevice8Impl *Device;
D3DRESOURCETYPE ResourceType;
void *Container;
IUnknown *Container;
D3DSURFACE_DESC myDesc;
BYTE *allocatedMemory;
......
......@@ -18,6 +18,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <math.h>
#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; i<object->levels; 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);
}
}
......
......@@ -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 */
......
......@@ -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;
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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) {
......
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