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/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/fake_picture_layer_impl.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/trees/layer_tree_impl.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
22 static const int kTimeLimitMillis
= 2000;
23 static const int kWarmupRuns
= 5;
24 static const int kTimeCheckInterval
= 10;
26 void AddTiling(float scale
,
27 FakePictureLayerImpl
* layer
,
28 std::vector
<Tile
*>* all_tiles
) {
29 PictureLayerTiling
* tiling
= layer
->AddTiling(scale
);
31 tiling
->CreateAllTilesForTesting();
32 std::vector
<Tile
*> tiling_tiles
= tiling
->AllTilesForTesting();
34 tiling_tiles
.begin(), tiling_tiles
.end(), std::back_inserter(*all_tiles
));
37 class PictureLayerImplPerfTest
: public testing::Test
{
39 PictureLayerImplPerfTest()
40 : proxy_(base::MessageLoopProxy::current()),
41 host_impl_(ImplSidePaintingSettings(),
43 &shared_bitmap_manager_
),
45 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
46 kTimeCheckInterval
) {}
48 void SetUp() override
{
49 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
52 void SetupPendingTree(const gfx::Size
& layer_bounds
,
53 const gfx::Size
& tile_size
) {
54 scoped_refptr
<FakePicturePileImpl
> pile
=
55 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
56 host_impl_
.CreatePendingTree();
57 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
58 pending_tree
->DetachLayerTree();
60 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
61 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, 7, pile
);
62 pending_layer
->SetDrawsContent(true);
63 pending_tree
->SetRootLayer(pending_layer
.Pass());
65 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
66 host_impl_
.pending_tree()->LayerById(7));
67 pending_layer_
->DoPostCommitInitializationIfNeeded();
70 void RunRasterIteratorConstructAndIterateTest(
71 const std::string
& test_name
,
73 const gfx::Size
& viewport_size
) {
74 host_impl_
.SetViewportSize(viewport_size
);
75 host_impl_
.pending_tree()->UpdateDrawProperties();
79 int count
= num_tiles
;
80 PictureLayerImpl::LayerRasterTileIterator
it(pending_layer_
, false);
82 ASSERT_TRUE(it
) << "count: " << count
;
83 ASSERT_TRUE(*it
!= nullptr) << "count: " << count
;
87 } while (!timer_
.HasTimeLimitExpired());
89 perf_test::PrintResult("layer_raster_tile_iterator_construct_and_iterate",
92 timer_
.LapsPerSecond(),
97 void RunRasterIteratorConstructTest(const std::string
& test_name
,
98 const gfx::Rect
& viewport
) {
99 host_impl_
.SetViewportSize(viewport
.size());
100 pending_layer_
->SetScrollOffset(
101 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
102 host_impl_
.pending_tree()->UpdateDrawProperties();
106 PictureLayerImpl::LayerRasterTileIterator
it(pending_layer_
, false);
108 } while (!timer_
.HasTimeLimitExpired());
110 perf_test::PrintResult("layer_raster_tile_iterator_construct",
113 timer_
.LapsPerSecond(),
118 void RunEvictionIteratorConstructAndIterateTest(
119 const std::string
& test_name
,
121 const gfx::Size
& viewport_size
) {
122 host_impl_
.SetViewportSize(viewport_size
);
123 host_impl_
.pending_tree()->UpdateDrawProperties();
125 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
126 SMOOTHNESS_TAKES_PRIORITY
,
127 NEW_CONTENT_TAKES_PRIORITY
};
128 int priority_count
= 0;
131 int count
= num_tiles
;
132 PictureLayerImpl::LayerEvictionTileIterator
it(
133 pending_layer_
, priorities
[priority_count
]);
135 ASSERT_TRUE(it
) << "count: " << count
;
136 ASSERT_TRUE(*it
!= nullptr) << "count: " << count
;
139 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
141 } while (!timer_
.HasTimeLimitExpired());
143 perf_test::PrintResult("layer_eviction_tile_iterator_construct_and_iterate",
146 timer_
.LapsPerSecond(),
151 void RunEvictionIteratorConstructTest(const std::string
& test_name
,
152 const gfx::Rect
& viewport
) {
153 host_impl_
.SetViewportSize(viewport
.size());
154 pending_layer_
->SetScrollOffset(
155 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
156 host_impl_
.pending_tree()->UpdateDrawProperties();
158 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
159 SMOOTHNESS_TAKES_PRIORITY
,
160 NEW_CONTENT_TAKES_PRIORITY
};
161 int priority_count
= 0;
164 PictureLayerImpl::LayerEvictionTileIterator
it(
165 pending_layer_
, priorities
[priority_count
]);
166 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
168 } while (!timer_
.HasTimeLimitExpired());
170 perf_test::PrintResult("layer_eviction_tile_iterator_construct",
173 timer_
.LapsPerSecond(),
179 TestSharedBitmapManager shared_bitmap_manager_
;
180 FakeImplProxy proxy_
;
181 FakeLayerTreeHostImpl host_impl_
;
182 FakePictureLayerImpl
* pending_layer_
;
186 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
189 TEST_F(PictureLayerImplPerfTest
, LayerRasterTileIteratorConstructAndIterate
) {
190 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
192 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
194 pending_layer_
->AddTiling(low_res_factor
);
195 pending_layer_
->AddTiling(0.3f
);
196 pending_layer_
->AddTiling(0.7f
);
197 pending_layer_
->AddTiling(1.0f
);
198 pending_layer_
->AddTiling(2.0f
);
200 RunRasterIteratorConstructAndIterateTest(
201 "32_100x100", 32, gfx::Size(100, 100));
202 RunRasterIteratorConstructAndIterateTest(
203 "32_500x500", 32, gfx::Size(500, 500));
204 RunRasterIteratorConstructAndIterateTest(
205 "64_100x100", 64, gfx::Size(100, 100));
206 RunRasterIteratorConstructAndIterateTest(
207 "64_500x500", 64, gfx::Size(500, 500));
210 TEST_F(PictureLayerImplPerfTest
, LayerRasterTileIteratorConstruct
) {
211 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
213 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
215 pending_layer_
->AddTiling(low_res_factor
);
216 pending_layer_
->AddTiling(0.3f
);
217 pending_layer_
->AddTiling(0.7f
);
218 pending_layer_
->AddTiling(1.0f
);
219 pending_layer_
->AddTiling(2.0f
);
221 RunRasterIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
222 RunRasterIteratorConstructTest("5000_0_100x100",
223 gfx::Rect(5000, 0, 100, 100));
224 RunRasterIteratorConstructTest("9999_0_100x100",
225 gfx::Rect(9999, 0, 100, 100));
228 TEST_F(PictureLayerImplPerfTest
, LayerEvictionTileIteratorConstructAndIterate
) {
229 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
231 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
233 std::vector
<Tile
*> all_tiles
;
234 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
235 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
236 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
237 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
238 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
240 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
241 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
243 RunEvictionIteratorConstructAndIterateTest(
244 "32_100x100", 32, gfx::Size(100, 100));
245 RunEvictionIteratorConstructAndIterateTest(
246 "32_500x500", 32, gfx::Size(500, 500));
247 RunEvictionIteratorConstructAndIterateTest(
248 "64_100x100", 64, gfx::Size(100, 100));
249 RunEvictionIteratorConstructAndIterateTest(
250 "64_500x500", 64, gfx::Size(500, 500));
253 TEST_F(PictureLayerImplPerfTest
, LayerEvictionTileIteratorConstruct
) {
254 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
256 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
258 std::vector
<Tile
*> all_tiles
;
259 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
260 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
261 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
262 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
263 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
265 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
266 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
268 RunEvictionIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
269 RunEvictionIteratorConstructTest("5000_0_100x100",
270 gfx::Rect(5000, 0, 100, 100));
271 RunEvictionIteratorConstructTest("9999_0_100x100",
272 gfx::Rect(9999, 0, 100, 100));