xingliu | e43518a | 2016-07-28 23:59:47 | [diff] [blame^] | 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 | #ifndef CC_TREES_LAYER_TREE_H_ |
| 6 | #define CC_TREES_LAYER_TREE_H_ |
| 7 | |
| 8 | #include <unordered_map> |
| 9 | #include <unordered_set> |
| 10 | |
| 11 | #include "base/macros.h" |
| 12 | #include "cc/base/cc_export.h" |
| 13 | |
| 14 | namespace cc { |
| 15 | |
| 16 | namespace proto { |
| 17 | class LayerTree; |
| 18 | class LayerUpdate; |
| 19 | } |
| 20 | |
| 21 | class AnimationHost; |
| 22 | class Layer; |
| 23 | |
| 24 | class CC_EXPORT LayerTree { |
| 25 | public: |
| 26 | using LayerSet = std::unordered_set<Layer*>; |
| 27 | using LayerIdMap = std::unordered_map<int, Layer*>; |
| 28 | |
| 29 | explicit LayerTree(std::unique_ptr<AnimationHost> animation_host); |
| 30 | ~LayerTree(); |
| 31 | |
| 32 | void RegisterLayer(Layer* layer); |
| 33 | void UnregisterLayer(Layer* layer); |
| 34 | Layer* LayerById(int id) const; |
| 35 | bool UpdateLayers(const LayerList& update_layer_list, |
| 36 | bool* content_is_suitable_for_gpu); |
| 37 | |
| 38 | void AddLayerShouldPushProperties(Layer* layer); |
| 39 | void RemoveLayerShouldPushProperties(Layer* layer); |
| 40 | std::unordered_set<Layer*>& LayersThatShouldPushProperties(); |
| 41 | bool LayerNeedsPushPropertiesForTesting(Layer* layer) const; |
| 42 | |
| 43 | void ToProtobuf(proto::LayerTree* proto); |
| 44 | void FromProtobuf(const proto::LayerTree& proto); |
| 45 | |
| 46 | AnimationHost* animation_host() const { return animation_host_.get(); } |
| 47 | |
| 48 | bool in_paint_layer_contents() const { return in_paint_layer_contents_; } |
| 49 | |
| 50 | private: |
| 51 | friend class LayerTreeHostSerializationTest; |
| 52 | |
| 53 | // Set of layers that need to push properties. |
| 54 | LayerSet layers_that_should_push_properties_; |
| 55 | |
| 56 | // Layer id to Layer map. |
| 57 | LayerIdMap layer_id_map_; |
| 58 | |
| 59 | bool in_paint_layer_contents_; |
| 60 | |
| 61 | std::unique_ptr<AnimationHost> animation_host_; |
| 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(LayerTree); |
| 64 | }; |
| 65 | |
| 66 | } // namespace cc |
| 67 | |
| 68 | #endif // CC_TREES_LAYER_TREE_H_ |