Bug 1370412 - Part 9. Add factor of 2 state to the SurfaceCache memory reports. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Tue, 05 Sep 2017 07:58:46 -0400
changeset 378985 5cd1c5cd9b0154c25a5bb8971dfb5e7fc0583987
parent 378984 85cdb40c26211ea3288c46927641e14f0f5661d9
child 378986 e273a191e75d48429d7a11ab216874ce15e24e33
push id32446
push userarchaeopteryx@coole-files.de
push dateTue, 05 Sep 2017 21:56:34 +0000
treeherdermozilla-central@f64e2b4dcf5e [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 9. Add factor of 2 state to the SurfaceCache memory reports. r=tnikkel
image/FrameAnimator.cpp
image/Image.h
image/SurfaceCache.cpp
image/imgLoader.cpp
--- a/image/FrameAnimator.cpp
+++ b/image/FrameAnimator.cpp
@@ -525,17 +525,19 @@ DoCollectSizeOfCompositingSurfaces(const
                                    MallocSizeOf aMallocSizeOf)
 {
   // Concoct a SurfaceKey for this surface.
   SurfaceKey key = RasterSurfaceKey(aSurface->GetImageSize(),
                                     DefaultSurfaceFlags(),
                                     PlaybackType::eStatic);
 
   // Create a counter for this surface.
-  SurfaceMemoryCounter counter(key, /* aIsLocked = */ true, aType);
+  SurfaceMemoryCounter counter(key, /* aIsLocked = */ true,
+                               /* aCannotSubstitute */ false,
+                               /* aIsFactor2 */ false, aType);
 
   // Extract the surface's memory usage information.
   size_t heap = 0, nonHeap = 0, handles = 0;
   aSurface->AddSizeOfExcludingThis(aMallocSizeOf, heap, nonHeap, handles);
   counter.Values().SetDecodedHeap(heap);
   counter.Values().SetDecodedNonHeap(nonHeap);
   counter.Values().SetSharedHandles(handles);
 
--- a/image/Image.h
+++ b/image/Image.h
@@ -67,34 +67,42 @@ enum class SurfaceMemoryCounterType
   COMPOSITING,
   COMPOSITING_PREV
 };
 
 struct SurfaceMemoryCounter
 {
   SurfaceMemoryCounter(const SurfaceKey& aKey,
                        bool aIsLocked,
+                       bool aCannotSubstitute,
+                       bool aIsFactor2,
                        SurfaceMemoryCounterType aType =
                          SurfaceMemoryCounterType::NORMAL)
     : mKey(aKey)
     , mType(aType)
     , mIsLocked(aIsLocked)
+    , mCannotSubstitute(aCannotSubstitute)
+    , mIsFactor2(aIsFactor2)
   { }
 
   const SurfaceKey& Key() const { return mKey; }
   MemoryCounter& Values() { return mValues; }
   const MemoryCounter& Values() const { return mValues; }
   SurfaceMemoryCounterType Type() const { return mType; }
   bool IsLocked() const { return mIsLocked; }
+  bool CannotSubstitute() const { return mCannotSubstitute; }
+  bool IsFactor2() const { return mIsFactor2; }
 
 private:
   const SurfaceKey mKey;
   MemoryCounter mValues;
   const SurfaceMemoryCounterType mType;
   const bool mIsLocked;
+  const bool mCannotSubstitute;
+  const bool mIsFactor2;
 };
 
 struct ImageMemoryCounter
 {
   ImageMemoryCounter(Image* aImage, SizeOfState& aState, bool aIsUsed);
 
   nsCString& URI() { return mURI; }
   const nsCString& URI() const { return mURI; }
--- a/image/SurfaceCache.cpp
+++ b/image/SurfaceCache.cpp
@@ -180,20 +180,22 @@ public:
   struct MOZ_STACK_CLASS SurfaceMemoryReport
   {
     SurfaceMemoryReport(nsTArray<SurfaceMemoryCounter>& aCounters,
                         MallocSizeOf                    aMallocSizeOf)
       : mCounters(aCounters)
       , mMallocSizeOf(aMallocSizeOf)
     { }
 
-    void Add(NotNull<CachedSurface*> aCachedSurface)
+    void Add(NotNull<CachedSurface*> aCachedSurface, bool aIsFactor2)
     {
       SurfaceMemoryCounter counter(aCachedSurface->GetSurfaceKey(),
-                                   aCachedSurface->IsLocked());
+                                   aCachedSurface->IsLocked(),
+                                   aCachedSurface->CannotSubstitute(),
+                                   aIsFactor2);
 
       if (aCachedSurface->IsPlaceholder()) {
         return;
       }
 
       // Record the memory used by the ISurfaceProvider. This may not have a
       // straightforward relationship to the size of the surface that
       // DrawableRef() returns if the surface is generated dynamically. (i.e.,
@@ -593,16 +595,31 @@ public:
     if (idealArea <= currentArea && currentArea < bestMatchArea) {
       return true;
     }
 
     // This surface isn't an improvement over the current best match.
     return false;
   }
 
+  void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
+                             MallocSizeOf                    aMallocSizeOf)
+  {
+    CachedSurface::SurfaceMemoryReport report(aCounters, aMallocSizeOf);
+    for (auto iter = ConstIter(); !iter.Done(); iter.Next()) {
+      NotNull<CachedSurface*> surface = WrapNotNull(iter.UserData());
+      const IntSize& size = surface->GetSurfaceKey().Size();
+      bool factor2Size = false;
+      if (mFactor2Mode) {
+        factor2Size = (size == SuggestedSize(size));
+      }
+      report.Add(surface, factor2Size);
+    }
+  }
+
   SurfaceTable::Iterator ConstIter() const
   {
     return mSurfaces.ConstIter();
   }
 
   void SetLocked(bool aLocked) { mLocked = aLocked; }
   bool IsLocked() const { return mLocked; }
 
@@ -1117,20 +1134,17 @@ public:
                              MallocSizeOf                    aMallocSizeOf)
   {
     RefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
     if (!cache) {
       return;  // No surfaces for this image.
     }
 
     // Report all surfaces in the per-image cache.
-    CachedSurface::SurfaceMemoryReport report(aCounters, aMallocSizeOf);
-    for (auto iter = cache->ConstIter(); !iter.Done(); iter.Next()) {
-      report.Add(WrapNotNull(iter.UserData()));
-    }
+    cache->CollectSizeOfSurfaces(aCounters, aMallocSizeOf);
   }
 
 private:
   already_AddRefed<ImageSurfaceCache> GetImageCache(const ImageKey aImageKey)
   {
     RefPtr<ImageSurfaceCache> imageCache;
     mImageCaches.Get(aImageKey, getter_AddRefs(imageCache));
     return imageCache.forget();
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -276,16 +276,22 @@ private:
   static void ReportSurfaces(nsIHandleReportCallback* aHandleReport,
                              nsISupports* aData,
                              const nsACString& aPathPrefix,
                              const ImageMemoryCounter& aCounter)
   {
     for (const SurfaceMemoryCounter& counter : aCounter.Surfaces()) {
       nsAutoCString surfacePathPrefix(aPathPrefix);
       surfacePathPrefix.Append(counter.IsLocked() ? "locked/" : "unlocked/");
+      if (counter.IsFactor2()) {
+        surfacePathPrefix.Append("factor2/");
+      }
+      if (counter.CannotSubstitute()) {
+        surfacePathPrefix.Append("cannot_substitute/");
+      }
       surfacePathPrefix.Append("surface(");
       surfacePathPrefix.AppendInt(counter.Key().Size().width);
       surfacePathPrefix.Append("x");
       surfacePathPrefix.AppendInt(counter.Key().Size().height);
 
       if (counter.Values().SharedHandles() > 0) {
         surfacePathPrefix.Append(", shared:");
         surfacePathPrefix.AppendInt(uint32_t(counter.Values().SharedHandles()));