[gtk/gtk-3-24: 2/3] Limit corner mask cache



commit 18f56ddf53058600a7829da020ea1da2e937c46e
Author: Luca Bacci <luca bacci982 gmail com>
Date:   Sun Jun 21 13:34:22 2020 +0200

    Limit corner mask cache
    
    Fixes issue #2853

 gtk/gtkcssshadowvalue.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 8e3b52d3c0..074ef2b909 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -32,6 +32,8 @@
 #include <math.h>
 #include <float.h>
 
+#define CORNER_MASK_CACHE_MAX_SIZE 2000U
+
 struct _GtkCssValue {
   GTK_CSS_VALUE_BASE
   guint inset :1;
@@ -840,6 +842,17 @@ draw_shadow_corner (const GtkCssValue   *shadow,
       cairo_fill (mask_cr);
       _gtk_cairo_blur_surface (mask, radius, GTK_BLUR_X | GTK_BLUR_Y);
       cairo_destroy (mask_cr);
+
+      if (g_hash_table_size (corner_mask_cache) >= CORNER_MASK_CACHE_MAX_SIZE)
+        {
+          GHashTableIter iter;
+          guint i = 0;
+
+          g_hash_table_iter_init (&iter, corner_mask_cache);
+          while (g_hash_table_iter_next (&iter, NULL, NULL))
+            if (i++ % 4 == 0)
+              g_hash_table_iter_remove (&iter);
+        }
       g_hash_table_insert (corner_mask_cache, g_memdup (&key, sizeof (key)), mask);
     }
 


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