[PATCH 1/5] d3d9: Introduce a resource structure.

Stefan Dösinger stefan at codeweavers.com
Mon Mar 24 06:17:14 CDT 2014


---
 dlls/d3d9/buffer.c       | 20 ++++++++++++--------
 dlls/d3d9/d3d9_main.c    |  9 +++++++++
 dlls/d3d9/d3d9_private.h | 18 +++++++++++++-----
 dlls/d3d9/device.c       |  2 +-
 dlls/d3d9/surface.c      | 10 ++++++----
 dlls/d3d9/texture.c      | 22 ++++++++++++----------
 dlls/d3d9/volume.c       | 10 ++++++----
 7 files changed, 59 insertions(+), 32 deletions(-)

diff --git a/dlls/d3d9/buffer.c b/dlls/d3d9/buffer.c
index d543b27..d0ad890 100644
--- a/dlls/d3d9/buffer.c
+++ b/dlls/d3d9/buffer.c
@@ -50,7 +50,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9 *i
 static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
 {
     struct d3d9_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer9(iface);
-    ULONG refcount = InterlockedIncrement(&buffer->refcount);
+    ULONG refcount = InterlockedIncrement(&buffer->resource.refcount);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
 
@@ -68,7 +68,7 @@ static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
 static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface)
 {
     struct d3d9_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer9(iface);
-    ULONG refcount = InterlockedDecrement(&buffer->refcount);
+    ULONG refcount = InterlockedDecrement(&buffer->resource.refcount);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
@@ -275,7 +275,9 @@ static const IDirect3DVertexBuffer9Vtbl d3d9_vertexbuffer_vtbl =
 
 static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
 {
-    HeapFree(GetProcessHeap(), 0, parent);
+    struct d3d9_vertexbuffer *buffer = parent;
+    d3d9_resource_cleanup(&buffer->resource);
+    HeapFree(GetProcessHeap(), 0, buffer);
 }
 
 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
@@ -289,8 +291,8 @@ HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *
     HRESULT hr;
 
     buffer->IDirect3DVertexBuffer9_iface.lpVtbl = &d3d9_vertexbuffer_vtbl;
-    buffer->refcount = 1;
     buffer->fvf = fvf;
+    d3d9_resource_init(&buffer->resource);
 
     wined3d_mutex_lock();
     hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
@@ -344,7 +346,7 @@ static HRESULT WINAPI d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9 *ifa
 static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface)
 {
     struct d3d9_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer9(iface);
-    ULONG refcount = InterlockedIncrement(&buffer->refcount);
+    ULONG refcount = InterlockedIncrement(&buffer->resource.refcount);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
 
@@ -362,7 +364,7 @@ static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface)
 static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface)
 {
     struct d3d9_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer9(iface);
-    ULONG refcount = InterlockedDecrement(&buffer->refcount);
+    ULONG refcount = InterlockedDecrement(&buffer->resource.refcount);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
@@ -567,7 +569,9 @@ static const IDirect3DIndexBuffer9Vtbl d3d9_indexbuffer_vtbl =
 
 static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
 {
-    HeapFree(GetProcessHeap(), 0, parent);
+    struct d3d9_indexbuffer *buffer = parent;
+    d3d9_resource_cleanup(&buffer->resource);
+    HeapFree(GetProcessHeap(), 0, buffer);
 }
 
 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
@@ -581,8 +585,8 @@ HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *de
     HRESULT hr;
 
     buffer->IDirect3DIndexBuffer9_iface.lpVtbl = &d3d9_indexbuffer_vtbl;
-    buffer->refcount = 1;
     buffer->format = wined3dformat_from_d3dformat(format);
+    d3d9_resource_init(&buffer->resource);
 
     wined3d_mutex_lock();
     hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
diff --git a/dlls/d3d9/d3d9_main.c b/dlls/d3d9/d3d9_main.c
index d8c5e23..c8dd901 100644
--- a/dlls/d3d9/d3d9_main.c
+++ b/dlls/d3d9/d3d9_main.c
@@ -162,3 +162,12 @@ void WINAPI D3DPERF_SetRegion(D3DCOLOR color, const WCHAR *name)
 {
     FIXME("color 0x%08x, name %s stub!\n", color, debugstr_w(name));
 }
+
+void d3d9_resource_cleanup(struct d3d9_resource *resource)
+{
+}
+
+void d3d9_resource_init(struct d3d9_resource *resource)
+{
+    resource->refcount = 1;
+}
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index 5172a78..40be940 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -166,10 +166,18 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine
         UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
         D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) DECLSPEC_HIDDEN;
 
