[banshee/art-caching] Avoid reloading artwork when it hasn't changed



commit 2508b4875f76b245a57bec64e5fcf9330d05417d
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Dec 3 18:56:11 2009 -0800

    Avoid reloading artwork when it hasn't changed
    
    TrackInfoDisplay would reload the artwork for every consecutive song of
    an album.  And in fact, it would load it twice, once for the
    StartOfStream signal and once for TrackInfoUpdated.

 .../Banshee.Gui.Widgets/TrackInfoDisplay.cs        |   34 ++++++++++++++------
 1 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
index 41e4759..3182d1b 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
@@ -48,6 +48,8 @@ namespace Banshee.Gui.Widgets
 {
     public abstract class TrackInfoDisplay : Widget
     {
+        private string current_artwork_id;
+
         private ArtworkManager artwork_manager;
         protected ArtworkManager ArtworkManager {
             get { return artwork_manager; }
@@ -157,10 +159,20 @@ namespace Banshee.Gui.Widgets
         {
             base.OnSizeAllocated (allocation);
 
+            if (missing_audio_image != null) {
+                ((IDisposable)missing_audio_image).Dispose ();
+                missing_audio_image = null;
+            }
+
+            if (missing_video_image != null) {
+                ((IDisposable)missing_video_image).Dispose ();
+                missing_video_image = null;
+            }
+
             if (current_track == null) {
                 LoadCurrentTrack ();
             } else {
-                LoadImage (current_track);
+                LoadImage (current_track, true);
             }
         }
 
@@ -362,21 +374,23 @@ namespace Banshee.Gui.Widgets
 
             incoming_track = track;
 
-            LoadImage (track);
+            LoadImage (track, false);
 
             if (stage.Actor == null) {
                 stage.Reset ();
             }
         }
 
-        private void LoadImage (TrackInfo track)
+        private void LoadImage (TrackInfo track, bool force)
         {
-            ImageSurface image = artwork_manager.LookupScaleSurface (track.ArtworkId, ArtworkSizeRequest);
+            string artwork_id = track.ArtworkId;
+            if (current_artwork_id != artwork_id || force) {
+                current_artwork_id = artwork_id;
+                incoming_image = artwork_manager.LookupScaleSurface (artwork_id, ArtworkSizeRequest);
+            }
 
-            if (image == null) {
-                LoadMissingImage ((track.MediaAttributes & TrackMediaAttributes.VideoStream) != 0);
-            } else {
-                incoming_image = image;
+            if (incoming_image == null) {
+                incoming_image = MissingImage (track.HasAttribute (TrackMediaAttributes.VideoStream));
             }
 
             if (track == current_track) {
@@ -384,9 +398,9 @@ namespace Banshee.Gui.Widgets
             }
         }
 
-        private void LoadMissingImage (bool is_video)
+        private ImageSurface MissingImage (bool is_video)
         {
-            incoming_image = is_video ? MissingVideoImage : MissingAudioImage;
+            return is_video ? MissingVideoImage : MissingAudioImage;
         }
 
         private double last_fps = 0.0;



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