| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/layers/layer_list_iterator.h" | 5 #include "cc/layers/layer_list_iterator.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/containers/adapters.h" | 9 #include "base/containers/adapters.h" |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "cc/test/fake_impl_task_runner_provider.h" | 10 #include "cc/test/fake_impl_task_runner_provider.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 11 #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/test_shared_bitmap_manager.h" | 13 #include "cc/test/test_shared_bitmap_manager.h" |
| 13 #include "cc/test/test_task_graph_runner.h" | 14 #include "cc/test/test_task_graph_runner.h" |
| 14 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace cc { | 18 namespace cc { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 TEST(LayerListIteratorTest, VerifyTraversalOrder) { | 21 TEST(LayerListIteratorTest, VerifyTraversalOrder) { |
| 21 // Unfortunate preamble. | 22 // Unfortunate preamble. |
| 22 FakeImplTaskRunnerProvider task_runner_provider; | 23 FakeImplTaskRunnerProvider task_runner_provider; |
| 23 TestSharedBitmapManager shared_bitmap_manager; | 24 TestSharedBitmapManager shared_bitmap_manager; |
| 24 TestTaskGraphRunner task_graph_runner; | 25 TestTaskGraphRunner task_graph_runner; |
| 25 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 26 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 26 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 27 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 27 &task_graph_runner); | 28 &task_graph_runner); |
| 28 host_impl.SetVisible(true); | 29 host_impl.SetVisible(true); |
| 29 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 30 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 30 | 31 |
| 31 // This test constructs the following tree. | 32 // This test constructs the following tree. |
| 32 // 1 | 33 // 1 |
| 33 // +-2 | 34 // +-2 |
| 34 // | +-3 | 35 // | +-3 |
| 35 // | +-4 | 36 // | +-4 |
| 36 // + 5 | 37 // + 5 |
| 37 // +-6 | 38 // +-6 |
| 38 // +-7 | 39 // +-7 |
| 39 // We expect to visit all seven layers in that order. | 40 // We expect to visit all seven layers in that order. |
| 40 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1); | 41 std::unique_ptr<LayerImpl> layer1 = |
| 41 scoped_ptr<LayerImpl> layer2 = LayerImpl::Create(host_impl.active_tree(), 2); | 42 LayerImpl::Create(host_impl.active_tree(), 1); |
| 42 scoped_ptr<LayerImpl> layer3 = LayerImpl::Create(host_impl.active_tree(), 3); | 43 std::unique_ptr<LayerImpl> layer2 = |
| 43 scoped_ptr<LayerImpl> layer4 = LayerImpl::Create(host_impl.active_tree(), 4); | 44 LayerImpl::Create(host_impl.active_tree(), 2); |
| 44 scoped_ptr<LayerImpl> layer5 = LayerImpl::Create(host_impl.active_tree(), 5); | 45 std::unique_ptr<LayerImpl> layer3 = |
| 45 scoped_ptr<LayerImpl> layer6 = LayerImpl::Create(host_impl.active_tree(), 6); | 46 LayerImpl::Create(host_impl.active_tree(), 3); |
| 46 scoped_ptr<LayerImpl> layer7 = LayerImpl::Create(host_impl.active_tree(), 7); | 47 std::unique_ptr<LayerImpl> layer4 = |
| 48 LayerImpl::Create(host_impl.active_tree(), 4); |
| 49 std::unique_ptr<LayerImpl> layer5 = |
| 50 LayerImpl::Create(host_impl.active_tree(), 5); |
| 51 std::unique_ptr<LayerImpl> layer6 = |
| 52 LayerImpl::Create(host_impl.active_tree(), 6); |
| 53 std::unique_ptr<LayerImpl> layer7 = |
| 54 LayerImpl::Create(host_impl.active_tree(), 7); |
| 47 | 55 |
| 48 layer2->AddChild(std::move(layer3)); | 56 layer2->AddChild(std::move(layer3)); |
| 49 layer2->AddChild(std::move(layer4)); | 57 layer2->AddChild(std::move(layer4)); |
| 50 | 58 |
| 51 layer5->AddChild(std::move(layer6)); | 59 layer5->AddChild(std::move(layer6)); |
| 52 layer5->AddChild(std::move(layer7)); | 60 layer5->AddChild(std::move(layer7)); |
| 53 | 61 |
| 54 layer1->AddChild(std::move(layer2)); | 62 layer1->AddChild(std::move(layer2)); |
| 55 layer1->AddChild(std::move(layer5)); | 63 layer1->AddChild(std::move(layer5)); |
| 56 | 64 |
| 57 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 65 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 58 | 66 |
| 59 int i = 1; | 67 int i = 1; |
| 60 for (auto* layer : *host_impl.active_tree()) { | 68 for (auto* layer : *host_impl.active_tree()) { |
| 61 EXPECT_EQ(i++, layer->id()); | 69 EXPECT_EQ(i++, layer->id()); |
| 62 } | 70 } |
| 63 EXPECT_EQ(8, i); | 71 EXPECT_EQ(8, i); |
| 64 } | 72 } |
| 65 | 73 |
| 66 TEST(LayerListIteratorTest, VerifySingleLayer) { | 74 TEST(LayerListIteratorTest, VerifySingleLayer) { |
| 67 // Unfortunate preamble. | 75 // Unfortunate preamble. |
| 68 FakeImplTaskRunnerProvider task_runner_provider; | 76 FakeImplTaskRunnerProvider task_runner_provider; |
| 69 TestSharedBitmapManager shared_bitmap_manager; | 77 TestSharedBitmapManager shared_bitmap_manager; |
| 70 TestTaskGraphRunner task_graph_runner; | 78 TestTaskGraphRunner task_graph_runner; |
| 71 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 79 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 72 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 80 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 73 &task_graph_runner); | 81 &task_graph_runner); |
| 74 host_impl.SetVisible(true); | 82 host_impl.SetVisible(true); |
| 75 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 83 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 76 | 84 |
| 77 // This test constructs a tree consisting of a single layer. | 85 // This test constructs a tree consisting of a single layer. |
| 78 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1); | 86 std::unique_ptr<LayerImpl> layer1 = |
| 87 LayerImpl::Create(host_impl.active_tree(), 1); |
| 79 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 88 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 80 | 89 |
| 81 int i = 1; | 90 int i = 1; |
| 82 for (auto* layer : *host_impl.active_tree()) { | 91 for (auto* layer : *host_impl.active_tree()) { |
| 83 EXPECT_EQ(i++, layer->id()); | 92 EXPECT_EQ(i++, layer->id()); |
| 84 } | 93 } |
| 85 EXPECT_EQ(2, i); | 94 EXPECT_EQ(2, i); |
| 86 } | 95 } |
| 87 | 96 |
| 88 TEST(LayerListIteratorTest, VerifyNullFirstLayer) { | 97 TEST(LayerListIteratorTest, VerifyNullFirstLayer) { |
| 89 // Ensures that if an iterator is constructed with a nullptr, that it can be | 98 // Ensures that if an iterator is constructed with a nullptr, that it can be |
| 90 // iterated without issue and that it remains equal to any other | 99 // iterated without issue and that it remains equal to any other |
| 91 // null-initialized iterator. | 100 // null-initialized iterator. |
| 92 LayerListIterator it(nullptr); | 101 LayerListIterator it(nullptr); |
| 93 LayerListIterator end(nullptr); | 102 LayerListIterator end(nullptr); |
| 94 | 103 |
| 95 EXPECT_EQ(it, end); | 104 EXPECT_EQ(it, end); |
| 96 ++it; | 105 ++it; |
| 97 EXPECT_EQ(it, end); | 106 EXPECT_EQ(it, end); |
| 98 } | 107 } |
| 99 | 108 |
| 100 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) { | 109 TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) { |
| 101 // Unfortunate preamble. | 110 // Unfortunate preamble. |
| 102 FakeImplTaskRunnerProvider task_runner_provider; | 111 FakeImplTaskRunnerProvider task_runner_provider; |
| 103 TestSharedBitmapManager shared_bitmap_manager; | 112 TestSharedBitmapManager shared_bitmap_manager; |
| 104 TestTaskGraphRunner task_graph_runner; | 113 TestTaskGraphRunner task_graph_runner; |
| 105 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 114 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 106 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 115 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 107 &task_graph_runner); | 116 &task_graph_runner); |
| 108 host_impl.SetVisible(true); | 117 host_impl.SetVisible(true); |
| 109 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 118 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 110 | 119 |
| 111 // This test constructs the following tree. | 120 // This test constructs the following tree. |
| 112 // 1 | 121 // 1 |
| 113 // +-2 | 122 // +-2 |
| 114 // | +-3 | 123 // | +-3 |
| 115 // | +-4 | 124 // | +-4 |
| 116 // + 5 | 125 // + 5 |
| 117 // +-6 | 126 // +-6 |
| 118 // +-7 | 127 // +-7 |
| 119 // We expect to visit all seven layers in reverse order. | 128 // We expect to visit all seven layers in reverse order. |
| 120 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1); | 129 std::unique_ptr<LayerImpl> layer1 = |
| 121 scoped_ptr<LayerImpl> layer2 = LayerImpl::Create(host_impl.active_tree(), 2); | 130 LayerImpl::Create(host_impl.active_tree(), 1); |
| 122 scoped_ptr<LayerImpl> layer3 = LayerImpl::Create(host_impl.active_tree(), 3); | 131 std::unique_ptr<LayerImpl> layer2 = |
| 123 scoped_ptr<LayerImpl> layer4 = LayerImpl::Create(host_impl.active_tree(), 4); | 132 LayerImpl::Create(host_impl.active_tree(), 2); |
| 124 scoped_ptr<LayerImpl> layer5 = LayerImpl::Create(host_impl.active_tree(), 5); | 133 std::unique_ptr<LayerImpl> layer3 = |
| 125 scoped_ptr<LayerImpl> layer6 = LayerImpl::Create(host_impl.active_tree(), 6); | 134 LayerImpl::Create(host_impl.active_tree(), 3); |
| 126 scoped_ptr<LayerImpl> layer7 = LayerImpl::Create(host_impl.active_tree(), 7); | 135 std::unique_ptr<LayerImpl> layer4 = |
| 136 LayerImpl::Create(host_impl.active_tree(), 4); |
| 137 std::unique_ptr<LayerImpl> layer5 = |
| 138 LayerImpl::Create(host_impl.active_tree(), 5); |
| 139 std::unique_ptr<LayerImpl> layer6 = |
| 140 LayerImpl::Create(host_impl.active_tree(), 6); |
| 141 std::unique_ptr<LayerImpl> layer7 = |
| 142 LayerImpl::Create(host_impl.active_tree(), 7); |
| 127 | 143 |
| 128 layer2->AddChild(std::move(layer3)); | 144 layer2->AddChild(std::move(layer3)); |
| 129 layer2->AddChild(std::move(layer4)); | 145 layer2->AddChild(std::move(layer4)); |
| 130 | 146 |
| 131 layer5->AddChild(std::move(layer6)); | 147 layer5->AddChild(std::move(layer6)); |
| 132 layer5->AddChild(std::move(layer7)); | 148 layer5->AddChild(std::move(layer7)); |
| 133 | 149 |
| 134 layer1->AddChild(std::move(layer2)); | 150 layer1->AddChild(std::move(layer2)); |
| 135 layer1->AddChild(std::move(layer5)); | 151 layer1->AddChild(std::move(layer5)); |
| 136 | 152 |
| 137 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 153 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 138 | 154 |
| 139 int i = 7; | 155 int i = 7; |
| 140 | 156 |
| 141 for (auto* layer : base::Reversed(*host_impl.active_tree())) { | 157 for (auto* layer : base::Reversed(*host_impl.active_tree())) { |
| 142 EXPECT_EQ(i--, layer->id()); | 158 EXPECT_EQ(i--, layer->id()); |
| 143 } | 159 } |
| 144 | 160 |
| 145 EXPECT_EQ(0, i); | 161 EXPECT_EQ(0, i); |
| 146 } | 162 } |
| 147 | 163 |
| 148 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { | 164 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { |
| 149 // Unfortunate preamble. | 165 // Unfortunate preamble. |
| 150 FakeImplTaskRunnerProvider task_runner_provider; | 166 FakeImplTaskRunnerProvider task_runner_provider; |
| 151 TestSharedBitmapManager shared_bitmap_manager; | 167 TestSharedBitmapManager shared_bitmap_manager; |
| 152 TestTaskGraphRunner task_graph_runner; | 168 TestTaskGraphRunner task_graph_runner; |
| 153 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 169 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 154 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 170 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 155 &task_graph_runner); | 171 &task_graph_runner); |
| 156 host_impl.SetVisible(true); | 172 host_impl.SetVisible(true); |
| 157 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 173 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 158 | 174 |
| 159 // This test constructs a tree consisting of a single layer. | 175 // This test constructs a tree consisting of a single layer. |
| 160 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1); | 176 std::unique_ptr<LayerImpl> layer1 = |
| 177 LayerImpl::Create(host_impl.active_tree(), 1); |
| 161 host_impl.active_tree()->SetRootLayer(std::move(layer1)); | 178 host_impl.active_tree()->SetRootLayer(std::move(layer1)); |
| 162 | 179 |
| 163 int i = 1; | 180 int i = 1; |
| 164 for (auto* layer : base::Reversed(*host_impl.active_tree())) { | 181 for (auto* layer : base::Reversed(*host_impl.active_tree())) { |
| 165 EXPECT_EQ(i--, layer->id()); | 182 EXPECT_EQ(i--, layer->id()); |
| 166 } | 183 } |
| 167 EXPECT_EQ(0, i); | 184 EXPECT_EQ(0, i); |
| 168 } | 185 } |
| 169 | 186 |
| 170 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) { | 187 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) { |
| 171 // Ensures that if an iterator is constructed with a nullptr, that it can be | 188 // Ensures that if an iterator is constructed with a nullptr, that it can be |
| 172 // iterated without issue and that it remains equal to any other | 189 // iterated without issue and that it remains equal to any other |
| 173 // null-initialized iterator. | 190 // null-initialized iterator. |
| 174 LayerListReverseIterator it(nullptr); | 191 LayerListReverseIterator it(nullptr); |
| 175 LayerListReverseIterator end(nullptr); | 192 LayerListReverseIterator end(nullptr); |
| 176 | 193 |
| 177 EXPECT_EQ(it, end); | 194 EXPECT_EQ(it, end); |
| 178 ++it; | 195 ++it; |
| 179 EXPECT_EQ(it, end); | 196 EXPECT_EQ(it, end); |
| 180 } | 197 } |
| 181 | 198 |
| 182 } // namespace | 199 } // namespace |
| 183 } // namespace cc | 200 } // namespace cc |
| OLD | NEW |