Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/painted_scrollbar_layer.h" | 5 #include "cc/layers/painted_scrollbar_layer.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 track_rect_.x() - location_.x()); | 123 track_rect_.x() - location_.x()); |
| 124 scrollbar_layer->SetTrackLength(track_rect_.width()); | 124 scrollbar_layer->SetTrackLength(track_rect_.width()); |
| 125 } else { | 125 } else { |
| 126 scrollbar_layer->SetTrackStart( | 126 scrollbar_layer->SetTrackStart( |
| 127 track_rect_.y() - location_.y()); | 127 track_rect_.y() - location_.y()); |
| 128 scrollbar_layer->SetTrackLength(track_rect_.height()); | 128 scrollbar_layer->SetTrackLength(track_rect_.height()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (track_resource_.get()) | 131 if (track_resource_.get()) |
| 132 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); | 132 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); |
| 133 else | |
| 134 scrollbar_layer->set_track_ui_resource_id(0); | |
| 133 if (thumb_resource_.get()) | 135 if (thumb_resource_.get()) |
| 134 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); | 136 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); |
| 137 else | |
| 138 scrollbar_layer->set_thumb_ui_resource_id(0); | |
| 135 | 139 |
| 136 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); | 140 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); |
| 137 } | 141 } |
| 138 | 142 |
| 139 ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { | 143 ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { |
| 140 return this; | 144 return this; |
| 141 } | 145 } |
| 142 | 146 |
| 143 void PaintedScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { | 147 void PaintedScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { |
| 144 PaintedScrollbarLayerImpl* scrollbar_layer = | 148 PaintedScrollbarLayerImpl* scrollbar_layer = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 | 204 |
| 201 bool PaintedScrollbarLayer::Update(ResourceUpdateQueue* queue, | 205 bool PaintedScrollbarLayer::Update(ResourceUpdateQueue* queue, |
| 202 const OcclusionTracker<Layer>* occlusion) { | 206 const OcclusionTracker<Layer>* occlusion) { |
| 203 UpdateThumbAndTrackGeometry(); | 207 UpdateThumbAndTrackGeometry(); |
| 204 | 208 |
| 205 gfx::Rect track_layer_rect = gfx::Rect(location_, bounds()); | 209 gfx::Rect track_layer_rect = gfx::Rect(location_, bounds()); |
| 206 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( | 210 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( |
| 207 track_layer_rect); | 211 track_layer_rect); |
| 212 bool updated = false; | |
| 213 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) { | |
| 214 if (track_resource_) { | |
| 215 track_resource_.reset(); | |
| 216 if (thumb_resource_) | |
| 217 thumb_resource_.reset(); | |
| 218 SetNeedsPushProperties(); | |
| 219 updated = true; | |
| 220 } | |
| 221 return updated; | |
| 222 } | |
| 208 | 223 |
| 209 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) | 224 if (!has_thumb_ && thumb_resource_) { |
| 210 return false; | 225 thumb_resource_.reset(); |
| 226 SetNeedsPushProperties(); | |
|
danakj
2014/09/15 18:16:27
Thanks, can you add a test that will exercise this
MuVen
2014/09/16 13:34:31
Done.
| |
| 227 } | |
| 211 | 228 |
| 212 { | 229 { |
| 213 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 230 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
| 214 true); | 231 true); |
| 215 ContentsScalingLayer::Update(queue, occlusion); | 232 ContentsScalingLayer::Update(queue, occlusion); |
| 216 } | 233 } |
| 217 | 234 |
| 218 if (update_rect_.IsEmpty() && track_resource_) | 235 if (update_rect_.IsEmpty() && track_resource_) |
| 219 return false; | 236 return updated; |
| 220 | 237 |
| 221 track_resource_ = ScopedUIResource::Create( | 238 track_resource_ = ScopedUIResource::Create( |
| 222 layer_tree_host(), | 239 layer_tree_host(), |
| 223 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); | 240 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); |
| 224 | 241 |
| 225 gfx::Rect thumb_layer_rect = OriginThumbRect(); | 242 gfx::Rect thumb_layer_rect = OriginThumbRect(); |
| 226 gfx::Rect scaled_thumb_rect = | 243 gfx::Rect scaled_thumb_rect = |
| 227 ScrollbarLayerRectToContentRect(thumb_layer_rect); | 244 ScrollbarLayerRectToContentRect(thumb_layer_rect); |
| 228 if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { | 245 if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { |
| 229 thumb_resource_ = ScopedUIResource::Create( | 246 thumb_resource_ = ScopedUIResource::Create( |
| 230 layer_tree_host(), | 247 layer_tree_host(), |
| 231 RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); | 248 RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); |
| 232 } | 249 } |
| 233 | 250 |
| 234 // UI resources changed so push properties is needed. | 251 // UI resources changed so push properties is needed. |
| 235 SetNeedsPushProperties(); | 252 SetNeedsPushProperties(); |
| 236 return true; | 253 updated = true; |
| 254 return updated; | |
| 237 } | 255 } |
| 238 | 256 |
| 239 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 257 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
| 240 const gfx::Rect& layer_rect, | 258 const gfx::Rect& layer_rect, |
| 241 const gfx::Rect& content_rect, | 259 const gfx::Rect& content_rect, |
| 242 ScrollbarPart part) { | 260 ScrollbarPart part) { |
| 243 DCHECK(!content_rect.size().IsEmpty()); | 261 DCHECK(!content_rect.size().IsEmpty()); |
| 244 DCHECK(!layer_rect.size().IsEmpty()); | 262 DCHECK(!layer_rect.size().IsEmpty()); |
| 245 | 263 |
| 246 SkBitmap skbitmap; | 264 SkBitmap skbitmap; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 266 | 284 |
| 267 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 285 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
| 268 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 286 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 269 // allocation and copying. | 287 // allocation and copying. |
| 270 skbitmap.setImmutable(); | 288 skbitmap.setImmutable(); |
| 271 | 289 |
| 272 return UIResourceBitmap(skbitmap); | 290 return UIResourceBitmap(skbitmap); |
| 273 } | 291 } |
| 274 | 292 |
| 275 } // namespace cc | 293 } // namespace cc |
| OLD | NEW |