[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 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 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/tree_synchronizer.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 9 | #include <set> |
| 10 | |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 11 | #include "base/logging.h" |
primiano | c06e238 | 2015-01-28 04:21:49 | [diff] [blame] | 12 | #include "base/trace_event/trace_event.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/layer.h" |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 14 | #include "cc/layers/layer_collections.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 15 | #include "cc/layers/layer_impl.h" |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 16 | #include "cc/trees/layer_tree_host.h" |
| 17 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 19 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 21 | template <typename LayerTreeType> |
| 22 | void SynchronizeTreesInternal(LayerTreeType* source_tree, |
| 23 | LayerTreeImpl* tree_impl, |
| 24 | PropertyTrees* property_trees) { |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 25 | DCHECK(tree_impl); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 26 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 27 | TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 28 | std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers()); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 29 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 30 | OwnedLayerImplMap old_layer_map; |
| 31 | for (auto& it : *old_layers) |
| 32 | old_layer_map[it->id()] = std::move(it); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 33 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 34 | PushLayerList(&old_layer_map, source_tree, tree_impl); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 35 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 36 | for (int id : property_trees->effect_tree.mask_replica_layer_ids()) { |
| 37 | std::unique_ptr<LayerImpl> layer_impl(ReuseOrCreateLayerImpl( |
| 38 | &old_layer_map, source_tree->LayerById(id), tree_impl)); |
| 39 | tree_impl->AddLayer(std::move(layer_impl)); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 40 | } |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 41 | } |
| 42 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 43 | void TreeSynchronizer::SynchronizeTrees(Layer* layer_root, |
| 44 | LayerTreeImpl* tree_impl) { |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 45 | if (!layer_root) { |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 46 | tree_impl->DetachLayers(); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 47 | } else { |
| 48 | SynchronizeTreesInternal(layer_root->layer_tree_host(), tree_impl, |
| 49 | layer_root->layer_tree_host()->property_trees()); |
| 50 | } |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 51 | } |
| 52 | |
jaydasika | e57ef9da | 2016-06-22 14:32:55 | [diff] [blame] | 53 | void TreeSynchronizer::SynchronizeTrees(LayerTreeImpl* pending_tree, |
| 54 | LayerTreeImpl* active_tree) { |
| 55 | if (pending_tree->LayerListIsEmpty()) { |
| 56 | active_tree->DetachLayers(); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 57 | } else { |
jaydasika | e57ef9da | 2016-06-22 14:32:55 | [diff] [blame] | 58 | SynchronizeTreesInternal(pending_tree, active_tree, |
| 59 | pending_tree->property_trees()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 60 | } |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | template <typename LayerType> |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 64 | std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers, |
| 65 | LayerType* layer, |
| 66 | LayerTreeImpl* tree_impl) { |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 67 | if (!layer) |
| 68 | return nullptr; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 69 | std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 70 | if (!layer_impl) |
| 71 | layer_impl = layer->CreateLayerImpl(tree_impl); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 72 | return layer_impl; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | } |
| 74 | |
jaydasika | 4b0fd751 | 2016-06-09 18:12:53 | [diff] [blame] | 75 | template <typename LayerTreeType> |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 76 | void PushLayerList(OwnedLayerImplMap* old_layers, |
| 77 | LayerTreeType* host, |
| 78 | LayerTreeImpl* tree_impl) { |
jaydasika | 4b0fd751 | 2016-06-09 18:12:53 | [diff] [blame] | 79 | tree_impl->ClearLayerList(); |
| 80 | for (auto* layer : *host) { |
| 81 | std::unique_ptr<LayerImpl> layer_impl( |
| 82 | ReuseOrCreateLayerImpl(old_layers, layer, tree_impl)); |
| 83 | |
jaydasika | 4b0fd751 | 2016-06-09 18:12:53 | [diff] [blame] | 84 | tree_impl->AddToLayerList(layer_impl.get()); |
| 85 | tree_impl->AddLayer(std::move(layer_impl)); |
| 86 | } |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 87 | tree_impl->OnCanDrawStateChangedForTree(); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 88 | } |
| 89 | |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 90 | template <typename LayerType> |
| 91 | static void PushLayerPropertiesInternal( |
| 92 | std::unordered_set<LayerType*> layers_that_should_push_properties, |
| 93 | LayerTreeImpl* impl_tree) { |
| 94 | for (auto layer : layers_that_should_push_properties) { |
| 95 | LayerImpl* layer_impl = impl_tree->LayerById(layer->id()); |
| 96 | DCHECK(layer_impl); |
| 97 | layer->PushPropertiesTo(layer_impl); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree, |
| 102 | LayerTreeImpl* active_tree) { |
| 103 | PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(), |
| 104 | active_tree); |
| 105 | } |
| 106 | |
| 107 | void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree, |
| 108 | LayerTreeImpl* impl_tree) { |
| 109 | PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(), |
| 110 | impl_tree); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 111 | } |
| 112 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 113 | } // namespace cc |