| 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 "cc/debug/lap_timer.h" | 5 #include "cc/debug/lap_timer.h" |
| 6 #include "cc/output/compositor_frame.h" | 6 #include "cc/output/compositor_frame.h" |
| 7 #include "cc/output/delegated_frame_data.h" | 7 #include "cc/output/delegated_frame_data.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/surface_aggregator.h" | 10 #include "cc/surfaces/surface_aggregator.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 class SurfaceAggregatorPerfTest : public testing::Test { | 29 class SurfaceAggregatorPerfTest : public testing::Test { |
| 30 public: | 30 public: |
| 31 SurfaceAggregatorPerfTest() : factory_(&manager_, &empty_client_) { | 31 SurfaceAggregatorPerfTest() : factory_(&manager_, &empty_client_) { |
| 32 output_surface_ = FakeOutputSurface::CreateSoftware( | 32 output_surface_ = FakeOutputSurface::CreateSoftware( |
| 33 make_scoped_ptr(new SoftwareOutputDevice)); | 33 make_scoped_ptr(new SoftwareOutputDevice)); |
| 34 output_surface_->BindToClient(&output_surface_client_); | 34 output_surface_->BindToClient(&output_surface_client_); |
| 35 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | 35 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 36 | 36 |
| 37 resource_provider_ = FakeResourceProvider::Create( | 37 resource_provider_ = FakeResourceProvider::Create( |
| 38 output_surface_.get(), shared_bitmap_manager_.get()); | 38 output_surface_.get(), shared_bitmap_manager_.get()); |
| 39 aggregator_.reset( | |
| 40 new SurfaceAggregator(&manager_, resource_provider_.get())); | |
| 41 } | 39 } |
| 42 | 40 |
| 43 void RunTest(int num_surfaces, | 41 void RunTest(int num_surfaces, |
| 44 int num_textures, | 42 int num_textures, |
| 45 float opacity, | 43 float opacity, |
| 44 bool optimize_damage, |
| 45 bool full_damage, |
| 46 const std::string& name) { | 46 const std::string& name) { |
| 47 aggregator_.reset(new SurfaceAggregator(&manager_, resource_provider_.get(), |
| 48 optimize_damage)); |
| 47 for (int i = 1; i <= num_surfaces; i++) { | 49 for (int i = 1; i <= num_surfaces; i++) { |
| 48 factory_.Create(SurfaceId(i)); | 50 factory_.Create(SurfaceId(i)); |
| 49 scoped_ptr<RenderPass> pass(RenderPass::Create()); | 51 scoped_ptr<RenderPass> pass(RenderPass::Create()); |
| 50 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 52 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 51 | 53 |
| 52 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 54 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 53 for (int j = 0; j < num_textures; j++) { | 55 for (int j = 0; j < num_textures; j++) { |
| 54 TransferableResource resource; | 56 TransferableResource resource; |
| 55 resource.id = j; | 57 resource.id = j; |
| 56 resource.is_software = true; | 58 resource.is_software = true; |
| 57 frame_data->resource_list.push_back(resource); | 59 frame_data->resource_list.push_back(resource); |
| 58 | 60 |
| 59 TextureDrawQuad* quad = | 61 TextureDrawQuad* quad = |
| 60 pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 62 pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 61 const gfx::Rect rect(0, 0, 1, 1); | 63 const gfx::Rect rect(0, 0, 1, 1); |
| 62 const gfx::Rect opaque_rect; | 64 const gfx::Rect opaque_rect; |
| 63 const gfx::Rect visible_rect(0, 0, 1, 1); | 65 // Half of rects should be visible with partial damage. |
| 66 gfx::Rect visible_rect = |
| 67 j % 2 == 0 ? gfx::Rect(0, 0, 1, 1) : gfx::Rect(1, 1, 1, 1); |
| 64 bool needs_blending = false; | 68 bool needs_blending = false; |
| 65 bool premultiplied_alpha = false; | 69 bool premultiplied_alpha = false; |
| 66 const gfx::PointF uv_top_left; | 70 const gfx::PointF uv_top_left; |
| 67 const gfx::PointF uv_bottom_right; | 71 const gfx::PointF uv_bottom_right; |
| 68 SkColor background_color = SK_ColorGREEN; | 72 SkColor background_color = SK_ColorGREEN; |
| 69 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f}; | 73 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f}; |
| 70 bool flipped = false; | 74 bool flipped = false; |
| 71 bool nearest_neighbor = false; | 75 bool nearest_neighbor = false; |
| 72 quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, j, | 76 quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, j, |
| 73 gfx::Size(), false, premultiplied_alpha, uv_top_left, | 77 gfx::Size(), false, premultiplied_alpha, uv_top_left, |
| 74 uv_bottom_right, background_color, vertex_opacity, flipped, | 78 uv_bottom_right, background_color, vertex_opacity, flipped, |
| 75 nearest_neighbor); | 79 nearest_neighbor); |
| 76 } | 80 } |
| 77 sqs = pass->CreateAndAppendSharedQuadState(); | 81 sqs = pass->CreateAndAppendSharedQuadState(); |
| 78 sqs->opacity = opacity; | 82 sqs->opacity = opacity; |
| 79 if (i > 1) { | 83 if (i > 1) { |
| 80 SurfaceDrawQuad* surface_quad = | 84 SurfaceDrawQuad* surface_quad = |
| 81 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); | 85 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 82 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), | 86 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), |
| 83 SurfaceId(i - 1)); | 87 SurfaceId(i - 1)); |
| 84 } | 88 } |
| 85 | 89 |
| 86 frame_data->render_pass_list.push_back(pass.Pass()); | 90 frame_data->render_pass_list.push_back(pass.Pass()); |
| 87 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 91 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 88 frame->delegated_frame_data = frame_data.Pass(); | 92 frame->delegated_frame_data = frame_data.Pass(); |
| 89 factory_.SubmitFrame(SurfaceId(i), frame.Pass(), | 93 factory_.SubmitFrame(SurfaceId(i), frame.Pass(), |
| 90 SurfaceFactory::DrawCallback()); | 94 SurfaceFactory::DrawCallback()); |
| 91 } | 95 } |
| 92 | 96 |
| 97 factory_.Create(SurfaceId(num_surfaces + 1)); |
| 93 timer_.Reset(); | 98 timer_.Reset(); |
| 94 do { | 99 do { |
| 100 scoped_ptr<RenderPass> pass(RenderPass::Create()); |
| 101 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 102 |
| 103 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 104 SurfaceDrawQuad* surface_quad = |
| 105 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 106 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 100, 100), |
| 107 gfx::Rect(0, 0, 100, 100), SurfaceId(num_surfaces)); |
| 108 |
| 109 if (full_damage) |
| 110 pass->damage_rect = gfx::Rect(0, 0, 100, 100); |
| 111 else |
| 112 pass->damage_rect = gfx::Rect(0, 0, 1, 1); |
| 113 |
| 114 frame_data->render_pass_list.push_back(pass.Pass()); |
| 115 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 116 frame->delegated_frame_data = frame_data.Pass(); |
| 117 factory_.SubmitFrame(SurfaceId(num_surfaces + 1), frame.Pass(), |
| 118 SurfaceFactory::DrawCallback()); |
| 119 |
| 95 scoped_ptr<CompositorFrame> aggregated = | 120 scoped_ptr<CompositorFrame> aggregated = |
| 96 aggregator_->Aggregate(SurfaceId(num_surfaces)); | 121 aggregator_->Aggregate(SurfaceId(num_surfaces + 1)); |
| 97 timer_.NextLap(); | 122 timer_.NextLap(); |
| 98 } while (!timer_.HasTimeLimitExpired()); | 123 } while (!timer_.HasTimeLimitExpired()); |
| 99 | 124 |
| 100 perf_test::PrintResult("aggregator_speed", "", name, timer_.LapsPerSecond(), | 125 perf_test::PrintResult("aggregator_speed", "", name, timer_.LapsPerSecond(), |
| 101 "runs/s", true); | 126 "runs/s", true); |
| 102 | 127 |
| 128 factory_.Destroy(SurfaceId(num_surfaces + 1)); |
| 103 for (int i = 1; i <= num_surfaces; i++) | 129 for (int i = 1; i <= num_surfaces; i++) |
| 104 factory_.Destroy(SurfaceId(i)); | 130 factory_.Destroy(SurfaceId(i)); |
| 105 } | 131 } |
| 106 | 132 |
| 107 protected: | 133 protected: |
| 108 SurfaceManager manager_; | 134 SurfaceManager manager_; |
| 109 EmptySurfaceFactoryClient empty_client_; | 135 EmptySurfaceFactoryClient empty_client_; |
| 110 SurfaceFactory factory_; | 136 SurfaceFactory factory_; |
| 111 FakeOutputSurfaceClient output_surface_client_; | 137 FakeOutputSurfaceClient output_surface_client_; |
| 112 scoped_ptr<OutputSurface> output_surface_; | 138 scoped_ptr<OutputSurface> output_surface_; |
| 113 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 139 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 114 scoped_ptr<ResourceProvider> resource_provider_; | 140 scoped_ptr<ResourceProvider> resource_provider_; |
| 115 scoped_ptr<SurfaceAggregator> aggregator_; | 141 scoped_ptr<SurfaceAggregator> aggregator_; |
| 116 LapTimer timer_; | 142 LapTimer timer_; |
| 117 }; | 143 }; |
| 118 | 144 |
| 119 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaque) { | 145 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaque) { |
| 120 RunTest(20, 100, 1.f, "many_surfaces_opaque"); | 146 RunTest(20, 100, 1.f, false, true, "many_surfaces_opaque"); |
| 121 } | 147 } |
| 122 | 148 |
| 123 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesTransparent) { | 149 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesTransparent) { |
| 124 RunTest(20, 100, .5f, "many_surfaces_transparent"); | 150 RunTest(20, 100, .5f, false, true, "many_surfaces_transparent"); |
| 125 } | 151 } |
| 126 | 152 |
| 127 TEST_F(SurfaceAggregatorPerfTest, FewSurfaces) { | 153 TEST_F(SurfaceAggregatorPerfTest, FewSurfaces) { |
| 128 RunTest(3, 1000, 1.f, "few_surfaces"); | 154 RunTest(3, 1000, 1.f, false, true, "few_surfaces"); |
| 155 } |
| 156 |
| 157 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaqueDamageCalc) { |
| 158 RunTest(20, 100, 1.f, true, true, "many_surfaces_opaque_damage_calc"); |
| 159 } |
| 160 |
| 161 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesTransparentDamageCalc) { |
| 162 RunTest(20, 100, .5f, true, true, "many_surfaces_transparent_damage_calc"); |
| 163 } |
| 164 |
| 165 TEST_F(SurfaceAggregatorPerfTest, FewSurfacesDamageCalc) { |
| 166 RunTest(3, 1000, 1.f, true, true, "few_surfaces_damage_calc"); |
| 167 } |
| 168 |
| 169 TEST_F(SurfaceAggregatorPerfTest, FewSurfacesAggregateDamaged) { |
| 170 RunTest(3, 1000, 1.f, true, false, "few_surfaces_aggregate_damaged"); |
| 129 } | 171 } |
| 130 | 172 |
| 131 } // namespace | 173 } // namespace |
| 132 } // namespace cc | 174 } // namespace cc |
| OLD | NEW |