OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "cc/layers/content_layer.h" | 11 #include "cc/layers/content_layer.h" |
12 #include "cc/layers/nine_patch_layer.h" | 12 #include "cc/layers/nine_patch_layer.h" |
13 #include "cc/layers/solid_color_layer.h" | 13 #include "cc/layers/solid_color_layer.h" |
14 #include "cc/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
15 #include "cc/test/layer_tree_json_parser.h" | 15 #include "cc/test/layer_tree_json_parser.h" |
16 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
17 #include "cc/test/paths.h" | 17 #include "cc/test/paths.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 static const int kTimeLimitMillis = 2000; | 22 static const int kTimeLimitMillis = 2000; |
23 static const int kWarmupRuns = 5; | 23 static const int kWarmupRuns = 5; |
24 static const int kTimeCheckInterval = 10; | 24 static const int kTimeCheckInterval = 10; |
25 | 25 |
26 class LayerTreeHostPerfTest : public LayerTreeTest { | 26 class LayerTreeHostPerfTest : public LayerTreeTest { |
27 public: | 27 public: |
28 LayerTreeHostPerfTest() | 28 LayerTreeHostPerfTest() |
29 : num_draws_(0) { | 29 : num_draws_(0), |
| 30 full_damage_each_frame_(false) { |
30 fake_content_layer_client_.set_paint_all_opaque(true); | 31 fake_content_layer_client_.set_paint_all_opaque(true); |
31 } | 32 } |
32 | 33 |
33 virtual void BeginTest() OVERRIDE { | 34 virtual void BeginTest() OVERRIDE { |
34 BuildTree(); | 35 BuildTree(); |
35 PostSetNeedsCommitToMainThread(); | 36 PostSetNeedsCommitToMainThread(); |
36 } | 37 } |
37 | 38 |
38 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 39 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
39 ++num_draws_; | 40 ++num_draws_; |
40 if (num_draws_ == kWarmupRuns) | 41 if (num_draws_ == kWarmupRuns) |
41 start_time_ = base::TimeTicks::HighResNow(); | 42 start_time_ = base::TimeTicks::HighResNow(); |
42 | 43 |
43 if (!start_time_.is_null() && (num_draws_ % kTimeCheckInterval) == 0) { | 44 if (!start_time_.is_null() && (num_draws_ % kTimeCheckInterval) == 0) { |
44 base::TimeDelta elapsed = base::TimeTicks::HighResNow() - start_time_; | 45 base::TimeDelta elapsed = base::TimeTicks::HighResNow() - start_time_; |
45 if (elapsed >= base::TimeDelta::FromMilliseconds(kTimeLimitMillis)) { | 46 if (elapsed >= base::TimeDelta::FromMilliseconds(kTimeLimitMillis)) { |
46 elapsed_ = elapsed; | 47 elapsed_ = elapsed; |
47 EndTest(); | 48 EndTest(); |
48 return; | 49 return; |
49 } | 50 } |
50 } | 51 } |
51 impl->setNeedsRedraw(); | 52 impl->setNeedsRedraw(); |
| 53 if (full_damage_each_frame_) |
| 54 impl->SetFullRootLayerDamage(); |
52 } | 55 } |
53 | 56 |
54 virtual void BuildTree() {} | 57 virtual void BuildTree() {} |
55 | 58 |
56 virtual void AfterTest() OVERRIDE { | 59 virtual void AfterTest() OVERRIDE { |
57 // Format matches chrome/test/perf/perf_test.h:PrintResult | 60 // Format matches chrome/test/perf/perf_test.h:PrintResult |
58 printf("*RESULT %s: frames= %.2f runs/s\n", | 61 printf("*RESULT %s: frames= %.2f runs/s\n", |
59 test_name_.c_str(), | 62 test_name_.c_str(), |
60 num_draws_ / elapsed_.InSecondsF()); | 63 num_draws_ / elapsed_.InSecondsF()); |
61 } | 64 } |
62 | 65 |
63 protected: | 66 protected: |
64 base::TimeTicks start_time_; | 67 base::TimeTicks start_time_; |
65 int num_draws_; | 68 int num_draws_; |
66 std::string test_name_; | 69 std::string test_name_; |
67 base::TimeDelta elapsed_; | 70 base::TimeDelta elapsed_; |
68 FakeContentLayerClient fake_content_layer_client_; | 71 FakeContentLayerClient fake_content_layer_client_; |
| 72 bool full_damage_each_frame_; |
69 }; | 73 }; |
70 | 74 |
71 | 75 |
72 class LayerTreeHostPerfTestJsonReader : public LayerTreeHostPerfTest { | 76 class LayerTreeHostPerfTestJsonReader : public LayerTreeHostPerfTest { |
73 public: | 77 public: |
74 LayerTreeHostPerfTestJsonReader() | 78 LayerTreeHostPerfTestJsonReader() |
75 : LayerTreeHostPerfTest() { | 79 : LayerTreeHostPerfTest() { |
76 } | 80 } |
77 | 81 |
78 void ReadTestFile(std::string name) { | 82 void ReadTestFile(std::string name) { |
(...skipping 16 matching lines...) Expand all Loading... |
95 private: | 99 private: |
96 std::string json_; | 100 std::string json_; |
97 }; | 101 }; |
98 | 102 |
99 // Simulates a tab switcher scene with two stacks of 10 tabs each. | 103 // Simulates a tab switcher scene with two stacks of 10 tabs each. |
100 TEST_F(LayerTreeHostPerfTestJsonReader, TenTenSingleThread) { | 104 TEST_F(LayerTreeHostPerfTestJsonReader, TenTenSingleThread) { |
101 ReadTestFile("10_10_layer_tree"); | 105 ReadTestFile("10_10_layer_tree"); |
102 RunTest(false); | 106 RunTest(false); |
103 } | 107 } |
104 | 108 |
| 109 // Simulates a tab switcher scene with two stacks of 10 tabs each. |
| 110 TEST_F(LayerTreeHostPerfTestJsonReader, |
| 111 TenTenSingleThread_FullDamageEachFrame) { |
| 112 full_damage_each_frame_ = true; |
| 113 ReadTestFile("10_10_layer_tree"); |
| 114 RunTest(false); |
| 115 } |
| 116 |
105 // Simulates main-thread scrolling on each frame. | 117 // Simulates main-thread scrolling on each frame. |
106 class ScrollingLayerTreePerfTest : public LayerTreeHostPerfTestJsonReader { | 118 class ScrollingLayerTreePerfTest : public LayerTreeHostPerfTestJsonReader { |
107 public: | 119 public: |
108 ScrollingLayerTreePerfTest() | 120 ScrollingLayerTreePerfTest() |
109 : LayerTreeHostPerfTestJsonReader() { | 121 : LayerTreeHostPerfTestJsonReader() { |
110 } | 122 } |
111 | 123 |
112 virtual void BuildTree() OVERRIDE { | 124 virtual void BuildTree() OVERRIDE { |
113 LayerTreeHostPerfTestJsonReader::BuildTree(); | 125 LayerTreeHostPerfTestJsonReader::BuildTree(); |
114 scrollable_ = layer_tree_host()->root_layer()->children()[1]; | 126 scrollable_ = layer_tree_host()->root_layer()->children()[1]; |
115 ASSERT_TRUE(scrollable_); | 127 ASSERT_TRUE(scrollable_); |
116 } | 128 } |
117 | 129 |
118 virtual void Layout() OVERRIDE { | 130 virtual void Layout() OVERRIDE { |
119 static const gfx::Vector2d delta = gfx::Vector2d(0, 10); | 131 static const gfx::Vector2d delta = gfx::Vector2d(0, 10); |
120 scrollable_->SetScrollOffset(scrollable_->scroll_offset() + delta); | 132 scrollable_->SetScrollOffset(scrollable_->scroll_offset() + delta); |
121 } | 133 } |
122 | 134 |
123 private: | 135 private: |
124 scoped_refptr<Layer> scrollable_; | 136 scoped_refptr<Layer> scrollable_; |
125 }; | 137 }; |
126 | 138 |
127 TEST_F(ScrollingLayerTreePerfTest, LongScrollablePage) { | 139 TEST_F(ScrollingLayerTreePerfTest, LongScrollablePage) { |
128 ReadTestFile("long_scrollable_page"); | 140 ReadTestFile("long_scrollable_page"); |
129 RunTest(false); | 141 RunTest(false); |
130 } | 142 } |
131 | 143 |
132 } // namespace | 144 } // namespace |
133 } // namespace cc | 145 } // namespace cc |
OLD | NEW |