[libwnck/wip/muktupavels/icons: 2/5] icon-cache: cache only one size




commit 5dfab42e1af389c7a9e3628f30233d9d7b06dccc
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Dec 19 23:46:16 2021 +0200

    icon-cache: cache only one size
    
    Create icon cache for each size - mini and normal.
    
    This will allow in future commits to load only icon size that is
    actually used by someone.

 libwnck/application.c             | 39 ++++++++++------
 libwnck/class-group.c             |  6 +--
 libwnck/tasklist.c                |  3 +-
 libwnck/window.c                  | 43 +++++++++++------
 libwnck/wnck-icon-cache-private.h |  6 +--
 libwnck/wnck-icon-cache.c         | 98 +++++++--------------------------------
 libwnck/xutils.c                  |  9 +---
 libwnck/xutils.h                  |  6 +--
 8 files changed, 81 insertions(+), 129 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index 78d251a..7c607d9 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -67,6 +67,7 @@ struct _WnckApplicationPrivate
   GdkPixbuf *mini_icon;
 
   WnckIconCache *icon_cache;
+  WnckIconCache *mini_icon_cache;
 
   WnckWindow *icon_window;
 
@@ -112,6 +113,9 @@ wnck_application_init (WnckApplication *application)
 
   application->priv->icon_cache = _wnck_icon_cache_new ();
   _wnck_icon_cache_set_want_fallback (application->priv->icon_cache, FALSE);
+
+  application->priv->mini_icon_cache = _wnck_icon_cache_new ();
+  _wnck_icon_cache_set_want_fallback (application->priv->mini_icon_cache, FALSE);
 }
 
 static void
@@ -181,6 +185,9 @@ wnck_application_finalize (GObject *object)
   _wnck_icon_cache_free (application->priv->icon_cache);
   application->priv->icon_cache = NULL;
 
+  _wnck_icon_cache_free (application->priv->mini_icon_cache);
+  application->priv->mini_icon_cache = NULL;
+
   g_free (application->priv->startup_id);
   application->priv->startup_id = NULL;
 
