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/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "cc/animation/layer_animation_controller.h" | 16 #include "cc/animation/layer_animation_controller.h" |
16 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
17 #include "cc/layers/layer_impl.h" | 18 #include "cc/layers/layer_impl.h" |
18 #include "cc/test/animation_test_common.h" | 19 #include "cc/test/animation_test_common.h" |
19 #include "cc/test/fake_impl_task_runner_provider.h" | 20 #include "cc/test/fake_impl_task_runner_provider.h" |
20 #include "cc/test/fake_layer_tree_host.h" | 21 #include "cc/test/fake_layer_tree_host.h" |
21 #include "cc/test/fake_rendering_stats_instrumentation.h" | 22 #include "cc/test/fake_rendering_stats_instrumentation.h" |
22 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
23 #include "cc/test/test_task_graph_runner.h" | 24 #include "cc/test/test_task_graph_runner.h" |
24 #include "cc/trees/layer_tree_host_common.h" | 25 #include "cc/trees/layer_tree_host_common.h" |
25 #include "cc/trees/single_thread_proxy.h" | 26 #include "cc/trees/single_thread_proxy.h" |
26 #include "cc/trees/task_runner_provider.h" | 27 #include "cc/trees/task_runner_provider.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 namespace cc { | 30 namespace cc { |
30 namespace { | 31 namespace { |
31 | 32 |
32 class MockLayerImpl : public LayerImpl { | 33 class MockLayerImpl : public LayerImpl { |
33 public: | 34 public: |
34 static scoped_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl, | 35 static std::unique_ptr<MockLayerImpl> Create(LayerTreeImpl* tree_impl, |
35 int layer_id) { | 36 int layer_id) { |
36 return make_scoped_ptr(new MockLayerImpl(tree_impl, layer_id)); | 37 return base::WrapUnique(new MockLayerImpl(tree_impl, layer_id)); |
37 } | 38 } |
38 ~MockLayerImpl() override { | 39 ~MockLayerImpl() override { |
39 if (layer_impl_destruction_list_) | 40 if (layer_impl_destruction_list_) |
40 layer_impl_destruction_list_->push_back(id()); | 41 layer_impl_destruction_list_->push_back(id()); |
41 } | 42 } |
42 | 43 |
43 void SetLayerImplDestructionList(std::vector<int>* list) { | 44 void SetLayerImplDestructionList(std::vector<int>* list) { |
44 layer_impl_destruction_list_ = list; | 45 layer_impl_destruction_list_ = list; |
45 } | 46 } |
46 | 47 |
47 private: | 48 private: |
48 MockLayerImpl(LayerTreeImpl* tree_impl, int layer_id) | 49 MockLayerImpl(LayerTreeImpl* tree_impl, int layer_id) |
49 : LayerImpl(tree_impl, layer_id), layer_impl_destruction_list_(NULL) {} | 50 : LayerImpl(tree_impl, layer_id), layer_impl_destruction_list_(NULL) {} |
50 | 51 |
51 std::vector<int>* layer_impl_destruction_list_; | 52 std::vector<int>* layer_impl_destruction_list_; |
52 }; | 53 }; |
53 | 54 |
54 class MockLayer : public Layer { | 55 class MockLayer : public Layer { |
55 public: | 56 public: |
56 static scoped_refptr<MockLayer> Create( | 57 static scoped_refptr<MockLayer> Create( |
57 std::vector<int>* layer_impl_destruction_list) { | 58 std::vector<int>* layer_impl_destruction_list) { |
58 return make_scoped_refptr(new MockLayer(layer_impl_destruction_list)); | 59 return make_scoped_refptr(new MockLayer(layer_impl_destruction_list)); |
59 } | 60 } |
60 | 61 |
61 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override { | 62 std::unique_ptr<LayerImpl> CreateLayerImpl( |
| 63 LayerTreeImpl* tree_impl) override { |
62 return MockLayerImpl::Create(tree_impl, layer_id_); | 64 return MockLayerImpl::Create(tree_impl, layer_id_); |
63 } | 65 } |
64 | 66 |
65 void PushPropertiesTo(LayerImpl* layer_impl) override { | 67 void PushPropertiesTo(LayerImpl* layer_impl) override { |
66 Layer::PushPropertiesTo(layer_impl); | 68 Layer::PushPropertiesTo(layer_impl); |
67 | 69 |
68 MockLayerImpl* mock_layer_impl = static_cast<MockLayerImpl*>(layer_impl); | 70 MockLayerImpl* mock_layer_impl = static_cast<MockLayerImpl*>(layer_impl); |
69 mock_layer_impl->SetLayerImplDestructionList(layer_impl_destruction_list_); | 71 mock_layer_impl->SetLayerImplDestructionList(layer_impl_destruction_list_); |
70 } | 72 } |
71 | 73 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 167 |
166 class TreeSynchronizerTest : public testing::Test { | 168 class TreeSynchronizerTest : public testing::Test { |
167 public: | 169 public: |
168 TreeSynchronizerTest() | 170 TreeSynchronizerTest() |
169 : client_(FakeLayerTreeHostClient::DIRECT_3D), | 171 : client_(FakeLayerTreeHostClient::DIRECT_3D), |
170 host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_)) {} | 172 host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_)) {} |
171 | 173 |
172 protected: | 174 protected: |
173 FakeLayerTreeHostClient client_; | 175 FakeLayerTreeHostClient client_; |
174 TestTaskGraphRunner task_graph_runner_; | 176 TestTaskGraphRunner task_graph_runner_; |
175 scoped_ptr<FakeLayerTreeHost> host_; | 177 std::unique_ptr<FakeLayerTreeHost> host_; |
176 | 178 |
177 bool is_equal(ScrollTree::ScrollOffsetMap map, | 179 bool is_equal(ScrollTree::ScrollOffsetMap map, |
178 ScrollTree::ScrollOffsetMap other) { | 180 ScrollTree::ScrollOffsetMap other) { |
179 if (map.size() != other.size()) | 181 if (map.size() != other.size()) |
180 return false; | 182 return false; |
181 for (auto& map_entry : map) { | 183 for (auto& map_entry : map) { |
182 if (other.find(map_entry.first) == other.end()) | 184 if (other.find(map_entry.first) == other.end()) |
183 return false; | 185 return false; |
184 SyncedScrollOffset& from_map = *map_entry.second.get(); | 186 SyncedScrollOffset& from_map = *map_entry.second.get(); |
185 SyncedScrollOffset& from_other = *other[map_entry.first].get(); | 187 SyncedScrollOffset& from_other = *other[map_entry.first].get(); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 host_->active_tree()->ClearLayers(); | 531 host_->active_tree()->ClearLayers(); |
530 } | 532 } |
531 | 533 |
532 TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) { | 534 TEST_F(TreeSynchronizerTest, SynchronizeScrollParent) { |
533 LayerTreeSettings settings; | 535 LayerTreeSettings settings; |
534 FakeImplTaskRunnerProvider task_runner_provider; | 536 FakeImplTaskRunnerProvider task_runner_provider; |
535 FakeRenderingStatsInstrumentation stats_instrumentation; | 537 FakeRenderingStatsInstrumentation stats_instrumentation; |
536 FakeLayerTreeHostImplClient impl_client; | 538 FakeLayerTreeHostImplClient impl_client; |
537 TestSharedBitmapManager shared_bitmap_manager; | 539 TestSharedBitmapManager shared_bitmap_manager; |
538 TestTaskGraphRunner task_graph_runner; | 540 TestTaskGraphRunner task_graph_runner; |
539 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 541 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
540 settings, &impl_client, &task_runner_provider, &stats_instrumentation, | 542 settings, &impl_client, &task_runner_provider, &stats_instrumentation, |
541 &shared_bitmap_manager, nullptr, &task_graph_runner, 0); | 543 &shared_bitmap_manager, nullptr, &task_graph_runner, 0); |
542 | 544 |
543 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 545 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
544 scoped_refptr<Layer> scroll_parent = Layer::Create(); | 546 scoped_refptr<Layer> scroll_parent = Layer::Create(); |
545 layer_tree_root->AddChild(scroll_parent); | 547 layer_tree_root->AddChild(scroll_parent); |
546 layer_tree_root->AddChild(Layer::Create()); | 548 layer_tree_root->AddChild(Layer::Create()); |
547 layer_tree_root->AddChild(Layer::Create()); | 549 layer_tree_root->AddChild(Layer::Create()); |
548 | 550 |
549 host_->SetRootLayer(layer_tree_root); | 551 host_->SetRootLayer(layer_tree_root); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 592 } |
591 } | 593 } |
592 | 594 |
593 TEST_F(TreeSynchronizerTest, SynchronizeClipParent) { | 595 TEST_F(TreeSynchronizerTest, SynchronizeClipParent) { |
594 LayerTreeSettings settings; | 596 LayerTreeSettings settings; |
595 FakeImplTaskRunnerProvider task_runner_provider; | 597 FakeImplTaskRunnerProvider task_runner_provider; |
596 FakeRenderingStatsInstrumentation stats_instrumentation; | 598 FakeRenderingStatsInstrumentation stats_instrumentation; |
597 FakeLayerTreeHostImplClient impl_client; | 599 FakeLayerTreeHostImplClient impl_client; |
598 TestSharedBitmapManager shared_bitmap_manager; | 600 TestSharedBitmapManager shared_bitmap_manager; |
599 TestTaskGraphRunner task_graph_runner; | 601 TestTaskGraphRunner task_graph_runner; |
600 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 602 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
601 settings, &impl_client, &task_runner_provider, &stats_instrumentation, | 603 settings, &impl_client, &task_runner_provider, &stats_instrumentation, |
602 &shared_bitmap_manager, nullptr, &task_graph_runner, 0); | 604 &shared_bitmap_manager, nullptr, &task_graph_runner, 0); |
603 | 605 |
604 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 606 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
605 scoped_refptr<Layer> clip_parent = Layer::Create(); | 607 scoped_refptr<Layer> clip_parent = Layer::Create(); |
606 scoped_refptr<Layer> intervening = Layer::Create(); | 608 scoped_refptr<Layer> intervening = Layer::Create(); |
607 scoped_refptr<Layer> clip_child1 = Layer::Create(); | 609 scoped_refptr<Layer> clip_child1 = Layer::Create(); |
608 scoped_refptr<Layer> clip_child2 = Layer::Create(); | 610 scoped_refptr<Layer> clip_child2 = Layer::Create(); |
609 layer_tree_root->AddChild(clip_parent); | 611 layer_tree_root->AddChild(clip_parent); |
610 clip_parent->AddChild(intervening); | 612 clip_parent->AddChild(intervening); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 | 768 |
767 // Set ScrollOffset active delta: gfx::ScrollOffset(10, 10) | 769 // Set ScrollOffset active delta: gfx::ScrollOffset(10, 10) |
768 LayerImpl* scroll_layer_impl = | 770 LayerImpl* scroll_layer_impl = |
769 host_impl->active_tree()->LayerById(scroll_layer->id()); | 771 host_impl->active_tree()->LayerById(scroll_layer->id()); |
770 ScrollTree& scroll_tree = | 772 ScrollTree& scroll_tree = |
771 host_impl->active_tree()->property_trees()->scroll_tree; | 773 host_impl->active_tree()->property_trees()->scroll_tree; |
772 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), | 774 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), |
773 gfx::ScrollOffset(20, 30)); | 775 gfx::ScrollOffset(20, 30)); |
774 | 776 |
775 // Pull ScrollOffset delta for main thread, and change offset on main thread | 777 // Pull ScrollOffset delta for main thread, and change offset on main thread |
776 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 778 std::unique_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
777 scroll_tree.CollectScrollDeltas(scroll_info.get()); | 779 scroll_tree.CollectScrollDeltas(scroll_info.get()); |
778 host_->proxy()->SetNeedsCommit(); | 780 host_->proxy()->SetNeedsCommit(); |
779 host_->ApplyScrollAndScale(scroll_info.get()); | 781 host_->ApplyScrollAndScale(scroll_info.get()); |
780 EXPECT_EQ(gfx::ScrollOffset(20, 30), scroll_layer->scroll_offset()); | 782 EXPECT_EQ(gfx::ScrollOffset(20, 30), scroll_layer->scroll_offset()); |
781 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 100)); | 783 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
782 | 784 |
783 // More update to ScrollOffset active delta: gfx::ScrollOffset(20, 20) | 785 // More update to ScrollOffset active delta: gfx::ScrollOffset(20, 20) |
784 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), | 786 scroll_tree.SetScrollOffset(scroll_layer_impl->id(), |
785 gfx::ScrollOffset(40, 50)); | 787 gfx::ScrollOffset(40, 50)); |
786 host_impl->active_tree()->SetCurrentlyScrollingLayer(scroll_layer_impl); | 788 host_impl->active_tree()->SetCurrentlyScrollingLayer(scroll_layer_impl); |
(...skipping 13 matching lines...) Expand all Loading... |
800 scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); | 802 scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); |
801 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); | 803 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); |
802 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( | 804 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
803 gfx::ScrollOffset(100, 100)); | 805 gfx::ScrollOffset(100, 100)); |
804 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); | 806 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
805 EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); | 807 EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); |
806 } | 808 } |
807 | 809 |
808 } // namespace | 810 } // namespace |
809 } // namespace cc | 811 } // namespace cc |
OLD | NEW |