Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/webp/WEBPImageDecoder.cpp

Issue 2365943005: Cap memory usage in webp catch up (Closed)
Patch Set: Moving purge check out of conditional branch. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 m_repetitionCount = cAnimationLoopInfinite; 249 m_repetitionCount = cAnimationLoopInfinite;
250 // FIXME: Implement ICC profile support for animated images. 250 // FIXME: Implement ICC profile support for animated images.
251 m_formatFlags &= ~ICCP_FLAG; 251 m_formatFlags &= ~ICCP_FLAG;
252 } 252 }
253 253
254 if ((m_formatFlags & ICCP_FLAG) && !ignoresGammaAndColorProfile()) 254 if ((m_formatFlags & ICCP_FLAG) && !ignoresGammaAndColorProfile())
255 readColorProfile(); 255 readColorProfile();
256 } 256 }
257 257
258 ASSERT(isDecodedSizeAvailable()); 258 ASSERT(isDecodedSizeAvailable());
259
260 size_t frameCount = WebPDemuxGetI(m_demux, WEBP_FF_FRAME_COUNT);
261 updateAggressivePurging(frameCount);
262
259 return true; 263 return true;
260 } 264 }
261 265
262 bool WEBPImageDecoder::initFrameBuffer(size_t frameIndex) { 266 bool WEBPImageDecoder::initFrameBuffer(size_t frameIndex) {
263 ImageFrame& buffer = m_frameBufferCache[frameIndex]; 267 ImageFrame& buffer = m_frameBufferCache[frameIndex];
264 if (buffer.getStatus() != ImageFrame::FrameEmpty) // Already initialized. 268 if (buffer.getStatus() != ImageFrame::FrameEmpty) // Already initialized.
265 return true; 269 return true;
266 270
267 const size_t requiredPreviousFrameIndex = buffer.requiredPreviousFrameIndex(); 271 const size_t requiredPreviousFrameIndex = buffer.requiredPreviousFrameIndex();
268 if (requiredPreviousFrameIndex == kNotFound) { 272 if (requiredPreviousFrameIndex == kNotFound) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } else { 483 } else {
480 decodeSingleFrame(webpFrame.fragment.bytes, webpFrame.fragment.size, *i); 484 decodeSingleFrame(webpFrame.fragment.bytes, webpFrame.fragment.size, *i);
481 WebPDemuxReleaseIterator(&webpFrame); 485 WebPDemuxReleaseIterator(&webpFrame);
482 } 486 }
483 if (failed()) 487 if (failed())
484 return; 488 return;
485 489
486 // We need more data to continue decoding. 490 // We need more data to continue decoding.
487 if (m_frameBufferCache[*i].getStatus() != ImageFrame::FrameComplete) 491 if (m_frameBufferCache[*i].getStatus() != ImageFrame::FrameComplete)
488 break; 492 break;
493
494 if (m_purgeAggressively)
495 clearCacheExceptFrame(*i);
489 } 496 }
490 497
491 // It is also a fatal error if all data is received and we have decoded all 498 // It is also a fatal error if all data is received and we have decoded all
492 // frames available but the file is truncated. 499 // frames available but the file is truncated.
493 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && 500 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() &&
494 m_demux && m_demuxState != WEBP_DEMUX_DONE) 501 m_demux && m_demuxState != WEBP_DEMUX_DONE)
495 setFailed(); 502 setFailed();
496 } 503 }
497 504
498 bool WEBPImageDecoder::decodeSingleFrame(const uint8_t* dataBytes, 505 bool WEBPImageDecoder::decodeSingleFrame(const uint8_t* dataBytes,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 return false; 564 return false;
558 } 565 }
559 // FALLTHROUGH 566 // FALLTHROUGH
560 default: 567 default:
561 clear(); 568 clear();
562 return setFailed(); 569 return setFailed();
563 } 570 }
564 } 571 }
565 572
566 } // namespace blink 573 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698