Bug 1191114 (Part 2) - Add support for creating an anonymous metadata decoder, for use in tests. r=tn
authorSeth Fowler <mark.seth.fowler@gmail.com>
Wed, 12 Aug 2015 10:41:05 -0700
changeset 257517 fce34ae035239a2014509c8262424dcdccd07e9f
parent 257516 3db1ac46dacc9db0dcafdec5b9314dcd14be2237
child 257518 721ecdee33a7d1a008ed661439a2cbe8af7169b8
push id29221
push userryanvm@gmail.com
push dateThu, 13 Aug 2015 14:43:44 +0000
treeherdermozilla-central@0cddd6a6565a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1191114
milestone43.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 1191114 (Part 2) - Add support for creating an anonymous metadata decoder, for use in tests. r=tn
image/DecoderFactory.cpp
image/DecoderFactory.h
--- a/image/DecoderFactory.cpp
+++ b/image/DecoderFactory.cpp
@@ -210,10 +210,35 @@ DecoderFactory::CreateAnonymousDecoder(D
   decoder->Init();
   if (NS_FAILED(decoder->GetDecoderError())) {
     return nullptr;
   }
 
   return decoder.forget();
 }
 
+/* static */ already_AddRefed<Decoder>
+DecoderFactory::CreateAnonymousMetadataDecoder(DecoderType aType,
+                                               SourceBuffer* aSourceBuffer)
+{
+  if (aType == DecoderType::UNKNOWN) {
+    return nullptr;
+  }
+
+  nsRefPtr<Decoder> decoder =
+    GetDecoder(aType, /* aImage = */ nullptr, /* aIsRedecode = */ false);
+  MOZ_ASSERT(decoder, "Should have a decoder now");
+
+  // Initialize the decoder.
+  decoder->SetMetadataDecode(true);
+  decoder->SetIterator(aSourceBuffer->Iterator());
+  decoder->SetIsFirstFrameDecode();
+
+  decoder->Init();
+  if (NS_FAILED(decoder->GetDecoderError())) {
+    return nullptr;
+  }
+
+  return decoder.forget();
+}
+
 } // namespace image
 } // namespace mozilla
--- a/image/DecoderFactory.h
+++ b/image/DecoderFactory.h
@@ -96,21 +96,47 @@ public:
    */
   static already_AddRefed<Decoder>
   CreateMetadataDecoder(DecoderType aType,
                         RasterImage* aImage,
                         SourceBuffer* aSourceBuffer,
                         int aSampleSize,
                         const gfx::IntSize& aResolution);
 
+  /**
+   * 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 aFlags Flags specifying what type of output the decoder should
+   *               produce; see GetDecodeFlags() in RasterImage.h.
+   */
   static already_AddRefed<Decoder>
   CreateAnonymousDecoder(DecoderType aType,
                          SourceBuffer* aSourceBuffer,
                          uint32_t aFlags);
 
+  /**
+   * 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.
+   *
+   * @param aType Which type of decoder to create - JPEG, PNG, etc.
+   * @param aSourceBuffer The SourceBuffer which the decoder will read its data
+   *                      from.
+   * @param aFlags Flags specifying what type of output the decoder should
+   *               produce; see GetDecodeFlags() in RasterImage.h.
+   */
+  static already_AddRefed<Decoder>
+  CreateAnonymousMetadataDecoder(DecoderType aType,
+                                 SourceBuffer* aSourceBuffer);
+
 private:
   virtual ~DecoderFactory() = 0;
 
   /**
    * An internal method which allocates a new decoder of the requested @aType.
    */
   static already_AddRefed<Decoder> GetDecoder(DecoderType aType,
                                               RasterImage* aImage,