3 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.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.
23 * @short_description: window/surface abstraction
24 * @title: GstVulkanWindow
25 * @see_also: #GstGLContext, #GstGLDisplay
27 * GstVulkanWindow represents a window that elements can render into. A window can
28 * either be a user visible window (onscreen) or hidden (offscreen).
40 #if GST_VULKAN_HAVE_WINDOW_X11
41 #include "x11/vkwindow_x11.h"
43 #if GST_VULKAN_HAVE_WINDOW_XCB
44 #include "xcb/vkwindow_xcb.h"
46 #if GST_VULKAN_HAVE_WINDOW_WAYLAND
47 #include "wayland/vkwindow_wayland.h"
49 #if GST_VULKAN_HAVE_WINDOW_COCOA
50 #include "cocoa/vkwindow_cocoa.h"
52 #if GST_VULKAN_HAVE_WINDOW_IOS
53 #include "ios/vkwindow_ios.h"
56 #define GST_CAT_DEFAULT gst_vulkan_window_debug
57 GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
59 struct _GstVulkanWindowPrivate
65 #define gst_vulkan_window_parent_class parent_class
66 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GstVulkanWindow, gst_vulkan_window,
69 static void gst_vulkan_window_finalize (GObject * object);
71 typedef struct _GstVulkanDummyWindow
73 GstVulkanWindow parent;
76 } GstVulkanDummyWindow;
78 typedef struct _GstVulkanDummyWindowCass
80 GstVulkanWindowClass parent;
81 } GstVulkanDummyWindowClass;
83 GstVulkanDummyWindow *gst_vulkan_dummy_window_new (void);
93 static guint gst_vulkan_window_signals[LAST_SIGNAL] = { 0 };
96 _accum_logical_and (GSignalInvocationHint * ihint, GValue * return_accu,
97 const GValue * handler_return, gpointer data)
99 gboolean val = g_value_get_boolean (handler_return);
100 gboolean val2 = g_value_get_boolean (return_accu);
102 g_value_set_boolean (return_accu, val && val2);
108 gst_vulkan_window_error_quark (void)
110 return g_quark_from_static_string ("gst-gl-window-error-quark");
114 gst_vulkan_window_default_open (GstVulkanWindow * window, GError ** error)
120 gst_vulkan_window_default_close (GstVulkanWindow * window)
127 static volatile gsize _init = 0;
129 if (g_once_init_enter (&_init)) {
130 GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "vulkanwindow", 0,
132 g_once_init_leave (&_init, 1);
137 gst_vulkan_window_init (GstVulkanWindow * window)
139 window->priv = gst_vulkan_window_get_instance_private (window);
143 gst_vulkan_window_class_init (GstVulkanWindowClass * klass)
145 klass->open = GST_DEBUG_FUNCPTR (gst_vulkan_window_default_open);
146 klass->close = GST_DEBUG_FUNCPTR (gst_vulkan_window_default_close);
148 gst_vulkan_window_signals[SIGNAL_CLOSE] =
149 g_signal_new ("close", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
150 (GSignalAccumulator) _accum_logical_and, NULL, NULL, G_TYPE_BOOLEAN, 0);
152 gst_vulkan_window_signals[SIGNAL_DRAW] =
153 g_signal_new ("draw", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
154 NULL, NULL, NULL, G_TYPE_NONE, 0);
156 G_OBJECT_CLASS (klass)->finalize = gst_vulkan_window_finalize;
162 * gst_vulkan_window_new:
163 * @display: a #GstGLDisplay
165 * Returns: (transfer full): a new #GstVulkanWindow using @display's connection
170 gst_vulkan_window_new (GstVulkanDisplay * display)
172 GstVulkanWindow *window = NULL;
173 const gchar *user_choice;
175 g_return_val_if_fail (display != NULL, NULL);
179 user_choice = g_getenv ("GST_VULKAN_WINDOW");
180 GST_INFO ("creating a window, user choice:%s", user_choice);
181 #if GST_VULKAN_HAVE_WINDOW_X11
182 if (!window && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
183 window = GST_VULKAN_WINDOW (gst_vulkan_window_x11_new (display));
185 #if GST_VULKAN_HAVE_WINDOW_XCB
186 if (!window && (!user_choice || g_strstr_len (user_choice, 3, "xcb")))
187 window = GST_VULKAN_WINDOW (gst_vulkan_window_xcb_new (display));
189 #if GST_VULKAN_HAVE_WINDOW_WAYLAND
190 if (!window && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
191 window = GST_VULKAN_WINDOW (gst_vulkan_window_wayland_new (display));
193 #if GST_VULKAN_HAVE_WINDOW_COCOA
194 if (!window && (!user_choice || g_strstr_len (user_choice, 5, "cocoa")))
195 window = GST_VULKAN_WINDOW (gst_vulkan_window_cocoa_new (display));
197 #if GST_VULKAN_HAVE_WINDOW_IOS
198 if (!window && (!user_choice || g_strstr_len (user_choice, 3, "ios")))
199 window = GST_VULKAN_WINDOW (gst_vulkan_window_ios_new (display));
202 /* subclass returned a NULL window */
203 GST_WARNING ("Could not create window. user specified %s, creating dummy"
204 " window", user_choice ? user_choice : "(null)");
206 window = GST_VULKAN_WINDOW (gst_vulkan_dummy_window_new ());
209 window->display = gst_object_ref (display);
215 gst_vulkan_window_finalize (GObject * object)
217 GstVulkanWindow *window = GST_VULKAN_WINDOW (object);
219 gst_object_unref (window->display);
221 G_OBJECT_CLASS (gst_vulkan_window_parent_class)->finalize (object);
225 gst_vulkan_window_get_display (GstVulkanWindow * window)
227 g_return_val_if_fail (GST_IS_VULKAN_WINDOW (window), NULL);
229 return gst_object_ref (window->display);
233 gst_vulkan_window_get_surface (GstVulkanWindow * window, GError ** error)
235 GstVulkanWindowClass *klass;
237 g_return_val_if_fail (GST_IS_VULKAN_WINDOW (window), (VkSurfaceKHR) 0);
238 klass = GST_VULKAN_WINDOW_GET_CLASS (window);
239 g_return_val_if_fail (klass->get_surface != NULL, (VkSurfaceKHR) 0);
241 return klass->get_surface (window, error);
245 gst_vulkan_window_get_presentation_support (GstVulkanWindow * window,
246 GstVulkanDevice * device, guint32 queue_family_idx)
248 GstVulkanWindowClass *klass;
250 g_return_val_if_fail (GST_IS_VULKAN_WINDOW (window), FALSE);
251 klass = GST_VULKAN_WINDOW_GET_CLASS (window);
252 g_return_val_if_fail (klass->get_presentation_support != NULL, FALSE);
254 return klass->get_presentation_support (window, device, queue_family_idx);
258 gst_vulkan_window_open (GstVulkanWindow * window, GError ** error)
260 GstVulkanWindowClass *klass;
262 g_return_val_if_fail (GST_IS_VULKAN_WINDOW (window), FALSE);
263 klass = GST_VULKAN_WINDOW_GET_CLASS (window);
264 g_return_val_if_fail (klass->open != NULL, FALSE);
266 return klass->open (window, error);
270 gst_vulkan_window_close (GstVulkanWindow * window)
272 GstVulkanWindowClass *klass;
275 g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
276 klass = GST_VULKAN_WINDOW_GET_CLASS (window);
277 g_return_if_fail (klass->close != NULL);
279 g_signal_emit (window, gst_vulkan_window_signals[SIGNAL_CLOSE], 0, &to_close);
282 klass->close (window);
286 gst_vulkan_window_resize (GstVulkanWindow * window, gint width, gint height)
288 g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
290 window->priv->surface_width = width;
291 window->priv->surface_height = height;
293 /* XXX: possibly queue a resize/redraw */
297 gst_vulkan_window_redraw (GstVulkanWindow * window)
299 g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
301 g_signal_emit (window, gst_vulkan_window_signals[SIGNAL_DRAW], 0);
305 gst_vulkan_window_set_window_handle (GstVulkanWindow * window, guintptr handle)
307 GstVulkanWindowClass *klass;
309 g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
310 klass = GST_VULKAN_WINDOW_GET_CLASS (window);
312 if (!klass->set_window_handle) {
314 g_warning ("%s does not implement the set_window_handle vfunc. "
315 "Output will not be embedded into the specified surface.",
316 GST_OBJECT_NAME (window));
318 klass->set_window_handle (window, handle);
322 GType gst_vulkan_dummy_window_get_type (void);
323 G_DEFINE_TYPE (GstVulkanDummyWindow, gst_vulkan_dummy_window,
324 GST_TYPE_VULKAN_WINDOW);
327 gst_vulkan_dummy_window_class_init (GstVulkanDummyWindowClass * klass)
332 gst_vulkan_dummy_window_init (GstVulkanDummyWindow * dummy)
337 GstVulkanDummyWindow *
338 gst_vulkan_dummy_window_new (void)
340 GstVulkanDummyWindow *window;
342 window = g_object_new (gst_vulkan_dummy_window_get_type (), NULL);
343 gst_object_ref_sink (window);