Bug 1183852 - Only mark surfaces as used in the SurfaceCache if a caller requested exactly that surface. r=dholbert

This commit is contained in:
Seth Fowler 2015-07-14 22:19:02 -07:00
Родитель 666cbfecb2
Коммит 141d7e2ab0
1 изменённых файлов: 19 добавлений и 12 удалений

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

@ -425,7 +425,7 @@ public:
Lifetime aLifetime)
{
// If this is a duplicate surface, refuse to replace the original.
if (MOZ_UNLIKELY(Lookup(aImageKey, aSurfaceKey))) {
if (MOZ_UNLIKELY(Lookup(aImageKey, aSurfaceKey, /* aMarkUsed = */ false))) {
return InsertOutcome::FAILURE_ALREADY_PRESENT;
}
@ -545,7 +545,8 @@ public:
}
LookupResult Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
const SurfaceKey& aSurfaceKey,
bool aMarkUsed = true)
{
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache) {
@ -565,10 +566,8 @@ public:
return LookupResult();
}
if (cache->IsLocked()) {
LockSurface(surface);
} else {
mExpirationTracker.MarkUsed(surface);
if (aMarkUsed) {
MarkUsed(surface, cache);
}
return LookupResult(Move(ref), /* aIsExactMatch = */ true);
@ -607,12 +606,6 @@ public:
Remove(surface);
}
if (cache->IsLocked()) {
LockSurface(surface);
} else {
mExpirationTracker.MarkUsed(surface);
}
SurfaceKey key = surface->GetSurfaceKey();
const bool isExactMatch = key.Size() == aSurfaceKey.Size();
@ -621,6 +614,11 @@ public:
(aAlternateFlags && key == aSurfaceKey.WithNewFlags(*aAlternateFlags))),
"Result differs in a way other than size or alternate flags");
if (isExactMatch) {
MarkUsed(surface, cache);
}
return LookupResult(Move(ref), isExactMatch);
}
@ -860,6 +858,15 @@ private:
return aCost <= mMaxCost - mLockedCost;
}
void MarkUsed(CachedSurface* aSurface, ImageSurfaceCache* aCache)
{
if (aCache->IsLocked()) {
LockSurface(aSurface);
} else {
mExpirationTracker.MarkUsed(aSurface);
}
}
struct SurfaceTracker : public nsExpirationTracker<CachedSurface, 2>
{
explicit SurfaceTracker(uint32_t aSurfaceCacheExpirationTimeMS)