[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 | |
| 5 | #include "cc/trees/layer_tree_host_common.h" |
| 6 | |
| 7 | #include <sstream> |
| 8 | |
| 9 | #include "base/file_util.h" |
| 10 | #include "base/files/file_path.h" |
| 11 | #include "base/path_service.h" |
| 12 | #include "base/strings/string_piece.h" |
| 13 | #include "base/threading/thread.h" |
| 14 | #include "base/time/time.h" |
[email protected] | 29d39a4 | 2014-05-13 19:40:58 | [diff] [blame^] | 15 | #include "cc/debug/lap_timer.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 16 | #include "cc/layers/layer.h" |
| 17 | #include "cc/test/fake_content_layer_client.h" |
| 18 | #include "cc/test/fake_layer_tree_host_client.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 19 | #include "cc/test/layer_tree_json_parser.h" |
| 20 | #include "cc/test/layer_tree_test.h" |
| 21 | #include "cc/test/paths.h" |
| 22 | #include "cc/trees/layer_tree_impl.h" |
| 23 | #include "testing/perf/perf_test.h" |
| 24 | |
| 25 | namespace cc { |
| 26 | namespace { |
| 27 | |
| 28 | static const int kTimeLimitMillis = 2000; |
| 29 | static const int kWarmupRuns = 5; |
| 30 | static const int kTimeCheckInterval = 10; |
| 31 | |
| 32 | class LayerTreeHostCommonPerfTest : public LayerTreeTest { |
| 33 | public: |
| 34 | LayerTreeHostCommonPerfTest() |
| 35 | : timer_(kWarmupRuns, |
| 36 | base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 37 | kTimeCheckInterval) {} |
| 38 | |
| 39 | void ReadTestFile(const std::string& name) { |
| 40 | base::FilePath test_data_dir; |
[email protected] | e51444a | 2013-12-10 23:05:01 | [diff] [blame] | 41 | ASSERT_TRUE(PathService::Get(CCPaths::DIR_TEST_DATA, &test_data_dir)); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 42 | base::FilePath json_file = test_data_dir.AppendASCII(name + ".json"); |
| 43 | ASSERT_TRUE(base::ReadFileToString(json_file, &json_)); |
| 44 | } |
| 45 | |
| 46 | virtual void SetupTree() OVERRIDE { |
| 47 | gfx::Size viewport = gfx::Size(720, 1038); |
| 48 | layer_tree_host()->SetViewportSize(viewport); |
| 49 | scoped_refptr<Layer> root = |
| 50 | ParseTreeFromJson(json_, &content_layer_client_); |
| 51 | ASSERT_TRUE(root.get()); |
| 52 | layer_tree_host()->SetRootLayer(root); |
| 53 | } |
| 54 | |
| 55 | void SetTestName(const std::string& name) { test_name_ = name; } |
| 56 | |
| 57 | virtual void AfterTest() OVERRIDE { |
| 58 | CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown()."; |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 59 | perf_test::PrintResult("calc_draw_props_time", |
| 60 | "", |
| 61 | test_name_, |
| 62 | 1000 * timer_.MsPerLap(), |
| 63 | "us", |
| 64 | true); |
| 65 | } |
| 66 | |
| 67 | protected: |
| 68 | FakeContentLayerClient content_layer_client_; |
| 69 | LapTimer timer_; |
| 70 | std::string test_name_; |
| 71 | std::string json_; |
| 72 | }; |
| 73 | |
| 74 | class CalcDrawPropsMainTest : public LayerTreeHostCommonPerfTest { |
| 75 | public: |
| 76 | void RunCalcDrawProps() { |
| 77 | RunTest(false, false, false); |
| 78 | } |
| 79 | |
| 80 | virtual void BeginTest() OVERRIDE { |
| 81 | timer_.Reset(); |
| 82 | |
| 83 | do { |
| 84 | bool can_render_to_separate_surface = true; |
| 85 | int max_texture_size = 8096; |
| 86 | RenderSurfaceLayerList update_list; |
| 87 | LayerTreeHostCommon::CalcDrawPropsMainInputs inputs( |
| 88 | layer_tree_host()->root_layer(), |
| 89 | layer_tree_host()->device_viewport_size(), |
| 90 | gfx::Transform(), |
| 91 | layer_tree_host()->device_scale_factor(), |
| 92 | layer_tree_host()->page_scale_factor(), |
| 93 | layer_tree_host()->page_scale_layer(), |
| 94 | max_texture_size, |
| 95 | layer_tree_host()->settings().can_use_lcd_text, |
| 96 | can_render_to_separate_surface, |
| 97 | layer_tree_host() |
| 98 | ->settings() |
| 99 | .layer_transforms_should_scale_layer_contents, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 100 | &update_list, |
| 101 | 0); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 102 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 103 | |
| 104 | timer_.NextLap(); |
| 105 | } while (!timer_.HasTimeLimitExpired()); |
| 106 | |
| 107 | EndTest(); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | class CalcDrawPropsImplTest : public LayerTreeHostCommonPerfTest { |
| 112 | public: |
| 113 | void RunCalcDrawProps() { |
| 114 | RunTestWithImplSidePainting(); |
| 115 | } |
| 116 | |
| 117 | virtual void BeginTest() OVERRIDE { |
| 118 | PostSetNeedsCommitToMainThread(); |
| 119 | } |
| 120 | |
| 121 | virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 122 | timer_.Reset(); |
| 123 | LayerTreeImpl* active_tree = host_impl->active_tree(); |
| 124 | |
| 125 | do { |
| 126 | bool can_render_to_separate_surface = true; |
| 127 | int max_texture_size = 8096; |
| 128 | LayerImplList update_list; |
| 129 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
| 130 | active_tree->root_layer(), |
| 131 | active_tree->DrawViewportSize(), |
| 132 | host_impl->DrawTransform(), |
| 133 | active_tree->device_scale_factor(), |
| 134 | active_tree->total_page_scale_factor(), |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 135 | active_tree->InnerViewportContainerLayer(), |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 136 | max_texture_size, |
| 137 | host_impl->settings().can_use_lcd_text, |
| 138 | can_render_to_separate_surface, |
| 139 | host_impl->settings().layer_transforms_should_scale_layer_contents, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 140 | &update_list, |
| 141 | 0); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 142 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 143 | |
| 144 | timer_.NextLap(); |
| 145 | } while (!timer_.HasTimeLimitExpired()); |
| 146 | |
| 147 | EndTest(); |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | TEST_F(CalcDrawPropsMainTest, TenTen) { |
[email protected] | 27efb2b | 2014-02-10 19:27:16 | [diff] [blame] | 152 | SetTestName("10_10_main_thread"); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 153 | ReadTestFile("10_10_layer_tree"); |
| 154 | RunCalcDrawProps(); |
| 155 | } |
| 156 | |
| 157 | TEST_F(CalcDrawPropsMainTest, HeavyPage) { |
[email protected] | 27efb2b | 2014-02-10 19:27:16 | [diff] [blame] | 158 | SetTestName("heavy_page_main_thread"); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 159 | ReadTestFile("heavy_layer_tree"); |
| 160 | RunCalcDrawProps(); |
| 161 | } |
| 162 | |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 163 | TEST_F(CalcDrawPropsMainTest, TouchRegionLight) { |
[email protected] | 27efb2b | 2014-02-10 19:27:16 | [diff] [blame] | 164 | SetTestName("touch_region_light_main_thread"); |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 165 | ReadTestFile("touch_region_light"); |
| 166 | RunCalcDrawProps(); |
| 167 | } |
| 168 | |
| 169 | TEST_F(CalcDrawPropsMainTest, TouchRegionHeavy) { |
[email protected] | 27efb2b | 2014-02-10 19:27:16 | [diff] [blame] | 170 | SetTestName("touch_region_heavy_main_thread"); |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 171 | ReadTestFile("touch_region_heavy"); |
| 172 | RunCalcDrawProps(); |
| 173 | } |
| 174 | |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 175 | TEST_F(CalcDrawPropsImplTest, TenTen) { |
| 176 | SetTestName("10_10"); |
| 177 | ReadTestFile("10_10_layer_tree"); |
| 178 | RunCalcDrawProps(); |
| 179 | } |
| 180 | |
| 181 | TEST_F(CalcDrawPropsImplTest, HeavyPage) { |
| 182 | SetTestName("heavy_page"); |
| 183 | ReadTestFile("heavy_layer_tree"); |
| 184 | RunCalcDrawProps(); |
| 185 | } |
| 186 | |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 187 | TEST_F(CalcDrawPropsImplTest, TouchRegionLight) { |
| 188 | SetTestName("touch_region_light"); |
| 189 | ReadTestFile("touch_region_light"); |
| 190 | RunCalcDrawProps(); |
| 191 | } |
| 192 | |
| 193 | TEST_F(CalcDrawPropsImplTest, TouchRegionHeavy) { |
| 194 | SetTestName("touch_region_heavy"); |
| 195 | ReadTestFile("touch_region_heavy"); |
| 196 | RunCalcDrawProps(); |
| 197 | } |
| 198 | |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 199 | } // namespace |
| 200 | } // namespace cc |