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

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: Add command line flag, remove need for DCHECK(). 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 layer_rect, contents_scale_y(), contents_scale_y()); 265 layer_rect, contents_scale_y(), contents_scale_y());
261 // We should never return a rect bigger than the content_bounds(). 266 // We should never return a rect bigger than the content_bounds().
262 gfx::Size clamped_size = expanded_rect.size(); 267 gfx::Size clamped_size = expanded_rect.size();
263 clamped_size.SetToMin(content_bounds()); 268 clamped_size.SetToMin(content_bounds());
264 expanded_rect.set_size(clamped_size); 269 expanded_rect.set_size(clamped_size);
265 return expanded_rect; 270 return expanded_rect;
266 } 271 }
267 272
268 void ScrollbarLayer::SetTexturePriorities( 273 void ScrollbarLayer::SetTexturePriorities(
269 const PriorityCalculator& priority_calc) { 274 const PriorityCalculator& priority_calc) {
270 if (layer_tree_host()->settings().solid_color_scrollbars) 275 if (is_solid_color())
271 return; 276 return;
272 277
273 if (content_bounds().IsEmpty()) 278 if (content_bounds().IsEmpty())
274 return; 279 return;
275 DCHECK_LE(content_bounds().width(), MaxTextureSize()); 280 DCHECK_LE(content_bounds().width(), MaxTextureSize());
276 DCHECK_LE(content_bounds().height(), MaxTextureSize()); 281 DCHECK_LE(content_bounds().height(), MaxTextureSize());
277 282
278 CreateUpdaterIfNeeded(); 283 CreateUpdaterIfNeeded();
279 284
280 bool draws_to_root = !render_target()->parent(); 285 bool draws_to_root = !render_target()->parent();
281 if (track_) { 286 if (track_) {
282 track_->texture()->SetDimensions(content_bounds(), texture_format_); 287 track_->texture()->SetDimensions(content_bounds(), texture_format_);
283 track_->texture()->set_request_priority( 288 track_->texture()->set_request_priority(
284 PriorityCalculator::UIPriority(draws_to_root)); 289 PriorityCalculator::UIPriority(draws_to_root));
285 } 290 }
286 if (thumb_) { 291 if (thumb_) {
287 gfx::Size thumb_size = OriginThumbRect().size(); 292 gfx::Size thumb_size = OriginThumbRect().size();
288 thumb_->texture()->SetDimensions(thumb_size, texture_format_); 293 thumb_->texture()->SetDimensions(thumb_size, texture_format_);
289 thumb_->texture()->set_request_priority( 294 thumb_->texture()->set_request_priority(
290 PriorityCalculator::UIPriority(draws_to_root)); 295 PriorityCalculator::UIPriority(draws_to_root));
291 } 296 }
292 } 297 }
293 298
294 void ScrollbarLayer::Update(ResourceUpdateQueue* queue, 299 void ScrollbarLayer::Update(ResourceUpdateQueue* queue,
295 const OcclusionTracker* occlusion, 300 const OcclusionTracker* occlusion,
296 RenderingStats* stats) { 301 RenderingStats* stats) {
297 track_rect_ = scrollbar_->TrackRect(); 302 track_rect_ = scrollbar_->TrackRect();
298 303
299 if (layer_tree_host()->settings().solid_color_scrollbars) 304 if (is_solid_color())
300 return; 305 return;
301 306
302 { 307 {
303 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, 308 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
304 true); 309 true);
305 ContentsScalingLayer::Update(queue, occlusion, stats); 310 ContentsScalingLayer::Update(queue, occlusion, stats);
306 } 311 }
307 312
308 dirty_rect_.Union(update_rect_); 313 dirty_rect_.Union(update_rect_);
309 if (content_bounds().IsEmpty()) 314 if (content_bounds().IsEmpty())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 thumb_size = gfx::Size(scrollbar_->ThumbLength(), 348 thumb_size = gfx::Size(scrollbar_->ThumbLength(),
344 scrollbar_->ThumbThickness()); 349 scrollbar_->ThumbThickness());
345 } else { 350 } else {
346 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), 351 thumb_size = gfx::Size(scrollbar_->ThumbThickness(),
347 scrollbar_->ThumbLength()); 352 scrollbar_->ThumbLength());
348 } 353 }
349 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); 354 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
350 } 355 }
351 356
352 } // namespace cc 357 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698