From 721363b4e59a8b85e8ae292dfc24ce7bae59412e Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Fri, 19 Sep 2014 14:53:28 -0700 Subject: [PATCH] Bug 1060200 (Part 2) - Add SurfaceCache::RemoveIfPresent so invalid entries can be freed eagerly. r=dholbert --- image/src/SurfaceCache.cpp | 24 ++++++++++++++++++++++++ image/src/SurfaceCache.h | 12 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/image/src/SurfaceCache.cpp b/image/src/SurfaceCache.cpp index b4a557a820c2..bb22016e86fe 100644 --- a/image/src/SurfaceCache.cpp +++ b/image/src/SurfaceCache.cpp @@ -339,6 +339,20 @@ public: return ref; } + void RemoveIfPresent(const ImageKey aImageKey, + const SurfaceKey& aSurfaceKey) + { + nsRefPtr cache = GetImageCache(aImageKey); + if (!cache) + return; // No cached surfaces for this image. + + nsRefPtr surface = cache->Lookup(aSurfaceKey); + if (!surface) + return; // Lookup in the per-image cache missed. + + Remove(surface); + } + bool CanHold(const Cost aCost) const { return aCost <= mMaxCost; @@ -537,6 +551,16 @@ SurfaceCache::CanHold(const IntSize& aSize) return sInstance->CanHold(cost); } +/* static */ void +SurfaceCache::RemoveIfPresent(const ImageKey aImageKey, + const SurfaceKey& aSurfaceKey) +{ + MOZ_ASSERT(sInstance, "Should be initialized"); + MOZ_ASSERT(NS_IsMainThread()); + + return sInstance->RemoveIfPresent(aImageKey, aSurfaceKey); +} + /* static */ void SurfaceCache::Discard(Image* aImageKey) { diff --git a/image/src/SurfaceCache.h b/image/src/SurfaceCache.h index 442583f9de3f..29231a97d901 100644 --- a/image/src/SurfaceCache.h +++ b/image/src/SurfaceCache.h @@ -183,6 +183,18 @@ struct SurfaceCache */ static bool CanHold(const IntSize& aSize); + /* + * Removes a surface from the cache, if it's present. + * + * Use this function to remove individual surfaces that have become invalid. + * Prefer Discard() or DiscardAll() when they're applicable, as they have much + * better performance than calling this function repeatedly. + * + * @param aImageKey Key data identifying which image the surface belongs to. + * @param aSurfaceKey Key data which uniquely identifies the requested surface. + */ + static void RemoveIfPresent(const ImageKey aImageKey, + const SurfaceKey& aSurfaceKey); /* * Evicts any cached surfaces associated with the given image from the cache. * This MUST be called, at a minimum, when the image is destroyed. If