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/test_shared_bitmap_manager.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/perf/perf_test.h"
23 class EmptySurfaceFactoryClient
: public SurfaceFactoryClient
{
25 void ReturnResources(const ReturnedResourceArray
& resources
) override
{}
28 class SurfaceAggregatorPerfTest
: public testing::Test
{
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
);
36 resource_provider_
= ResourceProvider::Create(
37 output_surface_
.get(), shared_bitmap_manager_
.get(), nullptr, nullptr,
40 new SurfaceAggregator(&manager_
, resource_provider_
.get()));
43 void RunTest(int num_surfaces
,
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
);
52 SharedQuadState
* sqs
= pass
->CreateAndAppendSharedQuadState();
53 for (int j
= 0; j
< num_textures
; j
++) {
54 TransferableResource resource
;
56 resource
.is_software
= true;
57 frame_data
->resource_list
.push_back(resource
);
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
};
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
,
77 sqs
= pass
->CreateAndAppendSharedQuadState();
78 sqs
->opacity
= opacity
;
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),
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());
95 scoped_ptr
<CompositorFrame
> aggregated
=
96 aggregator_
->Aggregate(SurfaceId(num_surfaces
));
98 } while (!timer_
.HasTimeLimitExpired());
100 perf_test::PrintResult("aggregator_speed", "", name
, timer_
.LapsPerSecond(),
103 for (int i
= 1; i
<= num_surfaces
; i
++)
104 factory_
.Destroy(SurfaceId(i
));
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_
;
119 TEST_F(SurfaceAggregatorPerfTest
, ManySurfacesOpaque
) {
120 RunTest(20, 100, 1.f
, "many_surfaces_opaque");
123 TEST_F(SurfaceAggregatorPerfTest
, ManySurfacesTransparent
) {
124 RunTest(20, 100, .5f
, "many_surfaces_transparent");
127 TEST_F(SurfaceAggregatorPerfTest
, FewSurfaces
) {
128 RunTest(3, 1000, 1.f
, "few_surfaces");