Support swap promises that are pinned to a particular layer tree.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_perftest.cc
blob9e7d82bf6fc33e20e7b0f7bce47a2819c973b113
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/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/test_shared_bitmap_manager.h"
15 #include "cc/test/test_task_graph_runner.h"
16 #include "cc/tiles/tiling_set_raster_queue_all.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->set_resolution(HIGH_RESOLUTION);
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_(LayerTreeSettings(),
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 SetupActiveTree(const gfx::Size& layer_bounds,
57 const gfx::Size& tile_size) {
58 scoped_refptr<FakePicturePileImpl> pile =
59 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
60 LayerTreeImpl* active_tree = host_impl_.active_tree();
61 active_tree->DetachLayerTree();
63 scoped_ptr<FakePictureLayerImpl> active_layer =
64 FakePictureLayerImpl::CreateWithRasterSource(active_tree, 7, pile);
65 active_layer->SetDrawsContent(true);
66 active_layer->SetHasRenderSurface(true);
67 active_tree->SetRootLayer(active_layer.Pass());
69 active_layer_ = static_cast<FakePictureLayerImpl*>(
70 host_impl_.active_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_.active_tree()->UpdateDrawProperties(update_lcd_text);
80 timer_.Reset();
81 do {
82 int count = num_tiles;
83 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
84 active_layer_->picture_layer_tiling_set(), false));
85 while (count--) {
86 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
87 ASSERT_TRUE(queue->Top().tile()) << "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 active_layer_->PushScrollOffsetFromMainThreadAndClobberActiveValue(
101 gfx::ScrollOffset(viewport.x(), viewport.y()));
102 bool update_lcd_text = false;
103 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
105 timer_.Reset();
106 do {
107 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
108 active_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 active_layer_->MarkAllTilingsUsed();
122 bool update_lcd_text = false;
123 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
125 timer_.Reset();
126 do {
127 int count = num_tiles;
128 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
129 active_layer_->picture_layer_tiling_set()));
130 while (count--) {
131 ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
132 ASSERT_TRUE(queue->Top().tile()) << "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 active_layer_->PushScrollOffsetFromMainThreadAndClobberActiveValue(
147 gfx::ScrollOffset(viewport.x(), viewport.y()));
148 active_layer_->MarkAllTilingsUsed();
149 bool update_lcd_text = false;
150 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
152 timer_.Reset();
153 do {
154 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
155 active_layer_->picture_layer_tiling_set()));
156 timer_.NextLap();
157 } while (!timer_.HasTimeLimitExpired());
159 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name,
160 timer_.LapsPerSecond(), "runs/s", true);
163 protected:
164 TestSharedBitmapManager shared_bitmap_manager_;
165 TestTaskGraphRunner task_graph_runner_;
166 FakeImplProxy proxy_;
167 FakeLayerTreeHostImpl host_impl_;
168 FakePictureLayerImpl* active_layer_;
169 LapTimer timer_;
171 private:
172 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
175 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstructAndIterate) {
176 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
178 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
180 active_layer_->AddTiling(low_res_factor);
181 active_layer_->AddTiling(0.3f);
182 active_layer_->AddTiling(0.7f);
183 active_layer_->AddTiling(1.0f);
184 active_layer_->AddTiling(2.0f);
186 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
187 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
188 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
189 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
192 TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstruct) {
193 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
195 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
197 active_layer_->AddTiling(low_res_factor);
198 active_layer_->AddTiling(0.3f);
199 active_layer_->AddTiling(0.7f);
200 active_layer_->AddTiling(1.0f);
201 active_layer_->AddTiling(2.0f);
203 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
204 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
205 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
208 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstructAndIterate) {
209 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
211 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
213 std::vector<Tile*> all_tiles;
214 AddTiling(low_res_factor, active_layer_, &all_tiles);
215 AddTiling(0.3f, active_layer_, &all_tiles);
216 AddTiling(0.7f, active_layer_, &all_tiles);
217 AddTiling(1.0f, active_layer_, &all_tiles);
218 AddTiling(2.0f, active_layer_, &all_tiles);
220 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
221 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
223 RunEvictionQueueConstructAndIterateTest(
224 "32_100x100", 32, gfx::Size(100, 100));
225 RunEvictionQueueConstructAndIterateTest(
226 "32_500x500", 32, gfx::Size(500, 500));
227 RunEvictionQueueConstructAndIterateTest(
228 "64_100x100", 64, gfx::Size(100, 100));
229 RunEvictionQueueConstructAndIterateTest(
230 "64_500x500", 64, gfx::Size(500, 500));
233 TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstruct) {
234 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
236 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
238 std::vector<Tile*> all_tiles;
239 AddTiling(low_res_factor, active_layer_, &all_tiles);
240 AddTiling(0.3f, active_layer_, &all_tiles);
241 AddTiling(0.7f, active_layer_, &all_tiles);
242 AddTiling(1.0f, active_layer_, &all_tiles);
243 AddTiling(2.0f, active_layer_, &all_tiles);
245 ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
246 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
248 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
249 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
250 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
253 } // namespace
254 } // namespace cc