| 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" |
| 11 #include "cc/resources/ui_resource_bitmap.h" | 11 #include "cc/resources/ui_resource_bitmap.h" |
| 12 #include "cc/trees/layer_tree_host.h" | 12 #include "cc/trees/layer_tree_host.h" |
| 13 #include "cc/trees/layer_tree_impl.h" | 13 #include "cc/trees/layer_tree_impl.h" |
| 14 #include "skia/ext/platform_canvas.h" | 14 #include "skia/ext/platform_canvas.h" |
| 15 #include "skia/ext/refptr.h" | 15 #include "skia/ext/refptr.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkSize.h" | 18 #include "third_party/skia/include/core/SkSize.h" |
| 19 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 20 | 20 |
| 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()); |
| 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(scoped_ptr<Scrollbar> scrollbar, | 36 PaintedScrollbarLayer::PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 static_cast<PaintedScrollbarLayerImpl*>(layer); | 149 static_cast<PaintedScrollbarLayerImpl*>(layer); |
| 150 | 150 |
| 151 scrollbar_layer->SetScrollLayerAndClipLayerByIds(scroll_layer_id_, | 151 scrollbar_layer->SetScrollLayerAndClipLayerByIds(scroll_layer_id_, |
| 152 clip_layer_id_); | 152 clip_layer_id_); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { | 155 void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 156 // When the LTH is set to null or has changed, then this layer should remove | 156 // When the LTH is set to null or has changed, then this layer should remove |
| 157 // all of its associated resources. | 157 // all of its associated resources. |
| 158 if (!host || host != layer_tree_host()) { | 158 if (!host || host != layer_tree_host()) { |
| 159 track_resource_.reset(); | 159 track_resource_ = nullptr; |
| 160 thumb_resource_.reset(); | 160 thumb_resource_ = nullptr; |
| 161 } | 161 } |
| 162 | 162 |
| 163 ContentsScalingLayer::SetLayerTreeHost(host); | 163 ContentsScalingLayer::SetLayerTreeHost(host); |
| 164 } | 164 } |
| 165 | 165 |
| 166 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( | 166 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( |
| 167 const gfx::Rect& layer_rect) const { | 167 const gfx::Rect& layer_rect) const { |
| 168 // Don't intersect with the bounds as in LayerRectToContentRect() because | 168 // Don't intersect with the bounds as in LayerRectToContentRect() because |
| 169 // layer_rect here might be in coordinates of the containing layer. | 169 // layer_rect here might be in coordinates of the containing layer. |
| 170 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( | 170 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 UpdateThumbAndTrackGeometry(); | 207 UpdateThumbAndTrackGeometry(); |
| 208 | 208 |
| 209 gfx::Rect track_layer_rect = gfx::Rect(location_, bounds()); | 209 gfx::Rect track_layer_rect = gfx::Rect(location_, bounds()); |
| 210 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( | 210 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( |
| 211 track_layer_rect); | 211 track_layer_rect); |
| 212 | 212 |
| 213 bool updated = false; | 213 bool updated = false; |
| 214 | 214 |
| 215 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) { | 215 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) { |
| 216 if (track_resource_) { | 216 if (track_resource_) { |
| 217 track_resource_.reset(); | 217 track_resource_ = nullptr; |
| 218 if (thumb_resource_) | 218 thumb_resource_ = nullptr; |
| 219 thumb_resource_.reset(); | |
| 220 SetNeedsPushProperties(); | 219 SetNeedsPushProperties(); |
| 221 updated = true; | 220 updated = true; |
| 222 } | 221 } |
| 223 return updated; | 222 return updated; |
| 224 } | 223 } |
| 225 | 224 |
| 226 if (!has_thumb_ && thumb_resource_) { | 225 if (!has_thumb_ && thumb_resource_) { |
| 227 thumb_resource_.reset(); | 226 thumb_resource_ = nullptr; |
| 228 SetNeedsPushProperties(); | 227 SetNeedsPushProperties(); |
| 229 } | 228 } |
| 230 | 229 |
| 231 { | 230 { |
| 232 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 231 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
| 233 true); | 232 true); |
| 234 ContentsScalingLayer::Update(queue, occlusion); | 233 ContentsScalingLayer::Update(queue, occlusion); |
| 235 } | 234 } |
| 236 | 235 |
| 237 if (update_rect_.IsEmpty() && track_resource_) | 236 if (update_rect_.IsEmpty() && track_resource_) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 285 |
| 287 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 286 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
| 288 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 287 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 289 // allocation and copying. | 288 // allocation and copying. |
| 290 skbitmap.setImmutable(); | 289 skbitmap.setImmutable(); |
| 291 | 290 |
| 292 return UIResourceBitmap(skbitmap); | 291 return UIResourceBitmap(skbitmap); |
| 293 } | 292 } |
| 294 | 293 |
| 295 } // namespace cc | 294 } // namespace cc |
| OLD | NEW |