[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 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. |
| 4 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7 | #include <memory> |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 8 | #include <sstream> |
| 9 | |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
thestig | 90a0908 | 2014-09-10 07:59:46 | [diff] [blame] | 11 | #include "base/files/file_util.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 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" |
chrishtr | 82b5d950 | 2017-03-20 18:25:33 | [diff] [blame] | 16 | #include "cc/base/lap_timer.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 17 | #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] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 20 | #include "cc/test/layer_tree_json_parser.h" |
| 21 | #include "cc/test/layer_tree_test.h" |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 22 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 23 | #include "cc/trees/layer_tree_impl.h" |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 24 | #include "components/viz/test/paths.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 25 | #include "testing/perf/perf_test.h" |
| 26 | |
| 27 | namespace cc { |
| 28 | namespace { |
| 29 | |
| 30 | static const int kTimeLimitMillis = 2000; |
| 31 | static const int kWarmupRuns = 5; |
| 32 | static const int kTimeCheckInterval = 10; |
| 33 | |
| 34 | class 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; |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 43 | ASSERT_TRUE(PathService::Get(viz::Paths::DIR_TEST_DATA, &test_data_dir)); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 44 | base::FilePath json_file = test_data_dir.AppendASCII(name + ".json"); |
| 45 | ASSERT_TRUE(base::ReadFileToString(json_file, &json_)); |
| 46 | } |
| 47 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 48 | void SetupTree() override { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 49 | gfx::Size viewport = gfx::Size(720, 1038); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 50 | layer_tree_host()->SetViewportSize(viewport); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 51 | scoped_refptr<Layer> root = |
| 52 | ParseTreeFromJson(json_, &content_layer_client_); |
| 53 | ASSERT_TRUE(root.get()); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 54 | layer_tree_host()->SetRootLayer(root); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 55 | content_layer_client_.set_bounds(viewport); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void SetTestName(const std::string& name) { test_name_ = name; } |
| 59 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 60 | void AfterTest() override { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 61 | CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown()."; |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 62 | 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 Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 77 | class CalcDrawPropsTest : public LayerTreeHostCommonPerfTest { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 78 | public: |
Olga Sharonova | e899468 | 2017-11-22 12:05:22 | [diff] [blame] | 79 | void RunCalcDrawProps() { RunTest(CompositorMode::SINGLE_THREADED); } |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 80 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 81 | void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 82 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 83 | void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 84 | timer_.Reset(); |
| 85 | LayerTreeImpl* active_tree = host_impl->active_tree(); |
| 86 | |
| 87 | do { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 88 | int max_texture_size = 8096; |
danakj | dc24211f2 | 2017-05-09 18:58:25 | [diff] [blame] | 89 | DoCalcDrawPropertiesImpl(max_texture_size, active_tree, host_impl); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 90 | |
| 91 | timer_.NextLap(); |
| 92 | } while (!timer_.HasTimeLimitExpired()); |
| 93 | |
| 94 | EndTest(); |
| 95 | } |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 96 | |
danakj | dc24211f2 | 2017-05-09 18:58:25 | [diff] [blame] | 97 | void DoCalcDrawPropertiesImpl(int max_texture_size, |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 98 | LayerTreeImpl* active_tree, |
| 99 | LayerTreeHostImpl* host_impl) { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 100 | RenderSurfaceList update_list; |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 101 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
danakj | 914d301 | 2017-05-05 18:08:34 | [diff] [blame] | 102 | active_tree->root_layer_for_testing(), |
| 103 | active_tree->DeviceViewport().size(), host_impl->DrawTransform(), |
| 104 | active_tree->device_scale_factor(), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 105 | active_tree->current_page_scale_factor(), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 106 | active_tree->InnerViewportContainerLayer(), |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 107 | active_tree->InnerViewportScrollLayer(), |
| 108 | active_tree->OuterViewportScrollLayer(), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 109 | active_tree->elastic_overscroll()->Current(active_tree->IsActiveTree()), |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 110 | active_tree->OverscrollElasticityLayer(), max_texture_size, |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 111 | host_impl->settings().layer_transforms_should_scale_layer_contents, |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 112 | &update_list, active_tree->property_trees()); |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 113 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 114 | } |
| 115 | }; |
| 116 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 117 | TEST_F(CalcDrawPropsTest, TenTen) { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 118 | SetTestName("10_10"); |
| 119 | ReadTestFile("10_10_layer_tree"); |
| 120 | RunCalcDrawProps(); |
| 121 | } |
| 122 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 123 | TEST_F(CalcDrawPropsTest, HeavyPage) { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 124 | SetTestName("heavy_page"); |
| 125 | ReadTestFile("heavy_layer_tree"); |
| 126 | RunCalcDrawProps(); |
| 127 | } |
| 128 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 129 | TEST_F(CalcDrawPropsTest, TouchRegionLight) { |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 130 | SetTestName("touch_region_light"); |
| 131 | ReadTestFile("touch_region_light"); |
| 132 | RunCalcDrawProps(); |
| 133 | } |
| 134 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 135 | TEST_F(CalcDrawPropsTest, TouchRegionHeavy) { |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 136 | SetTestName("touch_region_heavy"); |
| 137 | ReadTestFile("touch_region_heavy"); |
| 138 | RunCalcDrawProps(); |
| 139 | } |
| 140 | |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 141 | } // namespace |
| 142 | } // namespace cc |