[gnome-mahjongg] game-view.vala: Avoid reloading the entire SVG theme file on each draw operation



commit d5bfc44392dddffc433d2ac7156716776df01941
Author: Alberto Ruiz <aruiz gnome org>
Date:   Fri Oct 4 00:31:45 2019 +0100

    game-view.vala: Avoid reloading the entire SVG theme file on each draw operation

 src/game-view.vala | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/src/game-view.vala b/src/game-view.vala
index c04802b..2024525 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -14,6 +14,7 @@ public class GameView : Gtk.DrawingArea
     private Cairo.Pattern? tile_pattern = null;
     private int tile_pattern_width = 0;
     private int tile_pattern_height = 0;
+    private Rsvg.Handle? theme_handle = null;
 
     private int x_offset;
     private int y_offset;
@@ -39,7 +40,7 @@ public class GameView : Gtk.DrawingArea
     public string? theme
     {
         get { return _theme; }
-        set { _theme = value; tile_pattern = null; queue_draw (); }
+        set { _theme = value; tile_pattern = null; theme_handle = null; queue_draw (); }
     }
 
     public GameView ()
@@ -142,12 +143,14 @@ public class GameView : Gtk.DrawingArea
     {
         try
         {
-            var h = new Rsvg.Handle.from_file (theme);
+            if (theme_handle == null) {
+                theme_handle = new Rsvg.Handle.from_file (theme);
+            };
 
             var m = Cairo.Matrix.identity ();
-            m.scale ((double) width / h.width, (double) height / h.height);
+            m.scale ((double) width / theme_handle.width, (double) height / theme_handle.height);
             c.set_matrix (m);
-            h.render_cairo (c);
+            theme_handle.render_cairo (c);
 
             return;
         }


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