blob: 4f21270cd435fa1231111b9fd9b3fe81f589f1b7 [file] [log] [blame]
[email protected]c0dd24c2012-08-30 23:25:271// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/tree_synchronizer.h"
[email protected]c0dd24c2012-08-30 23:25:276
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
[email protected]ac7c7f52012-11-08 06:26:509#include <algorithm>
[email protected]0e98cdd2013-08-23 00:44:3010#include <set>
[email protected]bf691c22013-03-26 21:15:0611#include <vector>
[email protected]ac7c7f52012-11-08 06:26:5012
[email protected]d097e242014-02-28 21:51:1113#include "base/format_macros.h"
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
[email protected]d097e242014-02-28 21:51:1115#include "base/strings/stringprintf.h"
[email protected]95e4e1a02013-03-18 07:09:0916#include "cc/animation/layer_animation_controller.h"
[email protected]cc3cfaa2013-03-18 09:05:5217#include "cc/layers/layer.h"
18#include "cc/layers/layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0319#include "cc/test/animation_test_common.h"
khushalsagarb64b360d2015-10-21 19:25:1620#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]f4e25f92013-07-13 20:54:5321#include "cc/test/fake_layer_tree_host.h"
hendrikw9b7f6d982014-11-04 22:28:3522#include "cc/test/fake_rendering_stats_instrumentation.h"
[email protected]4e2eb352014-03-20 17:25:4523#include "cc/test/test_shared_bitmap_manager.h"
danakjcf610582015-06-16 22:48:5624#include "cc/test/test_task_graph_runner.h"
jaydasika13c05062016-04-01 18:12:2725#include "cc/trees/layer_tree_host_common.h"
[email protected]556fd292013-03-18 08:03:0426#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1627#include "cc/trees/task_runner_provider.h"
[email protected]7f0c53db2012-10-02 00:23:1828#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2729
[email protected]ba565742012-11-10 09:29:4830namespace cc {
[email protected]c0dd24c2012-08-30 23:25:2731namespace {
32
[email protected]96baf3e2012-10-22 23:09:5533class MockLayerImpl : public LayerImpl {
[email protected]b5651c22013-03-14 15:06:3334 public:
danakj60bc3bc2016-04-09 00:24:4835 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]b5651c22013-03-14 15:06:3338 }
dcheng716bedf2014-10-21 09:51:0839 ~MockLayerImpl() override {
[email protected]b5651c22013-03-14 15:06:3340 if (layer_impl_destruction_list_)
41 layer_impl_destruction_list_->push_back(id());
42 }
[email protected]c0dd24c2012-08-30 23:25:2743
[email protected]b5651c22013-03-14 15:06:3344 void SetLayerImplDestructionList(std::vector<int>* list) {
45 layer_impl_destruction_list_ = list;
46 }
[email protected]c0dd24c2012-08-30 23:25:2747
[email protected]b5651c22013-03-14 15:06:3348 private:
49 MockLayerImpl(LayerTreeImpl* tree_impl, int layer_id)
vollick83fbfc82016-03-22 18:33:2750 : LayerImpl(tree_impl, layer_id), layer_impl_destruction_list_(NULL) {}
[email protected]c0dd24c2012-08-30 23:25:2751
[email protected]b5651c22013-03-14 15:06:3352 std::vector<int>* layer_impl_destruction_list_;
[email protected]c0dd24c2012-08-30 23:25:2753};
54
[email protected]96baf3e2012-10-22 23:09:5555class MockLayer : public Layer {
[email protected]b5651c22013-03-14 15:06:3356 public:
57 static scoped_refptr<MockLayer> Create(
58 std::vector<int>* layer_impl_destruction_list) {
loyso0940d412016-03-14 01:30:3159 return make_scoped_refptr(new MockLayer(layer_impl_destruction_list));
[email protected]b5651c22013-03-14 15:06:3360 }
[email protected]c0dd24c2012-08-30 23:25:2761
danakj60bc3bc2016-04-09 00:24:4862 std::unique_ptr<LayerImpl> CreateLayerImpl(
63 LayerTreeImpl* tree_impl) override {
danakjf446a072014-09-27 21:55:4864 return MockLayerImpl::Create(tree_impl, layer_id_);
[email protected]b5651c22013-03-14 15:06:3365 }
[email protected]c0dd24c2012-08-30 23:25:2766
dcheng716bedf2014-10-21 09:51:0867 void PushPropertiesTo(LayerImpl* layer_impl) override {
[email protected]b5651c22013-03-14 15:06:3368 Layer::PushPropertiesTo(layer_impl);
[email protected]c0dd24c2012-08-30 23:25:2769
[email protected]b5651c22013-03-14 15:06:3370 MockLayerImpl* mock_layer_impl = static_cast<MockLayerImpl*>(layer_impl);
71 mock_layer_impl->SetLayerImplDestructionList(layer_impl_destruction_list_);
72 }
[email protected]d58499a2012-10-09 22:27:4773
[email protected]b5651c22013-03-14 15:06:3374 private:
loyso0940d412016-03-14 01:30:3175 explicit MockLayer(std::vector<int>* layer_impl_destruction_list)
76 : layer_impl_destruction_list_(layer_impl_destruction_list) {}
dcheng716bedf2014-10-21 09:51:0877 ~MockLayer() override {}
[email protected]c0dd24c2012-08-30 23:25:2778
[email protected]b5651c22013-03-14 15:06:3379 std::vector<int>* layer_impl_destruction_list_;
[email protected]c0dd24c2012-08-30 23:25:2780};
81
[email protected]b5651c22013-03-14 15:06:3382void ExpectTreesAreIdentical(Layer* layer,
83 LayerImpl* layer_impl,
84 LayerTreeImpl* tree_impl) {
85 ASSERT_TRUE(layer);
86 ASSERT_TRUE(layer_impl);
[email protected]c0dd24c2012-08-30 23:25:2787
[email protected]b5651c22013-03-14 15:06:3388 EXPECT_EQ(layer->id(), layer_impl->id());
89 EXPECT_EQ(layer_impl->layer_tree_impl(), tree_impl);
[email protected]c0dd24c2012-08-30 23:25:2790
[email protected]b5651c22013-03-14 15:06:3391 EXPECT_EQ(layer->non_fast_scrollable_region(),
92 layer_impl->non_fast_scrollable_region());
[email protected]c0dd24c2012-08-30 23:25:2793
[email protected]b5651c22013-03-14 15:06:3394 ASSERT_EQ(!!layer->mask_layer(), !!layer_impl->mask_layer());
95 if (layer->mask_layer()) {
[email protected]d097e242014-02-28 21:51:1196 SCOPED_TRACE("mask_layer");
vollick83fbfc82016-03-22 18:33:2797 ExpectTreesAreIdentical(layer->mask_layer(), layer_impl->mask_layer(),
98 tree_impl);
[email protected]b5651c22013-03-14 15:06:3399 }
[email protected]c0dd24c2012-08-30 23:25:27100
[email protected]b5651c22013-03-14 15:06:33101 ASSERT_EQ(!!layer->replica_layer(), !!layer_impl->replica_layer());
102 if (layer->replica_layer()) {
[email protected]d097e242014-02-28 21:51:11103 SCOPED_TRACE("replica_layer");
vollick83fbfc82016-03-22 18:33:27104 ExpectTreesAreIdentical(layer->replica_layer(), layer_impl->replica_layer(),
105 tree_impl);
[email protected]b5651c22013-03-14 15:06:33106 }
[email protected]c0dd24c2012-08-30 23:25:27107
[email protected]50761e92013-03-29 20:51:28108 const LayerList& layer_children = layer->children();
vollick83fbfc82016-03-22 18:33:27109 const LayerImplList& layer_impl_children = layer_impl->children();
[email protected]c0dd24c2012-08-30 23:25:27110
[email protected]b5651c22013-03-14 15:06:33111 ASSERT_EQ(layer_children.size(), layer_impl_children.size());
[email protected]c0dd24c2012-08-30 23:25:27112
[email protected]0e98cdd2013-08-23 00:44:30113 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) {
vollick83fbfc82016-03-22 18:33:27120 ASSERT_EQ(layer_scroll_children->size(),
121 layer_impl_scroll_children->size());
[email protected]0e98cdd2013-08-23 00:44:30122 }
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) !=
vollick83fbfc82016-03-22 18:33:27132 layer_scroll_parent->scroll_children()->end());
[email protected]0e98cdd2013-08-23 00:44:30133 ASSERT_TRUE(layer_impl_scroll_parent->scroll_children()->find(layer_impl) !=
vollick83fbfc82016-03-22 18:33:27134 layer_impl_scroll_parent->scroll_children()->end());
[email protected]0e98cdd2013-08-23 00:44:30135 }
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();
vollick83fbfc82016-03-22 18:33:27154 const std::set<Layer*>* clip_children = layer_clip_parent->clip_children();
[email protected]0e98cdd2013-08-23 00:44:30155 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]b5651c22013-03-14 15:06:33161 for (size_t i = 0; i < layer_children.size(); ++i) {
[email protected]d097e242014-02-28 21:51:11162 SCOPED_TRACE(base::StringPrintf("child layer %" PRIuS, i).c_str());
vollick83fbfc82016-03-22 18:33:27163 ExpectTreesAreIdentical(layer_children[i].get(), layer_impl_children[i],
164 tree_impl);
[email protected]b5651c22013-03-14 15:06:33165 }
[email protected]c0dd24c2012-08-30 23:25:27166}
167
[email protected]c2282382012-12-16 00:46:03168class TreeSynchronizerTest : public testing::Test {
[email protected]b5651c22013-03-14 15:06:33169 public:
enne2097cab2014-09-25 20:16:31170 TreeSynchronizerTest()
171 : client_(FakeLayerTreeHostClient::DIRECT_3D),
loyso0940d412016-03-14 01:30:31172 host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_)) {}
[email protected]c2282382012-12-16 00:46:03173
[email protected]b5651c22013-03-14 15:06:33174 protected:
enne2097cab2014-09-25 20:16:31175 FakeLayerTreeHostClient client_;
danakjcf610582015-06-16 22:48:56176 TestTaskGraphRunner task_graph_runner_;
danakj60bc3bc2016-04-09 00:24:48177 std::unique_ptr<FakeLayerTreeHost> host_;
sunxdc36713a2016-03-03 22:31:10178
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]c2282382012-12-16 00:46:03196};
197
[email protected]c0dd24c2012-08-30 23:25:27198// Attempts to synchronizes a null tree. This should not crash, and should
199// return a null tree.
[email protected]b5651c22013-03-14 15:06:33200TEST_F(TreeSynchronizerTest, SyncNullTree) {
vollick83fbfc82016-03-22 18:33:27201 TreeSynchronizer::SynchronizeTrees(static_cast<Layer*>(NULL),
202 host_->active_tree());
203 EXPECT_TRUE(!host_->active_tree()->root_layer());
[email protected]c0dd24c2012-08-30 23:25:27204}
205
[email protected]b5651c22013-03-14 15:06:33206// Constructs a very simple tree and synchronizes it without trying to reuse any
207// preexisting layers.
208TEST_F(TreeSynchronizerTest, SyncSimpleTreeFromEmpty) {
loyso0940d412016-03-14 01:30:31209 scoped_refptr<Layer> layer_tree_root = Layer::Create();
210 layer_tree_root->AddChild(Layer::Create());
211 layer_tree_root->AddChild(Layer::Create());
[email protected]c0dd24c2012-08-30 23:25:27212
[email protected]f4e25f92013-07-13 20:54:53213 host_->SetRootLayer(layer_tree_root);
214
vollick83fbfc82016-03-22 18:33:27215 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
216 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27217
[email protected]b5651c22013-03-14 15:06:33218 ExpectTreesAreIdentical(layer_tree_root.get(),
vollick83fbfc82016-03-22 18:33:27219 host_->active_tree()->root_layer(),
[email protected]f4e25f92013-07-13 20:54:53220 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27221}
222
[email protected]b5651c22013-03-14 15:06:33223// Constructs a very simple tree and synchronizes it attempting to reuse some
224// layers
225TEST_F(TreeSynchronizerTest, SyncSimpleTreeReusingLayers) {
226 std::vector<int> layer_impl_destruction_list;
[email protected]c0dd24c2012-08-30 23:25:27227
[email protected]b5651c22013-03-14 15:06:33228 scoped_refptr<Layer> layer_tree_root =
loyso0940d412016-03-14 01:30:31229 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]c0dd24c2012-08-30 23:25:27232
[email protected]f4e25f92013-07-13 20:54:53233 host_->SetRootLayer(layer_tree_root);
234
vollick83fbfc82016-03-22 18:33:27235 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]f4e25f92013-07-13 20:54:53239 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27240
[email protected]b5651c22013-03-14 15:06:33241 // We have to push properties to pick up the destruction list pointer.
jaydasika9234e402016-03-21 20:44:22242 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
243 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53244
[email protected]b5651c22013-03-14 15:06:33245 // Add a new layer to the Layer side
loysoa6edaaff2015-05-25 03:26:44246 layer_tree_root->children()[0]->AddChild(
loyso0940d412016-03-14 01:30:31247 MockLayer::Create(&layer_impl_destruction_list));
[email protected]b5651c22013-03-14 15:06:33248 // Remove one.
249 layer_tree_root->children()[1]->RemoveFromParent();
250 int second_layer_impl_id = layer_impl_tree_root->children()[1]->id();
[email protected]c0dd24c2012-08-30 23:25:27251
[email protected]b5651c22013-03-14 15:06:33252 // Synchronize again. After the sync the trees should be equivalent and we
253 // should have created and destroyed one LayerImpl.
vollick83fbfc82016-03-22 18:33:27254 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]f4e25f92013-07-13 20:54:53259 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27260
[email protected]b5651c22013-03-14 15:06:33261 ASSERT_EQ(1u, layer_impl_destruction_list.size());
262 EXPECT_EQ(second_layer_impl_id, layer_impl_destruction_list[0]);
vollick83fbfc82016-03-22 18:33:27263
264 host_->active_tree()->ClearLayers();
[email protected]c0dd24c2012-08-30 23:25:27265}
266
[email protected]b5651c22013-03-14 15:06:33267// Constructs a very simple tree and checks that a stacking-order change is
268// tracked properly.
269TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndTrackStackingOrderChange) {
270 std::vector<int> layer_impl_destruction_list;
[email protected]c0dd24c2012-08-30 23:25:27271
[email protected]b5651c22013-03-14 15:06:33272 // 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 =
loyso0940d412016-03-14 01:30:31275 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]b5651c22013-03-14 15:06:33278 layer_tree_root->AddChild(child2);
[email protected]f4e25f92013-07-13 20:54:53279
280 host_->SetRootLayer(layer_tree_root);
281
vollick83fbfc82016-03-22 18:33:27282 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
283 host_->active_tree());
jaydasikaef64f9e42016-03-12 01:08:18284 LayerImpl* layer_impl_tree_root = host_->active_tree()->root_layer();
285 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]f4e25f92013-07-13 20:54:53286 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53287
[email protected]b5651c22013-03-14 15:06:33288 // We have to push properties to pick up the destruction list pointer.
jaydasika9234e402016-03-21 20:44:22289 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
290 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53291
jaydasikaef64f9e42016-03-12 01:08:18292 host_->active_tree()->ResetAllChangeTracking(
293 PropertyTrees::ResetFlags::ALL_TREES);
[email protected]c0dd24c2012-08-30 23:25:27294
[email protected]b5651c22013-03-14 15:06:33295 // re-insert the layer and sync again.
296 child2->RemoveFromParent();
297 layer_tree_root->AddChild(child2);
vollick83fbfc82016-03-22 18:33:27298 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
299 host_->active_tree());
jaydasikaef64f9e42016-03-12 01:08:18300 layer_impl_tree_root = host_->active_tree()->root_layer();
301 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]f4e25f92013-07-13 20:54:53302 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27303
jaydasika9234e402016-03-21 20:44:22304 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
305 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53306
[email protected]b5651c22013-03-14 15:06:33307 // 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());
vollick83fbfc82016-03-22 18:33:27311 host_->active_tree()->ClearLayers();
[email protected]c0dd24c2012-08-30 23:25:27312}
313
[email protected]b5651c22013-03-14 15:06:33314TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndProperties) {
loyso0940d412016-03-14 01:30:31315 scoped_refptr<Layer> layer_tree_root = Layer::Create();
316 layer_tree_root->AddChild(Layer::Create());
317 layer_tree_root->AddChild(Layer::Create());
[email protected]c0dd24c2012-08-30 23:25:27318
[email protected]f4e25f92013-07-13 20:54:53319 host_->SetRootLayer(layer_tree_root);
320
[email protected]b5651c22013-03-14 15:06:33321 // 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]c0dd24c2012-08-30 23:25:27325
[email protected]b5651c22013-03-14 15:06:33326 float first_child_opacity = 0.25f;
327 layer_tree_root->children()[0]->SetOpacity(first_child_opacity);
[email protected]c0dd24c2012-08-30 23:25:27328
[email protected]b5651c22013-03-14 15:06:33329 gfx::Size second_child_bounds = gfx::Size(25, 53);
330 layer_tree_root->children()[1]->SetBounds(second_child_bounds);
[email protected]445881f2013-04-16 01:11:59331 layer_tree_root->children()[1]->SavePaintProperties();
[email protected]c0dd24c2012-08-30 23:25:27332
vollick83fbfc82016-03-22 18:33:27333 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]f4e25f92013-07-13 20:54:53337 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27338
jaydasika9234e402016-03-21 20:44:22339 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
340 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53341
[email protected]b5651c22013-03-14 15:06:33342 // 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]c0dd24c2012-08-30 23:25:27347
[email protected]b5651c22013-03-14 15:06:33348 EXPECT_EQ(first_child_opacity,
349 layer_impl_tree_root->children()[0]->opacity());
[email protected]c0dd24c2012-08-30 23:25:27350
bokancccfde72014-10-08 15:15:22351 gfx::Size second_layer_impl_child_bounds =
[email protected]b5651c22013-03-14 15:06:33352 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]c0dd24c2012-08-30 23:25:27357}
358
[email protected]b5651c22013-03-14 15:06:33359TEST_F(TreeSynchronizerTest, ReuseLayerImplsAfterStructuralChange) {
360 std::vector<int> layer_impl_destruction_list;
[email protected]c0dd24c2012-08-30 23:25:27361
[email protected]b5651c22013-03-14 15:06:33362 // Set up a tree with this sort of structure:
363 // root --- A --- B ---+--- C
364 // |
365 // +--- D
366 scoped_refptr<Layer> layer_tree_root =
loyso0940d412016-03-14 01:30:31367 MockLayer::Create(&layer_impl_destruction_list);
368 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list));
[email protected]c0dd24c2012-08-30 23:25:27369
vollick83fbfc82016-03-22 18:33:27370 scoped_refptr<Layer> layer_a = layer_tree_root->children()[0];
loyso0940d412016-03-14 01:30:31371 layer_a->AddChild(MockLayer::Create(&layer_impl_destruction_list));
[email protected]c0dd24c2012-08-30 23:25:27372
vollick83fbfc82016-03-22 18:33:27373 scoped_refptr<Layer> layer_b = layer_a->children()[0];
loyso0940d412016-03-14 01:30:31374 layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list));
[email protected]c0dd24c2012-08-30 23:25:27375
vollick83fbfc82016-03-22 18:33:27376 scoped_refptr<Layer> layer_c = layer_b->children()[0];
loyso0940d412016-03-14 01:30:31377 layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list));
vollick83fbfc82016-03-22 18:33:27378 scoped_refptr<Layer> layer_d = layer_b->children()[1];
[email protected]c0dd24c2012-08-30 23:25:27379
[email protected]f4e25f92013-07-13 20:54:53380 host_->SetRootLayer(layer_tree_root);
381
vollick83fbfc82016-03-22 18:33:27382 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]f4e25f92013-07-13 20:54:53386 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27387
[email protected]b5651c22013-03-14 15:06:33388 // We have to push properties to pick up the destruction list pointer.
jaydasika9234e402016-03-21 20:44:22389 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
390 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53391
[email protected]b5651c22013-03-14 15:06:33392 // 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]c0dd24c2012-08-30 23:25:27405
[email protected]b5651c22013-03-14 15:06:33406 // After another synchronize our trees should match and we should not have
407 // destroyed any LayerImpls
vollick83fbfc82016-03-22 18:33:27408 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]f4e25f92013-07-13 20:54:53412 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27413
[email protected]b5651c22013-03-14 15:06:33414 EXPECT_EQ(0u, layer_impl_destruction_list.size());
vollick83fbfc82016-03-22 18:33:27415
416 host_->active_tree()->ClearLayers();
[email protected]c0dd24c2012-08-30 23:25:27417}
418
[email protected]b5651c22013-03-14 15:06:33419// Constructs a very simple tree, synchronizes it, then synchronizes to a
420// totally new tree. All layers from the old tree should be deleted.
421TEST_F(TreeSynchronizerTest, SyncSimpleTreeThenDestroy) {
422 std::vector<int> layer_impl_destruction_list;
[email protected]c0dd24c2012-08-30 23:25:27423
[email protected]b5651c22013-03-14 15:06:33424 scoped_refptr<Layer> old_layer_tree_root =
loyso0940d412016-03-14 01:30:31425 MockLayer::Create(&layer_impl_destruction_list);
[email protected]b5651c22013-03-14 15:06:33426 old_layer_tree_root->AddChild(
loyso0940d412016-03-14 01:30:31427 MockLayer::Create(&layer_impl_destruction_list));
[email protected]b5651c22013-03-14 15:06:33428 old_layer_tree_root->AddChild(
loyso0940d412016-03-14 01:30:31429 MockLayer::Create(&layer_impl_destruction_list));
[email protected]c0dd24c2012-08-30 23:25:27430
[email protected]f4e25f92013-07-13 20:54:53431 host_->SetRootLayer(old_layer_tree_root);
432
[email protected]b5651c22013-03-14 15:06:33433 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]c0dd24c2012-08-30 23:25:27436
vollick83fbfc82016-03-22 18:33:27437 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]f4e25f92013-07-13 20:54:53441 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27442
[email protected]b5651c22013-03-14 15:06:33443 // We have to push properties to pick up the destruction list pointer.
jaydasika9234e402016-03-21 20:44:22444 TreeSynchronizer::PushLayerProperties(old_layer_tree_root->layer_tree_host(),
445 host_->active_tree());
[email protected]5c4824e12013-01-12 16:34:53446
[email protected]b5651c22013-03-14 15:06:33447 // Remove all children on the Layer side.
448 old_layer_tree_root->RemoveAllChildren();
[email protected]c0dd24c2012-08-30 23:25:27449
[email protected]b5651c22013-03-14 15:06:33450 // Synchronize again. After the sync all LayerImpls from the old tree should
451 // be deleted.
loyso0940d412016-03-14 01:30:31452 scoped_refptr<Layer> new_layer_tree_root = Layer::Create();
[email protected]f4e25f92013-07-13 20:54:53453 host_->SetRootLayer(new_layer_tree_root);
vollick83fbfc82016-03-22 18:33:27454
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]f4e25f92013-07-13 20:54:53459 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27460
[email protected]b5651c22013-03-14 15:06:33461 ASSERT_EQ(3u, layer_impl_destruction_list.size());
[email protected]2cdbdba2012-10-28 13:15:05462
[email protected]b5651c22013-03-14 15:06:33463 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]c0dd24c2012-08-30 23:25:27475}
476
477// Constructs+syncs a tree with mask, replica, and replica mask layers.
[email protected]b5651c22013-03-14 15:06:33478TEST_F(TreeSynchronizerTest, SyncMaskReplicaAndReplicaMaskLayers) {
loyso0940d412016-03-14 01:30:31479 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]c0dd24c2012-08-30 23:25:27483
[email protected]b5651c22013-03-14 15:06:33484 // First child gets a mask layer.
loyso0940d412016-03-14 01:30:31485 scoped_refptr<Layer> mask_layer = Layer::Create();
[email protected]b5651c22013-03-14 15:06:33486 layer_tree_root->children()[0]->SetMaskLayer(mask_layer.get());
[email protected]c0dd24c2012-08-30 23:25:27487
[email protected]b5651c22013-03-14 15:06:33488 // Second child gets a replica layer.
loyso0940d412016-03-14 01:30:31489 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]b5651c22013-03-14 15:06:33490 layer_tree_root->children()[1]->SetReplicaLayer(replica_layer.get());
[email protected]c0dd24c2012-08-30 23:25:27491
[email protected]b5651c22013-03-14 15:06:33492 // Third child gets a replica layer with a mask layer.
loyso0940d412016-03-14 01:30:31493 scoped_refptr<Layer> replica_layer_with_mask = Layer::Create();
494 scoped_refptr<Layer> replica_mask_layer = Layer::Create();
[email protected]b5651c22013-03-14 15:06:33495 replica_layer_with_mask->SetMaskLayer(replica_mask_layer.get());
vollick83fbfc82016-03-22 18:33:27496 layer_tree_root->children()[2]->SetReplicaLayer(
497 replica_layer_with_mask.get());
[email protected]c0dd24c2012-08-30 23:25:27498
[email protected]f4e25f92013-07-13 20:54:53499 host_->SetRootLayer(layer_tree_root);
500
vollick83fbfc82016-03-22 18:33:27501 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]f4e25f92013-07-13 20:54:53505 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27506
[email protected]b5651c22013-03-14 15:06:33507 // Remove the mask layer.
508 layer_tree_root->children()[0]->SetMaskLayer(NULL);
vollick83fbfc82016-03-22 18:33:27509 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]f4e25f92013-07-13 20:54:53513 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27514
[email protected]b5651c22013-03-14 15:06:33515 // Remove the replica layer.
516 layer_tree_root->children()[1]->SetReplicaLayer(NULL);
vollick83fbfc82016-03-22 18:33:27517 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]f4e25f92013-07-13 20:54:53521 host_->active_tree());
[email protected]c0dd24c2012-08-30 23:25:27522
[email protected]b5651c22013-03-14 15:06:33523 // Remove the replica mask.
524 replica_layer_with_mask->SetMaskLayer(NULL);
vollick83fbfc82016-03-22 18:33:27525 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]f4e25f92013-07-13 20:54:53529 host_->active_tree());
vollick83fbfc82016-03-22 18:33:27530
531 host_->active_tree()->ClearLayers();
[email protected]c0dd24c2012-08-30 23:25:27532}
533
[email protected]0e98cdd2013-08-23 00:44:30534TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) {
535 LayerTreeSettings settings;
khushalsagarb64b360d2015-10-21 19:25:16536 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]0e98cdd2013-08-23 00:44:30537 FakeRenderingStatsInstrumentation stats_instrumentation;
vollick83fbfc82016-03-22 18:33:27538 FakeLayerTreeHostImplClient impl_client;
danakjcf610582015-06-16 22:48:56539 TestSharedBitmapManager shared_bitmap_manager;
540 TestTaskGraphRunner task_graph_runner;
danakj60bc3bc2016-04-09 00:24:48541 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
vollick83fbfc82016-03-22 18:33:27542 settings, &impl_client, &task_runner_provider, &stats_instrumentation,
khushalsagarb64b360d2015-10-21 19:25:16543 &shared_bitmap_manager, nullptr, &task_graph_runner, 0);
[email protected]0e98cdd2013-08-23 00:44:30544
loyso0940d412016-03-14 01:30:31545 scoped_refptr<Layer> layer_tree_root = Layer::Create();
546 scoped_refptr<Layer> scroll_parent = Layer::Create();
[email protected]0e98cdd2013-08-23 00:44:30547 layer_tree_root->AddChild(scroll_parent);
loyso0940d412016-03-14 01:30:31548 layer_tree_root->AddChild(Layer::Create());
549 layer_tree_root->AddChild(Layer::Create());
[email protected]0e98cdd2013-08-23 00:44:30550
551 host_->SetRootLayer(layer_tree_root);
552
553 // First child is the second and third child's scroll parent.
Daniel Chengeea98042014-08-26 00:28:10554 layer_tree_root->children()[1]->SetScrollParent(scroll_parent.get());
555 layer_tree_root->children()[2]->SetScrollParent(scroll_parent.get());
[email protected]0e98cdd2013-08-23 00:44:30556
vollick83fbfc82016-03-22 18:33:27557 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
558 host_impl->active_tree());
559 LayerImpl* layer_impl_tree_root = host_impl->active_tree()->root_layer();
jaydasika9234e402016-03-21 20:44:22560 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
561 host_impl->active_tree());
[email protected]d097e242014-02-28 21:51:11562 {
563 SCOPED_TRACE("case one");
vollick83fbfc82016-03-22 18:33:27564 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]d097e242014-02-28 21:51:11565 host_impl->active_tree());
566 }
[email protected]0e98cdd2013-08-23 00:44:30567
568 // Remove the first scroll child.
569 layer_tree_root->children()[1]->RemoveFromParent();
vollick83fbfc82016-03-22 18:33:27570 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
571 host_impl->active_tree());
jaydasika9234e402016-03-21 20:44:22572 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
573 host_impl->active_tree());
[email protected]d097e242014-02-28 21:51:11574 {
575 SCOPED_TRACE("case two");
vollick83fbfc82016-03-22 18:33:27576 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]d097e242014-02-28 21:51:11577 host_impl->active_tree());
578 }
[email protected]0e98cdd2013-08-23 00:44:30579
580 // Add an additional scroll layer.
loyso0940d412016-03-14 01:30:31581 scoped_refptr<Layer> additional_scroll_child = Layer::Create();
[email protected]0e98cdd2013-08-23 00:44:30582 layer_tree_root->AddChild(additional_scroll_child);
Daniel Chengeea98042014-08-26 00:28:10583 additional_scroll_child->SetScrollParent(scroll_parent.get());
vollick83fbfc82016-03-22 18:33:27584 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
585 host_impl->active_tree());
jaydasika9234e402016-03-21 20:44:22586 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
587 host_impl->active_tree());
[email protected]d097e242014-02-28 21:51:11588 {
589 SCOPED_TRACE("case three");
vollick83fbfc82016-03-22 18:33:27590 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]d097e242014-02-28 21:51:11591 host_impl->active_tree());
592 }
[email protected]0e98cdd2013-08-23 00:44:30593}
594
595TEST_F(TreeSynchronizerTest, SynchronizeClipParent) {
596 LayerTreeSettings settings;
khushalsagarb64b360d2015-10-21 19:25:16597 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]0e98cdd2013-08-23 00:44:30598 FakeRenderingStatsInstrumentation stats_instrumentation;
vollick83fbfc82016-03-22 18:33:27599 FakeLayerTreeHostImplClient impl_client;
danakjcf610582015-06-16 22:48:56600 TestSharedBitmapManager shared_bitmap_manager;
601 TestTaskGraphRunner task_graph_runner;
danakj60bc3bc2016-04-09 00:24:48602 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
vollick83fbfc82016-03-22 18:33:27603 settings, &impl_client, &task_runner_provider, &stats_instrumentation,
khushalsagarb64b360d2015-10-21 19:25:16604 &shared_bitmap_manager, nullptr, &task_graph_runner, 0);
[email protected]0e98cdd2013-08-23 00:44:30605
loyso0940d412016-03-14 01:30:31606 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]0e98cdd2013-08-23 00:44:30611 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 Chengeea98042014-08-26 00:28:10619 clip_child1->SetClipParent(clip_parent.get());
620 clip_child2->SetClipParent(clip_parent.get());
[email protected]0e98cdd2013-08-23 00:44:30621
vollick83fbfc82016-03-22 18:33:27622 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
623 host_impl->active_tree());
624 LayerImpl* layer_impl_tree_root = host_impl->active_tree()->root_layer();
jaydasika9234e402016-03-21 20:44:22625 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
626 host_impl->active_tree());
vollick83fbfc82016-03-22 18:33:27627 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]0e98cdd2013-08-23 00:44:30628 host_impl->active_tree());
629
630 // Remove the first clip child.
631 clip_child1->RemoveFromParent();
632 clip_child1 = NULL;
633
vollick83fbfc82016-03-22 18:33:27634 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
635 host_impl->active_tree());
jaydasika9234e402016-03-21 20:44:22636 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
637 host_impl->active_tree());
vollick83fbfc82016-03-22 18:33:27638 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]0e98cdd2013-08-23 00:44:30639 host_impl->active_tree());
640
641 // Add an additional clip child.
loyso0940d412016-03-14 01:30:31642 scoped_refptr<Layer> additional_clip_child = Layer::Create();
[email protected]0e98cdd2013-08-23 00:44:30643 intervening->AddChild(additional_clip_child);
Daniel Chengeea98042014-08-26 00:28:10644 additional_clip_child->SetClipParent(clip_parent.get());
vollick83fbfc82016-03-22 18:33:27645 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
646 host_impl->active_tree());
jaydasika9234e402016-03-21 20:44:22647 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
648 host_impl->active_tree());
vollick83fbfc82016-03-22 18:33:27649 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]0e98cdd2013-08-23 00:44:30650 host_impl->active_tree());
651
652 // Remove the nearest clipping ancestor.
653 clip_parent->RemoveFromParent();
654 clip_parent = NULL;
vollick83fbfc82016-03-22 18:33:27655 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
656 host_impl->active_tree());
jaydasika9234e402016-03-21 20:44:22657 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
658 host_impl->active_tree());
vollick83fbfc82016-03-22 18:33:27659 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
[email protected]0e98cdd2013-08-23 00:44:30660 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
sunxd54e08e9d2016-02-22 23:01:28668TEST_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
loyso0940d412016-03-14 01:30:31678 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();
sunxd54e08e9d2016-02-22 23:01:28683
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(
vollickcb3f6b12016-03-01 23:44:10702 host_impl->active_tree()->LayerById(scroll_layer->id()));
sunxd54e08e9d2016-02-22 23:01:28703 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
sunxdc36713a2016-03-03 22:31:10714TEST_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
loyso0940d412016-03-14 01:30:31726 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();
sunxdc36713a2016-03-03 22:31:10731
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;
sunxdc044b11a2016-03-16 16:23:20774 scroll_tree.SetScrollOffset(scroll_layer_impl->id(),
775 gfx::ScrollOffset(20, 30));
sunxdc36713a2016-03-03 22:31:10776
777 // Pull ScrollOffset delta for main thread, and change offset on main thread
danakj60bc3bc2016-04-09 00:24:48778 std::unique_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet());
sunxdc36713a2016-03-03 22:31:10779 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)
sunxdc044b11a2016-03-16 16:23:20786 scroll_tree.SetScrollOffset(scroll_layer_impl->id(),
787 gfx::ScrollOffset(40, 50));
sunxdc36713a2016-03-03 22:31:10788 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]ba565742012-11-10 09:29:48810} // namespace
811} // namespace cc