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