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 #endif
39
40 gboolean
gst_gtk_handle_need_context(GstBus * bus,GstMessage * msg,gpointer data)41 gst_gtk_handle_need_context (GstBus * bus, GstMessage * msg, gpointer data)
42 {
43 gboolean ret = FALSE;
44
45 switch (GST_MESSAGE_TYPE (msg)) {
46 case GST_MESSAGE_NEED_CONTEXT:
47 {
48 const gchar *context_type;
49
50 gst_message_parse_context_type (msg, &context_type);
51 g_print ("got need context %s\n", context_type);
52
53 if (g_strcmp0 (context_type, "GstWaylandDisplayHandleContextType") == 0) {
54 #if GST_GL_HAVE_WINDOW_WAYLAND && defined(GDK_WINDOWING_WAYLAND)
55 GstContext *context = NULL;
56 GdkDisplay *gdk_display = gdk_display_get_default ();
57 if (GDK_IS_WAYLAND_DISPLAY (gdk_display)) {
58 struct wl_display *wayland_display =
59 gdk_wayland_display_get_wl_display (gdk_display);
60 if (wayland_display) {
61 GstStructure *s;
62
63 context =
64 gst_context_new ("GstWaylandDisplayHandleContextType", TRUE);
65
66 s = gst_context_writable_structure (context);
67 gst_structure_set (s, "display", G_TYPE_POINTER, wayland_display,
68 NULL);
69
70 gst_element_set_context (GST_ELEMENT (msg->src), context);
71
72 ret = TRUE;
73 }
74 }
75 #else
76 GST_ERROR
77 ("Asked for wayland display context, but compiled without wayland support");
78 #endif
79 }
80 }
81 default:
82 break;
83 }
84
85 return ret;
86 }
87
88 void
gst_video_overlay_set_gtk_window(GstVideoOverlay * videooverlay,GtkWidget * widget)89 gst_video_overlay_set_gtk_window (GstVideoOverlay * videooverlay,
90 GtkWidget * widget)
91 {
92 GdkWindow *window;
93 GdkDisplay *display;
94 const gchar *user_choice = g_getenv ("GST_GL_WINDOW");
95
96 window = gtk_widget_get_window (widget);
97 display = gdk_window_get_display (window);
98
99 #if GST_GL_HAVE_WINDOW_WIN32 && defined(GDK_WINDOWING_WIN32)
100 if (GDK_IS_WIN32_DISPLAY (display) && (!user_choice
101 || g_strcmp0 (user_choice, "win32") == 0)) {
102 gst_video_overlay_set_window_handle (videooverlay,
103 (guintptr) GDK_WINDOW_HWND (window));
104 } else
105 #endif
106 #if GST_GL_HAVE_WINDOW_COCOA && defined(GDK_WINDOWING_QUARTZ)
107 if (GDK_IS_QUARTZ_DISPLAY (display) && (!user_choice
108 || g_strcmp0 (user_choice, "cocoa") == 0)) {
109 gst_video_overlay_set_window_handle (videooverlay, (guintptr)
110 gdk_quartz_window_get_nsview (window));
111 } else
112 #endif
113 #if GST_GL_HAVE_WINDOW_X11 && defined(GDK_WINDOWING_X11)
114 if (GDK_IS_X11_DISPLAY (display) && (!user_choice
115 || g_strcmp0 (user_choice, "x11") == 0)) {
116 gst_video_overlay_set_window_handle (videooverlay, GDK_WINDOW_XID (window));
117 } else
118 #endif
119 #if GST_GL_HAVE_WINDOW_WAYLAND && defined(GDK_WINDOWING_WAYLAND)
120 if (GDK_IS_WAYLAND_DISPLAY (display) && (!user_choice
121 || g_strcmp0 (user_choice, "wayland") == 0)) {
122 gst_video_overlay_set_window_handle (videooverlay,
123 (guintptr) gdk_wayland_window_get_wl_surface (window));
124 } else
125 #endif
126 g_error ("Unsupported Gtk+ backend");
127 }
128