| 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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include "cc/animation/keyframed_animation_curve.h" | 7 #include "cc/animation/keyframed_animation_curve.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
| 10 #include "cc/resources/layer_painter.h" | 10 #include "cc/resources/layer_painter.h" |
| 11 #include "cc/test/animation_test_common.h" | 11 #include "cc/test/animation_test_common.h" |
| 12 #include "cc/test/fake_impl_proxy.h" | 12 #include "cc/test/fake_impl_proxy.h" |
| 13 #include "cc/test/fake_layer_tree_host_client.h" | 13 #include "cc/test/fake_layer_tree_host_client.h" |
| 14 #include "cc/test/fake_layer_tree_host_impl.h" | 14 #include "cc/test/fake_layer_tree_host_impl.h" |
| 15 #include "cc/test/geometry_test_utils.h" | 15 #include "cc/test/geometry_test_utils.h" |
| 16 #include "cc/test/layer_test_common.h" | 16 #include "cc/test/layer_test_common.h" |
| 17 #include "cc/test/test_gpu_memory_buffer_manager.h" | 17 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 18 #include "cc/test/test_shared_bitmap_manager.h" | 18 #include "cc/test/test_shared_bitmap_manager.h" |
| 19 #include "cc/test/test_task_graph_runner.h" |
| 19 #include "cc/trees/layer_tree_host.h" | 20 #include "cc/trees/layer_tree_host.h" |
| 20 #include "cc/trees/single_thread_proxy.h" | 21 #include "cc/trees/single_thread_proxy.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gfx/transform.h" | 24 #include "ui/gfx/transform.h" |
| 24 | 25 |
| 25 using ::testing::AnyNumber; | 26 using ::testing::AnyNumber; |
| 26 using ::testing::AtLeast; | 27 using ::testing::AtLeast; |
| 27 using ::testing::Mock; | 28 using ::testing::Mock; |
| 28 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
| 29 using ::testing::_; | 30 using ::testing::_; |
| 30 | 31 |
| 31 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ | 32 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ |
| 32 do { \ | 33 do { \ |
| 33 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ | 34 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ |
| 34 code_to_test; \ | 35 code_to_test; \ |
| 35 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 36 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
| 36 } while (false) | 37 } while (false) |
| 37 | 38 |
| 38 namespace cc { | 39 namespace cc { |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 class MockLayerTreeHost : public LayerTreeHost { | 42 class MockLayerTreeHost : public LayerTreeHost { |
| 42 public: | 43 public: |
| 43 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) | 44 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
| 44 : LayerTreeHost(client, nullptr, nullptr, LayerTreeSettings()) { | 45 : LayerTreeHost(client, nullptr, nullptr, nullptr, LayerTreeSettings()) { |
| 45 InitializeSingleThreaded(client, | 46 InitializeSingleThreaded(client, |
| 46 base::MessageLoopProxy::current(), | 47 base::MessageLoopProxy::current(), |
| 47 nullptr); | 48 nullptr); |
| 48 } | 49 } |
| 49 | 50 |
| 50 MOCK_METHOD0(SetNeedsCommit, void()); | 51 MOCK_METHOD0(SetNeedsCommit, void()); |
| 51 MOCK_METHOD0(SetNeedsUpdateLayers, void()); | 52 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
| 52 MOCK_METHOD0(SetNeedsFullTreeSync, void()); | 53 MOCK_METHOD0(SetNeedsFullTreeSync, void()); |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 class MockLayerPainter : public LayerPainter { | 56 class MockLayerPainter : public LayerPainter { |
| 56 public: | 57 public: |
| 57 void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) override {} | 58 void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) override {} |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 class LayerTest : public testing::Test { | 61 class LayerTest : public testing::Test { |
| 61 public: | 62 public: |
| 62 LayerTest() | 63 LayerTest() |
| 63 : host_impl_(&proxy_, &shared_bitmap_manager_), | 64 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), |
| 64 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 65 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 65 | 66 |
| 66 protected: | 67 protected: |
| 67 void SetUp() override { | 68 void SetUp() override { |
| 68 layer_tree_host_.reset(new StrictMock<MockLayerTreeHost>(&fake_client_)); | 69 layer_tree_host_.reset(new StrictMock<MockLayerTreeHost>(&fake_client_)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void TearDown() override { | 72 void TearDown() override { |
| 72 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 73 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 73 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 74 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 child1_->AddChild(grand_child2_); | 125 child1_->AddChild(grand_child2_); |
| 125 child2_->AddChild(grand_child3_); | 126 child2_->AddChild(grand_child3_); |
| 126 | 127 |
| 127 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 128 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 128 | 129 |
| 129 VerifyTestTreeInitialState(); | 130 VerifyTestTreeInitialState(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 FakeImplProxy proxy_; | 133 FakeImplProxy proxy_; |
| 133 TestSharedBitmapManager shared_bitmap_manager_; | 134 TestSharedBitmapManager shared_bitmap_manager_; |
| 135 TestTaskGraphRunner task_graph_runner_; |
| 134 FakeLayerTreeHostImpl host_impl_; | 136 FakeLayerTreeHostImpl host_impl_; |
| 135 | 137 |
| 136 FakeLayerTreeHostClient fake_client_; | 138 FakeLayerTreeHostClient fake_client_; |
| 137 scoped_ptr<StrictMock<MockLayerTreeHost>> layer_tree_host_; | 139 scoped_ptr<StrictMock<MockLayerTreeHost>> layer_tree_host_; |
| 138 scoped_refptr<Layer> parent_; | 140 scoped_refptr<Layer> parent_; |
| 139 scoped_refptr<Layer> child1_; | 141 scoped_refptr<Layer> child1_; |
| 140 scoped_refptr<Layer> child2_; | 142 scoped_refptr<Layer> child2_; |
| 141 scoped_refptr<Layer> child3_; | 143 scoped_refptr<Layer> child3_; |
| 142 scoped_refptr<Layer> grand_child1_; | 144 scoped_refptr<Layer> grand_child1_; |
| 143 scoped_refptr<Layer> grand_child2_; | 145 scoped_refptr<Layer> grand_child2_; |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 | 930 |
| 929 class LayerTreeHostFactory { | 931 class LayerTreeHostFactory { |
| 930 public: | 932 public: |
| 931 LayerTreeHostFactory() | 933 LayerTreeHostFactory() |
| 932 : client_(FakeLayerTreeHostClient::DIRECT_3D), | 934 : client_(FakeLayerTreeHostClient::DIRECT_3D), |
| 933 shared_bitmap_manager_(new TestSharedBitmapManager), | 935 shared_bitmap_manager_(new TestSharedBitmapManager), |
| 934 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager) {} | 936 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager) {} |
| 935 | 937 |
| 936 scoped_ptr<LayerTreeHost> Create() { | 938 scoped_ptr<LayerTreeHost> Create() { |
| 937 return LayerTreeHost::CreateSingleThreaded( | 939 return LayerTreeHost::CreateSingleThreaded( |
| 938 &client_, | 940 &client_, &client_, shared_bitmap_manager_.get(), |
| 939 &client_, | 941 gpu_memory_buffer_manager_.get(), nullptr, LayerTreeSettings(), |
| 940 shared_bitmap_manager_.get(), | 942 base::MessageLoopProxy::current(), nullptr); |
| 941 gpu_memory_buffer_manager_.get(), | |
| 942 LayerTreeSettings(), | |
| 943 base::MessageLoopProxy::current(), | |
| 944 nullptr); | |
| 945 } | 943 } |
| 946 | 944 |
| 947 scoped_ptr<LayerTreeHost> Create(LayerTreeSettings settings) { | 945 scoped_ptr<LayerTreeHost> Create(LayerTreeSettings settings) { |
| 948 return LayerTreeHost::CreateSingleThreaded( | 946 return LayerTreeHost::CreateSingleThreaded( |
| 949 &client_, | 947 &client_, &client_, shared_bitmap_manager_.get(), |
| 950 &client_, | 948 gpu_memory_buffer_manager_.get(), nullptr, settings, |
| 951 shared_bitmap_manager_.get(), | 949 base::MessageLoopProxy::current(), nullptr); |
| 952 gpu_memory_buffer_manager_.get(), | |
| 953 settings, | |
| 954 base::MessageLoopProxy::current(), | |
| 955 nullptr); | |
| 956 } | 950 } |
| 957 | 951 |
| 958 private: | 952 private: |
| 959 FakeLayerTreeHostClient client_; | 953 FakeLayerTreeHostClient client_; |
| 960 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 954 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
| 961 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 955 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 962 }; | 956 }; |
| 963 | 957 |
| 964 void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { | 958 void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { |
| 965 EXPECT_EQ(host, layer->layer_tree_host()); | 959 EXPECT_EQ(host, layer->layer_tree_host()); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 root_layer->AddChild(becomes_not_draws_content); | 1246 root_layer->AddChild(becomes_not_draws_content); |
| 1253 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); | 1247 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); |
| 1254 | 1248 |
| 1255 becomes_draws_content->SetIsDrawable(true); | 1249 becomes_draws_content->SetIsDrawable(true); |
| 1256 root_layer->AddChild(becomes_draws_content); | 1250 root_layer->AddChild(becomes_draws_content); |
| 1257 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); | 1251 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); |
| 1258 } | 1252 } |
| 1259 | 1253 |
| 1260 } // namespace | 1254 } // namespace |
| 1261 } // namespace cc | 1255 } // namespace cc |
| OLD | NEW |