Bug 1285865 (Part 4) - Rename Decoder::WriteInternal() to Decoder::DoDecode() and fix its argument types. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Mon, 11 Jul 2016 00:05:51 -0700
changeset 344584 6735ebca30843305e2a4fff37e72f630a2620417
parent 344583 6188761ca7f41e2830f99ecf44b0d8a793dbbffb
child 344585 1c717a8dc382b5aeee20f4231488c5ea2320e890
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 4) - Rename Decoder::WriteInternal() to Decoder::DoDecode() and fix its argument types. r=edwin
image/Decoder.cpp
image/Decoder.h
image/StreamingLexer.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,17 +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.
-      WriteInternal(mIterator->Data(), mIterator->Length());
+      DoDecode(mIterator->Data(), mIterator->Length());
     }
   }
 
   CompleteDecode();
   return HasError() ? NS_ERROR_FAILURE : NS_OK;
 }
 
 bool
--- a/image/Decoder.h
+++ b/image/Decoder.h
@@ -283,17 +283,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 void WriteInternal(const char* aBuffer, uint32_t aCount) = 0;
+  virtual void DoDecode(const char* aBuffer, size_t aLength) = 0;
   virtual void BeforeFinishInternal();
   virtual void FinishInternal();
   virtual void FinishWithErrorInternal();
 
   /*
    * Progress notifications.
    */
 
--- a/image/StreamingLexer.h
+++ b/image/StreamingLexer.h
@@ -206,34 +206,34 @@ private:
  *
  *  - Create a State type. This should be an |enum class| listing all of the
  *    states that you can be in while lexing the image format you're trying to
  *    read.
  *
  *  - Add an instance of StreamingLexer<State> to your decoder class. Initialize
  *    it with a Transition::To() the state that you want to start lexing in.
  *
- *  - In your decoder's WriteInternal method(), call Lex(), passing in the input
- *    data and length that are passed to WriteInternal(). You also need to pass
+ *  - In your decoder's DoDecode() method, call Lex(), passing in the input
+ *    data and length that are passed to DoDecode(). You also need to pass
  *    a lambda which dispatches to lexing code for each state based on the State
  *    value that's passed in. The lambda generally should just continue a
  *    |switch| statement that calls different methods for each State value. Each
  *    method should return a LexerTransition<State>, which the lambda should
  *    return in turn.
  *
  *  - Write the methods that actually implement lexing for your image format.
  *    These methods should return either Transition::To(), to move on to another
  *    state, or Transition::Terminate{Success,Failure}(), if lexing has
  *    terminated in either success or failure. (There are also additional
  *    transitions for unbuffered reads; see below.)
  *
  * That's all there is to it. The StreamingLexer will track your position in the
  * input and buffer enough data so that your lexing methods can process
  * everything in one pass. Lex() returns Nothing() if more data is needed, in
- * which case you should just return from WriteInternal(). If lexing reaches a
+ * which case you should just return from DoDecode(). If lexing reaches a
  * terminal state, Lex() returns Some(State::SUCCESS) or Some(State::FAILURE),
  * and you can check which one to determine if lexing succeeded or failed and do
  * any necessary cleanup.
  *
  * There's one more wrinkle: some lexers may want to *avoid* buffering in some
  * cases, and just process the data as it comes in. This is useful if, for
  * example, you just want to skip over a large section of data; there's no point
  * in buffering data you're just going to ignore.
--- a/image/decoders/nsBMPDecoder.cpp
+++ b/image/decoders/nsBMPDecoder.cpp
@@ -431,25 +431,25 @@ nsBMPDecoder::FinishRow()
     }
   } else {
     PostInvalidation(IntRect(0, mCurrentRow, mH.mWidth, 1));
   }
   mCurrentRow--;
 }
 
 void
-nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
+nsBMPDecoder::DoDecode(const char* aBuffer, size_t aLength)
 {
-  MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
+  MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
   MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aCount > 0);
+  MOZ_ASSERT(aLength > 0);
 
   Maybe<TerminalState> terminalState =
-    mLexer.Lex(aBuffer, aCount, [=](State aState,
-                                    const char* aData, size_t aLength) {
+    mLexer.Lex(aBuffer, aLength, [=](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();
         case State::AFTER_GAP:        return AfterGap();
--- a/image/decoders/nsBMPDecoder.h
+++ b/image/decoders/nsBMPDecoder.h
@@ -144,18 +144,17 @@ public:
 
   /// Force transparency from outside. (Used by the ICO decoder.)
   void SetHasTransparency()
   {
     mMayHaveTransparency = true;
     mDoesHaveTransparency = true;
   }
 
-  virtual void WriteInternal(const char* aBuffer,
-                             uint32_t aCount) override;
+  void DoDecode(const char* aBuffer, size_t aLength) 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,25 +450,25 @@ 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]);
   }
 }
 
 void
