Changeset 44825 in webkit


Ignore:
Timestamp:
Jun 18, 2009 2:29:11 PM (15 years ago)
Author:
pkasting@chromium.org
Message:

2009-06-18 Peter Kasting <pkasting@google.com>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=26460 part one
Make isSizeAvailable non-const, since it's not logically const (it
triggers lazy decoding), and simplify all the implementations (without
changing behavior; just make less verbose). Remove some other
inappropriate consts, which enables the removal of all the mutable
declarations in the decoders.

  • platform/image-decoders/ImageDecoder.h: (WebCore::ImageDecoder::isSizeAvailable): (WebCore::ImageDecoder::setSize): Make public to avoid needing a friend declaration in the JPEG decoder, and because the ICO/BMP decoders will soon need this.
  • platform/image-decoders/gif/GIFImageDecoder.cpp: (WebCore::GIFImageDecoder::isSizeAvailable): (WebCore::GIFImageDecoder::repetitionCount): (WebCore::GIFImageDecoder::decode):
  • platform/image-decoders/gif/GIFImageDecoder.h:
  • platform/image-decoders/ico/ICOImageDecoder.cpp: (WebCore::ICOImageDecoder::isSizeAvailable):
  • platform/image-decoders/ico/ICOImageDecoder.h:
  • platform/image-decoders/jpeg/JPEGImageDecoder.cpp: (WebCore::JPEGImageDecoder::isSizeAvailable): (WebCore::JPEGImageDecoder::decode):
  • platform/image-decoders/jpeg/JPEGImageDecoder.h:
  • platform/image-decoders/png/PNGImageDecoder.cpp: (WebCore::PNGImageDecoder::isSizeAvailable): (WebCore::PNGImageDecoder::decode):
  • platform/image-decoders/png/PNGImageDecoder.h:
  • platform/image-decoders/xbm/XBMImageDecoder.cpp: (WebCore::XBMImageDecoder::isSizeAvailable): (WebCore::XBMImageDecoder::frameBufferAtIndex): (WebCore::XBMImageDecoder::decode):
  • platform/image-decoders/xbm/XBMImageDecoder.h: Rename decodeXBM() to decode() for consistency with the JPEG/PNG decoders, and in the future the ICO/BMP decoders.
