[PATCH 2/5] wined3d: Explicitly destroy the volume in texture3d_sub_resource_cleanup().

Henri Verbeet hverbeet at codeweavers.com
Tue Aug 19 02:22:26 CDT 2014


The texture always has the only reference to its subresources. This also means
we never have to set the container to NULL.
---
 dlls/wined3d/texture.c         |    4 +--
 dlls/wined3d/volume.c          |   62 ++++++++++++----------------------------
 dlls/wined3d/wined3d_private.h |    2 +-
 3 files changed, 20 insertions(+), 48 deletions(-)

diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 8beb9f8..423dec8 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1064,9 +1064,7 @@ static void texture3d_sub_resource_cleanup(struct wined3d_resource *sub_resource
 {
     struct wined3d_volume *volume = volume_from_resource(sub_resource);
 
-    /* Cleanup the container. */
-    volume_set_container(volume, NULL);
-    wined3d_volume_decref(volume);
+    wined3d_volume_destroy(volume);
 }
 
 static const struct wined3d_texture_ops texture3d_ops =
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 994cfc2..f1d09e5 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -27,13 +27,6 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
 
-void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container)
-{
-    TRACE("volume %p, container %p.\n", volume, container);
-
-    volume->container = container;
-}
-
 static BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
 {
     if (volume->resource.heap_memory)
@@ -461,6 +454,18 @@ static void wined3d_volume_free_pbo(struct wined3d_volume *volume)
     context_release(context);
 }
 
+void wined3d_volume_destroy(struct wined3d_volume *volume)
+{
+    TRACE("volume %p.\n", volume);
+
+    if (volume->pbo)
+        wined3d_volume_free_pbo(volume);
+
+    resource_cleanup(&volume->resource);
+    volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
+    HeapFree(GetProcessHeap(), 0, volume);
+}
+
 static void volume_unload(struct wined3d_resource *resource)
 {
     struct wined3d_volume *volume = volume_from_resource(resource);
@@ -504,46 +509,16 @@ static void volume_unload(struct wined3d_resource *resource)
 
 ULONG CDECL wined3d_volume_incref(struct wined3d_volume *volume)
 {
-    ULONG refcount;
-
-    if (volume->container)
-    {
-        TRACE("Forwarding to container %p.\n", volume->container);
-        return wined3d_texture_incref(volume->container);
-    }
-
-    refcount = InterlockedIncrement(&volume->resource.ref);
-
-    TRACE("%p increasing refcount to %u.\n", volume, refcount);
+    TRACE("Forwarding to container %p.\n", volume->container);
 
-    return refcount;
+    return wined3d_texture_incref(volume->container);
 }
 
 ULONG CDECL wined3d_volume_decref(struct wined3d_volume *volume)
 {
-    ULONG refcount;
-
-    if (volume->container)
-    {
-        TRACE("Forwarding to container %p.\n", volume->container);
-        return wined3d_texture_decref(volume->container);
-    }
+    TRACE("Forwarding to container %p.\n", volume->container);
 
-    refcount = InterlockedDecrement(&volume->resource.ref);
-
-    TRACE("%p decreasing refcount to %u.\n", volume, refcount);
-
-    if (!refcount)
-    {
-        if (volume->pbo)
-            wined3d_volume_free_pbo(volume);
-
-        resource_cleanup(&volume->resource);
-        volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
-        HeapFree(GetProcessHeap(), 0, volume);
-    }
-
-    return refcount;
+    return wined3d_texture_decref(volume->container);
 }
 
 void * CDECL wined3d_volume_get_parent(const struct wined3d_volume *volume)
@@ -846,7 +821,7 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_texture
         volume->flags |= WINED3D_VFLAG_PBO;
     }
 
-    volume_set_container(volume, container);
+    volume->container = container;
 
     return WINED3D_OK;
 }
@@ -879,8 +854,7 @@ HRESULT wined3d_volume_create(struct wined3d_texture *container, const struct wi
             wined3d_texture_get_parent(container), object, &parent, &parent_ops)))
     {
         WARN("Failed to create volume parent, hr %#x.\n", hr);
-        volume_set_container(object, NULL);
-        wined3d_volume_decref(object);
+        wined3d_volume_destroy(object);
         return hr;
     }
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 9341b2f..20594e1 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2188,9 +2188,9 @@ static inline struct wined3d_volume *volume_from_resource(struct wined3d_resourc
 
 HRESULT wined3d_volume_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
         unsigned int level, struct wined3d_volume **volume) DECLSPEC_HIDDEN;
+void wined3d_volume_destroy(struct wined3d_volume *volume) DECLSPEC_HIDDEN;
 void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context *context,
         BOOL srgb_mode) DECLSPEC_HIDDEN;
-void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container) DECLSPEC_HIDDEN;
 void wined3d_volume_invalidate_location(struct wined3d_volume *volume, DWORD location) DECLSPEC_HIDDEN;
 void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wined3d_context *context,
         const struct wined3d_bo_address *data) DECLSPEC_HIDDEN;
-- 
1.7.10.4




More information about the wine-patches mailing list