Removed
Link Here
|
1 |
https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/767 |
2 |
|
3 |
--- ext/gtk/gstgtkbasesink.c.orig 2019-12-03 11:06:37 UTC |
4 |
+++ ext/gtk/gstgtkbasesink.c |
5 |
@@ -1,6 +1,7 @@ |
6 |
/* |
7 |
* GStreamer |
8 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com> |
9 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
10 |
* |
11 |
* This library is free software; you can redistribute it and/or |
12 |
* modify it under the terms of the GNU Library General Public |
13 |
@@ -77,7 +78,7 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstGtkBaseSink, gst_ |
14 |
G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION, |
15 |
gst_gtk_base_sink_navigation_interface_init); |
16 |
GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_base_sink, |
17 |
- "gtkbasesink", 0, "Gtk Video Sink base class")); |
18 |
+ "gtkbasesink", 0, "GTK Video Sink base class")); |
19 |
|
20 |
|
21 |
static void |
22 |
@@ -97,7 +98,7 @@ gst_gtk_base_sink_class_init (GstGtkBaseSinkClass * kl |
23 |
gobject_class->get_property = gst_gtk_base_sink_get_property; |
24 |
|
25 |
g_object_class_install_property (gobject_class, PROP_WIDGET, |
26 |
- g_param_spec_object ("widget", "Gtk Widget", |
27 |
+ g_param_spec_object ("widget", "GTK Widget", |
28 |
"The GtkWidget to place in the widget hierarchy " |
29 |
"(must only be get from the GTK main thread)", |
30 |
GTK_TYPE_WIDGET, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
31 |
@@ -114,10 +115,13 @@ gst_gtk_base_sink_class_init (GstGtkBaseSinkClass * kl |
32 |
"The pixel aspect ratio of the device", DEFAULT_PAR_N, DEFAULT_PAR_D, |
33 |
G_MAXINT, 1, 1, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
34 |
|
35 |
+ /* Disabling alpha was removed in GTK4 */ |
36 |
+#if !defined(BUILD_FOR_GTK4) |
37 |
g_object_class_install_property (gobject_class, PROP_IGNORE_ALPHA, |
38 |
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha", |
39 |
"When enabled, alpha will be ignored and converted to black", |
40 |
DEFAULT_IGNORE_ALPHA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
41 |
+#endif |
42 |
|
43 |
gobject_class->finalize = gst_gtk_base_sink_finalize; |
44 |
|
45 |
@@ -144,6 +148,8 @@ gst_gtk_base_sink_finalize (GObject * object) |
46 |
{ |
47 |
GstGtkBaseSink *gtk_sink = GST_GTK_BASE_SINK (object); |
48 |
|
49 |
+ GST_DEBUG ("finalizing base sink"); |
50 |
+ |
51 |
GST_OBJECT_LOCK (gtk_sink); |
52 |
if (gtk_sink->window && gtk_sink->window_destroy_id) |
53 |
g_signal_handler_disconnect (gtk_sink->window, gtk_sink->window_destroy_id); |
54 |
@@ -168,6 +174,14 @@ static void |
55 |
window_destroy_cb (GtkWidget * widget, GstGtkBaseSink * gtk_sink) |
56 |
{ |
57 |
GST_OBJECT_LOCK (gtk_sink); |
58 |
+ if (gtk_sink->widget) { |
59 |
+ if (gtk_sink->widget_destroy_id) { |
60 |
+ g_signal_handler_disconnect (gtk_sink->widget, |
61 |
+ gtk_sink->widget_destroy_id); |
62 |
+ gtk_sink->widget_destroy_id = 0; |
63 |
+ } |
64 |
+ g_clear_object (>k_sink->widget); |
65 |
+ } |
66 |
gtk_sink->window = NULL; |
67 |
GST_OBJECT_UNLOCK (gtk_sink); |
68 |
} |
69 |
@@ -180,7 +194,11 @@ gst_gtk_base_sink_get_widget (GstGtkBaseSink * gtk_sin |
70 |
|
71 |
/* Ensure GTK is initialized, this has no side effect if it was already |
72 |
* initialized. Also, we do that lazily, so the application can be first */ |
73 |
- if (!gtk_init_check (NULL, NULL)) { |
74 |
+ if (!gtk_init_check ( |
75 |
+#if !defined(BUILD_FOR_GTK4) |
76 |
+ NULL, NULL |
77 |
+#endif |
78 |
+ )) { |
79 |
GST_ERROR_OBJECT (gtk_sink, "Could not ensure GTK initialization."); |
80 |
return NULL; |
81 |
} |
82 |
@@ -195,13 +213,16 @@ gst_gtk_base_sink_get_widget (GstGtkBaseSink * gtk_sin |
83 |
gtk_sink->bind_pixel_aspect_ratio = |
84 |
g_object_bind_property (gtk_sink, "pixel-aspect-ratio", gtk_sink->widget, |
85 |
"pixel-aspect-ratio", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); |
86 |
+#if !defined(BUILD_FOR_GTK4) |
87 |
gtk_sink->bind_ignore_alpha = |
88 |
g_object_bind_property (gtk_sink, "ignore-alpha", gtk_sink->widget, |
89 |
"ignore-alpha", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); |
90 |
+#endif |
91 |
|
92 |
/* Take the floating ref, other wise the destruction of the container will |
93 |
* make this widget disapear possibly before we are done. */ |
94 |
gst_object_ref_sink (gtk_sink->widget); |
95 |
+ |
96 |
gtk_sink->widget_destroy_id = g_signal_connect (gtk_sink->widget, "destroy", |
97 |
G_CALLBACK (widget_destroy_cb), gtk_sink); |
98 |
|
99 |
@@ -311,25 +332,55 @@ gst_gtk_base_sink_start_on_main (GstBaseSink * bsink) |
100 |
GstGtkBaseSink *gst_sink = GST_GTK_BASE_SINK (bsink); |
101 |
GstGtkBaseSinkClass *klass = GST_GTK_BASE_SINK_GET_CLASS (bsink); |
102 |
GtkWidget *toplevel; |
103 |
+#if defined(BUILD_FOR_GTK4) |
104 |
+ GtkRoot *root; |
105 |
+#endif |
106 |
|
107 |
if (gst_gtk_base_sink_get_widget (gst_sink) == NULL) |
108 |
return FALSE; |
109 |
|
110 |
/* After this point, gtk_sink->widget will always be set */ |
111 |
|
112 |
+#if defined(BUILD_FOR_GTK4) |
113 |
+ root = gtk_widget_get_root (GTK_WIDGET (gst_sink->widget)); |
114 |
+ if (!GTK_IS_ROOT (root)) { |
115 |
+ GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (gst_sink->widget)); |
116 |
+ if (parent) { |
117 |
+ GtkWidget *temp_parent; |
118 |
+ while ((temp_parent = gtk_widget_get_parent (parent))) |
119 |
+ parent = temp_parent; |
120 |
+ } |
121 |
+ toplevel = (parent) ? parent : GTK_WIDGET (gst_sink->widget); |
122 |
+#else |
123 |
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gst_sink->widget)); |
124 |
if (!gtk_widget_is_toplevel (toplevel)) { |
125 |
+#endif |
126 |
/* sanity check */ |
127 |
g_assert (klass->window_title); |
128 |
|
129 |
/* User did not add widget its own UI, let's popup a new GtkWindow to |
130 |
* make gst-launch-1.0 work. */ |
131 |
- gst_sink->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
132 |
+ gst_sink->window = gtk_window_new ( |
133 |
+#if !defined(BUILD_FOR_GTK4) |
134 |
+ GTK_WINDOW_TOPLEVEL |
135 |
+#endif |
136 |
+ ); |
137 |
gtk_window_set_default_size (GTK_WINDOW (gst_sink->window), 640, 480); |
138 |
gtk_window_set_title (GTK_WINDOW (gst_sink->window), klass->window_title); |
139 |
- gtk_container_add (GTK_CONTAINER (gst_sink->window), toplevel); |
140 |
- gst_sink->window_destroy_id = g_signal_connect (gst_sink->window, "destroy", |
141 |
- G_CALLBACK (window_destroy_cb), gst_sink); |
142 |
+#if defined(BUILD_FOR_GTK4) |
143 |
+ gtk_window_set_child (GTK_WINDOW ( |
144 |
+#else |
145 |
+ gtk_container_add (GTK_CONTAINER ( |
146 |
+#endif |
147 |
+ gst_sink->window), toplevel); |
148 |
+ |
149 |
+ gst_sink->window_destroy_id = g_signal_connect ( |
150 |
+#if defined(BUILD_FOR_GTK4) |
151 |
+ GTK_WINDOW (gst_sink->window), |
152 |
+#else |
153 |
+ gst_sink->window, |
154 |
+#endif |
155 |
+ "destroy", G_CALLBACK (window_destroy_cb), gst_sink); |
156 |
} |
157 |
|
158 |
return TRUE; |
159 |
@@ -348,7 +399,11 @@ gst_gtk_base_sink_stop_on_main (GstBaseSink * bsink) |
160 |
GstGtkBaseSink *gst_sink = GST_GTK_BASE_SINK (bsink); |
161 |
|
162 |
if (gst_sink->window) { |
163 |
+#if defined(BUILD_FOR_GTK4) |
164 |
+ gtk_window_destroy (GTK_WINDOW (gst_sink->window)); |
165 |
+#else |
166 |
gtk_widget_destroy (gst_sink->window); |
167 |
+#endif |
168 |
gst_sink->window = NULL; |
169 |
gst_sink->widget = NULL; |
170 |
} |
171 |
@@ -369,10 +424,14 @@ gst_gtk_base_sink_stop (GstBaseSink * bsink) |
172 |
} |
173 |
|
174 |
static void |
175 |
-gst_gtk_widget_show_all_and_unref (GtkWidget * widget) |
176 |
+gst_gtk_window_show_all_and_unref (GtkWidget * window) |
177 |
{ |
178 |
- gtk_widget_show_all (widget); |
179 |
- g_object_unref (widget); |
180 |
+#if defined(BUILD_FOR_GTK4) |
181 |
+ gtk_window_present (GTK_WINDOW (window)); |
182 |
+#else |
183 |
+ gtk_widget_show_all (window); |
184 |
+#endif |
185 |
+ g_object_unref (window); |
186 |
} |
187 |
|
188 |
static GstStateChangeReturn |
189 |
@@ -400,7 +459,7 @@ gst_gtk_base_sink_change_state (GstElement * element, |
190 |
GST_OBJECT_UNLOCK (gtk_sink); |
191 |
|
192 |
if (window) |
193 |
- gst_gtk_invoke_on_main ((GThreadFunc) gst_gtk_widget_show_all_and_unref, |
194 |
+ gst_gtk_invoke_on_main ((GThreadFunc) gst_gtk_window_show_all_and_unref, |
195 |
window); |
196 |
|
197 |
break; |
198 |
--- ext/gtk/gstgtkbasesink.h.orig 2019-12-03 11:06:37 UTC |
199 |
+++ ext/gtk/gstgtkbasesink.h |
200 |
@@ -51,14 +51,14 @@ GType gst_gtk_base_sink_get_type (void); |
201 |
struct _GstGtkBaseSink |
202 |
{ |
203 |
/* <private> */ |
204 |
- GstVideoSink parent; |
205 |
+ GstVideoSink parent; |
206 |
|
207 |
- GstVideoInfo v_info; |
208 |
+ GstVideoInfo v_info; |
209 |
|
210 |
GtkGstBaseWidget *widget; |
211 |
|
212 |
/* properties */ |
213 |
- gboolean force_aspect_ratio; |
214 |
+ gboolean force_aspect_ratio; |
215 |
GBinding *bind_aspect_ratio; |
216 |
|
217 |
gint par_n; |
218 |
@@ -69,8 +69,8 @@ struct _GstGtkBaseSink |
219 |
GBinding *bind_ignore_alpha; |
220 |
|
221 |
GtkWidget *window; |
222 |
- gulong widget_destroy_id; |
223 |
- gulong window_destroy_id; |
224 |
+ gulong widget_destroy_id; |
225 |
+ gulong window_destroy_id; |
226 |
}; |
227 |
|
228 |
/** |
229 |
--- ext/gtk/gstgtkglsink.c.orig 2019-12-03 11:06:37 UTC |
230 |
+++ ext/gtk/gstgtkglsink.c |
231 |
@@ -1,6 +1,7 @@ |
232 |
/* |
233 |
* GStreamer |
234 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com> |
235 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
236 |
* |
237 |
* This library is free software; you can redistribute it and/or |
238 |
* modify it under the terms of the GNU Library General Public |
239 |
@@ -23,12 +24,18 @@ |
240 |
* @title: gtkglsink |
241 |
*/ |
242 |
|
243 |
+/** |
244 |
+ * SECTION:element-gtk4glsink |
245 |
+ * @title: gtk4glsink |
246 |
+ */ |
247 |
+ |
248 |
#ifdef HAVE_CONFIG_H |
249 |
#include "config.h" |
250 |
#endif |
251 |
|
252 |
#include <gst/gl/gstglfuncs.h> |
253 |
|
254 |
+#include "gtkconfig.h" |
255 |
#include "gstgtkglsink.h" |
256 |
#include "gtkgstglwidget.h" |
257 |
|
258 |
@@ -58,7 +65,7 @@ static GstStaticPadTemplate gst_gtk_gl_sink_template = |
259 |
#define gst_gtk_gl_sink_parent_class parent_class |
260 |
G_DEFINE_TYPE_WITH_CODE (GstGtkGLSink, gst_gtk_gl_sink, |
261 |
GST_TYPE_GTK_BASE_SINK, GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_gl_sink, |
262 |
- "gtkglsink", 0, "Gtk GL Video Sink")); |
263 |
+ GTKCONFIG_GLSINK, 0, GTKCONFIG_NAME " GL Video Sink")); |
264 |
|
265 |
static void |
266 |
gst_gtk_gl_sink_class_init (GstGtkGLSinkClass * klass) |
267 |
@@ -82,11 +89,13 @@ gst_gtk_gl_sink_class_init (GstGtkGLSinkClass * klass) |
268 |
gstbasesink_class->get_caps = gst_gtk_gl_sink_get_caps; |
269 |
|
270 |
gstgtkbasesink_class->create_widget = gtk_gst_gl_widget_new; |
271 |
- gstgtkbasesink_class->window_title = "Gtk+ GL renderer"; |
272 |
+ gstgtkbasesink_class->window_title = GTKCONFIG_NAME " GL Renderer"; |
273 |
|
274 |
- gst_element_class_set_metadata (gstelement_class, "Gtk GL Video Sink", |
275 |
+ gst_element_class_set_metadata (gstelement_class, |
276 |
+ GTKCONFIG_NAME " GL Video Sink", |
277 |
"Sink/Video", "A video sink that renders to a GtkWidget using OpenGL", |
278 |
- "Matthew Waters <matthew@centricular.com>"); |
279 |
+ "Matthew Waters <matthew@centricular.com>, " |
280 |
+ "Rafał Dzięgiel <rafostar.github@gmail.com>"); |
281 |
|
282 |
gst_element_class_add_static_pad_template (gstelement_class, |
283 |
&gst_gtk_gl_sink_template); |
284 |
@@ -120,16 +129,18 @@ gst_gtk_gl_sink_query (GstBaseSink * bsink, GstQuery * |
285 |
} |
286 |
|
287 |
static void |
288 |
-_size_changed_cb (GtkWidget * widget, GdkRectangle * rectangle, |
289 |
- GstGtkGLSink * gtk_sink) |
290 |
+_size_changed_cb (GtkWidget * widget, gint width, |
291 |
+ gint height, GstGtkGLSink * gtk_sink) |
292 |
{ |
293 |
- gint scale_factor, width, height; |
294 |
gboolean reconfigure; |
295 |
|
296 |
- scale_factor = gtk_widget_get_scale_factor (widget); |
297 |
- width = scale_factor * gtk_widget_get_allocated_width (widget); |
298 |
- height = scale_factor * gtk_widget_get_allocated_height (widget); |
299 |
+ GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget); |
300 |
|
301 |
+ /* Ignore size changes before widget is negotiated |
302 |
+ * we are going to queue a resize after negotiation */ |
303 |
+ if (!base_widget->negotiated) |
304 |
+ return; |
305 |
+ |
306 |
GST_OBJECT_LOCK (gtk_sink); |
307 |
reconfigure = |
308 |
(width != gtk_sink->display_width || height != gtk_sink->display_height); |
309 |
@@ -138,7 +149,7 @@ _size_changed_cb (GtkWidget * widget, GdkRectangle * r |
310 |
GST_OBJECT_UNLOCK (gtk_sink); |
311 |
|
312 |
if (reconfigure) { |
313 |
- GST_DEBUG_OBJECT (gtk_sink, "Sending reconfigure event on sinkpad."); |
314 |
+ GST_DEBUG_OBJECT (gtk_sink, "Sending reconfigure event on sinkpad"); |
315 |
gst_pad_push_event (GST_BASE_SINK (gtk_sink)->sinkpad, |
316 |
gst_event_new_reconfigure ()); |
317 |
} |
318 |
@@ -147,9 +158,9 @@ _size_changed_cb (GtkWidget * widget, GdkRectangle * r |
319 |
static void |
320 |
destroy_cb (GtkWidget * widget, GstGtkGLSink * gtk_sink) |
321 |
{ |
322 |
- if (gtk_sink->size_allocate_sig_handler) { |
323 |
- g_signal_handler_disconnect (widget, gtk_sink->size_allocate_sig_handler); |
324 |
- gtk_sink->size_allocate_sig_handler = 0; |
325 |
+ if (gtk_sink->widget_resize_sig_handler) { |
326 |
+ g_signal_handler_disconnect (widget, gtk_sink->widget_resize_sig_handler); |
327 |
+ gtk_sink->widget_resize_sig_handler = 0; |
328 |
} |
329 |
|
330 |
if (gtk_sink->widget_destroy_sig_handler) { |
331 |
@@ -172,29 +183,34 @@ gst_gtk_gl_sink_start (GstBaseSink * bsink) |
332 |
gst_widget = GTK_GST_GL_WIDGET (base_sink->widget); |
333 |
|
334 |
/* Track the allocation size */ |
335 |
- gtk_sink->size_allocate_sig_handler = |
336 |
- g_signal_connect (gst_widget, "size-allocate", |
337 |
- G_CALLBACK (_size_changed_cb), gtk_sink); |
338 |
+ if (!gtk_sink->widget_resize_sig_handler) { |
339 |
+ gtk_sink->widget_resize_sig_handler = |
340 |
+ g_signal_connect (gst_widget, "resize", |
341 |
+ G_CALLBACK (_size_changed_cb), gtk_sink); |
342 |
+ } |
343 |
|
344 |
- gtk_sink->widget_destroy_sig_handler = |
345 |
- g_signal_connect (gst_widget, "destroy", G_CALLBACK (destroy_cb), |
346 |
- gtk_sink); |
347 |
+ if (!gtk_sink->widget_destroy_sig_handler) { |
348 |
+ gtk_sink->widget_destroy_sig_handler = |
349 |
+ g_signal_connect (gst_widget, "destroy", G_CALLBACK (destroy_cb), |
350 |
+ gtk_sink); |
351 |
+ } |
352 |
|
353 |
- _size_changed_cb (GTK_WIDGET (gst_widget), NULL, gtk_sink); |
354 |
- |
355 |
if (!gtk_gst_gl_widget_init_winsys (gst_widget)) { |
356 |
GST_ELEMENT_ERROR (bsink, RESOURCE, NOT_FOUND, ("%s", |
357 |
- "Failed to initialize OpenGL with Gtk"), (NULL)); |
358 |
+ "Failed to initialize OpenGL with GTK"), (NULL)); |
359 |
return FALSE; |
360 |
} |
361 |
|
362 |
- gtk_sink->display = gtk_gst_gl_widget_get_display (gst_widget); |
363 |
- gtk_sink->context = gtk_gst_gl_widget_get_context (gst_widget); |
364 |
- gtk_sink->gtk_context = gtk_gst_gl_widget_get_gtk_context (gst_widget); |
365 |
+ if (!gtk_sink->display) |
366 |
+ gtk_sink->display = gtk_gst_gl_widget_get_display (gst_widget); |
367 |
+ if (!gtk_sink->context) |
368 |
+ gtk_sink->context = gtk_gst_gl_widget_get_context (gst_widget); |
369 |
+ if (!gtk_sink->gtk_context) |
370 |
+ gtk_sink->gtk_context = gtk_gst_gl_widget_get_gtk_context (gst_widget); |
371 |
|
372 |
if (!gtk_sink->display || !gtk_sink->context || !gtk_sink->gtk_context) { |
373 |
GST_ELEMENT_ERROR (bsink, RESOURCE, NOT_FOUND, ("%s", |
374 |
- "Failed to retrieve OpenGL context from Gtk"), (NULL)); |
375 |
+ "Failed to retrieve OpenGL context from GTK"), (NULL)); |
376 |
return FALSE; |
377 |
} |
378 |
|
379 |
@@ -208,7 +224,14 @@ static gboolean |
380 |
gst_gtk_gl_sink_stop (GstBaseSink * bsink) |
381 |
{ |
382 |
GstGtkGLSink *gtk_sink = GST_GTK_GL_SINK (bsink); |
383 |
+ GstGtkBaseSink *base_sink = GST_GTK_BASE_SINK (bsink); |
384 |
|
385 |
+ if (gtk_sink->widget_resize_sig_handler) { |
386 |
+ g_signal_handler_disconnect (base_sink->widget, |
387 |
+ gtk_sink->widget_resize_sig_handler); |
388 |
+ gtk_sink->widget_resize_sig_handler = 0; |
389 |
+ } |
390 |
+ |
391 |
if (gtk_sink->display) { |
392 |
gst_object_unref (gtk_sink->display); |
393 |
gtk_sink->display = NULL; |
394 |
@@ -348,10 +371,10 @@ gst_gtk_gl_sink_finalize (GObject * object) |
395 |
GstGtkGLSink *gtk_sink = GST_GTK_GL_SINK (object); |
396 |
GstGtkBaseSink *base_sink = GST_GTK_BASE_SINK (object); |
397 |
|
398 |
- if (gtk_sink->size_allocate_sig_handler) { |
399 |
+ if (gtk_sink->widget_resize_sig_handler) { |
400 |
g_signal_handler_disconnect (base_sink->widget, |
401 |
- gtk_sink->size_allocate_sig_handler); |
402 |
- gtk_sink->size_allocate_sig_handler = 0; |
403 |
+ gtk_sink->widget_resize_sig_handler); |
404 |
+ gtk_sink->widget_resize_sig_handler = 0; |
405 |
} |
406 |
|
407 |
if (gtk_sink->widget_destroy_sig_handler) { |
408 |
--- ext/gtk/gstgtkglsink.h.orig 2019-12-03 11:06:37 UTC |
409 |
+++ ext/gtk/gstgtkglsink.h |
410 |
@@ -65,7 +65,7 @@ struct _GstGtkGLSink |
411 |
gint display_width; |
412 |
gint display_height; |
413 |
|
414 |
- gulong size_allocate_sig_handler; |
415 |
+ gulong widget_resize_sig_handler; |
416 |
gulong widget_destroy_sig_handler; |
417 |
}; |
418 |
|
419 |
--- ext/gtk/gstgtksink.c.orig 2019-12-03 11:06:37 UTC |
420 |
+++ ext/gtk/gstgtksink.c |
421 |
@@ -19,15 +19,22 @@ |
422 |
*/ |
423 |
|
424 |
/** |
425 |
- * SECTION:element-gtkgstsink |
426 |
- * @title: gtkgstsink |
427 |
+ * SECTION:element-gtksink |
428 |
+ * @title: gtksink |
429 |
* |
430 |
*/ |
431 |
|
432 |
+/** |
433 |
+ * SECTION:element-gtk4sink |
434 |
+ * @title: gtk4sink |
435 |
+ * |
436 |
+ */ |
437 |
+ |
438 |
#ifdef HAVE_CONFIG_H |
439 |
#include "config.h" |
440 |
#endif |
441 |
|
442 |
+#include "gtkconfig.h" |
443 |
#include "gtkgstwidget.h" |
444 |
#include "gstgtksink.h" |
445 |
|
446 |
@@ -49,8 +56,8 @@ GST_STATIC_PAD_TEMPLATE ("sink", |
447 |
|
448 |
#define gst_gtk_sink_parent_class parent_class |
449 |
G_DEFINE_TYPE_WITH_CODE (GstGtkSink, gst_gtk_sink, GST_TYPE_GTK_BASE_SINK, |
450 |
- GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_sink, "gtksink", 0, |
451 |
- "Gtk Video Sink")); |
452 |
+ GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_sink, GTKCONFIG_SINK, 0, |
453 |
+ GTKCONFIG_NAME " Video Sink")); |
454 |
|
455 |
static void |
456 |
gst_gtk_sink_class_init (GstGtkSinkClass * klass) |
457 |
@@ -62,9 +69,10 @@ gst_gtk_sink_class_init (GstGtkSinkClass * klass) |
458 |
base_class = (GstGtkBaseSinkClass *) klass; |
459 |
|
460 |
base_class->create_widget = gtk_gst_widget_new; |
461 |
- base_class->window_title = "Gtk+ Cairo renderer"; |
462 |
+ base_class->window_title = GTKCONFIG_NAME " Cairo Renderer"; |
463 |
|
464 |
- gst_element_class_set_metadata (gstelement_class, "Gtk Video Sink", |
465 |
+ gst_element_class_set_metadata (gstelement_class, |
466 |
+ GTKCONFIG_NAME " Video Sink", |
467 |
"Sink/Video", "A video sink that renders to a GtkWidget", |
468 |
"Matthew Waters <matthew@centricular.com>"); |
469 |
|
470 |
--- ext/gtk/gstplugin.c.orig 2019-12-03 11:06:37 UTC |
471 |
+++ ext/gtk/gstplugin.c |
472 |
@@ -1,6 +1,7 @@ |
473 |
/* |
474 |
* GStreamer |
475 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com> |
476 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
477 |
* |
478 |
* This library is free software; you can redistribute it and/or |
479 |
* modify it under the terms of the GNU Library General Public |
480 |
@@ -22,31 +23,31 @@ |
481 |
#include "config.h" |
482 |
#endif |
483 |
|
484 |
+#include "gtkconfig.h" |
485 |
#include "gstgtksink.h" |
486 |
-#if defined(HAVE_GTK3_GL) |
487 |
+ |
488 |
+#if defined(HAVE_GTK_GL) |
489 |
#include "gstgtkglsink.h" |
490 |
#endif |
491 |
|
492 |
static gboolean |
493 |
plugin_init (GstPlugin * plugin) |
494 |
{ |
495 |
- if (!gst_element_register (plugin, "gtksink", |
496 |
+ if (!gst_element_register (plugin, GTKCONFIG_SINK, |
497 |
GST_RANK_NONE, GST_TYPE_GTK_SINK)) { |
498 |
return FALSE; |
499 |
} |
500 |
-#if defined(HAVE_GTK3_GL) |
501 |
- if (!gst_element_register (plugin, "gtkglsink", |
502 |
+#if defined(HAVE_GTK_GL) |
503 |
+ if (!gst_element_register (plugin, GTKCONFIG_GLSINK, |
504 |
GST_RANK_NONE, GST_TYPE_GTK_GL_SINK)) { |
505 |
return FALSE; |
506 |
} |
507 |
#endif |
508 |
- |
509 |
return TRUE; |
510 |
} |
511 |
|
512 |
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, |
513 |
GST_VERSION_MINOR, |
514 |
- gtk, |
515 |
- "Gtk+ sink", |
516 |
+ GTKCONFIG_PLUGIN, GTKCONFIG_NAME " sink", |
517 |
plugin_init, PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME, |
518 |
GST_PACKAGE_ORIGIN) |
519 |
--- ext/gtk/gtkconfig.h.orig 2021-08-23 11:11:05 UTC |
520 |
+++ ext/gtk/gtkconfig.h |
521 |
@@ -0,0 +1,31 @@ |
522 |
+/* |
523 |
+ * GStreamer |
524 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
525 |
+ * |
526 |
+ * This library is free software; you can redistribute it and/or |
527 |
+ * modify it under the terms of the GNU Library General Public |
528 |
+ * License as published by the Free Software Foundation; either |
529 |
+ * version 2 of the License, or (at your option) any later version. |
530 |
+ * |
531 |
+ * This library is distributed in the hope that it will be useful, |
532 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
533 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
534 |
+ * Library General Public License for more details. |
535 |
+ * |
536 |
+ * You should have received a copy of the GNU Library General Public |
537 |
+ * License along with this library; if not, write to the |
538 |
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
539 |
+ * Boston, MA 02110-1301, USA. |
540 |
+ */ |
541 |
+ |
542 |
+#if defined(BUILD_FOR_GTK4) |
543 |
+#define GTKCONFIG_PLUGIN gtk4 |
544 |
+#define GTKCONFIG_NAME "GTK4" |
545 |
+#define GTKCONFIG_SINK "gtk4sink" |
546 |
+#define GTKCONFIG_GLSINK "gtk4glsink" |
547 |
+#else |
548 |
+#define GTKCONFIG_PLUGIN gtk |
549 |
+#define GTKCONFIG_NAME "GTK" |
550 |
+#define GTKCONFIG_SINK "gtksink" |
551 |
+#define GTKCONFIG_GLSINK "gtkglsink" |
552 |
+#endif |
553 |
--- ext/gtk/gtkgstbasewidget.c.orig 2019-12-03 11:06:37 UTC |
554 |
+++ ext/gtk/gtkgstbasewidget.c |
555 |
@@ -1,6 +1,7 @@ |
556 |
/* |
557 |
* GStreamer |
558 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com> |
559 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
560 |
* |
561 |
* This library is free software; you can redistribute it and/or |
562 |
* modify it under the terms of the GNU Library General Public |
563 |
@@ -74,7 +75,23 @@ gtk_gst_base_widget_get_preferred_height (GtkWidget * |
564 |
*natural = video_height; |
565 |
} |
566 |
|
567 |
+#if defined(BUILD_FOR_GTK4) |
568 |
static void |
569 |
+gtk_gst_base_widget_measure (GtkWidget * widget, GtkOrientation orientation, |
570 |
+ gint for_size, gint * min, gint * natural, |
571 |
+ gint * minimum_baseline, gint * natural_baseline) |
572 |
+{ |
573 |
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) |
574 |
+ gtk_gst_base_widget_get_preferred_width (widget, min, natural); |
575 |
+ else |
576 |
+ gtk_gst_base_widget_get_preferred_height (widget, min, natural); |
577 |
+ |
578 |
+ *minimum_baseline = -1; |
579 |
+ *natural_baseline = -1; |
580 |
+} |
581 |
+#endif |
582 |
+ |
583 |
+static void |
584 |
gtk_gst_base_widget_set_property (GObject * object, guint prop_id, |
585 |
const GValue * value, GParamSpec * pspec) |
586 |
{ |
587 |
@@ -235,22 +252,46 @@ _gdk_key_to_navigation_string (guint keyval) |
588 |
} |
589 |
} |
590 |
|
591 |
+static GdkEvent * |
592 |
+_get_current_event (GtkEventController * controller) |
593 |
+{ |
594 |
+#if defined(BUILD_FOR_GTK4) |
595 |
+ return gtk_event_controller_get_current_event (controller); |
596 |
+#else |
597 |
+ return gtk_get_current_event (); |
598 |
+#endif |
599 |
+} |
600 |
+ |
601 |
+static void |
602 |
+_gdk_event_free (GdkEvent * event) |
603 |
+{ |
604 |
+#if !defined(BUILD_FOR_GTK4) |
605 |
+ if (event) |
606 |
+ gdk_event_free (event); |
607 |
+#endif |
608 |
+} |
609 |
+ |
610 |
static gboolean |
611 |
-gtk_gst_base_widget_key_event (GtkWidget * widget, GdkEventKey * event) |
612 |
+gtk_gst_base_widget_key_event (GtkEventControllerKey * key_controller, |
613 |
+ guint keyval, guint keycode, GdkModifierType state) |
614 |
{ |
615 |
+ GtkEventController *controller = GTK_EVENT_CONTROLLER (key_controller); |
616 |
+ GtkWidget *widget = gtk_event_controller_get_widget (controller); |
617 |
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget); |
618 |
GstElement *element; |
619 |
|
620 |
if ((element = g_weak_ref_get (&base_widget->element))) { |
621 |
if (GST_IS_NAVIGATION (element)) { |
622 |
- const gchar *str = _gdk_key_to_navigation_string (event->keyval); |
623 |
- const gchar *key_type = |
624 |
- event->type == GDK_KEY_PRESS ? "key-press" : "key-release"; |
625 |
+ GdkEvent *event = _get_current_event (controller); |
626 |
+ const gchar *str = _gdk_key_to_navigation_string (keyval); |
627 |
|
628 |
- if (!str) |
629 |
- str = event->string; |
630 |
- |
631 |
- gst_navigation_send_key_event (GST_NAVIGATION (element), key_type, str); |
632 |
+ if (str) { |
633 |
+ const gchar *key_type = |
634 |
+ gdk_event_get_event_type (event) == |
635 |
+ GDK_KEY_PRESS ? "key-press" : "key-release"; |
636 |
+ gst_navigation_send_key_event (GST_NAVIGATION (element), key_type, str); |
637 |
+ } |
638 |
+ _gdk_event_free (event); |
639 |
} |
640 |
g_object_unref (element); |
641 |
} |
642 |
@@ -325,22 +366,43 @@ _display_size_to_stream_size (GtkGstBaseWidget * base_ |
643 |
} |
644 |
|
645 |
static gboolean |
646 |
-gtk_gst_base_widget_button_event (GtkWidget * widget, GdkEventButton * event) |
647 |
+gtk_gst_base_widget_button_event ( |
648 |
+#if defined(BUILD_FOR_GTK4) |
649 |
+ GtkGestureClick * gesture, |
650 |
+#else |
651 |
+ GtkGestureMultiPress * gesture, |
652 |
+#endif |
653 |
+ gint n_press, gdouble x, gdouble y) |
654 |
{ |
655 |
+ GtkEventController *controller = GTK_EVENT_CONTROLLER (gesture); |
656 |
+ GtkWidget *widget = gtk_event_controller_get_widget (controller); |
657 |
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget); |
658 |
GstElement *element; |
659 |
|
660 |
if ((element = g_weak_ref_get (&base_widget->element))) { |
661 |
if (GST_IS_NAVIGATION (element)) { |
662 |
+ GdkEvent *event = _get_current_event (controller); |
663 |
const gchar *key_type = |
664 |
- event->type == |
665 |
- GDK_BUTTON_PRESS ? "mouse-button-press" : "mouse-button-release"; |
666 |
- gdouble x, y; |
667 |
+ gdk_event_get_event_type (event) == GDK_BUTTON_PRESS |
668 |
+ ? "mouse-button-press" : "mouse-button-release"; |
669 |
+ gdouble stream_x, stream_y; |
670 |
+#if !defined(BUILD_FOR_GTK4) |
671 |
+ guint button; |
672 |
+ gdk_event_get_button (event, &button); |
673 |
+#endif |
674 |
|
675 |
- _display_size_to_stream_size (base_widget, event->x, event->y, &x, &y); |
676 |
+ _display_size_to_stream_size (base_widget, x, y, &stream_x, &stream_y); |
677 |
|
678 |
gst_navigation_send_mouse_event (GST_NAVIGATION (element), key_type, |
679 |
- event->button, x, y); |
680 |
+#if defined(BUILD_FOR_GTK4) |
681 |
+ /* Gesture is set to ignore other buttons so we do not have to check */ |
682 |
+ GDK_BUTTON_PRIMARY, |
683 |
+#else |
684 |
+ button, |
685 |
+#endif |
686 |
+ stream_x, stream_y); |
687 |
+ |
688 |
+ _gdk_event_free (event); |
689 |
} |
690 |
g_object_unref (element); |
691 |
} |
692 |
@@ -349,19 +411,22 @@ gtk_gst_base_widget_button_event (GtkWidget * widget, |
693 |
} |
694 |
|
695 |
static gboolean |
696 |
-gtk_gst_base_widget_motion_event (GtkWidget * widget, GdkEventMotion * event) |
697 |
+gtk_gst_base_widget_motion_event (GtkEventControllerMotion * motion_controller, |
698 |
+ gdouble x, gdouble y) |
699 |
{ |
700 |
+ GtkEventController *controller = GTK_EVENT_CONTROLLER (motion_controller); |
701 |
+ GtkWidget *widget = gtk_event_controller_get_widget (controller); |
702 |
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget); |
703 |
GstElement *element; |
704 |
|
705 |
if ((element = g_weak_ref_get (&base_widget->element))) { |
706 |
if (GST_IS_NAVIGATION (element)) { |
707 |
- gdouble x, y; |
708 |
+ gdouble stream_x, stream_y; |
709 |
|
710 |
- _display_size_to_stream_size (base_widget, event->x, event->y, &x, &y); |
711 |
+ _display_size_to_stream_size (base_widget, x, y, &stream_x, &stream_y); |
712 |
|
713 |
gst_navigation_send_mouse_event (GST_NAVIGATION (element), "mouse-move", |
714 |
- 0, x, y); |
715 |
+ 0, stream_x, stream_y); |
716 |
} |
717 |
g_object_unref (element); |
718 |
} |
719 |
@@ -395,23 +460,20 @@ gtk_gst_base_widget_class_init (GtkGstBaseWidgetClass |
720 |
"When enabled, alpha will be ignored and converted to black", |
721 |
DEFAULT_IGNORE_ALPHA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
722 |
|
723 |
+#if defined(BUILD_FOR_GTK4) |
724 |
+ widget_klass->measure = gtk_gst_base_widget_measure; |
725 |
+#else |
726 |
widget_klass->get_preferred_width = gtk_gst_base_widget_get_preferred_width; |
727 |
widget_klass->get_preferred_height = gtk_gst_base_widget_get_preferred_height; |
728 |
- widget_klass->key_press_event = gtk_gst_base_widget_key_event; |
729 |
- widget_klass->key_release_event = gtk_gst_base_widget_key_event; |
730 |
- widget_klass->button_press_event = gtk_gst_base_widget_button_event; |
731 |
- widget_klass->button_release_event = gtk_gst_base_widget_button_event; |
732 |
- widget_klass->motion_notify_event = gtk_gst_base_widget_motion_event; |
733 |
+#endif |
734 |
|
735 |
GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_base_widget, "gtkbasewidget", 0, |
736 |
- "Gtk Video Base Widget"); |
737 |
+ "GTK Video Base Widget"); |
738 |
} |
739 |
|
740 |
void |
741 |
gtk_gst_base_widget_init (GtkGstBaseWidget * widget) |
742 |
{ |
743 |
- int event_mask; |
744 |
- |
745 |
widget->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO; |
746 |
widget->par_n = DEFAULT_PAR_N; |
747 |
widget->par_d = DEFAULT_PAR_D; |
748 |
@@ -423,20 +485,66 @@ gtk_gst_base_widget_init (GtkGstBaseWidget * widget) |
749 |
g_weak_ref_init (&widget->element, NULL); |
750 |
g_mutex_init (&widget->lock); |
751 |
|
752 |
+ widget->key_controller = gtk_event_controller_key_new ( |
753 |
+#if !defined(BUILD_FOR_GTK4) |
754 |
+ GTK_WIDGET (widget) |
755 |
+#endif |
756 |
+ ); |
757 |
+ g_signal_connect (widget->key_controller, "key-pressed", |
758 |
+ G_CALLBACK (gtk_gst_base_widget_key_event), NULL); |
759 |
+ g_signal_connect (widget->key_controller, "key-released", |
760 |
+ G_CALLBACK (gtk_gst_base_widget_key_event), NULL); |
761 |
+ |
762 |
+ widget->motion_controller = gtk_event_controller_motion_new ( |
763 |
+#if !defined(BUILD_FOR_GTK4) |
764 |
+ GTK_WIDGET (widget) |
765 |
+#endif |
766 |
+ ); |
767 |
+ g_signal_connect (widget->motion_controller, "motion", |
768 |
+ G_CALLBACK (gtk_gst_base_widget_motion_event), NULL); |
769 |
+ |
770 |
+ widget->click_gesture = |
771 |
+#if defined(BUILD_FOR_GTK4) |
772 |
+ gtk_gesture_click_new (); |
773 |
+#else |
774 |
+ gtk_gesture_multi_press_new (GTK_WIDGET (widget)); |
775 |
+#endif |
776 |
+ g_signal_connect (widget->click_gesture, "pressed", |
777 |
+ G_CALLBACK (gtk_gst_base_widget_button_event), NULL); |
778 |
+ g_signal_connect (widget->click_gesture, "released", |
779 |
+ G_CALLBACK (gtk_gst_base_widget_button_event), NULL); |
780 |
+ |
781 |
+#if defined(BUILD_FOR_GTK4) |
782 |
+ /* Otherwise widget in grid will appear as a 1x1px |
783 |
+ * video which might be misleading for users */ |
784 |
+ gtk_widget_set_hexpand (GTK_WIDGET (widget), TRUE); |
785 |
+ gtk_widget_set_vexpand (GTK_WIDGET (widget), TRUE); |
786 |
+ |
787 |
+ gtk_widget_set_focusable (GTK_WIDGET (widget), TRUE); |
788 |
+ gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (widget->click_gesture), |
789 |
+ GDK_BUTTON_PRIMARY); |
790 |
+ |
791 |
+ gtk_widget_add_controller (GTK_WIDGET (widget), widget->key_controller); |
792 |
+ gtk_widget_add_controller (GTK_WIDGET (widget), widget->motion_controller); |
793 |
+ gtk_widget_add_controller (GTK_WIDGET (widget), |
794 |
+ GTK_EVENT_CONTROLLER (widget->click_gesture)); |
795 |
+#endif |
796 |
+ |
797 |
gtk_widget_set_can_focus (GTK_WIDGET (widget), TRUE); |
798 |
- event_mask = gtk_widget_get_events (GTK_WIDGET (widget)); |
799 |
- event_mask |= GDK_KEY_PRESS_MASK |
800 |
- | GDK_KEY_RELEASE_MASK |
801 |
- | GDK_BUTTON_PRESS_MASK |
802 |
- | GDK_BUTTON_RELEASE_MASK |
803 |
- | GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK; |
804 |
- gtk_widget_set_events (GTK_WIDGET (widget), event_mask); |
805 |
} |
806 |
|
807 |
void |
808 |
gtk_gst_base_widget_finalize (GObject * object) |
809 |
{ |
810 |
GtkGstBaseWidget *widget = GTK_GST_BASE_WIDGET (object); |
811 |
+ |
812 |
+ /* GTK4 takes ownership of EventControllers |
813 |
+ * while GTK3 still needs manual unref */ |
814 |
+#if !defined(BUILD_FOR_GTK4) |
815 |
+ g_object_unref (widget->key_controller); |
816 |
+ g_object_unref (widget->motion_controller); |
817 |
+ g_object_unref (widget->click_gesture); |
818 |
+#endif |
819 |
|
820 |
gst_buffer_replace (&widget->pending_buffer, NULL); |
821 |
gst_buffer_replace (&widget->buffer, NULL); |
822 |
--- ext/gtk/gtkgstbasewidget.h.orig 2019-12-03 11:06:37 UTC |
823 |
+++ ext/gtk/gtkgstbasewidget.h |
824 |
@@ -1,6 +1,7 @@ |
825 |
/* |
826 |
* GStreamer |
827 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com> |
828 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
829 |
* |
830 |
* This library is free software; you can redistribute it and/or |
831 |
* modify it under the terms of the GNU Library General Public |
832 |
@@ -25,6 +26,10 @@ |
833 |
#include <gst/gst.h> |
834 |
#include <gst/video/video.h> |
835 |
|
836 |
+#if !defined(BUILD_FOR_GTK4) |
837 |
+#include <gdk/gdk.h> |
838 |
+#endif |
839 |
+ |
840 |
#define GTK_GST_BASE_WIDGET(w) ((GtkGstBaseWidget *)(w)) |
841 |
#define GTK_GST_BASE_WIDGET_CLASS(k) ((GtkGstBaseWidgetClass *)(k)) |
842 |
#define GTK_GST_BASE_WIDGET_LOCK(w) g_mutex_lock(&((GtkGstBaseWidget*)(w))->lock) |
843 |
@@ -39,9 +44,7 @@ struct _GtkGstBaseWidget |
844 |
{ |
845 |
union { |
846 |
GtkDrawingArea drawing_area; |
847 |
-#if GTK_CHECK_VERSION(3, 15, 0) |
848 |
GtkGLArea gl_area; |
849 |
-#endif |
850 |
} parent; |
851 |
|
852 |
/* properties */ |
853 |
@@ -67,6 +70,11 @@ struct _GtkGstBaseWidget |
854 |
GMutex lock; |
855 |
GWeakRef element; |
856 |
|
857 |
+ /* event controllers */ |
858 |
+ GtkEventController *key_controller; |
859 |
+ GtkEventController *motion_controller; |
860 |
+ GtkGesture *click_gesture; |
861 |
+ |
862 |
/* Pending draw idles callback */ |
863 |
guint draw_id; |
864 |
}; |
865 |
@@ -75,9 +83,7 @@ struct _GtkGstBaseWidgetClass |
866 |
{ |
867 |
union { |
868 |
GtkDrawingAreaClass drawing_area_class; |
869 |
-#if GTK_CHECK_VERSION(3, 15, 0) |
870 |
GtkGLAreaClass gl_area_class; |
871 |
-#endif |
872 |
} parent_class; |
873 |
}; |
874 |
|
875 |
--- ext/gtk/gtkgstglwidget.c.orig 2019-12-03 11:06:37 UTC |
876 |
+++ ext/gtk/gtkgstglwidget.c |
877 |
@@ -1,6 +1,7 @@ |
878 |
/* |
879 |
* GStreamer |
880 |
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com> |
881 |
+ * Copyright (C) 2020 Rafał Dzięgiel <rafostar.github@gmail.com> |
882 |
* |
883 |
* This library is free software; you can redistribute it and/or |
884 |
* modify it under the terms of the GNU Library General Public |
885 |
@@ -30,12 +31,20 @@ |
886 |
#include <gst/video/video.h> |
887 |
|
888 |
#if GST_GL_HAVE_WINDOW_X11 && defined (GDK_WINDOWING_X11) |
889 |
+#if defined(BUILD_FOR_GTK4) |
890 |
+#include <gdk/x11/gdkx.h> |
891 |
+#else |
892 |
#include <gdk/gdkx.h> |
893 |
+#endif |
894 |
#include <gst/gl/x11/gstgldisplay_x11.h> |
895 |
#endif |
896 |
|
897 |
#if GST_GL_HAVE_WINDOW_WAYLAND && defined (GDK_WINDOWING_WAYLAND) |
898 |
+#if defined(BUILD_FOR_GTK4) |
899 |
+#include <gdk/wayland/gdkwayland.h> |
900 |
+#else |
901 |
#include <gdk/gdkwayland.h> |
902 |
+#endif |
903 |
#include <gst/gl/wayland/gstgldisplay_wayland.h> |
904 |
#endif |
905 |
|
906 |
@@ -78,8 +87,7 @@ static const GLfloat vertices[] = { |
907 |
G_DEFINE_TYPE_WITH_CODE (GtkGstGLWidget, gtk_gst_gl_widget, GTK_TYPE_GL_AREA, |
908 |
G_ADD_PRIVATE (GtkGstGLWidget) |
909 |
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gtkgstglwidget", 0, |
910 |
- "Gtk Gst GL Widget"); |
911 |
- ); |
912 |
+ "GTK Gst GL Widget")); |
913 |
|
914 |
static void |
915 |
gtk_gst_gl_widget_bind_buffer (GtkGstGLWidget * gst_widget) |
916 |
@@ -407,8 +415,11 @@ gtk_gst_gl_widget_init (GtkGstGLWidget * gst_widget) |
917 |
|
918 |
GST_INFO ("Created %" GST_PTR_FORMAT, priv->display); |
919 |
|
920 |
+ /* GTK4 always has alpha */ |
921 |
+#if !defined(BUILD_FOR_GTK4) |
922 |
gtk_gl_area_set_has_alpha (GTK_GL_AREA (gst_widget), |
923 |
!base_widget->ignore_alpha); |
924 |
+#endif |
925 |
} |
926 |
|
927 |
static void |
928 |
--- ext/gtk/gtkgstwidget.c.orig 2019-12-03 11:06:37 UTC |
929 |
+++ ext/gtk/gtkgstwidget.c |
930 |
@@ -38,17 +38,15 @@ |
931 |
|
932 |
G_DEFINE_TYPE (GtkGstWidget, gtk_gst_widget, GTK_TYPE_DRAWING_AREA); |
933 |
|
934 |
-static gboolean |
935 |
-gtk_gst_widget_draw (GtkWidget * widget, cairo_t * cr) |
936 |
+static void |
937 |
+_drawing_area_draw (GtkDrawingArea * da, cairo_t * cr, |
938 |
+ gint widget_width, gint widget_height, gpointer data) |
939 |
{ |
940 |
+ GtkWidget *widget = GTK_WIDGET (da); |
941 |
GtkGstBaseWidget *gst_widget = (GtkGstBaseWidget *) widget; |
942 |
- guint widget_width, widget_height; |
943 |
cairo_surface_t *surface; |
944 |
GstVideoFrame frame; |
945 |
|
946 |
- widget_width = gtk_widget_get_allocated_width (widget); |
947 |
- widget_height = gtk_widget_get_allocated_height (widget); |
948 |
- |
949 |
GTK_GST_BASE_WIDGET_LOCK (gst_widget); |
950 |
|
951 |
/* There is not much to optimize in term of redisplay, so simply swap the |
952 |
@@ -148,7 +146,10 @@ gtk_gst_widget_draw (GtkWidget * widget, cairo_t * cr) |
953 |
color.alpha = 1.0; |
954 |
} else { |
955 |
gtk_style_context_get_color (gtk_widget_get_style_context (widget), |
956 |
- GTK_STATE_FLAG_NORMAL, &color); |
957 |
+#if !defined(BUILD_FOR_GTK4) |
958 |
+ GTK_STATE_FLAG_NORMAL, |
959 |
+#endif |
960 |
+ &color); |
961 |
} |
962 |
gdk_cairo_set_source_rgba (cr, &color); |
963 |
cairo_rectangle (cr, 0, 0, widget_width, widget_height); |
964 |
@@ -156,8 +157,20 @@ gtk_gst_widget_draw (GtkWidget * widget, cairo_t * cr) |
965 |
} |
966 |
|
967 |
GTK_GST_BASE_WIDGET_UNLOCK (gst_widget); |
968 |
+} |
969 |
+ |
970 |
+#if !defined(BUILD_FOR_GTK4) |
971 |
+static gboolean |
972 |
+gtk_gst_widget_draw (GtkWidget * widget, cairo_t * cr) |
973 |
+{ |
974 |
+ gint width = gtk_widget_get_allocated_width (widget); |
975 |
+ gint height = gtk_widget_get_allocated_height (widget); |
976 |
+ |
977 |
+ _drawing_area_draw (GTK_DRAWING_AREA (widget), cr, width, height, NULL); |
978 |
+ |
979 |
return FALSE; |
980 |
} |
981 |
+#endif |
982 |
|
983 |
static void |
984 |
gtk_gst_widget_finalize (GObject * object) |
985 |
@@ -171,17 +184,25 @@ static void |
986 |
gtk_gst_widget_class_init (GtkGstWidgetClass * klass) |
987 |
{ |
988 |
GObjectClass *gobject_klass = (GObjectClass *) klass; |
989 |
+#if !defined(BUILD_FOR_GTK4) |
990 |
GtkWidgetClass *widget_klass = (GtkWidgetClass *) klass; |
991 |
+#endif |
992 |
|
993 |
gtk_gst_base_widget_class_init (GTK_GST_BASE_WIDGET_CLASS (klass)); |
994 |
gobject_klass->finalize = gtk_gst_widget_finalize; |
995 |
+#if !defined(BUILD_FOR_GTK4) |
996 |
widget_klass->draw = gtk_gst_widget_draw; |
997 |
+#endif |
998 |
} |
999 |
|
1000 |
static void |
1001 |
gtk_gst_widget_init (GtkGstWidget * widget) |
1002 |
{ |
1003 |
gtk_gst_base_widget_init (GTK_GST_BASE_WIDGET (widget)); |
1004 |
+#if defined(BUILD_FOR_GTK4) |
1005 |
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (widget), |
1006 |
+ _drawing_area_draw, NULL, NULL); |
1007 |
+#endif |
1008 |
} |
1009 |
|
1010 |
GtkWidget * |
1011 |
--- ext/gtk/meson.build.orig 2019-12-03 11:06:37 UTC |
1012 |
+++ ext/gtk/meson.build |
1013 |
@@ -1,3 +1,4 @@ |
1014 |
+gtk_versions = [3, 4] |
1015 |
gtk_sources = [ |
1016 |
'gstgtkbasesink.c', |
1017 |
'gstgtksink.c', |
1018 |
@@ -6,52 +7,86 @@ gtk_sources = [ |
1019 |
'gtkgstbasewidget.c', |
1020 |
'gtkgstwidget.c', |
1021 |
] |
1022 |
+gtk_dep = dependency('gtk+-3.0', required : get_option('gtk3')) |
1023 |
+gtk_optional_deps = [] |
1024 |
|
1025 |
-gtk_defines = [] |
1026 |
-optional_deps = [] |
1027 |
+gtk4_dep = dependency('gtk4', required : get_option('gtk4')) |
1028 |
+gtk4_optional_deps = [] |
1029 |
|
1030 |
-gtk_dep = dependency('gtk+-3.0', required : get_option('gtk3')) |
1031 |
-if gtk_dep.found() |
1032 |
- if build_gstgl and gstgl_dep.found() and gtk_dep.version().version_compare('>=3.15.0') |
1033 |
- have_gtk3_gl_windowing = false |
1034 |
+foreach gtk_ver : gtk_versions |
1035 |
+ gtkv = 'gtk' + gtk_ver.to_string() |
1036 |
|
1037 |
+ gtk_state = get_option(gtkv) |
1038 |
+ if gtk_state.disabled() |
1039 |
+ continue |
1040 |
+ endif |
1041 |
+ |
1042 |
+ min_ver = gtk_ver >= 4 ? '3.99.2' : '3.24.0' |
1043 |
+ x11_str = gtk_ver >= 4 ? gtkv + '-x11' : 'gtk+-x11-3.0' |
1044 |
+ way_str = gtk_ver >= 4 ? gtkv + '-wayland' : 'gtk+-wayland-3.0' |
1045 |
+ lib_dep = gtk_ver >= 4 ? gtk4_dep : gtk_dep |
1046 |
+ |
1047 |
+ if not lib_dep.found() or not lib_dep.version().version_compare('>=' + min_ver) |
1048 |
+ continue |
1049 |
+ endif |
1050 |
+ |
1051 |
+ lib_sources = [] |
1052 |
+ gtk_defines = [] |
1053 |
+ optional_deps = [] |
1054 |
+ have_gtk_gl_windowing = false |
1055 |
+ |
1056 |
+ lib_sources += gtk_sources |
1057 |
+ |
1058 |
+ if build_gstgl |
1059 |
if gst_gl_have_window_x11 and gst_gl_have_platform_glx |
1060 |
# FIXME: automagic |
1061 |
- gtk_x11_dep = dependency('gtk+-x11-3.0', required : false) |
1062 |
+ gtk_x11_dep = dependency(x11_str, required : false) |
1063 |
if gtk_x11_dep.found() |
1064 |
optional_deps += gtk_x11_dep |
1065 |
- have_gtk3_gl_windowing = true |
1066 |
+ have_gtk_gl_windowing = true |
1067 |
endif |
1068 |
endif |
1069 |
|
1070 |
if gst_gl_have_window_wayland and gst_gl_have_platform_egl |
1071 |
# FIXME: automagic |
1072 |
- gtk_wayland_dep = dependency('gtk+-wayland-3.0', required : false) |
1073 |
+ gtk_wayland_dep = dependency(way_str, required : false) |
1074 |
if gtk_wayland_dep.found() |
1075 |
optional_deps += gtk_wayland_dep |
1076 |
- have_gtk3_gl_windowing = true |
1077 |
+ have_gtk_gl_windowing = true |
1078 |
endif |
1079 |
endif |
1080 |
+ endif |
1081 |
|
1082 |
- if have_gtk3_gl_windowing |
1083 |
- gtk_sources += [ |
1084 |
- 'gstgtkglsink.c', |
1085 |
- 'gtkgstglwidget.c', |
1086 |
- ] |
1087 |
- optional_deps += gstgl_dep |
1088 |
- gtk_defines += ['-DGST_USE_UNSTABLE_API', '-DHAVE_GTK3_GL'] |
1089 |
- endif |
1090 |
+ if have_gtk_gl_windowing |
1091 |
+ lib_sources += [ |
1092 |
+ 'gstgtkglsink.c', |
1093 |
+ 'gtkgstglwidget.c', |
1094 |
+ ] |
1095 |
+ optional_deps += gstgl_dep |
1096 |
+ gtk_defines += ['-DGST_USE_UNSTABLE_API', '-DHAVE_GTK_GL'] |
1097 |
endif |
1098 |
|
1099 |
- gstgtk = library('gstgtk', |
1100 |
- gtk_sources, |
1101 |
+ if gtk_ver == 3 |
1102 |
+ gtk_optional_deps = optional_deps |
1103 |
+ elif gtk_ver == 4 |
1104 |
+ gtk4_optional_deps = optional_deps |
1105 |
+ gtk_defines += '-DBUILD_FOR_GTK4' |
1106 |
+ endif |
1107 |
+ |
1108 |
+ lib_name = 'gstgtk' |
1109 |
+ if gtk_ver > 3 |
1110 |
+ lib_name += gtk_ver.to_string() |
1111 |
+ endif |
1112 |
+ |
1113 |
+ gstgtk = library(lib_name, |
1114 |
+ lib_sources, |
1115 |
c_args : gst_plugins_good_args + gtk_defines, |
1116 |
link_args : noseh_link_args, |
1117 |
include_directories : [configinc], |
1118 |
- dependencies : [gtk_dep, gstvideo_dep, gstbase_dep, libm] + optional_deps, |
1119 |
+ dependencies : [lib_dep, gstvideo_dep, gstbase_dep, libm] + optional_deps, |
1120 |
install : true, |
1121 |
install_dir : plugins_install_dir, |
1122 |
) |
1123 |
pkgconfig.generate(gstgtk, install_dir : plugins_pkgconfig_install_dir) |
1124 |
-endif |
1125 |
+endforeach |
1126 |
|
1127 |
--- meson_options.txt.orig 2019-12-03 11:06:37 UTC |
1128 |
+++ meson_options.txt |
1129 |
@@ -53,6 +53,7 @@ option('dv1394', type : 'feature', value : 'auto', des |
1130 |
option('flac', type : 'feature', value : 'auto', description : 'FLAC audio codec plugin') |
1131 |
option('gdk-pixbuf', type : 'feature', value : 'auto', description : 'gdk-pixbuf image decoder, overlay, and sink plugin') |
1132 |
option('gtk3', type : 'feature', value : 'auto', description : 'GTK+ video sink plugin') |
1133 |
+option('gtk4', type : 'feature', value : 'disabled', description : 'GTK4 video sink plugin') |
1134 |
option('jack', type : 'feature', value : 'auto', description : 'JACK audio source/sink plugin') |
1135 |
option('jpeg', type : 'feature', value : 'auto', description : 'JPEG image codec plugin') |
1136 |
option('lame', type : 'feature', value : 'auto', description : 'LAME mp3 audio encoder plugin') |
1137 |
--- tests/examples/gtk/meson.build.orig 2019-12-03 11:06:37 UTC |
1138 |
+++ tests/examples/gtk/meson.build |
1139 |
@@ -1,5 +1,5 @@ |
1140 |
executable('gtksink', 'gtksink.c', |
1141 |
- dependencies: [gst_dep, gtk_dep, optional_deps], |
1142 |
+ dependencies: [gst_dep, gtk_dep, gtk_optional_deps], |
1143 |
c_args: gst_plugins_good_args, |
1144 |
include_directories: [configinc], |
1145 |
install: false) |