Location:
trunk/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r44821 r44825  
     12009-06-18  Peter Kasting  <pkasting@google.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=26460 part one
     6        Make isSizeAvailable non-const, since it's not logically const (it
     7        triggers lazy decoding), and simplify all the implementations (without
     8        changing behavior; just make less verbose).  Remove some other
     9        inappropriate consts, which enables the removal of all the mutable
     10        declarations in the decoders.
     11
     12        * platform/image-decoders/ImageDecoder.h:
     13        (WebCore::ImageDecoder::isSizeAvailable):
     14        (WebCore::ImageDecoder::setSize): Make public to avoid needing a friend declaration in the JPEG decoder, and because the ICO/BMP decoders will soon need this.
     15        * platform/image-decoders/gif/GIFImageDecoder.cpp:
     16        (WebCore::GIFImageDecoder::isSizeAvailable):
     17        (WebCore::GIFImageDecoder::repetitionCount):
     18        (WebCore::GIFImageDecoder::decode):
     19        * platform/image-decoders/gif/GIFImageDecoder.h:
     20        * platform/image-decoders/ico/ICOImageDecoder.cpp:
     21        (WebCore::ICOImageDecoder::isSizeAvailable):
     22        * platform/image-decoders/ico/ICOImageDecoder.h:
     23        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
     24        (WebCore::JPEGImageDecoder::isSizeAvailable):
     25        (WebCore::JPEGImageDecoder::decode):
     26        * platform/image-decoders/jpeg/JPEGImageDecoder.h:
     27        * platform/image-decoders/png/PNGImageDecoder.cpp:
     28        (WebCore::PNGImageDecoder::isSizeAvailable):
     29        (WebCore::PNGImageDecoder::decode):
     30        * platform/image-decoders/png/PNGImageDecoder.h:
     31        * platform/image-decoders/xbm/XBMImageDecoder.cpp:
     32        (WebCore::XBMImageDecoder::isSizeAvailable):
     33        (WebCore::XBMImageDecoder::frameBufferAtIndex):
     34        (WebCore::XBMImageDecoder::decode):
     35        * platform/image-decoders/xbm/XBMImageDecoder.h: Rename decodeXBM() to decode() for consistency with the JPEG/PNG decoders, and in the future the ICO/BMP decoders.
     36
    1372009-06-17  Brent Fulgham  <bfulgham@webkit.org>
    238
  • trunk/WebCore/platform/image-decoders/ImageDecoder.h

    r44669 r44825  
    201201        // seen a failure. Decoders may want to override this to lazily decode
    202202        // enough of the image to get the size.
    203         virtual bool isSizeAvailable() const
     203        virtual bool isSizeAvailable()
    204204        {
    205205            return !m_failed && m_sizeAvailable;
     
    212212            ASSERT(!m_failed);
    213213            return m_size;
     214        }
     215
     216        // Called by the image decoders to set their decoded size, this also check
     217        // the size for validity. It will return true if the size was set, or false
     218        // if there is an error. On error, the m_failed flag will be set and the
     219        // caller should immediately stop decoding.
     220        virtual bool setSize(unsigned width, unsigned height)
     221        {
     222            if (isOverSize(width, height)) {
     223                m_failed = true;
     224                return false;
     225            }
     226            m_size = IntSize(width, height);
     227            m_sizeAvailable = true;
     228            return true;
    214229        }
    215230
     
    242257
    243258    protected:
    244         // Called by the image decoders to set their decoded size, this also check
    245         // the size for validity. It will return true if the size was set, or false
    246         // if there is an error. On error, the m_failed flag will be set and the
    247         // caller should immediately stop decoding.
    248         bool setSize(unsigned width, unsigned height)
    249         {
    250             if (isOverSize(width, height)) {
    251                 m_failed = true;
    252                 return false;
    253             }
    254             m_size = IntSize(width, height);
    255             m_sizeAvailable = true;
    256             return true;
    257         }
    258 
    259259        RefPtr<SharedBuffer> m_data; // The encoded data.
    260260        Vector<RGBA32Buffer> m_frameBufferCache;
    261         mutable bool m_failed;
     261        bool m_failed;
    262262
    263263    private:
  • trunk/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp

    r44631 r44825  
    114114
    115115// Whether or not the size information has been decoded yet.
    116 bool GIFImageDecoder::isSizeAvailable() const
    117 {
    118     // If we have pending data to decode, send it to the GIF reader now.
    119     if (!ImageDecoder::isSizeAvailable() && m_reader) {
    120         if (m_failed)
    121             return false;
    122 
    123         // The decoder will go ahead and aggressively consume everything up until the first
    124         // size is encountered.
    125         decode(GIFSizeQuery, 0);
    126     }
     116bool GIFImageDecoder::isSizeAvailable()
     117{
     118    if (!ImageDecoder::isSizeAvailable() && !failed() && m_reader)
     119         decode(GIFSizeQuery, 0);
    127120
    128121    return ImageDecoder::isSizeAvailable();
     
    153146
    154147// The number of repetitions to perform for an animation loop.
    155 int GIFImageDecoder::repetitionCount() const
     148int GIFImageDecoder::repetitionCount()
    156149{
    157150    // This value can arrive at any point in the image data stream.  Most GIFs
     
    238231
    239232// Feed data to the GIF reader.
    240 void GIFImageDecoder::decode(GIFQuery query, unsigned haltAtFrame) const
     233void GIFImageDecoder::decode(GIFQuery query, unsigned haltAtFrame)
    241234{
    242235    if (m_failed)
  • trunk/WebCore/platform/image-decoders/gif/GIFImageDecoder.h

    r44553 r44825  
    4545
    4646        // Whether or not the size information has been decoded yet.
    47         virtual bool isSizeAvailable() const;
     47        virtual bool isSizeAvailable();
    4848
    4949        // The total number of frames for the image.  Will scan the image data for the answer
     
    5252
    5353        // The number of repetitions to perform for an animation loop.
    54         virtual int repetitionCount() const;
     54        virtual int repetitionCount();
    5555
    5656        virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
     
    8080        bool m_frameCountValid;
    8181        bool m_currentBufferSawAlpha;
    82         mutable int m_repetitionCount;
    83         mutable GIFImageDecoderPrivate* m_reader;
     82        int m_repetitionCount;
     83        GIFImageDecoderPrivate* m_reader;
    8484    };
    8585
  • trunk/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp

    r44634 r44825  
    8181}
    8282
    83 bool ICOImageDecoder::isSizeAvailable() const
     83bool ICOImageDecoder::isSizeAvailable()
    8484{
    8585    return (m_imageType == PNG) ? m_pngDecoder.isSizeAvailable() :
  • trunk/WebCore/platform/image-decoders/ico/ICOImageDecoder.h

    r44634 r44825  
    5555
    5656        // ImageDecoder
    57         virtual bool isSizeAvailable() const;
     57        virtual bool isSizeAvailable();
    5858        virtual IntSize size() const;
    5959
  • trunk/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

    r44631 r44825  
    410410
    411411// Whether or not the size information has been decoded yet.
    412 bool JPEGImageDecoder::isSizeAvailable() const
    413 {
    414     // If we have pending data to decode, send it to the JPEG reader now.
    415     if (!ImageDecoder::isSizeAvailable() && m_reader) {
    416         if (m_failed)
    417             return false;
    418 
    419         // The decoder will go ahead and aggressively consume everything up until the
    420         // size is encountered.
    421         decode(true);
    422     }
     412bool JPEGImageDecoder::isSizeAvailable()
     413{
     414    if (!ImageDecoder::isSizeAvailable() && !failed() && m_reader)
     415         decode(true);
    423416
    424417    return ImageDecoder::isSizeAvailable();
     
    441434
    442435// Feed data to the JPEG reader.
    443 void JPEGImageDecoder::decode(bool sizeOnly) const
     436void JPEGImageDecoder::decode(bool sizeOnly)
    444437{
    445438    if (m_failed)
  • trunk/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h

    r44553 r44825  
    4545
    4646        // Whether or not the size information has been decoded yet.
    47         virtual bool isSizeAvailable() const;
     47        virtual bool isSizeAvailable();
    4848
    4949        virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
     
    5151        virtual bool supportsAlpha() const { return false; }
    5252
    53         void decode(bool sizeOnly = false) const;
     53        void decode(bool sizeOnly = false);
    5454
    5555        JPEGImageReader* reader() { return m_reader; }
     
    5959
    6060    private:
    61         friend class JPEGImageReader;
    62         mutable JPEGImageReader* m_reader;
     61        JPEGImageReader* m_reader;
    6362    };
    6463
  • trunk/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp

    r44631 r44825  
    161161
    162162// Whether or not the size information has been decoded yet.
    163 bool PNGImageDecoder::isSizeAvailable() const
    164 {
    165     // If we have pending data to decode, send it to the PNG reader now.
    166     if (!ImageDecoder::isSizeAvailable() && m_reader) {
    167         if (m_failed)
    168             return false;
    169 
    170         // The decoder will go ahead and aggressively consume everything up until the
    171         // size is encountered.
    172         decode(true);
    173     }
     163bool PNGImageDecoder::isSizeAvailable()
     164{
     165    if (!ImageDecoder::isSizeAvailable() && !failed() && m_reader)
     166         decode(true);
    174167
    175168    return ImageDecoder::isSizeAvailable();
     
    192185
    193186// Feed data to the PNG reader.
    194 void PNGImageDecoder::decode(bool sizeOnly) const
     187void PNGImageDecoder::decode(bool sizeOnly)
    195188{
    196189    if (m_failed)
  • trunk/WebCore/platform/image-decoders/png/PNGImageDecoder.h

    r44167 r44825  
    4545
    4646        // Whether or not the size information has been decoded yet.
    47         virtual bool isSizeAvailable() const;
     47        virtual bool isSizeAvailable();
    4848
    4949        virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
    5050
    51         void decode(bool sizeOnly = false) const;
     51        void decode(bool sizeOnly = false);
    5252
    5353        PNGImageReader* reader() { return m_reader; }
     
    6060
    6161    private:
    62         mutable PNGImageReader* m_reader;
     62        PNGImageReader* m_reader;
    6363    };
    6464
  • trunk/WebCore/platform/image-decoders/xbm/XBMImageDecoder.cpp

    r44646 r44825  
    5757}
    5858
    59 bool XBMImageDecoder::isSizeAvailable() const
    60 {
    61     // This method should either (a) not be const, or (b) not be expected to
    62     // do anything that changes m_sizeAvailable. The png and jpeg decoders
    63     // get around this with callbacks from external libraries.
    64     //
    65     // FIXME: Find out if we can patch webkit to take care of this.
     59bool XBMImageDecoder::isSizeAvailable()
     60{
    6661    if (!ImageDecoder::isSizeAvailable() && !m_failed)
    67         const_cast<XBMImageDecoder*>(this)->decodeXBM(true);
    68 
    69     return !m_failed && ImageDecoder::isSizeAvailable();
     62        decode(true);
     63
     64    return ImageDecoder::isSizeAvailable();
    7065}
    7166
     
    8075    // Attempt to get the size if we don't have it yet.
    8176    if (!ImageDecoder::isSizeAvailable())
    82         decodeXBM(true);
     77        decode(true);
    8378   
    8479    // Initialize the framebuffer if needed.
     
    9893    // Keep trying to decode until we've got the entire image.
    9994    if (buffer.status() == RGBA32Buffer::FramePartial)
    100         decodeXBM(false);
     95        decode(false);
    10196
    10297    return &buffer;
     
    262257
    263258// Decode as much as we can of the XBM file.
    264 void XBMImageDecoder::decodeXBM(bool sizeOnly)
     259void XBMImageDecoder::decode(bool sizeOnly)
    265260{
    266261    if (failed())
  • trunk/WebCore/platform/image-decoders/xbm/XBMImageDecoder.h

    r44643 r44825  
    4646        virtual void setData(SharedBuffer* data, bool allDataReceived);
    4747        // Whether or not the size information has been decoded yet.
    48         virtual bool isSizeAvailable() const;
     48        virtual bool isSizeAvailable();
    4949        virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
    5050
     
    6666        bool decodeDatum(uint16_t* result);
    6767        bool decodeData();
    68         void decodeXBM(bool sizeOnly);
     68        void decode(bool sizeOnly);
    6969
    7070        // FIXME: Copying all the XBM data just so we can NULL-terminate, just
Note: See TracChangeset for help on using the changeset viewer.