OLD | NEW |
1 | 1 |
2 // Copyright 2012 The Chromium Authors. All rights reserved. | 2 // Copyright 2012 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "cc/layers/scrollbar_layer.h" | 6 #include "cc/layers/scrollbar_layer.h" |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "cc/layers/scrollbar_layer_impl.h" | 11 #include "cc/layers/scrollbar_layer_impl.h" |
12 #include "cc/resources/caching_bitmap_content_layer_updater.h" | 12 #include "cc/resources/caching_bitmap_content_layer_updater.h" |
13 #include "cc/resources/layer_painter.h" | 13 #include "cc/resources/layer_painter.h" |
14 #include "cc/resources/prioritized_resource.h" | 14 #include "cc/resources/prioritized_resource.h" |
15 #include "cc/resources/resource_update_queue.h" | 15 #include "cc/resources/resource_update_queue.h" |
16 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
17 #include "ui/gfx/rect_conversions.h" | 17 #include "ui/gfx/rect_conversions.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 scoped_ptr<LayerImpl> ScrollbarLayer::CreateLayerImpl( | 21 scoped_ptr<LayerImpl> ScrollbarLayer::CreateLayerImpl( |
22 LayerTreeImpl* tree_impl) { | 22 LayerTreeImpl* tree_impl) { |
23 return ScrollbarLayerImpl::Create( | 23 return ScrollbarLayerImpl::Create( |
24 tree_impl, id(), scrollbar_->Orientation()).PassAs<LayerImpl>(); | 24 tree_impl, id(), scrollbar_->Orientation(), is_solid_color_) |
| 25 .PassAs<LayerImpl>(); |
25 } | 26 } |
26 | 27 |
27 scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create( | 28 scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create( |
28 scoped_ptr<Scrollbar> scrollbar, | 29 scoped_ptr<Scrollbar> scrollbar, |
29 int scroll_layer_id) { | 30 int scroll_layer_id, |
| 31 bool is_solid_color) { |
30 return make_scoped_refptr(new ScrollbarLayer(scrollbar.Pass(), | 32 return make_scoped_refptr(new ScrollbarLayer(scrollbar.Pass(), |
31 scroll_layer_id)); | 33 scroll_layer_id, |
| 34 is_solid_color)); |
32 } | 35 } |
33 | 36 |
34 ScrollbarLayer::ScrollbarLayer( | 37 ScrollbarLayer::ScrollbarLayer( |
35 scoped_ptr<Scrollbar> scrollbar, | 38 scoped_ptr<Scrollbar> scrollbar, |
36 int scroll_layer_id) | 39 int scroll_layer_id, |
| 40 bool is_solid_color) |
37 : scrollbar_(scrollbar.Pass()), | 41 : scrollbar_(scrollbar.Pass()), |
38 scroll_layer_id_(scroll_layer_id), | 42 scroll_layer_id_(scroll_layer_id), |
| 43 is_solid_color_(is_solid_color), |
39 texture_format_(GL_INVALID_ENUM) { | 44 texture_format_(GL_INVALID_ENUM) { |
40 if (!scrollbar_->IsOverlay()) | 45 if (!scrollbar_->IsOverlay()) |
41 SetShouldScrollOnMainThread(true); | 46 SetShouldScrollOnMainThread(true); |
42 } | 47 } |
43 | 48 |
44 ScrollbarLayer::~ScrollbarLayer() {} | 49 ScrollbarLayer::~ScrollbarLayer() {} |
45 | 50 |
46 void ScrollbarLayer::SetScrollLayerId(int id) { | 51 void ScrollbarLayer::SetScrollLayerId(int id) { |
47 if (id == scroll_layer_id_) | 52 if (id == scroll_layer_id_) |
48 return; | 53 return; |
49 | 54 |
50 scroll_layer_id_ = id; | 55 scroll_layer_id_ = id; |
51 SetNeedsFullTreeSync(); | 56 SetNeedsFullTreeSync(); |
52 } | 57 } |
53 | 58 |
54 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const { | 59 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const { |
55 return scrollbar_->IsOverlay(); | 60 return scrollbar_->IsOverlay(); |
56 } | 61 } |
57 | 62 |
58 ScrollbarOrientation ScrollbarLayer::Orientation() const { | 63 ScrollbarOrientation ScrollbarLayer::Orientation() const { |
59 return scrollbar_->Orientation(); | 64 return scrollbar_->Orientation(); |
60 } | 65 } |
61 | 66 |
62 int ScrollbarLayer::MaxTextureSize() { | 67 int ScrollbarLayer::MaxTextureSize() { |
63 DCHECK(layer_tree_host()); | 68 DCHECK(layer_tree_host()); |
64 return layer_tree_host()->GetRendererCapabilities().max_texture_size; | 69 return layer_tree_host()->GetRendererCapabilities().max_texture_size; |
65 } | 70 } |
66 | 71 |
67 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { | 72 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { |
68 if (layer_tree_host()->settings().solid_color_scrollbars) | 73 if (is_solid_color()) |
69 return scale; | 74 return scale; |
70 | 75 |
71 // If the scaled content_bounds() is bigger than the max texture size of the | 76 // If the scaled content_bounds() is bigger than the max texture size of the |
72 // device, we need to clamp it by rescaling, since content_bounds() is used | 77 // device, we need to clamp it by rescaling, since content_bounds() is used |
73 // below to set the texture size. | 78 // below to set the texture size. |
74 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); | 79 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); |
75 if (scaled_bounds.width() > MaxTextureSize() || | 80 if (scaled_bounds.width() > MaxTextureSize() || |
76 scaled_bounds.height() > MaxTextureSize()) { | 81 scaled_bounds.height() > MaxTextureSize()) { |
77 if (scaled_bounds.width() > scaled_bounds.height()) | 82 if (scaled_bounds.width() > scaled_bounds.height()) |
78 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); | 83 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); |
(...skipping 18 matching lines...) Expand all Loading... |
97 contents_scale_x, | 102 contents_scale_x, |
98 contents_scale_y, | 103 contents_scale_y, |
99 content_bounds); | 104 content_bounds); |
100 } | 105 } |
101 | 106 |
102 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 107 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
103 ContentsScalingLayer::PushPropertiesTo(layer); | 108 ContentsScalingLayer::PushPropertiesTo(layer); |
104 | 109 |
105 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); | 110 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); |
106 | 111 |
107 if (layer_tree_host() && | 112 if (layer_tree_host() && is_solid_color()) { |
108 layer_tree_host()->settings().solid_color_scrollbars) { | |
109 int thickness_override = | 113 int thickness_override = |
110 layer_tree_host()->settings().solid_color_scrollbar_thickness_dip; | 114 layer_tree_host()->settings().solid_color_scrollbar_thickness_dip; |
111 if (thickness_override != -1) { | 115 if (thickness_override != -1) { |
112 scrollbar_layer->set_thumb_thickness(thickness_override); | 116 scrollbar_layer->set_thumb_thickness(thickness_override); |
113 } else { | 117 } else { |
114 if (Orientation() == HORIZONTAL) | 118 if (Orientation() == HORIZONTAL) |
115 scrollbar_layer->set_thumb_thickness(bounds().height()); | 119 scrollbar_layer->set_thumb_thickness(bounds().height()); |
116 else | 120 else |
117 scrollbar_layer->set_thumb_thickness(bounds().width()); | 121 scrollbar_layer->set_thumb_thickness(bounds().width()); |
118 } | 122 } |
119 } else { | 123 } else { |
120 scrollbar_layer->set_thumb_thickness(thumb_thickness_); | 124 scrollbar_layer->set_thumb_thickness(thumb_thickness_); |
121 } | 125 } |
122 scrollbar_layer->set_thumb_length(thumb_length_); | 126 scrollbar_layer->set_thumb_length(thumb_length_); |
123 if (Orientation() == HORIZONTAL) { | 127 if (Orientation() == HORIZONTAL) { |
124 scrollbar_layer->set_track_start(track_rect_.x()); | 128 scrollbar_layer->set_track_start(track_rect_.x()); |
125 scrollbar_layer->set_track_length(track_rect_.width()); | 129 scrollbar_layer->set_track_length(track_rect_.width()); |
126 } else { | 130 } else { |
127 scrollbar_layer->set_track_start(track_rect_.y()); | 131 scrollbar_layer->set_track_start(track_rect_.y()); |
128 scrollbar_layer->set_track_length(track_rect_.height()); | 132 scrollbar_layer->set_track_length(track_rect_.height()); |
129 } | 133 } |
| 134 scrollbar_layer->set_is_solid_color(is_solid_color()); |
130 | 135 |
131 if (track_ && track_->texture()->have_backing_texture()) | 136 if (track_ && track_->texture()->have_backing_texture()) |
132 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id()); | 137 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id()); |
133 else | 138 else |
134 scrollbar_layer->set_track_resource_id(0); | 139 scrollbar_layer->set_track_resource_id(0); |
135 | 140 |
136 if (thumb_ && thumb_->texture()->have_backing_texture()) | 141 if (thumb_ && thumb_->texture()->have_backing_texture()) |
137 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id()); | 142 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id()); |
138 else | 143 else |
139 scrollbar_layer->set_thumb_resource_id(0); | 144 scrollbar_layer->set_thumb_resource_id(0); |
(...skipping 27 matching lines...) Expand all Loading... |
167 gfx::RectF* opaque) OVERRIDE { | 172 gfx::RectF* opaque) OVERRIDE { |
168 scrollbar_->PaintPart(canvas, part_, content_rect); | 173 scrollbar_->PaintPart(canvas, part_, content_rect); |
169 } | 174 } |
170 | 175 |
171 private: | 176 private: |
172 Scrollbar* scrollbar_; | 177 Scrollbar* scrollbar_; |
173 ScrollbarPart part_; | 178 ScrollbarPart part_; |
174 }; | 179 }; |
175 | 180 |
176 void ScrollbarLayer::CreateUpdaterIfNeeded() { | 181 void ScrollbarLayer::CreateUpdaterIfNeeded() { |
177 if (layer_tree_host()->settings().solid_color_scrollbars) | 182 if (is_solid_color()) |
178 return; | 183 return; |
179 | 184 |
180 texture_format_ = | 185 texture_format_ = |
181 layer_tree_host()->GetRendererCapabilities().best_texture_format; | 186 layer_tree_host()->GetRendererCapabilities().best_texture_format; |
182 | 187 |
183 if (!track_updater_.get()) { | 188 if (!track_updater_.get()) { |
184 track_updater_ = CachingBitmapContentLayerUpdater::Create( | 189 track_updater_ = CachingBitmapContentLayerUpdater::Create( |
185 scoped_ptr<LayerPainter>( | 190 scoped_ptr<LayerPainter>( |
186 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) | 191 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) |
187 .Pass(), | 192 .Pass(), |
(...skipping 16 matching lines...) Expand all Loading... |
204 if (!thumb_ && scrollbar_->HasThumb()) { | 209 if (!thumb_ && scrollbar_->HasThumb()) { |
205 thumb_ = thumb_updater_->CreateResource( | 210 thumb_ = thumb_updater_->CreateResource( |
206 layer_tree_host()->contents_texture_manager()); | 211 layer_tree_host()->contents_texture_manager()); |
207 } | 212 } |
208 } | 213 } |
209 | 214 |
210 void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, | 215 void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, |
211 LayerUpdater::Resource* resource, | 216 LayerUpdater::Resource* resource, |
212 gfx::Rect rect, | 217 gfx::Rect rect, |
213 ResourceUpdateQueue* queue) { | 218 ResourceUpdateQueue* queue) { |
214 if (layer_tree_host()->settings().solid_color_scrollbars) | 219 if (is_solid_color()) |
215 return; | 220 return; |
216 | 221 |
217 // Skip painting and uploading if there are no invalidations and | 222 // Skip painting and uploading if there are no invalidations and |
218 // we already have valid texture data. | 223 // we already have valid texture data. |
219 if (resource->texture()->have_backing_texture() && | 224 if (resource->texture()->have_backing_texture() && |
220 resource->texture()->size() == rect.size() && | 225 resource->texture()->size() == rect.size() && |
221 !is_dirty()) | 226 !is_dirty()) |
222 return; | 227 return; |
223 | 228 |
224 // We should always have enough memory for UI. | 229 // We should always have enough memory for UI. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 layer_rect, contents_scale_y(), contents_scale_y()); | 263 layer_rect, contents_scale_y(), contents_scale_y()); |
259 // We should never return a rect bigger than the content_bounds(). | 264 // We should never return a rect bigger than the content_bounds(). |
260 gfx::Size clamped_size = expanded_rect.size(); | 265 gfx::Size clamped_size = expanded_rect.size(); |
261 clamped_size.SetToMin(content_bounds()); | 266 clamped_size.SetToMin(content_bounds()); |
262 expanded_rect.set_size(clamped_size); | 267 expanded_rect.set_size(clamped_size); |
263 return expanded_rect; | 268 return expanded_rect; |
264 } | 269 } |
265 | 270 |
266 void ScrollbarLayer::SetTexturePriorities( | 271 void ScrollbarLayer::SetTexturePriorities( |
267 const PriorityCalculator& priority_calc) { | 272 const PriorityCalculator& priority_calc) { |
268 if (layer_tree_host()->settings().solid_color_scrollbars) | 273 if (is_solid_color()) |
269 return; | 274 return; |
270 | 275 |
271 if (content_bounds().IsEmpty()) | 276 if (content_bounds().IsEmpty()) |
272 return; | 277 return; |
273 DCHECK_LE(content_bounds().width(), MaxTextureSize()); | 278 DCHECK_LE(content_bounds().width(), MaxTextureSize()); |
274 DCHECK_LE(content_bounds().height(), MaxTextureSize()); | 279 DCHECK_LE(content_bounds().height(), MaxTextureSize()); |
275 | 280 |
276 CreateUpdaterIfNeeded(); | 281 CreateUpdaterIfNeeded(); |
277 | 282 |
278 bool draws_to_root = !render_target()->parent(); | 283 bool draws_to_root = !render_target()->parent(); |
279 if (track_) { | 284 if (track_) { |
280 track_->texture()->SetDimensions(content_bounds(), texture_format_); | 285 track_->texture()->SetDimensions(content_bounds(), texture_format_); |
281 track_->texture()->set_request_priority( | 286 track_->texture()->set_request_priority( |
282 PriorityCalculator::UIPriority(draws_to_root)); | 287 PriorityCalculator::UIPriority(draws_to_root)); |
283 } | 288 } |
284 if (thumb_) { | 289 if (thumb_) { |
285 gfx::Size thumb_size = OriginThumbRect().size(); | 290 gfx::Size thumb_size = OriginThumbRect().size(); |
286 thumb_->texture()->SetDimensions(thumb_size, texture_format_); | 291 thumb_->texture()->SetDimensions(thumb_size, texture_format_); |
287 thumb_->texture()->set_request_priority( | 292 thumb_->texture()->set_request_priority( |
288 PriorityCalculator::UIPriority(draws_to_root)); | 293 PriorityCalculator::UIPriority(draws_to_root)); |
289 } | 294 } |
290 } | 295 } |
291 | 296 |
292 void ScrollbarLayer::Update(ResourceUpdateQueue* queue, | 297 void ScrollbarLayer::Update(ResourceUpdateQueue* queue, |
293 const OcclusionTracker* occlusion) { | 298 const OcclusionTracker* occlusion) { |
294 track_rect_ = scrollbar_->TrackRect(); | 299 track_rect_ = scrollbar_->TrackRect(); |
295 | 300 |
296 if (layer_tree_host()->settings().solid_color_scrollbars) | 301 if (is_solid_color()) |
297 return; | 302 return; |
298 | 303 |
299 { | 304 { |
300 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 305 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
301 true); | 306 true); |
302 ContentsScalingLayer::Update(queue, occlusion); | 307 ContentsScalingLayer::Update(queue, occlusion); |
303 } | 308 } |
304 | 309 |
305 dirty_rect_.Union(update_rect_); | 310 dirty_rect_.Union(update_rect_); |
306 if (content_bounds().IsEmpty()) | 311 if (content_bounds().IsEmpty()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 thumb_size = gfx::Size(scrollbar_->ThumbLength(), | 343 thumb_size = gfx::Size(scrollbar_->ThumbLength(), |
339 scrollbar_->ThumbThickness()); | 344 scrollbar_->ThumbThickness()); |
340 } else { | 345 } else { |
341 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), | 346 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), |
342 scrollbar_->ThumbLength()); | 347 scrollbar_->ThumbLength()); |
343 } | 348 } |
344 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); | 349 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); |
345 } | 350 } |
346 | 351 |
347 } // namespace cc | 352 } // namespace cc |
OLD | NEW |