Bug 1282354 - Move code for SurfaceCache placeholder insertion from RasterImage to DecoderFactory. r=dholbert
authorSeth Fowler <mark.seth.fowler@gmail.com>
Sun, 26 Jun 2016 22:05:58 -0700
changeset 343498 1fe160cfbce20585e6a619f93b1843ef72de20f2
parent 343497 872c207297631b960bea8de9baafe2de5e61d148
child 343499 067521ccd17907843e1db644ca0f02a1f5a6520a
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1282354
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 1282354 - Move code for SurfaceCache placeholder insertion from RasterImage to DecoderFactory. r=dholbert
image/DecoderFactory.cpp
image/DecoderFactory.h
image/RasterImage.cpp
--- a/image/DecoderFactory.cpp
+++ b/image/DecoderFactory.cpp
@@ -103,16 +103,17 @@ DecoderFactory::GetDecoder(DecoderType a
 
   return decoder.forget();
 }
 
 /* static */ already_AddRefed<IDecodingTask>
 DecoderFactory::CreateDecoder(DecoderType aType,
                               NotNull<RasterImage*> aImage,
                               NotNull<SourceBuffer*> aSourceBuffer,
+                              const IntSize& aIntrinsicSize,
                               const Maybe<IntSize>& aTargetSize,
                               DecoderFlags aDecoderFlags,
                               SurfaceFlags aSurfaceFlags,
                               int aSampleSize)
 {
   if (aType == DecoderType::UNKNOWN) {
     return nullptr;
   }
@@ -134,24 +135,36 @@ DecoderFactory::CreateDecoder(DecoderTyp
     MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
   }
 
   decoder->Init();
   if (NS_FAILED(decoder->GetDecoderError())) {
     return nullptr;
   }
 
+  // Add a placeholder to the SurfaceCache so we won't trigger any more decoders
+  // with the same parameters.
+  IntSize surfaceSize = aTargetSize.valueOr(aIntrinsicSize);
+  SurfaceKey surfaceKey =
+    RasterSurfaceKey(surfaceSize, aSurfaceFlags, /* aFrameNum = */ 0);
+  InsertOutcome outcome =
+    SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey);
+  if (outcome != InsertOutcome::SUCCESS) {
+    return nullptr;
+  }
+
   RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
   return task.forget();
 }
 
 /* static */ already_AddRefed<IDecodingTask>
 DecoderFactory::CreateAnimationDecoder(DecoderType aType,
                                        NotNull<RasterImage*> aImage,
                                        NotNull<SourceBuffer*> aSourceBuffer,
+                                       const IntSize& aIntrinsicSize,
                                        DecoderFlags aDecoderFlags,
                                        SurfaceFlags aSurfaceFlags)
 {
   if (aType == DecoderType::UNKNOWN) {
     return nullptr;
   }
 
   MOZ_ASSERT(aType == DecoderType::GIF || aType == DecoderType::PNG,
@@ -167,16 +180,26 @@ DecoderFactory::CreateAnimationDecoder(D
   decoder->SetDecoderFlags(aDecoderFlags | DecoderFlags::IS_REDECODE);
   decoder->SetSurfaceFlags(aSurfaceFlags);
 
   decoder->Init();
   if (NS_FAILED(decoder->GetDecoderError())) {
     return nullptr;
   }
 
+  // Add a placeholder for the first frame to the SurfaceCache so we won't
+  // trigger any more decoders with the same parameters.
+  SurfaceKey surfaceKey =
+    RasterSurfaceKey(aIntrinsicSize, aSurfaceFlags, /* aFrameNum = */ 0);
+  InsertOutcome outcome =
+    SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey);
+  if (outcome != InsertOutcome::SUCCESS) {
+    return nullptr;
+  }
+
   RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
   return task.forget();
 }
 
 /* static */ already_AddRefed<IDecodingTask>
 DecoderFactory::CreateMetadataDecoder(DecoderType aType,
                                       NotNull<RasterImage*> aImage,
                                       NotNull<SourceBuffer*> aSourceBuffer,
--- a/image/DecoderFactory.h
+++ b/image/DecoderFactory.h
@@ -49,52 +49,58 @@ public:
    * (If the image *is* animated, only the first frame will be decoded.) The
    * decoder will send notifications to @aImage.
    *
    * @param aType Which type of decoder to create - JPEG, PNG, etc.
    * @param aImage The image will own the decoder and which should receive
    *               notifications as decoding progresses.
    * @param aSourceBuffer The SourceBuffer which the decoder will read its data
    *                      from.
+   * @param aIntrinsicSize The intrinsic size of the image, normally obtained
+   *                       during the metadata decode.
    * @param aTargetSize If not Nothing(), the target size which the image should
    *                    be scaled to during decoding. It's an error to specify
    *                    a target size for a decoder type which doesn't support
    *                    downscale-during-decode.
    * @param aDecoderFlags Flags specifying the behavior of this decoder.
    * @param aSurfaceFlags Flags specifying the type of output this decoder
    *                      should produce.
    * @param aSampleSize The sample size requested using #-moz-samplesize (or 0
    *                    if none).
    */
   static already_AddRefed<IDecodingTask>
   CreateDecoder(DecoderType aType,
                 NotNull<RasterImage*> aImage,
                 NotNull<SourceBuffer*> aSourceBuffer,
+                const gfx::IntSize& aIntrinsicSize,
                 const Maybe<gfx::IntSize>& aTargetSize,
                 DecoderFlags aDecoderFlags,
                 SurfaceFlags aSurfaceFlags,
                 int aSampleSize);
 
   /**
    * Creates and initializes a decoder for animated images of type @aType.
    * The decoder will send notifications to @aImage.
    *
    * @param aType Which type of decoder to create - JPEG, PNG, etc.
    * @param aImage The image will own the decoder and which should receive
    *               notifications as decoding progresses.
    * @param aSourceBuffer The SourceBuffer which the decoder will read its data
    *                      from.
+   * @param aIntrinsicSize The intrinsic size of the image, normally obtained
+   *                       during the metadata decode.
    * @param aDecoderFlags Flags specifying the behavior of this decoder.
    * @param aSurfaceFlags Flags specifying the type of output this decoder
    *                      should produce.
    */
   static already_AddRefed<IDecodingTask>
   CreateAnimationDecoder(DecoderType aType,
                          NotNull<RasterImage*> aImage,
                          NotNull<SourceBuffer*> aSourceBuffer,
+                         const gfx::IntSize& aIntrinsicSize,
                          DecoderFlags aDecoderFlags,
                          SurfaceFlags aSurfaceFlags);
 
   /**
    * Creates and initializes a metadata decoder of type @aType. This decoder
    * will only decode the image's header, extracting metadata like the size of
    * the image. No actual image data will be decoded and no surfaces will be
    * allocated. The decoder will send notifications to @aImage.
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1304,41 +1304,30 @@ RasterImage::Decode(const IntSize& aSize
     // alpha or not.
     surfaceFlags &= ~SurfaceFlags::NO_PREMULTIPLY_ALPHA;
   }
 
   // Create a decoder.
   RefPtr<IDecodingTask> task;
   if (mAnim) {
     task = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this),
-                                                  mSourceBuffer, decoderFlags,
-                                                  surfaceFlags);
+                                                  mSourceBuffer, mSize,
+                                                  decoderFlags, surfaceFlags);
   } else {
     task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this),
-                                         mSourceBuffer, targetSize, decoderFlags,
-                                         surfaceFlags, mRequestedSampleSize);
+                                         mSourceBuffer, mSize, targetSize,
+                                         decoderFlags, surfaceFlags,
+                                         mRequestedSampleSize);
   }
 
   // Make sure DecoderFactory was able to create a decoder successfully.
   if (!task) {
     return NS_ERROR_FAILURE;
   }
 
-  // Add a placeholder for the first frame to the SurfaceCache so we won't
-  // trigger any more decoders with the same parameters.
-  SurfaceKey surfaceKey =
-    RasterSurfaceKey(aSize,
-                     task->GetDecoder()->GetSurfaceFlags(),
-                     /* aFrameNum = */ 0);
-  InsertOutcome outcome =
-    SurfaceCache::InsertPlaceholder(ImageKey(this), surfaceKey);
-  if (outcome != InsertOutcome::SUCCESS) {
-    return NS_ERROR_FAILURE;
-  }
-
   mDecodeCount++;
 
   // We're ready to decode; start the decoder.
   LaunchDecodingTask(task, this, aFlags, mHasSourceData);
   return NS_OK;
 }
 
 NS_IMETHODIMP