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
->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::ThreadTaskRunnerHandle::Get()),
43 host_impl_(LayerTreeSettings(),
45 &shared_bitmap_manager_
,
48 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
49 kTimeCheckInterval
) {}
51 void SetUp() override
{
52 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
55 void SetupActiveTree(const gfx::Size
& layer_bounds
,
56 const gfx::Size
& tile_size
) {
57 scoped_refptr
<FakePicturePileImpl
> pile
=
58 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
59 LayerTreeImpl
* active_tree
= host_impl_
.active_tree();
60 active_tree
->DetachLayerTree();
62 scoped_ptr
<FakePictureLayerImpl
> active_layer
=
63 FakePictureLayerImpl::CreateWithRasterSource(active_tree
, 7, pile
);
64 active_layer
->SetDrawsContent(true);
65 active_layer
->SetHasRenderSurface(true);
66 active_tree
->SetRootLayer(active_layer
.Pass());
68 active_layer_
= static_cast<FakePictureLayerImpl
*>(
69 host_impl_
.active_tree()->LayerById(7));
72 void RunRasterQueueConstructAndIterateTest(const std::string
& test_name
,
74 const gfx::Size
& viewport_size
) {
75 host_impl_
.SetViewportSize(viewport_size
);
76 bool update_lcd_text
= false;
77 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
81 int count
= num_tiles
;
82 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
83 active_layer_
->picture_layer_tiling_set(), false));
85 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
86 ASSERT_TRUE(queue
->Top().tile()) << "count: " << count
;
90 } while (!timer_
.HasTimeLimitExpired());
92 perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
93 test_name
, timer_
.LapsPerSecond(), "runs/s", true);
96 void RunRasterQueueConstructTest(const std::string
& test_name
,
97 const gfx::Rect
& viewport
) {
98 host_impl_
.SetViewportSize(viewport
.size());
99 active_layer_
->PushScrollOffsetFromMainThreadAndClobberActiveValue(
100 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
101 bool update_lcd_text
= false;
102 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
106 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
107 active_layer_
->picture_layer_tiling_set(), false));
109 } while (!timer_
.HasTimeLimitExpired());
111 perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name
,
112 timer_
.LapsPerSecond(), "runs/s", true);
115 void RunEvictionQueueConstructAndIterateTest(
116 const std::string
& test_name
,
118 const gfx::Size
& viewport_size
) {
119 host_impl_
.SetViewportSize(viewport_size
);
120 active_layer_
->MarkAllTilingsUsed();
121 bool update_lcd_text
= false;
122 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
126 int count
= num_tiles
;
127 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
128 active_layer_
->picture_layer_tiling_set()));
130 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
131 ASSERT_TRUE(queue
->Top().tile()) << "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 active_layer_
->PushScrollOffsetFromMainThreadAndClobberActiveValue(
146 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
147 active_layer_
->MarkAllTilingsUsed();
148 bool update_lcd_text
= false;
149 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
153 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
154 active_layer_
->picture_layer_tiling_set()));
156 } while (!timer_
.HasTimeLimitExpired());
158 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name
,
159 timer_
.LapsPerSecond(), "runs/s", true);
163 TestSharedBitmapManager shared_bitmap_manager_
;
164 TestTaskGraphRunner task_graph_runner_
;
165 FakeImplProxy proxy_
;
166 FakeLayerTreeHostImpl host_impl_
;
167 FakePictureLayerImpl
* active_layer_
;
171 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
174 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstructAndIterate
) {
175 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
177 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
179 active_layer_
->AddTiling(low_res_factor
);
180 active_layer_
->AddTiling(0.3f
);
181 active_layer_
->AddTiling(0.7f
);
182 active_layer_
->AddTiling(1.0f
);
183 active_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 SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
194 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
196 active_layer_
->AddTiling(low_res_factor
);
197 active_layer_
->AddTiling(0.3f
);
198 active_layer_
->AddTiling(0.7f
);
199 active_layer_
->AddTiling(1.0f
);
200 active_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 SetupActiveTree(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
, active_layer_
, &all_tiles
);
214 AddTiling(0.3f
, active_layer_
, &all_tiles
);
215 AddTiling(0.7f
, active_layer_
, &all_tiles
);
216 AddTiling(1.0f
, active_layer_
, &all_tiles
);
217 AddTiling(2.0f
, active_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 SetupActiveTree(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
, active_layer_
, &all_tiles
);
239 AddTiling(0.3f
, active_layer_
, &all_tiles
);
240 AddTiling(0.7f
, active_layer_
, &all_tiles
);
241 AddTiling(1.0f
, active_layer_
, &all_tiles
);
242 AddTiling(2.0f
, active_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));