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