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



commit 6648a731c749b9aeb1279aa1b671968d5a6139d5
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.

 src/spice-display.vala | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/src/spice-display.vala b/src/spice-display.vala
index f55503fb..40afdab1 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -193,9 +193,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]