Changeset 44652 in webkit


Ignore:
Timestamp:
Jun 13, 2009 11:55:41 AM (15 years ago)
Author:
pkasting@chromium.org
Message:

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

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=25709 part nine
Factor Cairo-specific implementation out of ImageDecoder.h into
ImageDecoderCairo.cpp. Add some comments to functions declared
in ImageDecoder.h.

  • GNUmakefile.am:
  • WebCore.vcproj/WebCore.vcproj:
  • platform/image-decoders/ImageDecoder.h:
  • platform/image-decoders/cairo: Added.
  • platform/image-decoders/cairo/ImageDecoderCairo.cpp: Added. (WebCore::RGBA32Buffer::RGBA32Buffer): (WebCore::RGBA32Buffer::clear): (WebCore::RGBA32Buffer::zeroFill): (WebCore::RGBA32Buffer::copyBitmapData): (WebCore::RGBA32Buffer::setSize): (WebCore::RGBA32Buffer::asNewNativeImage): (WebCore::RGBA32Buffer::hasAlpha): (WebCore::RGBA32Buffer::setHasAlpha): (WebCore::RGBA32Buffer::operator=): (WebCore::RGBA32Buffer::width): (WebCore::RGBA32Buffer::height): (WebCore::RGBA32Buffer::getAddr):
