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/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "ui/gfx/geometry/vector2d_conversions.h" | 66 #include "ui/gfx/geometry/vector2d_conversions.h" |
67 | 67 |
68 using testing::_; | 68 using testing::_; |
69 using testing::AnyNumber; | 69 using testing::AnyNumber; |
70 using testing::AtLeast; | 70 using testing::AtLeast; |
71 using testing::Mock; | 71 using testing::Mock; |
72 | 72 |
73 namespace cc { | 73 namespace cc { |
74 namespace { | 74 namespace { |
75 | 75 |
76 class LayerTreeHostTest : public LayerTreeTest { | 76 class LayerTreeHostTest : public LayerTreeTest {}; |
77 protected: | |
78 // These tests are not pixel tests, and they use a fake output surface, | |
79 // while storing pointers to the test-types for tests to poke at. | |
80 std::unique_ptr<OutputSurface> CreateOutputSurface() override { | |
81 auto context = TestContextProvider::Create(); | |
82 context_provider_ = context.get(); | |
83 auto ret = delegating_renderer() | |
84 ? FakeOutputSurface::CreateDelegating3d(std::move(context)) | |
85 : FakeOutputSurface::Create3d(std::move(context)); | |
86 output_surface_ = ret.get(); | |
87 return std::move(ret); | |
88 } | |
89 | |
90 FakeOutputSurface* fake_output_surface() { return output_surface_; } | |
91 TestContextProvider* test_context_provider() { return context_provider_; } | |
92 | |
93 private: | |
94 FakeOutputSurface* output_surface_ = nullptr; | |
95 TestContextProvider* context_provider_ = nullptr; | |
96 }; | |
97 | 77 |
98 class LayerTreeHostTestHasImplThreadTest : public LayerTreeHostTest { | 78 class LayerTreeHostTestHasImplThreadTest : public LayerTreeHostTest { |
99 public: | 79 public: |
100 LayerTreeHostTestHasImplThreadTest() : threaded_(false) {} | 80 LayerTreeHostTestHasImplThreadTest() : threaded_(false) {} |
101 | 81 |
102 void RunTest(CompositorMode mode, bool delegating_renderer) override { | 82 void RunTest(CompositorMode mode, bool delegating_renderer) override { |
103 threaded_ = mode == CompositorMode::THREADED; | 83 threaded_ = mode == CompositorMode::THREADED; |
104 LayerTreeHostTest::RunTest(mode, delegating_renderer); | 84 LayerTreeHostTest::RunTest(mode, delegating_renderer); |
105 } | 85 } |
106 | 86 |
(...skipping 2865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2972 PostSetNeedsCommitToMainThread(); | 2952 PostSetNeedsCommitToMainThread(); |
2973 break; | 2953 break; |
2974 case 5: | 2954 case 5: |
2975 ClearResources(); | 2955 ClearResources(); |
2976 EndTest(); | 2956 EndTest(); |
2977 break; | 2957 break; |
2978 } | 2958 } |
2979 } | 2959 } |
2980 | 2960 |
2981 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 2961 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
2982 auto* context = test_context_provider()->TestContext3d(); | 2962 auto* context = static_cast<TestContextProvider*>( |
| 2963 impl->output_surface()->context_provider()) |
| 2964 ->TestContext3d(); |
2983 | 2965 |
2984 int frame = impl->active_tree()->source_frame_number(); | 2966 int frame = impl->active_tree()->source_frame_number(); |
2985 switch (frame) { | 2967 switch (frame) { |
2986 case 0: | 2968 case 0: |
2987 ASSERT_EQ(0u, context->NumTextures()); | 2969 ASSERT_EQ(0u, context->NumTextures()); |
2988 break; | 2970 break; |
2989 case 1: | 2971 case 1: |
2990 // Created two textures. | 2972 // Created two textures. |
2991 ASSERT_EQ(2u, context->NumTextures()); | 2973 ASSERT_EQ(2u, context->NumTextures()); |
2992 break; | 2974 break; |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4033 } | 4015 } |
4034 | 4016 |
4035 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 4017 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
4036 LayerTreeHostImpl::FrameData* frame_data, | 4018 LayerTreeHostImpl::FrameData* frame_data, |
4037 DrawResult draw_result) override { | 4019 DrawResult draw_result) override { |
4038 ++num_commits_; | 4020 ++num_commits_; |
4039 switch (num_commits_) { | 4021 switch (num_commits_) { |
4040 case 1: | 4022 case 1: |
4041 EXPECT_EQ(0, callback_count_); | 4023 EXPECT_EQ(0, callback_count_); |
4042 callback_count_ = 0; | 4024 callback_count_ = 0; |
4043 SetCallback(true); | 4025 SetCallback(host_impl, true); |
4044 PostSetNeedsCommitToMainThread(); | 4026 PostSetNeedsCommitToMainThread(); |
4045 break; | 4027 break; |
4046 case 2: | 4028 case 2: |
4047 EXPECT_EQ(1, callback_count_); | 4029 EXPECT_EQ(1, callback_count_); |
4048 callback_count_ = 0; | 4030 callback_count_ = 0; |
4049 SetCallback(false); | 4031 SetCallback(host_impl, false); |
4050 PostSetNeedsCommitToMainThread(); | 4032 PostSetNeedsCommitToMainThread(); |
4051 break; | 4033 break; |
4052 case 3: | 4034 case 3: |
4053 EXPECT_EQ(0, callback_count_); | 4035 EXPECT_EQ(0, callback_count_); |
4054 callback_count_ = 0; | 4036 callback_count_ = 0; |
4055 EndTest(); | 4037 EndTest(); |
4056 break; | 4038 break; |
4057 default: | 4039 default: |
4058 ADD_FAILURE() << num_commits_; | 4040 ADD_FAILURE() << num_commits_; |
4059 EndTest(); | 4041 EndTest(); |
4060 break; | 4042 break; |
4061 } | 4043 } |
4062 return LayerTreeHostTest::PrepareToDrawOnThread( | 4044 return LayerTreeHostTest::PrepareToDrawOnThread( |
4063 host_impl, frame_data, draw_result); | 4045 host_impl, frame_data, draw_result); |
4064 } | 4046 } |
4065 | 4047 |
4066 void AfterTest() override { EXPECT_EQ(3, num_commits_); } | 4048 void AfterTest() override { EXPECT_EQ(3, num_commits_); } |
4067 | 4049 |
4068 void SetCallback(bool enable) { | 4050 void SetCallback(LayerTreeHostImpl* host_impl, bool enable) { |
4069 fake_output_surface()->SetTreeActivationCallback( | 4051 host_impl->SetTreeActivationCallback( |
4070 enable | 4052 enable |
4071 ? base::Bind( | 4053 ? base::Bind( |
4072 &LayerTreeHostTestTreeActivationCallback::ActivationCallback, | 4054 &LayerTreeHostTestTreeActivationCallback::ActivationCallback, |
4073 base::Unretained(this)) | 4055 base::Unretained(this)) |
4074 : base::Closure()); | 4056 : base::Closure()); |
4075 } | 4057 } |
4076 | 4058 |
4077 void ActivationCallback() { ++callback_count_; } | 4059 void ActivationCallback() { ++callback_count_; } |
4078 | 4060 |
4079 int num_commits_; | 4061 int num_commits_; |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4653 break; | 4635 break; |
4654 } | 4636 } |
4655 } | 4637 } |
4656 | 4638 |
4657 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 4639 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
4658 if (host_impl->pending_tree()) { | 4640 if (host_impl->pending_tree()) { |
4659 if (host_impl->pending_tree()->source_frame_number() == 1) { | 4641 if (host_impl->pending_tree()->source_frame_number() == 1) { |
4660 base::AutoLock lock(swap_promise_result_.lock); | 4642 base::AutoLock lock(swap_promise_result_.lock); |
4661 EXPECT_FALSE(swap_promise_result_.did_activate_called); | 4643 EXPECT_FALSE(swap_promise_result_.did_activate_called); |
4662 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4644 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
4663 SetCallback(true); | 4645 SetCallback(host_impl, true); |
4664 } else { | 4646 } else { |
4665 SetCallback(false); | 4647 SetCallback(host_impl, false); |
4666 } | 4648 } |
4667 } | 4649 } |
4668 } | 4650 } |
4669 | 4651 |
4670 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 4652 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
4671 if (host_impl->active_tree()->source_frame_number() == 1) { | 4653 if (host_impl->active_tree()->source_frame_number() == 1) { |
4672 base::AutoLock lock(swap_promise_result_.lock); | 4654 base::AutoLock lock(swap_promise_result_.lock); |
4673 EXPECT_TRUE(swap_promise_result_.did_activate_called); | 4655 EXPECT_TRUE(swap_promise_result_.did_activate_called); |
4674 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4656 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
4675 } | 4657 } |
4676 } | 4658 } |
4677 | 4659 |
4678 void ActivationCallback() { | 4660 void ActivationCallback() { |
4679 // DidActivate needs to happen before the tree activation callback. | 4661 // DidActivate needs to happen before the tree activation callback. |
4680 base::AutoLock lock(swap_promise_result_.lock); | 4662 base::AutoLock lock(swap_promise_result_.lock); |
4681 EXPECT_TRUE(swap_promise_result_.did_activate_called); | 4663 EXPECT_TRUE(swap_promise_result_.did_activate_called); |
4682 } | 4664 } |
4683 | 4665 |
4684 void SetCallback(bool enable) { | 4666 void SetCallback(LayerTreeHostImpl* host_impl, bool enable) { |
4685 fake_output_surface()->SetTreeActivationCallback( | 4667 host_impl->SetTreeActivationCallback( |
4686 enable | 4668 enable |
4687 ? base::Bind(&LayerTreeHostTestKeepSwapPromise::ActivationCallback, | 4669 ? base::Bind(&LayerTreeHostTestKeepSwapPromise::ActivationCallback, |
4688 base::Unretained(this)) | 4670 base::Unretained(this)) |
4689 : base::Closure()); | 4671 : base::Closure()); |
4690 } | 4672 } |
4691 | 4673 |
4692 void SwapBuffersCompleteOnThread() override { | 4674 void SwapBuffersCompleteOnThread() override { |
4693 if (num_swaps_++ >= 1) { | 4675 if (num_swaps_++ >= 1) { |
4694 // The commit changes layers so it should cause a swap. | 4676 // The commit changes layers so it should cause a swap. |
4695 base::AutoLock lock(swap_promise_result_.lock); | 4677 base::AutoLock lock(swap_promise_result_.lock); |
(...skipping 2101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6797 | 6779 |
6798 void AfterTest() override {} | 6780 void AfterTest() override {} |
6799 }; | 6781 }; |
6800 | 6782 |
6801 MULTI_THREAD_TEST_F(LayerTreeHostTestDestroyWhileInitializingOutputSurface); | 6783 MULTI_THREAD_TEST_F(LayerTreeHostTestDestroyWhileInitializingOutputSurface); |
6802 | 6784 |
6803 // Makes sure that painted_device_scale_factor is propagated to the | 6785 // Makes sure that painted_device_scale_factor is propagated to the |
6804 // frame's metadata. | 6786 // frame's metadata. |
6805 class LayerTreeHostTestPaintedDeviceScaleFactor : public LayerTreeHostTest { | 6787 class LayerTreeHostTestPaintedDeviceScaleFactor : public LayerTreeHostTest { |
6806 protected: | 6788 protected: |
| 6789 LayerTreeHostTestPaintedDeviceScaleFactor() = default; |
| 6790 |
| 6791 std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
| 6792 auto ret = FakeOutputSurface::CreateDelegating3d(); |
| 6793 fake_output_surface_ = ret.get(); |
| 6794 return std::move(ret); |
| 6795 } |
| 6796 |
6807 void BeginTest() override { | 6797 void BeginTest() override { |
6808 layer_tree_host()->SetPaintedDeviceScaleFactor(2.0f); | 6798 layer_tree_host()->SetPaintedDeviceScaleFactor(2.0f); |
6809 EXPECT_EQ(1.0f, layer_tree_host()->device_scale_factor()); | 6799 EXPECT_EQ(1.0f, layer_tree_host()->device_scale_factor()); |
6810 PostSetNeedsCommitToMainThread(); | 6800 PostSetNeedsCommitToMainThread(); |
6811 } | 6801 } |
6812 | 6802 |
6813 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 6803 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
6814 EXPECT_EQ(2.0f, host_impl->active_tree()->painted_device_scale_factor()); | 6804 EXPECT_EQ(2.0f, host_impl->active_tree()->painted_device_scale_factor()); |
6815 EXPECT_EQ(1.0f, host_impl->active_tree()->device_scale_factor()); | 6805 EXPECT_EQ(1.0f, host_impl->active_tree()->device_scale_factor()); |
6816 } | 6806 } |
6817 | 6807 |
6818 void SwapBuffersCompleteOnThread() override { | 6808 void SwapBuffersCompleteOnThread() override { |
6819 EXPECT_EQ( | 6809 EXPECT_EQ( |
6820 2.0f, | 6810 2.0f, |
6821 fake_output_surface()->last_sent_frame()->metadata.device_scale_factor); | 6811 fake_output_surface_->last_sent_frame()->metadata.device_scale_factor); |
6822 EndTest(); | 6812 EndTest(); |
6823 } | 6813 } |
6824 | 6814 |
6825 void AfterTest() override {} | 6815 void AfterTest() override {} |
| 6816 |
| 6817 FakeOutputSurface* fake_output_surface_ = nullptr; |
6826 }; | 6818 }; |
6827 | 6819 |
6828 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); | 6820 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); |
6829 | 6821 |
6830 // The GPU image decode controller hands images off to Skia for rasterization. | 6822 // The GPU image decode controller hands images off to Skia for rasterization. |
6831 // When used with large images, the images in question could be deleted before | 6823 // When used with large images, the images in question could be deleted before |
6832 // Skia was done with them, causing a crash. This test performs an end-to-end | 6824 // Skia was done with them, causing a crash. This test performs an end-to-end |
6833 // check of large image rasterization to ensure we do not hit this crash. | 6825 // check of large image rasterization to ensure we do not hit this crash. |
6834 // Note that this code path won't always hit the crash, even when incorrect | 6826 // Note that this code path won't always hit the crash, even when incorrect |
6835 // behavior occurs, so this is more of a sanity check. | 6827 // behavior occurs, so this is more of a sanity check. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6900 private: | 6892 private: |
6901 FakeContentLayerClient client_; | 6893 FakeContentLayerClient client_; |
6902 const gfx::Size viewport_size_; | 6894 const gfx::Size viewport_size_; |
6903 const gfx::Size large_image_size_; | 6895 const gfx::Size large_image_size_; |
6904 }; | 6896 }; |
6905 | 6897 |
6906 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); | 6898 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); |
6907 | 6899 |
6908 } // namespace | 6900 } // namespace |
6909 } // namespace cc | 6901 } // namespace cc |
OLD | NEW |