Bug 1116719 - Remove Image::FrameRect. r=tn
authorSeth Fowler <seth@mozilla.com>
Wed, 07 Jan 2015 01:40:23 -0800
changeset 235456 3f32666fc1dc747ade2aa2d5d9db7e59cc934cd9
parent 235455 da5084c9e3e640723ff9541da88fe150c294739c
child 235457 6e4dce410c272c458fd4772644e759d043ba0e8b
push id366
push usercmanchester@mozilla.com
push dateThu, 08 Jan 2015 16:40:24 +0000
reviewerstn
bugs1116719
milestone37.0a1
Bug 1116719 - Remove Image::FrameRect. r=tn
image/src/ClippedImage.cpp
image/src/ClippedImage.h
image/src/DynamicImage.cpp
image/src/DynamicImage.h
image/src/FrozenImage.cpp
image/src/FrozenImage.h
image/src/Image.h
image/src/ImageWrapper.cpp
image/src/ImageWrapper.h
image/src/OrientedImage.cpp
image/src/OrientedImage.h
image/src/ProgressTracker.cpp
image/src/RasterImage.cpp
image/src/RasterImage.h
image/src/VectorImage.cpp
image/src/VectorImage.h
--- a/image/src/ClippedImage.cpp
+++ b/image/src/ClippedImage.cpp
@@ -160,26 +160,16 @@ ClippedImage::ShouldClip()
   }
 
   MOZ_ASSERT(mShouldClip.isSome(), "Should have computed a result");
   return *mShouldClip;
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(ClippedImage, ImageWrapper)
 
