memory: provide a mem_unmap function that takes the flags to unmap
authorMatthew Waters <matthew@centricular.com>
Wed, 3 Jun 2015 08:03:36 +0000 (18:03 +1000)
committerMatthew Waters <matthew@centricular.com>
Wed, 3 Jun 2015 10:41:59 +0000 (20:41 +1000)
There are gstmemory's available that operate in two memory domains
and need to ensure consistent access between these domains.

Imagine a scenario where e.g. the GLMemory is mapped twice in both
the GPU and the CPU domain.  On unmap or a subsequent map, it would
like to ensure that the most recent data is available in the memory
domain requested.  Either by flushing the writes and/or initiating a
DMA transfer.  Without knowing which domain is being unmapped, the
memory does not know where the most recent data is to transfer to
the other memory domain.

Note: this still does not allow downgrading a memory map.

https://bugzilla.gnome.org/show_bug.cgi?id=750319

gst/gstallocator.h
gst/gstmemory.c
gst/gstmemory.h

index 99deee2..5dadd44 100644 (file)
@@ -97,6 +97,8 @@ typedef enum {
  * @mem_copy: the implementation of the GstMemoryCopyFunction
  * @mem_share: the implementation of the GstMemoryShareFunction
  * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
+ * @mem_unmap_full: the implementation of the GstMemoryUnmapFullFunction.
+ *      Will be used instead of @mem_unmap if present. Since 1.6
  *
  * The #GstAllocator is used to create new memory.
  */
@@ -104,18 +106,20 @@ struct _GstAllocator
 {
   GstObject  object;
 
-  const gchar              *mem_type;
+  const gchar               *mem_type;
 
   /*< public >*/
-  GstMemoryMapFunction      mem_map;
-  GstMemoryUnmapFunction    mem_unmap;
+  GstMemoryMapFunction       mem_map;
+  GstMemoryUnmapFunction     mem_unmap;
 
-  GstMemoryCopyFunction     mem_copy;
-  GstMemoryShareFunction    mem_share;
-  GstMemoryIsSpanFunction   mem_is_span;
+  GstMemoryCopyFunction      mem_copy;
+  GstMemoryShareFunction     mem_share;
+  GstMemoryIsSpanFunction    mem_is_span;
+
+  GstMemoryUnmapFullFunction mem_unmap_full;
 
   /*< private >*/
-  gpointer _gst_reserved[GST_PADDING];
+  gpointer _gst_reserved[GST_PADDING - 1];
 
   GstAllocatorPrivate *priv;
 };
index 5da0f58..511a6f3 100644 (file)
@@ -338,7 +338,10 @@ gst_memory_unmap (GstMemory * mem, GstMapInfo * info)
   g_return_if_fail (info != NULL);
   g_return_if_fail (info->memory == mem);
 
-  mem->allocator->mem_unmap (mem);
+  if (mem->allocator->mem_unmap_full)
+    mem->allocator->mem_unmap_full (mem, info->flags);
+  else
+    mem->allocator->mem_unmap (mem);
   gst_memory_unlock (mem, (GstLockFlags) info->flags);
 }
 
index 4819e2a..5c66464 100644 (file)
@@ -237,12 +237,19 @@ typedef gpointer    (*GstMemoryMapFunction)       (GstMemory *mem, gsize maxsize
  * @mem: a #GstMemory
  *
  * Return the pointer previously retrieved with gst_memory_map().
- *
- * Returns: %TRUE on success.
  */
 typedef void        (*GstMemoryUnmapFunction)     (GstMemory *mem);
 
 /**
+ * GstMemoryUnmapFullFunction:
+ * @mem: a #GstMemory
+ * @flags: a #GstMapFlags
+ *
+ * Return the pointer previously retrieved with gst_memory_map() with @flags.
+ */
+typedef void        (*GstMemoryUnmapFullFunction)     (GstMemory *mem, GstMapFlags flags);
+
+/**
  * GstMemoryCopyFunction:
  * @mem: a #GstMemory
  * @offset: an offset