| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_iterator.h" | 5 #include "cc/layers/layer_iterator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/test/fake_layer_tree_host.h" | 10 #include "cc/test/fake_layer_tree_host.h" |
| 11 #include "cc/trees/layer_tree_host_common.h" | 11 #include "cc/trees/layer_tree_host_common.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 15 | 15 |
| 16 using ::testing::Mock; | 16 using ::testing::Mock; |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::AtLeast; | 18 using ::testing::AtLeast; |
| 19 using ::testing::AnyNumber; | 19 using ::testing::AnyNumber; |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 class TestLayer : public Layer { | 24 class TestLayer : public Layer { |
| 25 public: | 25 public: |
| 26 static scoped_refptr<TestLayer> Create() { | 26 static scoped_refptr<TestLayer> Create(const LayerSettings& settings) { |
| 27 return make_scoped_refptr(new TestLayer()); | 27 return make_scoped_refptr(new TestLayer(settings)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 int count_representing_target_surface_; | 30 int count_representing_target_surface_; |
| 31 int count_representing_contributing_surface_; | 31 int count_representing_contributing_surface_; |
| 32 int count_representing_itself_; | 32 int count_representing_itself_; |
| 33 | 33 |
| 34 bool DrawsContent() const override { return draws_content_; } | 34 bool DrawsContent() const override { return draws_content_; } |
| 35 void set_draws_content(bool draws_content) { draws_content_ = draws_content; } | 35 void set_draws_content(bool draws_content) { draws_content_ = draws_content; } |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 TestLayer() : Layer(), draws_content_(true) { | 38 explicit TestLayer(const LayerSettings& settings) |
| 39 : Layer(settings), draws_content_(true) { |
| 39 SetBounds(gfx::Size(100, 100)); | 40 SetBounds(gfx::Size(100, 100)); |
| 40 SetPosition(gfx::Point()); | 41 SetPosition(gfx::Point()); |
| 41 } | 42 } |
| 42 ~TestLayer() override {} | 43 ~TestLayer() override {} |
| 43 | 44 |
| 44 bool draws_content_; | 45 bool draws_content_; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 #define EXPECT_COUNT(layer, target, contrib, itself) \ | 48 #define EXPECT_COUNT(layer, target, contrib, itself) \ |
| 48 EXPECT_EQ(target, layer->count_representing_target_surface_); \ | 49 EXPECT_EQ(target, layer->count_representing_target_surface_); \ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 TEST(LayerIteratorTest, EmptyTree) { | 97 TEST(LayerIteratorTest, EmptyTree) { |
| 97 RenderSurfaceLayerList render_surface_layer_list; | 98 RenderSurfaceLayerList render_surface_layer_list; |
| 98 | 99 |
| 99 IterateFrontToBack(&render_surface_layer_list); | 100 IterateFrontToBack(&render_surface_layer_list); |
| 100 } | 101 } |
| 101 | 102 |
| 102 TEST(LayerIteratorTest, SimpleTree) { | 103 TEST(LayerIteratorTest, SimpleTree) { |
| 103 scoped_refptr<TestLayer> root_layer = TestLayer::Create(); | 104 LayerSettings settings; |
| 104 scoped_refptr<TestLayer> first = TestLayer::Create(); | 105 scoped_refptr<TestLayer> root_layer = TestLayer::Create(settings); |
| 105 scoped_refptr<TestLayer> second = TestLayer::Create(); | 106 scoped_refptr<TestLayer> first = TestLayer::Create(settings); |
| 106 scoped_refptr<TestLayer> third = TestLayer::Create(); | 107 scoped_refptr<TestLayer> second = TestLayer::Create(settings); |
| 107 scoped_refptr<TestLayer> fourth = TestLayer::Create(); | 108 scoped_refptr<TestLayer> third = TestLayer::Create(settings); |
| 109 scoped_refptr<TestLayer> fourth = TestLayer::Create(settings); |
| 108 | 110 |
| 109 root_layer->AddChild(first); | 111 root_layer->AddChild(first); |
| 110 root_layer->AddChild(second); | 112 root_layer->AddChild(second); |
| 111 root_layer->AddChild(third); | 113 root_layer->AddChild(third); |
| 112 root_layer->AddChild(fourth); | 114 root_layer->AddChild(fourth); |
| 113 | 115 |
| 114 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 116 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 115 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | 117 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
| 116 host->SetRootLayer(root_layer); | 118 host->SetRootLayer(root_layer); |
| 117 | 119 |
| 118 RenderSurfaceLayerList render_surface_layer_list; | 120 RenderSurfaceLayerList render_surface_layer_list; |
| 119 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 121 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 120 root_layer.get(), root_layer->bounds(), &render_surface_layer_list); | 122 root_layer.get(), root_layer->bounds(), &render_surface_layer_list); |
| 121 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 123 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 122 | 124 |
| 123 IterateFrontToBack(&render_surface_layer_list); | 125 IterateFrontToBack(&render_surface_layer_list); |
| 124 EXPECT_COUNT(root_layer, 5, -1, 4); | 126 EXPECT_COUNT(root_layer, 5, -1, 4); |
| 125 EXPECT_COUNT(first, -1, -1, 3); | 127 EXPECT_COUNT(first, -1, -1, 3); |
| 126 EXPECT_COUNT(second, -1, -1, 2); | 128 EXPECT_COUNT(second, -1, -1, 2); |
| 127 EXPECT_COUNT(third, -1, -1, 1); | 129 EXPECT_COUNT(third, -1, -1, 1); |
| 128 EXPECT_COUNT(fourth, -1, -1, 0); | 130 EXPECT_COUNT(fourth, -1, -1, 0); |
| 129 } | 131 } |
| 130 | 132 |
| 131 TEST(LayerIteratorTest, ComplexTree) { | 133 TEST(LayerIteratorTest, ComplexTree) { |
| 132 scoped_refptr<TestLayer> root_layer = TestLayer::Create(); | 134 LayerSettings settings; |
| 133 scoped_refptr<TestLayer> root1 = TestLayer::Create(); | 135 scoped_refptr<TestLayer> root_layer = TestLayer::Create(settings); |
| 134 scoped_refptr<TestLayer> root2 = TestLayer::Create(); | 136 scoped_refptr<TestLayer> root1 = TestLayer::Create(settings); |
| 135 scoped_refptr<TestLayer> root3 = TestLayer::Create(); | 137 scoped_refptr<TestLayer> root2 = TestLayer::Create(settings); |
| 136 scoped_refptr<TestLayer> root21 = TestLayer::Create(); | 138 scoped_refptr<TestLayer> root3 = TestLayer::Create(settings); |
| 137 scoped_refptr<TestLayer> root22 = TestLayer::Create(); | 139 scoped_refptr<TestLayer> root21 = TestLayer::Create(settings); |
| 138 scoped_refptr<TestLayer> root23 = TestLayer::Create(); | 140 scoped_refptr<TestLayer> root22 = TestLayer::Create(settings); |
| 139 scoped_refptr<TestLayer> root221 = TestLayer::Create(); | 141 scoped_refptr<TestLayer> root23 = TestLayer::Create(settings); |
| 140 scoped_refptr<TestLayer> root231 = TestLayer::Create(); | 142 scoped_refptr<TestLayer> root221 = TestLayer::Create(settings); |
| 143 scoped_refptr<TestLayer> root231 = TestLayer::Create(settings); |
| 141 | 144 |
| 142 root_layer->AddChild(root1); | 145 root_layer->AddChild(root1); |
| 143 root_layer->AddChild(root2); | 146 root_layer->AddChild(root2); |
| 144 root_layer->AddChild(root3); | 147 root_layer->AddChild(root3); |
| 145 root2->AddChild(root21); | 148 root2->AddChild(root21); |
| 146 root2->AddChild(root22); | 149 root2->AddChild(root22); |
| 147 root2->AddChild(root23); | 150 root2->AddChild(root23); |
| 148 root22->AddChild(root221); | 151 root22->AddChild(root221); |
| 149 root23->AddChild(root231); | 152 root23->AddChild(root231); |
| 150 | 153 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 163 EXPECT_COUNT(root2, -1, -1, 6); | 166 EXPECT_COUNT(root2, -1, -1, 6); |
| 164 EXPECT_COUNT(root21, -1, -1, 5); | 167 EXPECT_COUNT(root21, -1, -1, 5); |
| 165 EXPECT_COUNT(root22, -1, -1, 4); | 168 EXPECT_COUNT(root22, -1, -1, 4); |
| 166 EXPECT_COUNT(root221, -1, -1, 3); | 169 EXPECT_COUNT(root221, -1, -1, 3); |
| 167 EXPECT_COUNT(root23, -1, -1, 2); | 170 EXPECT_COUNT(root23, -1, -1, 2); |
| 168 EXPECT_COUNT(root231, -1, -1, 1); | 171 EXPECT_COUNT(root231, -1, -1, 1); |
| 169 EXPECT_COUNT(root3, -1, -1, 0); | 172 EXPECT_COUNT(root3, -1, -1, 0); |
| 170 } | 173 } |
| 171 | 174 |
| 172 TEST(LayerIteratorTest, ComplexTreeMultiSurface) { | 175 TEST(LayerIteratorTest, ComplexTreeMultiSurface) { |
| 173 scoped_refptr<TestLayer> root_layer = TestLayer::Create(); | 176 LayerSettings settings; |
| 174 scoped_refptr<TestLayer> root1 = TestLayer::Create(); | 177 scoped_refptr<TestLayer> root_layer = TestLayer::Create(settings); |
| 175 scoped_refptr<TestLayer> root2 = TestLayer::Create(); | 178 scoped_refptr<TestLayer> root1 = TestLayer::Create(settings); |
| 176 scoped_refptr<TestLayer> root3 = TestLayer::Create(); | 179 scoped_refptr<TestLayer> root2 = TestLayer::Create(settings); |
| 177 scoped_refptr<TestLayer> root21 = TestLayer::Create(); | 180 scoped_refptr<TestLayer> root3 = TestLayer::Create(settings); |
| 178 scoped_refptr<TestLayer> root22 = TestLayer::Create(); | 181 scoped_refptr<TestLayer> root21 = TestLayer::Create(settings); |
| 179 scoped_refptr<TestLayer> root23 = TestLayer::Create(); | 182 scoped_refptr<TestLayer> root22 = TestLayer::Create(settings); |
| 180 scoped_refptr<TestLayer> root221 = TestLayer::Create(); | 183 scoped_refptr<TestLayer> root23 = TestLayer::Create(settings); |
| 181 scoped_refptr<TestLayer> root231 = TestLayer::Create(); | 184 scoped_refptr<TestLayer> root221 = TestLayer::Create(settings); |
| 185 scoped_refptr<TestLayer> root231 = TestLayer::Create(settings); |
| 182 | 186 |
| 183 root_layer->AddChild(root1); | 187 root_layer->AddChild(root1); |
| 184 root_layer->AddChild(root2); | 188 root_layer->AddChild(root2); |
| 185 root_layer->AddChild(root3); | 189 root_layer->AddChild(root3); |
| 186 root2->set_draws_content(false); | 190 root2->set_draws_content(false); |
| 187 root2->SetOpacity(0.5f); | 191 root2->SetOpacity(0.5f); |
| 188 root2->SetForceRenderSurface(true); // Force the layer to own a new surface. | 192 root2->SetForceRenderSurface(true); // Force the layer to own a new surface. |
| 189 root2->AddChild(root21); | 193 root2->AddChild(root21); |
| 190 root2->AddChild(root22); | 194 root2->AddChild(root22); |
| 191 root2->AddChild(root23); | 195 root2->AddChild(root23); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 210 EXPECT_COUNT(root21, -1, -1, 9); | 214 EXPECT_COUNT(root21, -1, -1, 9); |
| 211 EXPECT_COUNT(root22, 7, 8, 6); | 215 EXPECT_COUNT(root22, 7, 8, 6); |
| 212 EXPECT_COUNT(root221, -1, -1, 5); | 216 EXPECT_COUNT(root221, -1, -1, 5); |
| 213 EXPECT_COUNT(root23, 3, 4, 2); | 217 EXPECT_COUNT(root23, 3, 4, 2); |
| 214 EXPECT_COUNT(root231, -1, -1, 1); | 218 EXPECT_COUNT(root231, -1, -1, 1); |
| 215 EXPECT_COUNT(root3, -1, -1, 0); | 219 EXPECT_COUNT(root3, -1, -1, 0); |
| 216 } | 220 } |
| 217 | 221 |
| 218 } // namespace | 222 } // namespace |
| 219 } // namespace cc | 223 } // namespace cc |
| OLD | NEW |