OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/debug/lap_timer.h" |
| 6 #include "cc/output/compositor_frame.h" |
| 7 #include "cc/output/delegated_frame_data.h" |
| 8 #include "cc/quads/surface_draw_quad.h" |
| 9 #include "cc/quads/texture_draw_quad.h" |
| 10 #include "cc/surfaces/surface_aggregator.h" |
| 11 #include "cc/surfaces/surface_factory.h" |
| 12 #include "cc/surfaces/surface_factory_client.h" |
| 13 #include "cc/surfaces/surface_manager.h" |
| 14 #include "cc/test/fake_output_surface.h" |
| 15 #include "cc/test/fake_output_surface_client.h" |
| 16 #include "cc/test/test_shared_bitmap_manager.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "testing/perf/perf_test.h" |
| 19 |
| 20 namespace cc { |
| 21 namespace { |
| 22 |
| 23 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 24 public: |
| 25 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 26 }; |
| 27 |
| 28 class SurfaceAggregatorPerfTest : public testing::Test { |
| 29 public: |
| 30 SurfaceAggregatorPerfTest() : factory_(&manager_, &empty_client_) { |
| 31 output_surface_ = FakeOutputSurface::CreateSoftware( |
| 32 make_scoped_ptr(new SoftwareOutputDevice)); |
| 33 output_surface_->BindToClient(&output_surface_client_); |
| 34 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 35 |
| 36 resource_provider_ = ResourceProvider::Create( |
| 37 output_surface_.get(), shared_bitmap_manager_.get(), nullptr, nullptr, |
| 38 0, false, 1); |
| 39 aggregator_.reset( |
| 40 new SurfaceAggregator(&manager_, resource_provider_.get())); |
| 41 } |
| 42 |
| 43 void RunTest(int num_surfaces, |
| 44 int num_textures, |
| 45 float opacity, |
| 46 const std::string& name) { |
| 47 for (int i = 1; i <= num_surfaces; i++) { |
| 48 factory_.Create(SurfaceId(i)); |
| 49 scoped_ptr<RenderPass> pass(RenderPass::Create()); |
| 50 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 51 |
| 52 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 53 for (int j = 0; j < num_textures; j++) { |
| 54 TransferableResource resource; |
| 55 resource.id = j; |
| 56 resource.is_software = true; |
| 57 frame_data->resource_list.push_back(resource); |
| 58 |
| 59 TextureDrawQuad* quad = |
| 60 pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 61 const gfx::Rect rect(0, 0, 1, 1); |
| 62 const gfx::Rect opaque_rect; |
| 63 const gfx::Rect visible_rect(0, 0, 1, 1); |
| 64 bool needs_blending = false; |
| 65 bool premultiplied_alpha = false; |
| 66 const gfx::PointF uv_top_left; |
| 67 const gfx::PointF uv_bottom_right; |
| 68 SkColor background_color = SK_ColorGREEN; |
| 69 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f}; |
| 70 bool flipped = false; |
| 71 bool nearest_neighbor = false; |
| 72 quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, j, |
| 73 premultiplied_alpha, uv_top_left, uv_bottom_right, |
| 74 background_color, vertex_opacity, flipped, |
| 75 nearest_neighbor); |
| 76 } |
| 77 sqs = pass->CreateAndAppendSharedQuadState(); |
| 78 sqs->opacity = opacity; |
| 79 if (i > 1) { |
| 80 SurfaceDrawQuad* surface_quad = |
| 81 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 82 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), |
| 83 SurfaceId(i - 1)); |
| 84 } |
| 85 |
| 86 frame_data->render_pass_list.push_back(pass.Pass()); |
| 87 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 88 frame->delegated_frame_data = frame_data.Pass(); |
| 89 factory_.SubmitFrame(SurfaceId(i), frame.Pass(), |
| 90 SurfaceFactory::DrawCallback()); |
| 91 } |
| 92 |
| 93 timer_.Reset(); |
| 94 do { |
| 95 scoped_ptr<CompositorFrame> aggregated = |
| 96 aggregator_->Aggregate(SurfaceId(num_surfaces)); |
| 97 timer_.NextLap(); |
| 98 } while (!timer_.HasTimeLimitExpired()); |
| 99 |
| 100 perf_test::PrintResult("aggregator_speed", "", name, timer_.LapsPerSecond(), |
| 101 "runs/s", true); |
| 102 |
| 103 for (int i = 1; i <= num_surfaces; i++) |
| 104 factory_.Destroy(SurfaceId(i)); |
| 105 } |
| 106 |
| 107 protected: |
| 108 SurfaceManager manager_; |
| 109 EmptySurfaceFactoryClient empty_client_; |
| 110 SurfaceFactory factory_; |
| 111 FakeOutputSurfaceClient output_surface_client_; |
| 112 scoped_ptr<OutputSurface> output_surface_; |
| 113 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 114 scoped_ptr<ResourceProvider> resource_provider_; |
| 115 scoped_ptr<SurfaceAggregator> aggregator_; |
| 116 LapTimer timer_; |
| 117 }; |
| 118 |
| 119 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaque) { |
| 120 RunTest(20, 100, 1.f, "many_surfaces_opaque"); |
| 121 } |
| 122 |
| 123 TEST_F(SurfaceAggregatorPerfTest, ManySurfacesTransparent) { |
| 124 RunTest(20, 100, .5f, "many_surfaces_transparent"); |
| 125 } |
| 126 |
| 127 TEST_F(SurfaceAggregatorPerfTest, FewSurfaces) { |
| 128 RunTest(3, 1000, 1.f, "few_surfaces"); |
| 129 } |
| 130 |
| 131 } // namespace |
| 132 } // namespace cc |
OLD | NEW |