Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008-2009 Torch Mobile, Inc. | 2 * Copyright (C) 2008-2009 Torch Mobile, Inc. |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 int ImageDecoder::lowerBoundScaledY(int origY, int searchStart) | 220 int ImageDecoder::lowerBoundScaledY(int origY, int searchStart) |
| 221 { | 221 { |
| 222 return getScaledValue<LowerBound>(m_scaledRows, origY, searchStart); | 222 return getScaledValue<LowerBound>(m_scaledRows, origY, searchStart); |
| 223 } | 223 } |
| 224 | 224 |
| 225 int ImageDecoder::scaledY(int origY, int searchStart) | 225 int ImageDecoder::scaledY(int origY, int searchStart) |
| 226 { | 226 { |
| 227 return getScaledValue<Exact>(m_scaledRows, origY, searchStart); | 227 return getScaledValue<Exact>(m_scaledRows, origY, searchStart); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void ImageDecoder::clearFrameBufferCache(size_t clearExceptFrame) | |
| 231 { | |
| 232 // Don't clear if there is no or only one frame. | |
| 233 if (m_frameBufferCache.size() <= 1) | |
| 234 return; | |
| 235 | |
| 236 // We need to preserve frames such that: | |
| 237 // 1. We don't clear |clearExceptFrame|; | |
| 238 // 2. We don't clear any frame from which a future initFrameBuffer() call | |
| 239 // will copy bitmap data; | |
| 240 // 3. We don't clear empty frames. | |
|
Peter Kasting
2013/05/24 03:15:22
Why not clear empty frames? Shouldn't that just b
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 241 // All other frames can be cleared. | |
| 242 size_t frameToBeRequired; | |
|
Peter Kasting
2013/05/24 03:15:22
Nit: Init this to notFound; this allows eliminatin
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 243 if (clearExceptFrame < m_frameBufferCache.size() && m_frameBufferCache[clear ExceptFrame].status() == ImageFrame::FrameEmpty) { | |
| 244 frameToBeRequired = clearExceptFrame; | |
| 245 do { | |
| 246 frameToBeRequired = m_frameBufferCache[frameToBeRequired].requiredPr eviousFrameIndex(); | |
| 247 } while (frameToBeRequired != notFound && m_frameBufferCache[frameToBeRe quired].status() == ImageFrame::FrameEmpty); | |
|
Peter Kasting
2013/05/24 03:15:22
This loop tries to preserve the frame we'll need t
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 248 } else { | |
| 249 // initFrameBuffer() has already been called for this frame. | |
| 250 frameToBeRequired = notFound; | |
| 251 } | |
| 252 | |
| 253 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) { | |
| 254 if (i != clearExceptFrame && i != frameToBeRequired && m_frameBufferCach e[i].status() != ImageFrame::FrameEmpty) | |
| 255 clearFrameBuffer(i); | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 void ImageDecoder::clearFrameBuffer(size_t frameIndex) | |
| 260 { | |
| 261 m_frameBufferCache[frameIndex].clearPixelData(); | |
| 262 } | |
| 263 | |
| 264 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex) | |
|
Peter Kasting
2013/05/24 03:15:22
By the way, the algorithm in this function can be
| |
| 265 { | |
| 266 if (!frameIndex) { | |
| 267 // The first frame doesn't rely on any previous data. | |
| 268 return notFound; | |
| 269 } | |
| 270 | |
| 271 // The starting state for this frame depends on the previous frame's | |
| 272 // disposal method. | |
| 273 // | |
| 274 // Frames that use the DisposeOverwritePrevious method are effectively | |
| 275 // no-ops in terms of changing the starting state of a frame compared to | |
| 276 // the starting state of the previous frame, so skip over them. (If the | |
| 277 // first frame specifies this method, it will get treated like | |
| 278 // DisposeOverwriteBgcolor below and reset to a completely empty image.) | |
| 279 size_t prevFrame = frameIndex - 1; | |
| 280 const ImageFrame* prevBuffer = &m_frameBufferCache[prevFrame]; | |
|
Peter Kasting
2013/05/24 03:15:22
If we're going to do this we should either check o
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 281 ImageFrame::FrameDisposalMethod prevMethod = prevBuffer->disposalMethod(); | |
| 282 while (prevFrame && (prevMethod == ImageFrame::DisposeOverwritePrevious)) { | |
| 283 prevBuffer = &m_frameBufferCache[--prevFrame]; | |
| 284 prevMethod = prevBuffer->disposalMethod(); | |
| 285 } | |
| 286 | |
| 287 if (prevMethod == ImageFrame::DisposeNotSpecified || prevMethod == ImageFram e::DisposeKeep) { | |
| 288 // prevFrame will be used as the starting state for this frame. | |
|
Peter Kasting
2013/05/24 03:15:22
Nit: Might want to add a note or FIXME about being
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 289 return prevFrame; | |
| 290 } | |
| 291 | |
| 292 if (!prevFrame) { | |
| 293 // The first frame whose disposal method is DisposeOverwriteBgColor or | |
| 294 // DisposeOverritePrevious will be reset to background despite its size. | |
|
Peter Kasting
2013/05/24 03:15:22
Nit: Comment could be clearer; how about:
This fr
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 295 return notFound; | |
| 296 } | |
| 297 | |
| 298 ASSERT(prevMethod == ImageFrame::DisposeOverwriteBgcolor); | |
| 299 const IntRect& prevRect = prevBuffer->originalFrameRect(); | |
| 300 const IntSize& bufferSize = scaledSize(); | |
|
Peter Kasting
2013/05/24 03:15:22
I think scaledSize() got nuked (or is getting nuke
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 301 if (prevRect.contains(IntRect(IntPoint(), scaledSize()))) { | |
| 302 // prevFrame covering the whole image will be reset to background, | |
|
Peter Kasting
2013/05/24 03:15:22
Nit: A slightly shorter way of doing this:
//
Xianzhu
2013/05/28 22:54:21
Done.
| |
| 303 return notFound; | |
| 304 } | |
| 305 | |
| 306 // prevFrame only clears part of the image to background, so it contributes | |
| 307 // to the starting state of this frame. | |
| 308 return prevFrame; | |
| 309 } | |
| 310 | |
| 230 } // namespace WebCore | 311 } // namespace WebCore |
| OLD | NEW |