• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 __GST_VULKAN_IMAGE_MEMORY_H__
22 #define __GST_VULKAN_IMAGE_MEMORY_H__
23 
24 #include <gst/vulkan/gstvkbarrier.h>
25 #include <gst/vulkan/gstvkdevice.h>
26 
27 #include <gst/video/video.h>
28 
29 G_BEGIN_DECLS
30 
31 #define GST_TYPE_VULKAN_IMAGE_MEMORY_ALLOCATOR (gst_vulkan_image_memory_allocator_get_type())
32 GST_VULKAN_API
33 GType gst_vulkan_image_memory_allocator_get_type(void);
34 
35 #define GST_IS_VULKAN_IMAGE_MEMORY_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VULKAN_IMAGE_MEMORY_ALLOCATOR))
36 #define GST_IS_VULKAN_IMAGE_MEMORY_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VULKAN_IMAGE_MEMORY_ALLOCATOR))
37 #define GST_VULKAN_IMAGE_MEMORY_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanImageMemoryAllocatorClass))
38 #define GST_VULKAN_IMAGE_MEMORY_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanImageMemoryAllocator))
39 #define GST_VULKAN_IMAGE_MEMORY_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanImageMemoryAllocatorClass))
40 /**
41  * GST_VULKAN_IMAGE_MEMORY_ALLOCATOR_CAST:
42  *
43  * Since: 1.18
44  */
45 #define GST_VULKAN_IMAGE_MEMORY_ALLOCATOR_CAST(obj)            ((GstVulkanImageMemoryAllocator *)(obj))
46 
47 /**
48  * GST_VULKAN_IMAGE_MEMORY_ALLOCATOR_NAME:
49  *
50  * Since: 1.18
51  */
52 #define GST_VULKAN_IMAGE_MEMORY_ALLOCATOR_NAME "VulkanImage"
53 /**
54  * GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE:
55  *
56  * Since: 1.18
57  */
58 #define GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE "memory:VulkanImage"
59 
60 /**
61  * GstVulkanBarrierImageInfo:
62  * @parent: parent #GstVulkanBarrierMemoryInfo
63  * @image_layout: the image layout of this barrier
64  * @subresource_range: what subresource the barrier applies to
65  *
66  * Since: 1.18
67  */
68 struct _GstVulkanBarrierImageInfo
69 {
70   GstVulkanBarrierMemoryInfo parent;
71 
72   VkImageLayout image_layout;
73   /* FIXME: multiple layers or mipmap levels may require multiple barriers */
74   VkImageSubresourceRange subresource_range;
75 };
76 
77 /**
78  * GstVulkanImageMemory:
79  * @parent: parent #GstMemory
80  * @device: the #GstVulkanDevice to allocate images from
81  * @image: the Vulkan image handle
82  * @vk_mem: the backing #GstVulkanMemory for @image
83  * @create_info: creation information for @image
84  * @requirements: memory requirements for @image
85  * @format_properties: format properties
86  * @usage: intended usage for @image
87  * @barrier: last set barrier for @image
88  *
89  * Since: 1.18
90  */
91 struct _GstVulkanImageMemory
92 {
93   GstMemory parent;
94 
95   GstVulkanDevice * device;
96 
97   VkImage image;
98   GstVulkanMemory *vk_mem;
99 
100   VkImageCreateInfo create_info;
101   VkMemoryRequirements requirements;
102   VkImageFormatProperties format_properties;
103   VkImageUsageFlags usage;
104 
105   GstVulkanBarrierImageInfo barrier;
106 
107   /* <private> */
108   GMutex lock;
109   gboolean wrapped;
110   GDestroyNotify notify;
111   gpointer user_data;
112 
113   GPtrArray *views;
114   GPtrArray *outstanding_views;
115 
116   gpointer _padding[GST_PADDING];
117 };
118 
119 /**
120  * GstVulkanImageMemoryFindViewFunc:
121  *
122  * Function definition used to find views.  Return %TRUE if @view matches the
123  * criteria.
124  *
125  * Since: 1.18
126  */
127 typedef gboolean (*GstVulkanImageMemoryFindViewFunc) (GstVulkanImageView * view, gpointer user_data);
128 
129 /**
130  * GstVulkanImageMemoryAllocator
131  * @parent: the parent #GstAllocator
132  *
133  * Opaque #GstVulkanImageMemoryAllocator struct
134  *
135  * Since: 1.18
136  */
137 struct _GstVulkanImageMemoryAllocator
138 {
139   GstAllocator parent;
140 
141   /* <private> */
142   gpointer _reserved        [GST_PADDING];
143 };
144 
145 /**
146  * GstVulkanImageMemoryAllocatorClass:
147  * @parent_class: the parent #GstAllocatorClass
148  *
149  * The #GstVulkanImageMemoryAllocatorClass only contains private data
150  *
151  * Since: 1.18
152  */
153 struct _GstVulkanImageMemoryAllocatorClass
154 {
155   GstAllocatorClass parent_class;
156 
157   /* <private> */
158   gpointer _reserved        [GST_PADDING];
159 };
160 
161 GST_VULKAN_API
162 void            gst_vulkan_image_memory_init_once       (void);
163 GST_VULKAN_API
164 gboolean        gst_is_vulkan_image_memory              (GstMemory * mem);
165 
166 GST_VULKAN_API
167 gboolean        gst_vulkan_image_memory_init            (GstVulkanImageMemory * mem,
168                                                          GstAllocator * allocator,
169                                                          GstMemory * parent,
170                                                          GstVulkanDevice * device,
171                                                          VkImageUsageFlags usage,
172                                                          GstAllocationParams * params,
173                                                          gsize size,
174                                                          gpointer user_data,
175                                                          GDestroyNotify notify);
176 GST_VULKAN_API
177 GstMemory *     gst_vulkan_image_memory_alloc           (GstVulkanDevice * device,
178                                                          VkFormat format,
179                                                          gsize width,
180                                                          gsize height,
181                                                          VkImageTiling tiling,
182                                                          VkImageUsageFlags usage,
183                                                          VkMemoryPropertyFlags mem_prop_flags);
184 
185 GST_VULKAN_API
186 GstMemory *     gst_vulkan_image_memory_wrapped         (GstVulkanDevice * device,
187                                                          VkImage image,
188                                                          VkFormat format,
189                                                          gsize width,
190                                                          gsize height,
191                                                          VkImageTiling tiling,
192                                                          VkImageUsageFlags usage,
193                                                          gpointer user_data,
194                                                          GDestroyNotify notify);
195 
196 GST_VULKAN_API
197 guint32         gst_vulkan_image_memory_get_width       (GstVulkanImageMemory * image);
198 GST_VULKAN_API
199 guint32         gst_vulkan_image_memory_get_height      (GstVulkanImageMemory * image);
200 
201 GST_VULKAN_API
202 GstVulkanImageView *gst_vulkan_image_memory_find_view   (GstVulkanImageMemory * image,
203                                                          GstVulkanImageMemoryFindViewFunc find_func,
204                                                          gpointer user_data);
205 GST_VULKAN_API
206 void            gst_vulkan_image_memory_add_view        (GstVulkanImageMemory * image,
207                                                          GstVulkanImageView * view);
208 
209 GST_VULKAN_API
210 VkFormat gst_vulkan_format_from_video_info   (GstVideoInfo * v_info,
211                                               guint plane);
212 
213 G_END_DECLS
214 
215 #endif /* __GST_VULKAN_IMAGE_MEMORY_H__ */
216