-nsGIFDecoder2::WriteInternal(const char* aBuffer, uint32_t aCount)
+nsGIFDecoder2::DoDecode(const char* aBuffer, size_t aLength)
 {
-  MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
+  MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
   MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aCount > 0);
+  MOZ_ASSERT(aLength > 0);
 
   Maybe<TerminalState> terminalState =
-    mLexer.Lex(aBuffer, aCount, [=](State aState,
-                                    const char* aData, size_t aLength) {
+    mLexer.Lex(aBuffer, aLength, [=](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);
           case State::FINISHED_GLOBAL_COLOR_TABLE:
--- a/image/decoders/nsGIFDecoder2.h
+++ b/image/decoders/nsGIFDecoder2.h
@@ -19,17 +19,17 @@ class RasterImage;
 //////////////////////////////////////////////////////////////////////
 // nsGIFDecoder2 Definition
 
 class nsGIFDecoder2 : public Decoder
 {
 public:
   ~nsGIFDecoder2();
 
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
+  void DoDecode(const char* aBuffer, size_t aLength) 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,24 +593,24 @@ nsICODecoder::FinishResource()
       mContainedDecoder->GetSize() != GetRealSize()) {
     return Transition::TerminateFailure();
   }
 
   return Transition::TerminateSuccess();
 }
 
 void
-nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
+nsICODecoder::DoDecode(const char* aBuffer, size_t aLength)
 {
-  MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
+  MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
   MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aCount > 0);
+  MOZ_ASSERT(aLength > 0);
 
   Maybe<TerminalState> terminalState =
-    mLexer.Lex(aBuffer, aCount,
+    mLexer.Lex(aBuffer, aLength,
                [=](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;
 
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
+  void DoDecode(const char* aBuffer, size_t aLength) 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,25 +22,25 @@ nsIconDecoder::nsIconDecoder(RasterImage
 {
   // Nothing to do
 }
 
 nsIconDecoder::~nsIconDecoder()
 { }
 
 void
-nsIconDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
+nsIconDecoder::DoDecode(const char* aBuffer, size_t aLength)
 {
-  MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
+  MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
   MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aCount > 0);
+  MOZ_ASSERT(aLength > 0);
 
   Maybe<TerminalState> terminalState =
-    mLexer.Lex(aBuffer, aCount, [=](State aState,
-                                    const char* aData, size_t aLength) {
+    mLexer.Lex(aBuffer, aLength, [=](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();
         default:
--- a/image/decoders/nsIconDecoder.h
+++ b/image/decoders/nsIconDecoder.h
@@ -32,17 +32,17 @@ class RasterImage;
 //
 ////////////////////////////////////////////////////////////////////////////////
 
 class nsIconDecoder : public Decoder
 {
 public:
   virtual ~nsIconDecoder();
 
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
+  void DoDecode(const char* aBuffer, size_t aLength) 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,25 +175,25 @@ nsJPEGDecoder::FinishInternal()
   if ((mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER) &&
       (mState != JPEG_ERROR) &&
       !IsMetadataDecode()) {
     mState = JPEG_DONE;
   }
 }
 
 void
-nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
+nsJPEGDecoder::DoDecode(const char* aBuffer, size_t aLength)
 {
-  MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
+  MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
   MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aCount > 0);
+  MOZ_ASSERT(aLength > 0);
 
   Maybe<TerminalState> terminalState =
-    mLexer.Lex(aBuffer, aCount, [=](State aState,
-                                    const char* aData, size_t aLength) {
+    mLexer.Lex(aBuffer, aLength, [=](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;
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
+  void DoDecode(const char* aBuffer, size_t aLength) 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,25 +344,25 @@ nsPNGDecoder::InitInternal()
   png_set_progressive_read_fn(mPNG, static_cast<png_voidp>(this),
                               nsPNGDecoder::info_callback,
                               nsPNGDecoder::row_callback,
                               nsPNGDecoder::end_callback);
 
 }
 
 void
-nsPNGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
+nsPNGDecoder::DoDecode(const char* aBuffer, size_t aLength)
 {
-  MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
+  MOZ_ASSERT(!HasError(), "Shouldn't call DoDecode after error!");
   MOZ_ASSERT(aBuffer);
-  MOZ_ASSERT(aCount > 0);
+  MOZ_ASSERT(aLength > 0);
 
   Maybe<TerminalState> terminalState =
-    mLexer.Lex(aBuffer, aCount, [=](State aState,
-                                    const char* aData, size_t aLength) {
+    mLexer.Lex(aBuffer, aLength, [=](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;
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
+  void DoDecode(const char* aBuffer, size_t aLength) override;
   virtual Telemetry::ID SpeedHistogram() override;
 
   /// @return true if this PNG is a valid ICO resource.
   bool IsValidICO() const;
 
 private:
   friend class DecoderFactory;