wined3d/d3d9: Cleanup GetContainer for surfaces.

This commit is contained in:
H. Verbeet 2006-02-07 12:25:59 +01:00 committed by Alexandre Julliard
parent 78904aab2d
commit 2200f3e2ca
2 changed files with 42 additions and 43 deletions

View File

@ -114,47 +114,38 @@ D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
/* IDirect3DSurface9 Interface follow: */
HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
IWineD3DBase *wineD3DContainer = NULL;
IUnknown *wineD3DContainerParent = NULL;
HRESULT res;
IUnknown *IWineContainer = NULL;
TRACE("(%p) Relay\n", This);
/* The container returned from IWineD3DSurface_GetContainer is either an IWineD3DDevice,
one of the subclasses of IWineD3DBaseTexture or an IWineD3DSwapChain */
/* Get the IUnknown container. */
res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IUnknown, (void **)&IWineContainer);
if (res == D3D_OK && IWineContainer != NULL) {
/* Now find out what kind of container it is (so that we can get its parent)*/
IUnknown *IUnknownParent = NULL;
IUnknown *myContainer = NULL;
if(D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DDevice, (void **)&myContainer)){
IWineD3DDevice_GetParent((IWineD3DDevice *)IWineContainer, &IUnknownParent);
IUnknown_Release(myContainer);
} else
if(D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DBaseTexture, (void **)&myContainer)){
IWineD3DBaseTexture_GetParent((IWineD3DBaseTexture *)IWineContainer, &IUnknownParent);
IUnknown_Release(myContainer);
} else
if(D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DSwapChain, (void **)&myContainer)){
IWineD3DSwapChain_GetParent((IWineD3DSwapChain *)IWineContainer, &IUnknownParent);
IUnknown_Release(myContainer);
}else{
FIXME("Container is of unknown interface\n");
}
/* Tidy up.. */
IUnknown_Release((IWineD3DDevice *)IWineContainer);
/* Now, query the interface of the parent for the riid */
if(IUnknownParent != NULL){
res = IUnknown_QueryInterface(IUnknownParent, riid, ppContainer);
/* Tidy up.. */
IUnknown_Release(IUnknownParent);
}
TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
if (!ppContainer) {
ERR("Called without a valid ppContainer\n");
}
TRACE("(%p) : returning %p\n", This, *ppContainer);
/* Get the WineD3D container. */
res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IWineD3DBase, (void **)&wineD3DContainer);
if (res != D3D_OK) return res;
if (!wineD3DContainer) {
ERR("IWineD3DSurface_GetContainer should never return NULL\n");
}
/* Get the parent */
IWineD3DBase_GetParent(wineD3DContainer, &wineD3DContainerParent);
IUnknown_Release(wineD3DContainer);
if (!wineD3DContainerParent) {
ERR("IWineD3DBase_GetParent should never return NULL\n");
}
/* Now, query the interface of the parent for the riid */
res = IUnknown_QueryInterface(wineD3DContainerParent, riid, ppContainer);
IUnknown_Release(wineD3DContainerParent);
TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
return res;
}

View File

@ -175,19 +175,27 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **
HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
HRESULT hr;
if (ppContainer == NULL) {
ERR("Get container called witout a null ppContainer\n");
return E_NOINTERFACE;
IWineD3DBase *container = 0;
TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
if (!ppContainer) {
ERR("Called without a valid ppContainer.\n");
}
TRACE("(%p) : Relaying to queryInterface %p %p\n", This, ppContainer, *ppContainer);
/** From MSDN:
* If the surface is created using CreateImageSurface/CreateOffscreenPlainSurface, CreateRenderTarget,
* or CreateDepthStencilSurface, the surface is considered stand alone. In this case,
* GetContainer will return the Direct3D device used to create the surface.
*/
hr = IUnknown_QueryInterface(This->container, riid, ppContainer);
return hr;
if (This->container) {
container = This->container;
} else {
IWineD3DSurface_GetDevice(iface, (IWineD3DDevice **)&container);
}
TRACE("Relaying to QueryInterface\n");
return IUnknown_QueryInterface(container, riid, ppContainer);
}
HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc) {