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.
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/fake_resource_provider.h"
17 #include "cc/test/test_shared_bitmap_manager.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/perf/perf_test.h"
24 class EmptySurfaceFactoryClient
: public SurfaceFactoryClient
{
26 void ReturnResources(const ReturnedResourceArray
& resources
) override
{}
29 class SurfaceAggregatorPerfTest
: public testing::Test
{
31 SurfaceAggregatorPerfTest() : factory_(&manager_
, &empty_client_
) {
32 output_surface_
= FakeOutputSurface::CreateSoftware(
33 make_scoped_ptr(new SoftwareOutputDevice
));
34 output_surface_
->BindToClient(&output_surface_client_
);
35 shared_bitmap_manager_
.reset(new TestSharedBitmapManager
);
37 resource_provider_
= FakeResourceProvider::Create(
38 output_surface_
.get(), shared_bitmap_manager_
.get());
41 void RunTest(int num_surfaces
,
46 const std::string
& name
) {
47 aggregator_
.reset(new SurfaceAggregator(&manager_
, resource_provider_
.get(),
49 for (int i
= 1; i
<= num_surfaces
; i
++) {
50 factory_
.Create(SurfaceId(i
));
51 scoped_ptr
<RenderPass
> pass(RenderPass::Create());
52 scoped_ptr
<DelegatedFrameData
> frame_data(new DelegatedFrameData
);
54 SharedQuadState
* sqs
= pass
->CreateAndAppendSharedQuadState();
55 for (int j
= 0; j
< num_textures
; j
++) {
56 TransferableResource resource
;
58 resource
.is_software
= true;
59 frame_data
->resource_list
.push_back(resource
);
61 TextureDrawQuad
* quad
=
62 pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
63 const gfx::Rect
rect(0, 0, 1, 1);
64 const gfx::Rect opaque_rect
;
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);
68 bool needs_blending
= false;
69 bool premultiplied_alpha
= false;
70 const gfx::PointF uv_top_left
;
71 const gfx::PointF uv_bottom_right
;
72 SkColor background_color
= SK_ColorGREEN
;
73 const float vertex_opacity
[4] = {0.f
, 0.f
, 1.f
, 1.f
};
75 bool nearest_neighbor
= false;
76 quad
->SetAll(sqs
, rect
, opaque_rect
, visible_rect
, needs_blending
, j
,
77 gfx::Size(), false, premultiplied_alpha
, uv_top_left
,
78 uv_bottom_right
, background_color
, vertex_opacity
, flipped
,
81 sqs
= pass
->CreateAndAppendSharedQuadState();
82 sqs
->opacity
= opacity
;
84 SurfaceDrawQuad
* surface_quad
=
85 pass
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
86 surface_quad
->SetNew(sqs
, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1),
90 frame_data
->render_pass_list
.push_back(pass
.Pass());
91 scoped_ptr
<CompositorFrame
> frame(new CompositorFrame
);
92 frame
->delegated_frame_data
= frame_data
.Pass();
93 factory_
.SubmitCompositorFrame(SurfaceId(i
), frame
.Pass(),
94 SurfaceFactory::DrawCallback());
97 factory_
.Create(SurfaceId(num_surfaces
+ 1));
100 scoped_ptr
<RenderPass
> pass(RenderPass::Create());
101 scoped_ptr
<DelegatedFrameData
> frame_data(new DelegatedFrameData
);
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
));
110 pass
->damage_rect
= gfx::Rect(0, 0, 100, 100);
112 pass
->damage_rect
= gfx::Rect(0, 0, 1, 1);
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_
.SubmitCompositorFrame(SurfaceId(num_surfaces
+ 1), frame
.Pass(),
118 SurfaceFactory::DrawCallback());
120 scoped_ptr
<CompositorFrame
> aggregated
=
121 aggregator_
->Aggregate(SurfaceId(num_surfaces
+ 1));
123 } while (!timer_
.HasTimeLimitExpired());
125 perf_test::PrintResult("aggregator_speed", "", name
, timer_
.LapsPerSecond(),
128 factory_
.Destroy(SurfaceId(num_surfaces
+ 1));
129 for (int i
= 1; i
<= num_surfaces
; i
++)
130 factory_
.Destroy(SurfaceId(i
));
134 SurfaceManager manager_
;
135 EmptySurfaceFactoryClient empty_client_
;
136 SurfaceFactory factory_
;
137 FakeOutputSurfaceClient output_surface_client_
;
138 scoped_ptr
<OutputSurface
> output_surface_
;
139 scoped_ptr
<SharedBitmapManager
> shared_bitmap_manager_
;
140 scoped_ptr
<ResourceProvider
> resource_provider_
;
141 scoped_ptr
<SurfaceAggregator
> aggregator_
;
145 TEST_F(SurfaceAggregatorPerfTest
, ManySurfacesOpaque
) {
146 RunTest(20, 100, 1.f
, false, true, "many_surfaces_opaque");
149 TEST_F(SurfaceAggregatorPerfTest
, ManySurfacesTransparent
) {
150 RunTest(20, 100, .5f
, false, true, "many_surfaces_transparent");
153 TEST_F(SurfaceAggregatorPerfTest
, FewSurfaces
) {
154 RunTest(3, 1000, 1.f
, false, true, "few_surfaces");
157 TEST_F(SurfaceAggregatorPerfTest
, ManySurfacesOpaqueDamageCalc
) {
158 RunTest(20, 100, 1.f
, true, true, "many_surfaces_opaque_damage_calc");
161 TEST_F(SurfaceAggregatorPerfTest
, ManySurfacesTransparentDamageCalc
) {
162 RunTest(20, 100, .5f
, true, true, "many_surfaces_transparent_damage_calc");
165 TEST_F(SurfaceAggregatorPerfTest
, FewSurfacesDamageCalc
) {
166 RunTest(3, 1000, 1.f
, true, true, "few_surfaces_damage_calc");
169 TEST_F(SurfaceAggregatorPerfTest
, FewSurfacesAggregateDamaged
) {
170 RunTest(3, 1000, 1.f
, true, false, "few_surfaces_aggregate_damaged");