3 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
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.
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.
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.
25 #include <gst/vulkan/vulkan.h>
29 * @title: GstVulkanImageView
30 * @short_description: wrapper for `VkImageView`'s
31 * @see_also: #GstVulkanImageMemory, #GstVulkanDevice
33 * #GstVulkanImageView is a wrapper around a `VkImageView` mostly for
34 * usage across element boundaries with #GstVulkanImageMemory
37 #define GST_CAT_DEFUALT GST_CAT_VULKAN_IMAGE_VIEW
38 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFUALT);
43 static gsize _init = 0;
45 if (g_once_init_enter (&_init)) {
46 GST_DEBUG_CATEGORY_INIT (GST_CAT_VULKAN_IMAGE_VIEW, "vulkanimageview",
47 0, "Vulkan Image View");
48 g_once_init_leave (&_init, 1);
53 gst_vulkan_image_memory_release_view (GstVulkanImageMemory * image,
54 GstVulkanImageView * view);
57 gst_vulkan_image_view_dispose (GstVulkanImageView * view)
59 GstVulkanImageMemory *image;
61 if ((image = view->image) == NULL)
64 gst_vulkan_image_view_ref (view);
65 gst_vulkan_image_memory_release_view (image, view);
71 gst_vulkan_image_view_free (GstVulkanImageView * view)
73 GST_CAT_TRACE (GST_CAT_VULKAN_IMAGE_VIEW, "freeing image view:%p ", view);
76 vkDestroyImageView (view->device->device, view->view, NULL);
79 gst_memory_unref (GST_MEMORY_CAST (view->image));
82 gst_clear_object (&view->device);
88 * gst_vulkan_image_view_new:
89 * @image: a #GstVulkanImageMemory to create the new view from
90 * @create_info: the creation information to create the view from
92 * Returns: (transfer full): A new #GstVulkanImageView from @image and
98 gst_vulkan_image_view_new (GstVulkanImageMemory * image,
99 VkImageViewCreateInfo * create_info)
101 GstVulkanImageView *view;
102 GError *error = NULL;
105 g_return_val_if_fail (create_info != NULL, NULL);
106 g_return_val_if_fail (gst_is_vulkan_image_memory (GST_MEMORY_CAST (image)),
111 view = g_new0 (GstVulkanImageView, 1);
113 gst_mini_object_init ((GstMiniObject *) view, 0,
114 gst_vulkan_image_view_get_type (), NULL,
115 (GstMiniObjectDisposeFunction) gst_vulkan_image_view_dispose,
116 (GstMiniObjectFreeFunction) gst_vulkan_image_view_free);
119 vkCreateImageView (image->device->device, create_info, NULL, &view->view);
120 if (gst_vulkan_error_to_g_error (err, &error, "vkImageCreateView") < 0)
124 (GstVulkanImageMemory *) gst_memory_ref (GST_MEMORY_CAST (image));
125 view->device = gst_object_ref (image->device);
126 view->create_info = *create_info;
127 /* we cannot keep this as it may point to stack allocated memory */
128 view->create_info.pNext = NULL;
130 GST_CAT_TRACE (GST_CAT_VULKAN_IMAGE_VIEW, "new image view for image: %p",
137 GST_CAT_ERROR (GST_CAT_VULKAN_IMAGE_VIEW,
138 "Failed to allocate image memory %s", error->message);
139 g_clear_error (&error);
150 GST_DEFINE_MINI_OBJECT_TYPE (GstVulkanImageView, gst_vulkan_image_view);