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

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: Set color/thickness via command line also. 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
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
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
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 17 matching lines...) Expand all
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 RenderingStats* stats) { 219 RenderingStats* stats) {
215 if (layer_tree_host()->settings().solid_color_scrollbars) 220 if (is_solid_color())
216 return; 221 return;
217 222
218 // Skip painting and uploading if there are no invalidations and 223 // Skip painting and uploading if there are no invalidations and
219 // we already have valid texture data. 224 // we already have valid texture data.
220 if (resource->texture()->have_backing_texture() && 225 if (resource->texture()->have_backing_texture() &&
221 resource->texture()->size() == rect.size() && 226 resource->texture()->size() == rect.size() &&
222 !is_dirty()) 227 !is_dirty())
223 return; 228 return;
224 229
225 // We should always have enough memory for UI. 230 // We should always have enough memory for UI.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 layer_rect, contents_scale_y(), contents_scale_y()); 264 layer_rect, contents_scale_y(), contents_scale_y());
260 // We should never return a rect bigger than the content_bounds(). 265 // We should never return a rect bigger than the content_bounds().
261 gfx::Size clamped_size = expanded_rect.size(); 266 gfx::Size clamped_size = expanded_rect.size();
262 clamped_size.SetToMin(content_bounds()); 267 clamped_size.SetToMin(content_bounds());
263 expanded_rect.set_size(clamped_size); 268 expanded_rect.set_size(clamped_size);
264 return expanded_rect; 269 return expanded_rect;
265 } 270 }
266 271
267 void ScrollbarLayer::SetTexturePriorities( 272 void ScrollbarLayer::SetTexturePriorities(
268 const PriorityCalculator& priority_calc) { 273 const PriorityCalculator& priority_calc) {
269 if (layer_tree_host()->settings().solid_color_scrollbars) 274 if (is_solid_color())
270 return; 275 return;
271 276
272 if (content_bounds().IsEmpty()) 277 if (content_bounds().IsEmpty())
273 return; 278 return;
274 DCHECK_LE(content_bounds().width(), MaxTextureSize()); 279 DCHECK_LE(content_bounds().width(), MaxTextureSize());
275 DCHECK_LE(content_bounds().height(), MaxTextureSize()); 280 DCHECK_LE(content_bounds().height(), MaxTextureSize());
276 281
277 CreateUpdaterIfNeeded(); 282 CreateUpdaterIfNeeded();
278 283
279 bool draws_to_root = !render_target()->parent(); 284 bool draws_to_root = !render_target()->parent();
280 if (track_) { 285 if (track_) {
281 track_->texture()->SetDimensions(content_bounds(), texture_format_); 286 track_->texture()->SetDimensions(content_bounds(), texture_format_);
282 track_->texture()->set_request_priority( 287 track_->texture()->set_request_priority(
283 PriorityCalculator::UIPriority(draws_to_root)); 288 PriorityCalculator::UIPriority(draws_to_root));
284 } 289 }
285 if (thumb_) { 290 if (thumb_) {
286 gfx::Size thumb_size = OriginThumbRect().size(); 291 gfx::Size thumb_size = OriginThumbRect().size();
287 thumb_->texture()->SetDimensions(thumb_size, texture_format_); 292 thumb_->texture()->SetDimensions(thumb_size, texture_format_);
288 thumb_->texture()->set_request_priority( 293 thumb_->texture()->set_request_priority(
289 PriorityCalculator::UIPriority(draws_to_root)); 294 PriorityCalculator::UIPriority(draws_to_root));
290 } 295 }
291 } 296 }
292 297
293 void ScrollbarLayer::Update(ResourceUpdateQueue* queue, 298 void ScrollbarLayer::Update(ResourceUpdateQueue* queue,
294 const OcclusionTracker* occlusion, 299 const OcclusionTracker* occlusion,
295 RenderingStats* stats) { 300 RenderingStats* stats) {
296 track_rect_ = scrollbar_->TrackRect(); 301 track_rect_ = scrollbar_->TrackRect();
297 302
298 if (layer_tree_host()->settings().solid_color_scrollbars) 303 if (is_solid_color())
299 return; 304 return;
300 305
301 { 306 {
302 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, 307 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
303 true); 308 true);
304 ContentsScalingLayer::Update(queue, occlusion, stats); 309 ContentsScalingLayer::Update(queue, occlusion, stats);
305 } 310 }
306 311
307 dirty_rect_.Union(update_rect_); 312 dirty_rect_.Union(update_rect_);
308 if (content_bounds().IsEmpty()) 313 if (content_bounds().IsEmpty())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 thumb_size = gfx::Size(scrollbar_->ThumbLength(), 347 thumb_size = gfx::Size(scrollbar_->ThumbLength(),
343 scrollbar_->ThumbThickness()); 348 scrollbar_->ThumbThickness());
344 } else { 349 } else {
345 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), 350 thumb_size = gfx::Size(scrollbar_->ThumbThickness(),
346 scrollbar_->ThumbLength()); 351 scrollbar_->ThumbLength());
347 } 352 }
348 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); 353 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
349 } 354 }
350 355
351 } // namespace cc 356 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698