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 needs_update = false; | |
|
danakj
2014/09/11 20:12:56
nit: updated
MuVen
2014/09/12 14:09:12
Done.
| |
| 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 needs_update = true; | |
| 220 } | |
| 221 return needs_update; | |
| 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(); | |
| 227 needs_update = true; | |
| 228 return needs_update; | |
|
danakj
2014/09/11 20:12:56
not supposed to return here, you have a track rect
MuVen
2014/09/12 14:09:12
Done.
On 2014/09/11 20:12:56, danakj wrote:
| |
| 229 } | |
| 211 | 230 |
| 212 { | 231 { |
| 213 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 232 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
| 214 true); | 233 true); |
| 215 ContentsScalingLayer::Update(queue, occlusion); | 234 ContentsScalingLayer::Update(queue, occlusion); |
| 216 } | 235 } |
| 217 | 236 |
| 218 if (update_rect_.IsEmpty() && track_resource_) | 237 if (update_rect_.IsEmpty() && track_resource_) |
| 219 return false; | 238 return needs_update; |
| 220 | 239 |
| 221 track_resource_ = ScopedUIResource::Create( | 240 track_resource_ = ScopedUIResource::Create( |
| 222 layer_tree_host(), | 241 layer_tree_host(), |
| 223 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); | 242 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); |
| 224 | 243 |
| 225 gfx::Rect thumb_layer_rect = OriginThumbRect(); | 244 gfx::Rect thumb_layer_rect = OriginThumbRect(); |
| 226 gfx::Rect scaled_thumb_rect = | 245 gfx::Rect scaled_thumb_rect = |
| 227 ScrollbarLayerRectToContentRect(thumb_layer_rect); | 246 ScrollbarLayerRectToContentRect(thumb_layer_rect); |
| 228 if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { | 247 if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { |
| 229 thumb_resource_ = ScopedUIResource::Create( | 248 thumb_resource_ = ScopedUIResource::Create( |
| 230 layer_tree_host(), | 249 layer_tree_host(), |
| 231 RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); | 250 RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); |
| 232 } | 251 } |
| 233 | 252 |
| 234 // UI resources changed so push properties is needed. | 253 // UI resources changed so push properties is needed. |
| 235 SetNeedsPushProperties(); | 254 SetNeedsPushProperties(); |
| 236 return true; | 255 needs_update = true; |
| 256 return needs_update; | |
| 237 } | 257 } |
| 238 | 258 |
| 239 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 259 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
| 240 const gfx::Rect& layer_rect, | 260 const gfx::Rect& layer_rect, |
| 241 const gfx::Rect& content_rect, | 261 const gfx::Rect& content_rect, |
| 242 ScrollbarPart part) { | 262 ScrollbarPart part) { |
| 243 DCHECK(!content_rect.size().IsEmpty()); | 263 DCHECK(!content_rect.size().IsEmpty()); |
| 244 DCHECK(!layer_rect.size().IsEmpty()); | 264 DCHECK(!layer_rect.size().IsEmpty()); |
| 245 | 265 |
| 246 SkBitmap skbitmap; | 266 SkBitmap skbitmap; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 266 | 286 |
| 267 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 287 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
| 268 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 288 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 269 // allocation and copying. | 289 // allocation and copying. |
| 270 skbitmap.setImmutable(); | 290 skbitmap.setImmutable(); |
| 271 | 291 |
| 272 return UIResourceBitmap(skbitmap); | 292 return UIResourceBitmap(skbitmap); |
| 273 } | 293 } |
| 274 | 294 |
| 275 } // namespace cc | 295 } // namespace cc |
| OLD | NEW |