[email protected] | c0dd24c | 2012-08-30 23:25:27 | [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] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 10 | #include <set> |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 11 | #include <vector> |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 12 | |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 13 | #include "base/format_macros.h" |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 15 | #include "base/strings/stringprintf.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 16 | #include "cc/layers/layer.h" |
| 17 | #include "cc/layers/layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 18 | #include "cc/test/animation_test_common.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 19 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 20 | #include "cc/test/fake_layer_tree_host.h" |
hendrikw | 9b7f6d98 | 2014-11-04 22:28:35 | [diff] [blame] | 21 | #include "cc/test/fake_rendering_stats_instrumentation.h" |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 22 | #include "cc/test/test_shared_bitmap_manager.h" |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 23 | #include "cc/test/test_task_graph_runner.h" |
jaydasika | 13c0506 | 2016-04-01 18:12:27 | [diff] [blame] | 24 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 25 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 26 | #include "cc/trees/task_runner_provider.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 27 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 28 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 29 | namespace cc { |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 30 | namespace { |
| 31 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 32 | class MockLayerImpl : public LayerImpl { |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 33 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 34 | static std::unique_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl, |
| 35 | int layer_id) { |
| 36 | return base::WrapUnique(new MockLayerImpl(tree_impl, layer_id)); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 37 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 38 | ~MockLayerImpl() override { |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 39 | if (layer_impl_destruction_list_) |
| 40 | layer_impl_destruction_list_->push_back(id()); |
| 41 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 42 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 43 | void SetLayerImplDestructionList(std::vector<int>* list) { |
| 44 | layer_impl_destruction_list_ = list; |
| 45 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 46 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 47 | private: |
| 48 | MockLayerImpl(LayerTreeImpl* tree_impl, int layer_id) |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 49 | : LayerImpl(tree_impl, layer_id), layer_impl_destruction_list_(NULL) {} |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 50 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 51 | std::vector<int>* layer_impl_destruction_list_; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 52 | }; |
| 53 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 54 | class MockLayer : public Layer { |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 55 | public: |
| 56 | static scoped_refptr<MockLayer> Create( |
| 57 | std::vector<int>* layer_impl_destruction_list) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 58 | return make_scoped_refptr(new MockLayer(layer_impl_destruction_list)); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 59 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 60 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 61 | std::unique_ptr<LayerImpl> CreateLayerImpl( |
| 62 | LayerTreeImpl* tree_impl) override { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 63 | return MockLayerImpl::Create(tree_impl, layer_id_); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 64 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 65 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 66 | void PushPropertiesTo(LayerImpl* layer_impl) override { |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 67 | Layer::PushPropertiesTo(layer_impl); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 68 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 69 | MockLayerImpl* mock_layer_impl = static_cast<MockLayerImpl*>(layer_impl); |
| 70 | mock_layer_impl->SetLayerImplDestructionList(layer_impl_destruction_list_); |
| 71 | } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 72 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 73 | private: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 74 | explicit MockLayer(std::vector<int>* layer_impl_destruction_list) |
| 75 | : layer_impl_destruction_list_(layer_impl_destruction_list) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 76 | ~MockLayer() override {} |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 77 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 78 | std::vector<int>* layer_impl_destruction_list_; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 79 | }; |
| 80 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 81 | void ExpectTreesAreIdentical(Layer* layer, |
| 82 | LayerImpl* layer_impl, |
| 83 | LayerTreeImpl* tree_impl) { |
| 84 | ASSERT_TRUE(layer); |
| 85 | ASSERT_TRUE(layer_impl); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 86 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 87 | EXPECT_EQ(layer->id(), layer_impl->id()); |
| 88 | EXPECT_EQ(layer_impl->layer_tree_impl(), tree_impl); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 89 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 90 | EXPECT_EQ(layer->non_fast_scrollable_region(), |
| 91 | layer_impl->non_fast_scrollable_region()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 92 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 93 | ASSERT_EQ(!!layer->mask_layer(), !!layer_impl->mask_layer()); |
| 94 | if (layer->mask_layer()) { |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 95 | SCOPED_TRACE("mask_layer"); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 96 | ExpectTreesAreIdentical(layer->mask_layer(), layer_impl->mask_layer(), |
| 97 | tree_impl); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 98 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 99 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 100 | ASSERT_EQ(!!layer->replica_layer(), !!layer_impl->replica_layer()); |
| 101 | if (layer->replica_layer()) { |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 102 | SCOPED_TRACE("replica_layer"); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 103 | ExpectTreesAreIdentical(layer->replica_layer(), layer_impl->replica_layer(), |
| 104 | tree_impl); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 105 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 106 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 107 | const LayerList& layer_children = layer->children(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 108 | const LayerImplList& layer_impl_children = layer_impl->children(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 109 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 110 | ASSERT_EQ(layer_children.size(), layer_impl_children.size()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 111 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 112 | const Layer* layer_scroll_parent = layer->scroll_parent(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 113 | |
| 114 | if (layer_scroll_parent) { |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 115 | ASSERT_TRUE(layer_scroll_parent->scroll_children()->find(layer) != |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 116 | layer_scroll_parent->scroll_children()->end()); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 119 | const Layer* layer_clip_parent = layer->clip_parent(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 120 | |
| 121 | if (layer_clip_parent) { |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 122 | const std::set<Layer*>* clip_children = layer_clip_parent->clip_children(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 123 | ASSERT_TRUE(clip_children->find(layer) != clip_children->end()); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 124 | } |
| 125 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 126 | for (size_t i = 0; i < layer_children.size(); ++i) { |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 127 | SCOPED_TRACE(base::StringPrintf("child layer %" PRIuS, i).c_str()); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 128 | ExpectTreesAreIdentical(layer_children[i].get(), layer_impl_children[i], |
| 129 | tree_impl); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 130 | } |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | c228238 | 2012-12-16 00:46:03 | [diff] [blame] | 133 | class TreeSynchronizerTest : public testing::Test { |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 134 | public: |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 135 | TreeSynchronizerTest() |
| 136 | : client_(FakeLayerTreeHostClient::DIRECT_3D), |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 137 | host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_)) {} |
[email protected] | c228238 | 2012-12-16 00:46:03 | [diff] [blame] | 138 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 139 | protected: |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 140 | FakeLayerTreeHostClient client_; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 141 | TestTaskGraphRunner task_graph_runner_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 142 | std::unique_ptr<FakeLayerTreeHost> host_; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 143 | |
| 144 | bool is_equal(ScrollTree::ScrollOffsetMap map, |
| 145 | ScrollTree::ScrollOffsetMap other) { |
| 146 | if (map.size() != other.size()) |
| 147 | return false; |
| 148 | for (auto& map_entry : map) { |
| 149 | if (other.find(map_entry.first) == other.end()) |
| 150 | return false; |
| 151 | SyncedScrollOffset& from_map = *map_entry.second.get(); |
| 152 | SyncedScrollOffset& from_other = *other[map_entry.first].get(); |
| 153 | if (from_map.PendingBase() != from_other.PendingBase() || |
| 154 | from_map.ActiveBase() != from_other.ActiveBase() || |
| 155 | from_map.Delta() != from_other.Delta() || |
| 156 | from_map.PendingDelta().get() != from_other.PendingDelta().get()) |
| 157 | return false; |
| 158 | } |
| 159 | return true; |
| 160 | } |
[email protected] | c228238 | 2012-12-16 00:46:03 | [diff] [blame] | 161 | }; |
| 162 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 163 | // Attempts to synchronizes a null tree. This should not crash, and should |
| 164 | // return a null tree. |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 165 | TEST_F(TreeSynchronizerTest, SyncNullTree) { |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 166 | TreeSynchronizer::SynchronizeTrees(static_cast<Layer*>(NULL), |
| 167 | host_->active_tree()); |
| 168 | EXPECT_TRUE(!host_->active_tree()->root_layer()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 171 | // Constructs a very simple tree and synchronizes it without trying to reuse any |
| 172 | // preexisting layers. |
| 173 | TEST_F(TreeSynchronizerTest, SyncSimpleTreeFromEmpty) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 174 | scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 175 | layer_tree_root->AddChild(Layer::Create()); |
| 176 | layer_tree_root->AddChild(Layer::Create()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 177 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 178 | host_->SetRootLayer(layer_tree_root); |
| 179 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 180 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 181 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 182 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 183 | ExpectTreesAreIdentical(layer_tree_root.get(), |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 184 | host_->active_tree()->root_layer(), |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 185 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 188 | // Constructs a very simple tree and synchronizes it attempting to reuse some |
| 189 | // layers |
| 190 | TEST_F(TreeSynchronizerTest, SyncSimpleTreeReusingLayers) { |
| 191 | std::vector<int> layer_impl_destruction_list; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 192 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 193 | scoped_refptr<Layer> layer_tree_root = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 194 | MockLayer::Create(&layer_impl_destruction_list); |
| 195 | layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
| 196 | layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 197 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 198 | host_->SetRootLayer(layer_tree_root); |
| 199 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 200 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 201 | host_->active_tree()); |
| 202 | LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 203 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 204 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 205 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 206 | // We have to push properties to pick up the destruction list pointer. |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 207 | TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), |
| 208 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 209 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 210 | // Add a new layer to the Layer side |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 211 | layer_tree_root->children()[0]->AddChild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 212 | MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 213 | // Remove one. |
| 214 | layer_tree_root->children()[1]->RemoveFromParent(); |
| 215 | int second_layer_impl_id = layer_impl_tree_root->children()[1]->id(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 216 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 217 | // Synchronize again. After the sync the trees should be equivalent and we |
| 218 | // should have created and destroyed one LayerImpl. |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 219 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 220 | host_->active_tree()); |
| 221 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 222 | |
| 223 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 224 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 225 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 226 | ASSERT_EQ(1u, layer_impl_destruction_list.size()); |
| 227 | EXPECT_EQ(second_layer_impl_id, layer_impl_destruction_list[0]); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 228 | |
| 229 | host_->active_tree()->ClearLayers(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 230 | } |
| 231 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 232 | // Constructs a very simple tree and checks that a stacking-order change is |
| 233 | // tracked properly. |
| 234 | TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndTrackStackingOrderChange) { |
| 235 | std::vector<int> layer_impl_destruction_list; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 236 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 237 | // Set up the tree and sync once. child2 needs to be synced here, too, even |
| 238 | // though we remove it to set up the intended scenario. |
| 239 | scoped_refptr<Layer> layer_tree_root = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 240 | MockLayer::Create(&layer_impl_destruction_list); |
| 241 | scoped_refptr<Layer> child2 = MockLayer::Create(&layer_impl_destruction_list); |
| 242 | layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 243 | layer_tree_root->AddChild(child2); |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 244 | |
| 245 | host_->SetRootLayer(layer_tree_root); |
| 246 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 247 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 248 | host_->active_tree()); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 249 | LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 250 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 251 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 252 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 253 | // We have to push properties to pick up the destruction list pointer. |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 254 | TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), |
| 255 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 256 | |
jaydasika | d6f778b | 2016-05-19 22:51:26 | [diff] [blame^] | 257 | host_->active_tree()->ResetAllChangeTracking(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 258 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 259 | // re-insert the layer and sync again. |
| 260 | child2->RemoveFromParent(); |
| 261 | layer_tree_root->AddChild(child2); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 262 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 263 | host_->active_tree()); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 264 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 265 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 266 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 267 | |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 268 | TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), |
| 269 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 270 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 271 | // Check that the impl thread properly tracked the change. |
| 272 | EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged()); |
| 273 | EXPECT_FALSE(layer_impl_tree_root->children()[0]->LayerPropertyChanged()); |
| 274 | EXPECT_TRUE(layer_impl_tree_root->children()[1]->LayerPropertyChanged()); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 275 | host_->active_tree()->ClearLayers(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 276 | } |
| 277 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 278 | TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndProperties) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 279 | scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 280 | layer_tree_root->AddChild(Layer::Create()); |
| 281 | layer_tree_root->AddChild(Layer::Create()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 282 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 283 | host_->SetRootLayer(layer_tree_root); |
| 284 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 285 | // Pick some random properties to set. The values are not important, we're |
| 286 | // just testing that at least some properties are making it through. |
| 287 | gfx::PointF root_position = gfx::PointF(2.3f, 7.4f); |
| 288 | layer_tree_root->SetPosition(root_position); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 289 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 290 | float first_child_opacity = 0.25f; |
| 291 | layer_tree_root->children()[0]->SetOpacity(first_child_opacity); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 292 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 293 | gfx::Size second_child_bounds = gfx::Size(25, 53); |
| 294 | layer_tree_root->children()[1]->SetBounds(second_child_bounds); |
[email protected] | 445881f | 2013-04-16 01:11:59 | [diff] [blame] | 295 | layer_tree_root->children()[1]->SavePaintProperties(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 296 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 297 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 298 | host_->active_tree()); |
| 299 | LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 300 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 301 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 302 | |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 303 | TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), |
| 304 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 305 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 306 | // Check that the property values we set on the Layer tree are reflected in |
| 307 | // the LayerImpl tree. |
| 308 | gfx::PointF root_layer_impl_position = layer_impl_tree_root->position(); |
| 309 | EXPECT_EQ(root_position.x(), root_layer_impl_position.x()); |
| 310 | EXPECT_EQ(root_position.y(), root_layer_impl_position.y()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 311 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 312 | EXPECT_EQ(first_child_opacity, |
| 313 | layer_impl_tree_root->children()[0]->opacity()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 314 | |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 315 | gfx::Size second_layer_impl_child_bounds = |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 316 | layer_impl_tree_root->children()[1]->bounds(); |
| 317 | EXPECT_EQ(second_child_bounds.width(), |
| 318 | second_layer_impl_child_bounds.width()); |
| 319 | EXPECT_EQ(second_child_bounds.height(), |
| 320 | second_layer_impl_child_bounds.height()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 321 | } |
| 322 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 323 | TEST_F(TreeSynchronizerTest, ReuseLayerImplsAfterStructuralChange) { |
| 324 | std::vector<int> layer_impl_destruction_list; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 325 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 326 | // Set up a tree with this sort of structure: |
| 327 | // root --- A --- B ---+--- C |
| 328 | // | |
| 329 | // +--- D |
| 330 | scoped_refptr<Layer> layer_tree_root = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 331 | MockLayer::Create(&layer_impl_destruction_list); |
| 332 | layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 333 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 334 | scoped_refptr<Layer> layer_a = layer_tree_root->children()[0]; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 335 | layer_a->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 336 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 337 | scoped_refptr<Layer> layer_b = layer_a->children()[0]; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 338 | layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 339 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 340 | scoped_refptr<Layer> layer_c = layer_b->children()[0]; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 341 | layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list)); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 342 | scoped_refptr<Layer> layer_d = layer_b->children()[1]; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 343 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 344 | host_->SetRootLayer(layer_tree_root); |
| 345 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 346 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 347 | host_->active_tree()); |
| 348 | LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 349 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 350 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 351 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 352 | // We have to push properties to pick up the destruction list pointer. |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 353 | TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), |
| 354 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 355 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 356 | // Now restructure the tree to look like this: |
| 357 | // root --- D ---+--- A |
| 358 | // | |
| 359 | // +--- C --- B |
| 360 | layer_tree_root->RemoveAllChildren(); |
| 361 | layer_d->RemoveAllChildren(); |
| 362 | layer_tree_root->AddChild(layer_d); |
| 363 | layer_a->RemoveAllChildren(); |
| 364 | layer_d->AddChild(layer_a); |
| 365 | layer_c->RemoveAllChildren(); |
| 366 | layer_d->AddChild(layer_c); |
| 367 | layer_b->RemoveAllChildren(); |
| 368 | layer_c->AddChild(layer_b); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 369 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 370 | // After another synchronize our trees should match and we should not have |
| 371 | // destroyed any LayerImpls |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 372 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 373 | host_->active_tree()); |
| 374 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 375 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 376 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 377 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 378 | EXPECT_EQ(0u, layer_impl_destruction_list.size()); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 379 | |
| 380 | host_->active_tree()->ClearLayers(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 381 | } |
| 382 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 383 | // Constructs a very simple tree, synchronizes it, then synchronizes to a |
| 384 | // totally new tree. All layers from the old tree should be deleted. |
| 385 | TEST_F(TreeSynchronizerTest, SyncSimpleTreeThenDestroy) { |
| 386 | std::vector<int> layer_impl_destruction_list; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 387 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 388 | scoped_refptr<Layer> old_layer_tree_root = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 389 | MockLayer::Create(&layer_impl_destruction_list); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 390 | old_layer_tree_root->AddChild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 391 | MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 392 | old_layer_tree_root->AddChild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 393 | MockLayer::Create(&layer_impl_destruction_list)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 394 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 395 | host_->SetRootLayer(old_layer_tree_root); |
| 396 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 397 | int old_tree_root_layer_id = old_layer_tree_root->id(); |
| 398 | int old_tree_first_child_layer_id = old_layer_tree_root->children()[0]->id(); |
| 399 | int old_tree_second_child_layer_id = old_layer_tree_root->children()[1]->id(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 400 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 401 | TreeSynchronizer::SynchronizeTrees(old_layer_tree_root.get(), |
| 402 | host_->active_tree()); |
| 403 | LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 404 | ExpectTreesAreIdentical(old_layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 405 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 406 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 407 | // We have to push properties to pick up the destruction list pointer. |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 408 | TreeSynchronizer::PushLayerProperties(old_layer_tree_root->layer_tree_host(), |
| 409 | host_->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 410 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 411 | // Remove all children on the Layer side. |
| 412 | old_layer_tree_root->RemoveAllChildren(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 413 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 414 | // Synchronize again. After the sync all LayerImpls from the old tree should |
| 415 | // be deleted. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 416 | scoped_refptr<Layer> new_layer_tree_root = Layer::Create(); |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 417 | host_->SetRootLayer(new_layer_tree_root); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 418 | |
| 419 | TreeSynchronizer::SynchronizeTrees(new_layer_tree_root.get(), |
| 420 | host_->active_tree()); |
| 421 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 422 | ExpectTreesAreIdentical(new_layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 423 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 424 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 425 | ASSERT_EQ(3u, layer_impl_destruction_list.size()); |
[email protected] | 2cdbdba | 2012-10-28 13:15:05 | [diff] [blame] | 426 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 427 | EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(), |
| 428 | layer_impl_destruction_list.end(), |
| 429 | old_tree_root_layer_id) != |
| 430 | layer_impl_destruction_list.end()); |
| 431 | EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(), |
| 432 | layer_impl_destruction_list.end(), |
| 433 | old_tree_first_child_layer_id) != |
| 434 | layer_impl_destruction_list.end()); |
| 435 | EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(), |
| 436 | layer_impl_destruction_list.end(), |
| 437 | old_tree_second_child_layer_id) != |
| 438 | layer_impl_destruction_list.end()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | // Constructs+syncs a tree with mask, replica, and replica mask layers. |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 442 | TEST_F(TreeSynchronizerTest, SyncMaskReplicaAndReplicaMaskLayers) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 443 | scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 444 | layer_tree_root->AddChild(Layer::Create()); |
| 445 | layer_tree_root->AddChild(Layer::Create()); |
| 446 | layer_tree_root->AddChild(Layer::Create()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 447 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 448 | // First child gets a mask layer. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 449 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 450 | layer_tree_root->children()[0]->SetMaskLayer(mask_layer.get()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 451 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 452 | // Second child gets a replica layer. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 453 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 454 | layer_tree_root->children()[1]->SetReplicaLayer(replica_layer.get()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 455 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 456 | // Third child gets a replica layer with a mask layer. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 457 | scoped_refptr<Layer> replica_layer_with_mask = Layer::Create(); |
| 458 | scoped_refptr<Layer> replica_mask_layer = Layer::Create(); |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 459 | replica_layer_with_mask->SetMaskLayer(replica_mask_layer.get()); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 460 | layer_tree_root->children()[2]->SetReplicaLayer( |
| 461 | replica_layer_with_mask.get()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 462 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 463 | host_->SetRootLayer(layer_tree_root); |
| 464 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 465 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 466 | host_->active_tree()); |
| 467 | LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 468 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 469 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 470 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 471 | // Remove the mask layer. |
| 472 | layer_tree_root->children()[0]->SetMaskLayer(NULL); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 473 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 474 | host_->active_tree()); |
| 475 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 476 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 477 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 478 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 479 | // Remove the replica layer. |
| 480 | layer_tree_root->children()[1]->SetReplicaLayer(NULL); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 481 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 482 | host_->active_tree()); |
| 483 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 484 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 485 | host_->active_tree()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 486 | |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 487 | // Remove the replica mask. |
| 488 | replica_layer_with_mask->SetMaskLayer(NULL); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 489 | TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), |
| 490 | host_->active_tree()); |
| 491 | layer_impl_tree_root = host_->active_tree()->root_layer(); |
| 492 | ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 493 | host_->active_tree()); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 494 | |
| 495 | host_->active_tree()->ClearLayers(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 496 | } |
| 497 | |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 498 | TEST_F(TreeSynchronizerTest, SynchronizeCurrentlyScrollingNode) { |
| 499 | LayerTreeSettings settings; |
| 500 | FakeLayerTreeHostImplClient client; |
| 501 | FakeImplTaskRunnerProvider task_runner_provider; |
| 502 | FakeRenderingStatsInstrumentation stats_instrumentation; |
| 503 | TestSharedBitmapManager shared_bitmap_manager; |
| 504 | TestTaskGraphRunner task_graph_runner; |
| 505 | FakeLayerTreeHostImpl* host_impl = host_->host_impl(); |
| 506 | host_impl->CreatePendingTree(); |
| 507 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 508 | scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 509 | scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); |
| 510 | scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 511 | scoped_refptr<Layer> transient_scroll_clip_layer = Layer::Create(); |
| 512 | scoped_refptr<Layer> transient_scroll_layer = Layer::Create(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 513 | |
| 514 | layer_tree_root->AddChild(transient_scroll_clip_layer); |
| 515 | transient_scroll_clip_layer->AddChild(transient_scroll_layer); |
| 516 | transient_scroll_layer->AddChild(scroll_clip_layer); |
| 517 | scroll_clip_layer->AddChild(scroll_layer); |
| 518 | |
| 519 | transient_scroll_layer->SetScrollClipLayerId( |
| 520 | transient_scroll_clip_layer->id()); |
| 521 | scroll_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 522 | host_->SetRootLayer(layer_tree_root); |
| 523 | host_->BuildPropertyTreesForTesting(); |
| 524 | host_->CommitAndCreatePendingTree(); |
| 525 | host_impl->ActivateSyncTree(); |
| 526 | |
| 527 | ExpectTreesAreIdentical(layer_tree_root.get(), |
| 528 | host_impl->active_tree()->root_layer(), |
| 529 | host_impl->active_tree()); |
| 530 | |
| 531 | host_impl->active_tree()->SetCurrentlyScrollingLayer( |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 532 | host_impl->active_tree()->LayerById(scroll_layer->id())); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 533 | transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); |
| 534 | host_->BuildPropertyTreesForTesting(); |
| 535 | |
| 536 | host_impl->CreatePendingTree(); |
| 537 | host_->CommitAndCreatePendingTree(); |
| 538 | host_impl->ActivateSyncTree(); |
| 539 | |
| 540 | EXPECT_EQ(scroll_layer->id(), |
| 541 | host_impl->active_tree()->CurrentlyScrollingLayer()->id()); |
| 542 | } |
| 543 | |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 544 | TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) { |
| 545 | host_->InitializeSingleThreaded(&client_, base::ThreadTaskRunnerHandle::Get(), |
| 546 | nullptr); |
| 547 | LayerTreeSettings settings; |
| 548 | FakeLayerTreeHostImplClient client; |
| 549 | FakeImplTaskRunnerProvider task_runner_provider; |
| 550 | FakeRenderingStatsInstrumentation stats_instrumentation; |
| 551 | TestSharedBitmapManager shared_bitmap_manager; |
| 552 | TestTaskGraphRunner task_graph_runner; |
| 553 | FakeLayerTreeHostImpl* host_impl = host_->host_impl(); |
| 554 | host_impl->CreatePendingTree(); |
| 555 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 556 | scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 557 | scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); |
| 558 | scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 559 | scoped_refptr<Layer> transient_scroll_clip_layer = Layer::Create(); |
| 560 | scoped_refptr<Layer> transient_scroll_layer = Layer::Create(); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 561 | |
| 562 | layer_tree_root->AddChild(transient_scroll_clip_layer); |
| 563 | transient_scroll_clip_layer->AddChild(transient_scroll_layer); |
| 564 | transient_scroll_layer->AddChild(scroll_clip_layer); |
| 565 | scroll_clip_layer->AddChild(scroll_layer); |
| 566 | |
| 567 | transient_scroll_layer->SetScrollClipLayerId( |
| 568 | transient_scroll_clip_layer->id()); |
| 569 | scroll_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 570 | transient_scroll_layer->SetScrollOffset(gfx::ScrollOffset(1, 2)); |
| 571 | scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 572 | |
| 573 | host_->SetRootLayer(layer_tree_root); |
| 574 | host_->BuildPropertyTreesForTesting(); |
| 575 | host_->CommitAndCreatePendingTree(); |
| 576 | host_impl->ActivateSyncTree(); |
| 577 | |
| 578 | ExpectTreesAreIdentical(layer_tree_root.get(), |
| 579 | host_impl->active_tree()->root_layer(), |
| 580 | host_impl->active_tree()); |
| 581 | |
| 582 | // After the initial commit, scroll_offset_map in scroll_tree is expected to |
| 583 | // have one entry for scroll_layer and one entry for transient_scroll_layer, |
| 584 | // the pending base and active base must be the same at this stage. |
| 585 | ScrollTree::ScrollOffsetMap scroll_offset_map; |
| 586 | scroll_offset_map[scroll_layer->id()] = new SyncedScrollOffset; |
| 587 | scroll_offset_map[transient_scroll_layer->id()] = new SyncedScrollOffset; |
| 588 | scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 589 | scroll_layer->scroll_offset()); |
| 590 | scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 591 | scroll_offset_map[transient_scroll_layer->id()]->PushFromMainThread( |
| 592 | transient_scroll_layer->scroll_offset()); |
| 593 | scroll_offset_map[transient_scroll_layer->id()]->PushPendingToActive(); |
| 594 | EXPECT_TRUE( |
| 595 | is_equal(scroll_offset_map, host_impl->active_tree() |
| 596 | ->property_trees() |
| 597 | ->scroll_tree.scroll_offset_map())); |
| 598 | |
| 599 | // Set ScrollOffset active delta: gfx::ScrollOffset(10, 10) |
| 600 | LayerImpl* scroll_layer_impl = |
| 601 | host_impl->active_tree()->LayerById(scroll_layer->id()); |
| 602 | ScrollTree& scroll_tree = |
| 603 | host_impl->active_tree()->property_trees()->scroll_tree; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 604 | scroll_tree.SetScrollOffset(scroll_layer_impl->id(), |
| 605 | gfx::ScrollOffset(20, 30)); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 606 | |
| 607 | // Pull ScrollOffset delta for main thread, and change offset on main thread |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 608 | std::unique_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 609 | scroll_tree.CollectScrollDeltas(scroll_info.get()); |
| 610 | host_->proxy()->SetNeedsCommit(); |
| 611 | host_->ApplyScrollAndScale(scroll_info.get()); |
| 612 | EXPECT_EQ(gfx::ScrollOffset(20, 30), scroll_layer->scroll_offset()); |
| 613 | scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
| 614 | |
| 615 | // More update to ScrollOffset active delta: gfx::ScrollOffset(20, 20) |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 616 | scroll_tree.SetScrollOffset(scroll_layer_impl->id(), |
| 617 | gfx::ScrollOffset(40, 50)); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 618 | host_impl->active_tree()->SetCurrentlyScrollingLayer(scroll_layer_impl); |
| 619 | |
| 620 | // Make one layer unscrollable so that scroll tree topology changes |
| 621 | transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); |
| 622 | host_->BuildPropertyTreesForTesting(); |
| 623 | |
| 624 | host_impl->CreatePendingTree(); |
| 625 | host_->CommitAndCreatePendingTree(); |
| 626 | host_impl->ActivateSyncTree(); |
| 627 | |
| 628 | EXPECT_EQ(scroll_layer->id(), |
| 629 | host_impl->active_tree()->CurrentlyScrollingLayer()->id()); |
| 630 | scroll_offset_map.erase(transient_scroll_layer->id()); |
| 631 | scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(20, 30)); |
| 632 | scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); |
| 633 | scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); |
| 634 | scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 635 | gfx::ScrollOffset(100, 100)); |
| 636 | scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 637 | EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); |
| 638 | } |
| 639 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 640 | } // namespace |
| 641 | } // namespace cc |