[banshee] [grid] Grow surface cache as needed (bgo#612593)



commit a5cd9dab442fd9974a33d03b09cc9722b777fd41
Author: Alexander Kojevnikov <alexander kojevnikov com>
Date:   Sat Mar 13 16:38:00 2010 +1100

    [grid] Grow surface cache as needed (bgo#612593)

 .../Banshee.Collection.Gui/AlbumListView.cs        |   12 ++++++++-
 .../Banshee.Collection.Gui/ArtworkManager.cs       |   27 +++++++++++++++----
 .../Banshee.Collection.Gui/DataViewChildAlbum.cs   |    6 +---
 .../Hyena.Gui/Hyena.Data.Gui/DataViewLayoutGrid.cs |    6 ++++
 4 files changed, 39 insertions(+), 12 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
index d1919dd..058e46a 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
@@ -48,10 +48,20 @@ namespace Banshee.Collection.Gui
                 column_controller.Add (new Column ("Album", renderer = new ColumnCellAlbum (), 1.0));
                 ColumnController = column_controller;
             } else {
-                ViewLayout = new DataViewLayoutGrid () {
+                var layout = new DataViewLayoutGrid () {
                     ChildAllocator = () => new DataViewChildAlbum (),
                     View = this
                 };
+
+                layout.ChildCountChanged += (o, e) => {
+                    var artwork_manager = ServiceManager.Get<ArtworkManager> ();
+                    if (artwork_manager != null && e.Value > 0) {
+                        int size = (int)((DataViewChildAlbum)layout[0]).ImageSize;
+                        artwork_manager.ChangeCacheSize (size, e.Value);
+                    }
+                };
+
+                ViewLayout = layout;
             }
 
             ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.TrackInfoUpdated);
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
index 55acec8..1e351ef 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
@@ -121,13 +121,10 @@ namespace Banshee.Collection.Gui
 
                 if (cache == null) {
                     int bytes = 4 * size * size;
-                    int max = (1 << 21) / bytes;
+                    int max = (1 << 20) / bytes;
 
-                    Log.DebugFormat ("Creating new surface cache for {0}px, {1} KB (max) images, capped at 2 MB ({2} items)",
-                        size, bytes, max);
-
-                    cache = new SurfaceCache (max);
-                    scale_caches.Add (size, cache);
+                    ChangeCacheSize (size, max);
+                    cache = scale_caches[size];
                 }
 
                 cache.Add (id, surface);
@@ -233,6 +230,24 @@ namespace Banshee.Collection.Gui
             return cacheable_cover_sizes;
         }
 
+        public void ChangeCacheSize (int size, int max_count)
+        {
+            SurfaceCache cache;
+            if (scale_caches.TryGetValue (size, out cache)) {
+                if (max_count > cache.MaxCount) {
+                    Log.DebugFormat (
+                        "Growing surface cache for {0}px images to {1:0.00} MiB ({2} items)",
+                        size, 4 * size * size * max_count / 1048576d, max_count);
+                    cache.MaxCount = max_count;
+                }
+            } else {
+                Log.DebugFormat (
+                    "Creating new surface cache for {0}px images, capped at {1:0.00} MiB ({2} items)",
+                    size, 4 * size * size * max_count / 1048576d, max_count);
+                scale_caches.Add (size, new SurfaceCache (max_count));
+            }
+        }
+
         private static int dispose_count = 0;
         public static void DisposePixbuf (Pixbuf pixbuf)
         {
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DataViewChildAlbum.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DataViewChildAlbum.cs
index 4f1c60c..ba1cec1 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DataViewChildAlbum.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DataViewChildAlbum.cs
@@ -86,14 +86,10 @@ namespace Banshee.Collection.Gui
         {
             artwork_manager = ServiceManager.Get<ArtworkManager> ();
 
-            Padding = new Thickness (6);
-            ImageSize = 48;
-            ImageSpacing = 4;
-            TextSpacing = 2;
-
             Padding = new Thickness (5);
             ImageSize = 90;
             ImageSpacing = 2;
+            TextSpacing = 2;
         }
 
         public override void Arrange ()
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/DataViewLayoutGrid.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/DataViewLayoutGrid.cs
index d4d418e..2828043 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/DataViewLayoutGrid.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/DataViewLayoutGrid.cs
@@ -39,6 +39,7 @@ namespace Hyena.Data.Gui
         public int Columns { get; private set; }
 
         public Func<DataViewChild> ChildAllocator { get; set; }
+        public event EventHandler<EventArgs<int>> ChildCountChanged;
 
         protected override void InvalidateChildSize ()
         {
@@ -68,6 +69,11 @@ namespace Hyena.Data.Gui
                 : 0;
 
             ResizeChildCollection (Rows * Columns);
+
+            var handler = ChildCountChanged;
+            if (handler != null) {
+                handler (this, new EventArgs<int> (Rows * Columns));
+            }
         }
 
         protected override void InvalidateChildLayout ()



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