Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_perftest.cc
blobea73cb235e2064b6634750c226968d777c97efe8
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/resources/tiling_set_raster_queue_all.h"
9 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host_impl.h"
11 #include "cc/test/fake_output_surface.h"
12 #include "cc/test/fake_picture_layer_impl.h"
13 #include "cc/test/fake_picture_pile_impl.h"
14 #include "cc/test/impl_side_painting_settings.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/layer_tree_impl.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/perf/perf_test.h"
20 namespace cc {
21 namespace {
23 static const int kTimeLimitMillis = 2000;
24 static const int kWarmupRuns = 5;
25 static const int kTimeCheckInterval = 10;
27 void AddTiling(float scale,
28 FakePictureLayerImpl* layer,
29 std::vector<Tile*>* all_tiles) {
30 PictureLayerTiling* tiling = layer->AddTiling(scale);
32 tiling->CreateAllTilesForTesting();
33 std::vector<Tile*> tiling_tiles = tiling->AllTilesForTesting();
34 std::copy(
35 tiling_tiles.begin(), tiling_tiles.end(), std::back_inserter(*all_tiles));
38 class PictureLayerImplPerfTest : public testing::Test {
39 public:
40 PictureLayerImplPerfTest()
41 : proxy_(base::MessageLoopProxy::current()),
42 host_impl_(ImplSidePaintingSettings(),
43 &proxy_,
44 &shared_bitmap_manager_),
45 timer_(kWarmupRuns,
46 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
47 kTimeCheckInterval) {}
49 void SetUp() override {
50 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
53 void SetupPendingTree(const gfx::Size& layer_bounds,
54 const gfx::Size& tile_size) {
55 scoped_refptr<FakePicturePileImpl> pile =
56 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
57 host_impl_.CreatePendingTree();
58 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
59 pending_tree->DetachLayerTree();
61 scoped_ptr<FakePictureLayerImpl> pending_layer =
62 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 7, pile);
63 pending_layer->SetDrawsContent(true);
64 pending_layer->SetHasRenderSurface(true);
65 pending_tree->SetRootLayer(pending_layer.Pass());
67 pending_layer_ = static_cast<FakePictureLayerImpl*>(
68 host_impl_.pending_tree()->LayerById(7));
71 void RunRasterQueueConstructAndIterateTest(const std::string& test_name,
72 int num_tiles,
73 const gfx::Size& viewport_size) {
74 host_impl_.SetViewportSize(viewport_size);
75 bool update_lcd_text = false;
76 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
78 timer_.Reset();
79 do {
80 int count = num_tiles;
81 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
82 pending_layer_->picture_layer_tiling_set(), false));
83 while (count--) {
84 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
85 ASSERT_TRUE(queue->Top() != nullptr) << "count: " << count;
86 queue->Pop();
88 timer_.NextLap();
89 } while (!timer_.HasTimeLimitExpired());
91 perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
92 test_name, timer_.LapsPerSecond(), "runs/s", true);
95 void RunRasterQueueConstructTest(const std::string& test_name,
96 const gfx::Rect& viewport) {
97 host_impl_.SetViewportSize(viewport.size());
98 pending_layer_->PushScrollOffsetFromMainThread(
99 gfx::ScrollOffset(viewport.x(), viewport.y()));
100 bool update_lcd_text = false;
101 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
103 timer_.Reset();
104 do {
105 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
106 pending_layer_->picture_layer_tiling_set(), false));
107 timer_.NextLap();
108 } while (!timer_.HasTimeLimitExpired());
110 perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name,
111 timer_.LapsPerSecond(), "runs/s", true);
114 void RunEvictionQueueConstructAndIterateTest(
115 const std::string& test_name,
116 int num_tiles,
117 const gfx::Size& viewport_size) {
118 host_impl_.SetViewportSize(viewport_size);
119 bool update_lcd_text = false;
120 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
122 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
123 SMOOTHNESS_TAKES_PRIORITY,
124 NEW_CONTENT_TAKES_PRIORITY};
125 int priority_count = 0;
126 timer_.Reset();
127 do {
128 int count = num_tiles;
129 scoped_ptr<TilingSetEvictionQueue> queue(
130 new TilingSetEvictionQueue(pending_layer_->picture_layer_tiling_set(),
131 priorities[priority_count], false));
132 while (count--) {
133 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
134 ASSERT_TRUE(queue->Top() != nullptr) << "count: " << count;
135 queue->Pop();
137 priority_count = (priority_count + 1) % arraysize(priorities);
138 timer_.NextLap();
139 } while (!timer_.HasTimeLimitExpired());
141 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
142 "", test_name, timer_.LapsPerSecond(), "runs/s",
143 true);
146 void RunEvictionQueueConstructTest(const std::string& test_name,
147 const gfx::Rect& viewport) {
148 host_impl_.SetViewportSize(viewport.size());
149 pending_layer_->PushScrollOffsetFromMainThread(
150 gfx::ScrollOffset(viewport.x(), viewport.y()));
151 bool update_lcd_text = false;
152 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
154 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
155 SMOOTHNESS_TAKES_PRIORITY,
156 NEW_CONTENT_TAKES_PRIORITY};
157 int priority_count = 0;
158 timer_.Reset();
159 do {
160 scoped_ptr<TilingSetEvictionQueue> queue(
161 new TilingSetEvictionQueue(pending_layer_->picture_layer_tiling_set(),
162 priorities[priority_count], false));
163 priority_count = (priority_count + 1) % arraysize(priorities);
164 timer_.NextLap();
165 } while (!timer_.HasTimeLimitExpired());
167 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name,
168 timer_.LapsPerSecond(), "runs/s", true);
171 protected:
172 TestSharedBitmapManager shared_bitmap_manager_;
173 FakeImplProxy proxy_;
174 FakeLayerTreeHostImpl host_impl_;
175 FakePictureLayerImpl* pending_layer_;
176 LapTimer timer_;
178 private:
179 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
182 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstructAndIterate) {
183 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
185 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
187 pending_layer_->AddTiling(low_res_factor);
188 pending_layer_->AddTiling(0.3f);
189 pending_layer_->AddTiling(0.7f);
190 pending_layer_->AddTiling(1.0f);
191 pending_layer_->AddTiling(2.0f);
193 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
194 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
195 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
196 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
199 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstruct) {
200 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
202 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
204 pending_layer_->AddTiling(low_res_factor);
205 pending_layer_->AddTiling(0.3f);
206 pending_layer_->AddTiling(0.7f);
207 pending_layer_->AddTiling(1.0f);
208 pending_layer_->AddTiling(2.0f);
210 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
211 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
212 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
215 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstructAndIterate) {
216 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
218 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
220 std::vector<Tile*> all_tiles;
221 AddTiling(low_res_factor, pending_layer_, &all_tiles);
222 AddTiling(0.3f, pending_layer_, &all_tiles);
223 AddTiling(0.7f, pending_layer_, &all_tiles);
224 AddTiling(1.0f, pending_layer_, &all_tiles);
225 AddTiling(2.0f, pending_layer_, &all_tiles);
227 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
228 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
230 RunEvictionQueueConstructAndIterateTest(
231 "32_100x100", 32, gfx::Size(100, 100));
232 RunEvictionQueueConstructAndIterateTest(
233 "32_500x500", 32, gfx::Size(500, 500));
234 RunEvictionQueueConstructAndIterateTest(
235 "64_100x100", 64, gfx::Size(100, 100));
236 RunEvictionQueueConstructAndIterateTest(
237 "64_500x500", 64, gfx::Size(500, 500));
240 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstruct) {
241 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
243 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
245 std::vector<Tile*> all_tiles;
246 AddTiling(low_res_factor, pending_layer_, &all_tiles);
247 AddTiling(0.3f, pending_layer_, &all_tiles);
248 AddTiling(0.7f, pending_layer_, &all_tiles);
249 AddTiling(1.0f, pending_layer_, &all_tiles);
250 AddTiling(2.0f, pending_layer_, &all_tiles);
252 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
253 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
255 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
256 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
257 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
260 } // namespace
261 } // namespace cc