blob: c1f7908f3bd3aa6787e108f72c87d9bbfae5b3c6 [file] [log] [blame]
[email protected]8428be22013-10-23 07:37:441// 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.
4
avi02a4d172015-12-21 06:14:365#include <stddef.h>
6
danakj60bc3bc2016-04-09 00:24:487#include <memory>
[email protected]8428be22013-10-23 07:37:448#include <sstream>
9
[email protected]8428be22013-10-23 07:37:4410#include "base/files/file_path.h"
thestig90a09082014-09-10 07:59:4611#include "base/files/file_util.h"
[email protected]8428be22013-10-23 07:37:4412#include "base/path_service.h"
13#include "base/strings/string_piece.h"
14#include "base/threading/thread.h"
15#include "base/time/time.h"
chrishtr82b5d9502017-03-20 18:25:3316#include "cc/base/lap_timer.h"
[email protected]8428be22013-10-23 07:37:4417#include "cc/layers/layer.h"
18#include "cc/test/fake_content_layer_client.h"
19#include "cc/test/fake_layer_tree_host_client.h"
[email protected]8428be22013-10-23 07:37:4420#include "cc/test/layer_tree_json_parser.h"
21#include "cc/test/layer_tree_test.h"
danakj60bc3bc2016-04-09 00:24:4822#include "cc/trees/layer_tree_host_common.h"
[email protected]8428be22013-10-23 07:37:4423#include "cc/trees/layer_tree_impl.h"
danakjc391f332017-07-12 20:45:5224#include "components/viz/test/paths.h"
[email protected]8428be22013-10-23 07:37:4425#include "testing/perf/perf_test.h"
26
27namespace cc {
28namespace {
29
30static const int kTimeLimitMillis = 2000;
31static const int kWarmupRuns = 5;
32static const int kTimeCheckInterval = 10;
33
34class LayerTreeHostCommonPerfTest : public LayerTreeTest {
35 public:
36 LayerTreeHostCommonPerfTest()
37 : timer_(kWarmupRuns,
38 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
39 kTimeCheckInterval) {}
40
41 void ReadTestFile(const std::string& name) {
42 base::FilePath test_data_dir;
danakjc391f332017-07-12 20:45:5243 ASSERT_TRUE(PathService::Get(viz::Paths::DIR_TEST_DATA, &test_data_dir));
[email protected]8428be22013-10-23 07:37:4444 base::FilePath json_file = test_data_dir.AppendASCII(name + ".json");
45 ASSERT_TRUE(base::ReadFileToString(json_file, &json_));
46 }
47
dcheng716bedf2014-10-21 09:51:0848 void SetupTree() override {
[email protected]8428be22013-10-23 07:37:4449 gfx::Size viewport = gfx::Size(720, 1038);
khushalsagarb69ba9452017-01-27 22:20:0750 layer_tree_host()->SetViewportSize(viewport);
[email protected]8428be22013-10-23 07:37:4451 scoped_refptr<Layer> root =
52 ParseTreeFromJson(json_, &content_layer_client_);
53 ASSERT_TRUE(root.get());
khushalsagarb69ba9452017-01-27 22:20:0754 layer_tree_host()->SetRootLayer(root);
chrishtr01539b802015-11-24 08:11:3255 content_layer_client_.set_bounds(viewport);
[email protected]8428be22013-10-23 07:37:4456 }
57
58 void SetTestName(const std::string& name) { test_name_ = name; }
59
dcheng716bedf2014-10-21 09:51:0860 void AfterTest() override {
[email protected]8428be22013-10-23 07:37:4461 CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown().";
[email protected]8428be22013-10-23 07:37:4462 perf_test::PrintResult("calc_draw_props_time",
63 "",
64 test_name_,
65 1000 * timer_.MsPerLap(),
66 "us",
67 true);
68 }
69
70 protected:
71 FakeContentLayerClient content_layer_client_;
72 LapTimer timer_;
73 std::string test_name_;
74 std::string json_;
75};
76
Dana Jansensab277762015-06-12 23:52:5577class CalcDrawPropsTest : public LayerTreeHostCommonPerfTest {
[email protected]8428be22013-10-23 07:37:4478 public:
Olga Sharonovae8994682017-11-22 12:05:2279 void RunCalcDrawProps() { RunTest(CompositorMode::SINGLE_THREADED); }
[email protected]8428be22013-10-23 07:37:4480
dcheng716bedf2014-10-21 09:51:0881 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]8428be22013-10-23 07:37:4482
dcheng716bedf2014-10-21 09:51:0883 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
[email protected]8428be22013-10-23 07:37:4484 timer_.Reset();
85 LayerTreeImpl* active_tree = host_impl->active_tree();
86
87 do {
[email protected]8428be22013-10-23 07:37:4488 int max_texture_size = 8096;
danakjdc24211f22017-05-09 18:58:2589 DoCalcDrawPropertiesImpl(max_texture_size, active_tree, host_impl);
[email protected]8428be22013-10-23 07:37:4490
91 timer_.NextLap();
92 } while (!timer_.HasTimeLimitExpired());
93
94 EndTest();
95 }
[email protected]bebb1a82014-06-06 05:03:5496
danakjdc24211f22017-05-09 18:58:2597 void DoCalcDrawPropertiesImpl(int max_texture_size,
[email protected]bebb1a82014-06-06 05:03:5498 LayerTreeImpl* active_tree,
99 LayerTreeHostImpl* host_impl) {
ajumab784ef42017-04-28 23:01:52100 RenderSurfaceList update_list;
[email protected]bebb1a82014-06-06 05:03:54101 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
danakj914d3012017-05-05 18:08:34102 active_tree->root_layer_for_testing(),
103 active_tree->DeviceViewport().size(), host_impl->DrawTransform(),
104 active_tree->device_scale_factor(),
aelias58eec0812014-12-04 01:04:40105 active_tree->current_page_scale_factor(),
ccameronb9aec4502014-12-05 19:31:00106 active_tree->InnerViewportContainerLayer(),
ajuma6b46da22015-06-25 21:53:02107 active_tree->InnerViewportScrollLayer(),
108 active_tree->OuterViewportScrollLayer(),
ccameronb9aec4502014-12-05 19:31:00109 active_tree->elastic_overscroll()->Current(active_tree->IsActiveTree()),
aeliasc26b50b72015-07-14 20:18:25110 active_tree->OverscrollElasticityLayer(), max_texture_size,
[email protected]bebb1a82014-06-06 05:03:54111 host_impl->settings().layer_transforms_should_scale_layer_contents,
ajuma0adb5902016-04-28 16:32:38112 &update_list, active_tree->property_trees());
[email protected]bebb1a82014-06-06 05:03:54113 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
114 }
115};
116
Dana Jansensab277762015-06-12 23:52:55117TEST_F(CalcDrawPropsTest, TenTen) {
[email protected]8428be22013-10-23 07:37:44118 SetTestName("10_10");
119 ReadTestFile("10_10_layer_tree");
120 RunCalcDrawProps();
121}
122
Dana Jansensab277762015-06-12 23:52:55123TEST_F(CalcDrawPropsTest, HeavyPage) {
[email protected]8428be22013-10-23 07:37:44124 SetTestName("heavy_page");
125 ReadTestFile("heavy_layer_tree");
126 RunCalcDrawProps();
127}
128
Dana Jansensab277762015-06-12 23:52:55129TEST_F(CalcDrawPropsTest, TouchRegionLight) {
[email protected]9d161d22013-10-29 20:54:10130 SetTestName("touch_region_light");
131 ReadTestFile("touch_region_light");
132 RunCalcDrawProps();
133}
134
Dana Jansensab277762015-06-12 23:52:55135TEST_F(CalcDrawPropsTest, TouchRegionHeavy) {
[email protected]9d161d22013-10-29 20:54:10136 SetTestName("touch_region_heavy");
137 ReadTestFile("touch_region_heavy");
138 RunCalcDrawProps();
139}
140
[email protected]8428be22013-10-23 07:37:44141} // namespace
142} // namespace cc