From 480d81cc52ba1c2f633b4a3dd9268455e20beb4a Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Tue, 5 Sep 2017 07:58:44 -0400 Subject: [PATCH] Bug 1370412 - Part 0. Add imgIContainer::GetNativeSizesLength to determine a ceiling on the maximum number of expected, unique surfaces. r=tnikkel --- image/DynamicImage.cpp | 6 ++++++ image/DynamicImage.h | 1 + image/ImageWrapper.cpp | 6 ++++++ image/ImageWrapper.h | 1 + image/RasterImage.cpp | 15 +++++++++++++++ image/RasterImage.h | 1 + image/VectorImage.cpp | 7 +++++++ image/VectorImage.h | 1 + image/imgIContainer.idl | 2 ++ 9 files changed, 40 insertions(+) diff --git a/image/DynamicImage.cpp b/image/DynamicImage.cpp index a019f8e8ce5e..2bd339e7cf5b 100644 --- a/image/DynamicImage.cpp +++ b/image/DynamicImage.cpp @@ -134,6 +134,12 @@ DynamicImage::GetNativeSizes(nsTArray& aNativeSizes) const return NS_ERROR_NOT_IMPLEMENTED; } +size_t +DynamicImage::GetNativeSizesLength() const +{ + return 0; +} + NS_IMETHODIMP DynamicImage::GetIntrinsicSize(nsSize* aSize) { diff --git a/image/DynamicImage.h b/image/DynamicImage.h index d65e9b265631..716f1e2f2870 100644 --- a/image/DynamicImage.h +++ b/image/DynamicImage.h @@ -32,6 +32,7 @@ public: // Inherited methods from Image. nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; + size_t GetNativeSizesLength() const override; virtual already_AddRefed GetProgressTracker() override; virtual size_t SizeOfSourceWithComputedFallback( SizeOfState& aState) const override; diff --git a/image/ImageWrapper.cpp b/image/ImageWrapper.cpp index a9d48142d381..8be7eb9a0c9e 100644 --- a/image/ImageWrapper.cpp +++ b/image/ImageWrapper.cpp @@ -145,6 +145,12 @@ ImageWrapper::GetNativeSizes(nsTArray& aNativeSizes) const return mInnerImage->GetNativeSizes(aNativeSizes); } +size_t +ImageWrapper::GetNativeSizesLength() const +{ + return mInnerImage->GetNativeSizesLength(); +} + NS_IMETHODIMP ImageWrapper::GetIntrinsicSize(nsSize* aSize) { diff --git a/image/ImageWrapper.h b/image/ImageWrapper.h index 40e0112a948c..061eac637328 100644 --- a/image/ImageWrapper.h +++ b/image/ImageWrapper.h @@ -23,6 +23,7 @@ public: // Inherited methods from Image. nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; + size_t GetNativeSizesLength() const override; virtual already_AddRefed GetProgressTracker() override; virtual size_t diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index 908bd9f683e3..657fcc94d912 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -241,6 +241,21 @@ RasterImage::GetNativeSizes(nsTArray& aNativeSizes) const 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) diff --git a/image/RasterImage.h b/image/RasterImage.h index fa669b9dffbf..c3e4a80fabf4 100644 --- a/image/RasterImage.h +++ b/image/RasterImage.h @@ -161,6 +161,7 @@ public: #endif nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; + size_t GetNativeSizesLength() const override; virtual nsresult StartAnimation() override; virtual nsresult StopAnimation() override; diff --git a/image/VectorImage.cpp b/image/VectorImage.cpp index 89f30eb7cf1e..3328cbbdfd2a 100644 --- a/image/VectorImage.cpp +++ b/image/VectorImage.cpp @@ -528,6 +528,13 @@ VectorImage::GetNativeSizes(nsTArray& aNativeSizes) const return NS_ERROR_NOT_IMPLEMENTED; } +//****************************************************************************** +size_t +VectorImage::GetNativeSizesLength() const +{ + return 0; +} + //****************************************************************************** NS_IMETHODIMP_(void) VectorImage::RequestRefresh(const TimeStamp& aTime) diff --git a/image/VectorImage.h b/image/VectorImage.h index a56025697cff..454a0764173f 100644 --- a/image/VectorImage.h +++ b/image/VectorImage.h @@ -35,6 +35,7 @@ public: // Methods inherited from Image nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; + size_t GetNativeSizesLength() const override; virtual size_t SizeOfSourceWithComputedFallback(SizeOfState& aState) const override; virtual void CollectSizeOfSurfaces(nsTArray& aCounters, diff --git a/image/imgIContainer.idl b/image/imgIContainer.idl index 49f9f35b68a5..cfa8886f3aba 100644 --- a/image/imgIContainer.idl +++ b/image/imgIContainer.idl @@ -565,5 +565,7 @@ interface imgIContainer : nsISupports * Get the set of sizes the image can decode to natively. */ virtual nsresult GetNativeSizes(nsTArray& aNativeSizes) const = 0; + + virtual size_t GetNativeSizesLength() const = 0; %} };