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