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

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

Issue 18341009: Refactor cc scrollbar layers to separate solid-color vs desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address tfarina@'s comments. 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"
(...skipping 16 matching lines...) Expand all
27 scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create( 27 scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create(
28 scoped_ptr<Scrollbar> scrollbar, 28 scoped_ptr<Scrollbar> scrollbar,
29 int scroll_layer_id) { 29 int scroll_layer_id) {
30 return make_scoped_refptr(new ScrollbarLayer(scrollbar.Pass(), 30 return make_scoped_refptr(new ScrollbarLayer(scrollbar.Pass(),
31 scroll_layer_id)); 31 scroll_layer_id));
32 } 32 }
33 33
34 ScrollbarLayer::ScrollbarLayer( 34 ScrollbarLayer::ScrollbarLayer(
35 scoped_ptr<Scrollbar> scrollbar, 35 scoped_ptr<Scrollbar> scrollbar,
36 int scroll_layer_id) 36 int scroll_layer_id)
37 : scrollbar_(scrollbar.Pass()), 37 : ScrollbarLayerBase(scroll_layer_id, scrollbar->Orientation()),
38 scroll_layer_id_(scroll_layer_id), 38 scrollbar_(scrollbar.Pass()),
39 texture_format_(GL_INVALID_ENUM) { 39 texture_format_(GL_INVALID_ENUM) {
40 if (!scrollbar_->IsOverlay()) 40 if (!scrollbar_->IsOverlay())
41 SetShouldScrollOnMainThread(true); 41 SetShouldScrollOnMainThread(true);
42 } 42 }
43 43
44 ScrollbarLayer::~ScrollbarLayer() {} 44 ScrollbarLayer::~ScrollbarLayer() {}
45 45
46 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const {
47 return scrollbar_->IsOverlay();
48 }
49
50 ScrollbarLayerBase* ScrollbarLayer::ToScrollbarLayerBase() { return this; }
51
52 int ScrollbarLayer::MaxTextureSize() {
53 DCHECK(layer_tree_host());
54 return layer_tree_host()->GetRendererCapabilities().max_texture_size;
55 }
56
46 void ScrollbarLayer::SetScrollLayerId(int id) { 57 void ScrollbarLayer::SetScrollLayerId(int id) {
47 if (id == scroll_layer_id_) 58 if (id == scroll_layer_id_)
48 return; 59 return;
49 60
50 scroll_layer_id_ = id; 61 scroll_layer_id_ = id;
51 SetNeedsFullTreeSync(); 62 SetNeedsFullTreeSync();
52 } 63 }
53 64
54 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const {
55 return scrollbar_->IsOverlay();
56 }
57
58 ScrollbarOrientation ScrollbarLayer::Orientation() const {
59 return scrollbar_->Orientation();
60 }
61
62 int ScrollbarLayer::MaxTextureSize() {
63 DCHECK(layer_tree_host());
64 return layer_tree_host()->GetRendererCapabilities().max_texture_size;
65 }
66
67 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { 65 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) {
68 if (layer_tree_host()->settings().solid_color_scrollbars)
69 return scale;
70
71 // If the scaled content_bounds() is bigger than the max texture size of the 66 // 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 67 // device, we need to clamp it by rescaling, since content_bounds() is used
73 // below to set the texture size. 68 // below to set the texture size.
74 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); 69 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale);
75 if (scaled_bounds.width() > MaxTextureSize() || 70 if (scaled_bounds.width() > MaxTextureSize() ||
76 scaled_bounds.height() > MaxTextureSize()) { 71 scaled_bounds.height() > MaxTextureSize()) {
77 if (scaled_bounds.width() > scaled_bounds.height()) 72 if (scaled_bounds.width() > scaled_bounds.height())
78 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); 73 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width());
79 else 74 else
80 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); 75 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height());
(...skipping 16 matching lines...) Expand all
97 contents_scale_x, 92 contents_scale_x,
98 contents_scale_y, 93 contents_scale_y,
99 content_bounds); 94 content_bounds);
100 } 95 }
101 96
102 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { 97 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
103 ContentsScalingLayer::PushPropertiesTo(layer); 98 ContentsScalingLayer::PushPropertiesTo(layer);
104 99
105 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); 100 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer);
106 101
107 if (layer_tree_host() && 102 scrollbar_layer->set_thumb_thickness(thumb_thickness_);
108 layer_tree_host()->settings().solid_color_scrollbars) {
109 int thickness_override =
110 layer_tree_host()->settings().solid_color_scrollbar_thickness_dip;
111 if (thickness_override != -1) {
112 scrollbar_layer->set_thumb_thickness(thickness_override);
113 } else {
114 if (Orientation() == HORIZONTAL)
115 scrollbar_layer->set_thumb_thickness(bounds().height());
116 else
117 scrollbar_layer->set_thumb_thickness(bounds().width());
118 }
119 } else {
120 scrollbar_layer->set_thumb_thickness(thumb_thickness_);
121 }
122 scrollbar_layer->set_thumb_length(thumb_length_); 103 scrollbar_layer->set_thumb_length(thumb_length_);
123 if (Orientation() == HORIZONTAL) { 104 if (Orientation() == HORIZONTAL) {
124 scrollbar_layer->set_track_start(track_rect_.x()); 105 scrollbar_layer->set_track_start(track_rect_.x());
125 scrollbar_layer->set_track_length(track_rect_.width()); 106 scrollbar_layer->set_track_length(track_rect_.width());
126 } else { 107 } else {
127 scrollbar_layer->set_track_start(track_rect_.y()); 108 scrollbar_layer->set_track_start(track_rect_.y());
128 scrollbar_layer->set_track_length(track_rect_.height()); 109 scrollbar_layer->set_track_length(track_rect_.height());
129 } 110 }
130 111
131 if (track_ && track_->texture()->have_backing_texture()) 112 if (track_ && track_->texture()->have_backing_texture())
132 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id()); 113 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id());
133 else 114 else
134 scrollbar_layer->set_track_resource_id(0); 115 scrollbar_layer->set_track_resource_id(0);
135 116
136 if (thumb_ && thumb_->texture()->have_backing_texture()) 117 if (thumb_ && thumb_->texture()->have_backing_texture())
137 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id()); 118 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id());
138 else 119 else
139 scrollbar_layer->set_thumb_resource_id(0); 120 scrollbar_layer->set_thumb_resource_id(0);
140 } 121 }
141 122
142 ScrollbarLayer* ScrollbarLayer::ToScrollbarLayer() {
143 return this;
144 }
145
146 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { 123 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) {
147 if (!host || host != layer_tree_host()) { 124 if (!host || host != layer_tree_host()) {
148 track_updater_ = NULL; 125 track_updater_ = NULL;
149 track_.reset(); 126 track_.reset();
150 thumb_updater_ = NULL; 127 thumb_updater_ = NULL;
151 thumb_.reset(); 128 thumb_.reset();
152 } 129 }
153 130
154 ContentsScalingLayer::SetLayerTreeHost(host); 131 ContentsScalingLayer::SetLayerTreeHost(host);
155 } 132 }
(...skipping 11 matching lines...) Expand all
167 gfx::RectF* opaque) OVERRIDE { 144 gfx::RectF* opaque) OVERRIDE {
168 scrollbar_->PaintPart(canvas, part_, content_rect); 145 scrollbar_->PaintPart(canvas, part_, content_rect);
169 } 146 }
170 147
171 private: 148 private:
172 Scrollbar* scrollbar_; 149 Scrollbar* scrollbar_;
173 ScrollbarPart part_; 150 ScrollbarPart part_;
174 }; 151 };
175 152
176 void ScrollbarLayer::CreateUpdaterIfNeeded() { 153 void ScrollbarLayer::CreateUpdaterIfNeeded() {
177 if (layer_tree_host()->settings().solid_color_scrollbars)
178 return;
179
180 texture_format_ = 154 texture_format_ =
181 layer_tree_host()->GetRendererCapabilities().best_texture_format; 155 layer_tree_host()->GetRendererCapabilities().best_texture_format;
182 156
183 if (!track_updater_.get()) { 157 if (!track_updater_.get()) {
184 track_updater_ = CachingBitmapContentLayerUpdater::Create( 158 track_updater_ = CachingBitmapContentLayerUpdater::Create(
185 scoped_ptr<LayerPainter>( 159 scoped_ptr<LayerPainter>(
186 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) 160 new ScrollbarPartPainter(scrollbar_.get(), TRACK))
187 .Pass(), 161 .Pass(),
188 rendering_stats_instrumentation(), 162 rendering_stats_instrumentation(),
189 id()); 163 id());
(...skipping 14 matching lines...) Expand all
204 if (!thumb_ && scrollbar_->HasThumb()) { 178 if (!thumb_ && scrollbar_->HasThumb()) {
205 thumb_ = thumb_updater_->CreateResource( 179 thumb_ = thumb_updater_->CreateResource(
206 layer_tree_host()->contents_texture_manager()); 180 layer_tree_host()->contents_texture_manager());
207 } 181 }
208 } 182 }
209 183
210 void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, 184 void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter,
211 LayerUpdater::Resource* resource, 185 LayerUpdater::Resource* resource,
212 gfx::Rect rect, 186 gfx::Rect rect,
213 ResourceUpdateQueue* queue) { 187 ResourceUpdateQueue* queue) {
214 if (layer_tree_host()->settings().solid_color_scrollbars)
215 return;
216
217 // Skip painting and uploading if there are no invalidations and 188 // Skip painting and uploading if there are no invalidations and
218 // we already have valid texture data. 189 // we already have valid texture data.
219 if (resource->texture()->have_backing_texture() && 190 if (resource->texture()->have_backing_texture() &&
220 resource->texture()->size() == rect.size() && 191 resource->texture()->size() == rect.size() &&
221 !is_dirty()) 192 !is_dirty())
222 return; 193 return;
223 194
224 // We should always have enough memory for UI. 195 // We should always have enough memory for UI.
225 DCHECK(resource->texture()->can_acquire_backing_texture()); 196 DCHECK(resource->texture()->can_acquire_backing_texture());
226 if (!resource->texture()->can_acquire_backing_texture()) 197 if (!resource->texture()->can_acquire_backing_texture())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 layer_rect, contents_scale_y(), contents_scale_y()); 229 layer_rect, contents_scale_y(), contents_scale_y());
259 // We should never return a rect bigger than the content_bounds(). 230 // We should never return a rect bigger than the content_bounds().
260 gfx::Size clamped_size = expanded_rect.size(); 231 gfx::Size clamped_size = expanded_rect.size();
261 clamped_size.SetToMin(content_bounds()); 232 clamped_size.SetToMin(content_bounds());
262 expanded_rect.set_size(clamped_size); 233 expanded_rect.set_size(clamped_size);
263 return expanded_rect; 234 return expanded_rect;
264 } 235 }
265 236
266 void ScrollbarLayer::SetTexturePriorities( 237 void ScrollbarLayer::SetTexturePriorities(
267 const PriorityCalculator& priority_calc) { 238 const PriorityCalculator& priority_calc) {
268 if (layer_tree_host()->settings().solid_color_scrollbars)
269 return;
270
271 if (content_bounds().IsEmpty()) 239 if (content_bounds().IsEmpty())
272 return; 240 return;
273 DCHECK_LE(content_bounds().width(), MaxTextureSize()); 241 DCHECK_LE(content_bounds().width(), MaxTextureSize());
274 DCHECK_LE(content_bounds().height(), MaxTextureSize()); 242 DCHECK_LE(content_bounds().height(), MaxTextureSize());
275 243
276 CreateUpdaterIfNeeded(); 244 CreateUpdaterIfNeeded();
277 245
278 bool draws_to_root = !render_target()->parent(); 246 bool draws_to_root = !render_target()->parent();
279 if (track_) { 247 if (track_) {
280 track_->texture()->SetDimensions(content_bounds(), texture_format_); 248 track_->texture()->SetDimensions(content_bounds(), texture_format_);
281 track_->texture()->set_request_priority( 249 track_->texture()->set_request_priority(
282 PriorityCalculator::UIPriority(draws_to_root)); 250 PriorityCalculator::UIPriority(draws_to_root));
283 } 251 }
284 if (thumb_) { 252 if (thumb_) {
285 gfx::Size thumb_size = OriginThumbRect().size(); 253 gfx::Size thumb_size = OriginThumbRect().size();
286 thumb_->texture()->SetDimensions(thumb_size, texture_format_); 254 thumb_->texture()->SetDimensions(thumb_size, texture_format_);
287 thumb_->texture()->set_request_priority( 255 thumb_->texture()->set_request_priority(
288 PriorityCalculator::UIPriority(draws_to_root)); 256 PriorityCalculator::UIPriority(draws_to_root));
289 } 257 }
290 } 258 }
291 259
292 void ScrollbarLayer::Update(ResourceUpdateQueue* queue, 260 void ScrollbarLayer::Update(ResourceUpdateQueue* queue,
293 const OcclusionTracker* occlusion) { 261 const OcclusionTracker* occlusion) {
294 track_rect_ = scrollbar_->TrackRect(); 262 track_rect_ = scrollbar_->TrackRect();
295 263
296 if (layer_tree_host()->settings().solid_color_scrollbars)
297 return;
298
299 { 264 {
300 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, 265 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
301 true); 266 true);
302 ContentsScalingLayer::Update(queue, occlusion); 267 ContentsScalingLayer::Update(queue, occlusion);
303 } 268 }
304 269
305 dirty_rect_.Union(update_rect_); 270 dirty_rect_.Union(update_rect_);
306 if (content_bounds().IsEmpty()) 271 if (content_bounds().IsEmpty())
307 return; 272 return;
308 if (visible_content_rect().IsEmpty()) 273 if (visible_content_rect().IsEmpty())
(...skipping 29 matching lines...) Expand all
338 thumb_size = gfx::Size(scrollbar_->ThumbLength(), 303 thumb_size = gfx::Size(scrollbar_->ThumbLength(),
339 scrollbar_->ThumbThickness()); 304 scrollbar_->ThumbThickness());
340 } else { 305 } else {
341 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), 306 thumb_size = gfx::Size(scrollbar_->ThumbThickness(),
342 scrollbar_->ThumbLength()); 307 scrollbar_->ThumbLength());
343 } 308 }
344 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); 309 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
345 } 310 }
346 311
347 } // namespace cc 312 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698