d3d11memory: Don't clear wrapped texture memory
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst-libs / gst / d3d11 / gstd3d11memory.cpp
index 869812b..a593701 100644 (file)
@@ -1473,6 +1473,7 @@ gst_d3d11_allocator_alloc_internal (GstD3D11Allocator * self,
   GstD3D11Memory *dmem;
   ID3D11RenderTargetView *rtv = nullptr;
   GstD3D11ClearRTVFunc clear_func = nullptr;
+  gboolean is_new_texture = TRUE;
 
   device_handle = gst_d3d11_device_get_device_handle (device);
 
@@ -1482,6 +1483,8 @@ gst_d3d11_allocator_alloc_internal (GstD3D11Allocator * self,
       GST_ERROR_OBJECT (self, "Couldn't create texture");
       return nullptr;
     }
+  } else {
+    is_new_texture = FALSE;
   }
 
   mem =
@@ -1489,6 +1492,10 @@ gst_d3d11_allocator_alloc_internal (GstD3D11Allocator * self,
   if (!mem)
     return nullptr;
 
+  /* Don't clear external texture */
+  if (!is_new_texture)
+    return mem;
+
   /* Clear with YUV black if needed and possible
    * TODO: do this using UAV if RTV is not allowed (e.g., packed YUV formats) */
   if ((desc->BindFlags & D3D11_BIND_RENDER_TARGET) == 0)
@@ -1755,7 +1762,6 @@ struct _GstD3D11PoolAllocatorPrivate
   gsize mem_size;
 };
 
-static void gst_d3d11_pool_allocator_dispose (GObject * object);
 static void gst_d3d11_pool_allocator_finalize (GObject * object);
 
 static gboolean
@@ -1776,7 +1782,6 @@ gst_d3d11_pool_allocator_class_init (GstD3D11PoolAllocatorClass * klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GstD3D11AllocatorClass *d3d11alloc_class = GST_D3D11_ALLOCATOR_CLASS (klass);
 
-  gobject_class->dispose = gst_d3d11_pool_allocator_dispose;
   gobject_class->finalize = gst_d3d11_pool_allocator_finalize;
 
   d3d11alloc_class->set_active = gst_d3d11_pool_allocator_set_active;
@@ -1805,16 +1810,6 @@ gst_d3d11_pool_allocator_init (GstD3D11PoolAllocator * allocator)
 }
 
 static void
-gst_d3d11_pool_allocator_dispose (GObject * object)
-{
-  GstD3D11PoolAllocator *self = GST_D3D11_POOL_ALLOCATOR (object);
-
-  gst_clear_object (&self->device);
-
-  G_OBJECT_CLASS (pool_alloc_parent_class)->dispose (object);
-}
-
-static void
 gst_d3d11_pool_allocator_finalize (GObject * object)
 {
   GstD3D11PoolAllocator *self = GST_D3D11_POOL_ALLOCATOR (object);
@@ -1829,6 +1824,8 @@ gst_d3d11_pool_allocator_finalize (GObject * object)
 
   GST_D3D11_CLEAR_COM (priv->texture);
 
+  gst_clear_object (&self->device);
+
   G_OBJECT_CLASS (pool_alloc_parent_class)->finalize (object);
 }
 
@@ -2058,12 +2055,13 @@ gst_d3d11_pool_allocator_release_memory (GstD3D11PoolAllocator * self,
 
   GST_MINI_OBJECT_CAST (mem)->dispose = NULL;
   mem->allocator = (GstAllocator *) gst_object_ref (_d3d11_memory_allocator);
-  gst_object_unref (self);
 
   /* keep it around in our queue */
   gst_atomic_queue_push (self->priv->queue, mem);
   gst_poll_write_control (self->priv->poll);
   dec_outstanding (self);
+
+  gst_object_unref (self);
 }
 
 static gboolean