[gnome-boxes/dont-crash-screenshots-with-gl-gnome-3-32] spice-display: Don't crash when taking screenshots with GL



commit b81450ab5ed77448e966610563158ab9dac10f2f
Author: Felipe Borges <felipeborges gnome org>
Date:   Fri May 24 15:36:33 2019 +0200

    spice-display: Don't crash when taking screenshots with GL
    
    Boxes crashes when taking screenshots (calling spice_display_get_pixbuf ()
    when GL (virgl) is enabled. This is a known Mesa issue, reported
    at https://bugs.freedesktop.org/106811
    
    This fix takes screenshots "client-side", in the widget, instead of
    asking spice-gtk for a pixbuf (that causes the crash for virgl). That is
    not a permanent fix because screenshot in the client-side implies that the
    screenshot is going to have the dimensions and aspect ration of the display
    widget (consequently the Boxes window).
    
    This commit should be reverted once the issues above are fixed and
    shipped to users.
    
    The issue has been initially reported as #311. Fixes #360 also.
    
    Fixes #397
    
    Cherry-picked from 6648a731c749b9aeb1279aa1b671968d5a6139d5

 src/spice-display.vala | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 1f98e744..6996dd35 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -200,9 +200,28 @@ public override void set_enable_audio (bool enable) {
         if (!display.ready)
             return null;
 
+        /* FIXME: This is a temporary workaround for a mesa issue that causes
+         * Boxes to crash when calling spice_display_get_pixbuf ();
+         * See https://bugs.freedesktop.org/106811 */
+        if ((machine as LibvirtMachine).acceleration_3d) {
+            return draw_pixbuf_client_side (display);
+        }
+
         return display.get_pixbuf ();
     }
 
+    private Gdk.Pixbuf draw_pixbuf_client_side (Spice.Display display) {
+        Gtk.Allocation alloc;
+        var widget = display as Gtk.Widget;
+        widget.get_allocation (out alloc);
+
+        var surface = new Cairo.ImageSurface (ARGB32, alloc.width, alloc.height);
+        var context = new Cairo.Context (surface);
+        widget.draw (context);
+
+        return Gdk.pixbuf_get_from_surface (surface, 0, 0, alloc.width, alloc.height);
+    }
+
     public override void collect_logs (StringBuilder builder) {
         builder.append_printf ("URL: %s\n", uri);
         if (gtk_session != null) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]