Bug 1285865 (Part 6) - Pass a SourceBufferIterator to Decoder::DoDecode(). r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Mon, 11 Jul 2016 00:07:50 -0700
changeset 344586 940b6ad95cfc5340ee8aa6fd4b7301f974fc2ea0
parent 344585 1c717a8dc382b5aeee20f4231488c5ea2320e890
child 344587 e86a99a37d8392234413a77403f47d3fb85345b9
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)
reviewersedwin
bugs1285865
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 1285865 (Part 6) - Pass a SourceBufferIterator to Decoder::DoDecode(). r=edwin
image/Decoder.cpp
image/Decoder.h
image/decoders/nsBMPDecoder.cpp
image/decoders/nsBMPDecoder.h
image/decoders/nsGIFDecoder2.cpp
image/decoders/nsGIFDecoder2.h
image/decoders/nsICODecoder.cpp
image/decoders/nsICODecoder.h
image/decoders/nsIconDecoder.cpp
image/decoders/nsIconDecoder.h
image/decoders/nsJPEGDecoder.cpp
image/decoders/nsJPEGDecoder.h
image/decoders/nsPNGDecoder.cpp
image/decoders/nsPNGDecoder.h
--- a/image/Decoder.cpp
+++ b/image/Decoder.cpp
@@ -147,18 +147,17 @@ Decoder::Decode(NotNull<IResumable*> aOn
 
     {
       PROFILER_LABEL("ImageDecoder", "Write",
         js::ProfileEntry::Category::GRAPHICS);
 
       AutoRecordDecoderTelemetry telemetry(this, mIterator->Length());
 
       // Pass the data along to the implementation.
-      Maybe<TerminalState> terminalState =
-        DoDecode(mIterator->Data(), mIterator->Length());
+      Maybe<TerminalState> terminalState = DoDecode(*mIterator);
 
       if (terminalState == Some(TerminalState::FAILURE)) {
         PostDataError();
       }
     }
   }
 
   CompleteDecode();
--- a/image/Decoder.h
+++ b/image/Decoder.h
@@ -285,17 +285,17 @@ protected:
    * Internal hooks. Decoder implementations may override these and
    * only these methods.
    *
    * BeforeFinishInternal() can be used to detect if decoding is in an
    * incomplete state, e.g. due to file truncation, in which case it should
    * call PostDataError().
    */
   virtual void InitInternal();
-  virtual Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) = 0;
+  virtual Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) = 0;
   virtual void BeforeFinishInternal();
   virtual void FinishInternal();
   virtual void FinishWithErrorInternal();
 
   /*
    * Progress notifications.
    */
 
--- a/image/decoders/nsBMPDecoder.cpp
+++ b/image/decoders/nsBMPDecoder.cpp
@@ -431,23 +431,23 @@ nsBMPDecoder::FinishRow()
     }
   } else {
     PostInvalidation(IntRect(0, mCurrentRow, mH.mWidth, 1));
   }
   mCurrentRow--;
 }
 
 Maybe<TerminalState>
-nsBMPDecoder::DoDecode(const char* aBuffer, size_t aLength)
+nsBMPDecoder::DoDecode(SourceBufferIterator& aIterator)
 {
   MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
-  MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aLength > 0);
+  MOZ_ASSERT(aIterator.Data());
+  MOZ_ASSERT(aIterator.Length() > 0);
 
