H. Verbeet : wined3d/d3d9: Cleanup GetContainer for surfaces.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Feb 7 06:05:29 CST 2006
Module: wine
Branch: refs/heads/master
Commit: 2200f3e2ca1b336b1512e68dcda3d919b90af583
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=2200f3e2ca1b336b1512e68dcda3d919b90af583
Author: H. Verbeet <hverbeet at gmail.com>
Date: Tue Feb 7 12:25:59 2006 +0100
wined3d/d3d9: Cleanup GetContainer for surfaces.
---
dlls/d3d9/surface.c | 63 +++++++++++++++++++++---------------------------
dlls/wined3d/surface.c | 22 +++++++++++------
2 files changed, 42 insertions(+), 43 deletions(-)
diff --git a/dlls/d3d9/surface.c b/dlls/d3d9/surface.c
index 6ea2d01..62c99c7 100644
--- a/dlls/d3d9/surface.c
+++ b/dlls/d3d9/surface.c
@@ -114,47 +114,38 @@ D3DRESOURCETYPE WINAPI IDirect3DSurface9
/* 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);
+ TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
- /* 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);
- }
-
+ 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;
}
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 0c928a5..722816a 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -175,19 +175,27 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetPa
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) {
More information about the wine-cvs
mailing list