Changeset 44652 in webkit
- Timestamp:
- Jun 13, 2009 11:55:41 AM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r44650 r44652 1 2009-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 1 28 2009-06-13 David Hyatt <hyatt@apple.com> 2 29 -
trunk/WebCore/GNUmakefile.am
r44634 r44652 1865 1865 WebCore/platform/image-decoders/bmp/BMPImageReader.cpp \ 1866 1866 WebCore/platform/image-decoders/bmp/BMPImageReader.h \ 1867 WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp \ 1867 1868 WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp \ 1868 1869 WebCore/platform/image-decoders/gif/GIFImageDecoder.h \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r44639 r44652 6253 6253 </File> 6254 6254 <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 6255 6287 Name="gif" 6256 6288 > -
trunk/WebCore/platform/image-decoders/ImageDecoder.h
r44648 r44652 35 35 #include <wtf/Vector.h> 36 36 37 #if PLATFORM(CAIRO)38 #include <cairo.h>39 #endif40 41 37 namespace WebCore { 42 38 … … 56 52 typedef unsigned PixelData; 57 53 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 // 66 59 // This exists because ImageDecoder keeps a Vector<RGBA32Buffer>, and 67 60 // Vector requires this constructor. … … 71 64 } 72 65 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. 105 80 void copyRowNTimes(int startX, int endX, int startY, int endY) 106 81 { … … 115 90 } 116 91 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 133 98 // To be used by ImageSource::createFrameAtIndex(). Returns a pointer 134 99 // to the underlying native image data. This pointer will be owned by 135 100 // 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; 146 104 const IntRect& rect() const { return m_rect; } 147 105 FrameStatus status() const { return m_status; } … … 149 107 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } 150 108 151 void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }109 void setHasAlpha(bool alpha); 152 110 void setRect(const IntRect& r) { m_rect = r; } 153 111 void setStatus(FrameStatus s) { m_status = s; } … … 161 119 162 120 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); 191 127 192 128 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) … … 206 142 } 207 143 144 #if PLATFORM(CAIRO) 208 145 Vector<PixelData> m_bytes; 209 146 IntSize m_size; // The size of the buffer. This should be the 210 147 // same as ImageDecoder::m_size. 211 148 bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency. 149 #endif 212 150 IntRect m_rect; // The rect of the original specified frame within the overall buffer. 213 151 // This will always just be the entire buffer except for GIF frames
Note: See TracChangeset
for help on using the changeset viewer.