@@ -329,31 +336,35 @@ get_icons (WnckApplication *app)
 {
   GdkPixbuf *icon;
   GdkPixbuf *mini_icon;
-  gsize normal_size;
-  gsize mini_size;
 
   icon = NULL;
   mini_icon = NULL;
-  normal_size = _wnck_get_default_icon_size ();
-  mini_size = _wnck_get_default_mini_icon_size ();
-
-  if (_wnck_read_icons (app->priv->screen,
-                        app->priv->xwindow,
-                        app->priv->icon_cache,
-                        &icon,
-                        normal_size,
-                        &mini_icon,
-                        mini_size))
+
+  if (_wnck_read_icon (app->priv->screen,
+                       app->priv->xwindow,
+                       app->priv->icon_cache,
+                       &icon,
+                       _wnck_get_default_icon_size ()))
     {
       app->priv->need_emit_icon_changed = TRUE;
 
       if (app->priv->icon)
         g_object_unref (G_OBJECT (app->priv->icon));
 
+      app->priv->icon = icon;
+    }
+
+  if (_wnck_read_icon (app->priv->screen,
+                       app->priv->xwindow,
+                       app->priv->mini_icon_cache,
+                       &mini_icon,
+                       _wnck_get_default_mini_icon_size ()))
+    {
+      app->priv->need_emit_icon_changed = TRUE;
+
       if (app->priv->mini_icon)
         g_object_unref (G_OBJECT (app->priv->mini_icon));
 
-      app->priv->icon = icon;
       app->priv->mini_icon = mini_icon;
     }
 
@@ -663,6 +674,8 @@ _wnck_application_process_property_notify (WnckApplication *app,
     {
       _wnck_icon_cache_property_changed (app->priv->icon_cache,
                                          xevent->xproperty.atom);
+      _wnck_icon_cache_property_changed (app->priv->mini_icon_cache,
+                                         xevent->xproperty.atom);
       emit_icon_changed (app);
     }
   else if (xevent->xproperty.atom ==
diff --git a/libwnck/class-group.c b/libwnck/class-group.c
index f4afc31..70a420a 100644
--- a/libwnck/class-group.c
+++ b/libwnck/class-group.c
@@ -455,10 +455,8 @@ set_icon (WnckClassGroup *class_group)
 
   if (!icon || !mini_icon)
     {
-      _wnck_get_fallback_icons (&icon,
-                                _wnck_get_default_icon_size (),
-                                &mini_icon,
-                                _wnck_get_default_mini_icon_size ());
+      _wnck_get_fallback_icon (&icon, _wnck_get_default_icon_size ());
+      _wnck_get_fallback_icon (&mini_icon, _wnck_get_default_mini_icon_size ());
       icons_reffed = TRUE;
     }
 
diff --git a/libwnck/tasklist.c b/libwnck/tasklist.c
index 8791b10..c12527e 100644
--- a/libwnck/tasklist.c
+++ b/libwnck/tasklist.c
@@ -3709,8 +3709,7 @@ wnck_task_get_icon (WnckTask *task)
 
       if (pixbuf == NULL)
         {
-          _wnck_get_fallback_icons (NULL, 0,
-                                    &pixbuf, MINI_ICON_SIZE);
+          _wnck_get_fallback_icon (&pixbuf, MINI_ICON_SIZE);
         }
 #endif
       break;
diff --git a/libwnck/window.c b/libwnck/window.c
index 25c56a5..f90933f 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -93,6 +93,7 @@ struct _WnckWindowPrivate
   GdkPixbuf *mini_icon;
 
   WnckIconCache *icon_cache;
+  WnckIconCache *mini_icon_cache;
 
   WnckWindowActions actions;
 
@@ -235,6 +236,7 @@ wnck_window_init (WnckWindow *window)
   window->priv = wnck_window_get_instance_private (window);
 
   window->priv->icon_cache = _wnck_icon_cache_new ();
+  window->priv->mini_icon_cache = _wnck_icon_cache_new ();
   window->priv->icon_geometry.width = -1; /* invalid cached value */
   window->priv->workspace = -1;
   window->priv->sort_order = G_MAXINT;
@@ -434,6 +436,9 @@ wnck_window_finalize (GObject *object)
   _wnck_icon_cache_free (window->priv->icon_cache);
   window->priv->icon_cache = NULL;
 
+  _wnck_icon_cache_free (window->priv->mini_icon_cache);
+  window->priv->mini_icon_cache = NULL;
+
   g_free (window->priv->startup_id);
   window->priv->startup_id = NULL;
   g_free (window->priv->res_class);
@@ -2118,31 +2123,35 @@ get_icons (WnckWindow *window)
 {
   GdkPixbuf *icon;
   GdkPixbuf *mini_icon;
-  gsize normal_size;
-  gsize mini_size;
 
   icon = NULL;
   mini_icon = NULL;
-  normal_size = _wnck_get_default_icon_size ();
-  mini_size = _wnck_get_default_mini_icon_size ();
 
-  if (_wnck_read_icons (window->priv->screen,
-                        window->priv->xwindow,
-                        window->priv->icon_cache,
-                        &icon,
-                        normal_size,
-                        &mini_icon,
-                        mini_size))
+  if (_wnck_read_icon (window->priv->screen,
+                       window->priv->xwindow,
+                       window->priv->icon_cache,
+                       &icon,
+                       _wnck_get_default_icon_size ()))
     {
       window->priv->need_emit_icon_changed = TRUE;
 
       if (window->priv->icon)
         g_object_unref (G_OBJECT (window->priv->icon));
 
+      window->priv->icon = icon;
+    }
+
+  if (_wnck_read_icon (window->priv->screen,
+                       window->priv->xwindow,
+                       window->priv->mini_icon_cache,
+                       &mini_icon,
+                       _wnck_get_default_mini_icon_size ()))
+    {
+      window->priv->need_emit_icon_changed = TRUE;
+
       if (window->priv->mini_icon)
         g_object_unref (G_OBJECT (window->priv->mini_icon));
 
-      window->priv->icon = icon;
       window->priv->mini_icon = mini_icon;
     }
 
@@ -2614,6 +2623,8 @@ _wnck_window_process_property_notify (WnckWindow *window,
     {
       _wnck_icon_cache_property_changed (window->priv->icon_cache,
                                          xevent->xproperty.atom);
+      _wnck_icon_cache_property_changed (window->priv->mini_icon_cache,
+                                         xevent->xproperty.atom);
       queue_update (window);
     }
   else if (xevent->xproperty.atom ==
@@ -3180,8 +3191,12 @@ update_wmhints (WnckWindow *window)
     {
       if ((hints->flags & IconPixmapHint) ||
           (hints->flags & IconMaskHint))
-        _wnck_icon_cache_property_changed (window->priv->icon_cache,
-                                           _wnck_atom_get ("WM_HINTS"));
+        {
+          _wnck_icon_cache_property_changed (window->priv->icon_cache,
+                                             _wnck_atom_get ("WM_HINTS"));
+          _wnck_icon_cache_property_changed (window->priv->mini_icon_cache,
+                                             _wnck_atom_get ("WM_HINTS"));
+        }
 
       if (hints->flags & WindowGroupHint)
           window->priv->group_leader = hints->window_group;
diff --git a/libwnck/wnck-icon-cache-private.h b/libwnck/wnck-icon-cache-private.h
index 6a3d5ec..50a72c9 100644
--- a/libwnck/wnck-icon-cache-private.h
+++ b/libwnck/wnck-icon-cache-private.h
@@ -38,13 +38,11 @@ void           _wnck_icon_cache_set_want_fallback    (WnckIconCache  *icon_cache
                                                       gboolean        setting);
 gboolean       _wnck_icon_cache_get_is_fallback      (WnckIconCache  *icon_cache);
 
-gboolean       _wnck_read_icons                      (WnckScreen     *screen,
+gboolean       _wnck_read_icon                       (WnckScreen     *screen,
                                                       Window          xwindow,
                                                       WnckIconCache  *icon_cache,
                                                       GdkPixbuf     **iconp,
-                                                      int             ideal_size,
-                                                      GdkPixbuf     **mini_iconp,
-                                                      int             ideal_mini_size);
+                                                      int             ideal_size);
 
 G_END_DECLS
 
diff --git a/libwnck/wnck-icon-cache.c b/libwnck/wnck-icon-cache.c
index 1749585..014d194 100644
--- a/libwnck/wnck-icon-cache.c
+++ b/libwnck/wnck-icon-cache.c
@@ -46,9 +46,7 @@ struct _WnckIconCache
   Pixmap prev_pixmap;
   Pixmap prev_mask;
   GdkPixbuf *icon;
-  GdkPixbuf *mini_icon;
   int ideal_size;
-  int ideal_mini_size;
   guint want_fallback : 1;
   /* TRUE if these props have changed */
   guint wm_hints_dirty : 1;
@@ -177,13 +175,9 @@ static gboolean
 read_rgb_icon (Screen  *screen,
                Window   xwindow,
                int      ideal_size,
-               int      ideal_mini_size,
                int     *width,
                int     *height,
-               guchar **pixdata,
-               int     *mini_width,
-               int     *mini_height,
-               guchar **mini_pixdata)
+               guchar **pixdata)
 {
   Display *display;
   Atom type;
@@ -194,8 +188,6 @@ read_rgb_icon (Screen  *screen,
   gulong *data;
   gulong *best;
   int w, h;
-  gulong *best_mini;
-  int mini_w, mini_h;
 
   display = DisplayOfScreen (screen);
 
@@ -227,22 +219,10 @@ read_rgb_icon (Screen  *screen,
       return FALSE;
     }
 
-  if (!find_best_size (data, nitems,
-                       ideal_mini_size,
-                       &mini_w, &mini_h, &best_mini))
-    {
-      XFree (data);
-      return FALSE;
-    }
-
   *width = w;
   *height = h;
 
-  *mini_width = mini_w;
-  *mini_height = mini_h;
-
   argbdata_to_pixdata (best, w * h, pixdata);
-  argbdata_to_pixdata (best_mini, mini_w * mini_h, mini_pixdata);
 
   XFree (data);
 
@@ -254,9 +234,7 @@ try_pixmap_and_mask (Screen     *screen,
                      Pixmap      src_pixmap,
                      Pixmap      src_mask,
                      GdkPixbuf **iconp,
-                     int         ideal_size,
-                     GdkPixbuf **mini_iconp,
-                     int         ideal_mini_size)
+                     int         ideal_size)
 {
   cairo_surface_t *surface, *mask_surface, *image;
   GdkDisplay *gdk_display;
@@ -339,11 +317,6 @@ try_pixmap_and_mask (Screen     *screen,
                                  ideal_size,
                                  ideal_size,
                                  GDK_INTERP_BILINEAR);
-      *mini_iconp =
-        gdk_pixbuf_scale_simple (unscaled,
-                                 ideal_mini_size,
-                                 ideal_mini_size,
-                                 GDK_INTERP_BILINEAR);
 
       g_object_unref (G_OBJECT (unscaled));
       return TRUE;
@@ -408,10 +381,6 @@ clear_icon_cache (WnckIconCache *icon_cache,
     g_object_unref (G_OBJECT (icon_cache->icon));
   icon_cache->icon = NULL;
 
-  if (icon_cache->mini_icon)
-    g_object_unref (G_OBJECT (icon_cache->mini_icon));
-  icon_cache->mini_icon = NULL;
-
   icon_cache->origin = USING_NO_ICON;
 
   if (dirty_all)
@@ -425,8 +394,7 @@ clear_icon_cache (WnckIconCache *icon_cache,
 static void
 replace_cache (WnckIconCache *icon_cache,
                IconOrigin     origin,
-               GdkPixbuf     *new_icon,
-               GdkPixbuf     *new_mini_icon)
+               GdkPixbuf     *new_icon)
 {
   clear_icon_cache (icon_cache, FALSE);
 
@@ -436,11 +404,6 @@ replace_cache (WnckIconCache *icon_cache,
     g_object_ref (G_OBJECT (new_icon));
 
   icon_cache->icon = new_icon;
-
-  if (new_mini_icon)
-    g_object_ref (G_OBJECT (new_mini_icon));
-
-  icon_cache->mini_icon = new_mini_icon;
 }
 
 static void
@@ -516,9 +479,7 @@ _wnck_icon_cache_new (void)
   icon_cache->origin = USING_NO_ICON;
   icon_cache->prev_pixmap = None;
   icon_cache->icon = NULL;
-  icon_cache->mini_icon = NULL;
   icon_cache->ideal_size = -1; /* won't be a legit size */
-  icon_cache->ideal_mini_size = -1;
   icon_cache->want_fallback = TRUE;
   icon_cache->wm_hints_dirty = TRUE;
   icon_cache->kwm_win_icon_dirty = TRUE;
@@ -585,20 +546,16 @@ _wnck_icon_cache_get_is_fallback (WnckIconCache *icon_cache)
 }
 
 gboolean
-_wnck_read_icons (WnckScreen     *screen,
-                  Window          xwindow,
-                  WnckIconCache  *icon_cache,
-                  GdkPixbuf     **iconp,
-                  int             ideal_size,
-                  GdkPixbuf     **mini_iconp,
-                  int             ideal_mini_size)
+_wnck_read_icon (WnckScreen     *screen,
+                 Window          xwindow,
+                 WnckIconCache  *icon_cache,
+                 GdkPixbuf     **iconp,
+                 int             ideal_size)
 {
   Screen *xscreen;
   Display *display;
   guchar *pixdata;
   int w, h;
-  guchar *mini_pixdata;
-  int mini_w, mini_h;
   Pixmap pixmap;
   Pixmap mask;
   XWMHints *hints;
@@ -611,14 +568,11 @@ _wnck_read_icons (WnckScreen     *screen,
   display = DisplayOfScreen (xscreen);
 
   *iconp = NULL;
-  *mini_iconp = NULL;
 
-  if (ideal_size != icon_cache->ideal_size ||
-      ideal_mini_size != icon_cache->ideal_mini_size)
+  if (ideal_size != icon_cache->ideal_size)
     clear_icon_cache (icon_cache, TRUE);
 
   icon_cache->ideal_size = ideal_size;
-  icon_cache->ideal_mini_size = ideal_mini_size;
 
   if (!_wnck_icon_cache_get_icon_invalidated (icon_cache))
     return FALSE; /* we have no new info to use */
@@ -640,19 +594,11 @@ _wnck_read_icons (WnckScreen     *screen,
     {
       icon_cache->net_wm_icon_dirty = FALSE;
 
-      if (read_rgb_icon (xscreen, xwindow,
-                         ideal_size,
-                         ideal_mini_size,
-                         &w, &h, &pixdata,
-                         &mini_w, &mini_h, &mini_pixdata))
+      if (read_rgb_icon (xscreen, xwindow, ideal_size, &w, &h, &pixdata))
         {
           *iconp = scaled_from_pixdata (pixdata, w, h, ideal_size, ideal_size);
 
-          *mini_iconp = scaled_from_pixdata (mini_pixdata, mini_w, mini_h,
-                                             ideal_mini_size, ideal_mini_size);
-
-          replace_cache (icon_cache, USING_NET_WM_ICON,
-                         *iconp, *mini_iconp);
+          replace_cache (icon_cache, USING_NET_WM_ICON, *iconp);
 
           return TRUE;
         }
@@ -687,15 +633,12 @@ _wnck_read_icons (WnckScreen     *screen,
            mask != icon_cache->prev_mask) &&
           pixmap != None)
         {
-          if (try_pixmap_and_mask (xscreen, pixmap, mask,
-                                   iconp, ideal_size,
-                                   mini_iconp, ideal_mini_size))
+          if (try_pixmap_and_mask (xscreen, pixmap, mask, iconp, ideal_size))
             {
               icon_cache->prev_pixmap = pixmap;
               icon_cache->prev_mask = mask;
 
-              replace_cache (icon_cache, USING_WM_HINTS,
-                             *iconp, *mini_iconp);
+              replace_cache (icon_cache, USING_WM_HINTS, *iconp);
 
               return TRUE;
             }
@@ -713,15 +656,12 @@ _wnck_read_icons (WnckScreen     *screen,
            mask != icon_cache->prev_mask) &&
           pixmap != None)
         {
-          if (try_pixmap_and_mask (xscreen, pixmap, mask,
-                                   iconp, ideal_size,
-                                   mini_iconp, ideal_mini_size))
+          if (try_pixmap_and_mask (xscreen, pixmap, mask, iconp, ideal_size))
             {
               icon_cache->prev_pixmap = pixmap;
               icon_cache->prev_mask = mask;
 
-              replace_cache (icon_cache, USING_KWM_WIN_ICON,
-                             *iconp, *mini_iconp);
+              replace_cache (icon_cache, USING_KWM_WIN_ICON, *iconp);
 
               return TRUE;
             }
@@ -731,13 +671,9 @@ _wnck_read_icons (WnckScreen     *screen,
   if (icon_cache->want_fallback &&
       icon_cache->origin < USING_FALLBACK_ICON)
     {
-      _wnck_get_fallback_icons (iconp,
-                                ideal_size,
-                                mini_iconp,
-                                ideal_mini_size);
+      _wnck_get_fallback_icon (iconp, ideal_size);
 
-      replace_cache (icon_cache, USING_FALLBACK_ICON,
-                     *iconp, *mini_iconp);
+      replace_cache (icon_cache, USING_FALLBACK_ICON, *iconp);
 
       return TRUE;
     }
diff --git a/libwnck/xutils.c b/libwnck/xutils.c
index 08e6325..532b51a 100644
--- a/libwnck/xutils.c
+++ b/libwnck/xutils.c
@@ -1461,16 +1461,11 @@ default_icon_at_size (int size)
 }
 
 void
-_wnck_get_fallback_icons (GdkPixbuf **iconp,
-                          int         ideal_size,
-                          GdkPixbuf **mini_iconp,
-                          int         ideal_mini_size)
+_wnck_get_fallback_icon (GdkPixbuf **iconp,
+                         int         ideal_size)
 {
   if (iconp)
     *iconp = default_icon_at_size (ideal_size);
-
-  if (mini_iconp)
-    *mini_iconp = default_icon_at_size (ideal_mini_size);
 }
 
 void
diff --git a/libwnck/xutils.h b/libwnck/xutils.h
index 4e5c620..7b26c92 100644
--- a/libwnck/xutils.h
+++ b/libwnck/xutils.h
@@ -156,10 +156,8 @@ void _wnck_keyboard_size (WnckScreen *screen,
 void _wnck_toggle_showing_desktop (Screen  *screen,
                                    gboolean show);
 
-void _wnck_get_fallback_icons (GdkPixbuf **iconp,
-                               int         ideal_size,
-                               GdkPixbuf **mini_iconp,
-                               int         ideal_mini_size);
+void _wnck_get_fallback_icon (GdkPixbuf **iconp,
+                              int         ideal_size);
 
 void _wnck_get_window_geometry (Screen *screen,
                                Window  xwindow,


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