Bug 1315554 - Part 8. Allow DecoderFactory::CreateDecoderForICOResource to create metadata decoders. r=tnikkel
☠☠ backed out by b6cbfeed5f34 ☠ ☠
authorAndrew Osmond <aosmond@mozilla.com>
Sat, 22 Jul 2017 00:14:59 -0400
changeset 419093 d46b7e02802cdb35ad182705bf27dd583f5533e3
parent 419092 dbae61d1cbee8540e6e7dd7f27d7fd9fc3d31f70
child 419094 18614b05270dc639d6cf9266f4293cf854e3a6c5
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1315554
milestone56.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 1315554 - Part 8. Allow DecoderFactory::CreateDecoderForICOResource to create metadata decoders. r=tnikkel
image/DecoderFactory.cpp
image/DecoderFactory.h
image/decoders/nsICODecoder.cpp
--- a/image/DecoderFactory.cpp
+++ b/image/DecoderFactory.cpp
@@ -231,16 +231,17 @@ DecoderFactory::CreateMetadataDecoder(De
   RefPtr<IDecodingTask> task = new MetadataDecodingTask(WrapNotNull(decoder));
   return task.forget();
 }
 
 /* static */ already_AddRefed<Decoder>
 DecoderFactory::CreateDecoderForICOResource(DecoderType aType,
                                             SourceBufferIterator&& aIterator,
                                             NotNull<nsICODecoder*> aICODecoder,
+                                            bool aIsMetadataDecode,
                                             const Maybe<IntSize>& aExpectedSize,
                                             const Maybe<uint32_t>& aDataOffset
                                               /* = Nothing() */)
 {
   // Create the decoder.
   RefPtr<Decoder> decoder;
   switch (aType) {
     case DecoderType::BMP:
@@ -256,20 +257,21 @@ DecoderFactory::CreateDecoderForICOResou
     default:
       MOZ_ASSERT_UNREACHABLE("Invalid ICO resource decoder type");
       return nullptr;
   }
 
   MOZ_ASSERT(decoder);
 
   // Initialize the decoder, copying settings from @aICODecoder.
-  MOZ_ASSERT(!aICODecoder->IsMetadataDecode());
-  decoder->SetMetadataDecode(aICODecoder->IsMetadataDecode());
+  decoder->SetMetadataDecode(aIsMetadataDecode);
   decoder->SetIterator(Forward<SourceBufferIterator>(aIterator));
-  decoder->SetOutputSize(aICODecoder->OutputSize());
+  if (!aIsMetadataDecode) {
+    decoder->SetOutputSize(aICODecoder->OutputSize());
+  }
   if (aExpectedSize) {
     decoder->SetExpectedSize(*aExpectedSize);
   }
   decoder->SetDecoderFlags(aICODecoder->GetDecoderFlags());
   decoder->SetSurfaceFlags(aICODecoder->GetSurfaceFlags());
   decoder->SetFinalizeFrames(false);
 
   if (NS_FAILED(decoder->Init())) {
--- a/image/DecoderFactory.h
+++ b/image/DecoderFactory.h
@@ -122,25 +122,29 @@ public:
    *              PNG.
    * @param aIterator The SourceBufferIterator which the decoder will read its
    *                  data from.
    * @param aICODecoder The ICO decoder which is controlling this resource
    *                    decoder. @aICODecoder's settings will be copied to the
    *                    resource decoder, so the two decoders will have the
    *                    same decoder flags, surface flags, target size, and
    *                    other parameters.
+   * @param aIsMetadataDecode Indicates whether or not this decoder is for
+   *                          metadata or not. Independent of the state of the
+   *                          parent decoder.
    * @param aExpectedSize The expected size of the resource from the ICO header.
    * @param aDataOffset If @aType is BMP, specifies the offset at which data
    *                    begins in the BMP resource. Must be Some() if and only
    *                    if @aType is BMP.
    */
   static already_AddRefed<Decoder>
   CreateDecoderForICOResource(DecoderType aType,
                               SourceBufferIterator&& aIterator,
                               NotNull<nsICODecoder*> aICODecoder,
+                              bool aIsMetadataDecode,
                               const Maybe<gfx::IntSize>& aExpectedSize,
                               const Maybe<uint32_t>& aDataOffset = Nothing());
 
   /**
    * 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.
--- a/image/decoders/nsICODecoder.cpp
+++ b/image/decoders/nsICODecoder.cpp
@@ -272,16 +272,17 @@ nsICODecoder::SniffResource(const char* 
     SourceBufferIterator containedIterator
       = mLexer.Clone(*mIterator, mDirEntry.mBytesInRes);
 
     // Create a PNG decoder which will do the rest of the work for us.
     mContainedDecoder =
       DecoderFactory::CreateDecoderForICOResource(DecoderType::PNG,
                                                   Move(containedIterator),
                                                   WrapNotNull(this),
+                                                  false,
                                                   Some(GetRealSize()));
 
     // Read in the rest of the PNG unbuffered.
     size_t toRead = mDirEntry.mBytesInRes - BITMAPINFOSIZE;
     return Transition::ToUnbuffered(ICOState::FINISHED_RESOURCE,
                                     ICOState::READ_RESOURCE,
                                     toRead);
   } else {
@@ -334,16 +335,17 @@ nsICODecoder::ReadBIH(const char* aData)
     = mLexer.Clone(*mIterator, mDirEntry.mBytesInRes);
 
   // Create a BMP decoder which will do most of the work for us; the exception
   // is the AND mask, which isn't present in standalone BMPs.
   mContainedDecoder =
     DecoderFactory::CreateDecoderForICOResource(DecoderType::BMP,
                                                 Move(containedIterator),
                                                 WrapNotNull(this),
+                                                false,
                                                 Some(GetRealSize()),
                                                 Some(dataOffset));
 
   RefPtr<nsBMPDecoder> bmpDecoder =
     static_cast<nsBMPDecoder*>(mContainedDecoder.get());
 
   // Ensure the decoder has parsed at least the BMP's bitmap info header.
   if (!FlushContainedDecoder()) {