Bug 1370412 - Part 7. ImageSurfaceCache::Lookup should enter factor of 2 mode on cache misses. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Tue, 05 Sep 2017 07:58:45 -0400
changeset 428466 71f26daac945b65873a2ce99498638a9cdec0bf7
parent 428465 9d1a5ce9c33350d2deb004808e8c65248ac1dc7a
child 428467 c856f513264340a2d6c2b70f71f345b5e4c8d6c0
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1370412
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1370412 - Part 7. ImageSurfaceCache::Lookup should enter factor of 2 mode on cache misses. r=tnikkel
image/SurfaceCache.cpp
--- a/image/SurfaceCache.cpp
+++ b/image/SurfaceCache.cpp
@@ -271,20 +271,29 @@ public:
     MOZ_ASSERT(mSurfaces.GetWeak(aSurface->GetSurfaceKey()),
         "Should not be removing a surface we don't have");
 
     RefPtr<CachedSurface> surface;
     mSurfaces.Remove(aSurface->GetSurfaceKey(), getter_AddRefs(surface));
     return surface.forget();
   }
 
-  already_AddRefed<CachedSurface> Lookup(const SurfaceKey& aSurfaceKey)
+  already_AddRefed<CachedSurface> Lookup(const SurfaceKey& aSurfaceKey,
+                                         bool aForAccess)
   {
     RefPtr<CachedSurface> surface;
     mSurfaces.Get(aSurfaceKey, getter_AddRefs(surface));
+
+    // If no exact match is found, and this is for use rather than internal
+    // accounting (i.e. insert and removal), we know this will trigger a
+    // decode. Make sure we switch now to factor of 2 mode if necessary.
+    if (!surface && aForAccess && !mFactor2Mode) {
+      MaybeSetFactor2Mode();
+    }
+
     return surface.forget();
   }
 
   /**
    * @returns A tuple containing the best matching CachedSurface if available,
    *          a MatchType describing how the CachedSurface was selected, and
    *          an IntSize which is the size the caller should choose to decode
    *          at should it attempt to do so.
@@ -754,17 +763,17 @@ public:
                       bool aMarkUsed = true)
   {
     RefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
     if (!cache) {
       // No cached surfaces for this image.
       return LookupResult(MatchType::NOT_FOUND);
     }
 
-    RefPtr<CachedSurface> surface = cache->Lookup(aSurfaceKey);
+    RefPtr<CachedSurface> surface = cache->Lookup(aSurfaceKey, aMarkUsed);
     if (!surface) {
       // Lookup in the per-image cache missed.
       return LookupResult(MatchType::NOT_FOUND);
     }
 
     if (surface->IsPlaceholder()) {
       return LookupResult(MatchType::PENDING);
     }
@@ -1094,17 +1103,18 @@ private:
                    const SurfaceKey& aSurfaceKey,
                    const StaticMutexAutoLock& aAutoLock)
   {
     RefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
     if (!cache) {
       return;  // No cached surfaces for this image.
     }
 
-    RefPtr<CachedSurface> surface = cache->Lookup(aSurfaceKey);
+    RefPtr<CachedSurface> surface =
+      cache->Lookup(aSurfaceKey, /* aForAccess = */ false);
     if (!surface) {
       return;  // Lookup in the per-image cache missed.
     }
 
     Remove(WrapNotNull(surface), aAutoLock);
   }
 
   class SurfaceTracker final :