Bug 1286161 (Part 1) - Expose SourceBuffer and SurfaceCache constants which are useful for testing. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Sun, 10 Jul 2016 23:48:17 -0700
changeset 347297 a6d457ff02be518c5ba3f2d278501e9fbb594069
parent 347296 515b58073c4619d3c08391beef75e479b5b896f3
child 347298 762323d53afaf171645aa0117bad84ed19842fc9
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1286161
milestone50.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 1286161 (Part 1) - Expose SourceBuffer and SurfaceCache constants which are useful for testing. r=edwin
image/SourceBuffer.cpp
image/SourceBuffer.h
image/SurfaceCache.cpp
image/SurfaceCache.h
--- a/image/SourceBuffer.cpp
+++ b/image/SourceBuffer.cpp
@@ -100,16 +100,18 @@ SourceBufferIterator::RemainingBytesIsNo
   return mOwner->RemainingBytesIsNoMoreThan(*this, aBytes);
 }
 
 
 //////////////////////////////////////////////////////////////////////////////
 // SourceBuffer implementation.
 //////////////////////////////////////////////////////////////////////////////
 
+const size_t SourceBuffer::MIN_CHUNK_CAPACITY;
+
 SourceBuffer::SourceBuffer()
   : mMutex("image::SourceBuffer")
   , mConsumerCount(0)
 { }
 
 SourceBuffer::~SourceBuffer()
 {
   MOZ_ASSERT(mConsumerCount == 0,
--- a/image/SourceBuffer.h
+++ b/image/SourceBuffer.h
@@ -318,16 +318,28 @@ public:
   //////////////////////////////////////////////////////////////////////////////
   // Consumer methods.
   //////////////////////////////////////////////////////////////////////////////
 
   /// Returns an iterator to this SourceBuffer.
   SourceBufferIterator Iterator();
 
 
+  //////////////////////////////////////////////////////////////////////////////
+  // Consumer methods.
+  //////////////////////////////////////////////////////////////////////////////
+
+  /**
+   * The minimum chunk capacity we'll allocate, if we don't know the correct
+   * capacity (which would happen because ExpectLength() wasn't called or gave
+   * us the wrong value). This is only exposed for use by tests; if normal code
+   * is using this, it's doing something wrong.
+   */
+  static const size_t MIN_CHUNK_CAPACITY = 4096;
+
 private:
   friend class SourceBufferIterator;
 
   ~SourceBuffer();
 
   //////////////////////////////////////////////////////////////////////////////
   // Chunk type and chunk-related methods.
   //////////////////////////////////////////////////////////////////////////////
@@ -419,18 +431,16 @@ private:
   bool IsEmpty();
   bool IsLastChunk(uint32_t aChunk);
 
 
   //////////////////////////////////////////////////////////////////////////////
   // Member variables.
   //////////////////////////////////////////////////////////////////////////////
 
-  static const size_t MIN_CHUNK_CAPACITY = 4096;
-
   /// All private members are protected by mMutex.
   mutable Mutex mMutex;
 
   /// The data in this SourceBuffer, stored as a series of Chunks.
   FallibleTArray<Chunk> mChunks;
 
   /// Consumers which are waiting to be notified when new data is available.
   nsTArray<RefPtr<IResumable>> mWaitingConsumers;
--- a/image/SurfaceCache.cpp
+++ b/image/SurfaceCache.cpp
@@ -655,16 +655,21 @@ public:
     return LookupResult(Move(ref), matchType);
   }
 
   bool CanHold(const Cost aCost) const
   {
     return aCost <= mMaxCost;
   }
 
+  size_t MaximumCapacity() const
+  {
+    return size_t(mMaxCost);
+  }
+
   void LockImage(const ImageKey aImageKey)
   {
     RefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
     if (!cache) {
       cache = new ImageSurfaceCache;
       mImageCaches.Put(aImageKey, cache);
     }
 
@@ -1121,10 +1126,21 @@ SurfaceCache::CollectSizeOfSurfaces(cons
   if (!sInstance) {
     return;
   }
 
   MutexAutoLock lock(sInstance->GetMutex());
   return sInstance->CollectSizeOfSurfaces(aImageKey, aCounters, aMallocSizeOf);
 }
 
+/* static */ size_t
+SurfaceCache::MaximumCapacity()
+{
+  if (!sInstance) {
+    return 0;
+  }
+
+  MutexAutoLock lock(sInstance->GetMutex());
+  return sInstance->MaximumCapacity();
+}
+
 } // namespace image
 } // namespace mozilla
--- a/image/SurfaceCache.h
+++ b/image/SurfaceCache.h
@@ -394,16 +394,22 @@ struct SurfaceCache
    * @param aCounters     An array into which the report for each surface will
    *                      be written.
    * @param aMallocSizeOf A fallback malloc memory reporting function.
    */
   static void CollectSizeOfSurfaces(const ImageKey    aImageKey,
                                     nsTArray<SurfaceMemoryCounter>& aCounters,
                                     MallocSizeOf      aMallocSizeOf);
 
+  /**
+   * @return maximum capacity of the SurfaceCache in bytes. This is only exposed
+   * for use by tests; normal code should use CanHold() instead.
+   */
+  static size_t MaximumCapacity();
+
 private:
   virtual ~SurfaceCache() = 0;  // Forbid instantiation.
 };
 
 } // namespace image
 } // namespace mozilla
 
 #endif // mozilla_image_SurfaceCache_h