OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/painted_scrollbar_layer.h" | 5 #include "cc/layers/painted_scrollbar_layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 bool PaintedScrollbarLayer::AlwaysUseActiveTreeOpacity() const { | 73 bool PaintedScrollbarLayer::AlwaysUseActiveTreeOpacity() const { |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { | 77 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { |
78 return scrollbar_->Orientation(); | 78 return scrollbar_->Orientation(); |
79 } | 79 } |
80 | 80 |
| 81 int PaintedScrollbarLayer::MaxTextureSize() { |
| 82 DCHECK(layer_tree_host()); |
| 83 return layer_tree_host()->GetRendererCapabilities().max_texture_size; |
| 84 } |
| 85 |
| 86 float PaintedScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { |
| 87 // If the scaled bounds() is bigger than the max texture size of the |
| 88 // device, we need to clamp it by rescaling, since this is used |
| 89 // below to set the texture size. |
| 90 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); |
| 91 if (scaled_bounds.width() > MaxTextureSize() || |
| 92 scaled_bounds.height() > MaxTextureSize()) { |
| 93 if (bounds().width() > bounds().height()) |
| 94 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); |
| 95 else |
| 96 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); |
| 97 } |
| 98 return scale; |
| 99 } |
| 100 |
81 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 101 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
82 Layer::PushPropertiesTo(layer); | 102 Layer::PushPropertiesTo(layer); |
83 | 103 |
84 PaintedScrollbarLayerImpl* scrollbar_layer = | 104 PaintedScrollbarLayerImpl* scrollbar_layer = |
85 static_cast<PaintedScrollbarLayerImpl*>(layer); | 105 static_cast<PaintedScrollbarLayerImpl*>(layer); |
86 | 106 |
87 scrollbar_layer->SetScrollLayerId(scroll_layer_id_); | 107 scrollbar_layer->SetScrollLayerId(scroll_layer_id_); |
88 scrollbar_layer->set_internal_contents_scale_and_bounds( | 108 scrollbar_layer->set_internal_contents_scale_and_bounds( |
89 internal_contents_scale_, internal_content_bounds_); | 109 internal_contents_scale_, internal_content_bounds_); |
90 | 110 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 .layer_transforms_should_scale_layer_contents) { | 195 .layer_transforms_should_scale_layer_contents) { |
176 gfx::Transform transform; | 196 gfx::Transform transform; |
177 transform = draw_property_utils::ScreenSpaceTransform( | 197 transform = draw_property_utils::ScreenSpaceTransform( |
178 this, GetLayerTree()->property_trees()->transform_tree); | 198 this, GetLayerTree()->property_trees()->transform_tree); |
179 | 199 |
180 gfx::Vector2dF transform_scales = | 200 gfx::Vector2dF transform_scales = |
181 MathUtil::ComputeTransform2dScaleComponents(transform, scale); | 201 MathUtil::ComputeTransform2dScaleComponents(transform, scale); |
182 scale = std::max(transform_scales.x(), transform_scales.y()); | 202 scale = std::max(transform_scales.x(), transform_scales.y()); |
183 } | 203 } |
184 bool changed = false; | 204 bool changed = false; |
185 changed |= UpdateProperty(scale, &internal_contents_scale_); | 205 changed |= UpdateProperty(ClampScaleToMaxTextureSize(scale), |
| 206 &internal_contents_scale_); |
186 changed |= | 207 changed |= |
187 UpdateProperty(gfx::ScaleToCeiledSize(bounds(), internal_contents_scale_), | 208 UpdateProperty(gfx::ScaleToCeiledSize(bounds(), internal_contents_scale_), |
188 &internal_content_bounds_); | 209 &internal_content_bounds_); |
189 if (changed) { | 210 if (changed) { |
190 // If the content scale or bounds change, repaint. | 211 // If the content scale or bounds change, repaint. |
191 SetNeedsDisplay(); | 212 SetNeedsDisplay(); |
192 } | 213 } |
193 } | 214 } |
194 | 215 |
195 bool PaintedScrollbarLayer::Update() { | 216 bool PaintedScrollbarLayer::Update() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 304 |
284 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 305 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
285 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 306 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
286 // allocation and copying. | 307 // allocation and copying. |
287 skbitmap.setImmutable(); | 308 skbitmap.setImmutable(); |
288 | 309 |
289 return UIResourceBitmap(skbitmap); | 310 return UIResourceBitmap(skbitmap); |
290 } | 311 } |
291 | 312 |
292 } // namespace cc | 313 } // namespace cc |
OLD | NEW |