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