Location:
trunk/WebCore
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r44650 r44652  
     12009-06-13  Peter Kasting  <pkasting@google.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=25709 part nine
     6        Factor Cairo-specific implementation out of ImageDecoder.h into
     7        ImageDecoderCairo.cpp.  Add some comments to functions declared
     8        in ImageDecoder.h.
     9
     10        * GNUmakefile.am:
     11        * WebCore.vcproj/WebCore.vcproj:
     12        * platform/image-decoders/ImageDecoder.h:
     13        * platform/image-decoders/cairo: Added.
     14        * platform/image-decoders/cairo/ImageDecoderCairo.cpp: Added.
     15        (WebCore::RGBA32Buffer::RGBA32Buffer):
     16        (WebCore::RGBA32Buffer::clear):
     17        (WebCore::RGBA32Buffer::zeroFill):
     18        (WebCore::RGBA32Buffer::copyBitmapData):
     19        (WebCore::RGBA32Buffer::setSize):
     20        (WebCore::RGBA32Buffer::asNewNativeImage):
     21        (WebCore::RGBA32Buffer::hasAlpha):
     22        (WebCore::RGBA32Buffer::setHasAlpha):
     23        (WebCore::RGBA32Buffer::operator=):
     24        (WebCore::RGBA32Buffer::width):
     25        (WebCore::RGBA32Buffer::height):
     26        (WebCore::RGBA32Buffer::getAddr):
     27
    1282009-06-13  David Hyatt  <hyatt@apple.com>
    229
  • trunk/WebCore/GNUmakefile.am

    r44634 r44652  
    18651865        WebCore/platform/image-decoders/bmp/BMPImageReader.cpp \
    18661866        WebCore/platform/image-decoders/bmp/BMPImageReader.h \
     1867        WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp \
    18671868        WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp \
    18681869        WebCore/platform/image-decoders/gif/GIFImageDecoder.h \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r44639 r44652  
    62536253                                </File>
    62546254                                <Filter
     6255                                        Name="cairo"
     6256                                        >
     6257                                        <File
     6258                                                RelativePath="..\platform\image-decoders\cairo\ImageDecoderCairo.cpp"
     6259                                                >
     6260                                                <FileConfiguration
     6261                                                        Name="Debug|Win32"
     6262                                                        ExcludedFromBuild="true"
     6263                                                        >
     6264                                                        <Tool
     6265                                                                Name="VCCLCompilerTool"
     6266                                                        />
     6267                                                </FileConfiguration>
     6268                                                <FileConfiguration
     6269                                                        Name="Release|Win32"
     6270                                                        ExcludedFromBuild="true"
     6271                                                        >
     6272                                                        <Tool
     6273                                                                Name="VCCLCompilerTool"
     6274                                                        />
     6275                                                </FileConfiguration>
     6276                                                <FileConfiguration
     6277                                                        Name="Debug_Internal|Win32"
     6278                                                        ExcludedFromBuild="true"
     6279                                                        >
     6280                                                        <Tool
     6281                                                                Name="VCCLCompilerTool"
     6282                                                        />
     6283                                                </FileConfiguration>
     6284                                        </File>
     6285                                </Filter>
     6286                                <Filter
    62556287                                        Name="gif"
    62566288                                        >
  • trunk/WebCore/platform/image-decoders/ImageDecoder.h

    r44648 r44652  
    3535#include <wtf/Vector.h>
    3636
    37 #if PLATFORM(CAIRO)
    38 #include <cairo.h>
    39 #endif
    40 
    4137namespace WebCore {
    4238
     
    5652        typedef unsigned PixelData;
    5753
    58         RGBA32Buffer()
    59             : m_hasAlpha(false)
    60             , m_status(FrameEmpty)
    61             , m_duration(0)
    62             , m_disposalMethod(DisposeNotSpecified)
    63         {
    64         }
    65 
     54        RGBA32Buffer();
     55
     56        // For backends which refcount their data, this constructor doesn't need
     57        // to create a new copy of the image data, only increase the ref count.
     58        //
    6659        // This exists because ImageDecoder keeps a Vector<RGBA32Buffer>, and
    6760        // Vector requires this constructor.
     
    7164        }
    7265
    73         void clear()
    74         {
    75             m_bytes.clear();
    76             m_status = FrameEmpty;
    77             // NOTE: Do not reset other members here; clearFrameBufferCache()
    78             // calls this to free the bitmap data, but other functions like
    79             // initFrameBuffer() and frameComplete() may still need to read
    80             // other metadata out of this frame later.
    81         }
    82 
    83         void zeroFill()
    84         {
    85             m_bytes.fill(0);
    86             m_hasAlpha = true;
    87         }
    88 
    89         // This function creates a new copy of the image data in |other|, so the
    90         // two images can be modified independently.
    91         void copyBitmapData(const RGBA32Buffer& other)
    92         {
    93             if (this == &other)
    94                 return;
    95 
    96             m_bytes = other.m_bytes;
    97             setHasAlpha(other.m_hasAlpha);
    98         }
    99 
    100         // This function copies [(startX, startY), (endX, startY)) to the same
    101         // X-coordinates on each subsequent row up to but not including endY.
    102         //
    103         // NOTE: This function does not sanity-check its arguments!  Callers
    104         // MUST not pass invalid values or this will corrupt memory.
     66        // Deletes the pixel data entirely; used by ImageDecoder to save memory
     67        // when we no longer need to display a frame and only need its metadata.
     68        void clear();
     69
     70        // Zeroes the pixel data in the buffer, setting it to fully-transparent.
     71        void zeroFill();
     72
     73        // Creates a new copy of the image data in |other|, so the two images
     74        // can be modified independently.
     75        void copyBitmapData(const RGBA32Buffer& other);
     76
     77        // Copies the pixel data at [(startX, startY), (endX, startY)) to the
     78        // same X-coordinates on each subsequent row up to but not including
     79        // endY.
    10580        void copyRowNTimes(int startX, int endX, int startY, int endY)
    10681        {
     
    11590        }
    11691
    117         // Must be called before any pixels are written. Will return true on
    118         // success, false if the memory allocation fails.
    119         bool setSize(int width, int height)
    120         {
    121             // NOTE: This has no way to check for allocation failure if the
    122             // requested size was too big...
    123             m_bytes.resize(width * height);
    124             m_size = IntSize(width, height);
    125 
    126             // Zero the image.
    127             zeroFill();
    128 
    129             return true;
    130         }
    131 
    132 #if PLATFORM(CAIRO)
     92        // Allocates space for the pixel data.  Must be called before any pixels
     93        // are written. Will return true on success, false if the memory
     94        // allocation fails.  Calling this multiple times is undefined and may
     95        // leak memory.
     96        bool setSize(int width, int height);
     97
    13398        // To be used by ImageSource::createFrameAtIndex().  Returns a pointer
    13499        // to the underlying native image data.  This pointer will be owned by
    135100        // the BitmapImage and freed in FrameData::clear().
    136         NativeImagePtr asNewNativeImage() const
    137         {
    138             return cairo_image_surface_create_for_data(
    139                 reinterpret_cast<unsigned char*>(const_cast<PixelData*>(
    140                     m_bytes.data())), CAIRO_FORMAT_ARGB32, width(), height(),
    141                 width() * sizeof(PixelData));
    142         }
    143 #endif
    144 
    145         bool hasAlpha() const { return m_hasAlpha; }
     101        NativeImagePtr asNewNativeImage() const;
     102
     103        bool hasAlpha() const;
    146104        const IntRect& rect() const { return m_rect; }
    147105        FrameStatus status() const { return m_status; }
     
    149107        FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
    150108
    151         void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
     109        void setHasAlpha(bool alpha);
    152110        void setRect(const IntRect& r) { m_rect = r; }
    153111        void setStatus(FrameStatus s) { m_status = s; }
     
    161119
    162120    private:
    163         // Initialize with another buffer.  This function doesn't create a new copy
    164         // of the image data, it only increases the refcount of the existing bitmap.
    165         //
    166         // Normal callers should not generally be using this function.  If you want
    167         // to create a copy on which you can modify the image data independently,
    168         // use copyBitmapData() instead.
    169         RGBA32Buffer& operator=(const RGBA32Buffer& other)
    170         {
    171             if (this == &other)
    172                 return *this;
    173 
    174             m_bytes = other.m_bytes;
    175             m_size = other.m_size;
    176             setHasAlpha(other.hasAlpha());
    177             setRect(other.rect());
    178             setStatus(other.status());
    179             setDuration(other.duration());
    180             setDisposalMethod(other.disposalMethod());
    181             return *this;
    182         }
    183 
    184         inline int width() const { return m_size.width(); }
    185         inline int height() const { return m_size.height(); }
    186 
    187         inline PixelData* getAddr(int x, int y)
    188         {
    189             return m_bytes.data() + (y * width()) + x;
    190         }
     121        RGBA32Buffer& operator=(const RGBA32Buffer& other);
     122
     123        inline int width() const;
     124        inline int height() const;
     125
     126        inline PixelData* getAddr(int x, int y);
    191127
    192128        inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
     
    206142        }
    207143
     144#if PLATFORM(CAIRO)
    208145        Vector<PixelData> m_bytes;
    209146        IntSize m_size;       // The size of the buffer.  This should be the
    210147                              // same as ImageDecoder::m_size.
    211148        bool m_hasAlpha;      // Whether or not any of the pixels in the buffer have transparency.
     149#endif
    212150        IntRect m_rect;       // The rect of the original specified frame within the overall buffer.
    213151                              // This will always just be the entire buffer except for GIF frames
Note: See TracChangeset for help on using the changeset viewer.