| 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 15 matching lines...) Expand all Loading... |
| 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 "config.h" | 31 #include "config.h" |
| 32 #include "core/layout/ImageQualityController.h" | 32 #include "core/layout/ImageQualityController.h" |
| 33 | 33 |
| 34 #include "core/frame/FrameView.h" | 34 #include "core/frame/FrameView.h" |
| 35 #include "core/frame/LocalFrame.h" | 35 #include "core/frame/LocalFrame.h" |
| 36 #include "platform/graphics/GraphicsContext.h" | |
| 37 | 36 |
| 38 namespace blink { | 37 namespace blink { |
| 39 | 38 |
| 40 static const double cLowQualityTimeThreshold = 0.500; // 500 ms | 39 static const double cLowQualityTimeThreshold = 0.500; // 500 ms |
| 41 | 40 |
| 42 static ImageQualityController* gImageQualityController = nullptr; | 41 static ImageQualityController* gImageQualityController = nullptr; |
| 43 | 42 |
| 44 ImageQualityController* ImageQualityController::imageQualityController() | 43 ImageQualityController* ImageQualityController::imageQualityController() |
| 45 { | 44 { |
| 46 if (!gImageQualityController) | 45 if (!gImageQualityController) |
| 47 gImageQualityController = new ImageQualityController; | 46 gImageQualityController = new ImageQualityController; |
| 48 | 47 |
| 49 return gImageQualityController; | 48 return gImageQualityController; |
| 50 } | 49 } |
| 51 | 50 |
| 52 void ImageQualityController::remove(LayoutObject* layoutObject) | 51 void ImageQualityController::remove(LayoutObject& layoutObject) |
| 53 { | 52 { |
| 54 if (gImageQualityController) { | 53 if (gImageQualityController) { |
| 55 gImageQualityController->objectDestroyed(layoutObject); | 54 gImageQualityController->objectDestroyed(layoutObject); |
| 56 if (gImageQualityController->isEmpty()) { | 55 if (gImageQualityController->isEmpty()) { |
| 57 delete gImageQualityController; | 56 delete gImageQualityController; |
| 58 gImageQualityController = nullptr; | 57 gImageQualityController = nullptr; |
| 59 } | 58 } |
| 60 } | 59 } |
| 61 } | 60 } |
| 62 | 61 |
| 63 bool ImageQualityController::has(const LayoutObject* layoutObject) | 62 bool ImageQualityController::has(const LayoutObject& layoutObject) |
| 64 { | 63 { |
| 65 return gImageQualityController && gImageQualityController->m_objectLayerSize
Map.contains(layoutObject); | 64 return gImageQualityController && gImageQualityController->m_objectLayerSize
Map.contains(&layoutObject); |
| 66 } | 65 } |
| 67 | 66 |
| 68 InterpolationQuality ImageQualityController::chooseInterpolationQuality(Graphics
Context* context, const LayoutObject* object, Image* image, const void* layer, c
onst LayoutSize& layoutSize) | 67 InterpolationQuality ImageQualityController::chooseInterpolationQuality(const La
youtObject& object, Image* image, const void* layer, const LayoutSize& layoutSiz
e) |
| 69 { | 68 { |
| 70 if (object->style()->imageRendering() == ImageRenderingPixelated) | 69 if (object.style()->imageRendering() == ImageRenderingPixelated) |
| 71 return InterpolationNone; | 70 return InterpolationNone; |
| 72 | 71 |
| 73 if (InterpolationDefault == InterpolationLow) | 72 if (InterpolationDefault == InterpolationLow) |
| 74 return InterpolationLow; | 73 return InterpolationLow; |
| 75 | 74 |
| 76 if (shouldPaintAtLowQuality(context, object, image, layer, layoutSize)) | 75 if (shouldPaintAtLowQuality(object, image, layer, layoutSize)) |
| 77 return InterpolationLow; | 76 return InterpolationLow; |
| 78 | 77 |
| 79 // For images that are potentially animated we paint them at medium quality. | 78 // For images that are potentially animated we paint them at medium quality. |
| 80 if (image && image->maybeAnimated()) | 79 if (image && image->maybeAnimated()) |
| 81 return InterpolationMedium; | 80 return InterpolationMedium; |
| 82 | 81 |
| 83 return InterpolationDefault; | 82 return InterpolationDefault; |
| 84 } | 83 } |
| 85 | 84 |
| 86 ImageQualityController::~ImageQualityController() | 85 ImageQualityController::~ImageQualityController() |
| 87 { | 86 { |
| 88 // This will catch users of ImageQualityController that forget to call clean
Up. | 87 // This will catch users of ImageQualityController that forget to call clean
Up. |
| 89 ASSERT(!gImageQualityController || gImageQualityController->isEmpty()); | 88 ASSERT(!gImageQualityController || gImageQualityController->isEmpty()); |
| 90 } | 89 } |
| 91 | 90 |
| 92 ImageQualityController::ImageQualityController() | 91 ImageQualityController::ImageQualityController() |
| 93 : m_timer(adoptPtr(new Timer<ImageQualityController>(this, &ImageQualityCont
roller::highQualityRepaintTimerFired))) | 92 : m_timer(adoptPtr(new Timer<ImageQualityController>(this, &ImageQualityCont
roller::highQualityRepaintTimerFired))) |
| 94 , m_animatedResizeIsActive(false) | 93 , m_animatedResizeIsActive(false) |
| 95 , m_liveResizeOptimizationIsActive(false) | 94 , m_liveResizeOptimizationIsActive(false) |
| 96 { | 95 { |
| 97 } | 96 } |
| 98 | 97 |
| 99 void ImageQualityController::setTimer(Timer<ImageQualityController>* newTimer) | 98 void ImageQualityController::setTimer(Timer<ImageQualityController>* newTimer) |
| 100 { | 99 { |
| 101 m_timer = adoptPtr(newTimer); | 100 m_timer = adoptPtr(newTimer); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void ImageQualityController::removeLayer(const LayoutObject* object, LayerSizeMa
p* innerMap, const void* layer) | 103 void ImageQualityController::removeLayer(const LayoutObject& object, LayerSizeMa
p* innerMap, const void* layer) |
| 105 { | 104 { |
| 106 if (innerMap) { | 105 if (innerMap) { |
| 107 innerMap->remove(layer); | 106 innerMap->remove(layer); |
| 108 if (innerMap->isEmpty()) | 107 if (innerMap->isEmpty()) |
| 109 objectDestroyed(object); | 108 objectDestroyed(object); |
| 110 } | 109 } |
| 111 } | 110 } |
| 112 | 111 |
| 113 void ImageQualityController::set(const LayoutObject* object, LayerSizeMap* inner
Map, const void* layer, const LayoutSize& size) | 112 void ImageQualityController::set(const LayoutObject& object, LayerSizeMap* inner
Map, const void* layer, const LayoutSize& size) |
| 114 { | 113 { |
| 115 if (innerMap) { | 114 if (innerMap) { |
| 116 innerMap->set(layer, size); | 115 innerMap->set(layer, size); |
| 117 } else { | 116 } else { |
| 118 LayerSizeMap newInnerMap; | 117 LayerSizeMap newInnerMap; |
| 119 newInnerMap.set(layer, size); | 118 newInnerMap.set(layer, size); |
| 120 m_objectLayerSizeMap.set(object, newInnerMap); | 119 m_objectLayerSizeMap.set(&object, newInnerMap); |
| 121 } | 120 } |
| 122 } | 121 } |
| 123 | 122 |
| 124 void ImageQualityController::objectDestroyed(const LayoutObject* object) | 123 void ImageQualityController::objectDestroyed(const LayoutObject& object) |
| 125 { | 124 { |
| 126 m_objectLayerSizeMap.remove(object); | 125 m_objectLayerSizeMap.remove(&object); |
| 127 if (m_objectLayerSizeMap.isEmpty()) { | 126 if (m_objectLayerSizeMap.isEmpty()) { |
| 128 m_animatedResizeIsActive = false; | 127 m_animatedResizeIsActive = false; |
| 129 m_timer->stop(); | 128 m_timer->stop(); |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 void ImageQualityController::highQualityRepaintTimerFired(Timer<ImageQualityCont
roller>*) | 132 void ImageQualityController::highQualityRepaintTimerFired(Timer<ImageQualityCont
roller>*) |
| 134 { | 133 { |
| 135 if (!m_animatedResizeIsActive && !m_liveResizeOptimizationIsActive) | 134 if (!m_animatedResizeIsActive && !m_liveResizeOptimizationIsActive) |
| 136 return; | 135 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 149 } | 148 } |
| 150 | 149 |
| 151 m_liveResizeOptimizationIsActive = false; | 150 m_liveResizeOptimizationIsActive = false; |
| 152 } | 151 } |
| 153 | 152 |
| 154 void ImageQualityController::restartTimer() | 153 void ImageQualityController::restartTimer() |
| 155 { | 154 { |
| 156 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); | 155 m_timer->startOneShot(cLowQualityTimeThreshold, BLINK_FROM_HERE); |
| 157 } | 156 } |
| 158 | 157 |
| 159 bool ImageQualityController::shouldPaintAtLowQuality(GraphicsContext* context, c
onst LayoutObject* object, Image* image, const void *layer, const LayoutSize& la
youtSize) | 158 bool ImageQualityController::shouldPaintAtLowQuality(const LayoutObject& object,
Image* image, const void *layer, const LayoutSize& layoutSize) |
| 160 { | 159 { |
| 161 // If the image is not a bitmap image, then none of this is relevant and we
just paint at high | 160 // If the image is not a bitmap image, then none of this is relevant and we
just paint at high |
| 162 // quality. | 161 // quality. |
| 163 if (!image || !image->isBitmapImage()) | 162 if (!image || !image->isBitmapImage()) |
| 164 return false; | 163 return false; |
| 165 | 164 |
| 166 if (!layer) | 165 if (!layer) |
| 167 return false; | 166 return false; |
| 168 | 167 |
| 169 if (object->style()->imageRendering() == ImageRenderingOptimizeContrast) | 168 if (object.style()->imageRendering() == ImageRenderingOptimizeContrast) |
| 170 return true; | 169 return true; |
| 171 | 170 |
| 172 // Look ourselves up in the hashtables. | 171 // Look ourselves up in the hashtables. |
| 173 ObjectLayerSizeMap::iterator i = m_objectLayerSizeMap.find(object); | 172 ObjectLayerSizeMap::iterator i = m_objectLayerSizeMap.find(&object); |
| 174 LayerSizeMap* innerMap = i != m_objectLayerSizeMap.end() ? &i->value : 0; | 173 LayerSizeMap* innerMap = i != m_objectLayerSizeMap.end() ? &i->value : 0; |
| 175 LayoutSize oldSize; | 174 LayoutSize oldSize; |
| 176 bool isFirstResize = true; | 175 bool isFirstResize = true; |
| 177 if (innerMap) { | 176 if (innerMap) { |
| 178 LayerSizeMap::iterator j = innerMap->find(layer); | 177 LayerSizeMap::iterator j = innerMap->find(layer); |
| 179 if (j != innerMap->end()) { | 178 if (j != innerMap->end()) { |
| 180 isFirstResize = false; | 179 isFirstResize = false; |
| 181 oldSize = j->value; | 180 oldSize = j->value; |
| 182 } | 181 } |
| 183 } | 182 } |
| 184 | 183 |
| 185 // If the containing FrameView is being resized, paint at low quality until
resizing is finished. | 184 // If the containing FrameView is being resized, paint at low quality until
resizing is finished. |
| 186 if (LocalFrame* frame = object->document().frame()) { | 185 if (LocalFrame* frame = object.document().frame()) { |
| 187 bool frameViewIsCurrentlyInLiveResize = frame->view() && frame->view()->
inLiveResize(); | 186 bool frameViewIsCurrentlyInLiveResize = frame->view() && frame->view()->
inLiveResize(); |
| 188 if (frameViewIsCurrentlyInLiveResize) { | 187 if (frameViewIsCurrentlyInLiveResize) { |
| 189 set(object, innerMap, layer, layoutSize); | 188 set(object, innerMap, layer, layoutSize); |
| 190 restartTimer(); | 189 restartTimer(); |
| 191 m_liveResizeOptimizationIsActive = true; | 190 m_liveResizeOptimizationIsActive = true; |
| 192 return true; | 191 return true; |
| 193 } | 192 } |
| 194 if (m_liveResizeOptimizationIsActive) { | 193 if (m_liveResizeOptimizationIsActive) { |
| 195 // Live resize has ended, paint in HQ and remove this object from th
e list. | 194 // Live resize has ended, paint in HQ and remove this object from th
e list. |
| 196 removeLayer(object, innerMap, layer); | 195 removeLayer(object, innerMap, layer); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // This object has been resized to two different sizes while the timer | 228 // This object has been resized to two different sizes while the timer |
| 230 // is active, so draw at low quality, set the flag for animated resizes and | 229 // is active, so draw at low quality, set the flag for animated resizes and |
| 231 // the object to the list for high quality redraw. | 230 // the object to the list for high quality redraw. |
| 232 set(object, innerMap, layer, layoutSize); | 231 set(object, innerMap, layer, layoutSize); |
| 233 m_animatedResizeIsActive = true; | 232 m_animatedResizeIsActive = true; |
| 234 restartTimer(); | 233 restartTimer(); |
| 235 return true; | 234 return true; |
| 236 } | 235 } |
| 237 | 236 |
| 238 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |