Bug 1292505 (Part 1b) - Update DecoderFactory to use SetOutputSize(), and propagate the changes to RasterImage. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Fri, 05 Aug 2016 04:19:03 -0700
changeset 308442 3ec9f4bad96e4fb3ea136786b7dfeae8fe394b40
parent 308441 ba7bfe146f7ff39d49f18e5d7d5046497dc92517
child 308443 a0050f7cc0cb93dcce6e30b0a7caf8729bd8785d
push id30537
push userphilringnalda@gmail.com
push dateSun, 07 Aug 2016 06:34:58 +0000
treeherdermozilla-central@70948f120f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1292505
milestone51.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 1292505 (Part 1b) - Update DecoderFactory to use SetOutputSize(), and propagate the changes to RasterImage. r=edwin
image/DecoderFactory.cpp
image/DecoderFactory.h
image/RasterImage.cpp
--- a/image/DecoderFactory.cpp
+++ b/image/DecoderFactory.cpp
@@ -104,51 +104,45 @@ 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,
+                              const IntSize& aOutputSize,
                               DecoderFlags aDecoderFlags,
                               SurfaceFlags aSurfaceFlags,
                               int aSampleSize)
 {
   if (aType == DecoderType::UNKNOWN) {
     return nullptr;
   }
 
   RefPtr<Decoder> decoder =
     GetDecoder(aType, aImage, bool(aDecoderFlags & DecoderFlags::IS_REDECODE));
   MOZ_ASSERT(decoder, "Should have a decoder now");
 
   // Initialize the decoder.
   decoder->SetMetadataDecode(false);
   decoder->SetIterator(aSourceBuffer->Iterator());
+  decoder->SetOutputSize(aOutputSize);
   decoder->SetDecoderFlags(aDecoderFlags | DecoderFlags::FIRST_FRAME_ONLY);
   decoder->SetSurfaceFlags(aSurfaceFlags);
   decoder->SetSampleSize(aSampleSize);
 
-  // Set a target size for downscale-during-decode if applicable.
-  if (aTargetSize) {
-    DebugOnly<nsresult> rv = decoder->SetTargetSize(*aTargetSize);
-    MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
-  }
-
   if (NS_FAILED(decoder->Init())) {
     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);
+    RasterSurfaceKey(aOutputSize, 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();
@@ -249,37 +243,31 @@ DecoderFactory::CreateDecoderForICOResou
       return nullptr;
   }
 
   MOZ_ASSERT(decoder);
 
   // Initialize the decoder, copying settings from @aICODecoder.
   decoder->SetMetadataDecode(aICODecoder->IsMetadataDecode());
   decoder->SetIterator(aSourceBuffer->Iterator());
+  decoder->SetOutputSize(aICODecoder->OutputSize());
   decoder->SetDecoderFlags(aICODecoder->GetDecoderFlags());
   decoder->SetSurfaceFlags(aICODecoder->GetSurfaceFlags());
 
-  // Set a target size for downscale-during-decode if applicable.
-  const Maybe<IntSize> targetSize = aICODecoder->GetTargetSize();
-  if (targetSize) {
-    DebugOnly<nsresult> rv = decoder->SetTargetSize(*targetSize);
-    MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
-  }
-
   if (NS_FAILED(decoder->Init())) {
     return nullptr;
   }
 
   return decoder.forget();
 }
 
 /* static */ already_AddRefed<Decoder>
 DecoderFactory::CreateAnonymousDecoder(DecoderType aType,
                                        NotNull<SourceBuffer*> aSourceBuffer,
-                                       const Maybe<IntSize>& aTargetSize,
+                                       const Maybe<IntSize>& aOutputSize,
                                        SurfaceFlags aSurfaceFlags)
 {
   if (aType == DecoderType::UNKNOWN) {
     return nullptr;
   }
 
   RefPtr<Decoder> decoder =
     GetDecoder(aType, /* aImage = */ nullptr, /* aIsRedecode = */ false);
@@ -298,20 +286,19 @@ DecoderFactory::CreateAnonymousDecoder(D
   // Decoder::GetCurrentFrame(). That means that anonymous decoders should
   // always be first-frame-only decoders, because nobody ever wants the *last*
   // frame.
   decoderFlags |= DecoderFlags::FIRST_FRAME_ONLY;
 
   decoder->SetDecoderFlags(decoderFlags);
   decoder->SetSurfaceFlags(aSurfaceFlags);
 
-  // Set a target size for downscale-during-decode if applicable.
-  if (aTargetSize) {
-    DebugOnly<nsresult> rv = decoder->SetTargetSize(*aTargetSize);
-    MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
+  // Set an output size for downscale-during-decode if requested.
+  if (aOutputSize) {
+    decoder->SetOutputSize(*aOutputSize);
   }
 
   if (NS_FAILED(decoder->Init())) {
     return nullptr;
   }
 
   return decoder.forget();
 }
--- a/image/DecoderFactory.h
+++ b/image/DecoderFactory.h
@@ -52,32 +52,31 @@ public:
    *
    * @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 aOutputSize The output size for the decoder. If this is smaller than
+   *                    the intrinsic size, the decoder will downscale the
+   *                    image.
    * @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,
+                const gfx::IntSize& aOutputSize,
                 DecoderFlags aDecoderFlags,
                 SurfaceFlags aSurfaceFlags,
                 int aSampleSize);
 
   /**
    * Creates and initializes a decoder for animated images of type @aType.
    * The decoder will send notifications to @aImage.
    *
@@ -145,27 +144,27 @@ public:
 
   /**
    * Creates and initializes an anonymous decoder (one which isn't associated
    * with an Image object). Only the first frame of the image will be decoded.
    *
    * @param aType Which type of decoder to create - JPEG, PNG, etc.
    * @param aSourceBuffer The SourceBuffer which the decoder will read its data
    *                      from.
-   * @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 aOutputSize If Some(), the output size for the decoder. If this is
+   *                    smaller than the intrinsic size, the decoder will
+   *                    downscale the image. If Nothing(), the output size will
+   *                    be the intrinsic size.
    * @param aSurfaceFlags Flags specifying the type of output this decoder
    *                      should produce.
    */
   static already_AddRefed<Decoder>
   CreateAnonymousDecoder(DecoderType aType,
                          NotNull<SourceBuffer*> aSourceBuffer,
-                         const Maybe<gfx::IntSize>& aTargetSize,
+                         const Maybe<gfx::IntSize>& aOutputSize,
                          SurfaceFlags aSurfaceFlags);
 
   /**
    * Creates and initializes an anonymous metadata decoder (one which isn't
    * associated with an Image object). 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.
    *
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1129,18 +1129,16 @@ RasterImage::Decode(const IntSize& aSize
   // we've decoded at aren't useful anymore. We can allow them to expire from
   // the cache by unlocking them here. When the decode finishes, it will send an
   // invalidation that will cause all instances of this image to redraw. If this
   // image is locked, any surfaces that are still useful will become locked
   // again when LookupFrame touches them, and the remainder will eventually
   // expire.
   SurfaceCache::UnlockEntries(ImageKey(this));
 
-  Maybe<IntSize> targetSize = mSize != aSize ? Some(aSize) : Nothing();
-
   // Determine which flags we need to decode this image with.
   DecoderFlags decoderFlags = DefaultDecoderFlags();
   if (aFlags & FLAG_ASYNC_NOTIFY) {
     decoderFlags |= DecoderFlags::ASYNC_NOTIFY;
   }
   if (mTransient) {
     decoderFlags |= DecoderFlags::IMAGE_IS_TRANSIENT;
   }
@@ -1158,17 +1156,17 @@ RasterImage::Decode(const IntSize& aSize
   // Create a decoder.
   RefPtr<IDecodingTask> task;
   if (mAnimationState) {
     task = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this),
                                                   mSourceBuffer, mSize,
                                                   decoderFlags, surfaceFlags);
   } else {
     task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this),
-                                         mSourceBuffer, mSize, targetSize,
+                                         mSourceBuffer, mSize, aSize,
                                          decoderFlags, surfaceFlags,
                                          mRequestedSampleSize);
   }
 
   // Make sure DecoderFactory was able to create a decoder successfully.
   if (!task) {
     return NS_ERROR_FAILURE;
   }