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