Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay()); | 122 // wjm: remove this? |
|
enne (OOO)
2013/08/12 23:15:01
No. Mac can have overlay scrollbars that are not
wjmaclean
2013/08/14 18:19:44
Done.
| |
| 123 // scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay()); | |
| 142 | 124 |
| 143 // ScrollbarLayer must push properties every frame. crbug.com/259095 | 125 // ScrollbarLayer must push properties every frame. crbug.com/259095 |
| 144 needs_push_properties_ = true; | 126 needs_push_properties_ = true; |
| 145 } | 127 } |
| 146 | 128 |
| 147 ScrollbarLayer* ScrollbarLayer::ToScrollbarLayer() { | |
| 148 return this; | |
| 149 } | |
| 150 | |
| 151 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { | 129 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 152 if (!host || host != layer_tree_host()) { | 130 if (!host || host != layer_tree_host()) { |
| 153 track_updater_ = NULL; | 131 track_updater_ = NULL; |
| 154 track_.reset(); | 132 track_.reset(); |
| 155 thumb_updater_ = NULL; | 133 thumb_updater_ = NULL; |
| 156 thumb_.reset(); | 134 thumb_.reset(); |
| 157 } | 135 } |
| 158 | 136 |
| 159 ContentsScalingLayer::SetLayerTreeHost(host); | 137 ContentsScalingLayer::SetLayerTreeHost(host); |
| 160 } | 138 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 172 gfx::RectF* opaque) OVERRIDE { | 150 gfx::RectF* opaque) OVERRIDE { |
| 173 scrollbar_->PaintPart(canvas, part_, content_rect); | 151 scrollbar_->PaintPart(canvas, part_, content_rect); |
| 174 } | 152 } |
| 175 | 153 |
| 176 private: | 154 private: |
| 177 Scrollbar* scrollbar_; | 155 Scrollbar* scrollbar_; |
| 178 ScrollbarPart part_; | 156 ScrollbarPart part_; |
| 179 }; | 157 }; |
| 180 | 158 |
| 181 void ScrollbarLayer::CreateUpdaterIfNeeded() { | 159 void ScrollbarLayer::CreateUpdaterIfNeeded() { |
| 182 if (layer_tree_host()->settings().solid_color_scrollbars) | |
| 183 return; | |
| 184 | |
| 185 texture_format_ = | 160 texture_format_ = |
| 186 layer_tree_host()->GetRendererCapabilities().best_texture_format; | 161 layer_tree_host()->GetRendererCapabilities().best_texture_format; |
| 187 | 162 |
| 188 if (!track_updater_.get()) { | 163 if (!track_updater_.get()) { |
| 189 track_updater_ = CachingBitmapContentLayerUpdater::Create( | 164 track_updater_ = CachingBitmapContentLayerUpdater::Create( |
| 190 scoped_ptr<LayerPainter>( | 165 scoped_ptr<LayerPainter>( |
| 191 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) | 166 new ScrollbarPartPainter(scrollbar_.get(), TRACK)) |
| 192 .Pass(), | 167 .Pass(), |
| 193 rendering_stats_instrumentation(), | 168 rendering_stats_instrumentation(), |
| 194 id()); | 169 id()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 209 if (!thumb_ && scrollbar_->HasThumb()) { | 184 if (!thumb_ && scrollbar_->HasThumb()) { |
| 210 thumb_ = thumb_updater_->CreateResource( | 185 thumb_ = thumb_updater_->CreateResource( |
| 211 layer_tree_host()->contents_texture_manager()); | 186 layer_tree_host()->contents_texture_manager()); |
| 212 } | 187 } |
| 213 } | 188 } |
| 214 | 189 |
| 215 bool ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, | 190 bool ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, |
| 216 LayerUpdater::Resource* resource, | 191 LayerUpdater::Resource* resource, |
| 217 gfx::Rect rect, | 192 gfx::Rect rect, |
| 218 ResourceUpdateQueue* queue) { | 193 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 | 194 // Skip painting and uploading if there are no invalidations and |
| 223 // we already have valid texture data. | 195 // we already have valid texture data. |
| 224 if (resource->texture()->have_backing_texture() && | 196 if (resource->texture()->have_backing_texture() && |
| 225 resource->texture()->size() == rect.size() && | 197 resource->texture()->size() == rect.size() && |
| 226 !is_dirty()) | 198 !is_dirty()) |
| 227 return false; | 199 return false; |
| 228 | 200 |
| 229 // We should always have enough memory for UI. | 201 // We should always have enough memory for UI. |
| 230 DCHECK(resource->texture()->can_acquire_backing_texture()); | 202 DCHECK(resource->texture()->can_acquire_backing_texture()); |
| 231 if (!resource->texture()->can_acquire_backing_texture()) | 203 if (!resource->texture()->can_acquire_backing_texture()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 layer_rect, contents_scale_y(), contents_scale_y()); | 236 layer_rect, contents_scale_y(), contents_scale_y()); |
| 265 // We should never return a rect bigger than the content_bounds(). | 237 // We should never return a rect bigger than the content_bounds(). |
| 266 gfx::Size clamped_size = expanded_rect.size(); | 238 gfx::Size clamped_size = expanded_rect.size(); |
| 267 clamped_size.SetToMin(content_bounds()); | 239 clamped_size.SetToMin(content_bounds()); |
| 268 expanded_rect.set_size(clamped_size); | 240 expanded_rect.set_size(clamped_size); |
| 269 return expanded_rect; | 241 return expanded_rect; |
| 270 } | 242 } |
| 271 | 243 |
| 272 void ScrollbarLayer::SetTexturePriorities( | 244 void ScrollbarLayer::SetTexturePriorities( |
| 273 const PriorityCalculator& priority_calc) { | 245 const PriorityCalculator& priority_calc) { |
| 274 if (layer_tree_host()->settings().solid_color_scrollbars) | |
| 275 return; | |
| 276 | |
| 277 if (content_bounds().IsEmpty()) | 246 if (content_bounds().IsEmpty()) |
| 278 return; | 247 return; |
| 279 DCHECK_LE(content_bounds().width(), MaxTextureSize()); | 248 DCHECK_LE(content_bounds().width(), MaxTextureSize()); |
| 280 DCHECK_LE(content_bounds().height(), MaxTextureSize()); | 249 DCHECK_LE(content_bounds().height(), MaxTextureSize()); |
| 281 | 250 |
| 282 CreateUpdaterIfNeeded(); | 251 CreateUpdaterIfNeeded(); |
| 283 | 252 |
| 284 bool draws_to_root = !render_target()->parent(); | 253 bool draws_to_root = !render_target()->parent(); |
| 285 if (track_) { | 254 if (track_) { |
| 286 track_->texture()->SetDimensions(content_bounds(), texture_format_); | 255 track_->texture()->SetDimensions(content_bounds(), texture_format_); |
| 287 track_->texture()->set_request_priority( | 256 track_->texture()->set_request_priority( |
| 288 PriorityCalculator::UIPriority(draws_to_root)); | 257 PriorityCalculator::UIPriority(draws_to_root)); |
| 289 } | 258 } |
| 290 if (thumb_) { | 259 if (thumb_) { |
| 291 gfx::Size thumb_size = OriginThumbRect().size(); | 260 gfx::Size thumb_size = OriginThumbRect().size(); |
| 292 thumb_->texture()->SetDimensions(thumb_size, texture_format_); | 261 thumb_->texture()->SetDimensions(thumb_size, texture_format_); |
| 293 thumb_->texture()->set_request_priority( | 262 thumb_->texture()->set_request_priority( |
| 294 PriorityCalculator::UIPriority(draws_to_root)); | 263 PriorityCalculator::UIPriority(draws_to_root)); |
| 295 } | 264 } |
| 296 } | 265 } |
| 297 | 266 |
| 298 bool ScrollbarLayer::Update(ResourceUpdateQueue* queue, | 267 bool ScrollbarLayer::Update(ResourceUpdateQueue* queue, |
| 299 const OcclusionTracker* occlusion) { | 268 const OcclusionTracker* occlusion) { |
| 300 track_rect_ = scrollbar_->TrackRect(); | 269 track_rect_ = scrollbar_->TrackRect(); |
| 301 | 270 |
| 302 if (layer_tree_host()->settings().solid_color_scrollbars) | 271 // WJM: is this specific to solid color scrollbars? probably!! |
| 303 return false; | |
| 304 | |
| 305 bool updated = false; | 272 bool updated = false; |
| 306 | 273 |
| 307 { | 274 { |
| 308 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 275 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
| 309 true); | 276 true); |
| 310 updated = ContentsScalingLayer::Update(queue, occlusion); | 277 updated = ContentsScalingLayer::Update(queue, occlusion); |
| 311 } | 278 } |
| 312 | 279 |
| 313 dirty_rect_.Union(update_rect_); | 280 dirty_rect_.Union(update_rect_); |
| 314 if (content_bounds().IsEmpty()) | 281 if (content_bounds().IsEmpty()) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 332 origin_thumb_rect, queue); | 299 origin_thumb_rect, queue); |
| 333 } | 300 } |
| 334 } | 301 } |
| 335 | 302 |
| 336 dirty_rect_ = gfx::RectF(); | 303 dirty_rect_ = gfx::RectF(); |
| 337 return updated; | 304 return updated; |
| 338 } | 305 } |
| 339 | 306 |
| 340 gfx::Rect ScrollbarLayer::OriginThumbRect() const { | 307 gfx::Rect ScrollbarLayer::OriginThumbRect() const { |
| 341 gfx::Size thumb_size; | 308 gfx::Size thumb_size; |
| 342 if (Orientation() == HORIZONTAL) { | 309 if (orientation() == HORIZONTAL) { |
| 343 thumb_size = gfx::Size(scrollbar_->ThumbLength(), | 310 thumb_size = gfx::Size(scrollbar_->ThumbLength(), |
| 344 scrollbar_->ThumbThickness()); | 311 scrollbar_->ThumbThickness()); |
| 345 } else { | 312 } else { |
| 346 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), | 313 thumb_size = gfx::Size(scrollbar_->ThumbThickness(), |
| 347 scrollbar_->ThumbLength()); | 314 scrollbar_->ThumbLength()); |
| 348 } | 315 } |
| 349 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); | 316 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); |
| 350 } | 317 } |
| 351 | 318 |
| 352 } // namespace cc | 319 } // namespace cc |
| OLD | NEW |