[banshee/art-caching] Only cache artwork for particular sizes
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee/art-caching] Only cache artwork for particular sizes
- Date: Fri, 4 Dec 2009 01:05:17 +0000 (UTC)
commit 2e61d30d878c86ba32ff69806132d7dfa2d0ff14
Author: Félix Velasco <felix velasco gmail com>
Date: Thu Dec 3 14:22:45 2009 +0100
Only cache artwork for particular sizes
The ArtworkManager has scaled images of all sizes requested of it,
sometimes only 1px different than other requests, but we currently cache
everything. Now we'll only cache particular sizes.
Signed-off-by: Gabriel Burt <gabriel burt gmail com>
.../Banshee.Collection.Gui/ArtworkManager.cs | 29 ++++++++++++++++++-
.../Banshee.Lastfm.Radio/LastfmSourceContents.cs | 1 +
.../Banshee.Moblin/RecentAlbumsView.cs | 1 +
.../NotificationAreaService.cs | 15 +++++-----
4 files changed, 37 insertions(+), 9 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
index ce33003..1a6172b 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
@@ -47,6 +47,7 @@ namespace Banshee.Collection.Gui
public class ArtworkManager : IService
{
private Dictionary<int, SurfaceCache> scale_caches = new Dictionary<int, SurfaceCache> ();
+ private HashSet<int> cacheable_cover_sizes = new HashSet<int> ();
private class SurfaceCache : LruCache<string, Cairo.ImageSurface>
{
@@ -69,6 +70,11 @@ namespace Banshee.Collection.Gui
} catch (Exception e) {
Log.Error ("Could not migrate old album artwork to new location.", e.Message, true);
}
+
+ AddCachedSize (36);
+ AddCachedSize (48);
+ AddCachedSize (64);
+ AddCachedSize (300);
}
private void MigrateLegacyAlbumArt ()
@@ -201,8 +207,12 @@ namespace Banshee.Collection.Gui
try {
Pixbuf pixbuf = new Pixbuf (orig_path);
Pixbuf scaled_pixbuf = pixbuf.ScaleSimple (size, size, Gdk.InterpType.Bilinear);
- Directory.CreateDirectory (Path.GetDirectoryName (path));
- scaled_pixbuf.Save (path, "jpeg");
+
+ if (IsCachedSize (size)) {
+ Directory.CreateDirectory (Path.GetDirectoryName (path));
+ scaled_pixbuf.Save (path, "jpeg");
+ }
+
DisposePixbuf (pixbuf);
return scaled_pixbuf;
} catch {}
@@ -211,6 +221,21 @@ namespace Banshee.Collection.Gui
return null;
}
+ public void AddCachedSize (int size)
+ {
+ cacheable_cover_sizes.Add (size);
+ }
+
+ public bool IsCachedSize (int size)
+ {
+ return cacheable_cover_sizes.Contains (size);
+ }
+
+ public IEnumerable<int> CachedSizes ()
+ {
+ return cacheable_cover_sizes;
+ }
+
private static int dispose_count = 0;
public static void DisposePixbuf (Pixbuf pixbuf)
{
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs
index f451395..5a19fa9 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs
@@ -187,6 +187,7 @@ namespace Banshee.Lastfm.Radio
public NumberedList (LastfmSource lastfm, string name) : base (name)
{
this.lastfm = lastfm;
+ artwork_manager.AddCachedSize(40);
tile_view = new NumberedTileView (1);
PackStart (tile_view, true, true, 0);
tile_view.Show ();
diff --git a/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs b/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs
index 6c3852d..f7bfd57 100644
--- a/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs
+++ b/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs
@@ -102,6 +102,7 @@ namespace Banshee.Moblin
{
RowSpacing = ColumnSpacing = 12;
Build ();
+ ServiceManager.Get<ArtworkManager> ().AddCachedSize (icon_size);
recent = new RecentAlbumsList (cols * rows);
recent.Changed += (o, a) => Reload ();
diff --git a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
index 4c34152..352f774 100644
--- a/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
+++ b/src/Extensions/Banshee.NotificationArea/Banshee.NotificationArea/NotificationAreaService.cs
@@ -69,6 +69,8 @@ namespace Banshee.NotificationArea
private TrackInfo current_track;
private Notification current_nf;
+ private const int icon_size = 42;
+
public NotificationAreaService ()
{
}
@@ -145,6 +147,9 @@ namespace Banshee.NotificationArea
// Forcefully load this
show_notifications = ShowNotifications;
+
+ artwork_manager_service = ServiceManager.Get<ArtworkManager> ();
+ artwork_manager_service.AddCachedSize (icon_size);
}
public void Dispose ()
@@ -328,7 +333,7 @@ namespace Banshee.NotificationArea
if (NotifyOnCloseSchema.Get ()) {
Gdk.Pixbuf image = IconThemeUtils.LoadIcon (48, Banshee.ServiceStack.Application.IconName);
if (image != null) {
- image = image.ScaleSimple (42, 42, Gdk.InterpType.Bilinear);
+ image = image.ScaleSimple (icon_size, icon_size, Gdk.InterpType.Bilinear);
}
Notification nf = new Notification (
@@ -434,22 +439,18 @@ namespace Banshee.NotificationArea
current_track.ArtistName, current_track.DisplayArtistName,
current_track.AlbumTitle, current_track.DisplayAlbumTitle);
- if (artwork_manager_service == null) {
- artwork_manager_service = ServiceManager.Get<ArtworkManager> ();
- }
-
Gdk.Pixbuf image = null;
if (artwork_manager_service != null) {
image = is_notification_daemon
- ? artwork_manager_service.LookupScalePixbuf (current_track.ArtworkId, 42)
+ ? artwork_manager_service.LookupScalePixbuf (current_track.ArtworkId, icon_size)
: artwork_manager_service.LookupPixbuf (current_track.ArtworkId);
}
if (image == null) {
image = IconThemeUtils.LoadIcon (48, "audio-x-generic");
if (image != null) {
- image.ScaleSimple (42, 42, Gdk.InterpType.Bilinear);
+ image.ScaleSimple (icon_size, icon_size, Gdk.InterpType.Bilinear);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]