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_SWAPPER_H_
22 #define _VK_SWAPPER_H_
23 
24 #include <gst/video/video.h>
25 
26 #include <vk.h>
27 
28 G_BEGIN_DECLS
29 
30 #define GST_TYPE_VULKAN_SWAPPER         (gst_vulkan_swapper_get_type())
31 #define GST_VULKAN_SWAPPER(o)           (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_VULKAN_SWAPPER, GstVulkanSwapper))
32 #define GST_VULKAN_SWAPPER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GST_TYPE_VULKAN_SWAPPER, GstVulkanSwapperClass))
33 #define GST_IS_VULKAN_SWAPPER(o)        (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_VULKAN_SWAPPER))
34 #define GST_IS_VULKAN_SWAPPER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_VULKAN_SWAPPER))
35 #define GST_VULKAN_SWAPPER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_VULKAN_SWAPPER, GstVulkanSwapperClass))
36 GType gst_vulkan_swapper_get_type       (void);
37 
38 #define GST_VULKAN_SWAPPER_VIDEO_FORMATS " { RGBA, BGRA, RGB, BGR } "
39 
40 struct _GstVulkanSwapper
41 {
42   GstObject parent;
43 
44   GstVulkanDevice *device;
45   GstVulkanWindow *window;
46   GstVulkanQueue *queue;
47 
48   VkSurfaceKHR    surface;
49 
50   VkSurfaceCapabilitiesKHR surf_props;
51   VkSurfaceFormatKHR *surf_formats;
52   guint32 n_surf_formats;
53   VkPresentModeKHR *surf_present_modes;
54   guint32 n_surf_present_modes;
55 
56   VkSwapchainKHR swap_chain;
57   GstVulkanImageMemory **swap_chain_images;
58   guint32 n_swap_chain_images;
59 
60   GstCaps *caps;
61   GstVideoInfo v_info;
62 
63   PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
64   PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR;
65   PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
66   PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR;
67   PFN_vkCreateSwapchainKHR CreateSwapchainKHR;
68   PFN_vkDestroySwapchainKHR DestroySwapchainKHR;
69   PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR;
70   PFN_vkAcquireNextImageKHR AcquireNextImageKHR;
71   PFN_vkQueuePresentKHR QueuePresentKHR;
72 
73   /* <private> */
74   /* runtime variables */
75   gint to_quit;
76   GstBuffer *current_buffer;
77 
78   /* signal handlers */
79   gulong close_id;
80   gulong draw_id;
81 
82   GstVulkanSwapperPrivate *priv;
83 };
84 
85 struct _GstVulkanSwapperClass
86 {
87   GstObjectClass parent_class;
88 };
89 
90 GstVulkanSwapper *  gst_vulkan_swapper_new                      (GstVulkanDevice * device,
91                                                                  GstVulkanWindow * window);
92 
93 GstCaps *           gst_vulkan_swapper_get_supported_caps       (GstVulkanSwapper * swapper,
94                                                                  GError ** error);
95 gboolean            gst_vulkan_swapper_set_caps                 (GstVulkanSwapper * swapper,
96                                                                  GstCaps * caps,
97                                                                  GError ** error);
98 gboolean            gst_vulkan_swapper_render_buffer            (GstVulkanSwapper * swapper,
99                                                                  GstBuffer * buffer,
100                                                                  GError ** error);
101 
102 G_END_DECLS
103 
104 #endif /* _VK_INSTANCE_H_ */
105