Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_perftest.cc
blob5369638c9808414b3deb27af4e892917e17cb3f1
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/test/test_task_graph_runner.h"
17 #include "cc/trees/layer_tree_impl.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/perf/perf_test.h"
21 namespace cc {
22 namespace {
24 static const int kTimeLimitMillis = 2000;
25 static const int kWarmupRuns = 5;
26 static const int kTimeCheckInterval = 10;
28 void AddTiling(float scale,
29 FakePictureLayerImpl* layer,
30 std::vector<Tile*>* all_tiles) {
31 PictureLayerTiling* tiling = layer->AddTiling(scale);
33 tiling->CreateAllTilesForTesting();
34 std::vector<Tile*> tiling_tiles = tiling->AllTilesForTesting();
35 std::copy(
36 tiling_tiles.begin(), tiling_tiles.end(), std::back_inserter(*all_tiles));
39 class PictureLayerImplPerfTest : public testing::Test {
40 public:
41 PictureLayerImplPerfTest()
42 : proxy_(base::MessageLoopProxy::current()),
43 host_impl_(ImplSidePaintingSettings(),
44 &proxy_,
45 &shared_bitmap_manager_,
46 &task_graph_runner_),
47 timer_(kWarmupRuns,
48 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
49 kTimeCheckInterval) {}
51 void SetUp() override {
52 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
55 void SetupPendingTree(const gfx::Size& layer_bounds,
56 const gfx::Size& tile_size) {
57 scoped_refptr<FakePicturePileImpl> pile =
58 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
59 host_impl_.CreatePendingTree();
60 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
61 pending_tree->DetachLayerTree();
63 scoped_ptr<FakePictureLayerImpl> pending_layer =
64 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 7, pile);
65 pending_layer->SetDrawsContent(true);
66 pending_layer->SetHasRenderSurface(true);
67 pending_tree->SetRootLayer(pending_layer.Pass());
69 pending_layer_ = static_cast<FakePictureLayerImpl*>(
70 host_impl_.pending_tree()->LayerById(7));
73 void RunRasterQueueConstructAndIterateTest(const std::string& test_name,
74 int num_tiles,
75 const gfx::Size& viewport_size) {
76 host_impl_.SetViewportSize(viewport_size);
77 bool update_lcd_text = false;
78 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
80 timer_.Reset();
81 do {
82 int count = num_tiles;
83 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
84 pending_layer_->picture_layer_tiling_set(), false));
85 while (count--) {
86 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
87 ASSERT_TRUE(queue->Top() != nullptr) << "count: " << count;
88 queue->Pop();
90 timer_.NextLap();
91 } while (!timer_.HasTimeLimitExpired());
93 perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
94 test_name, timer_.LapsPerSecond(), "runs/s", true);
97 void RunRasterQueueConstructTest(const std::string& test_name,
98 const gfx::Rect& viewport) {
99 host_impl_.SetViewportSize(viewport.size());
100 pending_layer_->PushScrollOffsetFromMainThread(
101 gfx::ScrollOffset(viewport.x(), viewport.y()));
102 bool update_lcd_text = false;
103 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
105 timer_.Reset();
106 do {
107 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
108 pending_layer_->picture_layer_tiling_set(), false));
109 timer_.NextLap();
110 } while (!timer_.HasTimeLimitExpired());
112 perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name,
113 timer_.LapsPerSecond(), "runs/s", true);
116 void RunEvictionQueueConstructAndIterateTest(
117 const std::string& test_name,
118 int num_tiles,
119 const gfx::Size& viewport_size) {
120 host_impl_.SetViewportSize(viewport_size);
121 bool update_lcd_text = false;
122 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
124 timer_.Reset();
125 do {
126 int count = num_tiles;
127 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
128 pending_layer_->picture_layer_tiling_set(), false));
129 while (count--) {
130 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
131 ASSERT_TRUE(queue->Top() != nullptr) << "count: " << count;
132 queue->Pop();
134 timer_.NextLap();
135 } while (!timer_.HasTimeLimitExpired());
137 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
138 "", test_name, timer_.LapsPerSecond(), "runs/s",
139 true);
142 void RunEvictionQueueConstructTest(const std::string& test_name,
143 const gfx::Rect& viewport) {
144 host_impl_.SetViewportSize(viewport.size());
145 pending_layer_->PushScrollOffsetFromMainThread(
146 gfx::ScrollOffset(viewport.x(), viewport.y()));
147 bool update_lcd_text = false;
148 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
150 timer_.Reset();
151 do {
152 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
153 pending_layer_->picture_layer_tiling_set(), false));
154 timer_.NextLap();
155 } while (!timer_.HasTimeLimitExpired());
157 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name,
158 timer_.LapsPerSecond(), "runs/s", true);
161 protected:
162 TestSharedBitmapManager shared_bitmap_manager_;
163 TestTaskGraphRunner task_graph_runner_;
164 FakeImplProxy proxy_;
165 FakeLayerTreeHostImpl host_impl_;
166 FakePictureLayerImpl* pending_layer_;
167 LapTimer timer_;
169 private:
170 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
173 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstructAndIterate) {
174 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
176 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
178 pending_layer_->AddTiling(low_res_factor);
179 pending_layer_->AddTiling(0.3f);
180 pending_layer_->AddTiling(0.7f);
181 pending_layer_->AddTiling(1.0f);
182 pending_layer_->AddTiling(2.0f);
184 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
185 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
186 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
187 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
190 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstruct) {
191 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
193 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
195 pending_layer_->AddTiling(low_res_factor);
196 pending_layer_->AddTiling(0.3f);
197 pending_layer_->AddTiling(0.7f);
198 pending_layer_->AddTiling(1.0f);
199 pending_layer_->AddTiling(2.0f);
201 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
202 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
203 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
206 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstructAndIterate) {
207 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
209 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
211 std::vector<Tile*> all_tiles;
212 AddTiling(low_res_factor, pending_layer_, &all_tiles);
213 AddTiling(0.3f, pending_layer_, &all_tiles);
214 AddTiling(0.7f, pending_layer_, &all_tiles);
215 AddTiling(1.0f, pending_layer_, &all_tiles);
216 AddTiling(2.0f, pending_layer_, &all_tiles);
218 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
219 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
221 RunEvictionQueueConstructAndIterateTest(
222 "32_100x100", 32, gfx::Size(100, 100));
223 RunEvictionQueueConstructAndIterateTest(
224 "32_500x500", 32, gfx::Size(500, 500));
225 RunEvictionQueueConstructAndIterateTest(
226 "64_100x100", 64, gfx::Size(100, 100));
227 RunEvictionQueueConstructAndIterateTest(
228 "64_500x500", 64, gfx::Size(500, 500));
231 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstruct) {
232 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
234 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
236 std::vector<Tile*> all_tiles;
237 AddTiling(low_res_factor, pending_layer_, &all_tiles);
238 AddTiling(0.3f, pending_layer_, &all_tiles);
239 AddTiling(0.7f, pending_layer_, &all_tiles);
240 AddTiling(1.0f, pending_layer_, &all_tiles);
241 AddTiling(2.0f, pending_layer_, &all_tiles);
243 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
244 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
246 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
247 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
248 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
251 } // namespace
252 } // namespace cc