| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "cc/base/lap_timer.h" | 6 #include "cc/base/lap_timer.h" |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/quads/surface_draw_quad.h" | 8 #include "cc/quads/surface_draw_quad.h" |
| 9 #include "cc/quads/texture_draw_quad.h" | 9 #include "cc/quads/texture_draw_quad.h" |
| 10 #include "cc/surfaces/framesink_manager_client.h" |
| 10 #include "cc/surfaces/surface_aggregator.h" | 11 #include "cc/surfaces/surface_aggregator.h" |
| 11 #include "cc/surfaces/surface_factory.h" | 12 #include "cc/surfaces/surface_factory.h" |
| 12 #include "cc/surfaces/surface_factory_client.h" | |
| 13 #include "cc/surfaces/surface_manager.h" | 13 #include "cc/surfaces/surface_manager.h" |
| 14 #include "cc/surfaces/surface_resource_holder_client.h" |
| 14 #include "cc/test/fake_output_surface_client.h" | 15 #include "cc/test/fake_output_surface_client.h" |
| 15 #include "cc/test/fake_resource_provider.h" | 16 #include "cc/test/fake_resource_provider.h" |
| 17 #include "cc/test/stub_surface_factory_client.h" |
| 16 #include "cc/test/test_context_provider.h" | 18 #include "cc/test/test_context_provider.h" |
| 17 #include "cc/test/test_shared_bitmap_manager.h" | 19 #include "cc/test/test_shared_bitmap_manager.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "testing/perf/perf_test.h" | 21 #include "testing/perf/perf_test.h" |
| 20 | 22 |
| 21 namespace cc { | 23 namespace cc { |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 static const base::UnguessableToken kArbitraryToken = | 26 static const base::UnguessableToken kArbitraryToken = |
| 25 base::UnguessableToken::Create(); | 27 base::UnguessableToken::Create(); |
| 26 | 28 |
| 27 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 29 class StubSurfaceResourceHolderClient : public SurfaceResourceHolderClient { |
| 28 public: | 30 public: |
| 31 StubSurfaceResourceHolderClient() = default; |
| 32 ~StubSurfaceResourceHolderClient() override = default; |
| 33 |
| 29 void ReturnResources(const ReturnedResourceArray& resources) override {} | 34 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 30 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} | |
| 31 }; | 35 }; |
| 32 | 36 |
| 33 class SurfaceAggregatorPerfTest : public testing::Test { | 37 class SurfaceAggregatorPerfTest : public testing::Test { |
| 34 public: | 38 public: |
| 35 SurfaceAggregatorPerfTest() { | 39 SurfaceAggregatorPerfTest() { |
| 36 context_provider_ = TestContextProvider::Create(); | 40 context_provider_ = TestContextProvider::Create(); |
| 37 context_provider_->BindToCurrentThread(); | 41 context_provider_->BindToCurrentThread(); |
| 38 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | 42 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 39 | 43 |
| 40 resource_provider_ = FakeResourceProvider::Create( | 44 resource_provider_ = FakeResourceProvider::Create( |
| 41 context_provider_.get(), shared_bitmap_manager_.get()); | 45 context_provider_.get(), shared_bitmap_manager_.get()); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void RunTest(int num_surfaces, | 48 void RunTest(int num_surfaces, |
| 45 int num_textures, | 49 int num_textures, |
| 46 float opacity, | 50 float opacity, |
| 47 bool optimize_damage, | 51 bool optimize_damage, |
| 48 bool full_damage, | 52 bool full_damage, |
| 49 const std::string& name) { | 53 const std::string& name) { |
| 50 std::vector<std::unique_ptr<SurfaceFactory>> child_factories(num_surfaces); | 54 std::vector<std::unique_ptr<SurfaceFactory>> child_factories(num_surfaces); |
| 51 for (int i = 0; i < num_surfaces; i++) | 55 for (int i = 0; i < num_surfaces; i++) |
| 52 child_factories[i].reset( | 56 child_factories[i].reset(new SurfaceFactory( |
| 53 new SurfaceFactory(FrameSinkId(1, i + 1), &manager_, &empty_client_)); | 57 FrameSinkId(1, i + 1), &manager_, &stub_surface_factory_client_, |
| 58 &stub_surface_resource_holder_client_)); |
| 54 aggregator_.reset(new SurfaceAggregator(&manager_, resource_provider_.get(), | 59 aggregator_.reset(new SurfaceAggregator(&manager_, resource_provider_.get(), |
| 55 optimize_damage)); | 60 optimize_damage)); |
| 56 for (int i = 0; i < num_surfaces; i++) { | 61 for (int i = 0; i < num_surfaces; i++) { |
| 57 LocalSurfaceId local_surface_id(i + 1, kArbitraryToken); | 62 LocalSurfaceId local_surface_id(i + 1, kArbitraryToken); |
| 58 std::unique_ptr<RenderPass> pass(RenderPass::Create()); | 63 std::unique_ptr<RenderPass> pass(RenderPass::Create()); |
| 59 CompositorFrame frame; | 64 CompositorFrame frame; |
| 60 | 65 |
| 61 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 66 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 62 for (int j = 0; j < num_textures; j++) { | 67 for (int j = 0; j < num_textures; j++) { |
| 63 TransferableResource resource; | 68 TransferableResource resource; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 SurfaceDrawQuadType::PRIMARY, nullptr); | 101 SurfaceDrawQuadType::PRIMARY, nullptr); |
| 97 } | 102 } |
| 98 | 103 |
| 99 frame.render_pass_list.push_back(std::move(pass)); | 104 frame.render_pass_list.push_back(std::move(pass)); |
| 100 child_factories[i]->SubmitCompositorFrame( | 105 child_factories[i]->SubmitCompositorFrame( |
| 101 local_surface_id, std::move(frame), SurfaceFactory::DrawCallback(), | 106 local_surface_id, std::move(frame), SurfaceFactory::DrawCallback(), |
| 102 SurfaceFactory::WillDrawCallback()); | 107 SurfaceFactory::WillDrawCallback()); |
| 103 } | 108 } |
| 104 | 109 |
| 105 SurfaceFactory root_factory(FrameSinkId(1, num_surfaces + 1), &manager_, | 110 SurfaceFactory root_factory(FrameSinkId(1, num_surfaces + 1), &manager_, |
| 106 &empty_client_); | 111 &stub_surface_factory_client_, |
| 112 &stub_surface_resource_holder_client_); |
| 107 timer_.Reset(); | 113 timer_.Reset(); |
| 108 do { | 114 do { |
| 109 std::unique_ptr<RenderPass> pass(RenderPass::Create()); | 115 std::unique_ptr<RenderPass> pass(RenderPass::Create()); |
| 110 CompositorFrame frame; | 116 CompositorFrame frame; |
| 111 | 117 |
| 112 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 118 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 113 SurfaceDrawQuad* surface_quad = | 119 SurfaceDrawQuad* surface_quad = |
| 114 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); | 120 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 115 surface_quad->SetNew( | 121 surface_quad->SetNew( |
| 116 sqs, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), | 122 sqs, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 | 143 |
| 138 perf_test::PrintResult("aggregator_speed", "", name, timer_.LapsPerSecond(), | 144 perf_test::PrintResult("aggregator_speed", "", name, timer_.LapsPerSecond(), |
| 139 "runs/s", true); | 145 "runs/s", true); |
| 140 for (int i = 0; i < num_surfaces; i++) | 146 for (int i = 0; i < num_surfaces; i++) |
| 141 child_factories[i]->EvictSurface(); | 147 child_factories[i]->EvictSurface(); |
| 142 root_factory.EvictSurface(); | 148 root_factory.EvictSurface(); |
| 143 } | 149 } |
| 144 | 150 |
| 145 protected: | 151 protected: |
| 146 SurfaceManager manager_; | 152 SurfaceManager manager_; |
| 147 EmptySurfaceFactoryClient empty_client_; | 153 StubSurfaceResourceHolderClient stub_surface_resource_holder_client_; |
| 154 StubSurfaceFactoryClient stub_surface_factory_client_; |
| 148 scoped_refptr<TestContextProvider> context_provider_; | 155 scoped_refptr<TestContextProvider> context_provider_; |
| 149 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; | 156 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 150 std::unique_ptr<ResourceProvider> resource_provider_; | 157 std::unique_ptr<ResourceProvider> resource_provider_; |
| 151 std::unique_ptr<SurfaceAggregator> aggregator_; | 158 std::unique_ptr<SurfaceAggregator> aggregator_; |
| 152 LapTimer timer_; | 159 LapTimer timer_; |
| 153 }; | 160 }; |
| 154 | 161 |
| 155 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaque) { | 162 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaque) { |
| 156 RunTest(20, 100, 1.f, false, true, "many_surfaces_opaque"); | 163 RunTest(20, 100, 1.f, false, true, "many_surfaces_opaque"); |
| 157 } | 164 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 175 TEST_F(SurfaceAggregatorPerfTest, FewSurfacesDamageCalc) { | 182 TEST_F(SurfaceAggregatorPerfTest, FewSurfacesDamageCalc) { |
| 176 RunTest(3, 1000, 1.f, true, true, "few_surfaces_damage_calc"); | 183 RunTest(3, 1000, 1.f, true, true, "few_surfaces_damage_calc"); |
| 177 } | 184 } |
| 178 | 185 |
| 179 TEST_F(SurfaceAggregatorPerfTest, FewSurfacesAggregateDamaged) { | 186 TEST_F(SurfaceAggregatorPerfTest, FewSurfacesAggregateDamaged) { |
| 180 RunTest(3, 1000, 1.f, true, false, "few_surfaces_aggregate_damaged"); | 187 RunTest(3, 1000, 1.f, true, false, "few_surfaces_aggregate_damaged"); |
| 181 } | 188 } |
| 182 | 189 |
| 183 } // namespace | 190 } // namespace |
| 184 } // namespace cc | 191 } // namespace cc |
| OLD | NEW |