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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/BitmapImage.cpp

Issue 1857543002: Don't recreate SkImages for high-res (GIF, WEBP...) animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review #4 fix. Thanks @pkasting. Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 BitmapImage::~BitmapImage() 100 BitmapImage::~BitmapImage()
101 { 101 {
102 stopAnimation(); 102 stopAnimation();
103 } 103 }
104 104
105 bool BitmapImage::currentFrameHasSingleSecurityOrigin() const 105 bool BitmapImage::currentFrameHasSingleSecurityOrigin() const
106 { 106 {
107 return true; 107 return true;
108 } 108 }
109 109
110 void BitmapImage::destroyDecodedData(bool destroyAll) 110 void BitmapImage::destroyDecodedData()
111 { 111 {
112 for (size_t i = 0; i < m_frames.size(); ++i) { 112 for (size_t i = 0; i < m_frames.size(); ++i) {
113 // The underlying frame isn't actually changing (we're just trying to 113 // The underlying frame isn't actually changing (we're just trying to
114 // save the memory for the framebuffer data), so we don't need to clear 114 // save the memory for the framebuffer data), so we don't need to clear
115 // the metadata. 115 // the metadata.
116 m_frames[i].clear(false); 116 m_frames[i].clear(false);
117 } 117 }
118 118
119 size_t frameBytesCleared = m_source.clearCacheExceptFrame(destroyAll ? kNotF ound : m_currentFrame); 119 size_t frameBytesCleared = m_source.clearCacheExceptFrame(kNotFound);
120 notifyMemoryChanged(-safeCast<int>(frameBytesCleared)); 120 notifyMemoryChanged(-safeCast<int>(frameBytesCleared));
121 } 121 }
122 122
123 void BitmapImage::destroyDecodedDataIfNecessary()
124 {
125 // Animated images >5MB are considered large enough that we'll only hang on
126 // to one frame at a time.
127 static const size_t cLargeAnimationCutoff = 5242880;
128 size_t allFrameBytes = 0;
129 for (size_t i = 0; i < m_frames.size(); ++i)
130 allFrameBytes += m_frames[i].m_frameBytes;
131
132 if (allFrameBytes > cLargeAnimationCutoff) {
133 destroyDecodedData(false);
134 }
135 }
136
137 void BitmapImage::notifyMemoryChanged(int delta) 123 void BitmapImage::notifyMemoryChanged(int delta)
138 { 124 {
139 if (delta && getImageObserver()) 125 if (delta && getImageObserver())
140 getImageObserver()->decodedSizeChanged(this, delta); 126 getImageObserver()->decodedSizeChanged(this, delta);
141 } 127 }
142 128
143 int BitmapImage::totalFrameBytes() 129 int BitmapImage::totalFrameBytes()
144 { 130 {
145 const size_t numFrames = frameCount(); 131 const size_t numFrames = frameCount();
146 size_t totalBytes = 0; 132 size_t totalBytes = 0;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 m_frameTimer.clear(); 550 m_frameTimer.clear();
565 } 551 }
566 552
567 void BitmapImage::resetAnimation() 553 void BitmapImage::resetAnimation()
568 { 554 {
569 stopAnimation(); 555 stopAnimation();
570 m_currentFrame = 0; 556 m_currentFrame = 0;
571 m_repetitionsComplete = 0; 557 m_repetitionsComplete = 0;
572 m_desiredFrameStartTime = 0; 558 m_desiredFrameStartTime = 0;
573 m_animationFinished = false; 559 m_animationFinished = false;
574
575 // For extremely large animations, when the animation is reset, we just thro w everything away.
576 destroyDecodedDataIfNecessary();
577 } 560 }
578 561
579 bool BitmapImage::maybeAnimated() 562 bool BitmapImage::maybeAnimated()
580 { 563 {
581 if (m_animationFinished) 564 if (m_animationFinished)
582 return false; 565 return false;
583 if (frameCount() > 1) 566 if (frameCount() > 1)
584 return true; 567 return true;
585 568
586 return m_source.repetitionCount() != cAnimationNone; 569 return m_source.repetitionCount() != cAnimationNone;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // because it is 0 (see comments on its declaration in ImageAnimation.h) . 607 // because it is 0 (see comments on its declaration in ImageAnimation.h) .
625 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom plete > m_repetitionCount) 608 if ((repetitionCount(true) != cAnimationLoopInfinite && m_repetitionsCom plete > m_repetitionCount)
626 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti tionsComplete > 0)) { 609 || (m_animationPolicy == ImageAnimationPolicyAnimateOnce && m_repeti tionsComplete > 0)) {
627 m_animationFinished = true; 610 m_animationFinished = true;
628 m_desiredFrameStartTime = 0; 611 m_desiredFrameStartTime = 0;
629 --m_currentFrame; 612 --m_currentFrame;
630 advancedAnimation = false; 613 advancedAnimation = false;
631 } else 614 } else
632 m_currentFrame = 0; 615 m_currentFrame = 0;
633 } 616 }
634 destroyDecodedDataIfNecessary();
635 617
636 // We need to draw this frame if we advanced to it while not skipping, or if 618 // We need to draw this frame if we advanced to it while not skipping, or if
637 // while trying to skip frames we hit the last frame and thus had to stop. 619 // while trying to skip frames we hit the last frame and thus had to stop.
638 if (skippingFrames != advancedAnimation) 620 if (skippingFrames != advancedAnimation)
639 getImageObserver()->animationAdvanced(this); 621 getImageObserver()->animationAdvanced(this);
640 return advancedAnimation; 622 return advancedAnimation;
641 } 623 }
642 624
643 } // namespace blink 625 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698