Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: cc/trees/tree_synchronizer_unittest.cc

Issue 2621403003: cc: Don't create SyncedPropety instances on the main thread. (Closed)
Patch Set: win test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/property_tree.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 14 matching lines...) Expand all
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/single_thread_proxy.h" 28 #include "cc/trees/single_thread_proxy.h"
29 #include "cc/trees/task_runner_provider.h" 29 #include "cc/trees/task_runner_provider.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 31
32 namespace cc { 32 namespace cc {
33 namespace { 33 namespace {
34 34
35 bool AreScrollOffsetsEqual(const SyncedScrollOffset* a,
36 const SyncedScrollOffset* b) {
37 return a->ActiveBase() == b->ActiveBase() &&
38 a->PendingBase() == b->PendingBase() && a->Delta() == b->Delta() &&
39 a->PendingDelta().get() == b->PendingDelta().get();
40 }
41
35 class MockLayerImpl : public LayerImpl { 42 class MockLayerImpl : public LayerImpl {
36 public: 43 public:
37 static std::unique_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl, 44 static std::unique_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl,
38 int layer_id) { 45 int layer_id) {
39 return base::WrapUnique(new MockLayerImpl(tree_impl, layer_id)); 46 return base::WrapUnique(new MockLayerImpl(tree_impl, layer_id));
40 } 47 }
41 ~MockLayerImpl() override { 48 ~MockLayerImpl() override {
42 if (layer_impl_destruction_list_) 49 if (layer_impl_destruction_list_)
43 layer_impl_destruction_list_->push_back(id()); 50 layer_impl_destruction_list_->push_back(id());
44 } 51 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 134 }
128 135
129 class TreeSynchronizerTest : public testing::Test { 136 class TreeSynchronizerTest : public testing::Test {
130 protected: 137 protected:
131 TreeSynchronizerTest() 138 TreeSynchronizerTest()
132 : animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)), 139 : animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)),
133 host_(FakeLayerTreeHost::Create(&client_, 140 host_(FakeLayerTreeHost::Create(&client_,
134 &task_graph_runner_, 141 &task_graph_runner_,
135 animation_host_.get())) {} 142 animation_host_.get())) {}
136 143
137 bool is_equal(ScrollTree::ScrollOffsetMap map,
138 ScrollTree::ScrollOffsetMap other) {
139 if (map.size() != other.size())
140 return false;
141 for (auto& map_entry : map) {
142 if (other.find(map_entry.first) == other.end())
143 return false;
144 SyncedScrollOffset& from_map = *map_entry.second.get();
145 SyncedScrollOffset& from_other = *other[map_entry.first].get();
146 if (from_map.PendingBase() != from_other.PendingBase() ||
147 from_map.ActiveBase() != from_other.ActiveBase() ||
148 from_map.Delta() != from_other.Delta() ||
149 from_map.PendingDelta().get() != from_other.PendingDelta().get())
150 return false;
151 }
152 return true;
153 }
154
155 FakeLayerTreeHostClient client_; 144 FakeLayerTreeHostClient client_;
156 StubLayerTreeHostSingleThreadClient single_thread_client_; 145 StubLayerTreeHostSingleThreadClient single_thread_client_;
157 TestTaskGraphRunner task_graph_runner_; 146 TestTaskGraphRunner task_graph_runner_;
158 std::unique_ptr<AnimationHost> animation_host_; 147 std::unique_ptr<AnimationHost> animation_host_;
159 std::unique_ptr<FakeLayerTreeHost> host_; 148 std::unique_ptr<FakeLayerTreeHost> host_;
160 }; 149 };
161 150
162 // Attempts to synchronizes a null tree. This should not crash, and should 151 // Attempts to synchronizes a null tree. This should not crash, and should
163 // return a null tree. 152 // return a null tree.
164 TEST_F(TreeSynchronizerTest, SyncNullTree) { 153 TEST_F(TreeSynchronizerTest, SyncNullTree) {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 host_->CommitAndCreatePendingTree(); 550 host_->CommitAndCreatePendingTree();
562 host_impl->ActivateSyncTree(); 551 host_impl->ActivateSyncTree();
563 552
564 ExpectTreesAreIdentical(layer_tree_root.get(), 553 ExpectTreesAreIdentical(layer_tree_root.get(),
565 host_impl->active_tree()->root_layer_for_testing(), 554 host_impl->active_tree()->root_layer_for_testing(),
566 host_impl->active_tree()); 555 host_impl->active_tree());
567 556
568 // After the initial commit, scroll_offset_map in scroll_tree is expected to 557 // After the initial commit, scroll_offset_map in scroll_tree is expected to
569 // have one entry for scroll_layer and one entry for transient_scroll_layer, 558 // have one entry for scroll_layer and one entry for transient_scroll_layer,
570 // the pending base and active base must be the same at this stage. 559 // the pending base and active base must be the same at this stage.
571 ScrollTree::ScrollOffsetMap scroll_offset_map; 560 scoped_refptr<SyncedScrollOffset> scroll_layer_offset =
572 scroll_offset_map[scroll_layer->id()] = new SyncedScrollOffset; 561 new SyncedScrollOffset;
573 scroll_offset_map[transient_scroll_layer->id()] = new SyncedScrollOffset; 562 scroll_layer_offset->PushFromMainThread(scroll_layer->scroll_offset());
574 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( 563 scroll_layer_offset->PushPendingToActive();
575 scroll_layer->scroll_offset()); 564 EXPECT_TRUE(AreScrollOffsetsEqual(
576 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); 565 scroll_layer_offset.get(),
577 scroll_offset_map[transient_scroll_layer->id()]->PushFromMainThread( 566 host_impl->active_tree()
567 ->property_trees()
568 ->scroll_tree.GetSyncedScrollOffset(scroll_layer->id())));
569
570 scoped_refptr<SyncedScrollOffset> transient_scroll_layer_offset =
571 new SyncedScrollOffset;
572 transient_scroll_layer_offset->PushFromMainThread(
578 transient_scroll_layer->scroll_offset()); 573 transient_scroll_layer->scroll_offset());
579 scroll_offset_map[transient_scroll_layer->id()]->PushPendingToActive(); 574 transient_scroll_layer_offset->PushPendingToActive();
580 EXPECT_TRUE( 575 EXPECT_TRUE(AreScrollOffsetsEqual(
581 is_equal(scroll_offset_map, host_impl->active_tree() 576 transient_scroll_layer_offset.get(),
582 ->property_trees() 577 host_impl->active_tree()
583 ->scroll_tree.scroll_offset_map())); 578 ->property_trees()
579 ->scroll_tree.GetSyncedScrollOffset(transient_scroll_layer->id())));
584 580
585 // Set ScrollOffset active delta: gfx::ScrollOffset(10, 10) 581 // Set ScrollOffset active delta: gfx::ScrollOffset(10, 10)
586 LayerImpl* scroll_layer_impl = 582 LayerImpl* scroll_layer_impl =
587 host_impl->active_tree()->LayerById(scroll_layer->id()); 583 host_impl->active_tree()->LayerById(scroll_layer->id());
588 ScrollTree& scroll_tree = 584 ScrollTree& scroll_tree =
589 host_impl->active_tree()->property_trees()->scroll_tree; 585 host_impl->active_tree()->property_trees()->scroll_tree;
590 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), 586 scroll_tree.SetScrollOffset(scroll_layer_impl->id(),
591 gfx::ScrollOffset(20, 30)); 587 gfx::ScrollOffset(20, 30));
592 588
593 // Pull ScrollOffset delta for main thread, and change offset on main thread 589 // Pull ScrollOffset delta for main thread, and change offset on main thread
(...skipping 12 matching lines...) Expand all
606 // Make one layer unscrollable so that scroll tree topology changes 602 // Make one layer unscrollable so that scroll tree topology changes
607 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); 603 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID);
608 host_->BuildPropertyTreesForTesting(); 604 host_->BuildPropertyTreesForTesting();
609 605
610 host_impl->CreatePendingTree(); 606 host_impl->CreatePendingTree();
611 host_->CommitAndCreatePendingTree(); 607 host_->CommitAndCreatePendingTree();
612 host_impl->ActivateSyncTree(); 608 host_impl->ActivateSyncTree();
613 609
614 EXPECT_EQ(scroll_layer->id(), 610 EXPECT_EQ(scroll_layer->id(),
615 host_impl->active_tree()->CurrentlyScrollingLayer()->id()); 611 host_impl->active_tree()->CurrentlyScrollingLayer()->id());
616 scroll_offset_map.erase(transient_scroll_layer->id()); 612 scroll_layer_offset->SetCurrent(gfx::ScrollOffset(20, 30));
617 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(20, 30)); 613 scroll_layer_offset->PullDeltaForMainThread();
618 scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); 614 scroll_layer_offset->SetCurrent(gfx::ScrollOffset(40, 50));
619 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); 615 scroll_layer_offset->PushFromMainThread(gfx::ScrollOffset(100, 100));
620 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( 616 scroll_layer_offset->PushPendingToActive();
621 gfx::ScrollOffset(100, 100)); 617 EXPECT_TRUE(AreScrollOffsetsEqual(
622 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); 618 scroll_layer_offset.get(),
623 EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); 619 host_impl->active_tree()
620 ->property_trees()
621 ->scroll_tree.GetSyncedScrollOffset(scroll_layer->id())));
622 EXPECT_EQ(nullptr, host_impl->active_tree()
623 ->property_trees()
624 ->scroll_tree.GetSyncedScrollOffset(
625 transient_scroll_layer->id()));
624 } 626 }
625 627
626 TEST_F(TreeSynchronizerTest, RefreshPropertyTreesCachedData) { 628 TEST_F(TreeSynchronizerTest, RefreshPropertyTreesCachedData) {
627 host_->InitializeSingleThreaded(&single_thread_client_, 629 host_->InitializeSingleThreaded(&single_thread_client_,
628 base::ThreadTaskRunnerHandle::Get()); 630 base::ThreadTaskRunnerHandle::Get());
629 LayerTreeSettings settings; 631 LayerTreeSettings settings;
630 FakeLayerTreeHostImplClient client; 632 FakeLayerTreeHostImplClient client;
631 FakeImplTaskRunnerProvider task_runner_provider; 633 FakeImplTaskRunnerProvider task_runner_provider;
632 FakeRenderingStatsInstrumentation stats_instrumentation; 634 FakeRenderingStatsInstrumentation stats_instrumentation;
633 TestTaskGraphRunner task_graph_runner; 635 TestTaskGraphRunner task_graph_runner;
(...skipping 29 matching lines...) Expand all
663 host_->CommitAndCreatePendingTree(); 665 host_->CommitAndCreatePendingTree();
664 host_impl->ActivateSyncTree(); 666 host_impl->ActivateSyncTree();
665 EXPECT_EQ( 667 EXPECT_EQ(
666 CombinedAnimationScale(0.f, 0.f), 668 CombinedAnimationScale(0.f, 0.f),
667 host_impl->active_tree()->property_trees()->GetAnimationScales( 669 host_impl->active_tree()->property_trees()->GetAnimationScales(
668 transform_layer->transform_tree_index(), host_impl->active_tree())); 670 transform_layer->transform_tree_index(), host_impl->active_tree()));
669 } 671 }
670 672
671 } // namespace 673 } // namespace
672 } // namespace cc 674 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698