Chromium Code Reviews| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 return frameBytesCleared; | 235 return frameBytesCleared; |
| 236 } | 236 } |
| 237 | 237 |
| 238 void ImageDecoder::clearFrameBuffer(size_t frameIndex) | 238 void ImageDecoder::clearFrameBuffer(size_t frameIndex) |
| 239 { | 239 { |
| 240 m_frameBufferCache[frameIndex].clearPixelData(); | 240 m_frameBufferCache[frameIndex].clearPixelData(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void ImageDecoder::updateAggressivePurging(size_t index) | |
| 244 { | |
| 245 if (m_purgeAggressively) | |
|
urvang
2016/10/03 19:18:06
So, once we set m_purgeAggressively to true, we'll
cblume
2016/10/03 19:39:19
I believe it is.
Ideally, this would be set once
urvang
2016/10/03 19:56:07
We call "if (m_purgeAggressively) clearCacheExcept
cblume
2016/10/03 20:05:35
You are correct. What I mean is we wouldn't have s
| |
| 246 return; | |
| 247 | |
| 248 // We don't want to cache so much that we cause a memory issue. | |
| 249 // | |
| 250 // If we used a LRU cache we would fill it and then on next animation loop | |
| 251 // we would need to decode all the frames again -- the LRU would give no | |
| 252 // benefit and would consume more memory. | |
| 253 // So instead, simply purge unused frames if caching all of the frames of | |
| 254 // the image would use more memory than the image decoder is allowed | |
| 255 // (m_maxDecodedBytes) or would overflow 32 bits.. | |
| 256 // | |
| 257 // As we decode we will learn the total number of frames, and thus total | |
| 258 // possible image memory used. | |
| 259 | |
| 260 const uint64_t frameArea = decodedSize().area(); | |
| 261 const uint64_t frameMemoryUsage = frameArea * 4; // 4 bytes per pixel | |
| 262 if (frameMemoryUsage / 4 != frameArea) { // overflow occurred | |
| 263 m_purgeAggressively = true; | |
| 264 return; | |
| 265 } | |
| 266 | |
| 267 const uint64_t totalMemoryUsage = frameMemoryUsage * index; | |
| 268 if (totalMemoryUsage / frameMemoryUsage != index) { // overflow occurred | |
| 269 m_purgeAggressively = true; | |
| 270 return; | |
| 271 } | |
| 272 | |
| 273 if (totalMemoryUsage > m_maxDecodedBytes) { | |
| 274 m_purgeAggressively = true; | |
| 275 } | |
| 276 } | |
| 277 | |
| 243 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex, bool frameRect IsOpaque) | 278 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex, bool frameRect IsOpaque) |
| 244 { | 279 { |
| 245 ASSERT(frameIndex <= m_frameBufferCache.size()); | 280 ASSERT(frameIndex <= m_frameBufferCache.size()); |
| 246 if (!frameIndex) { | 281 if (!frameIndex) { |
| 247 // The first frame doesn't rely on any previous data. | 282 // The first frame doesn't rely on any previous data. |
| 248 return kNotFound; | 283 return kNotFound; |
| 249 } | 284 } |
| 250 | 285 |
| 251 const ImageFrame* currBuffer = &m_frameBufferCache[frameIndex]; | 286 const ImageFrame* currBuffer = &m_frameBufferCache[frameIndex]; |
| 252 if ((frameRectIsOpaque || currBuffer->getAlphaBlendSource() == ImageFrame::B lendAtopBgcolor) | 287 if ((frameRectIsOpaque || currBuffer->getAlphaBlendSource() == ImageFrame::B lendAtopBgcolor) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 return; | 457 return; |
| 423 | 458 |
| 424 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; | 459 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; |
| 425 | 460 |
| 426 // FIXME: Don't force perceptual intent if the image profile contains an int ent. | 461 // FIXME: Don't force perceptual intent if the image profile contains an int ent. |
| 427 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU AL)); | 462 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU AL)); |
| 428 #endif // USE(QCMSLIB) | 463 #endif // USE(QCMSLIB) |
| 429 } | 464 } |
| 430 | 465 |
| 431 } // namespace blink | 466 } // namespace blink |
| OLD | NEW |