Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (IsKillable(collision))
        {
            if (mKillableCache.IsFull)
            {
                mKillableCache.Expand();
            }

            mKillableCache.Add(new KillableCache(collision));
        }
        else
        {
            if (mSurfaceCache.IsFull)
            {
                mSurfaceCache.Expand();
            }

            var newSurfaceCache = new SurfaceCache(collision);
            mSurfaceCache.Add(newSurfaceCache);

            ComputeSurface(true);
        }
    }
Esempio n. 4
0
 public ResourceManager(MemoryManager gmm, SurfaceCache cache)
 {
     Gmm   = gmm;
     Cache = cache;
 }