| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 ImageQualityController::~ImageQualityController() | 84 ImageQualityController::~ImageQualityController() |
| 85 { | 85 { |
| 86 // This will catch users of ImageQualityController that forget to call clean
Up. | 86 // This will catch users of ImageQualityController that forget to call clean
Up. |
| 87 ASSERT(!gImageQualityController || gImageQualityController->isEmpty()); | 87 ASSERT(!gImageQualityController || gImageQualityController->isEmpty()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 ImageQualityController::ImageQualityController() | 90 ImageQualityController::ImageQualityController() |
| 91 : m_timer(adoptPtr(new Timer<ImageQualityController>(this, &ImageQualityCont
roller::highQualityRepaintTimerFired))) | 91 : m_timer(adoptPtr(new Timer<ImageQualityController>(this, &ImageQualityCont
roller::highQualityRepaintTimerFired))) |
| 92 , m_liveResizeOptimizationIsActive(false) | |
| 93 { | 92 { |
| 94 } | 93 } |
| 95 | 94 |
| 96 void ImageQualityController::setTimer(Timer<ImageQualityController>* newTimer) | 95 void ImageQualityController::setTimer(Timer<ImageQualityController>* newTimer) |
| 97 { | 96 { |
| 98 m_timer = adoptPtr(newTimer); | 97 m_timer = adoptPtr(newTimer); |
| 99 } | 98 } |
| 100 | 99 |
| 101 void ImageQualityController::removeLayer(const LayoutObject& object, LayerSizeMa
p* innerMap, const void* layer) | 100 void ImageQualityController::removeLayer(const LayoutObject& object, LayerSizeMa
p* innerMap, const void* layer) |
| 102 { | 101 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 124 { | 123 { |
| 125 m_objectLayerSizeMap.remove(&object); | 124 m_objectLayerSizeMap.remove(&object); |
| 126 if (m_objectLayerSizeMap.isEmpty()) { | 125 if (m_objectLayerSizeMap.isEmpty()) { |
| 127 m_timer->stop(); | 126 m_timer->stop(); |
| 128 } | 127 } |
| 129 } | 128 } |
| 130 | 129 |
| 131 void ImageQualityController::highQualityRepaintTimerFired(Timer<ImageQualityCont
roller>*) | 130 void ImageQualityController::highQualityRepaintTimerFired(Timer<ImageQualityCont
roller>*) |
| 132 { | 131 { |
| 133 for (auto* layoutObject : m_objectLayerSizeMap.keys()) { | 132 for (auto* layoutObject : m_objectLayerSizeMap.keys()) { |
| 134 if (LocalFrame* frame = layoutObject->document().frame()) { | |
| 135 // If this layoutObject's containing FrameView is in live resize, pu
nt the timer and hold back for now. | |
| 136 if (frame->view() && frame->view()->inLiveResize()) { | |
| 137 restartTimer(); | |
| 138 return; | |
| 139 } | |
| 140 } | |
| 141 ObjectLayerSizeMap::iterator i = m_objectLayerSizeMap.find(layoutObject)
; | 133 ObjectLayerSizeMap::iterator i = m_objectLayerSizeMap.find(layoutObject)
; |
| 142 if (i != m_objectLayerSizeMap.end()) { | 134 if (i != m_objectLayerSizeMap.end()) { |
| 143 // Only invalidate the object if it is animating. | 135 // Only invalidate the object if it is animating. |
| 144 if (i->value.isResizing) { | 136 if (i->value.isResizing) { |
| 145 // TODO(wangxianzhu): Use LayoutObject::getMutableForPainting(). | 137 // TODO(wangxianzhu): Use LayoutObject::getMutableForPainting(). |
| 146 const_cast<LayoutObject*>(layoutObject)->setShouldDoFullPaintInv
alidation(); | 138 const_cast<LayoutObject*>(layoutObject)->setShouldDoFullPaintInv
alidation(); |
| 147 } | 139 } |
| 148 i->value.isResizing = false; | 140 i->value.isResizing = false; |
| 149 } | 141 } |
| 150 } | 142 } |
| 151 | |
| 152 m_liveResizeOptimizationIsActive = false; | |
| 153 } | 143 } |
| 154 | 144 |
| 155 void ImageQualityController::restartTimer() | 145 void ImageQualityController::restartTimer() |
| 156 { | 146 { |
| 157 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); | 147 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); |
| 158 } | 148 } |
| 159 | 149 |
| 160 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object,
Image* image, const void *layer, const LayoutSize& layoutSize) | 150 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object,
Image* image, const void *layer, const LayoutSize& layoutSize) |
| 161 { | 151 { |
| 162 // If the image is not a bitmap image, then none of this is relevant and we
just paint at high | 152 // If the image is not a bitmap image, then none of this is relevant and we
just paint at high |
| (...skipping 18 matching lines...) Expand all Loading... |
| 181 LayoutSize oldSize; | 171 LayoutSize oldSize; |
| 182 bool isFirstResize = true; | 172 bool isFirstResize = true; |
| 183 if (innerMap) { | 173 if (innerMap) { |
| 184 LayerSizeMap::iterator j = innerMap->find(layer); | 174 LayerSizeMap::iterator j = innerMap->find(layer); |
| 185 if (j != innerMap->end()) { | 175 if (j != innerMap->end()) { |
| 186 isFirstResize = false; | 176 isFirstResize = false; |
| 187 oldSize = j->value; | 177 oldSize = j->value; |
| 188 } | 178 } |
| 189 } | 179 } |
| 190 | 180 |
| 191 // If the containing FrameView is being resized, paint at low quality until
resizing is finished. | |
| 192 if (LocalFrame* frame = object.document().frame()) { | |
| 193 bool frameViewIsCurrentlyInLiveResize = frame->view() && frame->view()->
inLiveResize(); | |
| 194 if (frameViewIsCurrentlyInLiveResize) { | |
| 195 set(object, innerMap, layer, layoutSize, true); | |
| 196 restartTimer(); | |
| 197 m_liveResizeOptimizationIsActive = true; | |
| 198 return true; | |
| 199 } | |
| 200 if (m_liveResizeOptimizationIsActive) { | |
| 201 // Live resize has ended, paint in HQ and remove this object from th
e list. | |
| 202 removeLayer(object, innerMap, layer); | |
| 203 return false; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 if (layoutSize == image->size()) { | 181 if (layoutSize == image->size()) { |
| 208 // There is no scale in effect. If we had a scale in effect before, we c
an just remove this object from the list. | 182 // There is no scale in effect. If we had a scale in effect before, we c
an just remove this object from the list. |
| 209 removeLayer(object, innerMap, layer); | 183 removeLayer(object, innerMap, layer); |
| 210 return false; | 184 return false; |
| 211 } | 185 } |
| 212 | 186 |
| 213 // If an animated resize is active for this object, paint in low quality and
kick the timer ahead. | 187 // If an animated resize is active for this object, paint in low quality and
kick the timer ahead. |
| 214 if (objectIsResizing) { | 188 if (objectIsResizing) { |
| 215 bool sizesChanged = oldSize != layoutSize; | 189 bool sizesChanged = oldSize != layoutSize; |
| 216 set(object, innerMap, layer, layoutSize, sizesChanged); | 190 set(object, innerMap, layer, layoutSize, sizesChanged); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 234 } | 208 } |
| 235 // This object has been resized to two different sizes while the timer | 209 // This object has been resized to two different sizes while the timer |
| 236 // is active, so draw at low quality, set the flag for animated resizes and | 210 // is active, so draw at low quality, set the flag for animated resizes and |
| 237 // the object to the list for high quality redraw. | 211 // the object to the list for high quality redraw. |
| 238 set(object, innerMap, layer, layoutSize, true); | 212 set(object, innerMap, layer, layoutSize, true); |
| 239 restartTimer(); | 213 restartTimer(); |
| 240 return true; | 214 return true; |
| 241 } | 215 } |
| 242 | 216 |
| 243 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |