[Large Icon Service] Remove bad DCHECK.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_perftest.cc
blob4cb7050e354b696219295ed849d9d8311699e4bf
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 "base/thread_task_runner_handle.h"
8 #include "cc/debug/lap_timer.h"
9 #include "cc/resources/tiling_set_raster_queue_all.h"
10 #include "cc/test/fake_impl_proxy.h"
11 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_picture_layer_impl.h"
14 #include "cc/test/fake_picture_pile_impl.h"
15 #include "cc/test/impl_side_painting_settings.h"
16 #include "cc/test/test_shared_bitmap_manager.h"
17 #include "cc/test/test_task_graph_runner.h"
18 #include "cc/trees/layer_tree_impl.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/perf/perf_test.h"
22 namespace cc {
23 namespace {
25 static const int kTimeLimitMillis = 2000;
26 static const int kWarmupRuns = 5;
27 static const int kTimeCheckInterval = 10;
29 void AddTiling(float scale,
30 FakePictureLayerImpl* layer,
31 std::vector<Tile*>* all_tiles) {
32 PictureLayerTiling* tiling = layer->AddTiling(scale);
34 tiling->CreateAllTilesForTesting();
35 std::vector<Tile*> tiling_tiles = tiling->AllTilesForTesting();
36 std::copy(
37 tiling_tiles.begin(), tiling_tiles.end(), std::back_inserter(*all_tiles));
40 class PictureLayerImplPerfTest : public testing::Test {
41 public:
42 PictureLayerImplPerfTest()
43 : proxy_(base::ThreadTaskRunnerHandle::Get()),
44 host_impl_(ImplSidePaintingSettings(),
45 &proxy_,
46 &shared_bitmap_manager_,
47 &task_graph_runner_),
48 timer_(kWarmupRuns,
49 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
50 kTimeCheckInterval) {}
52 void SetUp() override {
53 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
56 void SetupPendingTree(const gfx::Size& layer_bounds,
57 const gfx::Size& tile_size) {
58 scoped_refptr<FakePicturePileImpl> pile =
59 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
60 host_impl_.CreatePendingTree();
61 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
62 pending_tree->DetachLayerTree();
64 scoped_ptr<FakePictureLayerImpl> pending_layer =
65 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 7, pile);
66 pending_layer->SetDrawsContent(true);
67 pending_layer->SetHasRenderSurface(true);
68 pending_tree->SetRootLayer(pending_layer.Pass());
70 pending_layer_ = static_cast<FakePictureLayerImpl*>(
71 host_impl_.pending_tree()->LayerById(7));
74 void RunRasterQueueConstructAndIterateTest(const std::string& test_name,
75 int num_tiles,
76 const gfx::Size& viewport_size) {
77 host_impl_.SetViewportSize(viewport_size);
78 bool update_lcd_text = false;
79 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
81 timer_.Reset();
82 do {
83 int count = num_tiles;
84 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
85 pending_layer_->picture_layer_tiling_set(), false));
86 while (count--) {
87 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
88 ASSERT_TRUE(queue->Top() != nullptr) << "count: " << count;
89 queue->Pop();
91 timer_.NextLap();
92 } while (!timer_.HasTimeLimitExpired());
94 perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
95 test_name, timer_.LapsPerSecond(), "runs/s", true);
98 void RunRasterQueueConstructTest(const std::string& test_name,
99 const gfx::Rect& viewport) {
100 host_impl_.SetViewportSize(viewport.size());
101 pending_layer_->PushScrollOffsetFromMainThread(
102 gfx::ScrollOffset(viewport.x(), viewport.y()));
103 bool update_lcd_text = false;
104 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
106 timer_.Reset();
107 do {
108 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
109 pending_layer_->picture_layer_tiling_set(), false));
110 timer_.NextLap();
111 } while (!timer_.HasTimeLimitExpired());
113 perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name,
114 timer_.LapsPerSecond(), "runs/s", true);
117 void RunEvictionQueueConstructAndIterateTest(
118 const std::string& test_name,
119 int num_tiles,
120 const gfx::Size& viewport_size) {
121 host_impl_.SetViewportSize(viewport_size);
122 bool update_lcd_text = false;
123 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
125 timer_.Reset();
126 do {
127 int count = num_tiles;
128 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
129 pending_layer_->picture_layer_tiling_set()));
130 while (count--) {
131 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
132 ASSERT_TRUE(queue->Top() != nullptr) << "count: " << count;
133 queue->Pop();
135 timer_.NextLap();
136 } while (!timer_.HasTimeLimitExpired());
138 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
139 "", test_name, timer_.LapsPerSecond(), "runs/s",
140 true);
143 void RunEvictionQueueConstructTest(const std::string& test_name,
144 const gfx::Rect& viewport) {
145 host_impl_.SetViewportSize(viewport.size());
146 pending_layer_->PushScrollOffsetFromMainThread(
147 gfx::ScrollOffset(viewport.x(), viewport.y()));
148 bool update_lcd_text = false;
149 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
151 timer_.Reset();
152 do {
153 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
154 pending_layer_->picture_layer_tiling_set()));
155 timer_.NextLap();
156 } while (!timer_.HasTimeLimitExpired());
158 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name,
159 timer_.LapsPerSecond(), "runs/s", true);
162 protected:
163 TestSharedBitmapManager shared_bitmap_manager_;
164 TestTaskGraphRunner task_graph_runner_;
165 FakeImplProxy proxy_;
166 FakeLayerTreeHostImpl host_impl_;
167 FakePictureLayerImpl* pending_layer_;
168 LapTimer timer_;
170 private:
171 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
174 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstructAndIterate) {
175 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
177 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
179 pending_layer_->AddTiling(low_res_factor);
180 pending_layer_->AddTiling(0.3f);
181 pending_layer_->AddTiling(0.7f);
182 pending_layer_->AddTiling(1.0f);
183 pending_layer_->AddTiling(2.0f);
185 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
186 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
187 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
188 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
191 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstruct) {
192 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
194 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
196 pending_layer_->AddTiling(low_res_factor);
197 pending_layer_->AddTiling(0.3f);
198 pending_layer_->AddTiling(0.7f);
199 pending_layer_->AddTiling(1.0f);
200 pending_layer_->AddTiling(2.0f);
202 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
203 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
204 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
207 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstructAndIterate) {
208 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
210 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
212 std::vector<Tile*> all_tiles;
213 AddTiling(low_res_factor, pending_layer_, &all_tiles);
214 AddTiling(0.3f, pending_layer_, &all_tiles);
215 AddTiling(0.7f, pending_layer_, &all_tiles);
216 AddTiling(1.0f, pending_layer_, &all_tiles);
217 AddTiling(2.0f, pending_layer_, &all_tiles);
219 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
220 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
222 RunEvictionQueueConstructAndIterateTest(
223 "32_100x100", 32, gfx::Size(100, 100));
224 RunEvictionQueueConstructAndIterateTest(
225 "32_500x500", 32, gfx::Size(500, 500));
226 RunEvictionQueueConstructAndIterateTest(
227 "64_100x100", 64, gfx::Size(100, 100));
228 RunEvictionQueueConstructAndIterateTest(
229 "64_500x500", 64, gfx::Size(500, 500));
232 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstruct) {
233 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
235 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
237 std::vector<Tile*> all_tiles;
238 AddTiling(low_res_factor, pending_layer_, &all_tiles);
239 AddTiling(0.3f, pending_layer_, &all_tiles);
240 AddTiling(0.7f, pending_layer_, &all_tiles);
241 AddTiling(1.0f, pending_layer_, &all_tiles);
242 AddTiling(2.0f, pending_layer_, &all_tiles);
244 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
245 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
247 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
248 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
249 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
252 } // namespace
253 } // namespace cc