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

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 Enne's comments. Created 7 years, 4 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 : scroll_layer_id_(scroll_layer_id),
38 scroll_layer_id_(scroll_layer_id), 38 orientation_(scrollbar->Orientation()),
39 scrollbar_(scrollbar.Pass()),
39 texture_format_(GL_INVALID_ENUM) { 40 texture_format_(GL_INVALID_ENUM) {
40 if (!scrollbar_->IsOverlay()) 41 if (!scrollbar_->IsOverlay())
41 SetShouldScrollOnMainThread(true); 42 SetShouldScrollOnMainThread(true);
42 } 43 }
43 44
44 ScrollbarLayer::~ScrollbarLayer() {} 45 ScrollbarLayer::~ScrollbarLayer() {}
45 46
46 void ScrollbarLayer::SetScrollLayerId(int id) { 47 void ScrollbarLayer::SetScrollLayerId(int id) {
47 if (id == scroll_layer_id_) 48 if (id == scroll_layer_id_)
48 return; 49 return;
49 50
50 scroll_layer_id_ = id; 51 scroll_layer_id_ = id;
51 SetNeedsFullTreeSync(); 52 SetNeedsFullTreeSync();
52 } 53 }
53 54
54 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const { 55 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const {
55 return scrollbar_->IsOverlay(); 56 return scrollbar_->IsOverlay();
56 } 57 }
57 58
58 ScrollbarOrientation ScrollbarLayer::Orientation() const { 59 ScrollbarLayerInterface* ScrollbarLayer::ToScrollbarLayer() {
59 return scrollbar_->Orientation(); 60 return this;
60 } 61 }
61 62
62 int ScrollbarLayer::MaxTextureSize() { 63 int ScrollbarLayer::MaxTextureSize() {
63 DCHECK(layer_tree_host()); 64 DCHECK(layer_tree_host());
64 return layer_tree_host()->GetRendererCapabilities().max_texture_size; 65 return layer_tree_host()->GetRendererCapabilities().max_texture_size;
65 } 66 }
66 67
68 int ScrollbarLayer::scroll_layer_id() const {
69 return scroll_layer_id_;
70 }
71
72 ScrollbarOrientation ScrollbarLayer::orientation() const {
73 return orientation_;
enne (OOO) 2013/08/14 21:01:09 Does this need a separate variable? What about jus
wjmaclean 2013/08/15 20:09:40 Done.
74 }
75
67 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { 76 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 77 // 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 78 // device, we need to clamp it by rescaling, since content_bounds() is used
73 // below to set the texture size. 79 // below to set the texture size.
74 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); 80 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale);
75 if (scaled_bounds.width() > MaxTextureSize() || 81 if (scaled_bounds.width() > MaxTextureSize() ||
76 scaled_bounds.height() > MaxTextureSize()) { 82 scaled_bounds.height() > MaxTextureSize()) {
77 if (scaled_bounds.width() > scaled_bounds.height()) 83 if (scaled_bounds.width() > scaled_bounds.height())
78 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); 84 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width());
79 else 85 else
80 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); 86 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height());
(...skipping 16 matching lines...) Expand all
97 contents_scale_x, 103 contents_scale_x,
98 contents_scale_y, 104 contents_scale_y,
99 content_bounds); 105 content_bounds);
100 } 106 }
101 107
102 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { 108 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
103 ContentsScalingLayer::PushPropertiesTo(layer); 109 ContentsScalingLayer::PushPropertiesTo(layer);
104 110
105 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); 111 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer);
106 112
107 if (layer_tree_host() && 113 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_); 114 scrollbar_layer->set_thumb_length(thumb_length_);
123 if (Orientation() == HORIZONTAL) { 115 if (orientation() == HORIZONTAL) {
124 scrollbar_layer->set_track_start(track_rect_.x()); 116 scrollbar_layer->set_track_start(track_rect_.x());
125 scrollbar_layer->set_track_length(track_rect_.width()); 117 scrollbar_layer->set_track_length(track_rect_.width());
126 } else { 118 } else {
127 scrollbar_layer->set_track_start(track_rect_.y()); 119 scrollbar_layer->set_track_start(track_rect_.y());
128 scrollbar_layer->set_track_length(track_rect_.height()); 120 scrollbar_layer->set_track_length(track_rect_.height());
129 } 121 }
130 122
131 if (track_ && track_->texture()->have_backing_texture()) 123 if (track_ && track_->texture()->have_backing_texture())
132 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id()); 124 scrollbar_layer->set_track_resource_id(track_->texture()->resource_id());
133 else 125 else
134 scrollbar_layer->set_track_resource_id(0); 126 scrollbar_layer->set_track_resource_id(0);
135 127
136 if (thumb_ && thumb_->texture()->have_backing_texture()) 128 if (thumb_ && thumb_->texture()->have_backing_texture())
137 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id()); 129 scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id());
138 else 130 else
139 scrollbar_layer->set_thumb_resource_id(0); 131 scrollbar_layer->set_thumb_resource_id(0);
140 132
141 scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay()); 133 scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay());
142 134
143 // ScrollbarLayer must push properties every frame. crbug.com/259095 135 // ScrollbarLayer must push properties every frame. crbug.com/259095
144 needs_push_properties_ = true; 136 needs_push_properties_ = true;
145 } 137 }
146 138
147 ScrollbarLayer* ScrollbarLayer::ToScrollbarLayer() {
148 return this;
149 }
150
151 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { 139 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) {
152 if (!host || host != layer_tree_host()) { 140 if (!host || host != layer_tree_host()) {
153 track_updater_ = NULL; 141 track_updater_ = NULL;
154 track_.reset(); 142 track_.reset();
155 thumb_updater_ = NULL; 143 thumb_updater_ = NULL;
156 thumb_.reset(); 144 thumb_.reset();
157 } 145 }
158 146
159 ContentsScalingLayer::SetLayerTreeHost(host); 147 ContentsScalingLayer::SetLayerTreeHost(host);
160 } 148 }
(...skipping 11 matching lines...) Expand all
172 gfx::RectF* opaque) OVERRIDE { 160 gfx::RectF* opaque) OVERRIDE {
173 scrollbar_->PaintPart(canvas, part_, content_rect); 161 scrollbar_->PaintPart(canvas, part_, content_rect);
174 } 162 }
175 163
176 private: 164 private:
177 Scrollbar* scrollbar_; 165 Scrollbar* scrollbar_;
178 ScrollbarPart part_; 166 ScrollbarPart part_;
179 }; 167 };
180 168
181 void ScrollbarLayer::CreateUpdaterIfNeeded() { 169 void ScrollbarLayer::CreateUpdaterIfNeeded() {
182 if (layer_tree_host()->settings().solid_color_scrollbars)
183 return;
184
185 texture_format_ = 170 texture_format_ =
186 layer_tree_host()->GetRendererCapabilities().best_texture_format; 171 layer_tree_host()->GetRendererCapabilities().best_texture_format;
187 172
188 if (!track_updater_.get()) { 173 if (!track_updater_.get()) {
189 track_updater_ = CachingBitmapContentLayerUpdater::Create( 174 track_updater_ = CachingBitmapContentLayerUpdater::Create(
190 scoped_ptr<LayerPainter>( 175 scoped_ptr<LayerPainter>(
191 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) 176 new ScrollbarPartPainter(scrollbar_.get(), TRACK))
192 .Pass(), 177 .Pass(),
193 rendering_stats_instrumentation(), 178 rendering_stats_instrumentation(),
194 id()); 179 id());
(...skipping 14 matching lines...) Expand all
209 if (!thumb_ && scrollbar_->HasThumb()) { 194 if (!thumb_ && scrollbar_->HasThumb()) {
210 thumb_ = thumb_updater_->CreateResource( 195 thumb_ = thumb_updater_->CreateResource(
211 layer_tree_host()->contents_texture_manager()); 196 layer_tree_host()->contents_texture_manager());
212 } 197 }
213 } 198 }
214 199
215 bool ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, 200 bool ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter,
216 LayerUpdater::Resource* resource, 201 LayerUpdater::Resource* resource,
217 gfx::Rect rect, 202 gfx::Rect rect,
218 ResourceUpdateQueue* queue) { 203 ResourceUpdateQueue* queue) {
219 if (layer_tree_host()->settings().solid_color_scrollbars)
220 return false;
221
222 // Skip painting and uploading if there are no invalidations and 204 // Skip painting and uploading if there are no invalidations and
223 // we already have valid texture data. 205 // we already have valid texture data.
224 if (resource->texture()->have_backing_texture() && 206 if (resource->texture()->have_backing_texture() &&
225 resource->texture()->size() == rect.size() && 207 resource->texture()->size() == rect.size() &&
226 !is_dirty()) 208 !is_dirty())
227 return false; 209 return false;
228 210
229 // We should always have enough memory for UI. 211 // We should always have enough memory for UI.
230 DCHECK(resource->texture()->can_acquire_backing_texture()); 212 DCHECK(resource->texture()->can_acquire_backing_texture());
231 if (!resource->texture()->can_acquire_backing_texture()) 213 if (!resource->texture()->can_acquire_backing_texture())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 layer_rect, contents_scale_y(), contents_scale_y()); 246 layer_rect, contents_scale_y(), contents_scale_y());
265 // We should never return a rect bigger than the content_bounds(). 247 // We should never return a rect bigger than the content_bounds().
266 gfx::Size clamped_size = expanded_rect.size(); 248 gfx::Size clamped_size = expanded_rect.size();
267 clamped_size.SetToMin(content_bounds()); 249 clamped_size.SetToMin(content_bounds());
268 expanded_rect.set_size(clamped_size); 250 expanded_rect.set_size(clamped_size);
269 return expanded_rect; 251 return expanded_rect;
270 } 252 }
271 253
272 void ScrollbarLayer::SetTexturePriorities( 254 void ScrollbarLayer::SetTexturePriorities(
273 const PriorityCalculator& priority_calc) { 255 const PriorityCalculator& priority_calc) {
274 if (layer_tree_host()->settings().solid_color_scrollbars)
275 return;
276
277 if (content_bounds().IsEmpty()) 256 if (content_bounds().IsEmpty())
278 return; 257 return;
279 DCHECK_LE(content_bounds().width(), MaxTextureSize()); 258 DCHECK_LE(content_bounds().width(), MaxTextureSize());
280 DCHECK_LE(content_bounds().height(), MaxTextureSize()); 259 DCHECK_LE(content_bounds().height(), MaxTextureSize());
281 260
282 CreateUpdaterIfNeeded(); 261 CreateUpdaterIfNeeded();
283 262
284 bool draws_to_root = !render_target()->parent(); 263 bool draws_to_root = !render_target()->parent();
285 if (track_) { 264 if (track_) {
286 track_->texture()->SetDimensions(content_bounds(), texture_format_); 265 track_->texture()->SetDimensions(content_bounds(), texture_format_);
287 track_->texture()->set_request_priority( 266 track_->texture()->set_request_priority(
288 PriorityCalculator::UIPriority(draws_to_root)); 267 PriorityCalculator::UIPriority(draws_to_root));
289 } 268 }
290 if (thumb_) { 269 if (thumb_) {
291 gfx::Size thumb_size = OriginThumbRect().size(); 270 gfx::Size thumb_size = OriginThumbRect().size();
292 thumb_->texture()->SetDimensions(thumb_size, texture_format_); 271 thumb_->texture()->SetDimensions(thumb_size, texture_format_);
293 thumb_->texture()->set_request_priority( 272 thumb_->texture()->set_request_priority(
294 PriorityCalculator::UIPriority(draws_to_root)); 273 PriorityCalculator::UIPriority(draws_to_root));
295 } 274 }
296 } 275 }
297 276
298 bool ScrollbarLayer::Update(ResourceUpdateQueue* queue, 277 bool ScrollbarLayer::Update(ResourceUpdateQueue* queue,
299 const OcclusionTracker* occlusion) { 278 const OcclusionTracker* occlusion) {
300 track_rect_ = scrollbar_->TrackRect(); 279 track_rect_ = scrollbar_->TrackRect();
301 280
302 if (layer_tree_host()->settings().solid_color_scrollbars) 281 // WJM: is this specific to solid color scrollbars? probably!!
enne (OOO) 2013/08/14 21:01:09 This is in ScrollbarLayer, so no longer has anythi
wjmaclean 2013/08/15 20:09:40 Yeah, picked this one off in a recent rebase ... g
303 return false;
304
305 bool updated = false; 282 bool updated = false;
306 283
307 { 284 {
308 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, 285 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
309 true); 286 true);
310 updated = ContentsScalingLayer::Update(queue, occlusion); 287 updated = ContentsScalingLayer::Update(queue, occlusion);
311 } 288 }
312 289
313 dirty_rect_.Union(update_rect_); 290 dirty_rect_.Union(update_rect_);
314 if (content_bounds().IsEmpty()) 291 if (content_bounds().IsEmpty())
(...skipping 17 matching lines...) Expand all
332 origin_thumb_rect, queue); 309 origin_thumb_rect, queue);
333 } 310 }
334 } 311 }
335 312
336 dirty_rect_ = gfx::RectF(); 313 dirty_rect_ = gfx::RectF();
337 return updated; 314 return updated;
338 } 315 }
339 316
340 gfx::Rect ScrollbarLayer::OriginThumbRect() const { 317 gfx::Rect ScrollbarLayer::OriginThumbRect() const {
341 gfx::Size thumb_size; 318 gfx::Size thumb_size;
342 if (Orientation() == HORIZONTAL) { 319 if (orientation() == HORIZONTAL) {
343 thumb_size = gfx::Size(scrollbar_->ThumbLength(), 320 thumb_size = gfx::Size(scrollbar_->ThumbLength(),
344 scrollbar_->ThumbThickness()); 321 scrollbar_->ThumbThickness());
345 } else { 322 } else {
346 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), 323 thumb_size = gfx::Size(scrollbar_->ThumbThickness(),
347 scrollbar_->ThumbLength()); 324 scrollbar_->ThumbLength());
348 } 325 }
349 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); 326 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
350 } 327 }
351 328
352 } // namespace cc 329 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698