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

Side by Side Diff: third_party/WebKit/Source/core/layout/ImageQualityController.cpp

Issue 1911273002: Don't restart the ImageQualityController timer unless it is already half over. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/layout/ImageQualityController.h" 31 #include "core/layout/ImageQualityController.h"
32 32
33 #include "core/frame/FrameView.h" 33 #include "core/frame/FrameView.h"
34 #include "core/frame/LocalFrame.h" 34 #include "core/frame/LocalFrame.h"
35 #include "core/page/ChromeClient.h"
36 #include "core/page/Page.h"
35 37
36 namespace blink { 38 namespace blink {
37 39
38 static const double cLowQualityTimeThreshold = 0.500; // 500 ms 40 const double ImageQualityController::cLowQualityTimeThreshold = 0.500; // 500 ms
41 const double ImageQualityController::cTimerRestartThreshold = 0.250; // 250 ms
39 42
40 static ImageQualityController* gImageQualityController = nullptr; 43 static ImageQualityController* gImageQualityController = nullptr;
41 44
42 ImageQualityController* ImageQualityController::imageQualityController() 45 ImageQualityController* ImageQualityController::imageQualityController()
43 { 46 {
44 if (!gImageQualityController) 47 if (!gImageQualityController)
45 gImageQualityController = new ImageQualityController; 48 gImageQualityController = new ImageQualityController;
46 49
47 return gImageQualityController; 50 return gImageQualityController;
48 } 51 }
(...skipping 15 matching lines...) Expand all
64 } 67 }
65 68
66 InterpolationQuality ImageQualityController::chooseInterpolationQuality(const La youtObject& object, Image* image, const void* layer, const LayoutSize& layoutSiz e) 69 InterpolationQuality ImageQualityController::chooseInterpolationQuality(const La youtObject& object, Image* image, const void* layer, const LayoutSize& layoutSiz e)
67 { 70 {
68 if (object.style()->imageRendering() == ImageRenderingPixelated) 71 if (object.style()->imageRendering() == ImageRenderingPixelated)
69 return InterpolationNone; 72 return InterpolationNone;
70 73
71 if (InterpolationDefault == InterpolationLow) 74 if (InterpolationDefault == InterpolationLow)
72 return InterpolationLow; 75 return InterpolationLow;
73 76
74 if (shouldPaintAtLowQuality(object, image, layer, layoutSize)) 77 if (shouldPaintAtLowQuality(object, image, layer, layoutSize, object.frameVi ew()->page()->chromeClient().lastFrameTimeMonotonic()))
75 return InterpolationLow; 78 return InterpolationLow;
76 79
77 // For images that are potentially animated we paint them at medium quality. 80 // For images that are potentially animated we paint them at medium quality.
78 if (image && image->maybeAnimated()) 81 if (image && image->maybeAnimated())
79 return InterpolationMedium; 82 return InterpolationMedium;
80 83
81 return InterpolationDefault; 84 return InterpolationDefault;
82 } 85 }
83 86
84 ImageQualityController::~ImageQualityController() 87 ImageQualityController::~ImageQualityController()
85 { 88 {
86 // This will catch users of ImageQualityController that forget to call clean Up. 89 // This will catch users of ImageQualityController that forget to call clean Up.
87 ASSERT(!gImageQualityController || gImageQualityController->isEmpty()); 90 ASSERT(!gImageQualityController || gImageQualityController->isEmpty());
88 } 91 }
89 92
90 ImageQualityController::ImageQualityController() 93 ImageQualityController::ImageQualityController()
91 : m_timer(adoptPtr(new Timer<ImageQualityController>(this, &ImageQualityCont roller::highQualityRepaintTimerFired))) 94 : m_timer(adoptPtr(new Timer<ImageQualityController>(this, &ImageQualityCont roller::highQualityRepaintTimerFired)))
95 , m_frameTimeWhenTimerStarted(0.0)
92 { 96 {
93 } 97 }
94 98
95 void ImageQualityController::setTimer(Timer<ImageQualityController>* newTimer) 99 void ImageQualityController::setTimer(Timer<ImageQualityController>* newTimer)
96 { 100 {
97 m_timer = adoptPtr(newTimer); 101 m_timer = adoptPtr(newTimer);
98 } 102 }
99 103
100 void ImageQualityController::removeLayer(const LayoutObject& object, LayerSizeMa p* innerMap, const void* layer) 104 void ImageQualityController::removeLayer(const LayoutObject& object, LayerSizeMa p* innerMap, const void* layer)
101 { 105 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // Only invalidate the object if it is animating. 137 // Only invalidate the object if it is animating.
134 if (!i.value.isResizing) 138 if (!i.value.isResizing)
135 continue; 139 continue;
136 140
137 // TODO(wangxianzhu): Use LayoutObject::getMutableForPainting(). 141 // TODO(wangxianzhu): Use LayoutObject::getMutableForPainting().
138 const_cast<LayoutObject*>(i.key)->setShouldDoFullPaintInvalidation(); 142 const_cast<LayoutObject*>(i.key)->setShouldDoFullPaintInvalidation();
139 i.value.isResizing = false; 143 i.value.isResizing = false;
140 } 144 }
141 } 145 }
142 146
143 void ImageQualityController::restartTimer() 147 void ImageQualityController::restartTimer(double lastFrameTimeMonotonic)
144 { 148 {
145 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); 149 if (lastFrameTimeMonotonic == 0.0 || m_frameTimeWhenTimerStarted == 0.0 || ( lastFrameTimeMonotonic - m_frameTimeWhenTimerStarted > cTimerRestartThreshold)) {
150 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE);
151 m_frameTimeWhenTimerStarted = lastFrameTimeMonotonic;
152 }
146 } 153 }
147 154
148 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object, Image* image, const void *layer, const LayoutSize& layoutSize) 155 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object, Image* image, const void *layer, const LayoutSize& layoutSize, double lastFrame TimeMonotonic)
149 { 156 {
150 // If the image is not a bitmap image, then none of this is relevant and we just paint at high 157 // If the image is not a bitmap image, then none of this is relevant and we just paint at high
151 // quality. 158 // quality.
152 if (!image || !image->isBitmapImage()) 159 if (!image || !image->isBitmapImage())
153 return false; 160 return false;
154 161
155 if (!layer) 162 if (!layer)
156 return false; 163 return false;
157 164
158 if (object.style()->imageRendering() == ImageRenderingOptimizeContrast) 165 if (object.style()->imageRendering() == ImageRenderingOptimizeContrast)
(...skipping 21 matching lines...) Expand all
180 // There is no scale in effect. If we had a scale in effect before, we c an just remove this object from the list. 187 // There is no scale in effect. If we had a scale in effect before, we c an just remove this object from the list.
181 removeLayer(object, innerMap, layer); 188 removeLayer(object, innerMap, layer);
182 return false; 189 return false;
183 } 190 }
184 191
185 // If an animated resize is active for this object, paint in low quality and kick the timer ahead. 192 // If an animated resize is active for this object, paint in low quality and kick the timer ahead.
186 if (objectIsResizing) { 193 if (objectIsResizing) {
187 bool sizesChanged = oldSize != layoutSize; 194 bool sizesChanged = oldSize != layoutSize;
188 set(object, innerMap, layer, layoutSize, sizesChanged); 195 set(object, innerMap, layer, layoutSize, sizesChanged);
189 if (sizesChanged) 196 if (sizesChanged)
190 restartTimer(); 197 restartTimer(lastFrameTimeMonotonic);
191 return true; 198 return true;
192 } 199 }
193 // If this is the first time resizing this image, or its size is the 200 // If this is the first time resizing this image, or its size is the
194 // same as the last resize, draw at high res, but record the paint 201 // same as the last resize, draw at high res, but record the paint
195 // size and set the timer. 202 // size and set the timer.
196 if (isFirstResize || oldSize == layoutSize) { 203 if (isFirstResize || oldSize == layoutSize) {
197 restartTimer(); 204 restartTimer(lastFrameTimeMonotonic);
198 set(object, innerMap, layer, layoutSize, false); 205 set(object, innerMap, layer, layoutSize, false);
199 return false; 206 return false;
200 } 207 }
201 // If the timer is no longer active, draw at high quality and don't 208 // If the timer is no longer active, draw at high quality and don't
202 // set the timer. 209 // set the timer.
203 if (!m_timer->isActive()) { 210 if (!m_timer->isActive()) {
204 removeLayer(object, innerMap, layer); 211 removeLayer(object, innerMap, layer);
205 return false; 212 return false;
206 } 213 }
207 // This object has been resized to two different sizes while the timer 214 // This object has been resized to two different sizes while the timer
208 // is active, so draw at low quality, set the flag for animated resizes and 215 // is active, so draw at low quality, set the flag for animated resizes and
209 // the object to the list for high quality redraw. 216 // the object to the list for high quality redraw.
210 set(object, innerMap, layer, layoutSize, true); 217 set(object, innerMap, layer, layoutSize, true);
211 restartTimer(); 218 restartTimer(lastFrameTimeMonotonic);
212 return true; 219 return true;
213 } 220 }
214 221
215 } // namespace blink 222 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698