OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 #include <limits> | 28 #include <limits> |
29 #include "platform/image-decoders/gif/GIFImageReader.h" | 29 #include "platform/image-decoders/gif/GIFImageReader.h" |
30 #include "wtf/NotFound.h" | 30 #include "wtf/NotFound.h" |
31 #include "wtf/PassOwnPtr.h" | 31 #include "wtf/PassOwnPtr.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp tion colorOptions, size_t maxDecodedBytes) | 35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp tion colorOptions, size_t maxDecodedBytes) |
36 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) | 36 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) |
37 , m_purgeAggressively(false) | |
37 , m_repetitionCount(cAnimationLoopOnce) | 38 , m_repetitionCount(cAnimationLoopOnce) |
38 { | 39 { |
39 } | 40 } |
40 | 41 |
41 GIFImageDecoder::~GIFImageDecoder() | 42 GIFImageDecoder::~GIFImageDecoder() |
42 { | 43 { |
43 } | 44 } |
44 | 45 |
45 void GIFImageDecoder::onSetData(SegmentReader* data) | 46 void GIFImageDecoder::onSetData(SegmentReader* data) |
46 { | 47 { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 buffer->setRequiredPreviousFrameIndex(findRequiredPreviousFrame(index, false )); | 295 buffer->setRequiredPreviousFrameIndex(findRequiredPreviousFrame(index, false )); |
295 } | 296 } |
296 | 297 |
297 void GIFImageDecoder::decode(size_t index) | 298 void GIFImageDecoder::decode(size_t index) |
298 { | 299 { |
299 parse(GIFFrameCountQuery); | 300 parse(GIFFrameCountQuery); |
300 | 301 |
301 if (failed()) | 302 if (failed()) |
302 return; | 303 return; |
303 | 304 |
305 // We don't want to cache so much that we cause a memory issue. | |
306 // If we used a LRU cache we would fill it and then on next animation loop | |
307 // we would need to decode all the frames again -- the LRU would give no | |
308 // benefit and would consume more memory. | |
309 // So instead, simply purge unused frames if our image would be too large. | |
310 | |
311 // As we decode we will learn the total number of frames, and thus total | |
312 // image memory usage. | |
scroggo_chromium
2016/06/20 17:59:40
It might be interesting to note that the "MemoryUs
cblume
2016/06/21 01:00:52
Oh, oops. I originally wrote this with a * 4 since
| |
313 IntSize decodedImageSize = this->decodedSize(); | |
314 unsigned frameMemoryUsage = decodedImageSize.width() * decodedImageSize.heig ht(); | |
scroggo_chromium
2016/06/20 17:59:40
Why is this unsigned? Should we call decodedImageS
cblume
2016/06/21 01:00:52
Hrmmm, the unsigned was a mistake. the .width() an
| |
315 unsigned long long imageMemoryUsage = static_cast<unsigned long long>(frameM emoryUsage) | |
scroggo_chromium
2016/06/20 17:59:40
The meaning of the word "image" here is not entire
cblume
2016/06/21 01:00:52
I did not parse what you said very well.
If I unde
scroggo_chromium
2016/06/21 15:46:08
Sorry, I'll try to explain it better:
You compute
cblume
2016/06/22 01:23:06
Ah, okay. I think I understand better now.
You ar
scroggo_chromium
2016/06/22 15:10:04
Yes, that is what I mean.
| |
316 * static_cast<unsigned long long>(index); | |
317 | |
318 bool overflowed = imageMemoryUsage > ((1 << 29) - 1); | |
scroggo_chromium
2016/06/20 17:59:40
How'd you pick this number?
| |
319 if (overflowed) { | |
scroggo_chromium
2016/06/20 17:59:40
It looks like this should be
if (overflowed |
| |
320 m_purgeAggressively = true; | |
321 } else { | |
322 if (imageMemoryUsage > m_maxDecodedBytes) | |
scroggo_chromium
2016/06/20 17:59:40
As mentioned above, imageMemoryUsage is in units o
| |
323 m_purgeAggressively = true; | |
324 } | |
325 | |
304 Vector<size_t> framesToDecode; | 326 Vector<size_t> framesToDecode; |
305 size_t frameToDecode = index; | 327 size_t frameToDecode = index; |
306 do { | 328 do { |
307 framesToDecode.append(frameToDecode); | 329 framesToDecode.append(frameToDecode); |
308 frameToDecode = m_frameBufferCache[frameToDecode].requiredPreviousFrameI ndex(); | 330 frameToDecode = m_frameBufferCache[frameToDecode].requiredPreviousFrameI ndex(); |
309 } while (frameToDecode != kNotFound && m_frameBufferCache[frameToDecode].get Status() != ImageFrame::FrameComplete); | 331 } while (frameToDecode != kNotFound && m_frameBufferCache[frameToDecode].get Status() != ImageFrame::FrameComplete); |
310 | 332 |
311 for (auto i = framesToDecode.rbegin(); i != framesToDecode.rend(); ++i) { | 333 for (auto i = framesToDecode.rbegin(); i != framesToDecode.rend(); ++i) { |
scroggo_chromium
2016/06/21 15:46:08
At this point, we know the actual amount of data w
| |
312 if (!m_reader->decode(*i)) { | 334 if (!m_reader->decode(*i)) { |
313 setFailed(); | 335 setFailed(); |
314 return; | 336 return; |
315 } | 337 } |
316 | 338 |
339 if (m_purgeAggressively) | |
scroggo_chromium
2016/06/20 17:59:40
As written, m_purgeAggressively could be a local v
cblume
2016/06/21 01:00:52
I do not want it to be a local variable.
If it wa
scroggo_chromium
2016/06/21 15:46:08
But isn't that already true in this patch set, at
| |
340 this->clearCacheExceptFrame(*i); | |
341 | |
317 // We need more data to continue decoding. | 342 // We need more data to continue decoding. |
318 if (m_frameBufferCache[*i].getStatus() != ImageFrame::FrameComplete) | 343 if (m_frameBufferCache[*i].getStatus() != ImageFrame::FrameComplete) |
319 break; | 344 break; |
320 } | 345 } |
321 | 346 |
322 // It is also a fatal error if all data is received and we have decoded all | 347 // It is also a fatal error if all data is received and we have decoded all |
323 // frames available but the file is truncated. | 348 // frames available but the file is truncated. |
324 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && m_reade r && !m_reader->parseCompleted()) | 349 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && m_reade r && !m_reader->parseCompleted()) |
325 setFailed(); | 350 setFailed(); |
326 } | 351 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 | 393 |
369 // Update our status to be partially complete. | 394 // Update our status to be partially complete. |
370 buffer->setStatus(ImageFrame::FramePartial); | 395 buffer->setStatus(ImageFrame::FramePartial); |
371 | 396 |
372 // Reset the alpha pixel tracker for this frame. | 397 // Reset the alpha pixel tracker for this frame. |
373 m_currentBufferSawAlpha = false; | 398 m_currentBufferSawAlpha = false; |
374 return true; | 399 return true; |
375 } | 400 } |
376 | 401 |
377 } // namespace blink | 402 } // namespace blink |
OLD | NEW |