1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef _VK_BUFFER_MEMORY_H_
22 #define _VK_BUFFER_MEMORY_H_
23 
24 #include <gst/gst.h>
25 #include <gst/gstallocator.h>
26 #include <gst/gstmemory.h>
27 
28 #include <vk.h>
29 
30 G_BEGIN_DECLS
31 
32 #define GST_TYPE_VULKAN_BUFFER_MEMORY_ALLOCATOR (gst_vulkan_buffer_memory_allocator_get_type())
33 GType gst_vulkan_buffer_memory_allocator_get_type(void);
34 
35 #define GST_IS_VULKAN_BUFFER_MEMORY_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VULKAN_BUFFER_MEMORY_ALLOCATOR))
36 #define GST_IS_VULKAN_BUFFER_MEMORY_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VULKAN_BUFFER_MEMORY_ALLOCATOR))
37 #define GST_VULKAN_BUFFER_MEMORY_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanBufferMemoryAllocatorClass))
38 #define GST_VULKAN_BUFFER_MEMORY_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanBufferMemoryAllocator))
39 #define GST_VULKAN_BUFFER_MEMORY_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanBufferMemoryAllocatorClass))
40 #define GST_VULKAN_BUFFER_MEMORY_ALLOCATOR_CAST(obj)            ((GstVulkanBufferMemoryAllocator *)(obj))
41 
42 #define GST_VULKAN_BUFFER_MEMORY_ALLOCATOR_NAME "VulkanBuffer"
43 #define GST_CAPS_FEATURE_MEMORY_VULKAN_BUFFER "memory:" GST_VULKAN_BUFFER_MEMORY_ALLOCATOR_NAME
44 
45 struct _GstVulkanBufferMemory
46 {
47   GstMemory parent;
48 
49   GstVulkanDevice * device;
50 
51   VkBuffer buffer;
52   VkBufferView view;
53   GstVulkanMemory *vk_mem;
54 
55   VkMemoryRequirements requirements;
56   VkBufferUsageFlags usage;
57 
58   GMutex lock;
59   gboolean wrapped;
60   GDestroyNotify notify;
61   gpointer user_data;
62 };
63 
64 /**
65  * GstVulkanBufferMemoryAllocator
66  *
67  * Opaque #GstVulkanBufferMemoryAllocator struct
68  */
69 struct _GstVulkanBufferMemoryAllocator
70 {
71   GstAllocator parent;
72 };
73 
74 /**
75  * GstVulkanBufferMemoryAllocatorClass:
76  *
77  * The #GstVulkanBufferMemoryAllocatorClass only contains private data
78  */
79 struct _GstVulkanBufferMemoryAllocatorClass
80 {
81   GstAllocatorClass parent_class;
82 };
83 
84 void            gst_vulkan_buffer_memory_init_once       (void);
85 gboolean        gst_is_vulkan_buffer_memory              (GstMemory * mem);
86 
87 GstMemory *     gst_vulkan_buffer_memory_alloc           (GstVulkanDevice * device,
88                                                          VkFormat format,
89                                                          gsize size,
90                                                          VkBufferUsageFlags usage,
91                                                          VkMemoryPropertyFlags mem_prop_flags);
92 
93 GstMemory *     gst_vulkan_buffer_memory_wrapped         (GstVulkanDevice * device,
94                                                          VkBuffer buffer,
95                                                          VkFormat format,
96                                                          VkBufferUsageFlags usage,
97                                                          gpointer user_data,
98                                                          GDestroyNotify notify);
99 
100 G_END_DECLS
101 
102 #endif /* _VK_BUFFER_MEMORY_H_ */
103