Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: cc/layers/scrollbar_layer.cc

Issue 17550008: Make IsSolidColor() a property on CC scrollbar layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DCHECK(layer_tree_host()) instead. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
67 bool ScrollbarLayer::IsSolidColor() const {
68 DCHECK(layer_tree_host());
enne (OOO) 2013/06/26 17:39:05 This seems dangerous. cc::Layers can be detached
wjmaclean 2013/06/26 18:16:00 There isn't a command line flag for force_solid_co
enne (OOO) 2013/06/26 20:02:11 Right now it can't differ, and is always true on A
69 return is_solid_color_ ||
70 layer_tree_host()->settings().force_solid_color_scrollbars;
71 }
72
62 int ScrollbarLayer::MaxTextureSize() { 73 int ScrollbarLayer::MaxTextureSize() {
63 DCHECK(layer_tree_host()); 74 DCHECK(layer_tree_host());
64 return layer_tree_host()->GetRendererCapabilities().max_texture_size; 75 return layer_tree_host()->GetRendererCapabilities().max_texture_size;
65 } 76 }
66 77
67 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { 78 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) {
68 if (layer_tree_host()->settings().solid_color_scrollbars) 79 if (IsSolidColor())
69 return scale; 80 return scale;
70 81
71 // If the scaled content_bounds() is bigger than the max texture size of the 82 // 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 83 // device, we need to clamp it by rescaling, since content_bounds() is used
73 // below to set the texture size. 84 // below to set the texture size.
74 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); 85 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale);
75 if (scaled_bounds.width() > MaxTextureSize() || 86 if (scaled_bounds.width() > MaxTextureSize() ||
76 scaled_bounds.height() > MaxTextureSize()) { 87 scaled_bounds.height() > MaxTextureSize()) {
77 if (scaled_bounds.width() > scaled_bounds.height()) 88 if (scaled_bounds.width() > scaled_bounds.height())
78 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); 89 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width());
(...skipping 18 matching lines...) Expand all
97 contents_scale_x, 108 contents_scale_x,
98 contents_scale_y, 109 contents_scale_y,
99 content_bounds); 110 content_bounds);
100 } 111 }
101 112
102 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { 113 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
103 ContentsScalingLayer::PushPropertiesTo(layer); 114 ContentsScalingLayer::PushPropertiesTo(layer);
104 115
105 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); 116 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer);
106 117
107 if (layer_tree_host() && 118 if (layer_tree_host() && IsSolidColor()) {
108 layer_tree_host()->settings().solid_color_scrollbars) {
109 int thickness_override = 119 int thickness_override =
110 layer_tree_host()->settings().solid_color_scrollbar_thickness_dip; 120 layer_tree_host()->settings().solid_color_scrollbar_thickness_dip;
111 if (thickness_override != -1) { 121 if (thickness_override != -1) {
112 scrollbar_layer->set_thumb_thickness(thickness_override); 122 scrollbar_layer->set_thumb_thickness(thickness_override);
113 } else { 123 } else {
114 if (Orientation() == HORIZONTAL) 124 if (Orientation() == HORIZONTAL)
115 scrollbar_layer->set_thumb_thickness(bounds().height()); 125 scrollbar_layer->set_thumb_thickness(bounds().height());
116 else 126 else
117 scrollbar_layer->set_thumb_thickness(bounds().width()); 127 scrollbar_layer->set_thumb_thickness(bounds().width());
118 } 128 }
119 } else { 129 } else {
120 scrollbar_layer->set_thumb_thickness(thumb_thickness_); 130 scrollbar_layer->set_thumb_thickness(thumb_thickness_);
121 } 131 }
122 scrollbar_layer->set_thumb_length(thumb_length_); 132 scrollbar_layer->set_thumb_length(thumb_length_);
123 if (Orientation() == HORIZONTAL) { 133 if (Orientation() == HORIZONTAL) {
124 scrollbar_layer->set_track_start(track_rect_.x()); 134 scrollbar_layer->set_track_start(track_rect_.x());
125 scrollbar_layer->set_track_length(track_rect_.width()); 135 scrollbar_layer->set_track_length(track_rect_.width());
126 } else { 136 } else {
127 scrollbar_layer->set_track_start(track_rect_.y()); 137 scrollbar_layer->set_track_start(track_rect_.y());
128 scrollbar_layer->set_track_length(track_rect_.height()); 138 scrollbar_layer->set_track_length(track_rect_.height());
129 } 139 }
140 scrollbar_layer->set_is_solid_color(IsSolidColor());
130 141
131 if (track_ && track_->texture()->have_backing_texture()) 142 if (track_ && track_->texture()->have_backing_texture())
132 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id()); 143 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id());
133 else 144 else
134 scrollbar_layer->set_track_resource_id(0); 145 scrollbar_layer->set_track_resource_id(0);
135 146
136 if (thumb_ && thumb_->texture()->have_backing_texture()) 147 if (thumb_ && thumb_->texture()->have_backing_texture())
137 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id()); 148 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id());
138 else 149 else
139 scrollbar_layer->set_thumb_resource_id(0); 150 scrollbar_layer->set_thumb_resource_id(0);
(...skipping 27 matching lines...) Expand all
167 gfx::RectF* opaque) OVERRIDE { 178 gfx::RectF* opaque) OVERRIDE {
168 scrollbar_->PaintPart(canvas, part_, content_rect); 179 scrollbar_->PaintPart(canvas, part_, content_rect);
169 } 180 }
170 181
171 private: 182 private:
172 Scrollbar* scrollbar_; 183 Scrollbar* scrollbar_;
173 ScrollbarPart part_; 184 ScrollbarPart part_;
174 }; 185 };
175 186
176 void ScrollbarLayer::CreateUpdaterIfNeeded() { 187 void ScrollbarLayer::CreateUpdaterIfNeeded() {
177 if (layer_tree_host()->settings().solid_color_scrollbars) 188 if (IsSolidColor())
178 return; 189 return;
179 190
180 texture_format_ = 191 texture_format_ =
181 layer_tree_host()->GetRendererCapabilities().best_texture_format; 192 layer_tree_host()->GetRendererCapabilities().best_texture_format;
182 193
183 if (!track_updater_.get()) { 194 if (!track_updater_.get()) {
184 track_updater_ = CachingBitmapContentLayerUpdater::Create( 195 track_updater_ = CachingBitmapContentLayerUpdater::Create(
185 scoped_ptr<LayerPainter>( 196 scoped_ptr<LayerPainter>(
186 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) 197 new ScrollbarPartPainter(scrollbar_.get(), TRACK))
187 .Pass(), 198 .Pass(),
(...skipping 17 matching lines...) Expand all
205 thumb_ = thumb_updater_->CreateResource( 216 thumb_ = thumb_updater_->CreateResource(
206 layer_tree_host()->contents_texture_manager()); 217 layer_tree_host()->contents_texture_manager());
207 } 218 }
208 } 219 }
209 220
210 void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, 221 void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter,
211 LayerUpdater::Resource* resource, 222 LayerUpdater::Resource* resource,
212 gfx::Rect rect, 223 gfx::Rect rect,
213 ResourceUpdateQueue* queue, 224 ResourceUpdateQueue* queue,
214 RenderingStats* stats) { 225 RenderingStats* stats) {
215 if (layer_tree_host()->settings().solid_color_scrollbars) 226 if (IsSolidColor())
216 return; 227 return;
217 228
218 // Skip painting and uploading if there are no invalidations and 229 // Skip painting and uploading if there are no invalidations and
219 // we already have valid texture data. 230 // we already have valid texture data.
220 if (resource->texture()->have_backing_texture() && 231 if (resource->texture()->have_backing_texture() &&
221 resource->texture()->size() == rect.size() && 232 resource->texture()->size() == rect.size() &&
222 !is_dirty()) 233 !is_dirty())
223 return; 234 return;
224 235
225 // We should always have enough memory for UI. 236 // We should always have enough memory for UI.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 layer_rect, contents_scale_y(), contents_scale_y()); 271 layer_rect, contents_scale_y(), contents_scale_y());
261 // We should never return a rect bigger than the content_bounds(). 272 // We should never return a rect bigger than the content_bounds().
262 gfx::Size clamped_size = expanded_rect.size(); 273 gfx::Size clamped_size = expanded_rect.size();
263 clamped_size.SetToMin(content_bounds()); 274 clamped_size.SetToMin(content_bounds());
264 expanded_rect.set_size(clamped_size); 275 expanded_rect.set_size(clamped_size);
265 return expanded_rect; 276 return expanded_rect;
266 } 277 }
267 278
268 void ScrollbarLayer::SetTexturePriorities( 279 void ScrollbarLayer::SetTexturePriorities(
269 const PriorityCalculator& priority_calc) { 280 const PriorityCalculator& priority_calc) {
270 if (layer_tree_host()->settings().solid_color_scrollbars) 281 if (IsSolidColor())
271 return; 282 return;
272 283
273 if (content_bounds().IsEmpty()) 284 if (content_bounds().IsEmpty())
274 return; 285 return;
275 DCHECK_LE(content_bounds().width(), MaxTextureSize()); 286 DCHECK_LE(content_bounds().width(), MaxTextureSize());
276 DCHECK_LE(content_bounds().height(), MaxTextureSize()); 287 DCHECK_LE(content_bounds().height(), MaxTextureSize());
277 288
278 CreateUpdaterIfNeeded(); 289 CreateUpdaterIfNeeded();
279 290
280 bool draws_to_root = !render_target()->parent(); 291 bool draws_to_root = !render_target()->parent();
281 if (track_) { 292 if (track_) {
282 track_->texture()->SetDimensions(content_bounds(), texture_format_); 293 track_->texture()->SetDimensions(content_bounds(), texture_format_);
283 track_->texture()->set_request_priority( 294 track_->texture()->set_request_priority(
284 PriorityCalculator::UIPriority(draws_to_root)); 295 PriorityCalculator::UIPriority(draws_to_root));
285 } 296 }
286 if (thumb_) { 297 if (thumb_) {
287 gfx::Size thumb_size = OriginThumbRect().size(); 298 gfx::Size thumb_size = OriginThumbRect().size();
288 thumb_->texture()->SetDimensions(thumb_size, texture_format_); 299 thumb_->texture()->SetDimensions(thumb_size, texture_format_);
289 thumb_->texture()->set_request_priority( 300 thumb_->texture()->set_request_priority(
290 PriorityCalculator::UIPriority(draws_to_root)); 301 PriorityCalculator::UIPriority(draws_to_root));
291 } 302 }
292 } 303 }
293 304
294 void ScrollbarLayer::Update(ResourceUpdateQueue* queue, 305 void ScrollbarLayer::Update(ResourceUpdateQueue* queue,
295 const OcclusionTracker* occlusion, 306 const OcclusionTracker* occlusion,
296 RenderingStats* stats) { 307 RenderingStats* stats) {
297 track_rect_ = scrollbar_->TrackRect(); 308 track_rect_ = scrollbar_->TrackRect();
298 309
299 if (layer_tree_host()->settings().solid_color_scrollbars) 310 if (IsSolidColor())
300 return; 311 return;
301 312
302 { 313 {
303 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, 314 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
304 true); 315 true);
305 ContentsScalingLayer::Update(queue, occlusion, stats); 316 ContentsScalingLayer::Update(queue, occlusion, stats);
306 } 317 }
307 318
308 dirty_rect_.Union(update_rect_); 319 dirty_rect_.Union(update_rect_);
309 if (content_bounds().IsEmpty()) 320 if (content_bounds().IsEmpty())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 thumb_size = gfx::Size(scrollbar_->ThumbLength(), 354 thumb_size = gfx::Size(scrollbar_->ThumbLength(),
344 scrollbar_->ThumbThickness()); 355 scrollbar_->ThumbThickness());
345 } else { 356 } else {
346 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), 357 thumb_size = gfx::Size(scrollbar_->ThumbThickness(),
347 scrollbar_->ThumbLength()); 358 scrollbar_->ThumbLength());
348 } 359 }
349 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); 360 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
350 } 361 }
351 362
352 } // namespace cc 363 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698