-nsIntRect
-ClippedImage::FrameRect(uint32_t aWhichFrame)
-{
-  if (!ShouldClip()) {
-    return InnerImage()->FrameRect(aWhichFrame);
-  }
-
-  return nsIntRect(0, 0, mClip.width, mClip.height);
-}
-
 NS_IMETHODIMP
 ClippedImage::GetWidth(int32_t* aWidth)
 {
   if (!ShouldClip()) {
     return InnerImage()->GetWidth(aWidth);
   }
 
   *aWidth = mClip.width;
--- a/image/src/ClippedImage.h
+++ b/image/src/ClippedImage.h
@@ -26,18 +26,16 @@ class DrawSingleTileCallback;
  */
 class ClippedImage : public ImageWrapper
 {
   typedef gfx::SourceSurface SourceSurface;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
-
   NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE;
   NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
   NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
   NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
   NS_IMETHOD_(TemporaryRef<SourceSurface>)
     GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE;
   NS_IMETHOD GetImageContainer(layers::LayerManager* aManager,
                                layers::ImageContainer** _retval) MOZ_OVERRIDE;
--- a/image/src/DynamicImage.cpp
+++ b/image/src/DynamicImage.cpp
@@ -31,23 +31,16 @@ DynamicImage::Init(const char* aMimeType
 }
 
 already_AddRefed<ProgressTracker>
 DynamicImage::GetProgressTracker()
 {
   return nullptr;
 }
 
-nsIntRect
-DynamicImage::FrameRect(uint32_t aWhichFrame)
-{
-  gfxIntSize size(mDrawable->Size());
-  return nsIntRect(0, 0, size.width, size.height);
-}
-
 size_t
 DynamicImage::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const
 {
   return 0;
 }
 
 size_t
 DynamicImage::SizeOfDecoded(gfxMemoryLocation aLocation,
--- a/image/src/DynamicImage.h
+++ b/image/src/DynamicImage.h
@@ -29,17 +29,16 @@ public:
   {
     MOZ_ASSERT(aDrawable, "Must have a gfxDrawable to wrap");
   }
 
   // Inherited methods from Image.
   virtual nsresult Init(const char* aMimeType, uint32_t aFlags) MOZ_OVERRIDE;
 
   virtual already_AddRefed<ProgressTracker> GetProgressTracker() MOZ_OVERRIDE;
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
   virtual size_t SizeOfSourceWithComputedFallback(
                                  MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
   virtual size_t SizeOfDecoded(gfxMemoryLocation aLocation,
                                MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
 
   virtual void IncrementAnimationConsumers() MOZ_OVERRIDE;
   virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
 #ifdef DEBUG
--- a/image/src/FrozenImage.cpp
+++ b/image/src/FrozenImage.cpp
@@ -8,22 +8,16 @@
 namespace mozilla {
 
 using namespace gfx;
 
 namespace image {
 
 NS_IMPL_ISUPPORTS_INHERITED0(FrozenImage, ImageWrapper)
 
-nsIntRect
-FrozenImage::FrameRect(uint32_t /* aWhichFrame - ignored */)
-{
-  return InnerImage()->FrameRect(FRAME_FIRST);
-}
-
 void
 FrozenImage::IncrementAnimationConsumers()
 {
   // Do nothing. This will prevent animation from starting if there are no other
   // instances of this image.
 }
 
 void
--- a/image/src/FrozenImage.h
+++ b/image/src/FrozenImage.h
@@ -26,17 +26,16 @@ namespace image {
  */
 class FrozenImage : public ImageWrapper
 {
   typedef gfx::SourceSurface SourceSurface;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
   virtual void IncrementAnimationConsumers() MOZ_OVERRIDE;
   virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
 
   NS_IMETHOD GetAnimated(bool* aAnimated) MOZ_OVERRIDE;
   NS_IMETHOD_(TemporaryRef<SourceSurface>)
     GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE;
   NS_IMETHOD GetImageContainer(layers::LayerManager* aManager,
                                layers::ImageContainer** _retval) MOZ_OVERRIDE;
--- a/image/src/Image.h
+++ b/image/src/Image.h
@@ -66,21 +66,16 @@ public:
    */
   virtual nsresult Init(const char* aMimeType,
                         uint32_t aFlags) = 0;
 
   virtual already_AddRefed<ProgressTracker> GetProgressTracker() = 0;
   virtual void SetProgressTracker(ProgressTracker* aProgressTracker) {}
 
   /**
-   * The rectangle defining the location and size of the given frame.
-   */
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) = 0;
-
-  /**
    * The size, in bytes, occupied by the compressed source data of the image.
    * If MallocSizeOf does not work on this platform, uses a fallback approach to
    * ensure that something reasonable is always returned.
    */
   virtual size_t SizeOfSourceWithComputedFallback(
                                           MallocSizeOf aMallocSizeOf) const = 0;
 
   /**
--- a/image/src/ImageWrapper.cpp
+++ b/image/src/ImageWrapper.cpp
@@ -28,22 +28,16 @@ ImageWrapper::Init(const char* aMimeType
 }
 
 already_AddRefed<ProgressTracker>
 ImageWrapper::GetProgressTracker()
 {
   return mInnerImage->GetProgressTracker();
 }
 
-nsIntRect
-ImageWrapper::FrameRect(uint32_t aWhichFrame)
-{
-  return mInnerImage->FrameRect(aWhichFrame);
-}
-
 size_t
 ImageWrapper::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const
 {
   return mInnerImage->SizeOfSourceWithComputedFallback(aMallocSizeOf);
 }
 
 size_t
 ImageWrapper::SizeOfDecoded(gfxMemoryLocation aLocation,
--- a/image/src/ImageWrapper.h
+++ b/image/src/ImageWrapper.h
@@ -20,17 +20,16 @@ class ImageWrapper : public Image
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_IMGICONTAINER
 
   // Inherited methods from Image.
   virtual nsresult Init(const char* aMimeType, uint32_t aFlags) MOZ_OVERRIDE;
 
   virtual already_AddRefed<ProgressTracker> GetProgressTracker() MOZ_OVERRIDE;
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
 
   virtual size_t
   SizeOfSourceWithComputedFallback( MallocSizeOf aMallocSizeOf) const
       MOZ_OVERRIDE;
   virtual size_t
   SizeOfDecoded(gfxMemoryLocation aLocation,
                 MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
 
--- a/image/src/OrientedImage.cpp
+++ b/image/src/OrientedImage.cpp
@@ -21,39 +21,16 @@ namespace mozilla {
 using namespace gfx;
 using layers::LayerManager;
 using layers::ImageContainer;
 
 namespace image {
 
 NS_IMPL_ISUPPORTS_INHERITED0(OrientedImage, ImageWrapper)
 
-nsIntRect
-OrientedImage::FrameRect(uint32_t aWhichFrame)
-{
-  nsresult rv;
-
-  // Retrieve the frame rect of the inner image.
-  nsIntRect innerRect = InnerImage()->FrameRect(aWhichFrame);
-  if (mOrientation.IsIdentity()) {
-    return innerRect;
-  }
-
-  // Get the underlying image's dimensions.
-  nsIntSize size;
-  rv = InnerImage()->GetWidth(&size.width);
-  NS_ENSURE_SUCCESS(rv, innerRect);
-  rv = InnerImage()->GetHeight(&size.height);
-  NS_ENSURE_SUCCESS(rv, innerRect);
-
-  // Transform the frame rect.
-  gfxRect finalRect = OrientationMatrix(size).TransformBounds(innerRect);
-  return nsIntRect(finalRect.x, finalRect.y, finalRect.width, finalRect.height);
-}
-
 NS_IMETHODIMP
 OrientedImage::GetWidth(int32_t* aWidth)
 {
   if (mOrientation.SwapsWidthAndHeight()) {
     return InnerImage()->GetHeight(aWidth);
   } else {
     return InnerImage()->GetWidth(aWidth);
   }
--- a/image/src/OrientedImage.h
+++ b/image/src/OrientedImage.h
@@ -23,18 +23,16 @@ namespace image {
  */
 class OrientedImage : public ImageWrapper
 {
   typedef gfx::SourceSurface SourceSurface;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
-
   NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE;
   NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
   NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
   NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
   NS_IMETHOD_(TemporaryRef<SourceSurface>)
     GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE;
   NS_IMETHOD GetImageContainer(layers::LayerManager* aManager,
                                layers::ImageContainer** _retval) MOZ_OVERRIDE;
--- a/image/src/ProgressTracker.cpp
+++ b/image/src/ProgressTracker.cpp
@@ -382,26 +382,28 @@ ProgressTracker::SyncNotify(IProgressObs
   nsAutoCString spec;
   if (mImage && mImage->GetURI()) {
     mImage->GetURI()->GetSpec(spec);
   }
   LOG_SCOPE_WITH_PARAM(GetImgLog(),
                        "ProgressTracker::SyncNotify", "uri", spec.get());
 #endif
 
-  nsIntRect r;
+  nsIntRect rect;
   if (mImage) {
-    // XXX - Should only send partial rects here, but that needs to
-    // wait until we fix up the observer interface
-    r = mImage->FrameRect(imgIContainer::FRAME_CURRENT);
+    if (NS_FAILED(mImage->GetWidth(&rect.width)) ||
+        NS_FAILED(mImage->GetHeight(&rect.height))) {
+      // Either the image has no intrinsic size, or it has an error.
+      rect = nsIntRect::GetMaxSizedIntRect();
+    }
   }
 
   ObserverArray array;
   array.AppendElement(aObserver);
-  SyncNotifyInternal(array, !!mImage, mProgress, r);
+  SyncNotifyInternal(array, !!mImage, mProgress, rect);
 }
 
 void
 ProgressTracker::EmulateRequestFinished(IProgressObserver* aObserver)
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "SyncNotifyState and mObservers are not threadsafe");
   nsRefPtr<IProgressObserver> kungFuDeathGrip(aObserver);
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -645,50 +645,16 @@ RasterImage::IsOpaque()
   if (!(progress & FLAG_DECODE_COMPLETE)) {
     return false;
   }
 
   // Other, we're opaque if FLAG_HAS_TRANSPARENCY is not set.
   return !(progress & FLAG_HAS_TRANSPARENCY);
 }
 
-nsIntRect
-RasterImage::FrameRect(uint32_t aWhichFrame)
-{
-  if (aWhichFrame > FRAME_MAX_VALUE) {
-    NS_WARNING("aWhichFrame outside valid range!");
-    return nsIntRect();
-  }
-
-  if (!mHasFirstFrame) {
-    return nsIntRect();
-  }
-
-  if (GetNumFrames() == 1) {
-    return nsIntRect(0, 0, mSize.width, mSize.height);
-  }
-
-  // We must be animated, so get the requested frame from our FrameBlender.
-  MOZ_ASSERT(mFrameBlender, "We should be animated here");
-  nsRefPtr<imgFrame> frame =
-    mFrameBlender->RawGetFrame(GetRequestedFrameIndex(aWhichFrame));
-
-  // If we have the frame, use that rectangle.
-  if (frame) {
-    return frame->GetRect();
-  }
-
-  // If the frame doesn't exist, we return the empty rectangle. It's not clear
-  // whether this is appropriate in general, but at the moment the only
-  // consumer of this method is ProgressTracker (when it wants to figure out
-  // dirty rectangles to send out batched observer updates). This should
-  // probably be revisited when we fix bug 503973.
-  return nsIntRect();
-}
-
 void
 RasterImage::OnSurfaceDiscarded()
 {
   if (mProgressTracker) {
     mProgressTracker->OnDiscard();
   }
 }
 
--- a/image/src/RasterImage.h
+++ b/image/src/RasterImage.h
@@ -154,17 +154,17 @@ public:
 #endif
 
   virtual nsresult StartAnimation() MOZ_OVERRIDE;
   virtual nsresult StopAnimation() MOZ_OVERRIDE;
 
   // Methods inherited from Image
   nsresult Init(const char* aMimeType,
                 uint32_t aFlags) MOZ_OVERRIDE;
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
+
   virtual void OnSurfaceDiscarded() MOZ_OVERRIDE;
 
   // Raster-specific methods
   static NS_METHOD WriteToRasterImage(nsIInputStream* aIn, void* aClosure,
                                       const char* aFromRawSegment,
                                       uint32_t aToOffset, uint32_t aCount,
                                       uint32_t* aWriteCount);
 
--- a/image/src/VectorImage.cpp
+++ b/image/src/VectorImage.cpp
@@ -354,22 +354,16 @@ VectorImage::Init(const char* aMimeType,
   MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations && !mError,
              "Flags unexpectedly set before initialization");
   MOZ_ASSERT(!strcmp(aMimeType, IMAGE_SVG_XML), "Unexpected mimetype");
 
   mIsInitialized = true;
   return NS_OK;
 }
 
-nsIntRect
-VectorImage::FrameRect(uint32_t aWhichFrame)
-{
-  return nsIntRect::GetMaxSizedIntRect();
-}
-
 size_t
 VectorImage::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const
 {
   nsIDocument* doc = mSVGDocumentWrapper->GetDocument();
   if (!doc) {
     return 0; // No document, so no memory used for the document.
   }
 
--- a/image/src/VectorImage.h
+++ b/image/src/VectorImage.h
@@ -35,17 +35,16 @@ public:
   NS_DECL_NSISTREAMLISTENER
   NS_DECL_IMGICONTAINER
 
   // (no public constructor - use ImageFactory)
 
   // Methods inherited from Image
   nsresult Init(const char* aMimeType,
                 uint32_t aFlags) MOZ_OVERRIDE;
-  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
 
   virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
   virtual size_t SizeOfDecoded(gfxMemoryLocation aLocation,
                                MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
 
   virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
                                         nsISupports* aContext,
                                         nsIInputStream* aInStr,