Bug 1368776 - Part 3. Move RasterImage::GetCurrentImage to ImageResource. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Fri, 17 Nov 2017 06:45:24 -0500
changeset 392464 92f75e98b12170ba1b8bc1bf7d73ab342b5e383c
parent 392463 ebd9a647eca91474a7fb92235414153b766ca092
child 392465 7ebbec7a624ae13e6a5048b0a57ae9ee87747d41
push id32921
push usernerli@mozilla.com
push dateFri, 17 Nov 2017 22:02:18 +0000
treeherdermozilla-central@daa0dcd1616c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1368776
milestone59.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 1368776 - Part 3. Move RasterImage::GetCurrentImage to ImageResource. r=tnikkel As part of the move, we add a IntSize parameter to ImageResource::GetCurrentImage. This is because we don't have access to the image's size (yet) from ImageResource, but additionally because we will need this anyways when we support multiple image containers at different sizes.
image/Image.cpp
image/Image.h
image/RasterImage.cpp
image/RasterImage.h
--- a/image/Image.cpp
+++ b/image/Image.cpp
@@ -47,16 +47,38 @@ ImageMemoryCounter::ImageMemoryCounter(I
   }
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // Image Base Types
 ///////////////////////////////////////////////////////////////////////////////
 
+Pair<DrawResult, RefPtr<layers::Image>>
+ImageResource::GetCurrentImage(ImageContainer* aContainer,
+                               const IntSize& aSize,
+                               uint32_t aFlags)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aContainer);
+
+  DrawResult drawResult;
+  RefPtr<SourceSurface> surface;
+  Tie(drawResult, surface) =
+    GetFrameInternal(aSize, FRAME_CURRENT, aFlags | FLAG_ASYNC_NOTIFY);
+  if (!surface) {
+    // The OS threw out some or all of our buffer. We'll need to wait for the
+    // redecode (which was automatically triggered by GetFrame) to complete.
+    return MakePair(drawResult, RefPtr<layers::Image>());
+  }
+
+  RefPtr<layers::Image> image = new layers::SourceSurfaceImage(surface);
+  return MakePair(drawResult, Move(image));
+}
+
 already_AddRefed<ImageContainer>
 ImageResource::GetImageContainerImpl(LayerManager* aManager,
                                      const IntSize& aSize,
                                      uint32_t aFlags)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aManager);
   MOZ_ASSERT((aFlags & ~(FLAG_SYNC_DECODE |
@@ -84,17 +106,17 @@ ImageResource::GetImageContainerImpl(Lay
     return container.forget();
   }
 
   // We need a new ImageContainer, so create one.
   container = LayerManager::CreateImageContainer();
 
   DrawResult drawResult;
   RefPtr<layers::Image> image;
-  Tie(drawResult, image) = GetCurrentImage(container, aFlags);
+  Tie(drawResult, image) = GetCurrentImage(container, aSize, aFlags);
   if (!image) {
     return nullptr;
   }
 
 #ifdef DEBUG
   NotifyDrawingObservers();
 #endif
 
@@ -109,28 +131,28 @@ ImageResource::GetImageContainerImpl(Lay
 
   mLastImageContainerDrawResult = drawResult;
   mImageContainer = container;
 
   return container.forget();
 }
 
 void
-ImageResource::UpdateImageContainer()
+ImageResource::UpdateImageContainer(const IntSize& aSize)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   RefPtr<layers::ImageContainer> container = mImageContainer.get();
   if (!container) {
     return;
   }
 
   DrawResult drawResult;
   RefPtr<layers::Image> image;
-  Tie(drawResult, image) = GetCurrentImage(container, FLAG_NONE);
+  Tie(drawResult, image) = GetCurrentImage(container, aSize, FLAG_NONE);
   if (!image) {
     return;
   }
 
   mLastImageContainerDrawResult = drawResult;
   AutoTArray<ImageContainer::NonOwningImage, 1> imageList;
   imageList.AppendElement(ImageContainer::NonOwningImage(image, TimeStamp(),
                                                          mLastFrameID++,
--- a/image/Image.h
+++ b/image/Image.h
@@ -331,28 +331,35 @@ protected:
   TimeStamp                     mLastRefreshTime;
   uint64_t                      mInnerWindowId;
   uint32_t                      mAnimationConsumers;
   uint16_t                      mAnimationMode; // Enum values in imgIContainer
   bool                          mInitialized:1; // Have we been initalized?
   bool                          mAnimating:1;   // Are we currently animating?
   bool                          mError:1;       // Error handling
 
-  virtual Pair<DrawResult, RefPtr<layers::Image>>
-    GetCurrentImage(layers::ImageContainer* aContainer, uint32_t aFlags)
+  virtual Pair<DrawResult, RefPtr<gfx::SourceSurface>>
+    GetFrameInternal(const gfx::IntSize& aSize,
+                     uint32_t aWhichFrame,
+                     uint32_t aFlags)
   {
-    return MakePair(DrawResult::BAD_IMAGE, RefPtr<layers::Image>());
+    return MakePair(DrawResult::BAD_IMAGE, RefPtr<gfx::SourceSurface>());
   }
 
+  Pair<DrawResult, RefPtr<layers::Image>>
+    GetCurrentImage(layers::ImageContainer* aContainer,
+                    const gfx::IntSize& aSize,
+                    uint32_t aFlags);
+
   already_AddRefed<layers::ImageContainer>
     GetImageContainerImpl(layers::LayerManager* aManager,
                           const gfx::IntSize& aSize,
                           uint32_t aFlags);
 
-  void UpdateImageContainer();
+  void UpdateImageContainer(const gfx::IntSize& aSize);
 
   void ReleaseImageContainer();
 
 private:
   // A weak pointer to our ImageContainer, which stays alive only as long as
   // the layer system needs it.
   WeakPtr<layers::ImageContainer> mImageContainer;
 
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -615,36 +615,16 @@ RasterImage::GetFrameInternal(const IntS
 
   if (!surface->IsFinished()) {
     return MakePair(DrawResult::INCOMPLETE, Move(sourceSurface));
   }
 
   return MakePair(DrawResult::SUCCESS, Move(sourceSurface));
 }
 
-Pair<DrawResult, RefPtr<layers::Image>>
-RasterImage::GetCurrentImage(ImageContainer* aContainer, uint32_t aFlags)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aContainer);
-
-  DrawResult drawResult;
-  RefPtr<SourceSurface> surface;
-  Tie(drawResult, surface) =
-    GetFrameInternal(mSize, FRAME_CURRENT, aFlags | FLAG_ASYNC_NOTIFY);
-  if (!surface) {
-    // The OS threw out some or all of our buffer. We'll need to wait for the
-    // redecode (which was automatically triggered by GetFrame) to complete.
-    return MakePair(drawResult, RefPtr<layers::Image>());
-  }
-
-  RefPtr<layers::Image> image = new layers::SourceSurfaceImage(surface);
-  return MakePair(drawResult, Move(image));
-}
-
 NS_IMETHODIMP_(bool)
 RasterImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
 {
   int32_t maxTextureSize = aManager->GetMaxTextureSize();
   if (!mHasSize ||
       mSize.width > maxTextureSize ||
       mSize.height > maxTextureSize) {
     return false;
@@ -1619,17 +1599,17 @@ RasterImage::NotifyProgress(Progress aPr
 
   // Ensure that we stay alive long enough to finish notifying.
   RefPtr<RasterImage> image = this;
 
   const bool wasDefaultFlags = aSurfaceFlags == DefaultSurfaceFlags();
 
   if (!aInvalidRect.IsEmpty() && wasDefaultFlags) {
     // Update our image container since we're invalidating.
-    UpdateImageContainer();
+    UpdateImageContainer(mSize);
   }
 
   if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY)) {
     // We may have decoded new animation frames; update our animation state.
     MOZ_ASSERT_IF(aFrameCount && *aFrameCount > 1, mAnimationState || mError);
     if (mAnimationState && aFrameCount) {
       mAnimationState->UpdateKnownFrameCount(*aFrameCount);
     }
--- a/image/RasterImage.h
+++ b/image/RasterImage.h
@@ -305,20 +305,17 @@ private:
                           const ImageRegion& aRegion,
                           gfx::SamplingFilter aSamplingFilter,
                           uint32_t aFlags,
                           float aOpacity);
 
   Pair<DrawResult, RefPtr<gfx::SourceSurface>>
     GetFrameInternal(const gfx::IntSize& aSize,
                      uint32_t aWhichFrame,
-                     uint32_t aFlags);
-
-  Pair<DrawResult, RefPtr<layers::Image>>
-    GetCurrentImage(layers::ImageContainer* aContainer, uint32_t aFlags) override;
+                     uint32_t aFlags) override;
 
   //////////////////////////////////////////////////////////////////////////////
   // Decoding.
   //////////////////////////////////////////////////////////////////////////////
 
   /**
    * Creates and runs a decoder, either synchronously or asynchronously
    * according to @aFlags. Decodes at the provided target size @aSize, using