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"
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();
36 tiling_tiles
.begin(), tiling_tiles
.end(), std::back_inserter(*all_tiles
));
39 class PictureLayerImplPerfTest
: public testing::Test
{
41 PictureLayerImplPerfTest()
42 : proxy_(base::MessageLoopProxy::current()),
43 host_impl_(ImplSidePaintingSettings(),
45 &shared_bitmap_manager_
,
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
,
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
);
82 int count
= num_tiles
;
83 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
84 pending_layer_
->picture_layer_tiling_set(), false));
86 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
87 ASSERT_TRUE(queue
->Top() != nullptr) << "count: " << count
;
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
);
107 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
108 pending_layer_
->picture_layer_tiling_set(), false));
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
,
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
);
126 int count
= num_tiles
;
127 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
128 pending_layer_
->picture_layer_tiling_set(), false));
130 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
131 ASSERT_TRUE(queue
->Top() != nullptr) << "count: " << count
;
135 } while (!timer_
.HasTimeLimitExpired());
137 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
138 "", test_name
, timer_
.LapsPerSecond(), "runs/s",
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
);
152 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
153 pending_layer_
->picture_layer_tiling_set(), false));
155 } while (!timer_
.HasTimeLimitExpired());
157 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name
,
158 timer_
.LapsPerSecond(), "runs/s", true);
162 TestSharedBitmapManager shared_bitmap_manager_
;
163 TestTaskGraphRunner task_graph_runner_
;
164 FakeImplProxy proxy_
;
165 FakeLayerTreeHostImpl host_impl_
;
166 FakePictureLayerImpl
* pending_layer_
;
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));