| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 PaintedScrollbarLayer::PaintedScrollbarLayer(const LayerSettings& settings, | 42 PaintedScrollbarLayer::PaintedScrollbarLayer(const LayerSettings& settings, |
| 43 scoped_ptr<Scrollbar> scrollbar, | 43 scoped_ptr<Scrollbar> scrollbar, |
| 44 int scroll_layer_id) | 44 int scroll_layer_id) |
| 45 : Layer(settings), | 45 : Layer(settings), |
| 46 scrollbar_(scrollbar.Pass()), | 46 scrollbar_(scrollbar.Pass()), |
| 47 scroll_layer_id_(scroll_layer_id), | 47 scroll_layer_id_(scroll_layer_id), |
| 48 internal_contents_scale_(1.f), | 48 internal_contents_scale_(1.f), |
| 49 thumb_thickness_(scrollbar_->ThumbThickness()), | 49 thumb_thickness_(scrollbar_->ThumbThickness()), |
| 50 thumb_length_(scrollbar_->ThumbLength()), | 50 thumb_length_(scrollbar_->ThumbLength()), |
| 51 is_overlay_(scrollbar_->IsOverlay()), | 51 is_overlay_(scrollbar_->IsOverlay()), |
| 52 has_thumb_(scrollbar_->HasThumb()) { | 52 has_thumb_(scrollbar_->HasThumb()), |
| 53 track_opacity_(scrollbar_->TrackOpacity()), |
| 54 thumb_opacity_(scrollbar_->ThumbOpacity()) { |
| 53 if (!scrollbar_->IsOverlay()) | 55 if (!scrollbar_->IsOverlay()) |
| 54 SetShouldScrollOnMainThread(true); | 56 SetShouldScrollOnMainThread(true); |
| 55 } | 57 } |
| 56 | 58 |
| 57 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} | 59 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} |
| 58 | 60 |
| 59 int PaintedScrollbarLayer::ScrollLayerId() const { | 61 int PaintedScrollbarLayer::ScrollLayerId() const { |
| 60 return scroll_layer_id_; | 62 return scroll_layer_id_; |
| 61 } | 63 } |
| 62 | 64 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 122 |
| 121 if (track_resource_.get()) | 123 if (track_resource_.get()) |
| 122 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); | 124 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); |
| 123 else | 125 else |
| 124 scrollbar_layer->set_track_ui_resource_id(0); | 126 scrollbar_layer->set_track_ui_resource_id(0); |
| 125 if (thumb_resource_.get()) | 127 if (thumb_resource_.get()) |
| 126 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); | 128 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); |
| 127 else | 129 else |
| 128 scrollbar_layer->set_thumb_ui_resource_id(0); | 130 scrollbar_layer->set_thumb_ui_resource_id(0); |
| 129 | 131 |
| 132 scrollbar_layer->set_thumb_opacity(thumb_opacity_); |
| 133 scrollbar_layer->set_track_opacity(track_opacity_); |
| 134 |
| 130 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); | 135 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); |
| 131 } | 136 } |
| 132 | 137 |
| 133 ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { | 138 ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { |
| 134 return this; | 139 return this; |
| 135 } | 140 } |
| 136 | 141 |
| 137 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { | 142 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 138 // When the LTH is set to null or has changed, then this layer should remove | 143 // When the LTH is set to null or has changed, then this layer should remove |
| 139 // all of its associated resources. | 144 // all of its associated resources. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 242 |
| 238 if (!has_thumb_ && thumb_resource_) { | 243 if (!has_thumb_ && thumb_resource_) { |
| 239 thumb_resource_ = nullptr; | 244 thumb_resource_ = nullptr; |
| 240 SetNeedsPushProperties(); | 245 SetNeedsPushProperties(); |
| 241 updated = true; | 246 updated = true; |
| 242 } | 247 } |
| 243 | 248 |
| 244 if (update_rect_.IsEmpty() && track_resource_) | 249 if (update_rect_.IsEmpty() && track_resource_) |
| 245 return updated; | 250 return updated; |
| 246 | 251 |
| 247 track_resource_ = ScopedUIResource::Create( | 252 if (!track_resource_ || scrollbar_->NeedsPaintPart(TRACK)) { |
| 248 layer_tree_host(), | 253 track_resource_ = ScopedUIResource::Create( |
| 249 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); | 254 layer_tree_host(), |
| 255 RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK)); |
| 256 } |
| 257 track_opacity_ = scrollbar_->TrackOpacity(); |
| 250 | 258 |
| 251 gfx::Rect thumb_layer_rect = OriginThumbRect(); | 259 gfx::Rect thumb_layer_rect = OriginThumbRect(); |
| 252 gfx::Rect scaled_thumb_rect = | 260 gfx::Rect scaled_thumb_rect = |
| 253 ScrollbarLayerRectToContentRect(thumb_layer_rect); | 261 ScrollbarLayerRectToContentRect(thumb_layer_rect); |
| 254 if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { | 262 if (has_thumb_ && !scaled_thumb_rect.IsEmpty()) { |
| 255 thumb_resource_ = ScopedUIResource::Create( | 263 if (!thumb_resource_ || scrollbar_->NeedsPaintPart(THUMB)) { |
| 256 layer_tree_host(), | 264 thumb_resource_ = ScopedUIResource::Create( |
| 257 RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); | 265 layer_tree_host(), |
| 266 RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB)); |
| 267 } |
| 268 thumb_opacity_ = scrollbar_->ThumbOpacity(); |
| 258 } | 269 } |
| 259 | 270 |
| 260 // UI resources changed so push properties is needed. | 271 // UI resources changed so push properties is needed. |
| 261 SetNeedsPushProperties(); | 272 SetNeedsPushProperties(); |
| 262 updated = true; | 273 updated = true; |
| 263 return updated; | 274 return updated; |
| 264 } | 275 } |
| 265 | 276 |
| 266 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 277 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
| 267 const gfx::Rect& layer_rect, | 278 const gfx::Rect& layer_rect, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 293 | 304 |
| 294 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 305 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
| 295 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 306 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 296 // allocation and copying. | 307 // allocation and copying. |
| 297 skbitmap.setImmutable(); | 308 skbitmap.setImmutable(); |
| 298 | 309 |
| 299 return UIResourceBitmap(skbitmap); | 310 return UIResourceBitmap(skbitmap); |
| 300 } | 311 } |
| 301 | 312 |
| 302 } // namespace cc | 313 } // namespace cc |
| OLD | NEW |