[Spice-devel] [PATCH v3 spice-gtk 2/2] Gstreamer: fix window resize when using GstVideoOverlay

Snir Sheriber ssheribe at redhat.com
Thu Jan 3 13:22:37 UTC 2019


With previous patch changes it's now possible to call GstVideoOverlay
interface functions in response to matching gtk events. This patch fixes
the window resize and possibly other rendering issues.

Signed-off-by: Snir Sheriber <ssheribe at redhat.com>
---
 src/spice-widget.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/spice-widget.c b/src/spice-widget.c
index e78fab4..3ff5be9 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -120,6 +120,10 @@ static void size_allocate(GtkWidget *widget, GtkAllocation *conf, gpointer data)
 static gboolean draw_event(GtkWidget *widget, cairo_t *cr, gpointer data);
 static void update_size_request(SpiceDisplay *display);
 static GdkDevice *spice_gdk_window_get_pointing_device(GdkWindow *window);
+#ifdef HAVE_GSTVIDEO
+static void gst_size_allocate(GtkWidget *widget, GdkRectangle *a, gpointer data);
+static gboolean gst_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data);
+#endif
 
 /* ---------------------------------------------------------------- */
 
@@ -649,8 +653,14 @@ static void spice_display_init(SpiceDisplay *display)
                      NULL);
     gtk_stack_add_named(d->stack, area, "gl-area");
 #endif
+#ifdef HAVE_GSTVIDEO
     area = gtk_drawing_area_new();
     gtk_stack_add_named(d->stack, area, "gst-area");
+    g_object_connect(area,
+                     "signal::draw", gst_draw_event, display,
+                     "signal::size-allocate", gst_size_allocate, display,
+                     NULL);
+#endif
 
     gtk_widget_show_all(widget);
 
@@ -2582,6 +2592,38 @@ static void gst_sync_bus_call(GstBus *bus, GstMessage *msg, SpiceDisplay *displa
 }
 #endif
 
+#ifdef HAVE_GSTVIDEO
+static gboolean gst_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
+{
+    SpiceDisplay *display = SPICE_DISPLAY(data);
+    SpiceDisplayPrivate *d = display->priv;
+    GstVideoOverlay *overlay = g_weak_ref_get(&d->overlay_weak_ref);
+
+    if (overlay) {
+        gst_video_overlay_expose(overlay);
+        gst_object_unref(overlay);
+        update_mouse_pointer(display);
+        return true;
+    }
+    return false;
+}
+
+void gst_size_allocate(GtkWidget *widget, GdkRectangle *a, gpointer data)
+{
+    SpiceDisplay *display = SPICE_DISPLAY(data);
+    SpiceDisplayPrivate *d = display->priv;
+    GstVideoOverlay *overlay = g_weak_ref_get(&d->overlay_weak_ref);
+
+    if (overlay) {
+        gint scale = gtk_widget_get_scale_factor(widget);
+
+        gst_video_overlay_set_render_rectangle(overlay, a->x * scale, a->y * scale,
+                                               a->width * scale, a->height * scale);
+        gst_object_unref(overlay);
+    }
+}
+#endif
+
 /* This callback should pass to the widget a pointer of the pipeline
  * so that we can set pipeline and overlay related calls from here.
  */
-- 
2.19.1



More information about the Spice-devel mailing list