1 /*
2 * GStreamer
3 * Copyright (C) 2009 David A. Schleef <ds@schleef.org>
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 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/gl/gl.h>
25 #include "gstgtk.h"
26
27 #if GST_GL_HAVE_WINDOW_WIN32 && defined(GDK_WINDOWING_WIN32)
28 #include <gdk/gdkwin32.h>
29 #endif
30 #if GST_GL_HAVE_WINDOW_X11 && defined(GDK_WINDOWING_X11)
31 #include <gdk/gdkx.h>
32 #endif
33 #if GST_GL_HAVE_WINDOW_WAYLAND && defined(GDK_WINDOWING_WAYLAND)
34 #include <gdk/gdkwayland.h>
35 #endif
36 #if GST_GL_HAVE_WINDOW_COCOA && defined(GDK_WINDOWING_QUARTZ)
37 #include <gdk/gdkquartz.h>
38 #if GTK_CHECK_VERSION(3, 24, 10)
39 #include <AppKit/AppKit.h>
40 NSView *gdk_quartz_window_get_nsview (GdkWindow * window);
41 #endif
42 #endif
43
44 gboolean
gst_gtk_handle_need_context(GstBus * bus,GstMessage * msg,gpointer data)45 gst_gtk_handle_need_context (GstBus * bus, GstMessage * msg, gpointer data)
46 {
47 gboolean ret = FALSE;
48
49 switch (GST_MESSAGE_TYPE (msg)) {
50 case GST_MESSAGE_NEED_CONTEXT:
51 {
52 const gchar *context_type;
53
54 gst_message_parse_context_type (msg, &context_type);
55 g_print ("got need context %s\n", context_type);
56
57 if (g_strcmp0 (context_type, "GstWaylandDisplayHandleContextType") == 0) {
58 #if GST_GL_HAVE_WINDOW_WAYLAND && defined(GDK_WINDOWING_WAYLAND)
59 GstContext *context = NULL;
60 GdkDisplay *gdk_display = gdk_display_get_default ();
61 if (GDK_IS_WAYLAND_DISPLAY (gdk_display)) {
62 struct wl_display *wayland_display =
63 gdk_wayland_display_get_wl_display (gdk_display);
64 if (wayland_display) {
65 GstStructure *s;
66
67 context =
68 gst_context_new ("GstWaylandDisplayHandleContextType", TRUE);
69
70 s = gst_context_writable_structure (context);
71 gst_structure_set (s, "display", G_TYPE_POINTER, wayland_display,
72 NULL);
73
74 gst_element_set_context (GST_ELEMENT (msg->src), context);
75
76 ret = TRUE;
77 }
78 }
79 #else
80 GST_ERROR
81 ("Asked for wayland display context, but compiled without wayland support");
82 #endif
83 }
84 }
85 default:
86 break;
87 }
88
89 return ret;
90 }
91
92 void
gst_video_overlay_set_gtk_window(GstVideoOverlay * videooverlay,GtkWidget * widget)93 gst_video_overlay_set_gtk_window (GstVideoOverlay * videooverlay,
94 GtkWidget * widget)
95 {
96 GdkWindow *window;
97 GdkDisplay *display;
98 const gchar *user_choice = g_getenv ("GST_GL_WINDOW");
99
100 window = gtk_widget_get_window (widget);
101 display = gdk_window_get_display (window);
102
103 #if GST_GL_HAVE_WINDOW_WIN32 && defined(GDK_WINDOWING_WIN32)
104 if (GDK_IS_WIN32_DISPLAY (display) && (!user_choice
105 || g_strcmp0 (user_choice, "win32") == 0)) {
106 gst_video_overlay_set_window_handle (videooverlay,
107 (guintptr) GDK_WINDOW_HWND (window));
108 } else
109 #endif
110 #if GST_GL_HAVE_WINDOW_COCOA && defined(GDK_WINDOWING_QUARTZ)
111 if (GDK_IS_QUARTZ_DISPLAY (display) && (!user_choice
112 || g_strcmp0 (user_choice, "cocoa") == 0)) {
113 gst_video_overlay_set_window_handle (videooverlay, (guintptr)
114 gdk_quartz_window_get_nsview (window));
115 } else
116 #endif
117 #if GST_GL_HAVE_WINDOW_X11 && defined(GDK_WINDOWING_X11)
118 if (GDK_IS_X11_DISPLAY (display) && (!user_choice
119 || g_strcmp0 (user_choice, "x11") == 0)) {
120 gst_video_overlay_set_window_handle (videooverlay, GDK_WINDOW_XID (window));
121 } else
122 #endif
123 #if GST_GL_HAVE_WINDOW_WAYLAND && defined(GDK_WINDOWING_WAYLAND)
124 if (GDK_IS_WAYLAND_DISPLAY (display) && (!user_choice
125 || g_strcmp0 (user_choice, "wayland") == 0)) {
126 gst_video_overlay_set_window_handle (videooverlay,
127 (guintptr) gdk_wayland_window_get_wl_surface (window));
128 } else
129 #endif
130 g_error ("Unsupported Gtk+ backend");
131 }
132