blob: 60177bf0648e7e0255e79d1b145740f023ceeb3d [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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]556fd292013-03-18 08:03:045#include "cc/trees/tree_synchronizer.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
[email protected]d097e242014-02-28 21:51:119#include <set>
10
[email protected]5c4824e12013-01-12 16:34:5311#include "base/logging.h"
primianoc06e2382015-01-28 04:21:4912#include "base/trace_event/trace_event.h"
[email protected]cc3cfaa2013-03-18 09:05:5213#include "cc/layers/layer.h"
vollick83fbfc82016-03-22 18:33:2714#include "cc/layers/layer_collections.h"
[email protected]cc3cfaa2013-03-18 09:05:5215#include "cc/layers/layer_impl.h"
jaydasika9234e402016-03-21 20:44:2216#include "cc/trees/layer_tree_host.h"
17#include "cc/trees/layer_tree_impl.h"
[email protected]94f206c12012-08-25 00:09:1418
[email protected]9c88e562012-09-14 22:21:3019namespace cc {
[email protected]94f206c12012-08-25 00:09:1420
ajuma1d4026a32016-06-14 13:18:5021template <typename LayerTreeType>
22void SynchronizeTreesInternal(LayerTreeType* source_tree,
23 LayerTreeImpl* tree_impl,
24 PropertyTrees* property_trees) {
[email protected]b5651c22013-03-14 15:06:3325 DCHECK(tree_impl);
[email protected]48871fc2013-01-23 07:36:5126
[email protected]b5651c22013-03-14 15:06:3327 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees");
danakj60bc3bc2016-04-09 00:24:4828 std::unique_ptr<OwnedLayerImplList> old_layers(tree_impl->DetachLayers());
[email protected]48871fc2013-01-23 07:36:5129
vollick83fbfc82016-03-22 18:33:2730 OwnedLayerImplMap old_layer_map;
31 for (auto& it : *old_layers)
32 old_layer_map[it->id()] = std::move(it);
[email protected]48871fc2013-01-23 07:36:5133
ajuma1d4026a32016-06-14 13:18:5034 PushLayerList(&old_layer_map, source_tree, tree_impl);
[email protected]48871fc2013-01-23 07:36:5135
ajuma1d4026a32016-06-14 13:18:5036 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));
vollick83fbfc82016-03-22 18:33:2740 }
[email protected]48871fc2013-01-23 07:36:5141}
42
vollick83fbfc82016-03-22 18:33:2743void TreeSynchronizer::SynchronizeTrees(Layer* layer_root,
44 LayerTreeImpl* tree_impl) {
ajuma1d4026a32016-06-14 13:18:5045 if (!layer_root) {
rockot2176f922016-06-08 19:18:3246 tree_impl->DetachLayers();
ajuma1d4026a32016-06-14 13:18:5047 } else {
48 SynchronizeTreesInternal(layer_root->layer_tree_host(), tree_impl,
49 layer_root->layer_tree_host()->property_trees());
50 }
[email protected]48871fc2013-01-23 07:36:5151}
52
jaydasikae57ef9da2016-06-22 14:32:5553void TreeSynchronizer::SynchronizeTrees(LayerTreeImpl* pending_tree,
54 LayerTreeImpl* active_tree) {
55 if (pending_tree->LayerListIsEmpty()) {
56 active_tree->DetachLayers();
ajuma1d4026a32016-06-14 13:18:5057 } else {
jaydasikae57ef9da2016-06-22 14:32:5558 SynchronizeTreesInternal(pending_tree, active_tree,
59 pending_tree->property_trees());
ajuma1d4026a32016-06-14 13:18:5060 }
[email protected]48871fc2013-01-23 07:36:5161}
62
63template <typename LayerType>
danakj60bc3bc2016-04-09 00:24:4864std::unique_ptr<LayerImpl> ReuseOrCreateLayerImpl(OwnedLayerImplMap* old_layers,
65 LayerType* layer,
66 LayerTreeImpl* tree_impl) {
vollick83fbfc82016-03-22 18:33:2767 if (!layer)
68 return nullptr;
danakj60bc3bc2016-04-09 00:24:4869 std::unique_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]);
[email protected]b5651c22013-03-14 15:06:3370 if (!layer_impl)
71 layer_impl = layer->CreateLayerImpl(tree_impl);
danakja04855a2015-11-18 20:39:1072 return layer_impl;
[email protected]94f206c12012-08-25 00:09:1473}
74
jaydasika4b0fd7512016-06-09 18:12:5375template <typename LayerTreeType>
ajuma1d4026a32016-06-14 13:18:5076void PushLayerList(OwnedLayerImplMap* old_layers,
77 LayerTreeType* host,
78 LayerTreeImpl* tree_impl) {
jaydasika4b0fd7512016-06-09 18:12:5379 tree_impl->ClearLayerList();
80 for (auto* layer : *host) {
81 std::unique_ptr<LayerImpl> layer_impl(
82 ReuseOrCreateLayerImpl(old_layers, layer, tree_impl));
83
jaydasika4b0fd7512016-06-09 18:12:5384 tree_impl->AddToLayerList(layer_impl.get());
85 tree_impl->AddLayer(std::move(layer_impl));
86 }
jaydasikabf1875a2016-06-28 03:39:5987 tree_impl->OnCanDrawStateChangedForTree();
[email protected]48871fc2013-01-23 07:36:5188}
89
jaydasika9234e402016-03-21 20:44:2290template <typename LayerType>
91static 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
101void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree,
102 LayerTreeImpl* active_tree) {
103 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(),
104 active_tree);
105}
106
107void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree,
108 LayerTreeImpl* impl_tree) {
109 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(),
110 impl_tree);
[email protected]48871fc2013-01-23 07:36:51111}
112
[email protected]bc5e77c2012-11-05 20:00:49113} // namespace cc