Add Apps.AppListSearchQueryLength UMA histogram.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common_perftest.cc
blob9a5de06bb0fcde4015aa0565e4b96c5acb0ef8f4
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"
7 #include <sstream>
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/path_service.h"
13 #include "base/strings/string_piece.h"
14 #include "base/threading/thread.h"
15 #include "base/time/time.h"
16 #include "cc/base/scoped_ptr_deque.h"
17 #include "cc/base/scoped_ptr_vector.h"
18 #include "cc/debug/lap_timer.h"
19 #include "cc/layers/layer.h"
20 #include "cc/output/bsp_tree.h"
21 #include "cc/quads/draw_polygon.h"
22 #include "cc/quads/draw_quad.h"
23 #include "cc/test/fake_content_layer_client.h"
24 #include "cc/test/fake_layer_tree_host_client.h"
25 #include "cc/test/layer_tree_json_parser.h"
26 #include "cc/test/layer_tree_test.h"
27 #include "cc/test/paths.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "testing/perf/perf_test.h"
31 namespace cc {
32 namespace {
34 static const int kTimeLimitMillis = 2000;
35 static const int kWarmupRuns = 5;
36 static const int kTimeCheckInterval = 10;
38 class LayerTreeHostCommonPerfTest : public LayerTreeTest {
39 public:
40 LayerTreeHostCommonPerfTest()
41 : timer_(kWarmupRuns,
42 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
43 kTimeCheckInterval) {}
45 void ReadTestFile(const std::string& name) {
46 base::FilePath test_data_dir;
47 ASSERT_TRUE(PathService::Get(CCPaths::DIR_TEST_DATA, &test_data_dir));
48 base::FilePath json_file = test_data_dir.AppendASCII(name + ".json");
49 ASSERT_TRUE(base::ReadFileToString(json_file, &json_));
52 void SetupTree() override {
53 gfx::Size viewport = gfx::Size(720, 1038);
54 layer_tree_host()->SetViewportSize(viewport);
55 scoped_refptr<Layer> root =
56 ParseTreeFromJson(json_, &content_layer_client_);
57 ASSERT_TRUE(root.get());
58 layer_tree_host()->SetRootLayer(root);
61 void SetTestName(const std::string& name) { test_name_ = name; }
63 void AfterTest() override {
64 CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown().";
65 perf_test::PrintResult("calc_draw_props_time",
66 "",
67 test_name_,
68 1000 * timer_.MsPerLap(),
69 "us",
70 true);
73 protected:
74 FakeContentLayerClient content_layer_client_;
75 LapTimer timer_;
76 std::string test_name_;
77 std::string json_;
80 class CalcDrawPropsMainTest : public LayerTreeHostCommonPerfTest {
81 public:
82 void RunCalcDrawProps() { RunTest(false, false, false); }
84 void BeginTest() override {
85 timer_.Reset();
87 do {
88 bool can_render_to_separate_surface = true;
89 bool verify_property_trees = false;
90 int max_texture_size = 8096;
91 RenderSurfaceLayerList update_list;
92 PropertyTrees property_trees;
93 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(
94 layer_tree_host()->root_layer(),
95 layer_tree_host()->device_viewport_size(), gfx::Transform(),
96 layer_tree_host()->device_scale_factor(),
97 layer_tree_host()->page_scale_factor(),
98 layer_tree_host()->overscroll_elasticity_layer(),
99 layer_tree_host()->elastic_overscroll(),
100 layer_tree_host()->page_scale_layer(), max_texture_size,
101 layer_tree_host()->settings().can_use_lcd_text,
102 layer_tree_host()->settings().layers_always_allowed_lcd_text,
103 can_render_to_separate_surface,
104 layer_tree_host()
105 ->settings()
106 .layer_transforms_should_scale_layer_contents,
107 verify_property_trees, &update_list, 0, &property_trees);
108 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
110 timer_.NextLap();
111 } while (!timer_.HasTimeLimitExpired());
113 EndTest();
117 class CalcDrawPropsImplTest : public LayerTreeHostCommonPerfTest {
118 public:
119 void RunCalcDrawProps() {
120 RunTestWithImplSidePainting();
123 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
125 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
126 timer_.Reset();
127 LayerTreeImpl* active_tree = host_impl->active_tree();
129 do {
130 bool can_render_to_separate_surface = true;
131 int max_texture_size = 8096;
132 DoCalcDrawPropertiesImpl(can_render_to_separate_surface,
133 max_texture_size,
134 active_tree,
135 host_impl);
137 timer_.NextLap();
138 } while (!timer_.HasTimeLimitExpired());
140 EndTest();
143 void DoCalcDrawPropertiesImpl(bool can_render_to_separate_surface,
144 int max_texture_size,
145 LayerTreeImpl* active_tree,
146 LayerTreeHostImpl* host_impl) {
147 LayerImplList update_list;
148 PropertyTrees property_trees;
149 bool verify_property_trees = false;
150 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
151 active_tree->root_layer(), active_tree->DrawViewportSize(),
152 host_impl->DrawTransform(), active_tree->device_scale_factor(),
153 active_tree->current_page_scale_factor(),
154 active_tree->InnerViewportContainerLayer(),
155 active_tree->elastic_overscroll()->Current(active_tree->IsActiveTree()),
156 active_tree->overscroll_elasticity_layer(), max_texture_size,
157 host_impl->settings().can_use_lcd_text,
158 host_impl->settings().layers_always_allowed_lcd_text,
159 can_render_to_separate_surface,
160 host_impl->settings().layer_transforms_should_scale_layer_contents,
161 verify_property_trees, &update_list, 0, &property_trees);
162 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
166 class BspTreePerfTest : public CalcDrawPropsImplTest {
167 public:
168 BspTreePerfTest() : num_duplicates_(1) {}
169 void RunSortLayers() { RunTest(false, false, false); }
171 void SetNumberOfDuplicates(int num_duplicates) {
172 num_duplicates_ = num_duplicates;
175 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
177 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
178 LayerTreeImpl* active_tree = host_impl->active_tree();
179 // First build the tree and then we'll start running tests on layersorter
180 // itself
181 bool can_render_to_separate_surface = true;
182 int max_texture_size = 8096;
183 DoCalcDrawPropertiesImpl(can_render_to_separate_surface,
184 max_texture_size,
185 active_tree,
186 host_impl);
188 LayerImplList base_list;
189 BuildLayerImplList(active_tree->root_layer(), &base_list);
191 int polygon_counter = 0;
192 ScopedPtrVector<DrawPolygon> polygon_list;
193 for (LayerImplList::iterator it = base_list.begin(); it != base_list.end();
194 ++it) {
195 DrawPolygon* draw_polygon =
196 new DrawPolygon(NULL,
197 gfx::RectF((*it)->content_bounds()),
198 (*it)->draw_transform(),
199 polygon_counter++);
200 polygon_list.push_back(scoped_ptr<DrawPolygon>(draw_polygon));
203 timer_.Reset();
204 do {
205 ScopedPtrDeque<DrawPolygon> test_list;
206 for (int i = 0; i < num_duplicates_; i++) {
207 for (size_t i = 0; i < polygon_list.size(); i++) {
208 test_list.push_back(polygon_list[i]->CreateCopy());
211 BspTree bsp_tree(&test_list);
212 timer_.NextLap();
213 } while (!timer_.HasTimeLimitExpired());
215 EndTest();
218 void BuildLayerImplList(LayerImpl* layer, LayerImplList* list) {
219 if (layer->Is3dSorted()) {
220 list->push_back(layer);
223 for (size_t i = 0; i < layer->children().size(); i++) {
224 BuildLayerImplList(layer->children()[i], list);
228 private:
229 LayerImplList base_list_;
230 int num_duplicates_;
233 TEST_F(CalcDrawPropsMainTest, TenTen) {
234 SetTestName("10_10_main_thread");
235 ReadTestFile("10_10_layer_tree");
236 RunCalcDrawProps();
239 TEST_F(CalcDrawPropsMainTest, HeavyPage) {
240 SetTestName("heavy_page_main_thread");
241 ReadTestFile("heavy_layer_tree");
242 RunCalcDrawProps();
245 TEST_F(CalcDrawPropsMainTest, TouchRegionLight) {
246 SetTestName("touch_region_light_main_thread");
247 ReadTestFile("touch_region_light");
248 RunCalcDrawProps();
251 TEST_F(CalcDrawPropsMainTest, TouchRegionHeavy) {
252 SetTestName("touch_region_heavy_main_thread");
253 ReadTestFile("touch_region_heavy");
254 RunCalcDrawProps();
257 TEST_F(CalcDrawPropsImplTest, TenTen) {
258 SetTestName("10_10");
259 ReadTestFile("10_10_layer_tree");
260 RunCalcDrawProps();
263 TEST_F(CalcDrawPropsImplTest, HeavyPage) {
264 SetTestName("heavy_page");
265 ReadTestFile("heavy_layer_tree");
266 RunCalcDrawProps();
269 TEST_F(CalcDrawPropsImplTest, TouchRegionLight) {
270 SetTestName("touch_region_light");
271 ReadTestFile("touch_region_light");
272 RunCalcDrawProps();
275 TEST_F(CalcDrawPropsImplTest, TouchRegionHeavy) {
276 SetTestName("touch_region_heavy");
277 ReadTestFile("touch_region_heavy");
278 RunCalcDrawProps();
281 TEST_F(BspTreePerfTest, LayerSorterCubes) {
282 SetTestName("layer_sort_cubes");
283 ReadTestFile("layer_sort_cubes");
284 RunSortLayers();
287 TEST_F(BspTreePerfTest, LayerSorterRubik) {
288 SetTestName("layer_sort_rubik");
289 ReadTestFile("layer_sort_rubik");
290 // TODO(vollick): Remove verify_property_trees setting after
291 // crbug.com/444219 is fixed.
292 bool old_verify_property_trees = verify_property_trees();
293 set_verify_property_trees(false);
294 RunSortLayers();
295 set_verify_property_trees(old_verify_property_trees);
298 TEST_F(BspTreePerfTest, BspTreeCubes) {
299 SetTestName("bsp_tree_cubes");
300 SetNumberOfDuplicates(1);
301 ReadTestFile("layer_sort_cubes");
302 RunSortLayers();
305 TEST_F(BspTreePerfTest, BspTreeRubik) {
306 SetTestName("bsp_tree_rubik");
307 SetNumberOfDuplicates(1);
308 ReadTestFile("layer_sort_rubik");
309 // TODO(vollick): Remove verify_property_trees setting after
310 // crbug.com/444219 is fixed.
311 bool old_verify_property_trees = verify_property_trees();
312 set_verify_property_trees(false);
313 RunSortLayers();
314 set_verify_property_trees(old_verify_property_trees);
317 TEST_F(BspTreePerfTest, BspTreeCubes_2) {
318 SetTestName("bsp_tree_cubes_2");
319 SetNumberOfDuplicates(2);
320 ReadTestFile("layer_sort_cubes");
321 RunSortLayers();
324 TEST_F(BspTreePerfTest, BspTreeCubes_4) {
325 SetTestName("bsp_tree_cubes_4");
326 SetNumberOfDuplicates(4);
327 ReadTestFile("layer_sort_cubes");
328 RunSortLayers();
331 } // namespace
332 } // namespace cc