+struct d3d9_resource
+{
+    LONG refcount;
+};
+
+void d3d9_resource_cleanup(struct d3d9_resource *resource) DECLSPEC_HIDDEN;
+void d3d9_resource_init(struct d3d9_resource *resource) DECLSPEC_HIDDEN;
+
 struct d3d9_volume
 {
     IDirect3DVolume9 IDirect3DVolume9_iface;
-    LONG refcount;
+    struct d3d9_resource resource;
     struct wined3d_volume *wined3d_volume;
     IUnknown *container;
     IUnknown *forwardReference;
@@ -192,7 +200,7 @@ HRESULT d3d9_swapchain_create(struct d3d9_device *device, struct wined3d_swapcha
 struct d3d9_surface
 {
     IDirect3DSurface9 IDirect3DSurface9_iface;
-    LONG refcount;
+    struct d3d9_resource resource;
     struct wined3d_surface *wined3d_surface;
     IDirect3DDevice9Ex *parent_device;
     IUnknown *container;
@@ -207,7 +215,7 @@ struct d3d9_surface *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface
 struct d3d9_vertexbuffer
 {
     IDirect3DVertexBuffer9 IDirect3DVertexBuffer9_iface;
-    LONG refcount;
+    struct d3d9_resource resource;
     struct wined3d_buffer *wined3d_buffer;
     IDirect3DDevice9Ex *parent_device;
     DWORD fvf;
@@ -220,7 +228,7 @@ struct d3d9_vertexbuffer *unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVerte
 struct d3d9_indexbuffer
 {
     IDirect3DIndexBuffer9 IDirect3DIndexBuffer9_iface;
-    LONG refcount;
+    struct d3d9_resource resource;
     struct wined3d_buffer *wined3d_buffer;
     IDirect3DDevice9Ex *parent_device;
     enum wined3d_format_id format;
@@ -233,7 +241,7 @@ struct d3d9_indexbuffer *unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBu
 struct d3d9_texture
 {
     IDirect3DBaseTexture9 IDirect3DBaseTexture9_iface;
-    LONG refcount;
+    struct d3d9_resource resource;
     struct wined3d_texture *wined3d_texture;
     IDirect3DDevice9Ex *parent_device;
 };
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 66bee95..263ac12 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -581,7 +581,7 @@ static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
         }
 
         surface = wined3d_resource_get_parent(resource);
-        if (surface->refcount)
+        if (surface->resource.refcount)
         {
             WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
             return D3DERR_INVALIDCALL;
diff --git a/dlls/d3d9/surface.c b/dlls/d3d9/surface.c
index 0c96d50..0595039 100644
--- a/dlls/d3d9/surface.c
+++ b/dlls/d3d9/surface.c
@@ -61,7 +61,7 @@ static ULONG WINAPI d3d9_surface_AddRef(IDirect3DSurface9 *iface)
         return IUnknown_AddRef(surface->forwardReference);
     }
 
-    refcount = InterlockedIncrement(&surface->refcount);
+    refcount = InterlockedIncrement(&surface->resource.refcount);
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
 
     if (refcount == 1)
@@ -89,7 +89,7 @@ static ULONG WINAPI d3d9_surface_Release(IDirect3DSurface9 *iface)
         return IUnknown_Release(surface->forwardReference);
     }
 
-    refcount = InterlockedDecrement(&surface->refcount);
+    refcount = InterlockedDecrement(&surface->resource.refcount);
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
     if (!refcount)
@@ -385,7 +385,9 @@ static const struct IDirect3DSurface9Vtbl d3d9_surface_vtbl =
 
 static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
 {
-    HeapFree(GetProcessHeap(), 0, parent);
+    struct d3d9_surface *surface = parent;
+    d3d9_resource_cleanup(&surface->resource);
+    HeapFree(GetProcessHeap(), 0, surface);
 }
 
 static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops =
@@ -399,7 +401,7 @@ void surface_init(struct d3d9_surface *surface, struct wined3d_surface *wined3d_
     struct wined3d_resource_desc desc;
 
     surface->IDirect3DSurface9_iface.lpVtbl = &d3d9_surface_vtbl;
-    surface->refcount = 1;
+    d3d9_resource_init(&surface->resource);
 
     wined3d_resource_get_desc(wined3d_surface_get_resource(wined3d_surface), &desc);
     switch (d3dformat_from_wined3dformat(desc.format))
diff --git a/dlls/d3d9/texture.c b/dlls/d3d9/texture.c
index b34fbc6..47ccb30 100644
--- a/dlls/d3d9/texture.c
+++ b/dlls/d3d9/texture.c
@@ -61,7 +61,7 @@ static HRESULT WINAPI d3d9_texture_2d_QueryInterface(IDirect3DTexture9 *iface, R
 static ULONG WINAPI d3d9_texture_2d_AddRef(IDirect3DTexture9 *iface)
 {
     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
-    ULONG ref = InterlockedIncrement(&texture->refcount);
+    ULONG ref = InterlockedIncrement(&texture->resource.refcount);
 
     TRACE("%p increasing refcount to %u.\n", iface, ref);
 
@@ -79,7 +79,7 @@ static ULONG WINAPI d3d9_texture_2d_AddRef(IDirect3DTexture9 *iface)
 static ULONG WINAPI d3d9_texture_2d_Release(IDirect3DTexture9 *iface)
 {
     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
-    ULONG ref = InterlockedDecrement(&texture->refcount);
+    ULONG ref = InterlockedDecrement(&texture->resource.refcount);
 
     TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
@@ -472,7 +472,7 @@ static HRESULT WINAPI d3d9_texture_cube_QueryInterface(IDirect3DCubeTexture9 *if
 static ULONG WINAPI d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 *iface)
 {
     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
-    ULONG ref = InterlockedIncrement(&texture->refcount);
+    ULONG ref = InterlockedIncrement(&texture->resource.refcount);
 
     TRACE("%p increasing refcount to %u.\n", iface, ref);
 
@@ -490,7 +490,7 @@ static ULONG WINAPI d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 *iface)
 static ULONG WINAPI d3d9_texture_cube_Release(IDirect3DCubeTexture9 *iface)
 {
     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
-    ULONG ref = InterlockedDecrement(&texture->refcount);
+    ULONG ref = InterlockedDecrement(&texture->resource.refcount);
 
     TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
@@ -911,7 +911,7 @@ static HRESULT WINAPI d3d9_texture_3d_QueryInterface(IDirect3DVolumeTexture9 *if
 static ULONG WINAPI d3d9_texture_3d_AddRef(IDirect3DVolumeTexture9 *iface)
 {
     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
-    ULONG ref = InterlockedIncrement(&texture->refcount);
+    ULONG ref = InterlockedIncrement(&texture->resource.refcount);
 
     TRACE("%p increasing refcount to %u.\n", iface, ref);
 
@@ -929,7 +929,7 @@ static ULONG WINAPI d3d9_texture_3d_AddRef(IDirect3DVolumeTexture9 *iface)
 static ULONG WINAPI d3d9_texture_3d_Release(IDirect3DVolumeTexture9 *iface)
 {
     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
-    ULONG ref = InterlockedDecrement(&texture->refcount);
+    ULONG ref = InterlockedDecrement(&texture->resource.refcount);
 
     TRACE("%p decreasing refcount to %u.\n", iface, ref);
 
@@ -1298,7 +1298,9 @@ struct d3d9_texture *unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture
 
 static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
 {
-    HeapFree(GetProcessHeap(), 0, parent);
+    struct d3d9_texture *texture = parent;
+    d3d9_resource_cleanup(&texture->resource);
+    HeapFree(GetProcessHeap(), 0, texture);
 }
 
 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
@@ -1314,7 +1316,7 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device,
     HRESULT hr;
 
     texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl;
-    texture->refcount = 1;
+    d3d9_resource_init(&texture->resource);
 
     desc.resource_type = WINED3D_RTYPE_TEXTURE;
     desc.format = wined3dformat_from_d3dformat(format);
@@ -1355,7 +1357,7 @@ HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *devic
     HRESULT hr;
 
     texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl;
-    texture->refcount = 1;
+    d3d9_resource_init(&texture->resource);
 
     desc.resource_type = WINED3D_RTYPE_CUBE_TEXTURE;
     desc.format = wined3dformat_from_d3dformat(format);
@@ -1395,7 +1397,7 @@ HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *dev
     HRESULT hr;
 
     texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl;
-    texture->refcount = 1;
+    d3d9_resource_init(&texture->resource);
 
     desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
     desc.format = wined3dformat_from_d3dformat(format);
diff --git a/dlls/d3d9/volume.c b/dlls/d3d9/volume.c
index ec4c2b3..a546c06 100644
--- a/dlls/d3d9/volume.c
+++ b/dlls/d3d9/volume.c
@@ -60,7 +60,7 @@ static ULONG WINAPI d3d9_volume_AddRef(IDirect3DVolume9 *iface)
         return IUnknown_AddRef(volume->forwardReference);
     }
 
-    refcount = InterlockedIncrement(&volume->refcount);
+    refcount = InterlockedIncrement(&volume->resource.refcount);
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
 
     if (refcount == 1)
@@ -86,7 +86,7 @@ static ULONG WINAPI d3d9_volume_Release(IDirect3DVolume9 *iface)
         return IUnknown_Release(volume->forwardReference);
     }
 
-    refcount = InterlockedDecrement(&volume->refcount);
+    refcount = InterlockedDecrement(&volume->resource.refcount);
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
     if (!refcount)
@@ -266,7 +266,9 @@ static const struct IDirect3DVolume9Vtbl d3d9_volume_vtbl =
 
 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
 {
-    HeapFree(GetProcessHeap(), 0, parent);
+    struct d3d9_volume *volume = parent;
+    d3d9_resource_cleanup(&volume->resource);
+    HeapFree(GetProcessHeap(), 0, volume);
 }
 
 static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
@@ -278,7 +280,7 @@ void volume_init(struct d3d9_volume *volume, struct wined3d_volume *wined3d_volu
         const struct wined3d_parent_ops **parent_ops)
 {
     volume->IDirect3DVolume9_iface.lpVtbl = &d3d9_volume_vtbl;
-    volume->refcount = 1;
+    d3d9_resource_init(&volume->resource);
     wined3d_volume_incref(wined3d_volume);
     volume->wined3d_volume = wined3d_volume;
 
-- 
1.8.3.2




More information about the wine-patches mailing list