From 4e29ade658188d7e6fc2df57437f9ec3d6dfb671 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 7 Dec 2009 11:08:38 +0100 Subject: [PATCH] dxgi: Add a separate function for surface initialization. --- dlls/dxgi/device.c | 19 +++++++------------ dlls/dxgi/dxgi_private.h | 4 ++-- dlls/dxgi/surface.c | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dlls/dxgi/device.c b/dlls/dxgi/device.c index 8562d67f782..7860d0cd60e 100644 --- a/dlls/dxgi/device.c +++ b/dlls/dxgi/device.c @@ -262,6 +262,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_device_create_surface(IWineDXGIDevice *ifa DXGI_USAGE usage, const DXGI_SHARED_RESOURCE *shared_resource, IUnknown *outer, void **surface) { struct dxgi_surface *object; + HRESULT hr; FIXME("iface %p, desc %p, usage %#x, shared_resource %p, outer %p, surface %p partial stub!\n", iface, desc, usage, shared_resource, outer, surface); @@ -273,22 +274,16 @@ static HRESULT STDMETHODCALLTYPE dxgi_device_create_surface(IWineDXGIDevice *ifa return E_OUTOFMEMORY; } - object->vtbl = &dxgi_surface_vtbl; - object->inner_unknown_vtbl = &dxgi_surface_inner_unknown_vtbl; - object->refcount = 1; - - if (outer) + hr = dxgi_surface_init(object, outer); + if (FAILED(hr)) { - object->outer_unknown = outer; - *surface = &object->inner_unknown_vtbl; - } - else - { - object->outer_unknown = (IUnknown *)&object->inner_unknown_vtbl; - *surface = object; + WARN("Failed to initialize surface, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; } TRACE("Created IDXGISurface %p\n", object); + *surface = outer ? (void *)&object->inner_unknown_vtbl : object; return S_OK; } diff --git a/dlls/dxgi/dxgi_private.h b/dlls/dxgi/dxgi_private.h index 033168bbeb7..69c9f6c76a6 100644 --- a/dlls/dxgi/dxgi_private.h +++ b/dlls/dxgi/dxgi_private.h @@ -130,8 +130,6 @@ struct dxgi_swapchain }; /* IDXGISurface */ -extern const struct IDXGISurfaceVtbl dxgi_surface_vtbl DECLSPEC_HIDDEN; -extern const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl DECLSPEC_HIDDEN; struct dxgi_surface { const struct IDXGISurfaceVtbl *vtbl; @@ -140,4 +138,6 @@ struct dxgi_surface LONG refcount; }; +HRESULT dxgi_surface_init(struct dxgi_surface *surface, IUnknown *outer) DECLSPEC_HIDDEN; + #endif /* __WINE_DXGI_PRIVATE_H */ diff --git a/dlls/dxgi/surface.c b/dlls/dxgi/surface.c index bdbeaf333e2..1e5038bc14c 100644 --- a/dlls/dxgi/surface.c +++ b/dlls/dxgi/surface.c @@ -165,7 +165,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_surface_Unmap(IDXGISurface *iface) return E_NOTIMPL; } -const struct IDXGISurfaceVtbl dxgi_surface_vtbl = +static const struct IDXGISurfaceVtbl dxgi_surface_vtbl = { /* IUnknown methods */ dxgi_surface_QueryInterface, @@ -184,10 +184,20 @@ const struct IDXGISurfaceVtbl dxgi_surface_vtbl = dxgi_surface_Unmap, }; -const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl = +static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl = { /* IUnknown methods */ dxgi_surface_inner_QueryInterface, dxgi_surface_inner_AddRef, dxgi_surface_inner_Release, }; + +HRESULT dxgi_surface_init(struct dxgi_surface *surface, IUnknown *outer) +{ + surface->vtbl = &dxgi_surface_vtbl; + surface->inner_unknown_vtbl = &dxgi_surface_inner_unknown_vtbl; + surface->refcount = 1; + surface->outer_unknown = outer ? outer : (IUnknown *)&surface->inner_unknown_vtbl; + + return S_OK; +}