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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 if (m_frameBufferCache[index].getStatus() != ImageFrame::FrameComplete) | 252 if (m_frameBufferCache[index].getStatus() != ImageFrame::FrameComplete) |
253 return false; | 253 return false; |
254 | 254 |
255 if (m_purgeAggressively) | 255 if (m_purgeAggressively) |
256 clearCacheExceptFrame(index); | 256 clearCacheExceptFrame(index); |
257 | 257 |
258 return true; | 258 return true; |
259 } | 259 } |
260 | 260 |
| 261 bool ImageDecoder::initFrameBuffer(size_t frameIndex) { |
| 262 DCHECK(frameIndex < m_frameBufferCache.size()); |
| 263 |
| 264 ImageFrame* const buffer = &m_frameBufferCache[frameIndex]; |
| 265 |
| 266 // If the frame is already initialized, return true. |
| 267 if (buffer->getStatus() != ImageFrame::FrameEmpty) |
| 268 return true; |
| 269 |
| 270 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex(); |
| 271 if (requiredPreviousFrameIndex == kNotFound) { |
| 272 // This frame doesn't rely on any previous data. |
| 273 if (!buffer->setSizeAndColorSpace(size().width(), size().height(), |
| 274 colorSpace())) { |
| 275 return setFailed(); |
| 276 } |
| 277 } else { |
| 278 ImageFrame* const prevBuffer = |
| 279 &m_frameBufferCache[requiredPreviousFrameIndex]; |
| 280 DCHECK(prevBuffer->getStatus() == ImageFrame::FrameComplete); |
| 281 |
| 282 // We try to reuse |prevBuffer| as starting state to avoid copying. |
| 283 // If canReusePreviousFrameBuffer returns false, we must copy the data since |
| 284 // |prevBuffer| is necessary to decode this or later frames. In that case, |
| 285 // copy the data instead. |
| 286 if ((!canReusePreviousFrameBuffer(frameIndex) || |
| 287 !buffer->takeBitmapDataIfWritable(prevBuffer)) && |
| 288 !buffer->copyBitmapData(*prevBuffer)) |
| 289 return setFailed(); |
| 290 |
| 291 if (prevBuffer->getDisposalMethod() == |
| 292 ImageFrame::DisposeOverwriteBgcolor) { |
| 293 // We want to clear the previous frame to transparent, without |
| 294 // affecting pixels in the image outside of the frame. |
| 295 const IntRect& prevRect = prevBuffer->originalFrameRect(); |
| 296 DCHECK(!prevRect.contains(IntRect(IntPoint(), size()))); |
| 297 buffer->zeroFillFrameRect(prevRect); |
| 298 } |
| 299 } |
| 300 |
| 301 // Update our status to be partially complete. |
| 302 buffer->setStatus(ImageFrame::FramePartial); |
| 303 |
| 304 onInitFrameBuffer(frameIndex); |
| 305 return true; |
| 306 } |
| 307 |
261 void ImageDecoder::updateAggressivePurging(size_t index) { | 308 void ImageDecoder::updateAggressivePurging(size_t index) { |
262 if (m_purgeAggressively) | 309 if (m_purgeAggressively) |
263 return; | 310 return; |
264 | 311 |
265 // We don't want to cache so much that we cause a memory issue. | 312 // We don't want to cache so much that we cause a memory issue. |
266 // | 313 // |
267 // If we used a LRU cache we would fill it and then on next animation loop | 314 // If we used a LRU cache we would fill it and then on next animation loop |
268 // we would need to decode all the frames again -- the LRU would give no | 315 // we would need to decode all the frames again -- the LRU would give no |
269 // benefit and would consume more memory. | 316 // benefit and would consume more memory. |
270 // So instead, simply purge unused frames if caching all of the frames of | 317 // So instead, simply purge unused frames if caching all of the frames of |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 492 |
446 if (SkColorSpace::Equals(m_embeddedColorSpace.get(), gTargetColorSpace)) { | 493 if (SkColorSpace::Equals(m_embeddedColorSpace.get(), gTargetColorSpace)) { |
447 return; | 494 return; |
448 } | 495 } |
449 | 496 |
450 m_sourceToOutputDeviceColorTransform = | 497 m_sourceToOutputDeviceColorTransform = |
451 SkColorSpaceXform::New(m_embeddedColorSpace.get(), gTargetColorSpace); | 498 SkColorSpaceXform::New(m_embeddedColorSpace.get(), gTargetColorSpace); |
452 } | 499 } |
453 | 500 |
454 } // namespace blink | 501 } // namespace blink |
OLD | NEW |