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> | |
8 | |
7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "cc/base/math_util.h" | |
10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 13 #include "cc/layers/painted_scrollbar_layer_impl.h" |
11 #include "cc/resources/ui_resource_bitmap.h" | 14 #include "cc/resources/ui_resource_bitmap.h" |
12 #include "cc/trees/layer_tree_host.h" | 15 #include "cc/trees/layer_tree_host.h" |
13 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
14 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
15 #include "skia/ext/refptr.h" | 18 #include "skia/ext/refptr.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
18 #include "third_party/skia/include/core/SkSize.h" | 21 #include "third_party/skia/include/core/SkSize.h" |
22 #include "ui/gfx/geometry/size_conversions.h" | |
19 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
20 | 24 |
21 namespace cc { | 25 namespace cc { |
22 | 26 |
23 scoped_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl( | 27 scoped_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl( |
24 LayerTreeImpl* tree_impl) { | 28 LayerTreeImpl* tree_impl) { |
25 return PaintedScrollbarLayerImpl::Create( | 29 return PaintedScrollbarLayerImpl::Create( |
26 tree_impl, id(), scrollbar_->Orientation()); | 30 tree_impl, id(), scrollbar_->Orientation()); |
27 } | 31 } |
28 | 32 |
29 scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( | 33 scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( |
30 scoped_ptr<Scrollbar> scrollbar, | 34 scoped_ptr<Scrollbar> scrollbar, |
31 int scroll_layer_id) { | 35 int scroll_layer_id) { |
32 return make_scoped_refptr( | 36 return make_scoped_refptr( |
33 new PaintedScrollbarLayer(scrollbar.Pass(), scroll_layer_id)); | 37 new PaintedScrollbarLayer(scrollbar.Pass(), scroll_layer_id)); |
34 } | 38 } |
35 | 39 |
36 PaintedScrollbarLayer::PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, | 40 PaintedScrollbarLayer::PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, |
37 int scroll_layer_id) | 41 int scroll_layer_id) |
38 : scrollbar_(scrollbar.Pass()), | 42 : scrollbar_(scrollbar.Pass()), |
39 scroll_layer_id_(scroll_layer_id), | 43 scroll_layer_id_(scroll_layer_id), |
40 clip_layer_id_(Layer::INVALID_ID), | 44 clip_layer_id_(Layer::INVALID_ID), |
45 internal_content_scale_(0.f), | |
41 thumb_thickness_(scrollbar_->ThumbThickness()), | 46 thumb_thickness_(scrollbar_->ThumbThickness()), |
42 thumb_length_(scrollbar_->ThumbLength()), | 47 thumb_length_(scrollbar_->ThumbLength()), |
43 is_overlay_(scrollbar_->IsOverlay()), | 48 is_overlay_(scrollbar_->IsOverlay()), |
44 has_thumb_(scrollbar_->HasThumb()) { | 49 has_thumb_(scrollbar_->HasThumb()) { |
45 if (!scrollbar_->IsOverlay()) | 50 if (!scrollbar_->IsOverlay()) |
46 SetShouldScrollOnMainThread(true); | 51 SetShouldScrollOnMainThread(true); |
47 } | 52 } |
48 | 53 |
49 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} | 54 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} |
50 | 55 |
(...skipping 24 matching lines...) Expand all Loading... | |
75 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { | 80 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { |
76 return scrollbar_->Orientation(); | 81 return scrollbar_->Orientation(); |
77 } | 82 } |
78 | 83 |
79 int PaintedScrollbarLayer::MaxTextureSize() { | 84 int PaintedScrollbarLayer::MaxTextureSize() { |
80 DCHECK(layer_tree_host()); | 85 DCHECK(layer_tree_host()); |
81 return layer_tree_host()->GetRendererCapabilities().max_texture_size; | 86 return layer_tree_host()->GetRendererCapabilities().max_texture_size; |
82 } | 87 } |
83 | 88 |
84 float PaintedScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { | 89 float PaintedScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { |
85 // If the scaled content_bounds() is bigger than the max texture size of the | 90 // If the scaled bounds() is bigger than the max texture size of the |
86 // device, we need to clamp it by rescaling, since content_bounds() is used | 91 // device, we need to clamp it by rescaling, since this is used |
87 // below to set the texture size. | 92 // below to set the texture size. |
88 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); | 93 gfx::Size scaled_bounds = |
94 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale, scale)); | |
89 if (scaled_bounds.width() > MaxTextureSize() || | 95 if (scaled_bounds.width() > MaxTextureSize() || |
90 scaled_bounds.height() > MaxTextureSize()) { | 96 scaled_bounds.height() > MaxTextureSize()) { |
91 if (scaled_bounds.width() > scaled_bounds.height()) | 97 if (scaled_bounds.width() > scaled_bounds.height()) |
92 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); | 98 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); |
93 else | 99 else |
94 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); | 100 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); |
95 } | 101 } |
96 return scale; | 102 return scale; |
97 } | 103 } |
98 | 104 |
99 void PaintedScrollbarLayer::CalculateContentsScale( | |
100 float ideal_contents_scale, | |
101 float* contents_scale_x, | |
102 float* contents_scale_y, | |
103 gfx::Size* content_bounds) { | |
104 ContentsScalingLayer::CalculateContentsScale( | |
105 ClampScaleToMaxTextureSize(ideal_contents_scale), | |
106 contents_scale_x, | |
107 contents_scale_y, | |
108 content_bounds); | |
109 } | |
110 | |
111 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 105 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
112 ContentsScalingLayer::PushPropertiesTo(layer); | 106 Layer::PushPropertiesTo(layer); |
113 | 107 |
114 PushScrollClipPropertiesTo(layer); | 108 PushScrollClipPropertiesTo(layer); |
115 | 109 |
116 PaintedScrollbarLayerImpl* scrollbar_layer = | 110 PaintedScrollbarLayerImpl* scrollbar_layer = |
117 static_cast<PaintedScrollbarLayerImpl*>(layer); | 111 static_cast<PaintedScrollbarLayerImpl*>(layer); |
118 | 112 |
113 scrollbar_layer->set_internal_content_scale_and_bounds( | |
114 internal_content_scale_, internal_content_bounds_); | |
115 | |
119 scrollbar_layer->SetThumbThickness(thumb_thickness_); | 116 scrollbar_layer->SetThumbThickness(thumb_thickness_); |
120 scrollbar_layer->SetThumbLength(thumb_length_); | 117 scrollbar_layer->SetThumbLength(thumb_length_); |
121 if (orientation() == HORIZONTAL) { | 118 if (orientation() == HORIZONTAL) { |
122 scrollbar_layer->SetTrackStart( | 119 scrollbar_layer->SetTrackStart( |
123 track_rect_.x() - location_.x()); | 120 track_rect_.x() - location_.x()); |
124 scrollbar_layer->SetTrackLength(track_rect_.width()); | 121 scrollbar_layer->SetTrackLength(track_rect_.width()); |
125 } else { | 122 } else { |
126 scrollbar_layer->SetTrackStart( | 123 scrollbar_layer->SetTrackStart( |
127 track_rect_.y() - location_.y()); | 124 track_rect_.y() - location_.y()); |
128 scrollbar_layer->SetTrackLength(track_rect_.height()); | 125 scrollbar_layer->SetTrackLength(track_rect_.height()); |
(...skipping 24 matching lines...) Expand all Loading... | |
153 } | 150 } |
154 | 151 |
155 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { | 152 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
156 // When the LTH is set to null or has changed, then this layer should remove | 153 // When the LTH is set to null or has changed, then this layer should remove |
157 // all of its associated resources. | 154 // all of its associated resources. |
158 if (!host || host != layer_tree_host()) { | 155 if (!host || host != layer_tree_host()) { |
159 track_resource_ = nullptr; | 156 track_resource_ = nullptr; |
160 thumb_resource_ = nullptr; | 157 thumb_resource_ = nullptr; |
161 } | 158 } |
162 | 159 |
163 ContentsScalingLayer::SetLayerTreeHost(host); | 160 Layer::SetLayerTreeHost(host); |
164 } | 161 } |
165 | 162 |
166 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( | 163 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( |
167 const gfx::Rect& layer_rect) const { | 164 const gfx::Rect& layer_rect) const { |
168 // Don't intersect with the bounds as in LayerRectToContentRect() because | 165 // Don't intersect with the bounds as in LayerRectToContentRect() because |
169 // layer_rect here might be in coordinates of the containing layer. | 166 // layer_rect here might be in coordinates of the containing layer. |
170 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( | 167 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( |
171 layer_rect, contents_scale_x(), contents_scale_y()); | 168 layer_rect, internal_content_scale_, internal_content_scale_); |
172 // We should never return a rect bigger than the content_bounds(). | 169 // We should never return a rect bigger than the content bounds. |
173 gfx::Size clamped_size = expanded_rect.size(); | 170 gfx::Size clamped_size = expanded_rect.size(); |
174 clamped_size.SetToMin(content_bounds()); | 171 clamped_size.SetToMin(internal_content_bounds_); |
175 expanded_rect.set_size(clamped_size); | 172 expanded_rect.set_size(clamped_size); |
176 return expanded_rect; | 173 return expanded_rect; |
177 } | 174 } |
178 | 175 |
179 gfx::Rect PaintedScrollbarLayer::OriginThumbRect() const { | 176 gfx::Rect PaintedScrollbarLayer::OriginThumbRect() const { |
180 gfx::Size thumb_size; | 177 gfx::Size thumb_size; |
181 if (orientation() == HORIZONTAL) { | 178 if (orientation() == HORIZONTAL) { |
182 thumb_size = | 179 thumb_size = |
183 gfx::Size(scrollbar_->ThumbLength(), scrollbar_->ThumbThickness()); | 180 gfx::Size(scrollbar_->ThumbLength(), scrollbar_->ThumbThickness()); |
184 } else { | 181 } else { |
(...skipping 10 matching lines...) Expand all Loading... | |
195 UpdateProperty(scrollbar_->HasThumb(), &has_thumb_); | 192 UpdateProperty(scrollbar_->HasThumb(), &has_thumb_); |
196 if (has_thumb_) { | 193 if (has_thumb_) { |
197 UpdateProperty(scrollbar_->ThumbThickness(), &thumb_thickness_); | 194 UpdateProperty(scrollbar_->ThumbThickness(), &thumb_thickness_); |
198 UpdateProperty(scrollbar_->ThumbLength(), &thumb_length_); | 195 UpdateProperty(scrollbar_->ThumbLength(), &thumb_length_); |
199 } else { | 196 } else { |
200 UpdateProperty(0, &thumb_thickness_); | 197 UpdateProperty(0, &thumb_thickness_); |
201 UpdateProperty(0, &thumb_length_); | 198 UpdateProperty(0, &thumb_length_); |
202 } | 199 } |
203 } | 200 } |
204 | 201 |
202 void PaintedScrollbarLayer::UpdateInternalContentScale() { | |
203 float scale = layer_tree_host()->device_scale_factor(); | |
enne (OOO)
2015/02/11 21:41:59
This is a change in behavior from ContentsScalingL
| |
204 if (layer_tree_host() | |
205 ->settings() | |
206 .layer_transforms_should_scale_layer_contents) { | |
207 gfx::Vector2dF transform_scales = | |
208 MathUtil::ComputeTransform2dScaleComponents(draw_transform(), scale); | |
209 scale = std::max(transform_scales.x(), transform_scales.y()); | |
210 } | |
211 bool changed = false; | |
212 changed |= UpdateProperty(ClampScaleToMaxTextureSize(scale), | |
213 &internal_content_scale_); | |
214 changed |= UpdateProperty( | |
215 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), internal_content_scale_)), | |
216 &internal_content_bounds_); | |
217 if (changed) { | |
218 // If the content scale or bounds change, repaint. | |
219 SetNeedsDisplay(); | |
enne (OOO)
2015/02/11 21:41:58
This replicates ContentsScalingLayer::Update, alth
| |
220 } | |
221 } | |
222 | |
205 bool PaintedScrollbarLayer::Update(ResourceUpdateQueue* queue, | 223 bool PaintedScrollbarLayer::Update(ResourceUpdateQueue* queue, |
206 const OcclusionTracker<Layer>* occlusion) { | 224 const OcclusionTracker<Layer>* occlusion) { |
225 { | |
226 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | |
227 true); | |
228 Layer::Update(queue, occlusion); | |
229 UpdateInternalContentScale(); | |
enne (OOO)
2015/02/11 21:41:59
As UpdateInternalContentScale can invalidate, it n
| |
230 } | |
231 | |
207 UpdateThumbAndTrackGeometry(); | 232 UpdateThumbAndTrackGeometry(); |
208 | 233 |
209 gfx::Rect track_layer_rect = gfx::Rect(location_, bounds()); | 234 gfx::Rect track_layer_rect = gfx::Rect(location_, bounds()); |
210 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( | 235 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( |
211 track_layer_rect); | 236 track_layer_rect); |
212 | 237 |
213 bool updated = false; | 238 bool updated = false; |
214 | 239 |
215 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) { | 240 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) { |
216 if (track_resource_) { | 241 if (track_resource_) { |
217 track_resource_ = nullptr; | 242 track_resource_ = nullptr; |
218 thumb_resource_ = nullptr; | 243 thumb_resource_ = nullptr; |
219 SetNeedsPushProperties(); | 244 SetNeedsPushProperties(); |
220 updated = true; | 245 updated = true; |
221 } | 246 } |
222 return updated; | 247 return updated; |
223 } | 248 } |
224 | 249 |
225 if (!has_thumb_ && thumb_resource_) { | 250 if (!has_thumb_ && thumb_resource_) { |
226 thumb_resource_ = nullptr; | 251 thumb_resource_ = nullptr; |
227 SetNeedsPushProperties(); | 252 SetNeedsPushProperties(); |
228 } | 253 updated = true; |
enne (OOO)
2015/02/11 21:41:59
I don't know why this didn't set updated, but it s
| |
229 | |
230 { | |
231 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | |
232 true); | |
233 ContentsScalingLayer::Update(queue, occlusion); | |
234 } | 254 } |
235 | 255 |
236 if (update_rect_.IsEmpty() && track_resource_) | 256 if (update_rect_.IsEmpty() && track_resource_) |
237 return updated; | 257 return updated; |
238 | 258 |
239 track_resource_ = ScopedUIResource::Create( | 259 track_resource_ = ScopedUIResource::Create( |
240 layer_tree_host(), | 260 layer_tree_host(), |
241 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); | 261 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); |
242 | 262 |
243 gfx::Rect thumb_layer_rect = OriginThumbRect(); | 263 gfx::Rect thumb_layer_rect = OriginThumbRect(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 | 305 |
286 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 306 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
287 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 307 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
288 // allocation and copying. | 308 // allocation and copying. |
289 skbitmap.setImmutable(); | 309 skbitmap.setImmutable(); |
290 | 310 |
291 return UIResourceBitmap(skbitmap); | 311 return UIResourceBitmap(skbitmap); |
292 } | 312 } |
293 | 313 |
294 } // namespace cc | 314 } // namespace cc |
OLD | NEW |