Unreviewed, rolling out r143936.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Feb 2013 22:06:15 +0000 (22:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Feb 2013 22:06:15 +0000 (22:06 +0000)
http://trac.webkit.org/changeset/143936
https://bugs.webkit.org/show_bug.cgi?id=110789

Causes webkit_unit_tests failures on android dbg (Requested by
vollick on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2013-02-25

Source/WebCore:

* platform/image-decoders/gif/GIFImageDecoder.cpp:
(WebCore::GIFImageDecoder::GIFImageDecoder):
(WebCore::GIFImageDecoder::setData):
(WebCore::GIFImageDecoder::frameCount):
(WebCore::GIFImageDecoder::decodingHalted):
(WebCore):
(WebCore::GIFImageDecoder::haveDecodedRow):
(WebCore::GIFImageDecoder::decode):
* platform/image-decoders/gif/GIFImageDecoder.h:
(GIFImageDecoder):
* platform/image-decoders/gif/GIFImageReader.cpp:
(GIFImageReader::doLZW):
(GIFImageReader::read):
* platform/image-decoders/gif/GIFImageReader.h:
(GIFFrameContext):
(GIFFrameContext::GIFFrameContext):
(GIFFrameContext::~GIFFrameContext):
(GIFImageReader::GIFImageReader):
(GIFImageReader::~GIFImageReader):
(GIFImageReader):
(GIFImageReader::globalColormap):
(GIFImageReader::globalColormapSize):

Source/WebKit/chromium:

* WebKit.gyp:
* WebKit.gypi:
* tests/GIFImageDecoderTest.cpp: Removed.
* tests/data/broken.gif: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143972 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
Source/WebCore/platform/image-decoders/gif/GIFImageReader.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageReader.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gyp
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp [deleted file]
Source/WebKit/chromium/tests/data/broken.gif [deleted file]

index fad646e..71da26c 100644 (file)
@@ -1,3 +1,35 @@
+2013-02-25  Sheriff Bot  <webkit.review.bot@gmail.com>
+
+        Unreviewed, rolling out r143936.
+        http://trac.webkit.org/changeset/143936
+        https://bugs.webkit.org/show_bug.cgi?id=110789
+
+        Causes webkit_unit_tests failures on android dbg (Requested by
+        vollick on #webkit).
+
+        * platform/image-decoders/gif/GIFImageDecoder.cpp:
+        (WebCore::GIFImageDecoder::GIFImageDecoder):
+        (WebCore::GIFImageDecoder::setData):
+        (WebCore::GIFImageDecoder::frameCount):
+        (WebCore::GIFImageDecoder::decodingHalted):
+        (WebCore):
+        (WebCore::GIFImageDecoder::haveDecodedRow):
+        (WebCore::GIFImageDecoder::decode):
+        * platform/image-decoders/gif/GIFImageDecoder.h:
+        (GIFImageDecoder):
+        * platform/image-decoders/gif/GIFImageReader.cpp:
+        (GIFImageReader::doLZW):
+        (GIFImageReader::read):
+        * platform/image-decoders/gif/GIFImageReader.h:
+        (GIFFrameContext):
+        (GIFFrameContext::GIFFrameContext):
+        (GIFFrameContext::~GIFFrameContext):
+        (GIFImageReader::GIFImageReader):
+        (GIFImageReader::~GIFImageReader):
+        (GIFImageReader):
+        (GIFImageReader::globalColormap):
+        (GIFImageReader::globalColormapSize):
+
 2013-02-25  Kentaro Hara  <haraken@chromium.org>
 
         [V8] Generate a wrapper function for method callbacks
index 6a51409..0cb2288 100644 (file)
@@ -37,6 +37,7 @@ GIFImageDecoder::GIFImageDecoder(ImageSource::AlphaOption alphaOption,
     : ImageDecoder(alphaOption, gammaAndColorProfileOption)
     , m_alreadyScannedThisDataForFrameCount(true)
     , m_repetitionCount(cAnimationLoopOnce)
+    , m_readOffset(0)
 {
 }
 
@@ -50,8 +51,6 @@ void GIFImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
         return;
 
     ImageDecoder::setData(data, allDataReceived);
-    if (m_reader)
-        m_reader->setData(data);
 
     // We need to rescan the frame count, as the new data may have changed it.
     m_alreadyScannedThisDataForFrameCount = false;
@@ -86,8 +85,7 @@ size_t GIFImageDecoder::frameCount()
         // all the data.  Note that this is no worse than what ImageIO does on
         // Mac right now (it also crawls all the data again).
         GIFImageReader reader(0);
-        reader.setData(m_data);
-        reader.decode(GIFFrameCountQuery, static_cast<unsigned>(-1));
+        reader.read((const unsigned char*)m_data->data(), m_data->size(), GIFFrameCountQuery, static_cast<unsigned>(-1));
         m_alreadyScannedThisDataForFrameCount = true;
         m_frameBufferCache.resize(reader.imagesCount());
         for (int i = 0; i < reader.imagesCount(); ++i)
@@ -193,6 +191,11 @@ void GIFImageDecoder::clearFrameBufferCache(size_t clearBeforeFrame)
     }
 }
 
+void GIFImageDecoder::decodingHalted(unsigned bytesLeft)
+{
+    m_readOffset = m_data->size() - bytesLeft;
+}
+
 bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, unsigned char* rowBuffer, unsigned char* rowEnd, unsigned rowNumber, unsigned repeatCount, bool writeTransparentPixels)
 {
     const GIFFrameContext* frameContext = m_reader->frameContext();
@@ -213,8 +216,8 @@ bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, unsigned char* rowBuff
     const unsigned char* colorMap;
     unsigned colorMapSize;
     if (frameContext->isLocalColormapDefined) {
-        colorMap = m_reader->localColormap(frameContext);
-        colorMapSize = m_reader->localColormapSize(frameContext);
+        colorMap = frameContext->localColormap;
+        colorMapSize = (unsigned)frameContext->localColormapSize;
     } else {
         colorMap = m_reader->globalColormap();
         colorMapSize = m_reader->globalColormapSize();
@@ -316,14 +319,12 @@ void GIFImageDecoder::decode(unsigned haltAtFrame, GIFQuery query)
     if (failed())
         return;
 
-    if (!m_reader) {
+    if (!m_reader)
         m_reader = adoptPtr(new GIFImageReader(this));
-        m_reader->setData(m_data);
-    }
 
     // If we couldn't decode the image but we've received all the data, decoding
     // has failed.
-    if (!m_reader->decode(query, haltAtFrame) && isAllDataReceived())
+    if (!m_reader->read((const unsigned char*)m_data->data() + m_readOffset, m_data->size() - m_readOffset, query, haltAtFrame) && isAllDataReceived())
         setFailed();
 }
 
index 9982a44..7bda994 100644 (file)
@@ -56,6 +56,7 @@ namespace WebCore {
         virtual void clearFrameBufferCache(size_t clearBeforeFrame);
 
         // Callbacks from the GIF reader.
+        void decodingHalted(unsigned bytesLeft);
         bool haveDecodedRow(unsigned frameIndex, unsigned char* rowBuffer, unsigned char* rowEnd, unsigned rowNumber, unsigned repeatCount, bool writeTransparentPixels);
         bool frameComplete(unsigned frameIndex, unsigned frameDuration, ImageFrame::FrameDisposalMethod disposalMethod);
         void gifComplete();
@@ -76,6 +77,7 @@ namespace WebCore {
         bool m_currentBufferSawAlpha;
         mutable int m_repetitionCount;
         OwnPtr<GIFImageReader> m_reader;
+        unsigned m_readOffset;
     };
 
 } // namespace WebCore
index cce069f..699d3c4 100644 (file)
@@ -201,7 +201,7 @@ bool GIFImageReader::outputRow()
 }
 
 // Perform Lempel-Ziv-Welch decoding.
-bool GIFImageReader::doLZW(const unsigned char* block, size_t bytesInBlock)
+bool GIFImageReader::doLZW(const unsigned char *q)
 {
     if (!m_frameContext)
         return true;
@@ -215,7 +215,7 @@ bool GIFImageReader::doLZW(const unsigned char* block, size_t bytesInBlock)
     // back into the GIF decoder structure when we exit.
     int avail = m_frameContext->avail;
     int bits = m_frameContext->bits;
-    size_t cnt = bytesInBlock;
+    int cnt = m_count;
     int codesize = m_frameContext->codesize;
     int codemask = m_frameContext->codemask;
     int oldcode = m_frameContext->oldcode;
@@ -249,7 +249,7 @@ bool GIFImageReader::doLZW(const unsigned char* block, size_t bytesInBlock)
             goto END; \
     } while (0)
 
-    for (ch = block; cnt-- > 0; ch++) {
+    for (ch = q; cnt-- > 0; ch++) {
         // Feed the next byte into the decoder's 32-bit input buffer.
         datum += ((int) *ch) << bits;
         bits += 8;
@@ -344,6 +344,7 @@ END:
     m_frameContext->bits = bits;
     m_frameContext->codesize = codesize;
     m_frameContext->codemask = codemask;
+    m_count = cnt;
     m_frameContext->oldcode = oldcode;
     m_frameContext->firstchar = firstchar;
     m_frameContext->datum = datum;
@@ -353,39 +354,68 @@ END:
     return true;
 }
 
-bool GIFImageReader::decode(GIFImageDecoder::GIFQuery query, unsigned haltAtFrame)
-{
-    ASSERT(m_bytesRead <= m_data->size());
-    return decodeInternal(m_bytesRead, m_data->size() - m_bytesRead, query, haltAtFrame);
-}
 
 // Process data arriving from the stream for the gif decoder.
-bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDecoder::GIFQuery query, unsigned haltAtFrame)
+bool GIFImageReader::read(const unsigned char *buf, unsigned len, GIFImageDecoder::GIFQuery query, unsigned haltAtFrame)
 {
     if (!len) {
         // No new data has come in since the last call, just ignore this call.
         return true;
     }
 
-    if (len < m_bytesToConsume)
-        return false;
+    const unsigned char *q = buf;
+
+    // Add what we have so far to the block.
+    // If previous call to me left something in the hold first complete current block
+    // or if we are filling the colormaps, first complete the colormap.
+    unsigned char* p = 0;
+    if (m_state == GIFGlobalColormap)
+        p = m_globalColormap;
+    else if (m_state == GIFImageColormap)
+        p = m_frameContext ? m_frameContext->localColormap : 0;
+    else if (m_bytesInHold)
+        p = m_hold;
+    else
+        p = 0;
+
+    if (p || (m_state == GIFGlobalColormap) || (m_state == GIFImageColormap)) {
+        // Add what we have sofar to the block
+        unsigned length = len < m_bytesToConsume ? len : m_bytesToConsume;
+        if (p)
+            memcpy(p + m_bytesInHold, buf, length);
+
+        if (length < m_bytesToConsume) {
+            // Not enough in 'buf' to complete current block, get more
+            m_bytesInHold += length;
+            m_bytesToConsume -= length;
+            if (m_client)
+                m_client->decodingHalted(0);
+            return false;
+        }
+
+        // Reset hold buffer count
+        m_bytesInHold = 0;
 
-    // This loop reads as many components from |m_data| as possible.
-    // At the beginning of each iteration, dataPosition will be advanced by m_bytesToConsume to
-    // point to the next component. len will be decremented accordingly.
-    while (len >= m_bytesToConsume) {
-        // FIXME: Rename this variable to currentComponent.
-        const unsigned char* q = data(dataPosition);
+        // Point 'q' to complete block in hold (or in colormap)
+        q = p;
+    }
 
-        // Mark the current component as consumed. Note that q will remain pointed at this
-        // component until the next loop iteration.
-        dataPosition += m_bytesToConsume;
+    // Invariant:
+    //    'q' is start of current to be processed block (hold, colormap or buf)
+    //    'm_bytesToConsume' is number of bytes to consume from 'buf'
+    //    'buf' points to the bytes to be consumed from the input buffer
+    //    'len' is number of bytes left in input buffer from position 'buf'.
+    //    At entrance of the for loop will 'buf' will be moved 'm_bytesToConsume'
+    //    to point to next buffer, 'len' is adjusted accordingly.
+    //    So that next round in for loop, q gets pointed to the next buffer.
+    for (;len >= m_bytesToConsume; q = buf) {
+        // Eat the current block from the buffer, q keeps pointed at current block.
+        buf += m_bytesToConsume;
         len -= m_bytesToConsume;
 
         switch (m_state) {
         case GIFLZW:
-            // m_bytesToConsume is the current component size because it hasn't been updated.
-            if (!doLZW(q, m_bytesToConsume))
+            if (!doLZW(q))
                 return false; // If doLZW() encountered an error, it has already called m_client->setFailed().
             GETN(1, GIFSubBlock);
             break;
@@ -458,18 +488,23 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
 
             if ((q[4] & 0x80) && m_globalColormapSize > 0) { /* global map */
                 // Get the global colormap
-                const size_t globalColormapBytes = 3 * m_globalColormapSize;
-                m_globalColormapPosition = dataPosition;
+                const unsigned size = 3*m_globalColormapSize;
+
+                // Malloc the color map, but only if we're not just counting frames.
+                if (query != GIFImageDecoder::GIFFrameCountQuery)
+                    m_globalColormap = new unsigned char[size];
 
-                if (len < globalColormapBytes) {
-                    // Wait until we have enough bytes to consume the entire colormap at once.
-                    GETN(globalColormapBytes, GIFGlobalColormap);
+                if (len < size) {
+                    // Use 'hold' pattern to get the global colormap
+                    GETN(size, GIFGlobalColormap);
                     break;
                 }
 
-                m_isGlobalColormapDefined = true;
-                dataPosition += globalColormapBytes;
-                len -= globalColormapBytes;
+                // Copy everything and go directly to GIFImage_start.
+                if (m_globalColormap)
+                    memcpy(m_globalColormap, buf, size);
+                buf += size;
+                len -= size;
             }
 
             GETN(1, GIFImageStart);
@@ -481,7 +516,7 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
         }
 
         case GIFGlobalColormap: {
-            m_isGlobalColormapDefined = true;
+            // Everything is already copied into m_globalColormap
             GETN(1, GIFImageStart);
             break;
         }
@@ -510,7 +545,7 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
         }
 
         case GIFExtension: {
-            size_t bytesInBlock = q[1];
+            m_count = q[1];
             GIFState es = GIFSkipBlock;
 
             // The GIF spec mandates lengths for three of the extensions below.
@@ -531,17 +566,17 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
             switch (*q) {
             case 0xf9:
                 es = GIFControlExtension;
-                bytesInBlock = std::max(bytesInBlock, static_cast<size_t>(4));
+                m_count = std::max(m_count, 4);
                 break;
 
             case 0x01:
                 // ignoring plain text extension
-                bytesInBlock = std::max(bytesInBlock, static_cast<size_t>(12));
+                m_count = std::max(m_count, 12);
                 break;
 
             case 0xff:
                 es = GIFApplicationExtension;
-                bytesInBlock = std::max(bytesInBlock, static_cast<size_t>(11));
+                m_count = std::max(m_count, 11);
                 break;
 
             case 0xfe:
@@ -549,8 +584,8 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
                 break;
             }
 
-            if (bytesInBlock)
-                GETN(bytesInBlock, es);
+            if (m_count)
+                GETN(m_count, es);
             else
                 GETN(1, GIFImageStart);
             break;
@@ -694,7 +729,8 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
             if (query == GIFImageDecoder::GIFSizeQuery || haltAtFrame == m_imagesDecoded) {
                 // The decoder needs to stop. Hand back the number of bytes we consumed from
                 // buffer minus 9 (the amount we consumed to read the header).
-                setRemainingBytes(len + 9);
+                if (m_client)
+                    m_client->decodingHalted(len + 9);
                 GETN(9, GIFImageHeader);
                 return true;
             }
@@ -758,24 +794,33 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
             // has a local colormap?
             if (q[8] & 0x80) {
                 int numColors = 2 << (q[8] & 0x7);
-                const size_t localColormapBytes = 3 * numColors;
+                const unsigned size = 3 * numColors;
+                unsigned char *map = m_frameContext ? m_frameContext->localColormap : 0;
+                if (m_frameContext && (!map || (numColors > m_frameContext->localColormapSize))) {
+                    delete []map;
+                    map = new unsigned char[size];
+                    if (!map)
+                        return m_client ? m_client->setFailed() : false;
+                }
 
                 // Switch to the new local palette after it loads
                 if (m_frameContext) {
-                    m_frameContext->localColormapPosition = dataPosition;
+                    m_frameContext->localColormap = map;
                     m_frameContext->localColormapSize = numColors;
+                    m_frameContext->isLocalColormapDefined = true;
                 }
 
-                if (len < localColormapBytes) {
-                    // Wait until we have enough bytes to consume the entire colormap at once.
-                    GETN(localColormapBytes, GIFImageColormap);
+                if (len < size) {
+                    // Use 'hold' pattern to get the image colormap
+                    GETN(size, GIFImageColormap);
                     break;
                 }
 
+                // Copy everything and directly go to GIFLZWStart
                 if (m_frameContext)
-                    m_frameContext->isLocalColormapDefined = true;
-                dataPosition += localColormapBytes;
-                len -= localColormapBytes;
+                    memcpy(m_frameContext->localColormap, buf, size);
+                buf += size;
+                len -= size;
             } else if (m_frameContext) {
                 // Switch back to the global palette
                 m_frameContext->isLocalColormapDefined = false;
@@ -785,23 +830,21 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
         }
 
         case GIFImageColormap: {
-            if (m_frameContext)
-                m_frameContext->isLocalColormapDefined = true;
+            // Everything is already copied into localColormap
             GETN(1, GIFLZWStart);
             break;
         }
 
         case GIFSubBlock: {
             // Still working on the same image: Process next LZW data block.
-            const size_t bytesInBlock = *q;
-            if (bytesInBlock) {
+            if ((m_count = *q)) {
                 // Make sure there are still rows left. If the GIF data
                 // is corrupt, we may not get an explicit terminator.
                 if (m_frameContext && !m_frameContext->rowsRemaining) {
                     // This is an illegal GIF, but we remain tolerant.
                     GETN(1, GIFSubBlock);
                 }
-                GETN(bytesInBlock, GIFLZW);
+                GETN(m_count, GIFLZW);
             } else {
                 // See if there are any more images in this sequence.
                 m_imagesDecoded++;
@@ -834,12 +877,23 @@ bool GIFImageReader::decodeInternal(size_t dataPosition, size_t len, GIFImageDec
         }
     }
 
-    setRemainingBytes(len);
-    return false;
-}
+    // Copy the leftover into m_frameContext->m_hold
+    m_bytesInHold = len;
+    if (len) {
+        // Add what we have sofar to the block
+        unsigned char* p;
+        if (m_state == GIFGlobalColormap)
+            p = m_globalColormap;
+        else if (m_state == GIFImageColormap)
+            p = m_frameContext ? m_frameContext->localColormap : 0;
+        else
+            p = m_hold;
+        if (p)
+            memcpy(p, buf, len);
+        m_bytesToConsume -= len;
+    }
 
-void GIFImageReader::setRemainingBytes(size_t remainingBytes)
-{
-    ASSERT(remainingBytes <= m_data->size());
-    m_bytesRead = m_data->size() - remainingBytes;
+    if (m_client)
+        m_client->decodingHalted(0);
+    return false;
 }
index c2e33e1..c082918 100644 (file)
 // Define ourselves as the clientPtr.  Mozilla just hacked their C++ callback class into this old C decoder,
 // so we will too.
 #include "GIFImageDecoder.h"
-#include "SharedBuffer.h"
 
 #define MAX_LZW_BITS          12
 #define MAX_BITS            4097 /* 2^MAX_LZW_BITS+1 */
 #define MAX_COLORS           256
-#define GIF_COLORS             3
+#define MAX_HOLD_SIZE        256
 
 const int cLoopCountNotSeen = -2;
 
@@ -104,7 +103,7 @@ public:
     unsigned height;
     int tpixel; // Index of transparent pixel.
     WebCore::ImageFrame::FrameDisposalMethod disposalMethod; // Restore to background, leave in place, etc.
-    size_t localColormapPosition; // Per-image colormap.
+    unsigned char *localColormap; // Per-image colormap.
     int localColormapSize; // Size of local colormap array.
     
     bool isLocalColormapDefined : 1;
@@ -141,7 +140,7 @@ public:
         , height(0)
         , tpixel(0)
         , disposalMethod(WebCore::ImageFrame::DisposeNotSpecified)
-        , localColormapPosition(0)
+        , localColormap(0)
         , localColormapSize(0)
         , isLocalColormapDefined(false)
         , progressiveDisplay(false)
@@ -157,6 +156,7 @@ public:
     ~GIFFrameContext()
     {
         delete [] rowbuf;
+        delete [] localColormap;
         delete [] prefix;
         delete [] suffix;
         delete [] stack;
@@ -169,87 +169,66 @@ public:
     GIFImageReader(WebCore::GIFImageDecoder* client = 0)
         : m_client(client)
         , m_state(GIFType)
-        , m_bytesToConsume(6) // Number of bytes for GIF type, either "GIF87a" or "GIF89a".
-        , m_bytesRead(0)
+        , m_bytesToConsume(6)
+        , m_bytesInHold(0)
+        , m_globalColormap(0)
         , m_screenBgcolor(0)
         , m_version(0)
         , m_screenWidth(0)
         , m_screenHeight(0)
-        , m_isGlobalColormapDefined(false)
-        , m_globalColormapPosition(0)
         , m_globalColormapSize(0)
         , m_imagesDecoded(0)
         , m_imagesCount(0)
         , m_loopCount(cLoopCountNotSeen)
+        , m_count(0)
         , m_frameContext(0)
     {
     }
 
     ~GIFImageReader()
     {
+        delete [] m_globalColormap;
+        m_globalColormap = 0;
+
         delete m_frameContext;
         m_frameContext = 0;
     }
 
-    void setData(PassRefPtr<WebCore::SharedBuffer> data) { m_data = data; }
-    bool decode(WebCore::GIFImageDecoder::GIFQuery, unsigned haltAtFrame);
+    bool read(const unsigned char* buf, unsigned numbytes, WebCore::GIFImageDecoder::GIFQuery = WebCore::GIFImageDecoder::GIFFullQuery, unsigned haltAtFrame = -1);
 
     int imagesCount() const { return m_imagesCount; }
     int loopCount() const { return m_loopCount; }
-
-    const unsigned char* globalColormap() const
-    {
-        return m_isGlobalColormapDefined ? data(m_globalColormapPosition) : 0;
-    }
-    int globalColormapSize() const
-    {
-        return m_isGlobalColormapDefined ? m_globalColormapSize : 0;
-    }
-
-    const unsigned char* localColormap(const GIFFrameContext* frame) const
-    {
-        return frame->isLocalColormapDefined ? data(frame->localColormapPosition) : 0;
-    }
-    int localColormapSize(const GIFFrameContext* frame) const
-    {
-        return frame->isLocalColormapDefined ? frame->localColormapSize : 0;
-    }
-
+    unsigned char* globalColormap() const { return m_globalColormap; }
+    int globalColormapSize() const { return m_globalColormapSize; }
     const GIFFrameContext* frameContext() const { return m_frameContext; }
 
 private:
-    bool decodeInternal(size_t dataPosition, size_t len, WebCore::GIFImageDecoder::GIFQuery, unsigned haltAtFrame);
     bool outputRow();
-    bool doLZW(const unsigned char *, size_t);
-    void setRemainingBytes(size_t);
-
-    const unsigned char* data(size_t dataPosition) const
-    {
-        return reinterpret_cast<const unsigned char*>(m_data->data()) + dataPosition;
-    }
+    bool doLZW(const unsigned char *q);
 
     WebCore::GIFImageDecoder* m_client;
 
     // Parsing state machine.
     GIFState m_state; // Current decoder master state.
-    size_t m_bytesToConsume; // Number of bytes to consume for next stage of parsing.
-    size_t m_bytesRead; // Number of bytes processed.
+    unsigned m_bytesToConsume; // Number of bytes to accumulate.
+    unsigned m_bytesInHold; // bytes accumulated so far.
+    unsigned char m_hold[MAX_HOLD_SIZE]; // Accumulation buffer.
+    unsigned char* m_globalColormap; // (3* MAX_COLORS in size) Default colormap if local not supplied, 3 bytes for each color.
     
     // Global (multi-image) state.
     int m_screenBgcolor; // Logical screen background color.
     int m_version; // Either 89 for GIF89 or 87 for GIF87.
     unsigned m_screenWidth; // Logical screen width & height.
     unsigned m_screenHeight;
-    bool m_isGlobalColormapDefined;
-    size_t m_globalColormapPosition; // (3* MAX_COLORS in size) Default colormap if local not supplied, 3 bytes for each color.
     int m_globalColormapSize; // Size of global colormap array.
     unsigned m_imagesDecoded; // Counts completed frames for animated GIFs.
     int m_imagesCount; // Counted all frames seen so far (including incomplete frames).
     int m_loopCount; // Netscape specific extension block to control the number of animation loops a GIF renders.
     
+    // Not really global, but convenient to locate here.
+    int m_count; // Remaining # bytes in sub-block.
+    
     GIFFrameContext* m_frameContext;
-
-    RefPtr<WebCore::SharedBuffer> m_data;
 };
 
 #endif
index 5521da9..33aca65 100644 (file)
@@ -1,3 +1,17 @@
+2013-02-25  Sheriff Bot  <webkit.review.bot@gmail.com>
+
+        Unreviewed, rolling out r143936.
+        http://trac.webkit.org/changeset/143936
+        https://bugs.webkit.org/show_bug.cgi?id=110789
+
+        Causes webkit_unit_tests failures on android dbg (Requested by
+        vollick on #webkit).
+
+        * WebKit.gyp:
+        * WebKit.gypi:
+        * tests/GIFImageDecoderTest.cpp: Removed.
+        * tests/data/broken.gif: Removed.
+
 2013-02-25  Alpha Lam  <hclam@chromium.org>
 
         GIFImageReader to read from source data directly
index 7a1825d..82259c2 100644 (file)
                                 # We should not include files depending on webkit_support.
                                 # These tests depend on webkit_support and
                                 # functions defined only in !WEBKIT_IMPLEMENTATION.
-                                'tests/GIFImageDecoderTest.cpp',
                                 'tests/LevelDBTest.cpp',
                             ],
                             'conditions': [
index 3b0a7a5..d581128 100644 (file)
@@ -72,7 +72,6 @@
             'tests/FrameLoaderClientImplTest.cpp',
             'tests/FrameTestHelpers.cpp',
             'tests/FrameTestHelpers.h',
-            'tests/GIFImageDecoderTest.cpp',
             'tests/GraphicsLayerChromiumTest.cpp',
             'tests/IDBAbortOnCorruptTest.cpp',
             'tests/IDBBindingUtilitiesTest.cpp',
diff --git a/Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp b/Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp
deleted file mode 100644 (file)
index 4d547e9..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#include "GIFImageDecoder.h"
-
-#include "FileSystem.h"
-#include "SharedBuffer.h"
-#include <gtest/gtest.h>
-#include <public/WebData.h>
-#include <public/WebSize.h>
-#include <webkit/support/webkit_support.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
-
-using namespace WebCore;
-using namespace WebKit;
-
-namespace {
-
-static PassRefPtr<SharedBuffer> readFile(const char* fileName)
-{
-    String filePath = webkit_support::GetWebKitRootDir();
-    filePath.append(fileName);
-
-    long long fileSize;
-    if (!getFileSize(filePath, fileSize))
-        return 0;
-
-    PlatformFileHandle handle = openFile(filePath, OpenForRead);
-    int fileLength = static_cast<int>(fileSize);
-    Vector<char> buffer(fileLength);
-    readFromFile(handle, buffer.data(), fileLength);
-    closeFile(handle);
-    return SharedBuffer::adoptVector(buffer);
-}
-
-TEST(GIFImageDecoderTest, decodeTwoFrames)
-{
-    OwnPtr<GIFImageDecoder> decoder(adoptPtr(new GIFImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied)));
-
-    RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated.gif");
-    ASSERT_TRUE(data.get());
-    decoder->setData(data.get(), true);
-    EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
-
-    ImageFrame* frame = decoder->frameBufferAtIndex(0);
-    EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
-    EXPECT_EQ(16, frame->getSkBitmap().width());
-    EXPECT_EQ(16, frame->getSkBitmap().height());
-
-    frame = decoder->frameBufferAtIndex(1);
-    EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
-    EXPECT_EQ(16, frame->getSkBitmap().width());
-    EXPECT_EQ(16, frame->getSkBitmap().height());
-
-    EXPECT_EQ(2u, decoder->frameCount());
-    EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
-}
-
-TEST(GIFImageDecoderTest, parseAndDecode)
-{
-    OwnPtr<GIFImageDecoder> decoder(adoptPtr(new GIFImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied)));
-
-    RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated.gif");
-    ASSERT_TRUE(data.get());
-    decoder->setData(data.get(), true);
-    EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
-
-    // This call will parse the entire file.
-    EXPECT_EQ(2u, decoder->frameCount());
-
-    ImageFrame* frame = decoder->frameBufferAtIndex(0);
-    EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
-    EXPECT_EQ(16, frame->getSkBitmap().width());
-    EXPECT_EQ(16, frame->getSkBitmap().height());
-
-    frame = decoder->frameBufferAtIndex(1);
-    EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
-    EXPECT_EQ(16, frame->getSkBitmap().width());
-    EXPECT_EQ(16, frame->getSkBitmap().height());
-    EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
-}
-
-TEST(GIFImageDecoderTest, parseByteByByte)
-{
-    OwnPtr<GIFImageDecoder> decoder(adoptPtr(new GIFImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied)));
-
-    RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated.gif");
-    ASSERT_TRUE(data.get());
-
-    size_t frameCount = 0;
-
-    // Pass data to decoder byte by byte.
-    for (unsigned length = 1; length <= data->size(); ++length) {
-        RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length);
-        decoder->setData(tempData.get(), length == data->size());
-
-        EXPECT_LE(frameCount, decoder->frameCount());
-        frameCount = decoder->frameCount();
-    }
-
-    EXPECT_EQ(2u, decoder->frameCount());
-
-    decoder->frameBufferAtIndex(0);
-    decoder->frameBufferAtIndex(1);
-    EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
-}
-
-TEST(GIFImageDecoderTest, parseAndDecodeByteByByte)
-{
-    OwnPtr<GIFImageDecoder> decoder(adoptPtr(new GIFImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied)));
-
-    RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated-gif-with-offsets.gif");
-    ASSERT_TRUE(data.get());
-
-    size_t frameCount = 0;
-    size_t framesDecoded = 0;
-
-    // Pass data to decoder byte by byte.
-    for (unsigned length = 1; length <= data->size(); ++length) {
-        RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length);
-        decoder->setData(tempData.get(), length == data->size());
-
-        EXPECT_LE(frameCount, decoder->frameCount());
-        frameCount = decoder->frameCount();
-
-        ImageFrame* frame = decoder->frameBufferAtIndex(frameCount - 1);
-        if (frame && frame->status() == ImageFrame::FrameComplete && framesDecoded < frameCount)
-            ++framesDecoded;
-    }
-
-    EXPECT_EQ(5u, decoder->frameCount());
-    EXPECT_EQ(5u, framesDecoded);
-    EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
-}
-
-// Second frame in the file is broken but test that first frame can be decoded.
-TEST(GIFImageDecoderTest, brokenSecondFrame)
-{
-    OwnPtr<GIFImageDecoder> decoder(adoptPtr(new GIFImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied)));
-
-    RefPtr<SharedBuffer> data = readFile("/Source/WebKit/chromium/tests/data/broken.gif");
-    ASSERT_TRUE(data.get());
-    decoder->setData(data.get(), true);
-
-    EXPECT_EQ(1u, decoder->frameCount());
-
-    ImageFrame* frame = decoder->frameBufferAtIndex(0);
-    EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
-    EXPECT_EQ(16, frame->getSkBitmap().width());
-    EXPECT_EQ(16, frame->getSkBitmap().height());
-
-    frame = decoder->frameBufferAtIndex(1);
-    EXPECT_FALSE(frame);
-    EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
-}
-
-} // namespace
diff --git a/Source/WebKit/chromium/tests/data/broken.gif b/Source/WebKit/chromium/tests/data/broken.gif
deleted file mode 100644 (file)
index e3a7c4e..0000000
Binary files a/Source/WebKit/chromium/tests/data/broken.gif and /dev/null differ