public Cairo.ImageSurface LookupScaleSurface(string id, int size, bool useCache) { SurfaceCache cache = null; Cairo.ImageSurface surface = null; if (id == null) { return(null); } if (useCache && scale_caches.TryGetValue(size, out cache) && cache.TryGetValue(id, out surface)) { return(surface); } if (null_artwork_ids.Contains(id)) { return(null); } Pixbuf pixbuf = LookupScalePixbuf(id, size); if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) { null_artwork_ids.Add(id); return(null); } try { surface = PixbufImageSurface.Create(pixbuf); if (surface == null) { return(null); } if (!useCache) { return(surface); } if (cache == null) { int bytes = 4 * size * size; int max = (1 << 20) / bytes; ChangeCacheSize(size, max); cache = scale_caches[size]; } cache.Add(id, surface); return(surface); } finally { DisposePixbuf(pixbuf); } }
public Cairo.ImageSurface LookupScaleSurface(string id, int size, bool useCache) { SurfaceCache cache = null; Cairo.ImageSurface surface = null; if (id == null) { return(null); } if (useCache && scale_caches.TryGetValue(size, out cache) && cache.TryGetValue(id, out surface)) { return(surface); } Pixbuf pixbuf = LookupScalePixbuf(id, size); if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) { return(null); } try { surface = PixbufImageSurface.Create(pixbuf); if (surface == null) { return(null); } if (!useCache) { return(surface); } if (cache == null) { int bytes = 4 * size * size; int max = (1 << 20) / bytes; Log.DebugFormat("Creating new surface cache for {0} KB (max) images, capped at 1 MB ({1} items)", bytes, max); cache = new SurfaceCache(max); scale_caches.Add(size, cache); } cache.Add(id, surface); return(surface); } finally { DisposePixbuf(pixbuf); } }