Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_perftest.cc
blob1f98a687df496a5dc2205fed8ac13e3bb051c7cd
1 // Copyright 2014 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.
5 #include "cc/layers/picture_layer_impl.h"
7 #include "cc/debug/lap_timer.h"
8 #include "cc/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/fake_picture_layer_impl.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/trees/layer_tree_impl.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
19 namespace cc {
20 namespace {
22 static const int kTimeLimitMillis = 2000;
23 static const int kWarmupRuns = 5;
24 static const int kTimeCheckInterval = 10;
26 void AddTiling(float scale,
27 FakePictureLayerImpl* layer,
28 std::vector<Tile*>* all_tiles) {
29 PictureLayerTiling* tiling = layer->AddTiling(scale);
31 tiling->CreateAllTilesForTesting();
32 std::vector<Tile*> tiling_tiles = tiling->AllTilesForTesting();
33 std::copy(
34 tiling_tiles.begin(), tiling_tiles.end(), std::back_inserter(*all_tiles));
37 class PictureLayerImplPerfTest : public testing::Test {
38 public:
39 PictureLayerImplPerfTest()
40 : proxy_(base::MessageLoopProxy::current()),
41 host_impl_(ImplSidePaintingSettings(),
42 &proxy_,
43 &shared_bitmap_manager_),
44 timer_(kWarmupRuns,
45 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
46 kTimeCheckInterval) {}
48 void SetUp() override {
49 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
52 void SetupPendingTree(const gfx::Size& layer_bounds,
53 const gfx::Size& tile_size) {
54 scoped_refptr<FakePicturePileImpl> pile =
55 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
56 host_impl_.CreatePendingTree();
57 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
58 pending_tree->DetachLayerTree();
60 scoped_ptr<FakePictureLayerImpl> pending_layer =
61 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 7, pile);
62 pending_layer->SetDrawsContent(true);
63 pending_tree->SetRootLayer(pending_layer.Pass());
65 pending_layer_ = static_cast<FakePictureLayerImpl*>(
66 host_impl_.pending_tree()->LayerById(7));
67 pending_layer_->DoPostCommitInitializationIfNeeded();
70 void RunRasterIteratorConstructAndIterateTest(
71 const std::string& test_name,
72 int num_tiles,
73 const gfx::Size& viewport_size) {
74 host_impl_.SetViewportSize(viewport_size);
75 host_impl_.pending_tree()->UpdateDrawProperties();
77 timer_.Reset();
78 do {
79 int count = num_tiles;
80 PictureLayerImpl::LayerRasterTileIterator it(pending_layer_, false);
81 while (count--) {
82 ASSERT_TRUE(it) << "count: " << count;
83 ASSERT_TRUE(*it != nullptr) << "count: " << count;
84 ++it;
86 timer_.NextLap();
87 } while (!timer_.HasTimeLimitExpired());
89 perf_test::PrintResult("layer_raster_tile_iterator_construct_and_iterate",
90 "",
91 test_name,
92 timer_.LapsPerSecond(),
93 "runs/s",
94 true);
97 void RunRasterIteratorConstructTest(const std::string& test_name,
98 const gfx::Rect& viewport) {
99 host_impl_.SetViewportSize(viewport.size());
100 pending_layer_->SetScrollOffset(
101 gfx::ScrollOffset(viewport.x(), viewport.y()));
102 host_impl_.pending_tree()->UpdateDrawProperties();
104 timer_.Reset();
105 do {
106 PictureLayerImpl::LayerRasterTileIterator it(pending_layer_, false);
107 timer_.NextLap();
108 } while (!timer_.HasTimeLimitExpired());
110 perf_test::PrintResult("layer_raster_tile_iterator_construct",
112 test_name,
113 timer_.LapsPerSecond(),
114 "runs/s",
115 true);
118 void RunEvictionIteratorConstructAndIterateTest(
119 const std::string& test_name,
120 int num_tiles,
121 const gfx::Size& viewport_size) {
122 host_impl_.SetViewportSize(viewport_size);
123 host_impl_.pending_tree()->UpdateDrawProperties();
125 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
126 SMOOTHNESS_TAKES_PRIORITY,
127 NEW_CONTENT_TAKES_PRIORITY};
128 int priority_count = 0;
129 timer_.Reset();
130 do {
131 int count = num_tiles;
132 PictureLayerImpl::LayerEvictionTileIterator it(
133 pending_layer_, priorities[priority_count]);
134 while (count--) {
135 ASSERT_TRUE(it) << "count: " << count;
136 ASSERT_TRUE(*it != nullptr) << "count: " << count;
137 ++it;
139 priority_count = (priority_count + 1) % arraysize(priorities);
140 timer_.NextLap();
141 } while (!timer_.HasTimeLimitExpired());
143 perf_test::PrintResult("layer_eviction_tile_iterator_construct_and_iterate",
145 test_name,
146 timer_.LapsPerSecond(),
147 "runs/s",
148 true);
151 void RunEvictionIteratorConstructTest(const std::string& test_name,
152 const gfx::Rect& viewport) {
153 host_impl_.SetViewportSize(viewport.size());
154 pending_layer_->SetScrollOffset(
155 gfx::ScrollOffset(viewport.x(), viewport.y()));
156 host_impl_.pending_tree()->UpdateDrawProperties();
158 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
159 SMOOTHNESS_TAKES_PRIORITY,
160 NEW_CONTENT_TAKES_PRIORITY};
161 int priority_count = 0;
162 timer_.Reset();
163 do {
164 PictureLayerImpl::LayerEvictionTileIterator it(
165 pending_layer_, priorities[priority_count]);
166 priority_count = (priority_count + 1) % arraysize(priorities);
167 timer_.NextLap();
168 } while (!timer_.HasTimeLimitExpired());
170 perf_test::PrintResult("layer_eviction_tile_iterator_construct",
172 test_name,
173 timer_.LapsPerSecond(),
174 "runs/s",
175 true);
178 protected:
179 TestSharedBitmapManager shared_bitmap_manager_;
180 FakeImplProxy proxy_;
181 FakeLayerTreeHostImpl host_impl_;
182 FakePictureLayerImpl* pending_layer_;
183 LapTimer timer_;
185 private:
186 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
189 TEST_F(PictureLayerImplPerfTest, LayerRasterTileIteratorConstructAndIterate) {
190 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
192 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
194 pending_layer_->AddTiling(low_res_factor);
195 pending_layer_->AddTiling(0.3f);
196 pending_layer_->AddTiling(0.7f);
197 pending_layer_->AddTiling(1.0f);
198 pending_layer_->AddTiling(2.0f);
200 RunRasterIteratorConstructAndIterateTest(
201 "32_100x100", 32, gfx::Size(100, 100));
202 RunRasterIteratorConstructAndIterateTest(
203 "32_500x500", 32, gfx::Size(500, 500));
204 RunRasterIteratorConstructAndIterateTest(
205 "64_100x100", 64, gfx::Size(100, 100));
206 RunRasterIteratorConstructAndIterateTest(
207 "64_500x500", 64, gfx::Size(500, 500));
210 TEST_F(PictureLayerImplPerfTest, LayerRasterTileIteratorConstruct) {
211 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
213 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
215 pending_layer_->AddTiling(low_res_factor);
216 pending_layer_->AddTiling(0.3f);
217 pending_layer_->AddTiling(0.7f);
218 pending_layer_->AddTiling(1.0f);
219 pending_layer_->AddTiling(2.0f);
221 RunRasterIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
222 RunRasterIteratorConstructTest("5000_0_100x100",
223 gfx::Rect(5000, 0, 100, 100));
224 RunRasterIteratorConstructTest("9999_0_100x100",
225 gfx::Rect(9999, 0, 100, 100));
228 TEST_F(PictureLayerImplPerfTest, LayerEvictionTileIteratorConstructAndIterate) {
229 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
231 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
233 std::vector<Tile*> all_tiles;
234 AddTiling(low_res_factor, pending_layer_, &all_tiles);
235 AddTiling(0.3f, pending_layer_, &all_tiles);
236 AddTiling(0.7f, pending_layer_, &all_tiles);
237 AddTiling(1.0f, pending_layer_, &all_tiles);
238 AddTiling(2.0f, pending_layer_, &all_tiles);
240 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
241 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
243 RunEvictionIteratorConstructAndIterateTest(
244 "32_100x100", 32, gfx::Size(100, 100));
245 RunEvictionIteratorConstructAndIterateTest(
246 "32_500x500", 32, gfx::Size(500, 500));
247 RunEvictionIteratorConstructAndIterateTest(
248 "64_100x100", 64, gfx::Size(100, 100));
249 RunEvictionIteratorConstructAndIterateTest(
250 "64_500x500", 64, gfx::Size(500, 500));
253 TEST_F(PictureLayerImplPerfTest, LayerEvictionTileIteratorConstruct) {
254 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
256 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
258 std::vector<Tile*> all_tiles;
259 AddTiling(low_res_factor, pending_layer_, &all_tiles);
260 AddTiling(0.3f, pending_layer_, &all_tiles);
261 AddTiling(0.7f, pending_layer_, &all_tiles);
262 AddTiling(1.0f, pending_layer_, &all_tiles);
263 AddTiling(2.0f, pending_layer_, &all_tiles);
265 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
266 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
268 RunEvictionIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
269 RunEvictionIteratorConstructTest("5000_0_100x100",
270 gfx::Rect(5000, 0, 100, 100));
271 RunEvictionIteratorConstructTest("9999_0_100x100",
272 gfx::Rect(9999, 0, 100, 100));
275 } // namespace
276 } // namespace cc