[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 1 | // Copyright 2012 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 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host.h" |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 6 | |
[email protected] | 3393fa9 | 2013-10-18 03:37:52 | [diff] [blame] | 7 | #include <sstream> |
| 8 | |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 9 | #include "base/file_util.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 11 | #include "base/path_service.h" |
[email protected] | daf079a | 2013-04-17 21:42:40 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 13 | #include "base/time/time.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 14 | #include "cc/layers/content_layer.h" |
| 15 | #include "cc/layers/nine_patch_layer.h" |
| 16 | #include "cc/layers/solid_color_layer.h" |
[email protected] | 3393fa9 | 2013-10-18 03:37:52 | [diff] [blame] | 17 | #include "cc/layers/texture_layer.h" |
| 18 | #include "cc/resources/texture_mailbox.h" |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 19 | #include "cc/test/fake_content_layer_client.h" |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 20 | #include "cc/test/lap_timer.h" |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 21 | #include "cc/test/layer_tree_json_parser.h" |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 22 | #include "cc/test/layer_tree_test.h" |
[email protected] | 1b901a3 | 2012-12-07 08:52:03 | [diff] [blame] | 23 | #include "cc/test/paths.h" |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 24 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 25 | #include "testing/perf/perf_test.h" |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 26 | |
| 27 | namespace cc { |
| 28 | namespace { |
| 29 | |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 30 | static const int kTimeLimitMillis = 2000; |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 31 | static const int kWarmupRuns = 5; |
| 32 | static const int kTimeCheckInterval = 10; |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 33 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 34 | class LayerTreeHostPerfTest : public LayerTreeTest { |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 35 | public: |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 36 | LayerTreeHostPerfTest() |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 37 | : draw_timer_(kWarmupRuns, |
| 38 | base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 39 | kTimeCheckInterval), |
| 40 | commit_timer_(0, base::TimeDelta(), 1), |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 41 | full_damage_each_frame_(false), |
| 42 | animation_driven_drawing_(false), |
| 43 | measure_commit_cost_(false) { |
[email protected] | 2384c8a | 2013-03-21 08:35:04 | [diff] [blame] | 44 | fake_content_layer_client_.set_paint_all_opaque(true); |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | 1673d6e | 2013-10-28 21:51:17 | [diff] [blame^] | 47 | virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 48 | settings->throttle_frame_production = false; |
| 49 | } |
| 50 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 51 | virtual void BeginTest() OVERRIDE { |
| 52 | BuildTree(); |
| 53 | PostSetNeedsCommitToMainThread(); |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 54 | } |
| 55 | |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 56 | virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { |
| 57 | if (animation_driven_drawing_ && !TestEnded()) |
| 58 | layer_tree_host()->SetNeedsAnimate(); |
| 59 | } |
| 60 | |
| 61 | virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 62 | if (measure_commit_cost_) |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 63 | commit_timer_.Start(); |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 67 | if (measure_commit_cost_ && draw_timer_.IsWarmedUp()) { |
| 68 | commit_timer_.NextLap(); |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 69 | } |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 72 | virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 73 | if (TestEnded()) { |
| 74 | return; |
| 75 | } |
| 76 | draw_timer_.NextLap(); |
| 77 | if (draw_timer_.HasTimeLimitExpired()) { |
| 78 | EndTest(); |
| 79 | return; |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 80 | } |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 81 | if (!animation_driven_drawing_) |
| 82 | impl->SetNeedsRedraw(); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 83 | if (full_damage_each_frame_) |
| 84 | impl->SetFullRootLayerDamage(); |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 87 | virtual void BuildTree() {} |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 88 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 89 | virtual void AfterTest() OVERRIDE { |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 90 | CHECK(!test_name_.empty()) << "Must SetTestName() before AfterTest()."; |
| 91 | perf_test::PrintResult("layer_tree_host_frame_count", "", test_name_, |
[email protected] | 01aba0d | 2013-09-14 05:04:18 | [diff] [blame] | 92 | draw_timer_.NumLaps(), "frame_count", true); |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 93 | perf_test::PrintResult("layer_tree_host_frame_time", "", test_name_, |
| 94 | 1000 * draw_timer_.MsPerLap(), "us", true); |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 95 | if (measure_commit_cost_) { |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 96 | perf_test::PrintResult("layer_tree_host_commit_count", "", test_name_, |
[email protected] | 01aba0d | 2013-09-14 05:04:18 | [diff] [blame] | 97 | commit_timer_.NumLaps(), "commit_count", true); |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 98 | perf_test::PrintResult("layer_tree_host_commit_time", "", test_name_, |
| 99 | 1000 * commit_timer_.MsPerLap(), "us", true); |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 100 | } |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 103 | protected: |
[email protected] | 542ce1a | 2013-08-29 14:25:44 | [diff] [blame] | 104 | LapTimer draw_timer_; |
| 105 | LapTimer commit_timer_; |
| 106 | |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 107 | std::string test_name_; |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 108 | FakeContentLayerClient fake_content_layer_client_; |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 109 | bool full_damage_each_frame_; |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 110 | bool animation_driven_drawing_; |
| 111 | |
| 112 | bool measure_commit_cost_; |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 113 | }; |
| 114 | |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 115 | |
| 116 | class LayerTreeHostPerfTestJsonReader : public LayerTreeHostPerfTest { |
| 117 | public: |
| 118 | LayerTreeHostPerfTestJsonReader() |
| 119 | : LayerTreeHostPerfTest() { |
| 120 | } |
| 121 | |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 122 | void SetTestName(const std::string& name) { |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 123 | test_name_ = name; |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void ReadTestFile(const std::string& name) { |
[email protected] | 6d4b67a | 2013-02-10 04:49:30 | [diff] [blame] | 127 | base::FilePath test_data_dir; |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 128 | ASSERT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)); |
[email protected] | 6d4b67a | 2013-02-10 04:49:30 | [diff] [blame] | 129 | base::FilePath json_file = test_data_dir.AppendASCII(name + ".json"); |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 130 | ASSERT_TRUE(base::ReadFileToString(json_file, &json_)); |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 133 | virtual void BuildTree() OVERRIDE { |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 134 | gfx::Size viewport = gfx::Size(720, 1038); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 135 | layer_tree_host()->SetViewportSize(viewport); |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 136 | scoped_refptr<Layer> root = ParseTreeFromJson(json_, |
| 137 | &fake_content_layer_client_); |
| 138 | ASSERT_TRUE(root.get()); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 139 | layer_tree_host()->SetRootLayer(root); |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | private: |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 143 | std::string json_; |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 144 | }; |
| 145 | |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 146 | // Simulates a tab switcher scene with two stacks of 10 tabs each. |
| 147 | TEST_F(LayerTreeHostPerfTestJsonReader, TenTenSingleThread) { |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 148 | SetTestName("10_10_single_thread"); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 149 | ReadTestFile("10_10_layer_tree"); |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame] | 150 | RunTest(false, false, false); |
[email protected] | 91cd748 | 2012-11-30 05:51:45 | [diff] [blame] | 151 | } |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 152 | |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 153 | TEST_F(LayerTreeHostPerfTestJsonReader, TenTenThreadedImplSide) { |
| 154 | SetTestName("10_10_threaded_impl_side"); |
| 155 | ReadTestFile("10_10_layer_tree"); |
| 156 | RunTestWithImplSidePainting(); |
| 157 | } |
| 158 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 159 | // Simulates a tab switcher scene with two stacks of 10 tabs each. |
| 160 | TEST_F(LayerTreeHostPerfTestJsonReader, |
| 161 | TenTenSingleThread_FullDamageEachFrame) { |
| 162 | full_damage_each_frame_ = true; |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 163 | SetTestName("10_10_single_thread_full_damage_each_frame"); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 164 | ReadTestFile("10_10_layer_tree"); |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame] | 165 | RunTest(false, false, false); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 168 | TEST_F(LayerTreeHostPerfTestJsonReader, |
| 169 | TenTenThreadedImplSide_FullDamageEachFrame) { |
| 170 | full_damage_each_frame_ = true; |
| 171 | SetTestName("10_10_threaded_impl_side_full_damage_each_frame"); |
| 172 | ReadTestFile("10_10_layer_tree"); |
| 173 | RunTestWithImplSidePainting(); |
| 174 | } |
| 175 | |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 176 | // Invalidates a leaf layer in the tree on the main thread after every commit. |
| 177 | class LayerTreeHostPerfTestLeafInvalidates |
| 178 | : public LayerTreeHostPerfTestJsonReader { |
| 179 | public: |
| 180 | virtual void BuildTree() OVERRIDE { |
| 181 | LayerTreeHostPerfTestJsonReader::BuildTree(); |
| 182 | |
| 183 | // Find a leaf layer. |
| 184 | for (layer_to_invalidate_ = layer_tree_host()->root_layer(); |
| 185 | layer_to_invalidate_->children().size(); |
| 186 | layer_to_invalidate_ = layer_to_invalidate_->children()[0]) {} |
| 187 | } |
| 188 | |
| 189 | virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 190 | if (TestEnded()) |
| 191 | return; |
| 192 | |
| 193 | static bool flip = true; |
| 194 | layer_to_invalidate_->SetOpacity(flip ? 1.f : 0.5f); |
| 195 | flip = !flip; |
| 196 | } |
| 197 | |
| 198 | protected: |
| 199 | Layer* layer_to_invalidate_; |
| 200 | }; |
| 201 | |
| 202 | // Simulates a tab switcher scene with two stacks of 10 tabs each. Invalidate a |
| 203 | // property on a leaf layer in the tree every commit. |
| 204 | TEST_F(LayerTreeHostPerfTestLeafInvalidates, TenTenSingleThread) { |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 205 | SetTestName("10_10_single_thread_leaf_invalidates"); |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 206 | ReadTestFile("10_10_layer_tree"); |
| 207 | RunTest(false, false, false); |
| 208 | } |
| 209 | |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 210 | TEST_F(LayerTreeHostPerfTestLeafInvalidates, TenTenThreadedImplSide) { |
| 211 | SetTestName("10_10_threaded_impl_side_leaf_invalidates"); |
| 212 | ReadTestFile("10_10_layer_tree"); |
| 213 | RunTestWithImplSidePainting(); |
| 214 | } |
| 215 | |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 216 | // Simulates main-thread scrolling on each frame. |
| 217 | class ScrollingLayerTreePerfTest : public LayerTreeHostPerfTestJsonReader { |
| 218 | public: |
| 219 | ScrollingLayerTreePerfTest() |
| 220 | : LayerTreeHostPerfTestJsonReader() { |
| 221 | } |
| 222 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 223 | virtual void BuildTree() OVERRIDE { |
| 224 | LayerTreeHostPerfTestJsonReader::BuildTree(); |
| 225 | scrollable_ = layer_tree_host()->root_layer()->children()[1]; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 226 | ASSERT_TRUE(scrollable_.get()); |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 229 | virtual void Layout() OVERRIDE { |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 230 | static const gfx::Vector2d delta = gfx::Vector2d(0, 10); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 231 | scrollable_->SetScrollOffset(scrollable_->scroll_offset() + delta); |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | private: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 235 | scoped_refptr<Layer> scrollable_; |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 236 | }; |
| 237 | |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 238 | TEST_F(ScrollingLayerTreePerfTest, LongScrollablePageSingleThread) { |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 239 | SetTestName("long_scrollable_page"); |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 240 | ReadTestFile("long_scrollable_page"); |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame] | 241 | RunTest(false, false, false); |
[email protected] | f8fef2bd | 2013-02-04 23:39:22 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 244 | TEST_F(ScrollingLayerTreePerfTest, LongScrollablePageThreadedImplSide) { |
| 245 | SetTestName("long_scrollable_page_threaded_impl_side"); |
| 246 | ReadTestFile("long_scrollable_page"); |
| 247 | RunTestWithImplSidePainting(); |
| 248 | } |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 249 | |
[email protected] | 3393fa9 | 2013-10-18 03:37:52 | [diff] [blame] | 250 | static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} |
| 251 | |
| 252 | // Simulates main-thread scrolling on each frame. |
| 253 | class BrowserCompositorInvalidateLayerTreePerfTest |
| 254 | : public LayerTreeHostPerfTestJsonReader { |
| 255 | public: |
| 256 | BrowserCompositorInvalidateLayerTreePerfTest() |
| 257 | : next_sync_point_(1) { |
| 258 | } |
| 259 | |
| 260 | virtual void BuildTree() OVERRIDE { |
| 261 | LayerTreeHostPerfTestJsonReader::BuildTree(); |
| 262 | tab_contents_ = |
| 263 | static_cast<TextureLayer*>( |
| 264 | layer_tree_host()->root_layer()->children()[0]-> |
| 265 | children()[0]-> |
| 266 | children()[0]-> |
| 267 | children()[0].get()); |
| 268 | ASSERT_TRUE(tab_contents_.get()); |
| 269 | } |
| 270 | |
| 271 | virtual void Layout() OVERRIDE { |
| 272 | gpu::Mailbox gpu_mailbox; |
| 273 | std::ostringstream name_stream; |
| 274 | name_stream << "name" << next_sync_point_; |
| 275 | const char* name = name_stream.str().c_str(); |
| 276 | memcpy(gpu_mailbox.name, name, strlen(name) + 1); |
| 277 | scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 278 | base::Bind(&EmptyReleaseCallback)); |
| 279 | TextureMailbox mailbox(gpu_mailbox, next_sync_point_); |
| 280 | next_sync_point_++; |
| 281 | |
| 282 | tab_contents_->SetTextureMailbox(mailbox, callback.Pass()); |
| 283 | } |
| 284 | |
| 285 | private: |
| 286 | scoped_refptr<TextureLayer> tab_contents_; |
| 287 | unsigned next_sync_point_; |
| 288 | }; |
| 289 | |
| 290 | TEST_F(BrowserCompositorInvalidateLayerTreePerfTest, DenseBrowserUI) { |
| 291 | SetTestName("dense_layer_tree"); |
| 292 | ReadTestFile("dense_layer_tree"); |
| 293 | RunTestWithImplSidePainting(); |
| 294 | } |
| 295 | |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 296 | // Simulates a page with several large, transformed and animated layers. |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 297 | TEST_F(LayerTreeHostPerfTestJsonReader, HeavyPageThreadedImplSide) { |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 298 | animation_driven_drawing_ = true; |
| 299 | measure_commit_cost_ = true; |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 300 | SetTestName("heavy_page"); |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 301 | ReadTestFile("heavy_layer_tree"); |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame] | 302 | RunTestWithImplSidePainting(); |
[email protected] | a49d0f8a | 2013-05-09 23:26:19 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | c0f7a7f | 2013-10-15 21:33:56 | [diff] [blame] | 305 | class PageScaleImplSidePaintingPerfTest |
| 306 | : public LayerTreeHostPerfTestJsonReader { |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 307 | public: |
| 308 | PageScaleImplSidePaintingPerfTest() |
| 309 | : max_scale_(16.f), min_scale_(1.f / max_scale_) {} |
| 310 | |
| 311 | virtual void SetupTree() OVERRIDE { |
| 312 | layer_tree_host()->SetPageScaleFactorAndLimits(1.f, min_scale_, max_scale_); |
| 313 | } |
| 314 | |
| 315 | virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, |
| 316 | float scale_delta) OVERRIDE { |
| 317 | float page_scale_factor = layer_tree_host()->page_scale_factor(); |
| 318 | page_scale_factor *= scale_delta; |
| 319 | layer_tree_host()->SetPageScaleFactorAndLimits( |
| 320 | page_scale_factor, min_scale_, max_scale_); |
| 321 | } |
| 322 | |
| 323 | virtual void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 324 | base::TimeTicks monotonic_time) OVERRIDE { |
| 325 | if (!host_impl->pinch_gesture_active()) { |
| 326 | host_impl->PinchGestureBegin(); |
| 327 | start_time_ = monotonic_time; |
| 328 | } |
| 329 | gfx::Point anchor(200, 200); |
| 330 | |
| 331 | float seconds = (monotonic_time - start_time_).InSecondsF(); |
| 332 | |
| 333 | // Every half second, zoom from min scale to max scale. |
| 334 | float interval = 0.5f; |
| 335 | |
| 336 | // Start time in the middle of the interval when zoom = 1. |
| 337 | seconds += interval / 2.f; |
| 338 | |
| 339 | // Stack two ranges together to go up from min to max and down from |
| 340 | // max to min in the next so as not to have a zoom discrepancy. |
| 341 | float time_in_two_intervals = fmod(seconds, 2.f * interval) / interval; |
| 342 | |
| 343 | // Map everything to go from min to max between 0 and 1. |
| 344 | float time_in_one_interval = |
| 345 | time_in_two_intervals > 1.f ? 2.f - time_in_two_intervals |
| 346 | : time_in_two_intervals; |
| 347 | // Normalize time to -1..1. |
| 348 | float normalized = 2.f * time_in_one_interval - 1.f; |
[email protected] | 81d20544 | 2013-07-29 21:42:03 | [diff] [blame] | 349 | float scale_factor = std::abs(normalized) * (max_scale_ - 1.f) + 1.f; |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 350 | float total_scale = normalized < 0.f ? 1.f / scale_factor : scale_factor; |
| 351 | |
| 352 | float desired_delta = |
| 353 | total_scale / host_impl->active_tree()->total_page_scale_factor(); |
| 354 | host_impl->PinchGestureUpdate(desired_delta, anchor); |
| 355 | } |
| 356 | |
| 357 | private: |
| 358 | float max_scale_; |
| 359 | float min_scale_; |
| 360 | base::TimeTicks start_time_; |
| 361 | }; |
| 362 | |
[email protected] | 0983f065 | 2013-10-14 20:25:19 | [diff] [blame] | 363 | TEST_F(PageScaleImplSidePaintingPerfTest, HeavyPage) { |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 364 | measure_commit_cost_ = true; |
[email protected] | ab1555a | 2013-09-04 02:16:16 | [diff] [blame] | 365 | SetTestName("heavy_page_page_scale"); |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 366 | ReadTestFile("heavy_layer_tree"); |
| 367 | RunTestWithImplSidePainting(); |
| 368 | } |
| 369 | |
[email protected] | ed9b489a | 2012-11-28 22:01:40 | [diff] [blame] | 370 | } // namespace |
| 371 | } // namespace cc |