Bug 1370412 - Part 0. Add imgIContainer::GetNativeSizesLength to determine a ceiling on the maximum number of expected, unique surfaces. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Tue, 05 Sep 2017 07:58:44 -0400
changeset 378896 83c49f7c9c9909302af341bd5b288dc2d9f3e4d7
parent 378895 25180e78cdc7374ee2ed57d65087962e75d1ce9b
child 378897 b9e5d359e10e0700cec1a04bff36b4b11d6ccfa0
push id94531
push useraosmond@gmail.com
push dateTue, 05 Sep 2017 11:58:59 +0000
treeherdermozilla-inbound@e273a191e75d [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 0. Add imgIContainer::GetNativeSizesLength to determine a ceiling on the maximum number of expected, unique surfaces. r=tnikkel
image/DynamicImage.cpp
image/DynamicImage.h
image/ImageWrapper.cpp
image/ImageWrapper.h
image/RasterImage.cpp
image/RasterImage.h
image/VectorImage.cpp
image/VectorImage.h
image/imgIContainer.idl
--- a/image/DynamicImage.cpp
+++ b/image/DynamicImage.cpp
@@ -129,16 +129,22 @@ DynamicImage::GetHeight(int32_t* aHeight
 }
 
 nsresult
 DynamicImage::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
+size_t
+DynamicImage::GetNativeSizesLength() const
+{
+  return 0;
+}
+
 NS_IMETHODIMP
 DynamicImage::GetIntrinsicSize(nsSize* aSize)
 {
   IntSize intSize(mDrawable->Size());
   *aSize = nsSize(intSize.width, intSize.height);
   return NS_OK;
 }
 
--- a/image/DynamicImage.h
+++ b/image/DynamicImage.h
@@ -27,16 +27,17 @@ public:
   explicit DynamicImage(gfxDrawable* aDrawable)
     : mDrawable(aDrawable)
   {
     MOZ_ASSERT(aDrawable, "Must have a gfxDrawable to wrap");
   }
 
   // Inherited methods from Image.
   nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
+  size_t GetNativeSizesLength() const override;
   virtual already_AddRefed<ProgressTracker> GetProgressTracker() override;
   virtual size_t SizeOfSourceWithComputedFallback(
                                  SizeOfState& aState) const override;
   virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
                                      MallocSizeOf aMallocSizeOf) const override;
 
   virtual void IncrementAnimationConsumers() override;
   virtual void DecrementAnimationConsumers() override;
--- a/image/ImageWrapper.cpp
+++ b/image/ImageWrapper.cpp
@@ -140,16 +140,22 @@ ImageWrapper::GetHeight(int32_t* aHeight
 }
 
 nsresult
 ImageWrapper::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const
 {
   return mInnerImage->GetNativeSizes(aNativeSizes);
 }
 
+size_t
+ImageWrapper::GetNativeSizesLength() const
+{
+  return mInnerImage->GetNativeSizesLength();
+}
+
 NS_IMETHODIMP
 ImageWrapper::GetIntrinsicSize(nsSize* aSize)
 {
   return mInnerImage->GetIntrinsicSize(aSize);
 }
 
 NS_IMETHODIMP
 ImageWrapper::GetIntrinsicRatio(nsSize* aSize)
--- a/image/ImageWrapper.h
+++ b/image/ImageWrapper.h
@@ -18,16 +18,17 @@ namespace image {
 class ImageWrapper : public Image
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_IMGICONTAINER
 
   // Inherited methods from Image.
   nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
+  size_t GetNativeSizesLength() const override;
   virtual already_AddRefed<ProgressTracker> GetProgressTracker() override;
 
   virtual size_t
     SizeOfSourceWithComputedFallback(SizeOfState& aState) const override;
   virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
                                      MallocSizeOf aMallocSizeOf) const override;
 
   virtual void IncrementAnimationConsumers() override;
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -237,16 +237,31 @@ RasterImage::GetNativeSizes(nsTArray<Int
   } else {
     aNativeSizes = mNativeSizes;
   }
 
   return NS_OK;
 }
 
 //******************************************************************************
+size_t
+RasterImage::GetNativeSizesLength() const
+{
+  if (mError || !mHasSize) {
+    return 0;
+  }
+
+  if (mNativeSizes.IsEmpty()) {
+    return 1;
+  }
+
+  return mNativeSizes.Length();
+}
+
+//******************************************************************************
 NS_IMETHODIMP
 RasterImage::GetIntrinsicSize(nsSize* aSize)
 {
   if (mError) {
     return NS_ERROR_FAILURE;
   }
 
   *aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
--- a/image/RasterImage.h
+++ b/image/RasterImage.h
@@ -156,16 +156,17 @@ public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIPROPERTIES
   NS_DECL_IMGICONTAINER
 #ifdef DEBUG
   NS_DECL_IMGICONTAINERDEBUG
 #endif
 
   nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
+  size_t GetNativeSizesLength() const override;
   virtual nsresult StartAnimation() override;
   virtual nsresult StopAnimation() override;
 
   // Methods inherited from Image
   virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
 
   virtual size_t SizeOfSourceWithComputedFallback(SizeOfState& aState)
     const override;
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -524,16 +524,23 @@ VectorImage::GetWidth(int32_t* aWidth)
 //******************************************************************************
 nsresult
 VectorImage::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 //******************************************************************************
+size_t
+VectorImage::GetNativeSizesLength() const
+{
+  return 0;
+}
+
+//******************************************************************************
 NS_IMETHODIMP_(void)
 VectorImage::RequestRefresh(const TimeStamp& aTime)
 {
   if (HadRecentRefresh(aTime)) {
     return;
   }
 
   PendingAnimationTracker* tracker =
--- a/image/VectorImage.h
+++ b/image/VectorImage.h
@@ -30,16 +30,17 @@ public:
   NS_DECL_NSIREQUESTOBSERVER
   NS_DECL_NSISTREAMLISTENER
   NS_DECL_IMGICONTAINER
 
   // (no public constructor - use ImageFactory)
 
   // Methods inherited from Image
   nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
+  size_t GetNativeSizesLength() const override;
   virtual size_t SizeOfSourceWithComputedFallback(SizeOfState& aState)
     const override;
   virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
                                      MallocSizeOf aMallocSizeOf) const override;
 
   virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
                                         nsISupports* aContext,
                                         nsIInputStream* aInStr,
--- a/image/imgIContainer.idl
+++ b/image/imgIContainer.idl
@@ -560,10 +560,12 @@ interface imgIContainer : nsISupports
    */
   [noscript, notxpcom] void propagateUseCounters(in nsIDocument aDocument);
 
   %{C++
   /*
    * Get the set of sizes the image can decode to natively.
    */
   virtual nsresult GetNativeSizes(nsTArray<nsIntSize>& aNativeSizes) const = 0;
+
+  virtual size_t GetNativeSizesLength() const = 0;
   %}
 };