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