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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 | 207 |
| 208 return ImageSize(frameSizeAtIndex(index)).area * | 208 return ImageSize(frameSizeAtIndex(index)).area * |
| 209 sizeof(ImageFrame::PixelData); | 209 sizeof(ImageFrame::PixelData); |
| 210 } | 210 } |
| 211 | 211 |
| 212 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) { | 212 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) { |
| 213 // Don't clear if there are no frames or only one frame. | 213 // Don't clear if there are no frames or only one frame. |
| 214 if (m_frameBufferCache.size() <= 1) | 214 if (m_frameBufferCache.size() <= 1) |
| 215 return 0; | 215 return 0; |
| 216 | 216 |
| 217 return clearCacheExceptTwoFrames(clearExceptFrame, kNotFound); | 217 // We expect that after this call, we'll be asked to decode frames after this |
| 218 // one. So we want to avoid clearing frames such that those requests would | |
| 219 // force re-decoding from the beginning of the image. There are two cases in | |
| 220 // which preserving |clearCacheExcept| frame is not enough to avoid that: | |
| 221 // | |
| 222 // 1. |clearExceptFrame| is not yet sufficiently decoded to decode subsequent | |
| 223 // frames. We need the previous frame to sufficiently decode this frame. | |
| 224 // 2. The disposal method of |clearExceptFrame| is DisposeOverwritePrevious. | |
| 225 // In that case, we need to keep the required previous frame in the cache | |
| 226 // to prevent re-decoding that frame when |clearExceptFrame| is disposed. | |
| 227 // | |
| 228 // If either 1 or 2 is true, store the required previous frame in | |
| 229 // |clearExceptFrame2| so it won't be cleared. | |
| 230 size_t clearExceptFrame2 = kNotFound; | |
| 231 if (clearExceptFrame < m_frameBufferCache.size()) { | |
| 232 const ImageFrame& frame = m_frameBufferCache[clearExceptFrame]; | |
| 233 if (!frameStatusSufficientForSuccessors(clearExceptFrame) || | |
| 234 frame.getDisposalMethod() == ImageFrame::DisposeOverwritePrevious) | |
| 235 clearExceptFrame2 = frame.requiredPreviousFrameIndex(); | |
| 236 } | |
| 237 | |
| 238 // Now |clearExceptFrame2| indicates the frame that future frames will depend | |
|
scroggo_chromium
2016/11/28 16:34:38
I don't think this comment is quite correct. It's
joostouwerling
2016/11/30 15:09:17
I don't think it was inherently wrong, but I clari
| |
| 239 // on. But if decoding is skipping forward past intermediate frames, this | |
| 240 // frame may be insufficiently decoded. So we need to keep traversing back | |
| 241 // through the required previous frames until we find the nearest ancestor | |
| 242 // that is sufficiently decoded. Preserving that will minimize the amount of | |
| 243 // future decoding needed. | |
| 244 while (clearExceptFrame2 < m_frameBufferCache.size() && | |
| 245 !frameStatusSufficientForSuccessors(clearExceptFrame2)) { | |
| 246 clearExceptFrame2 = | |
| 247 m_frameBufferCache[clearExceptFrame2].requiredPreviousFrameIndex(); | |
| 248 } | |
| 249 | |
| 250 return clearCacheExceptTwoFrames(clearExceptFrame, clearExceptFrame2); | |
| 218 } | 251 } |
| 219 | 252 |
| 220 size_t ImageDecoder::clearCacheExceptTwoFrames(size_t clearExceptFrame1, | 253 size_t ImageDecoder::clearCacheExceptTwoFrames(size_t clearExceptFrame1, |
| 221 size_t clearExceptFrame2) { | 254 size_t clearExceptFrame2) { |
| 222 size_t frameBytesCleared = 0; | 255 size_t frameBytesCleared = 0; |
| 223 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) { | 256 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) { |
| 224 if (m_frameBufferCache[i].getStatus() != ImageFrame::FrameEmpty && | 257 if (m_frameBufferCache[i].getStatus() != ImageFrame::FrameEmpty && |
| 225 i != clearExceptFrame1 && i != clearExceptFrame2) { | 258 i != clearExceptFrame1 && i != clearExceptFrame2) { |
| 226 frameBytesCleared += frameBytesAtIndex(i); | 259 frameBytesCleared += frameBytesAtIndex(i); |
| 227 clearFrameBuffer(i); | 260 clearFrameBuffer(i); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 | 478 |
| 446 if (SkColorSpace::Equals(m_embeddedColorSpace.get(), gTargetColorSpace)) { | 479 if (SkColorSpace::Equals(m_embeddedColorSpace.get(), gTargetColorSpace)) { |
| 447 return; | 480 return; |
| 448 } | 481 } |
| 449 | 482 |
| 450 m_sourceToOutputDeviceColorTransform = | 483 m_sourceToOutputDeviceColorTransform = |
| 451 SkColorSpaceXform::New(m_embeddedColorSpace.get(), gTargetColorSpace); | 484 SkColorSpaceXform::New(m_embeddedColorSpace.get(), gTargetColorSpace); |
| 452 } | 485 } |
| 453 | 486 |
| 454 } // namespace blink | 487 } // namespace blink |
| OLD | NEW |