d3d11memory: Add private method for texture wrapped memory allocation
authorSeungha Yang <seungha@centricular.com>
Fri, 1 Jul 2022 12:35:15 +0000 (21:35 +0900)
committerSeungha Yang <seungha@centricular.com>
Fri, 1 Jul 2022 20:37:55 +0000 (05:37 +0900)
Unlike public method gst_d3d11_allocator_alloc_wrapped(), newly
added method by this commit will not calculate CPU accessible memory
size, since staging texture must be allocated to calculate the size.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2697>

subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11_private.h
subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11memory.cpp

index 872b169..3aff9c8 100644 (file)
@@ -41,6 +41,16 @@ void  gst_d3d11_device_dxgi_debug  (GstD3D11Device * device,
                                     const gchar * function,
                                     gint line);
 
+/* Memory allocated by this method does not hold correct size.
+ * So this is private method and only plugins in -bad are expected to call
+ * this method */
+GST_D3D11_API
+GstMemory * gst_d3d11_allocator_alloc_wrapped_native_size (GstD3D11Allocator * allocator,
+                                                           GstD3D11Device * device,
+                                                           ID3D11Texture2D * texture,
+                                                           gpointer user_data,
+                                                           GDestroyNotify notify);
+
 #define GST_D3D11_CLEAR_COM(obj) G_STMT_START { \
     if (obj) { \
       (obj)->Release (); \
index 9e992f2..8a1ceb9 100644 (file)
@@ -1692,6 +1692,46 @@ gst_d3d11_allocator_alloc_wrapped (GstD3D11Allocator * allocator,
   return mem;
 }
 
+GstMemory *
+gst_d3d11_allocator_alloc_wrapped_native_size (GstD3D11Allocator * allocator,
+    GstD3D11Device * device, ID3D11Texture2D * texture, gpointer user_data,
+    GDestroyNotify notify)
+{
+  GstMemory *mem;
+  GstD3D11Memory *dmem;
+  D3D11_TEXTURE2D_DESC desc = { 0, };
+  ID3D11Texture2D *tex = nullptr;
+  HRESULT hr;
+  gsize size;
+
+  g_return_val_if_fail (GST_IS_D3D11_ALLOCATOR (allocator), nullptr);
+  g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), nullptr);
+  g_return_val_if_fail (texture != nullptr, nullptr);
+
+  hr = texture->QueryInterface (IID_PPV_ARGS (&tex));
+  if (FAILED (hr)) {
+    GST_WARNING_OBJECT (allocator, "Not a valid texture handle");
+    return nullptr;
+  }
+
+  tex->GetDesc (&desc);
+  mem = gst_d3d11_allocator_alloc_internal (allocator, device, &desc, tex);
+
+  if (!mem)
+    return nullptr;
+
+  /* XXX: This is not correct memory size */
+  size = desc.Width * desc.Height;
+  mem->maxsize = mem->size = size;
+
+  dmem = GST_D3D11_MEMORY_CAST (mem);
+
+  dmem->priv->user_data = user_data;
+  dmem->priv->notify = notify;
+
+  return mem;
+}
+
 /**
  * gst_d3d11_allocator_set_active:
  * @allocator: a #GstD3D11Allocator