| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/tree_synchronizer.h" | 5 #include "cc/trees/tree_synchronizer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "cc/layers/layer.h" | 16 #include "cc/layers/layer.h" |
| 17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/test/animation_test_common.h" | 18 #include "cc/test/animation_test_common.h" |
| 19 #include "cc/test/fake_impl_task_runner_provider.h" | 19 #include "cc/test/fake_impl_task_runner_provider.h" |
| 20 #include "cc/test/fake_layer_tree_host.h" | 20 #include "cc/test/fake_layer_tree_host.h" |
| 21 #include "cc/test/fake_rendering_stats_instrumentation.h" | 21 #include "cc/test/fake_rendering_stats_instrumentation.h" |
| 22 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 22 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 23 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
| 24 #include "cc/test/test_task_graph_runner.h" | 24 #include "cc/test/test_task_graph_runner.h" |
| 25 #include "cc/trees/effect_node.h" | 25 #include "cc/trees/effect_node.h" |
| 26 #include "cc/trees/layer_tree_host_common.h" | 26 #include "cc/trees/layer_tree_host_common.h" |
| 27 #include "cc/trees/single_thread_proxy.h" | 27 #include "cc/trees/single_thread_proxy.h" |
| 28 #include "cc/trees/task_runner_provider.h" | 28 #include "cc/trees/task_runner_provider.h" |
| 29 #include "cc/trees/transform_node.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 namespace cc { | 32 namespace cc { |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 class MockLayerImpl : public LayerImpl { | 35 class MockLayerImpl : public LayerImpl { |
| 35 public: | 36 public: |
| 36 static std::unique_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl, | 37 static std::unique_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl, |
| 37 int layer_id) { | 38 int layer_id) { |
| 38 return base::WrapUnique(new MockLayerImpl(tree_impl, layer_id)); | 39 return base::WrapUnique(new MockLayerImpl(tree_impl, layer_id)); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 scroll_offset_map.erase(transient_scroll_layer->id()); | 614 scroll_offset_map.erase(transient_scroll_layer->id()); |
| 614 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(20, 30)); | 615 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(20, 30)); |
| 615 scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); | 616 scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); |
| 616 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); | 617 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); |
| 617 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( | 618 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 618 gfx::ScrollOffset(100, 100)); | 619 gfx::ScrollOffset(100, 100)); |
| 619 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); | 620 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 620 EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); | 621 EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); |
| 621 } | 622 } |
| 622 | 623 |
| 624 TEST_F(TreeSynchronizerTest, |
| 625 SynchronizeScrollTreeScrollOffsetMapFromMainToActive) { |
| 626 host_->InitializeSingleThreaded(&single_thread_client_, |
| 627 base::ThreadTaskRunnerHandle::Get()); |
| 628 FakeLayerTreeHostImpl* host_impl = host_->host_impl(); |
| 629 |
| 630 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 631 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); |
| 632 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 633 |
| 634 layer_tree_root->AddChild(scroll_clip_layer); |
| 635 scroll_clip_layer->AddChild(scroll_layer); |
| 636 |
| 637 scroll_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 638 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 639 |
| 640 host_->SetRootLayer(layer_tree_root); |
| 641 host_->BuildPropertyTreesForTesting(); |
| 642 host_->FinishCommitOnImplThread(host_impl); |
| 643 |
| 644 ExpectTreesAreIdentical(layer_tree_root.get(), |
| 645 host_impl->active_tree()->root_layer_for_testing(), |
| 646 host_impl->active_tree()); |
| 647 |
| 648 // After the initial commit, scroll_offset_map in scroll_tree is expected to |
| 649 // have one entry for scroll_layer and one entry for transient_scroll_layer, |
| 650 // the pending base and active base must be the same at this stage. |
| 651 ScrollTree::ScrollOffsetMap scroll_offset_map; |
| 652 scroll_offset_map[scroll_layer->id()] = new SyncedScrollOffset; |
| 653 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 654 scroll_layer->scroll_offset()); |
| 655 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 656 EXPECT_TRUE( |
| 657 is_equal(scroll_offset_map, host_impl->active_tree() |
| 658 ->property_trees() |
| 659 ->scroll_tree.scroll_offset_map())); |
| 660 |
| 661 // When running Layout tests in single thread mode, it is possible that the |
| 662 // scroll tree's scroll offset map got cleared between commits, as a new test |
| 663 // is started after finishing the previous one. |
| 664 host_->property_trees()->scroll_tree.scroll_offset_map().clear(); |
| 665 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); |
| 666 |
| 667 host_->BuildPropertyTreesForTesting(); |
| 668 host_->FinishCommitOnImplThread(host_impl); |
| 669 |
| 670 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 671 gfx::ScrollOffset(0, 0)); |
| 672 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 673 EXPECT_TRUE( |
| 674 is_equal(scroll_offset_map, host_impl->active_tree() |
| 675 ->property_trees() |
| 676 ->scroll_tree.scroll_offset_map())); |
| 677 EXPECT_EQ(host_impl->active_tree() |
| 678 ->property_trees() |
| 679 ->transform_tree.Node(scroll_layer->transform_tree_index()) |
| 680 ->scroll_offset, |
| 681 gfx::ScrollOffset(0, 0)); |
| 682 } |
| 683 |
| 623 TEST_F(TreeSynchronizerTest, RefreshPropertyTreesCachedData) { | 684 TEST_F(TreeSynchronizerTest, RefreshPropertyTreesCachedData) { |
| 624 host_->InitializeSingleThreaded(&single_thread_client_, | 685 host_->InitializeSingleThreaded(&single_thread_client_, |
| 625 base::ThreadTaskRunnerHandle::Get()); | 686 base::ThreadTaskRunnerHandle::Get()); |
| 626 LayerTreeSettings settings; | 687 LayerTreeSettings settings; |
| 627 FakeLayerTreeHostImplClient client; | 688 FakeLayerTreeHostImplClient client; |
| 628 FakeImplTaskRunnerProvider task_runner_provider; | 689 FakeImplTaskRunnerProvider task_runner_provider; |
| 629 FakeRenderingStatsInstrumentation stats_instrumentation; | 690 FakeRenderingStatsInstrumentation stats_instrumentation; |
| 630 TestSharedBitmapManager shared_bitmap_manager; | 691 TestSharedBitmapManager shared_bitmap_manager; |
| 631 TestTaskGraphRunner task_graph_runner; | 692 TestTaskGraphRunner task_graph_runner; |
| 632 FakeLayerTreeHostImpl* host_impl = host_->host_impl(); | 693 FakeLayerTreeHostImpl* host_impl = host_->host_impl(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 661 host_->CommitAndCreatePendingTree(); | 722 host_->CommitAndCreatePendingTree(); |
| 662 host_impl->ActivateSyncTree(); | 723 host_impl->ActivateSyncTree(); |
| 663 EXPECT_EQ( | 724 EXPECT_EQ( |
| 664 CombinedAnimationScale(0.f, 0.f), | 725 CombinedAnimationScale(0.f, 0.f), |
| 665 host_impl->active_tree()->property_trees()->GetAnimationScales( | 726 host_impl->active_tree()->property_trees()->GetAnimationScales( |
| 666 transform_layer->transform_tree_index(), host_impl->active_tree())); | 727 transform_layer->transform_tree_index(), host_impl->active_tree())); |
| 667 } | 728 } |
| 668 | 729 |
| 669 } // namespace | 730 } // namespace |
| 670 } // namespace cc | 731 } // namespace cc |
| OLD | NEW |