Bug 1060200 (Part 2) - Add SurfaceCache::RemoveIfPresent so invalid entries can be freed eagerly. r=dholbert

This commit is contained in:
Seth Fowler 2014-09-19 14:53:28 -07:00
Родитель 9b9d1e1c9f
Коммит 721363b4e5
2 изменённых файлов: 36 добавлений и 0 удалений

Просмотреть файл

@ -339,6 +339,20 @@ public:
return ref;
}
void RemoveIfPresent(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache)
return; // No cached surfaces for this image.
nsRefPtr<CachedSurface> 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)
{

Просмотреть файл

@ -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