| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ui/compositor/paint_context.h" | 31 #include "ui/compositor/paint_context.h" |
| 32 #include "ui/gfx/animation/animation.h" | 32 #include "ui/gfx/animation/animation.h" |
| 33 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
| 34 #include "ui/gfx/geometry/point3_f.h" | 34 #include "ui/gfx/geometry/point3_f.h" |
| 35 #include "ui/gfx/geometry/point_conversions.h" | 35 #include "ui/gfx/geometry/point_conversions.h" |
| 36 #include "ui/gfx/geometry/size_conversions.h" | 36 #include "ui/gfx/geometry/size_conversions.h" |
| 37 #include "ui/gfx/interpolated_transform.h" | 37 #include "ui/gfx/interpolated_transform.h" |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 static cc::ElementId g_next_element_id = 1; |
| 42 |
| 41 const ui::Layer* GetRoot(const ui::Layer* layer) { | 43 const ui::Layer* GetRoot(const ui::Layer* layer) { |
| 42 while (layer->parent()) | 44 while (layer->parent()) |
| 43 layer = layer->parent(); | 45 layer = layer->parent(); |
| 44 return layer; | 46 return layer; |
| 45 } | 47 } |
| 46 | 48 |
| 47 } // namespace | 49 } // namespace |
| 48 | 50 |
| 49 namespace ui { | 51 namespace ui { |
| 50 | 52 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 142 } |
| 141 | 143 |
| 142 void Layer::ResetCompositor() { | 144 void Layer::ResetCompositor() { |
| 143 DCHECK(!parent_); | 145 DCHECK(!parent_); |
| 144 if (compositor_) { | 146 if (compositor_) { |
| 145 ResetCompositorForAnimatorsInTree(compositor_); | 147 ResetCompositorForAnimatorsInTree(compositor_); |
| 146 compositor_ = nullptr; | 148 compositor_ = nullptr; |
| 147 } | 149 } |
| 148 } | 150 } |
| 149 | 151 |
| 152 cc::ElementId Layer::NextElementId() { |
| 153 return g_next_element_id++; |
| 154 } |
| 155 |
| 150 void Layer::Add(Layer* child) { | 156 void Layer::Add(Layer* child) { |
| 151 DCHECK(!child->compositor_); | 157 DCHECK(!child->compositor_); |
| 152 if (child->parent_) | 158 if (child->parent_) |
| 153 child->parent_->Remove(child); | 159 child->parent_->Remove(child); |
| 154 child->parent_ = this; | 160 child->parent_ = this; |
| 155 children_.push_back(child); | 161 children_.push_back(child); |
| 156 cc_layer_->AddChild(child->cc_layer_); | 162 cc_layer_->AddChild(child->cc_layer_); |
| 157 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 163 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 158 Compositor* compositor = GetCompositor(); | 164 Compositor* compositor = GetCompositor(); |
| 159 if (compositor) | 165 if (compositor) |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 if (type_ == LAYER_SOLID_COLOR) { | 962 if (type_ == LAYER_SOLID_COLOR) { |
| 957 solid_color_layer_ = cc::SolidColorLayer::Create(); | 963 solid_color_layer_ = cc::SolidColorLayer::Create(); |
| 958 cc_layer_ = solid_color_layer_.get(); | 964 cc_layer_ = solid_color_layer_.get(); |
| 959 } else if (type_ == LAYER_NINE_PATCH) { | 965 } else if (type_ == LAYER_NINE_PATCH) { |
| 960 nine_patch_layer_ = cc::NinePatchLayer::Create(); | 966 nine_patch_layer_ = cc::NinePatchLayer::Create(); |
| 961 cc_layer_ = nine_patch_layer_.get(); | 967 cc_layer_ = nine_patch_layer_.get(); |
| 962 } else { | 968 } else { |
| 963 content_layer_ = cc::PictureLayer::Create(this); | 969 content_layer_ = cc::PictureLayer::Create(this); |
| 964 cc_layer_ = content_layer_.get(); | 970 cc_layer_ = content_layer_.get(); |
| 965 } | 971 } |
| 972 cc_layer_->SetElementId(NextElementId()); |
| 966 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 973 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
| 967 cc_layer_->SetContentsOpaque(true); | 974 cc_layer_->SetContentsOpaque(true); |
| 968 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 975 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 969 cc_layer_->SetLayerClient(this); | 976 cc_layer_->SetLayerClient(this); |
| 970 RecomputePosition(); | 977 RecomputePosition(); |
| 971 } | 978 } |
| 972 | 979 |
| 973 gfx::Transform Layer::transform() const { | 980 gfx::Transform Layer::transform() const { |
| 974 return cc_layer_->transform(); | 981 return cc_layer_->transform(); |
| 975 } | 982 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 if (animator_) { | 1023 if (animator_) { |
| 1017 animator_->ResetCompositor(compositor); | 1024 animator_->ResetCompositor(compositor); |
| 1018 animator_->RemoveFromCollection(collection); | 1025 animator_->RemoveFromCollection(collection); |
| 1019 } | 1026 } |
| 1020 | 1027 |
| 1021 for (auto* child : children_) | 1028 for (auto* child : children_) |
| 1022 child->ResetCompositorForAnimatorsInTree(compositor); | 1029 child->ResetCompositorForAnimatorsInTree(compositor); |
| 1023 } | 1030 } |
| 1024 | 1031 |
| 1025 } // namespace ui | 1032 } // namespace ui |
| OLD | NEW |