blob: 4a2724fd15d39f6fc86daad803f40e0d9b90ba16 [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
vmpstr36d6abff2015-11-14 01:37:117#include <deque>
danakj60bc3bc2016-04-09 00:24:488#include <memory>
[email protected]8428be22013-10-23 07:37:449#include <sstream>
10
[email protected]8428be22013-10-23 07:37:4411#include "base/files/file_path.h"
thestig90a09082014-09-10 07:59:4612#include "base/files/file_util.h"
[email protected]8428be22013-10-23 07:37:4413#include "base/path_service.h"
14#include "base/strings/string_piece.h"
15#include "base/threading/thread.h"
16#include "base/time/time.h"
chrishtr82b5d9502017-03-20 18:25:3317#include "cc/base/lap_timer.h"
[email protected]8428be22013-10-23 07:37:4418#include "cc/layers/layer.h"
19#include "cc/test/fake_content_layer_client.h"
20#include "cc/test/fake_layer_tree_host_client.h"
[email protected]8428be22013-10-23 07:37:4421#include "cc/test/layer_tree_json_parser.h"
22#include "cc/test/layer_tree_test.h"
23#include "cc/test/paths.h"
danakj60bc3bc2016-04-09 00:24:4824#include "cc/trees/layer_tree_host_common.h"
[email protected]8428be22013-10-23 07:37:4425#include "cc/trees/layer_tree_impl.h"
26#include "testing/perf/perf_test.h"
27
28namespace cc {
29namespace {
30
31static const int kTimeLimitMillis = 2000;
32static const int kWarmupRuns = 5;
33static const int kTimeCheckInterval = 10;
34
35class LayerTreeHostCommonPerfTest : public LayerTreeTest {
36 public:
37 LayerTreeHostCommonPerfTest()
38 : timer_(kWarmupRuns,
39 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
40 kTimeCheckInterval) {}
41
42 void ReadTestFile(const std::string& name) {
43 base::FilePath test_data_dir;
[email protected]e51444a2013-12-10 23:05:0144 ASSERT_TRUE(PathService::Get(CCPaths::DIR_TEST_DATA, &test_data_dir));
[email protected]8428be22013-10-23 07:37:4445 base::FilePath json_file = test_data_dir.AppendASCII(name + ".json");
46 ASSERT_TRUE(base::ReadFileToString(json_file, &json_));
47 }
48
dcheng716bedf2014-10-21 09:51:0849 void SetupTree() override {
[email protected]8428be22013-10-23 07:37:4450 gfx::Size viewport = gfx::Size(720, 1038);
khushalsagarb69ba9452017-01-27 22:20:0751 layer_tree_host()->SetViewportSize(viewport);
[email protected]8428be22013-10-23 07:37:4452 scoped_refptr<Layer> root =
53 ParseTreeFromJson(json_, &content_layer_client_);
54 ASSERT_TRUE(root.get());
khushalsagarb69ba9452017-01-27 22:20:0755 layer_tree_host()->SetRootLayer(root);
chrishtr01539b802015-11-24 08:11:3256 content_layer_client_.set_bounds(viewport);
[email protected]8428be22013-10-23 07:37:4457 }
58
59 void SetTestName(const std::string& name) { test_name_ = name; }
60
dcheng716bedf2014-10-21 09:51:0861 void AfterTest() override {
[email protected]8428be22013-10-23 07:37:4462 CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown().";
[email protected]8428be22013-10-23 07:37:4463 perf_test::PrintResult("calc_draw_props_time",
64 "",
65 test_name_,
66 1000 * timer_.MsPerLap(),
67 "us",
68 true);
69 }
70
71 protected:
72 FakeContentLayerClient content_layer_client_;
73 LapTimer timer_;
74 std::string test_name_;
75 std::string json_;
76};
77
Dana Jansensab277762015-06-12 23:52:5578class CalcDrawPropsTest : public LayerTreeHostCommonPerfTest {
[email protected]8428be22013-10-23 07:37:4479 public:
danakj0943a112016-08-11 00:33:4680 void RunCalcDrawProps() { RunTest(CompositorMode::SINGLE_THREADED); }
[email protected]8428be22013-10-23 07:37:4481
dcheng716bedf2014-10-21 09:51:0882 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
[email protected]8428be22013-10-23 07:37:4483
dcheng716bedf2014-10-21 09:51:0884 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
[email protected]8428be22013-10-23 07:37:4485 timer_.Reset();
86 LayerTreeImpl* active_tree = host_impl->active_tree();
87
88 do {
89 bool can_render_to_separate_surface = true;
90 int max_texture_size = 8096;
[email protected]bebb1a82014-06-06 05:03:5491 DoCalcDrawPropertiesImpl(can_render_to_separate_surface,
92 max_texture_size,
93 active_tree,
94 host_impl);
[email protected]8428be22013-10-23 07:37:4495
96 timer_.NextLap();
97 } while (!timer_.HasTimeLimitExpired());
98
99 EndTest();
100 }
[email protected]bebb1a82014-06-06 05:03:54101
102 void DoCalcDrawPropertiesImpl(bool can_render_to_separate_surface,
103 int max_texture_size,
104 LayerTreeImpl* active_tree,
105 LayerTreeHostImpl* host_impl) {
106 LayerImplList update_list;
107 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
jaydasikabf1875a2016-06-28 03:39:59108 active_tree->root_layer_for_testing(), active_tree->DrawViewportSize(),
danakj3f76ace2014-11-18 16:56:00109 host_impl->DrawTransform(), active_tree->device_scale_factor(),
aelias58eec0812014-12-04 01:04:40110 active_tree->current_page_scale_factor(),
ccameronb9aec4502014-12-05 19:31:00111 active_tree->InnerViewportContainerLayer(),
ajuma6b46da22015-06-25 21:53:02112 active_tree->InnerViewportScrollLayer(),
113 active_tree->OuterViewportScrollLayer(),
ccameronb9aec4502014-12-05 19:31:00114 active_tree->elastic_overscroll()->Current(active_tree->IsActiveTree()),
aeliasc26b50b72015-07-14 20:18:25115 active_tree->OverscrollElasticityLayer(), max_texture_size,
[email protected]bebb1a82014-06-06 05:03:54116 can_render_to_separate_surface,
117 host_impl->settings().layer_transforms_should_scale_layer_contents,
weiliangc365a6fe2016-05-12 19:32:31118 false, // do not verify_clip_tree_calculation for perf tests
jaydasika5237db02016-09-20 01:34:30119 false, // do not verify_visible_rect_calculation for perf tests
ajuma0adb5902016-04-28 16:32:38120 &update_list, active_tree->property_trees());
[email protected]bebb1a82014-06-06 05:03:54121 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
122 }
123};
124
Dana Jansensab277762015-06-12 23:52:55125TEST_F(CalcDrawPropsTest, TenTen) {
[email protected]8428be22013-10-23 07:37:44126 SetTestName("10_10");
127 ReadTestFile("10_10_layer_tree");
128 RunCalcDrawProps();
129}
130
Dana Jansensab277762015-06-12 23:52:55131TEST_F(CalcDrawPropsTest, HeavyPage) {
[email protected]8428be22013-10-23 07:37:44132 SetTestName("heavy_page");
133 ReadTestFile("heavy_layer_tree");
134 RunCalcDrawProps();
135}
136
Dana Jansensab277762015-06-12 23:52:55137TEST_F(CalcDrawPropsTest, TouchRegionLight) {
[email protected]9d161d22013-10-29 20:54:10138 SetTestName("touch_region_light");
139 ReadTestFile("touch_region_light");
140 RunCalcDrawProps();
141}
142
Dana Jansensab277762015-06-12 23:52:55143TEST_F(CalcDrawPropsTest, TouchRegionHeavy) {
[email protected]9d161d22013-10-29 20:54:10144 SetTestName("touch_region_heavy");
145 ReadTestFile("touch_region_heavy");
146 RunCalcDrawProps();
147}
148
[email protected]8428be22013-10-23 07:37:44149} // namespace
150} // namespace cc