| 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 "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "cc/animation/animation_host.h" | 17 #include "cc/animation/animation_host.h" |
| 18 #include "cc/layers/layer.h" | 18 #include "cc/layers/layer.h" |
| 19 #include "cc/layers/layer_impl.h" | 19 #include "cc/layers/layer_impl.h" |
| 20 #include "cc/test/animation_test_common.h" | 20 #include "cc/test/animation_test_common.h" |
| 21 #include "cc/test/fake_impl_task_runner_provider.h" | 21 #include "cc/test/fake_impl_task_runner_provider.h" |
| 22 #include "cc/test/fake_layer_tree_host.h" | 22 #include "cc/test/fake_layer_tree_host.h" |
| 23 #include "cc/test/fake_rendering_stats_instrumentation.h" | 23 #include "cc/test/fake_rendering_stats_instrumentation.h" |
| 24 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 24 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 25 #include "cc/test/test_task_graph_runner.h" | 25 #include "cc/test/test_task_graph_runner.h" |
| 26 #include "cc/trees/effect_node.h" | 26 #include "cc/trees/effect_node.h" |
| 27 #include "cc/trees/layer_tree_host_common.h" | 27 #include "cc/trees/layer_tree_host_common.h" |
| 28 #include "cc/trees/scroll_node.h" |
| 28 #include "cc/trees/single_thread_proxy.h" | 29 #include "cc/trees/single_thread_proxy.h" |
| 29 #include "cc/trees/task_runner_provider.h" | 30 #include "cc/trees/task_runner_provider.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 namespace cc { | 33 namespace cc { |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 bool AreScrollOffsetsEqual(const SyncedScrollOffset* a, | 36 bool AreScrollOffsetsEqual(const SyncedScrollOffset* a, |
| 36 const SyncedScrollOffset* b) { | 37 const SyncedScrollOffset* b) { |
| 37 return a->ActiveBase() == b->ActiveBase() && | 38 return a->ActiveBase() == b->ActiveBase() && |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 scroll_layer->SetScrollClipLayerId(scroll_clip_layer->id()); | 498 scroll_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 498 host_->SetRootLayer(layer_tree_root); | 499 host_->SetRootLayer(layer_tree_root); |
| 499 host_->BuildPropertyTreesForTesting(); | 500 host_->BuildPropertyTreesForTesting(); |
| 500 host_->CommitAndCreatePendingTree(); | 501 host_->CommitAndCreatePendingTree(); |
| 501 host_impl->ActivateSyncTree(); | 502 host_impl->ActivateSyncTree(); |
| 502 | 503 |
| 503 ExpectTreesAreIdentical(layer_tree_root.get(), | 504 ExpectTreesAreIdentical(layer_tree_root.get(), |
| 504 host_impl->active_tree()->root_layer_for_testing(), | 505 host_impl->active_tree()->root_layer_for_testing(), |
| 505 host_impl->active_tree()); | 506 host_impl->active_tree()); |
| 506 | 507 |
| 507 host_impl->active_tree()->SetCurrentlyScrollingLayer( | 508 ScrollNode* scroll_node = |
| 508 host_impl->active_tree()->LayerById(scroll_layer->id())); | 509 host_impl->active_tree()->property_trees()->scroll_tree.Node( |
| 510 scroll_layer->scroll_tree_index()); |
| 511 host_impl->active_tree()->SetCurrentlyScrollingNode(scroll_node); |
| 509 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); | 512 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); |
| 510 host_->BuildPropertyTreesForTesting(); | 513 host_->BuildPropertyTreesForTesting(); |
| 511 | 514 |
| 512 host_impl->CreatePendingTree(); | 515 host_impl->CreatePendingTree(); |
| 513 host_->CommitAndCreatePendingTree(); | 516 host_->CommitAndCreatePendingTree(); |
| 514 host_impl->ActivateSyncTree(); | 517 host_impl->ActivateSyncTree(); |
| 515 | 518 |
| 516 EXPECT_EQ(scroll_layer->id(), | 519 EXPECT_EQ(scroll_layer->scroll_tree_index(), |
| 517 host_impl->active_tree()->CurrentlyScrollingLayer()->id()); | 520 host_impl->active_tree()->CurrentlyScrollingNode()->id); |
| 518 } | 521 } |
| 519 | 522 |
| 520 TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) { | 523 TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) { |
| 521 host_->InitializeSingleThreaded(&single_thread_client_, | 524 host_->InitializeSingleThreaded(&single_thread_client_, |
| 522 base::ThreadTaskRunnerHandle::Get()); | 525 base::ThreadTaskRunnerHandle::Get()); |
| 523 LayerTreeSettings settings; | 526 LayerTreeSettings settings; |
| 524 FakeLayerTreeHostImplClient client; | 527 FakeLayerTreeHostImplClient client; |
| 525 FakeImplTaskRunnerProvider task_runner_provider; | 528 FakeImplTaskRunnerProvider task_runner_provider; |
| 526 FakeRenderingStatsInstrumentation stats_instrumentation; | 529 FakeRenderingStatsInstrumentation stats_instrumentation; |
| 527 TestTaskGraphRunner task_graph_runner; | 530 TestTaskGraphRunner task_graph_runner; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 std::unique_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 593 std::unique_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
| 591 scroll_tree.CollectScrollDeltas(scroll_info.get(), Layer::INVALID_ID); | 594 scroll_tree.CollectScrollDeltas(scroll_info.get(), Layer::INVALID_ID); |
| 592 host_->proxy()->SetNeedsCommit(); | 595 host_->proxy()->SetNeedsCommit(); |
| 593 host_->ApplyScrollAndScale(scroll_info.get()); | 596 host_->ApplyScrollAndScale(scroll_info.get()); |
| 594 EXPECT_EQ(gfx::ScrollOffset(20, 30), scroll_layer->scroll_offset()); | 597 EXPECT_EQ(gfx::ScrollOffset(20, 30), scroll_layer->scroll_offset()); |
| 595 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 100)); | 598 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
| 596 | 599 |
| 597 // More update to ScrollOffset active delta: gfx::ScrollOffset(20, 20) | 600 // More update to ScrollOffset active delta: gfx::ScrollOffset(20, 20) |
| 598 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), | 601 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), |
| 599 gfx::ScrollOffset(40, 50)); | 602 gfx::ScrollOffset(40, 50)); |
| 600 host_impl->active_tree()->SetCurrentlyScrollingLayer(scroll_layer_impl); | 603 host_impl->active_tree()->SetCurrentlyScrollingNode( |
| 604 scroll_tree.Node(scroll_layer_impl->scroll_tree_index())); |
| 601 | 605 |
| 602 // Make one layer unscrollable so that scroll tree topology changes | 606 // Make one layer unscrollable so that scroll tree topology changes |
| 603 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); | 607 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); |
| 604 host_->BuildPropertyTreesForTesting(); | 608 host_->BuildPropertyTreesForTesting(); |
| 605 | 609 |
| 606 host_impl->CreatePendingTree(); | 610 host_impl->CreatePendingTree(); |
| 607 host_->CommitAndCreatePendingTree(); | 611 host_->CommitAndCreatePendingTree(); |
| 608 host_impl->ActivateSyncTree(); | 612 host_impl->ActivateSyncTree(); |
| 609 | 613 |
| 610 EXPECT_EQ(scroll_layer->id(), | 614 EXPECT_EQ(scroll_layer->scroll_tree_index(), |
| 611 host_impl->active_tree()->CurrentlyScrollingLayer()->id()); | 615 host_impl->active_tree()->CurrentlyScrollingNode()->id); |
| 612 scroll_layer_offset->SetCurrent(gfx::ScrollOffset(20, 30)); | 616 scroll_layer_offset->SetCurrent(gfx::ScrollOffset(20, 30)); |
| 613 scroll_layer_offset->PullDeltaForMainThread(); | 617 scroll_layer_offset->PullDeltaForMainThread(); |
| 614 scroll_layer_offset->SetCurrent(gfx::ScrollOffset(40, 50)); | 618 scroll_layer_offset->SetCurrent(gfx::ScrollOffset(40, 50)); |
| 615 scroll_layer_offset->PushFromMainThread(gfx::ScrollOffset(100, 100)); | 619 scroll_layer_offset->PushFromMainThread(gfx::ScrollOffset(100, 100)); |
| 616 scroll_layer_offset->PushPendingToActive(); | 620 scroll_layer_offset->PushPendingToActive(); |
| 617 EXPECT_TRUE(AreScrollOffsetsEqual( | 621 EXPECT_TRUE(AreScrollOffsetsEqual( |
| 618 scroll_layer_offset.get(), | 622 scroll_layer_offset.get(), |
| 619 host_impl->active_tree() | 623 host_impl->active_tree() |
| 620 ->property_trees() | 624 ->property_trees() |
| 621 ->scroll_tree.GetSyncedScrollOffset(scroll_layer->id()))); | 625 ->scroll_tree.GetSyncedScrollOffset(scroll_layer->id()))); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 host_->CommitAndCreatePendingTree(); | 669 host_->CommitAndCreatePendingTree(); |
| 666 host_impl->ActivateSyncTree(); | 670 host_impl->ActivateSyncTree(); |
| 667 EXPECT_EQ( | 671 EXPECT_EQ( |
| 668 CombinedAnimationScale(0.f, 0.f), | 672 CombinedAnimationScale(0.f, 0.f), |
| 669 host_impl->active_tree()->property_trees()->GetAnimationScales( | 673 host_impl->active_tree()->property_trees()->GetAnimationScales( |
| 670 transform_layer->transform_tree_index(), host_impl->active_tree())); | 674 transform_layer->transform_tree_index(), host_impl->active_tree())); |
| 671 } | 675 } |
| 672 | 676 |
| 673 } // namespace | 677 } // namespace |
| 674 } // namespace cc | 678 } // namespace cc |
| OLD | NEW |