1 // Copyright 2013 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/trees/layer_tree_host_common.h"
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/path_service.h"
12 #include "base/strings/string_piece.h"
13 #include "base/threading/thread.h"
14 #include "base/time/time.h"
15 #include "cc/layers/layer.h"
16 #include "cc/test/fake_content_layer_client.h"
17 #include "cc/test/fake_layer_tree_host_client.h"
18 #include "cc/test/lap_timer.h"
19 #include "cc/test/layer_tree_json_parser.h"
20 #include "cc/test/layer_tree_test.h"
21 #include "cc/test/paths.h"
22 #include "cc/trees/layer_tree_impl.h"
23 #include "testing/perf/perf_test.h"
28 static const int kTimeLimitMillis
= 2000;
29 static const int kWarmupRuns
= 5;
30 static const int kTimeCheckInterval
= 10;
32 class LayerTreeHostCommonPerfTest
: public LayerTreeTest
{
34 LayerTreeHostCommonPerfTest()
36 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
37 kTimeCheckInterval
) {}
39 void ReadTestFile(const std::string
& name
) {
40 base::FilePath test_data_dir
;
41 ASSERT_TRUE(PathService::Get(CCPaths::DIR_TEST_DATA
, &test_data_dir
));
42 base::FilePath json_file
= test_data_dir
.AppendASCII(name
+ ".json");
43 ASSERT_TRUE(base::ReadFileToString(json_file
, &json_
));
46 virtual void SetupTree() OVERRIDE
{
47 gfx::Size viewport
= gfx::Size(720, 1038);
48 layer_tree_host()->SetViewportSize(viewport
);
49 scoped_refptr
<Layer
> root
=
50 ParseTreeFromJson(json_
, &content_layer_client_
);
51 ASSERT_TRUE(root
.get());
52 layer_tree_host()->SetRootLayer(root
);
55 void SetTestName(const std::string
& name
) { test_name_
= name
; }
57 virtual void AfterTest() OVERRIDE
{
58 CHECK(!test_name_
.empty()) << "Must SetTestName() before TearDown().";
59 perf_test::PrintResult("calc_draw_props_time",
62 1000 * timer_
.MsPerLap(),
68 FakeContentLayerClient content_layer_client_
;
70 std::string test_name_
;
74 class CalcDrawPropsMainTest
: public LayerTreeHostCommonPerfTest
{
76 void RunCalcDrawProps() {
77 RunTest(false, false, false);
80 virtual void BeginTest() OVERRIDE
{
84 bool can_render_to_separate_surface
= true;
85 int max_texture_size
= 8096;
86 RenderSurfaceLayerList update_list
;
87 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(
88 layer_tree_host()->root_layer(),
89 layer_tree_host()->device_viewport_size(),
91 layer_tree_host()->device_scale_factor(),
92 layer_tree_host()->page_scale_factor(),
93 layer_tree_host()->page_scale_layer(),
95 layer_tree_host()->settings().can_use_lcd_text
,
96 can_render_to_separate_surface
,
99 .layer_transforms_should_scale_layer_contents
,
101 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
104 } while (!timer_
.HasTimeLimitExpired());
110 class CalcDrawPropsImplTest
: public LayerTreeHostCommonPerfTest
{
112 void RunCalcDrawProps() {
113 RunTestWithImplSidePainting();
116 virtual void BeginTest() OVERRIDE
{
117 PostSetNeedsCommitToMainThread();
120 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
122 LayerTreeImpl
* active_tree
= host_impl
->active_tree();
125 bool can_render_to_separate_surface
= true;
126 int max_texture_size
= 8096;
127 LayerImplList update_list
;
128 LayerTreeHostCommon::CalcDrawPropsImplInputs
inputs(
129 active_tree
->root_layer(),
130 active_tree
->DrawViewportSize(),
131 host_impl
->DrawTransform(),
132 active_tree
->device_scale_factor(),
133 active_tree
->total_page_scale_factor(),
134 active_tree
->InnerViewportContainerLayer(),
136 host_impl
->settings().can_use_lcd_text
,
137 can_render_to_separate_surface
,
138 host_impl
->settings().layer_transforms_should_scale_layer_contents
,
140 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
143 } while (!timer_
.HasTimeLimitExpired());
149 TEST_F(CalcDrawPropsMainTest
, TenTen
) {
150 SetTestName("10_10_main_thread");
151 ReadTestFile("10_10_layer_tree");
155 TEST_F(CalcDrawPropsMainTest
, HeavyPage
) {
156 SetTestName("heavy_page_main_thread");
157 ReadTestFile("heavy_layer_tree");
161 TEST_F(CalcDrawPropsMainTest
, TouchRegionLight
) {
162 SetTestName("touch_region_light_main_thread");
163 ReadTestFile("touch_region_light");
167 TEST_F(CalcDrawPropsMainTest
, TouchRegionHeavy
) {
168 SetTestName("touch_region_heavy_main_thread");
169 ReadTestFile("touch_region_heavy");
173 TEST_F(CalcDrawPropsImplTest
, TenTen
) {
174 SetTestName("10_10");
175 ReadTestFile("10_10_layer_tree");
179 TEST_F(CalcDrawPropsImplTest
, HeavyPage
) {
180 SetTestName("heavy_page");
181 ReadTestFile("heavy_layer_tree");
185 TEST_F(CalcDrawPropsImplTest
, TouchRegionLight
) {
186 SetTestName("touch_region_light");
187 ReadTestFile("touch_region_light");
191 TEST_F(CalcDrawPropsImplTest
, TouchRegionHeavy
) {
192 SetTestName("touch_region_heavy");
193 ReadTestFile("touch_region_heavy");