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"
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();
37 tiling_tiles
.begin(), tiling_tiles
.end(), std::back_inserter(*all_tiles
));
40 class PictureLayerImplPerfTest
: public testing::Test
{
42 PictureLayerImplPerfTest()
43 : proxy_(base::ThreadTaskRunnerHandle::Get()),
44 output_surface_(FakeOutputSurface::Create3d()),
45 host_impl_(LayerTreeSettings(),
47 &shared_bitmap_manager_
,
50 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
51 kTimeCheckInterval
) {}
53 void SetUp() override
{
54 host_impl_
.InitializeRenderer(output_surface_
.get());
57 void SetupActiveTree(const gfx::Size
& layer_bounds
,
58 const gfx::Size
& tile_size
) {
59 scoped_refptr
<FakePicturePileImpl
> pile
=
60 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
61 LayerTreeImpl
* active_tree
= host_impl_
.active_tree();
62 active_tree
->DetachLayerTree();
64 scoped_ptr
<FakePictureLayerImpl
> active_layer
=
65 FakePictureLayerImpl::CreateWithRasterSource(active_tree
, 7, pile
);
66 active_layer
->SetDrawsContent(true);
67 active_layer
->SetHasRenderSurface(true);
68 active_tree
->SetRootLayer(active_layer
.Pass());
70 active_layer_
= static_cast<FakePictureLayerImpl
*>(
71 host_impl_
.active_tree()->LayerById(7));
74 void RunRasterQueueConstructAndIterateTest(const std::string
& test_name
,
76 const gfx::Size
& viewport_size
) {
77 host_impl_
.SetViewportSize(viewport_size
);
78 bool update_lcd_text
= false;
79 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
83 int count
= num_tiles
;
84 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
85 active_layer_
->picture_layer_tiling_set(), false));
87 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
88 ASSERT_TRUE(queue
->Top().tile()) << "count: " << count
;
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 active_layer_
->PushScrollOffsetFromMainThreadAndClobberActiveValue(
102 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
103 bool update_lcd_text
= false;
104 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
108 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
109 active_layer_
->picture_layer_tiling_set(), false));
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
,
120 const gfx::Size
& viewport_size
) {
121 host_impl_
.SetViewportSize(viewport_size
);
122 active_layer_
->MarkAllTilingsUsed();
123 bool update_lcd_text
= false;
124 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
128 int count
= num_tiles
;
129 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
130 active_layer_
->picture_layer_tiling_set()));
132 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
133 ASSERT_TRUE(queue
->Top().tile()) << "count: " << count
;
137 } while (!timer_
.HasTimeLimitExpired());
139 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
140 "", test_name
, timer_
.LapsPerSecond(), "runs/s",
144 void RunEvictionQueueConstructTest(const std::string
& test_name
,
145 const gfx::Rect
& viewport
) {
146 host_impl_
.SetViewportSize(viewport
.size());
147 active_layer_
->PushScrollOffsetFromMainThreadAndClobberActiveValue(
148 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
149 active_layer_
->MarkAllTilingsUsed();
150 bool update_lcd_text
= false;
151 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
155 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
156 active_layer_
->picture_layer_tiling_set()));
158 } while (!timer_
.HasTimeLimitExpired());
160 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name
,
161 timer_
.LapsPerSecond(), "runs/s", true);
165 TestSharedBitmapManager shared_bitmap_manager_
;
166 TestTaskGraphRunner task_graph_runner_
;
167 FakeImplProxy proxy_
;
168 scoped_ptr
<OutputSurface
> output_surface_
;
169 FakeLayerTreeHostImpl host_impl_
;
170 FakePictureLayerImpl
* active_layer_
;
174 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
177 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstructAndIterate
) {
178 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
180 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
182 active_layer_
->AddTiling(low_res_factor
);
183 active_layer_
->AddTiling(0.3f
);
184 active_layer_
->AddTiling(0.7f
);
185 active_layer_
->AddTiling(1.0f
);
186 active_layer_
->AddTiling(2.0f
);
188 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
189 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
190 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
191 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
194 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstruct
) {
195 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
197 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
199 active_layer_
->AddTiling(low_res_factor
);
200 active_layer_
->AddTiling(0.3f
);
201 active_layer_
->AddTiling(0.7f
);
202 active_layer_
->AddTiling(1.0f
);
203 active_layer_
->AddTiling(2.0f
);
205 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
206 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
207 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
210 TEST_F(PictureLayerImplPerfTest
, TilingSetEvictionQueueConstructAndIterate
) {
211 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
213 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
215 std::vector
<Tile
*> all_tiles
;
216 AddTiling(low_res_factor
, active_layer_
, &all_tiles
);
217 AddTiling(0.3f
, active_layer_
, &all_tiles
);
218 AddTiling(0.7f
, active_layer_
, &all_tiles
);
219 AddTiling(1.0f
, active_layer_
, &all_tiles
);
220 AddTiling(2.0f
, active_layer_
, &all_tiles
);
222 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
223 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
225 RunEvictionQueueConstructAndIterateTest(
226 "32_100x100", 32, gfx::Size(100, 100));
227 RunEvictionQueueConstructAndIterateTest(
228 "32_500x500", 32, gfx::Size(500, 500));
229 RunEvictionQueueConstructAndIterateTest(
230 "64_100x100", 64, gfx::Size(100, 100));
231 RunEvictionQueueConstructAndIterateTest(
232 "64_500x500", 64, gfx::Size(500, 500));
235 TEST_F(PictureLayerImplPerfTest
, TilingSetEvictionQueueConstruct
) {
236 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
238 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
240 std::vector
<Tile
*> all_tiles
;
241 AddTiling(low_res_factor
, active_layer_
, &all_tiles
);
242 AddTiling(0.3f
, active_layer_
, &all_tiles
);
243 AddTiling(0.7f
, active_layer_
, &all_tiles
);
244 AddTiling(1.0f
, active_layer_
, &all_tiles
);
245 AddTiling(2.0f
, active_layer_
, &all_tiles
);
247 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
248 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
250 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
251 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
252 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));