Bug 1315554 - Part 4. Combine nsICODecoder::ReadBMP and ::ReadPNG. r=tnikkel
☠☠ backed out by a652fc078608 ☠ ☠
authorAndrew Osmond <aosmond@mozilla.com>
Sat, 22 Jul 2017 00:14:59 -0400
changeset 419089 e67f6df41836b70373f7337ae392533ac9c8c7bf
parent 419088 9780a01b3e949a5bf0f6a95fe0e1ed25d5cebe29
child 419090 6fa3ad97ce9c28ac9e66adf75c37142b0a9e21e1
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 4. Combine nsICODecoder::ReadBMP and ::ReadPNG. r=tnikkel
image/decoders/nsICODecoder.cpp
image/decoders/nsICODecoder.h
--- a/image/decoders/nsICODecoder.cpp
+++ b/image/decoders/nsICODecoder.cpp
@@ -275,17 +275,17 @@ nsICODecoder::SniffResource(const char* 
 
     if (mDirEntry.mBytesInRes <= PNGSIGNATURESIZE) {
       return Transition::TerminateFailure();
     }
 
     // Read in the rest of the PNG unbuffered.
     size_t toRead = mDirEntry.mBytesInRes - PNGSIGNATURESIZE;
     return Transition::ToUnbuffered(ICOState::FINISHED_RESOURCE,
-                                    ICOState::READ_PNG,
+                                    ICOState::READ_RESOURCE,
                                     toRead);
   } else {
     // Make sure we have a sane size for the bitmap information header.
     int32_t bihSize = LittleEndian::readUint32(aData);
     if (bihSize != static_cast<int32_t>(BITMAPINFOSIZE)) {
       return Transition::TerminateFailure();
     }
 
@@ -294,23 +294,23 @@ nsICODecoder::SniffResource(const char* 
 
     // Read in the rest of the bitmap information header.
     return Transition::To(ICOState::READ_BIH,
                           BITMAPINFOSIZE - PNGSIGNATURESIZE);
   }
 }
 
 LexerTransition<ICOState>
-nsICODecoder::ReadPNG(const char* aData, uint32_t aLen)
+nsICODecoder::ReadResource(const char* aData, uint32_t aLen)
 {
   if (!WriteToContainedDecoder(aData, aLen)) {
     return Transition::TerminateFailure();
   }
 
-  return Transition::ContinueUnbuffered(ICOState::READ_PNG);
+  return Transition::ContinueUnbuffered(ICOState::READ_RESOURCE);
 }
 
 LexerTransition<ICOState>
 nsICODecoder::ReadBIH(const char* aData)
 {
   // Buffer the rest of the bitmap information header.
   memcpy(mBIHraw + PNGSIGNATURESIZE, aData, BITMAPINFOSIZE - PNGSIGNATURESIZE);
 
@@ -360,31 +360,21 @@ nsICODecoder::ReadBIH(const char* aData)
   // the BMP data itself.
   uint32_t bmpDataLength = bmpDecoder->GetCompressedImageSize() + 4 * numColors;
   bool hasANDMask = (BITMAPINFOSIZE + bmpDataLength) < mDirEntry.mBytesInRes;
   ICOState afterBMPState = hasANDMask ? ICOState::PREPARE_FOR_MASK
                                       : ICOState::FINISHED_RESOURCE;
 
   // Read in the rest of the BMP unbuffered.
   return Transition::ToUnbuffered(afterBMPState,
-                                  ICOState::READ_BMP,
+                                  ICOState::READ_RESOURCE,
                                   bmpDataLength);
 }
 
 LexerTransition<ICOState>
-nsICODecoder::ReadBMP(const char* aData, uint32_t aLen)
-{
-  if (!WriteToContainedDecoder(aData, aLen)) {
-    return Transition::TerminateFailure();
-  }
-
-  return Transition::ContinueUnbuffered(ICOState::READ_BMP);
-}
-
-LexerTransition<ICOState>
 nsICODecoder::PrepareForMask()
 {
   RefPtr<nsBMPDecoder> bmpDecoder =
     static_cast<nsBMPDecoder*>(mContainedDecoder.get());
 
   uint16_t numColors = GetNumColors();
   MOZ_ASSERT(numColors != uint16_t(-1));
 
@@ -563,22 +553,20 @@ nsICODecoder::DoDecode(SourceBufferItera
       case ICOState::DIR_ENTRY:
         return ReadDirEntry(aData);
       case ICOState::SKIP_TO_RESOURCE:
         return Transition::ContinueUnbuffered(ICOState::SKIP_TO_RESOURCE);
       case ICOState::FOUND_RESOURCE:
         return Transition::To(ICOState::SNIFF_RESOURCE, PNGSIGNATURESIZE);
       case ICOState::SNIFF_RESOURCE:
         return SniffResource(aData);
-      case ICOState::READ_PNG:
-        return ReadPNG(aData, aLength);
+      case ICOState::READ_RESOURCE:
+        return ReadResource(aData, aLength);
       case ICOState::READ_BIH:
         return ReadBIH(aData);
-      case ICOState::READ_BMP:
-        return ReadBMP(aData, aLength);
       case ICOState::PREPARE_FOR_MASK:
         return PrepareForMask();
       case ICOState::READ_MASK_ROW:
         return ReadMaskRow(aData);
       case ICOState::FINISH_MASK:
         return FinishMask();
       case ICOState::SKIP_MASK:
         return Transition::ContinueUnbuffered(ICOState::SKIP_MASK);
--- a/image/decoders/nsICODecoder.h
+++ b/image/decoders/nsICODecoder.h
@@ -22,19 +22,18 @@ class RasterImage;
 
 enum class ICOState
 {
   HEADER,
   DIR_ENTRY,
   SKIP_TO_RESOURCE,
   FOUND_RESOURCE,
   SNIFF_RESOURCE,
-  READ_PNG,
+  READ_RESOURCE,
   READ_BIH,
-  READ_BMP,
   PREPARE_FOR_MASK,
   READ_MASK_ROW,
   FINISH_MASK,
   SKIP_MASK,
   FINISHED_RESOURCE
 };
 
 class nsICODecoder : public Decoder
@@ -88,19 +87,18 @@ private:
   nsresult GetFinalStateFromContainedDecoder();
 
   // Obtains the number of colors from the BPP, mBPP must be filled in
   uint16_t GetNumColors();
 
   LexerTransition<ICOState> ReadHeader(const char* aData);
   LexerTransition<ICOState> ReadDirEntry(const char* aData);
   LexerTransition<ICOState> SniffResource(const char* aData);
-  LexerTransition<ICOState> ReadPNG(const char* aData, uint32_t aLen);
+  LexerTransition<ICOState> ReadResource(const char* aData, uint32_t aLen);
   LexerTransition<ICOState> ReadBIH(const char* aData);
-  LexerTransition<ICOState> ReadBMP(const char* aData, uint32_t aLen);
   LexerTransition<ICOState> PrepareForMask();
   LexerTransition<ICOState> ReadMaskRow(const char* aData);
   LexerTransition<ICOState> FinishMask();
   LexerTransition<ICOState> FinishResource();
 
   StreamingLexer<ICOState, 32> mLexer; // The lexer.
   RefPtr<Decoder> mContainedDecoder; // Either a BMP or PNG decoder.
   RefPtr<SourceBuffer> mContainedSourceBuffer;  // SourceBuffer for mContainedDecoder.