| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 29 matching lines...) Expand all Loading... |
| 131 { | 135 { |
| 132 for (auto& i : m_objectLayerSizeMap) { | 136 for (auto& i : m_objectLayerSizeMap) { |
| 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 } |
| 145 m_frameTimeWhenTimerStarted = 0.0; |
| 141 } | 146 } |
| 142 | 147 |
| 143 void ImageQualityController::restartTimer() | 148 void ImageQualityController::restartTimer(double lastFrameTimeMonotonic) |
| 144 { | 149 { |
| 145 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); | 150 if (!m_timer->isActive() || lastFrameTimeMonotonic == 0.0 || m_frameTimeWhen
TimerStarted == 0.0 || (lastFrameTimeMonotonic - m_frameTimeWhenTimerStarted > c
TimerRestartThreshold)) { |
| 151 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); |
| 152 m_frameTimeWhenTimerStarted = lastFrameTimeMonotonic; |
| 153 } |
| 146 } | 154 } |
| 147 | 155 |
| 148 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object,
Image* image, const void *layer, const LayoutSize& layoutSize) | 156 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object,
Image* image, const void *layer, const LayoutSize& layoutSize, double lastFrame
TimeMonotonic) |
| 149 { | 157 { |
| 150 // If the image is not a bitmap image, then none of this is relevant and we
just paint at high | 158 // If the image is not a bitmap image, then none of this is relevant and we
just paint at high |
| 151 // quality. | 159 // quality. |
| 152 if (!image || !image->isBitmapImage()) | 160 if (!image || !image->isBitmapImage()) |
| 153 return false; | 161 return false; |
| 154 | 162 |
| 155 if (!layer) | 163 if (!layer) |
| 156 return false; | 164 return false; |
| 157 | 165 |
| 158 if (object.style()->imageRendering() == ImageRenderingOptimizeContrast) | 166 if (object.style()->imageRendering() == ImageRenderingOptimizeContrast) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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. | 188 // 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); | 189 removeLayer(object, innerMap, layer); |
| 182 return false; | 190 return false; |
| 183 } | 191 } |
| 184 | 192 |
| 185 // If an animated resize is active for this object, paint in low quality and
kick the timer ahead. | 193 // If an animated resize is active for this object, paint in low quality and
kick the timer ahead. |
| 186 if (objectIsResizing) { | 194 if (objectIsResizing) { |
| 187 bool sizesChanged = oldSize != layoutSize; | 195 bool sizesChanged = oldSize != layoutSize; |
| 188 set(object, innerMap, layer, layoutSize, sizesChanged); | 196 set(object, innerMap, layer, layoutSize, sizesChanged); |
| 189 if (sizesChanged) | 197 if (sizesChanged) |
| 190 restartTimer(); | 198 restartTimer(lastFrameTimeMonotonic); |
| 191 return true; | 199 return true; |
| 192 } | 200 } |
| 193 // If this is the first time resizing this image, or its size is the | 201 // 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 | 202 // same as the last resize, draw at high res, but record the paint |
| 195 // size and set the timer. | 203 // size and set the timer. |
| 196 if (isFirstResize || oldSize == layoutSize) { | 204 if (isFirstResize || oldSize == layoutSize) { |
| 197 restartTimer(); | 205 restartTimer(lastFrameTimeMonotonic); |
| 198 set(object, innerMap, layer, layoutSize, false); | 206 set(object, innerMap, layer, layoutSize, false); |
| 199 return false; | 207 return false; |
| 200 } | 208 } |
| 201 // If the timer is no longer active, draw at high quality and don't | 209 // If the timer is no longer active, draw at high quality and don't |
| 202 // set the timer. | 210 // set the timer. |
| 203 if (!m_timer->isActive()) { | 211 if (!m_timer->isActive()) { |
| 204 removeLayer(object, innerMap, layer); | 212 removeLayer(object, innerMap, layer); |
| 205 return false; | 213 return false; |
| 206 } | 214 } |
| 207 // This object has been resized to two different sizes while the timer | 215 // 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 | 216 // is active, so draw at low quality, set the flag for animated resizes and |
| 209 // the object to the list for high quality redraw. | 217 // the object to the list for high quality redraw. |
| 210 set(object, innerMap, layer, layoutSize, true); | 218 set(object, innerMap, layer, layoutSize, true); |
| 211 restartTimer(); | 219 restartTimer(lastFrameTimeMonotonic); |
| 212 return true; | 220 return true; |
| 213 } | 221 } |
| 214 | 222 |
| 215 } // namespace blink | 223 } // namespace blink |
| OLD | NEW |