Changeset 78652 in webkit
- Timestamp:
- Feb 15, 2011 5:15:20 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r78648 r78652 1 2011-02-15 Ian Henderson <ianh@apple.com> 2 3 Reviewed by Darin Adler. 4 5 To determine image properties, CG allocates memory which isn't included in CachedImage's decoded size 6 https://bugs.webkit.org/show_bug.cgi?id=53281 7 8 When determining properties of an image (such as its size), CG ends up 9 decoding part of the image. This patch adds accounting for this extra 10 decoded size so a cache prune can clean up the allocations. 11 12 * platform/graphics/BitmapImage.cpp: 13 (WebCore::BitmapImage::BitmapImage): 14 (WebCore::BitmapImage::destroyMetadataAndNotify): 15 Clearing the source destroys the extra decoded data. Report this 16 change in decoded size to the image observer. 17 (WebCore::BitmapImage::cacheFrame): 18 The first decoded frame subsumes the data decoded when determining 19 image properties, so we subtract it out here. 20 (WebCore::BitmapImage::didDecodeProperties): 21 Reports the extra decoded size to the image's observer. 22 (WebCore::BitmapImage::size): 23 (WebCore::BitmapImage::currentFrameSize): 24 (WebCore::BitmapImage::getHotSpot): 25 (WebCore::BitmapImage::frameCount): 26 (WebCore::BitmapImage::isSizeAvailable): 27 (WebCore::BitmapImage::repetitionCount): 28 * platform/graphics/BitmapImage.h: 29 * platform/graphics/ImageSource.cpp: 30 (WebCore::ImageSource::bytesDecodedToDetermineProperties): 31 The default value is 0 to match the current behavior on other 32 platforms. 33 * platform/graphics/ImageSource.h: 34 * platform/graphics/cg/ImageSourceCG.cpp: 35 (WebCore::ImageSource::bytesDecodedToDetermineProperties): 36 Add a constant value for bytesDecodedToDetermineProperties(), measured 37 by tracing malloc/calloc calls while asking an image source for its 38 properties. 39 1 40 2011-02-15 James Robinson <jamesr@chromium.org> 2 41 -
trunk/Source/WebCore/platform/graphics/BitmapImage.cpp
r60849 r78652 61 61 , m_hasUniformFrameSize(true) 62 62 , m_decodedSize(0) 63 , m_decodedPropertiesSize(0) 63 64 , m_haveFrameCount(false) 64 65 , m_frameCount(0) … … 105 106 invalidatePlatformData(); 106 107 107 constint deltaBytes = framesCleared * -frameBytes(m_size);108 int deltaBytes = framesCleared * -frameBytes(m_size); 108 109 m_decodedSize += deltaBytes; 110 if (framesCleared > 0) { 111 deltaBytes -= m_decodedPropertiesSize; 112 m_decodedPropertiesSize = 0; 113 } 109 114 if (deltaBytes && imageObserver()) 110 115 imageObserver()->decodedSizeChanged(this, deltaBytes); … … 133 138 m_hasUniformFrameSize = false; 134 139 if (m_frames[index].m_frame) { 135 constint deltaBytes = frameBytes(frameSize);140 int deltaBytes = frameBytes(frameSize); 136 141 m_decodedSize += deltaBytes; 142 // The fully-decoded frame will subsume the partially decoded data used 143 // to determine image properties. 144 deltaBytes -= m_decodedPropertiesSize; 145 m_decodedPropertiesSize = 0; 137 146 if (imageObserver()) 138 147 imageObserver()->decodedSizeChanged(this, deltaBytes); 139 148 } 149 } 150 151 void BitmapImage::didDecodeProperties() const 152 { 153 if (m_decodedSize) 154 return; 155 size_t updatedSize = m_source.bytesDecodedToDetermineProperties(); 156 if (m_decodedPropertiesSize == updatedSize) 157 return; 158 int deltaBytes = updatedSize - m_decodedPropertiesSize; 159 #ifndef NDEBUG 160 bool overflow = updatedSize > m_decodedPropertiesSize && deltaBytes < 0; 161 bool underflow = updatedSize < m_decodedPropertiesSize && deltaBytes > 0; 162 ASSERT(!overflow && !underflow); 163 #endif 164 m_decodedPropertiesSize = updatedSize; 165 if (imageObserver()) 166 imageObserver()->decodedSizeChanged(this, deltaBytes); 140 167 } 141 168 … … 145 172 m_size = m_source.size(); 146 173 m_haveSize = true; 174 didDecodeProperties(); 147 175 } 148 176 return m_size; … … 153 181 if (!m_currentFrame || m_hasUniformFrameSize) 154 182 return size(); 155 return m_source.frameSizeAtIndex(m_currentFrame); 183 IntSize frameSize = m_source.frameSizeAtIndex(m_currentFrame); 184 didDecodeProperties(); 185 return frameSize; 156 186 } 157 187 158 188 bool BitmapImage::getHotSpot(IntPoint& hotSpot) const 159 189 { 160 return m_source.getHotSpot(hotSpot); 190 bool result = m_source.getHotSpot(hotSpot); 191 didDecodeProperties(); 192 return result; 161 193 } 162 194 … … 191 223 m_haveFrameCount = true; 192 224 m_frameCount = m_source.frameCount(); 225 didDecodeProperties(); 193 226 } 194 227 return m_frameCount; … … 201 234 202 235 m_sizeAvailable = m_source.isSizeAvailable(); 236 didDecodeProperties(); 203 237 204 238 return m_sizeAvailable; … … 257 291 // the count again once the whole image is decoded. 258 292 m_repetitionCount = m_source.repetitionCount(); 293 didDecodeProperties(); 259 294 m_repetitionCountStatus = (imageKnownToBeComplete || m_repetitionCount == cAnimationNone) ? Certain : Uncertain; 260 295 } -
trunk/Source/WebCore/platform/graphics/BitmapImage.h
r76248 r78652 212 212 bool isSizeAvailable(); 213 213 214 // Called after asking the source for any information that may require 215 // decoding part of the image (e.g., the image size). We need to report 216 // the partially decoded data to our observer so it has an accurate 217 // account of the BitmapImage's memory usage. 218 void didDecodeProperties() const; 219 214 220 // Animation. 215 221 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplete| should be set if the caller knows the entire image has been decoded. … … 278 284 279 285 unsigned m_decodedSize; // The current size of all decoded frames. 286 mutable unsigned m_decodedPropertiesSize; // The size of data decoded by the source to determine image properties (e.g. size, frame count, etc). 280 287 281 288 mutable bool m_haveFrameCount; -
trunk/Source/WebCore/platform/graphics/ImageSource.cpp
r75748 r78652 116 116 } 117 117 118 size_t ImageSource::bytesDecodedToDetermineProperties() const 119 { 120 return 0; 121 } 122 118 123 int ImageSource::repetitionCount() 119 124 { -
trunk/Source/WebCore/platform/graphics/ImageSource.h
r76248 r78652 170 170 bool getHotSpot(IntPoint&) const; 171 171 172 size_t bytesDecodedToDetermineProperties() const; 173 172 174 int repetitionCount(); 173 175 -
trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp
r73819 r78652 223 223 } 224 224 225 size_t ImageSource::bytesDecodedToDetermineProperties() const 226 { 227 // Measured by tracing malloc/calloc calls on Mac OS 10.6.6, x86_64. 228 // A non-zero value ensures cached images with no decoded frames still enter 229 // the live decoded resources list when the CGImageSource decodes image 230 // properties, allowing the cache to prune the partially decoded image. 231 // This value is likely to be inaccurate on other platforms, but the overall 232 // behavior is unchanged. 233 return 13088; 234 } 235 225 236 int ImageSource::repetitionCount() 226 237 {
Note: See TracChangeset
for help on using the changeset viewer.