Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surfaces/surface.h" | 5 #include "cc/surfaces/surface.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "cc/output/copy_output_result.h" | 7 #include "cc/output/copy_output_result.h" |
| 8 #include "cc/surfaces/compositor_frame_sink_support.h" | |
| 8 #include "cc/surfaces/local_surface_id_allocator.h" | 9 #include "cc/surfaces/local_surface_id_allocator.h" |
| 9 #include "cc/surfaces/surface_dependency_tracker.h" | 10 #include "cc/surfaces/surface_dependency_tracker.h" |
| 10 #include "cc/surfaces/surface_factory.h" | |
| 11 #include "cc/surfaces/surface_factory_client.h" | |
| 12 #include "cc/surfaces/surface_manager.h" | 11 #include "cc/surfaces/surface_manager.h" |
| 13 #include "cc/test/begin_frame_args_test.h" | 12 #include "cc/test/begin_frame_args_test.h" |
| 14 #include "cc/test/fake_external_begin_frame_source.h" | 13 #include "cc/test/fake_external_begin_frame_source.h" |
| 15 #include "cc/test/scheduler_test_common.h" | 14 #include "cc/test/scheduler_test_common.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 18 | 17 |
| 19 namespace cc { | 18 namespace cc { |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); | 21 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
|
Fady Samuel
2017/04/03 22:33:25
get rid of static keyword.
I probably introduced
Alex Z.
2017/04/04 14:10:33
Done.
| |
| 23 | 22 static constexpr bool is_root = true; |
| 24 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { | 23 static constexpr bool handles_frame_sink_id_invalidation = true; |
| 25 public: | 24 static constexpr bool need_sync_points = true; |
|
Fady Samuel
2017/04/03 22:33:25
Get rid of static if in anonymous namespace.
Alex Z.
2017/04/04 14:10:33
Done.
| |
| 26 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {} | |
| 27 | |
| 28 void ReturnResources(const ReturnedResourceArray& resources) override {} | |
| 29 | |
| 30 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override { | |
| 31 begin_frame_source_ = begin_frame_source; | |
| 32 } | |
| 33 | |
| 34 BeginFrameSource* begin_frame_source() { return begin_frame_source_; } | |
| 35 | |
| 36 private: | |
| 37 BeginFrameSource* begin_frame_source_; | |
| 38 }; | |
| 39 | 25 |
| 40 TEST(SurfaceTest, SurfaceLifetime) { | 26 TEST(SurfaceTest, SurfaceLifetime) { |
| 41 SurfaceManager manager; | 27 SurfaceManager manager; |
| 42 FakeSurfaceFactoryClient surface_factory_client; | 28 CompositorFrameSinkSupport support( |
| 43 SurfaceFactory factory(kArbitraryFrameSinkId, &manager, | 29 nullptr, &manager, kArbitraryFrameSinkId, is_root, |
| 44 &surface_factory_client); | 30 handles_frame_sink_id_invalidation, need_sync_points); |
| 45 | 31 |
| 46 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); | 32 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); |
| 47 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); | 33 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); |
| 48 factory.SubmitCompositorFrame(local_surface_id, CompositorFrame(), | 34 support.SubmitCompositorFrame(local_surface_id, CompositorFrame()); |
| 49 SurfaceFactory::DrawCallback()); | |
| 50 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); | 35 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); |
| 51 factory.EvictSurface(); | 36 support.EvictFrame(); |
| 52 | 37 |
| 53 EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id)); | 38 EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id)); |
| 54 } | 39 } |
| 55 | 40 |
| 56 TEST(SurfaceTest, SurfaceIds) { | 41 TEST(SurfaceTest, SurfaceIds) { |
| 57 for (size_t i = 0; i < 3; ++i) { | 42 for (size_t i = 0; i < 3; ++i) { |
| 58 LocalSurfaceIdAllocator allocator; | 43 LocalSurfaceIdAllocator allocator; |
| 59 LocalSurfaceId id1 = allocator.GenerateId(); | 44 LocalSurfaceId id1 = allocator.GenerateId(); |
| 60 LocalSurfaceId id2 = allocator.GenerateId(); | 45 LocalSurfaceId id2 = allocator.GenerateId(); |
| 61 EXPECT_NE(id1, id2); | 46 EXPECT_NE(id1, id2); |
| 62 } | 47 } |
| 63 } | 48 } |
| 64 | 49 |
| 65 void TestCopyResultCallback(bool* called, | 50 void TestCopyResultCallback(bool* called, |
| 66 std::unique_ptr<CopyOutputResult> result) { | 51 std::unique_ptr<CopyOutputResult> result) { |
| 67 *called = true; | 52 *called = true; |
| 68 } | 53 } |
| 69 | 54 |
| 70 // Test that CopyOutputRequests can outlive the current frame and be | 55 // Test that CopyOutputRequests can outlive the current frame and be |
| 71 // aggregated on the next frame. | 56 // aggregated on the next frame. |
| 72 TEST(SurfaceTest, CopyRequestLifetime) { | 57 TEST(SurfaceTest, CopyRequestLifetime) { |
| 73 SurfaceManager manager; | 58 SurfaceManager manager; |
| 74 FakeSurfaceFactoryClient surface_factory_client; | 59 CompositorFrameSinkSupport support( |
| 75 SurfaceFactory factory(kArbitraryFrameSinkId, &manager, | 60 nullptr, &manager, kArbitraryFrameSinkId, is_root, |
| 76 &surface_factory_client); | 61 handles_frame_sink_id_invalidation, need_sync_points); |
| 77 | 62 |
| 78 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); | 63 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); |
| 79 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); | 64 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); |
| 80 CompositorFrame frame; | 65 CompositorFrame frame; |
| 81 frame.render_pass_list.push_back(RenderPass::Create()); | 66 frame.render_pass_list.push_back(RenderPass::Create()); |
| 82 factory.SubmitCompositorFrame(local_surface_id, std::move(frame), | 67 support.SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 83 SurfaceFactory::DrawCallback()); | |
| 84 Surface* surface = manager.GetSurfaceForId(surface_id); | 68 Surface* surface = manager.GetSurfaceForId(surface_id); |
| 85 ASSERT_TRUE(!!surface); | 69 ASSERT_TRUE(!!surface); |
| 86 | 70 |
| 87 bool copy_called = false; | 71 bool copy_called = false; |
| 88 factory.RequestCopyOfSurface(CopyOutputRequest::CreateRequest( | 72 support.RequestCopyOfSurface(CopyOutputRequest::CreateRequest( |
| 89 base::Bind(&TestCopyResultCallback, ©_called))); | 73 base::Bind(&TestCopyResultCallback, ©_called))); |
| 90 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); | 74 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); |
| 91 EXPECT_FALSE(copy_called); | 75 EXPECT_FALSE(copy_called); |
| 92 | 76 |
| 93 int max_frame = 3, start_id = 200; | 77 int max_frame = 3, start_id = 200; |
| 94 for (int i = 0; i < max_frame; ++i) { | 78 for (int i = 0; i < max_frame; ++i) { |
| 95 CompositorFrame frame; | 79 CompositorFrame frame; |
| 96 frame.render_pass_list.push_back(RenderPass::Create()); | 80 frame.render_pass_list.push_back(RenderPass::Create()); |
| 97 frame.render_pass_list.back()->id = i * 3 + start_id; | 81 frame.render_pass_list.back()->id = i * 3 + start_id; |
| 98 frame.render_pass_list.push_back(RenderPass::Create()); | 82 frame.render_pass_list.push_back(RenderPass::Create()); |
| 99 frame.render_pass_list.back()->id = i * 3 + start_id + 1; | 83 frame.render_pass_list.back()->id = i * 3 + start_id + 1; |
| 100 frame.render_pass_list.push_back(RenderPass::Create()); | 84 frame.render_pass_list.push_back(RenderPass::Create()); |
| 101 frame.render_pass_list.back()->id = i * 3 + start_id + 2; | 85 frame.render_pass_list.back()->id = i * 3 + start_id + 2; |
| 102 factory.SubmitCompositorFrame(local_surface_id, std::move(frame), | 86 support.SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 103 SurfaceFactory::DrawCallback()); | |
| 104 } | 87 } |
| 105 | 88 |
| 106 int last_pass_id = (max_frame - 1) * 3 + start_id + 2; | 89 int last_pass_id = (max_frame - 1) * 3 + start_id + 2; |
| 107 // The copy request should stay on the Surface until TakeCopyOutputRequests | 90 // The copy request should stay on the Surface until TakeCopyOutputRequests |
| 108 // is called. | 91 // is called. |
| 109 EXPECT_FALSE(copy_called); | 92 EXPECT_FALSE(copy_called); |
| 110 EXPECT_EQ( | 93 EXPECT_EQ( |
| 111 1u, | 94 1u, |
| 112 surface->GetActiveFrame().render_pass_list.back()->copy_requests.size()); | 95 surface->GetActiveFrame().render_pass_list.back()->copy_requests.size()); |
| 113 | 96 |
| 114 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; | 97 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; |
| 115 surface->TakeCopyOutputRequests(©_requests); | 98 surface->TakeCopyOutputRequests(©_requests); |
| 116 EXPECT_EQ(1u, copy_requests.size()); | 99 EXPECT_EQ(1u, copy_requests.size()); |
| 117 // Last (root) pass should receive copy request. | 100 // Last (root) pass should receive copy request. |
| 118 ASSERT_EQ(1u, copy_requests.count(last_pass_id)); | 101 ASSERT_EQ(1u, copy_requests.count(last_pass_id)); |
| 119 EXPECT_FALSE(copy_called); | 102 EXPECT_FALSE(copy_called); |
| 120 copy_requests.find(last_pass_id)->second->SendEmptyResult(); | 103 copy_requests.find(last_pass_id)->second->SendEmptyResult(); |
| 121 EXPECT_TRUE(copy_called); | 104 EXPECT_TRUE(copy_called); |
| 122 | 105 |
| 123 factory.EvictSurface(); | 106 support.EvictFrame(); |
| 124 } | 107 } |
| 125 | 108 |
| 126 } // namespace | 109 } // namespace |
| 127 } // namespace cc | 110 } // namespace cc |
| OLD | NEW |