[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" |
[email protected] | 29d39a4 | 2014-05-13 19:40:58 | [diff] [blame] | 17 | #include "cc/debug/lap_timer.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 18 | #include "cc/layers/layer.h" |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 19 | #include "cc/output/bsp_tree.h" |
| 20 | #include "cc/quads/draw_polygon.h" |
| 21 | #include "cc/quads/draw_quad.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 22 | #include "cc/test/fake_content_layer_client.h" |
| 23 | #include "cc/test/fake_layer_tree_host_client.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 24 | #include "cc/test/layer_tree_json_parser.h" |
| 25 | #include "cc/test/layer_tree_test.h" |
| 26 | #include "cc/test/paths.h" |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame^] | 27 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 28 | #include "cc/trees/layer_tree_impl.h" |
| 29 | #include "testing/perf/perf_test.h" |
| 30 | |
| 31 | namespace cc { |
| 32 | namespace { |
| 33 | |
| 34 | static const int kTimeLimitMillis = 2000; |
| 35 | static const int kWarmupRuns = 5; |
| 36 | static const int kTimeCheckInterval = 10; |
| 37 | |
| 38 | class LayerTreeHostCommonPerfTest : public LayerTreeTest { |
| 39 | public: |
| 40 | LayerTreeHostCommonPerfTest() |
| 41 | : timer_(kWarmupRuns, |
| 42 | base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 43 | kTimeCheckInterval) {} |
| 44 | |
| 45 | void ReadTestFile(const std::string& name) { |
| 46 | base::FilePath test_data_dir; |
[email protected] | e51444a | 2013-12-10 23:05:01 | [diff] [blame] | 47 | ASSERT_TRUE(PathService::Get(CCPaths::DIR_TEST_DATA, &test_data_dir)); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 48 | base::FilePath json_file = test_data_dir.AppendASCII(name + ".json"); |
| 49 | ASSERT_TRUE(base::ReadFileToString(json_file, &json_)); |
| 50 | } |
| 51 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 52 | void SetupTree() override { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 53 | gfx::Size viewport = gfx::Size(720, 1038); |
| 54 | layer_tree_host()->SetViewportSize(viewport); |
| 55 | scoped_refptr<Layer> root = |
| 56 | ParseTreeFromJson(json_, &content_layer_client_); |
| 57 | ASSERT_TRUE(root.get()); |
| 58 | layer_tree_host()->SetRootLayer(root); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 59 | content_layer_client_.set_bounds(viewport); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void SetTestName(const std::string& name) { test_name_ = name; } |
| 63 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 64 | void AfterTest() override { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 65 | CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown()."; |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 66 | perf_test::PrintResult("calc_draw_props_time", |
| 67 | "", |
| 68 | test_name_, |
| 69 | 1000 * timer_.MsPerLap(), |
| 70 | "us", |
| 71 | true); |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | FakeContentLayerClient content_layer_client_; |
| 76 | LapTimer timer_; |
| 77 | std::string test_name_; |
| 78 | std::string json_; |
| 79 | }; |
| 80 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 81 | class CalcDrawPropsTest : public LayerTreeHostCommonPerfTest { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 82 | public: |
khushalsagar | e0a38d4 | 2016-01-29 01:15:06 | [diff] [blame] | 83 | void RunCalcDrawProps() { RunTest(CompositorMode::SINGLE_THREADED, false); } |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 84 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 85 | void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 86 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 87 | void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 88 | timer_.Reset(); |
| 89 | LayerTreeImpl* active_tree = host_impl->active_tree(); |
| 90 | |
| 91 | do { |
| 92 | bool can_render_to_separate_surface = true; |
| 93 | int max_texture_size = 8096; |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 94 | DoCalcDrawPropertiesImpl(can_render_to_separate_surface, |
| 95 | max_texture_size, |
| 96 | active_tree, |
| 97 | host_impl); |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 98 | |
| 99 | timer_.NextLap(); |
| 100 | } while (!timer_.HasTimeLimitExpired()); |
| 101 | |
| 102 | EndTest(); |
| 103 | } |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 104 | |
| 105 | void DoCalcDrawPropertiesImpl(bool can_render_to_separate_surface, |
| 106 | int max_texture_size, |
| 107 | LayerTreeImpl* active_tree, |
| 108 | LayerTreeHostImpl* host_impl) { |
| 109 | LayerImplList update_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 110 | active_tree->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 111 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 112 | active_tree->root_layer(), active_tree->DrawViewportSize(), |
| 113 | host_impl->DrawTransform(), active_tree->device_scale_factor(), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 114 | active_tree->current_page_scale_factor(), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 115 | active_tree->InnerViewportContainerLayer(), |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 116 | active_tree->InnerViewportScrollLayer(), |
| 117 | active_tree->OuterViewportScrollLayer(), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 118 | active_tree->elastic_overscroll()->Current(active_tree->IsActiveTree()), |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 119 | active_tree->OverscrollElasticityLayer(), max_texture_size, |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 120 | host_impl->settings().can_use_lcd_text, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 121 | host_impl->settings().layers_always_allowed_lcd_text, |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 122 | can_render_to_separate_surface, |
| 123 | host_impl->settings().layer_transforms_should_scale_layer_contents, |
weiliangc | 15346d2c | 2016-02-19 01:38:49 | [diff] [blame] | 124 | &update_list, active_tree->current_render_surface_list_id(), |
weiliangc | f429c53 | 2016-02-17 21:28:23 | [diff] [blame] | 125 | active_tree->property_trees()); |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 126 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 127 | } |
| 128 | }; |
| 129 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 130 | class BspTreePerfTest : public CalcDrawPropsTest { |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 131 | public: |
awoloszyn | fae52bf | 2015-03-24 18:19:21 | [diff] [blame] | 132 | BspTreePerfTest() : num_duplicates_(1) {} |
khushalsagar | e0a38d4 | 2016-01-29 01:15:06 | [diff] [blame] | 133 | void RunSortLayers() { RunTest(CompositorMode::SINGLE_THREADED, false); } |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 134 | |
| 135 | void SetNumberOfDuplicates(int num_duplicates) { |
| 136 | num_duplicates_ = num_duplicates; |
| 137 | } |
| 138 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 139 | void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 140 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 141 | void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 142 | LayerTreeImpl* active_tree = host_impl->active_tree(); |
| 143 | // First build the tree and then we'll start running tests on layersorter |
| 144 | // itself |
| 145 | bool can_render_to_separate_surface = true; |
| 146 | int max_texture_size = 8096; |
| 147 | DoCalcDrawPropertiesImpl(can_render_to_separate_surface, |
| 148 | max_texture_size, |
| 149 | active_tree, |
| 150 | host_impl); |
| 151 | |
| 152 | LayerImplList base_list; |
| 153 | BuildLayerImplList(active_tree->root_layer(), &base_list); |
| 154 | |
| 155 | int polygon_counter = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame^] | 156 | std::vector<std::unique_ptr<DrawPolygon>> polygon_list; |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 157 | for (LayerImplList::iterator it = base_list.begin(); it != base_list.end(); |
| 158 | ++it) { |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 159 | DrawPolygon* draw_polygon = new DrawPolygon( |
| 160 | NULL, gfx::RectF(gfx::SizeF((*it)->bounds())), |
| 161 | (*it)->draw_properties().target_space_transform, polygon_counter++); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame^] | 162 | polygon_list.push_back(std::unique_ptr<DrawPolygon>(draw_polygon)); |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | timer_.Reset(); |
| 166 | do { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame^] | 167 | std::deque<std::unique_ptr<DrawPolygon>> test_list; |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 168 | for (int i = 0; i < num_duplicates_; i++) { |
| 169 | for (size_t i = 0; i < polygon_list.size(); i++) { |
| 170 | test_list.push_back(polygon_list[i]->CreateCopy()); |
| 171 | } |
| 172 | } |
| 173 | BspTree bsp_tree(&test_list); |
| 174 | timer_.NextLap(); |
| 175 | } while (!timer_.HasTimeLimitExpired()); |
| 176 | |
| 177 | EndTest(); |
| 178 | } |
| 179 | |
awoloszyn | 3d8eb1d | 2015-03-12 14:38:32 | [diff] [blame] | 180 | void BuildLayerImplList(LayerImpl* layer, LayerImplList* list) { |
weiliangc | a1a2b00 | 2016-02-17 19:39:36 | [diff] [blame] | 181 | if (layer->Is3dSorted() && !layer->bounds().IsEmpty()) { |
awoloszyn | 3d8eb1d | 2015-03-12 14:38:32 | [diff] [blame] | 182 | list->push_back(layer); |
| 183 | } |
| 184 | |
| 185 | for (size_t i = 0; i < layer->children().size(); i++) { |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 186 | BuildLayerImplList(layer->children()[i], list); |
awoloszyn | 3d8eb1d | 2015-03-12 14:38:32 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 190 | private: |
awoloszyn | 3d8eb1d | 2015-03-12 14:38:32 | [diff] [blame] | 191 | LayerImplList base_list_; |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 192 | int num_duplicates_; |
| 193 | }; |
| 194 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 195 | TEST_F(CalcDrawPropsTest, TenTen) { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 196 | SetTestName("10_10"); |
| 197 | ReadTestFile("10_10_layer_tree"); |
| 198 | RunCalcDrawProps(); |
| 199 | } |
| 200 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 201 | TEST_F(CalcDrawPropsTest, HeavyPage) { |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 202 | SetTestName("heavy_page"); |
| 203 | ReadTestFile("heavy_layer_tree"); |
| 204 | RunCalcDrawProps(); |
| 205 | } |
| 206 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 207 | TEST_F(CalcDrawPropsTest, TouchRegionLight) { |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 208 | SetTestName("touch_region_light"); |
| 209 | ReadTestFile("touch_region_light"); |
| 210 | RunCalcDrawProps(); |
| 211 | } |
| 212 | |
Dana Jansens | ab27776 | 2015-06-12 23:52:55 | [diff] [blame] | 213 | TEST_F(CalcDrawPropsTest, TouchRegionHeavy) { |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 214 | SetTestName("touch_region_heavy"); |
| 215 | ReadTestFile("touch_region_heavy"); |
| 216 | RunCalcDrawProps(); |
| 217 | } |
| 218 | |
awoloszyn | 3d8eb1d | 2015-03-12 14:38:32 | [diff] [blame] | 219 | TEST_F(BspTreePerfTest, LayerSorterCubes) { |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 220 | SetTestName("layer_sort_cubes"); |
| 221 | ReadTestFile("layer_sort_cubes"); |
| 222 | RunSortLayers(); |
| 223 | } |
| 224 | |
awoloszyn | 3d8eb1d | 2015-03-12 14:38:32 | [diff] [blame] | 225 | TEST_F(BspTreePerfTest, LayerSorterRubik) { |
[email protected] | bebb1a8 | 2014-06-06 05:03:54 | [diff] [blame] | 226 | SetTestName("layer_sort_rubik"); |
| 227 | ReadTestFile("layer_sort_rubik"); |
| 228 | RunSortLayers(); |
| 229 | } |
| 230 | |
[email protected] | 2a021fb7b | 2014-08-02 07:53:49 | [diff] [blame] | 231 | TEST_F(BspTreePerfTest, BspTreeCubes) { |
| 232 | SetTestName("bsp_tree_cubes"); |
| 233 | SetNumberOfDuplicates(1); |
| 234 | ReadTestFile("layer_sort_cubes"); |
| 235 | RunSortLayers(); |
| 236 | } |
| 237 | |
| 238 | TEST_F(BspTreePerfTest, BspTreeRubik) { |
| 239 | SetTestName("bsp_tree_rubik"); |
| 240 | SetNumberOfDuplicates(1); |
| 241 | ReadTestFile("layer_sort_rubik"); |
| 242 | RunSortLayers(); |
| 243 | } |
| 244 | |
| 245 | TEST_F(BspTreePerfTest, BspTreeCubes_2) { |
| 246 | SetTestName("bsp_tree_cubes_2"); |
| 247 | SetNumberOfDuplicates(2); |
| 248 | ReadTestFile("layer_sort_cubes"); |
| 249 | RunSortLayers(); |
| 250 | } |
| 251 | |
| 252 | TEST_F(BspTreePerfTest, BspTreeCubes_4) { |
| 253 | SetTestName("bsp_tree_cubes_4"); |
| 254 | SetNumberOfDuplicates(4); |
| 255 | ReadTestFile("layer_sort_cubes"); |
| 256 | RunSortLayers(); |
| 257 | } |
| 258 | |
[email protected] | 8428be2 | 2013-10-23 07:37:44 | [diff] [blame] | 259 | } // namespace |
| 260 | } // namespace cc |