OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/animation/animation_host.h" |
| 6 #include "cc/layers/layer.h" |
| 7 #include "cc/proto/layer_tree.pb.h" |
| 8 #include "cc/trees/layer_tree.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 LayerTree::LayerTree(std::unique_ptr<AnimationHost>* animation_host) |
| 13 : in_paint_layer_contents_(false), |
| 14 animation_host_(std::move(*animation_host)) { |
| 15 DCHECK(animation_host_); |
| 16 } |
| 17 |
| 18 LayerTree::~LayerTree() {} |
| 19 |
| 20 void LayerTree::RegisterLayer(Layer* layer) { |
| 21 DCHECK(!LayerById(layer->id())); |
| 22 DCHECK(!in_paint_layer_contents_); |
| 23 layer_id_map_[layer->id()] = layer; |
| 24 if (layer->element_id()) { |
| 25 animation_host_->RegisterElement(layer->element_id(), |
| 26 ElementListType::ACTIVE); |
| 27 } |
| 28 } |
| 29 |
| 30 void LayerTree::UnregisterLayer(Layer* layer) { |
| 31 DCHECK(LayerById(layer->id())); |
| 32 DCHECK(!in_paint_layer_contents_); |
| 33 if (layer->element_id()) { |
| 34 animation_host_->UnregisterElement(layer->element_id(), |
| 35 ElementListType::ACTIVE); |
| 36 } |
| 37 RemoveLayerShouldPushProperties(layer); |
| 38 layer_id_map_.erase(layer->id()); |
| 39 } |
| 40 |
| 41 Layer* LayerTree::LayerById(int id) const { |
| 42 LayerIdMap::const_iterator iter = layer_id_map_.find(id); |
| 43 return iter != layer_id_map_.end() ? iter->second : nullptr; |
| 44 } |
| 45 |
| 46 void LayerTree::AddLayerShouldPushProperties(Layer* layer) { |
| 47 layers_that_should_push_properties_.insert(layer); |
| 48 } |
| 49 |
| 50 void LayerTree::RemoveLayerShouldPushProperties(Layer* layer) { |
| 51 layers_that_should_push_properties_.erase(layer); |
| 52 } |
| 53 |
| 54 std::unordered_set<Layer*>& LayerTree::LayersThatShouldPushProperties() { |
| 55 return layers_that_should_push_properties_; |
| 56 } |
| 57 |
| 58 void LayerTree::ToProtobuf(proto::LayerTree* proto) { |
| 59 for (auto layer : layers_that_should_push_properties_) { |
| 60 proto->add_layers_that_should_push_properties(layer->id()); |
| 61 } |
| 62 proto->set_in_paint_layer_contents(in_paint_layer_contents()); |
| 63 } |
| 64 |
| 65 void LayerTree::FromProtobuf(const proto::LayerTree& proto) { |
| 66 for (auto layer_id : proto.layers_that_should_push_properties()) { |
| 67 AddLayerShouldPushProperties(layer_id_map_[layer_id]); |
| 68 } |
| 69 in_paint_layer_contents_ = proto.in_paint_layer_contents(); |
| 70 } |
| 71 |
| 72 void LayerTree::set_in_paint_layer_contents(bool value) { |
| 73 in_paint_layer_contents_ = value; |
| 74 } |
| 75 |
| 76 } // namespace cc |
OLD | NEW |