| 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 15 matching lines...) Expand all Loading... |
| 26 tree_impl, id(), scrollbar_->Orientation()).PassAs<LayerImpl>(); | 26 tree_impl, id(), scrollbar_->Orientation()).PassAs<LayerImpl>(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( | 29 scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( |
| 30 scoped_ptr<Scrollbar> scrollbar, | 30 scoped_ptr<Scrollbar> scrollbar, |
| 31 int scroll_layer_id) { | 31 int scroll_layer_id) { |
| 32 return make_scoped_refptr( | 32 return make_scoped_refptr( |
| 33 new PaintedScrollbarLayer(scrollbar.Pass(), scroll_layer_id)); | 33 new PaintedScrollbarLayer(scrollbar.Pass(), scroll_layer_id)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 PaintedScrollbarLayer::PaintedScrollbarLayer( | 36 PaintedScrollbarLayer::PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, |
| 37 scoped_ptr<Scrollbar> scrollbar, | 37 int scroll_layer_id) |
| 38 int scroll_layer_id) | |
| 39 : scrollbar_(scrollbar.Pass()), | 38 : scrollbar_(scrollbar.Pass()), |
| 40 scroll_layer_id_(scroll_layer_id), | 39 scroll_layer_id_(scroll_layer_id), |
| 40 clip_layer_id_(Layer::INVALID_ID), |
| 41 thumb_thickness_(scrollbar_->ThumbThickness()), | 41 thumb_thickness_(scrollbar_->ThumbThickness()), |
| 42 thumb_length_(scrollbar_->ThumbLength()), | 42 thumb_length_(scrollbar_->ThumbLength()), |
| 43 is_overlay_(scrollbar_->IsOverlay()), | 43 is_overlay_(scrollbar_->IsOverlay()), |
| 44 has_thumb_(scrollbar_->HasThumb()) { | 44 has_thumb_(scrollbar_->HasThumb()) { |
| 45 if (!scrollbar_->IsOverlay()) | 45 if (!scrollbar_->IsOverlay()) |
| 46 SetShouldScrollOnMainThread(true); | 46 SetShouldScrollOnMainThread(true); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} | 49 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} |
| 50 | 50 |
| 51 int PaintedScrollbarLayer::ScrollLayerId() const { | 51 int PaintedScrollbarLayer::ScrollLayerId() const { |
| 52 return scroll_layer_id_; | 52 return scroll_layer_id_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void PaintedScrollbarLayer::SetScrollLayerId(int id) { | 55 void PaintedScrollbarLayer::SetScrollLayer(int layer_id) { |
| 56 if (id == scroll_layer_id_) | 56 if (layer_id == scroll_layer_id_) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 scroll_layer_id_ = id; | 59 scroll_layer_id_ = layer_id; |
| 60 SetNeedsFullTreeSync(); | 60 SetNeedsFullTreeSync(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void PaintedScrollbarLayer::SetClipLayer(int layer_id) { |
| 64 if (layer_id == clip_layer_id_) |
| 65 return; |
| 66 |
| 67 clip_layer_id_ = layer_id; |
| 68 SetNeedsFullTreeSync(); |
| 69 } |
| 70 |
| 63 bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const { | 71 bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const { |
| 64 return scrollbar_->IsOverlay(); | 72 return scrollbar_->IsOverlay(); |
| 65 } | 73 } |
| 66 | 74 |
| 67 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { | 75 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { |
| 68 return scrollbar_->Orientation(); | 76 return scrollbar_->Orientation(); |
| 69 } | 77 } |
| 70 | 78 |
| 71 int PaintedScrollbarLayer::MaxTextureSize() { | 79 int PaintedScrollbarLayer::MaxTextureSize() { |
| 72 DCHECK(layer_tree_host()); | 80 DCHECK(layer_tree_host()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 102 page_scale_factor, | 110 page_scale_factor, |
| 103 animating_transform_to_screen, | 111 animating_transform_to_screen, |
| 104 contents_scale_x, | 112 contents_scale_x, |
| 105 contents_scale_y, | 113 contents_scale_y, |
| 106 content_bounds); | 114 content_bounds); |
| 107 } | 115 } |
| 108 | 116 |
| 109 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 117 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
| 110 ContentsScalingLayer::PushPropertiesTo(layer); | 118 ContentsScalingLayer::PushPropertiesTo(layer); |
| 111 | 119 |
| 120 PushScrollClipPropertiesTo(layer); |
| 121 |
| 112 PaintedScrollbarLayerImpl* scrollbar_layer = | 122 PaintedScrollbarLayerImpl* scrollbar_layer = |
| 113 static_cast<PaintedScrollbarLayerImpl*>(layer); | 123 static_cast<PaintedScrollbarLayerImpl*>(layer); |
| 114 | 124 |
| 115 scrollbar_layer->SetThumbThickness(thumb_thickness_); | 125 scrollbar_layer->SetThumbThickness(thumb_thickness_); |
| 116 scrollbar_layer->SetThumbLength(thumb_length_); | 126 scrollbar_layer->SetThumbLength(thumb_length_); |
| 117 if (orientation() == HORIZONTAL) { | 127 if (orientation() == HORIZONTAL) { |
| 118 scrollbar_layer->SetTrackStart( | 128 scrollbar_layer->SetTrackStart( |
| 119 track_rect_.x() - location_.x()); | 129 track_rect_.x() - location_.x()); |
| 120 scrollbar_layer->SetTrackLength(track_rect_.width()); | 130 scrollbar_layer->SetTrackLength(track_rect_.width()); |
| 121 } else { | 131 } else { |
| 122 scrollbar_layer->SetTrackStart( | 132 scrollbar_layer->SetTrackStart( |
| 123 track_rect_.y() - location_.y()); | 133 track_rect_.y() - location_.y()); |
| 124 scrollbar_layer->SetTrackLength(track_rect_.height()); | 134 scrollbar_layer->SetTrackLength(track_rect_.height()); |
| 125 } | 135 } |
| 126 | 136 |
| 127 if (track_resource_.get()) | 137 if (track_resource_.get()) |
| 128 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); | 138 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); |
| 129 if (thumb_resource_.get()) | 139 if (thumb_resource_.get()) |
| 130 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); | 140 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); |
| 131 | 141 |
| 132 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); | 142 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_); |
| 133 } | 143 } |
| 134 | 144 |
| 135 ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { | 145 ScrollbarLayerInterface* PaintedScrollbarLayer::ToScrollbarLayer() { |
| 136 return this; | 146 return this; |
| 137 } | 147 } |
| 138 | 148 |
| 149 void PaintedScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { |
| 150 PaintedScrollbarLayerImpl* scrollbar_layer = |
| 151 static_cast<PaintedScrollbarLayerImpl*>(layer); |
| 152 |
| 153 scrollbar_layer->SetScrollLayerById(scroll_layer_id_); |
| 154 scrollbar_layer->SetClipLayerById(clip_layer_id_); |
| 155 } |
| 156 |
| 139 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { | 157 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 140 // When the LTH is set to null or has changed, then this layer should remove | 158 // When the LTH is set to null or has changed, then this layer should remove |
| 141 // all of its associated resources. | 159 // all of its associated resources. |
| 142 if (!host || host != layer_tree_host()) { | 160 if (!host || host != layer_tree_host()) { |
| 143 track_resource_.reset(); | 161 track_resource_.reset(); |
| 144 thumb_resource_.reset(); | 162 thumb_resource_.reset(); |
| 145 } | 163 } |
| 146 | 164 |
| 147 ContentsScalingLayer::SetLayerTreeHost(host); | 165 ContentsScalingLayer::SetLayerTreeHost(host); |
| 148 } | 166 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 259 |
| 242 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 260 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
| 243 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 261 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 244 // allocation and copying. | 262 // allocation and copying. |
| 245 skbitmap.setImmutable(); | 263 skbitmap.setImmutable(); |
| 246 | 264 |
| 247 return UIResourceBitmap(skbitmap); | 265 return UIResourceBitmap(skbitmap); |
| 248 } | 266 } |
| 249 | 267 |
| 250 } // namespace cc | 268 } // namespace cc |
| OLD | NEW |