OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 clearFrameBuffer(i); | 227 clearFrameBuffer(i); |
228 } | 228 } |
229 } | 229 } |
230 return frameBytesCleared; | 230 return frameBytesCleared; |
231 } | 231 } |
232 | 232 |
233 void ImageDecoder::clearFrameBuffer(size_t frameIndex) { | 233 void ImageDecoder::clearFrameBuffer(size_t frameIndex) { |
234 m_frameBufferCache[frameIndex].clearPixelData(); | 234 m_frameBufferCache[frameIndex].clearPixelData(); |
235 } | 235 } |
236 | 236 |
| 237 void ImageDecoder::updateAggressivePurging(size_t index) { |
| 238 if (m_purgeAggressively) |
| 239 return; |
| 240 |
| 241 // We don't want to cache so much that we cause a memory issue. |
| 242 // |
| 243 // If we used a LRU cache we would fill it and then on next animation loop |
| 244 // we would need to decode all the frames again -- the LRU would give no |
| 245 // benefit and would consume more memory. |
| 246 // So instead, simply purge unused frames if caching all of the frames of |
| 247 // the image would use more memory than the image decoder is allowed |
| 248 // (m_maxDecodedBytes) or would overflow 32 bits.. |
| 249 // |
| 250 // As we decode we will learn the total number of frames, and thus total |
| 251 // possible image memory used. |
| 252 |
| 253 const uint64_t frameArea = decodedSize().area(); |
| 254 const uint64_t frameMemoryUsage = frameArea * 4; // 4 bytes per pixel |
| 255 if (frameMemoryUsage / 4 != frameArea) { // overflow occurred |
| 256 m_purgeAggressively = true; |
| 257 return; |
| 258 } |
| 259 |
| 260 const uint64_t totalMemoryUsage = frameMemoryUsage * index; |
| 261 if (totalMemoryUsage / frameMemoryUsage != index) { // overflow occurred |
| 262 m_purgeAggressively = true; |
| 263 return; |
| 264 } |
| 265 |
| 266 if (totalMemoryUsage > m_maxDecodedBytes) { |
| 267 m_purgeAggressively = true; |
| 268 } |
| 269 } |
| 270 |
237 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex, | 271 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex, |
238 bool frameRectIsOpaque) { | 272 bool frameRectIsOpaque) { |
239 ASSERT(frameIndex <= m_frameBufferCache.size()); | 273 ASSERT(frameIndex <= m_frameBufferCache.size()); |
240 if (!frameIndex) { | 274 if (!frameIndex) { |
241 // The first frame doesn't rely on any previous data. | 275 // The first frame doesn't rely on any previous data. |
242 return kNotFound; | 276 return kNotFound; |
243 } | 277 } |
244 | 278 |
245 const ImageFrame* currBuffer = &m_frameBufferCache[frameIndex]; | 279 const ImageFrame* currBuffer = &m_frameBufferCache[frameIndex]; |
246 if ((frameRectIsOpaque || | 280 if ((frameRectIsOpaque || |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 461 |
428 // FIXME: Don't force perceptual intent if the image profile contains an | 462 // FIXME: Don't force perceptual intent if the image profile contains an |
429 // intent. | 463 // intent. |
430 m_sourceToOutputDeviceColorTransform.reset( | 464 m_sourceToOutputDeviceColorTransform.reset( |
431 qcms_transform_create(inputProfile.get(), dataFormat, gTargetColorProfile, | 465 qcms_transform_create(inputProfile.get(), dataFormat, gTargetColorProfile, |
432 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL)); | 466 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL)); |
433 #endif // USE(QCMSLIB) | 467 #endif // USE(QCMSLIB) |
434 } | 468 } |
435 | 469 |
436 } // namespace blink | 470 } // namespace blink |
OLD | NEW |