Changeset 54978 in webkit


Ignore:
Timestamp:
Feb 18, 2010 11:35:16 AM (14 years ago)
Author:
pkasting@chromium.org
Message:

Rework PNG-in-ICO decoding to copy the decoded framebuffer into the ICO
decoder, making the logic less crazy and more like the other decoders.
https://bugs.webkit.org/show_bug.cgi?id=28751

Reviewed by Adam Barth.

  • platform/image-decoders/ImageDecoder.cpp:

(WebCore::RGBA32Buffer::operator=):

  • platform/image-decoders/ImageDecoder.h:

(WebCore::RGBA32Buffer::RGBA32Buffer):

  • platform/image-decoders/ico/ICOImageDecoder.cpp:

(WebCore::ICOImageDecoder::frameBufferAtIndex):
(WebCore::ICOImageDecoder::decodeAtIndex):

  • platform/image-decoders/ico/ICOImageDecoder.h:
  • platform/image-decoders/qt/RGBA32BufferQt.cpp:

(WebCore::RGBA32Buffer::operator=):

  • platform/image-decoders/skia/ImageDecoderSkia.cpp:

(WebCore::RGBA32Buffer::operator=):

Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54974 r54978  
     12010-02-17  Peter Kasting  <pkasting@google.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        Rework PNG-in-ICO decoding to copy the decoded framebuffer into the ICO
     6        decoder, making the logic less crazy and more like the other decoders.
     7        https://bugs.webkit.org/show_bug.cgi?id=28751
     8
     9        * platform/image-decoders/ImageDecoder.cpp:
     10        (WebCore::RGBA32Buffer::operator=):
     11        * platform/image-decoders/ImageDecoder.h:
     12        (WebCore::RGBA32Buffer::RGBA32Buffer):
     13        * platform/image-decoders/ico/ICOImageDecoder.cpp:
     14        (WebCore::ICOImageDecoder::frameBufferAtIndex):
     15        (WebCore::ICOImageDecoder::decodeAtIndex):
     16        * platform/image-decoders/ico/ICOImageDecoder.h:
     17        * platform/image-decoders/qt/RGBA32BufferQt.cpp:
     18        (WebCore::RGBA32Buffer::operator=):
     19        * platform/image-decoders/skia/ImageDecoderSkia.cpp:
     20        (WebCore::RGBA32Buffer::operator=):
     21
    1222010-02-18  Pavel Feldman  <pfeldman@chromium.org>
    223
  • trunk/WebCore/platform/image-decoders/ImageDecoder.cpp

    r54836 r54978  
    9898}
    9999
     100RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
     101{
     102    if (this == &other)
     103        return *this;
     104
     105    copyBitmapData(other);
     106    setRect(other.rect());
     107    setStatus(other.status());
     108    setDuration(other.duration());
     109    setDisposalMethod(other.disposalMethod());
     110    return *this;
     111}
     112
    100113void RGBA32Buffer::clear()
    101114{
     
    150163{
    151164    m_status = status;
    152 }
    153 
    154 RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
    155 {
    156     if (this == &other)
    157         return *this;
    158 
    159     copyBitmapData(other);
    160     setRect(other.rect());
    161     setStatus(other.status());
    162     setDuration(other.duration());
    163     setDisposalMethod(other.disposalMethod());
    164     return *this;
    165165}
    166166
  • trunk/WebCore/platform/image-decoders/ImageDecoder.h

    r54823 r54978  
    7070        RGBA32Buffer();
    7171
    72         // For backends which refcount their data, this constructor doesn't need
    73         // to create a new copy of the image data, only increase the ref count.
    74         //
    75         // This exists because ImageDecoder keeps a Vector<RGBA32Buffer>, and
    76         // Vector requires this constructor.
    77         RGBA32Buffer(const RGBA32Buffer& other)
    78         {
    79             operator=(other);
    80         }
     72        RGBA32Buffer(const RGBA32Buffer& other) { operator=(other); }
     73
     74        // For backends which refcount their data, this operator doesn't need to
     75        // create a new copy of the image data, only increase the ref count.
     76        RGBA32Buffer& operator=(const RGBA32Buffer& other);
    8177
    8278        // Deletes the pixel data entirely; used by ImageDecoder to save memory
     
    140136
    141137    private:
    142         RGBA32Buffer& operator=(const RGBA32Buffer& other);
    143 
    144138        int width() const;
    145139        int height() const;
  • trunk/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp

    r54823 r54978  
    116116        return 0;
    117117
    118     // Determine the image type, and if this is a BMP, decode.
    119     decode(index, false);
    120 
    121     // PNGs decode into their own framebuffers, so only use our internal cache
    122     // for non-PNGs (BMP or unknown).
    123     if (!m_pngDecoders[index])
    124         return &m_frameBufferCache[index];
    125 
    126     // Fail if the size the PNGImageDecoder calculated does not match the size
    127     // in the directory.
    128     if (m_pngDecoders[index]->isSizeAvailable()) {
    129         const IntSize pngSize(m_pngDecoders[index]->size());
    130         const IconDirectoryEntry& dirEntry = m_dirEntries[index];
    131         if (pngSize != dirEntry.m_size) {
    132             setFailed();
    133             m_pngDecoders[index]->setFailed();
    134         }
    135     }
    136 
    137     return m_pngDecoders[index]->frameBufferAtIndex(0);
     118    RGBA32Buffer* buffer = &m_frameBufferCache[index];
     119    if (buffer->status() != RGBA32Buffer::FrameComplete)
     120        decode(index, false);
     121    return buffer;
    138122}
    139123
     
    185169    ASSERT(index < m_dirEntries.size());
    186170    const IconDirectoryEntry& dirEntry = m_dirEntries[index];
    187     if (!m_bmpReaders[index] && !m_pngDecoders[index]) {
    188         // Image type unknown.
    189         const ImageType imageType = imageTypeAtIndex(index);
    190         if (imageType == BMP) {
     171    const ImageType imageType = imageTypeAtIndex(index);
     172    if (imageType == Unknown)
     173        return false; // Not enough data to determine image type yet.
     174
     175    if (imageType == BMP) {
     176        if (!m_bmpReaders[index]) {
    191177            // We need to have already sized m_frameBufferCache before this, and
    192178            // we must not resize it again later (see caution in frameCount()).
     
    195181            m_bmpReaders[index]->setData(m_data.get());
    196182            m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]);
    197         } else if (imageType == PNG) {
    198             m_pngDecoders[index].set(new PNGImageDecoder());
    199             setDataForPNGDecoderAtIndex(index);
    200         } else {
    201             // Not enough data to determine image type yet.
    202             return false;
    203183        }
    204     }
    205 
    206     if (m_bmpReaders[index]) {
    207184        m_frameSize = dirEntry.m_size;
    208185        bool result = m_bmpReaders[index]->decodeBMP(false);
     
    211188    }
    212189
    213     // For PNGs, we're now done; further decoding will happen when calling
    214     // frameBufferAtIndex() on the PNG decoder.
    215     return true;
     190    if (!m_pngDecoders[index]) {
     191        m_pngDecoders[index].set(new PNGImageDecoder());
     192        setDataForPNGDecoderAtIndex(index);
     193    }
     194    // Fail if the size the PNGImageDecoder calculated does not match the size
     195    // in the directory.
     196    if (m_pngDecoders[index]->isSizeAvailable() && (m_pngDecoders[index]->size() != dirEntry.m_size)) {
     197        setFailed();
     198        return false;
     199    }
     200    m_frameBufferCache[index] = *m_pngDecoders[index]->frameBufferAtIndex(0);
     201    if (!m_pngDecoders[index]->failed())
     202      return true;
     203    setFailed();
     204    return false;
    216205}
    217206
  • trunk/WebCore/platform/image-decoders/ico/ICOImageDecoder.h

    r54823 r54978  
    8787        // after calculating the image size.  If decoding fails but there is no
    8888        // more data coming, sets the "decode failure" flag.
    89         //
    90         // NOTE: If the desired entry is a PNG, this doesn't actually trigger
    91         // decoding, it merely ensures the decoder is created and ready to
    92         // decode.  The caller will then call a function on the PNGImageDecoder
    93         // that actually triggers decoding.
    9489        void decode(size_t index, bool onlySize);
    9590
  • trunk/WebCore/platform/image-decoders/qt/RGBA32BufferQt.cpp

    r54823 r54978  
    4141    , m_disposalMethod(DisposeNotSpecified)
    4242{
     43}
     44
     45RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
     46{
     47    if (this == &other)
     48        return *this;
     49
     50    copyBitmapData(other);
     51    setRect(other.rect());
     52    setStatus(other.status());
     53    setDuration(other.duration());
     54    setDisposalMethod(other.disposalMethod());
     55    return *this;
    4356}
    4457
     
    116129}
    117130
    118 RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
    119 {
    120     if (this == &other)
    121         return *this;
    122 
    123     copyBitmapData(other);
    124     setRect(other.rect());
    125     setStatus(other.status());
    126     setDuration(other.duration());
    127     setDisposalMethod(other.disposalMethod());
    128     return *this;
    129 }
    130 
    131131int RGBA32Buffer::width() const
    132132{
  • trunk/WebCore/platform/image-decoders/skia/ImageDecoderSkia.cpp

    r53884 r54978  
    3535    , m_disposalMethod(DisposeNotSpecified)
    3636{
     37}
     38
     39RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
     40{
     41    if (this == &other)
     42        return *this;
     43
     44    m_bitmap = other.m_bitmap;
     45    // Keep the pixels locked since we will be writing directly into the
     46    // bitmap throughout this object's lifetime.
     47    m_bitmap.lockPixels();
     48    setRect(other.rect());
     49    setStatus(other.status());
     50    setDuration(other.duration());
     51    setDisposalMethod(other.disposalMethod());
     52    return *this;
    3753}
    3854
     
    99115}
    100116
    101 RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
    102 {
    103     if (this == &other)
    104         return *this;
    105 
    106     m_bitmap = other.m_bitmap;
    107     // Keep the pixels locked since we will be writing directly into the
    108     // bitmap throughout this object's lifetime.
    109     m_bitmap.lockPixels();
    110     setRect(other.rect());
    111     setStatus(other.status());
    112     setDuration(other.duration());
    113     setDisposalMethod(other.disposalMethod());
    114     return *this;
    115 }
    116 
    117117int RGBA32Buffer::width() const
    118118{
Note: See TracChangeset for help on using the changeset viewer.