-  return mLexer.Lex(aBuffer, aLength,
+  return mLexer.Lex(aIterator.Data(), aIterator.Length(),
                     [=](State aState, const char* aData, size_t aLength) {
     switch (aState) {
       case State::FILE_HEADER:      return ReadFileHeader(aData, aLength);
       case State::INFO_HEADER_SIZE: return ReadInfoHeaderSize(aData, aLength);
       case State::INFO_HEADER_REST: return ReadInfoHeaderRest(aData, aLength);
       case State::BITFIELDS:        return ReadBitfields(aData, aLength);
       case State::COLOR_TABLE:      return ReadColorTable(aData, aLength);
       case State::GAP:              return SkipGap();
--- a/image/decoders/nsBMPDecoder.h
+++ b/image/decoders/nsBMPDecoder.h
@@ -144,17 +144,17 @@ public:
 
   /// Force transparency from outside. (Used by the ICO decoder.)
   void SetHasTransparency()
   {
     mMayHaveTransparency = true;
     mDoesHaveTransparency = true;
   }
 
-  Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) override;
+  Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) override;
   virtual void BeforeFinishInternal() override;
   virtual void FinishInternal() override;
 
 private:
   friend class DecoderFactory;
 
   enum class State {
     FILE_HEADER,
--- a/image/decoders/nsGIFDecoder2.cpp
+++ b/image/decoders/nsGIFDecoder2.cpp
@@ -450,23 +450,23 @@ ConvertColormap(uint32_t* aColormap, uin
   // NB: can't use 32-bit reads, they might read off the end of the buffer
   while (c--) {
     from -= 3;
     *--to = gfxPackedPixel(0xFF, from[0], from[1], from[2]);
   }
 }
 
 Maybe<TerminalState>
-nsGIFDecoder2::DoDecode(const char* aBuffer, size_t aLength)
+nsGIFDecoder2::DoDecode(SourceBufferIterator& aIterator)
 {
   MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
-  MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aLength > 0);
+  MOZ_ASSERT(aIterator.Data());
+  MOZ_ASSERT(aIterator.Length() > 0);
 
-  return mLexer.Lex(aBuffer, aLength,
+  return mLexer.Lex(aIterator.Data(), aIterator.Length(),
                     [=](State aState, const char* aData, size_t aLength) {
     switch(aState) {
       case State::GIF_HEADER:
         return ReadGIFHeader(aData);
       case State::SCREEN_DESCRIPTOR:
         return ReadScreenDescriptor(aData);
       case State::GLOBAL_COLOR_TABLE:
         return ReadGlobalColorTable(aData, aLength);
--- a/image/decoders/nsGIFDecoder2.h
+++ b/image/decoders/nsGIFDecoder2.h
@@ -19,17 +19,17 @@ class RasterImage;
 //////////////////////////////////////////////////////////////////////
 // nsGIFDecoder2 Definition
 
 class nsGIFDecoder2 : public Decoder
 {
 public:
   ~nsGIFDecoder2();
 
-  Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) override;
+  Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) override;
   virtual void FinishInternal() override;
   virtual Telemetry::ID SpeedHistogram() override;
 
 private:
   friend class DecoderFactory;
 
   // Decoders should only be instantiated via DecoderFactory.
   explicit nsGIFDecoder2(RasterImage* aImage);
--- a/image/decoders/nsICODecoder.cpp
+++ b/image/decoders/nsICODecoder.cpp
@@ -593,23 +593,23 @@ nsICODecoder::FinishResource()
       mContainedDecoder->GetSize() != GetRealSize()) {
     return Transition::TerminateFailure();
   }
 
   return Transition::TerminateSuccess();
 }
 
 Maybe<TerminalState>
-nsICODecoder::DoDecode(const char* aBuffer, size_t aLength)
+nsICODecoder::DoDecode(SourceBufferIterator& aIterator)
 {
   MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
-  MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aLength > 0);
+  MOZ_ASSERT(aIterator.Data());
+  MOZ_ASSERT(aIterator.Length() > 0);
 
-  return mLexer.Lex(aBuffer, aLength,
+  return mLexer.Lex(aIterator.Data(), aIterator.Length(),
                     [=](ICOState aState, const char* aData, size_t aLength) {
     switch (aState) {
       case ICOState::HEADER:
         return ReadHeader(aData);
       case ICOState::DIR_ENTRY:
         return ReadDirEntry(aData);
       case ICOState::SKIP_TO_RESOURCE:
         return Transition::ContinueUnbuffered(ICOState::SKIP_TO_RESOURCE);
--- a/image/decoders/nsICODecoder.h
+++ b/image/decoders/nsICODecoder.h
@@ -65,17 +65,17 @@ public:
   gfx::IntSize GetRealSize() const
   {
     return gfx::IntSize(GetRealWidth(), GetRealHeight());
   }
 
   /// @return The offset from the beginning of the ICO to the first resource.
   size_t FirstResourceOffset() const;
 
-  Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) override;
+  Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) override;
   virtual void FinishInternal() override;
   virtual void FinishWithErrorInternal() override;
 
 private:
   friend class DecoderFactory;
 
   // Decoders should only be instantiated via DecoderFactory.
   explicit nsICODecoder(RasterImage* aImage);
--- a/image/decoders/nsIconDecoder.cpp
+++ b/image/decoders/nsIconDecoder.cpp
@@ -22,23 +22,23 @@ nsIconDecoder::nsIconDecoder(RasterImage
 {
   // Nothing to do
 }
 
 nsIconDecoder::~nsIconDecoder()
 { }
 
 Maybe<TerminalState>
-nsIconDecoder::DoDecode(const char* aBuffer, size_t aLength)
+nsIconDecoder::DoDecode(SourceBufferIterator& aIterator)
 {
   MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
-  MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aLength > 0);
+  MOZ_ASSERT(aIterator.Data());
+  MOZ_ASSERT(aIterator.Length() > 0);
 
-  return mLexer.Lex(aBuffer, aLength,
+  return mLexer.Lex(aIterator.Data(), aIterator.Length(),
                     [=](State aState, const char* aData, size_t aLength) {
     switch (aState) {
       case State::HEADER:
         return ReadHeader(aData);
       case State::ROW_OF_PIXELS:
         return ReadRowOfPixels(aData, aLength);
       case State::FINISH:
         return Finish();
--- a/image/decoders/nsIconDecoder.h
+++ b/image/decoders/nsIconDecoder.h
@@ -32,17 +32,17 @@ class RasterImage;
 //
 ////////////////////////////////////////////////////////////////////////////////
 
 class nsIconDecoder : public Decoder
 {
 public:
   virtual ~nsIconDecoder();
 
-  Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) override;
+  Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) override;
 
 private:
   friend class DecoderFactory;
 
   // Decoders should only be instantiated via DecoderFactory.
   explicit nsIconDecoder(RasterImage* aImage);
 
   enum class State {
--- a/image/decoders/nsJPEGDecoder.cpp
+++ b/image/decoders/nsJPEGDecoder.cpp
@@ -175,23 +175,23 @@ nsJPEGDecoder::FinishInternal()
   if ((mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER) &&
       (mState != JPEG_ERROR) &&
       !IsMetadataDecode()) {
     mState = JPEG_DONE;
   }
 }
 
 Maybe<TerminalState>
-nsJPEGDecoder::DoDecode(const char* aBuffer, size_t aLength)
+nsJPEGDecoder::DoDecode(SourceBufferIterator& aIterator)
 {
   MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
-  MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aLength > 0);
+  MOZ_ASSERT(aIterator.Data());
+  MOZ_ASSERT(aIterator.Length() > 0);
 
-  return mLexer.Lex(aBuffer, aLength,
+  return mLexer.Lex(aIterator.Data(), aIterator.Length(),
                     [=](State aState, const char* aData, size_t aLength) {
     switch (aState) {
       case State::JPEG_DATA:
         return ReadJPEGData(aData, aLength);
       case State::FINISHED_JPEG_DATA:
         return FinishedJPEGData();
     }
     MOZ_CRASH("Unknown State");
--- a/image/decoders/nsJPEGDecoder.h
+++ b/image/decoders/nsJPEGDecoder.h
@@ -53,17 +53,17 @@ public:
   virtual ~nsJPEGDecoder();
 
   virtual void SetSampleSize(int aSampleSize) override
   {
     mSampleSize = aSampleSize;
   }
 
   virtual void InitInternal() override;
-  Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) override;
+  Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) override;
   virtual void FinishInternal() override;
 
   virtual Telemetry::ID SpeedHistogram() override;
   void NotifyDone();
 
 protected:
   Orientation ReadOrientationFromEXIF();
   void OutputScanlines(bool* suspend);
--- a/image/decoders/nsPNGDecoder.cpp
+++ b/image/decoders/nsPNGDecoder.cpp
@@ -344,23 +344,23 @@ nsPNGDecoder::InitInternal()
   png_set_progressive_read_fn(mPNG, static_cast<png_voidp>(this),
                               nsPNGDecoder::info_callback,
                               nsPNGDecoder::row_callback,
                               nsPNGDecoder::end_callback);
 
 }
 
 Maybe<TerminalState>
-nsPNGDecoder::DoDecode(const char* aBuffer, size_t aLength)
+nsPNGDecoder::DoDecode(SourceBufferIterator& aIterator)
 {
   MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
-  MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aLength > 0);
+  MOZ_ASSERT(aIterator.Data());
+  MOZ_ASSERT(aIterator.Length() > 0);
 
-  return mLexer.Lex(aBuffer, aLength,
+  return mLexer.Lex(aIterator.Data(), aIterator.Length(),
                     [=](State aState, const char* aData, size_t aLength) {
     switch (aState) {
       case State::PNG_DATA:
         return ReadPNGData(aData, aLength);
       case State::FINISHED_PNG_DATA:
         return FinishedPNGData();
     }
     MOZ_CRASH("Unknown State");
--- a/image/decoders/nsPNGDecoder.h
+++ b/image/decoders/nsPNGDecoder.h
@@ -18,17 +18,17 @@ namespace image {
 class RasterImage;
 
 class nsPNGDecoder : public Decoder
 {
 public:
   virtual ~nsPNGDecoder();
 
   virtual void InitInternal() override;
-  Maybe<TerminalState> DoDecode(const char* aBuffer, size_t aLength) override;
+  Maybe<TerminalState> DoDecode(SourceBufferIterator& aIterator) override;
   virtual Telemetry::ID SpeedHistogram() override;
 
   /// @return true if this PNG is a valid ICO resource.
   bool IsValidICO() const;
 
 private:
   friend class DecoderFactory;