[gnome-games] ui: Cache scaled cover in GameThumbnail
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Cache scaled cover in GameThumbnail
- Date: Wed, 13 Jul 2016 07:25:51 +0000 (UTC)
commit 927b2dedbadc61348d87432652f204289e49f706
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Jul 12 21:47:12 2016 +0200
ui: Cache scaled cover in GameThumbnail
This avoid rescaling the cover again and again and hence speeds up
drawing it.
Fixes #301
src/ui/game-thumbnail.vala | 36 ++++++++++++++++++++++++++----------
1 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index b40a79f..12fa05d 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -48,6 +48,10 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
default = null;
}
+ private Gdk.Pixbuf? cover_cache;
+ private int previous_cover_width;
+ private int previous_cover_height;
+
public struct DrawingContext {
Cairo.Context cr;
Gdk.Window? window;
@@ -109,11 +113,7 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
}
public bool draw_cover (DrawingContext context) {
- var g_icon = cover.get_cover ();
- if (g_icon == null)
- return false;
-
- var pixbuf = get_scaled_cover (context, g_icon);
+ var pixbuf = get_scaled_cover (context);
if (pixbuf == null)
return false;
@@ -180,25 +180,41 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
}
}
- private Gdk.Pixbuf? get_scaled_cover (DrawingContext context, GLib.Icon? icon) {
- if (icon == null)
+ private Gdk.Pixbuf? get_scaled_cover (DrawingContext context) {
+ if (previous_cover_width != context.width) {
+ previous_cover_width = context.width;
+ cover_cache = null;
+ }
+
+ if (previous_cover_height != context.height) {
+ previous_cover_height = context.height;
+ cover_cache = null;
+ }
+
+ if (cover_cache != null)
+ return cover_cache;
+
+ var g_icon = cover.get_cover ();
+ if (g_icon == null)
return null;
var theme = Gtk.IconTheme.get_default ();
var lookup_flags = Gtk.IconLookupFlags.FORCE_SIZE | Gtk.IconLookupFlags.FORCE_REGULAR;
var size = int.min (context.width, context.height) - COVER_MARGIN * 2;
- var icon_info = theme.lookup_by_gicon (icon, (int) size, lookup_flags);
+ var icon_info = theme.lookup_by_gicon (g_icon, (int) size, lookup_flags);
try {
- return icon_info.load_icon ();
+ cover_cache = icon_info.load_icon ();
}
catch (Error e) {
warning (@"Couldn't load the icon: $(e.message)\n");
- return null;
}
+
+ return cover_cache;
}
private void invalidate_cover () {
+ cover_cache = null;
queue_draw ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]