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 virtual void SetUp() OVERRIDE
{
49 host_impl_
.InitializeRenderer(
50 FakeOutputSurface::Create3d().PassAs
<OutputSurface
>());
53 void SetupPendingTree(const gfx::Size
& layer_bounds
,
54 const gfx::Size
& tile_size
) {
55 scoped_refptr
<FakePicturePileImpl
> pile
=
56 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
57 host_impl_
.CreatePendingTree();
58 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
59 pending_tree
->DetachLayerTree();
61 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
62 FakePictureLayerImpl::CreateWithPile(pending_tree
, 7, pile
);
63 pending_layer
->SetDrawsContent(true);
64 pending_tree
->SetRootLayer(pending_layer
.PassAs
<LayerImpl
>());
66 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
67 host_impl_
.pending_tree()->LayerById(7));
68 pending_layer_
->DoPostCommitInitializationIfNeeded();
71 void RunRasterIteratorConstructAndIterateTest(
72 const std::string
& test_name
,
74 const gfx::Size
& viewport_size
) {
75 host_impl_
.SetViewportSize(viewport_size
);
76 host_impl_
.pending_tree()->UpdateDrawProperties();
80 int count
= num_tiles
;
81 PictureLayerImpl::LayerRasterTileIterator
it(pending_layer_
, false);
83 ASSERT_TRUE(it
) << "count: " << count
;
84 ASSERT_TRUE(*it
!= NULL
) << "count: " << count
;
88 } while (!timer_
.HasTimeLimitExpired());
90 perf_test::PrintResult("layer_raster_tile_iterator_construct_and_iterate",
93 timer_
.LapsPerSecond(),
98 void RunRasterIteratorConstructTest(const std::string
& test_name
,
99 const gfx::Rect
& viewport
) {
100 host_impl_
.SetViewportSize(viewport
.size());
101 pending_layer_
->SetScrollOffset(gfx::Vector2d(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
!= NULL
) << "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(gfx::Vector2d(viewport
.x(), viewport
.y()));
155 host_impl_
.pending_tree()->UpdateDrawProperties();
157 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
158 SMOOTHNESS_TAKES_PRIORITY
,
159 NEW_CONTENT_TAKES_PRIORITY
};
160 int priority_count
= 0;
163 PictureLayerImpl::LayerEvictionTileIterator
it(
164 pending_layer_
, priorities
[priority_count
]);
165 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
167 } while (!timer_
.HasTimeLimitExpired());
169 perf_test::PrintResult("layer_eviction_tile_iterator_construct",
172 timer_
.LapsPerSecond(),
178 TestSharedBitmapManager shared_bitmap_manager_
;
179 FakeImplProxy proxy_
;
180 FakeLayerTreeHostImpl host_impl_
;
181 FakePictureLayerImpl
* pending_layer_
;
185 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
188 TEST_F(PictureLayerImplPerfTest
, LayerRasterTileIteratorConstructAndIterate
) {
189 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
191 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
193 pending_layer_
->AddTiling(low_res_factor
);
194 pending_layer_
->AddTiling(0.3f
);
195 pending_layer_
->AddTiling(0.7f
);
196 pending_layer_
->AddTiling(1.0f
);
197 pending_layer_
->AddTiling(2.0f
);
199 RunRasterIteratorConstructAndIterateTest(
200 "32_100x100", 32, gfx::Size(100, 100));
201 RunRasterIteratorConstructAndIterateTest(
202 "32_500x500", 32, gfx::Size(500, 500));
203 RunRasterIteratorConstructAndIterateTest(
204 "64_100x100", 64, gfx::Size(100, 100));
205 RunRasterIteratorConstructAndIterateTest(
206 "64_500x500", 64, gfx::Size(500, 500));
209 TEST_F(PictureLayerImplPerfTest
, LayerRasterTileIteratorConstruct
) {
210 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
212 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
214 pending_layer_
->AddTiling(low_res_factor
);
215 pending_layer_
->AddTiling(0.3f
);
216 pending_layer_
->AddTiling(0.7f
);
217 pending_layer_
->AddTiling(1.0f
);
218 pending_layer_
->AddTiling(2.0f
);
220 RunRasterIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
221 RunRasterIteratorConstructTest("5000_0_100x100",
222 gfx::Rect(5000, 0, 100, 100));
223 RunRasterIteratorConstructTest("9999_0_100x100",
224 gfx::Rect(9999, 0, 100, 100));
227 TEST_F(PictureLayerImplPerfTest
, LayerEvictionTileIteratorConstructAndIterate
) {
228 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
230 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
232 std::vector
<Tile
*> all_tiles
;
233 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
234 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
235 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
236 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
237 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
239 ASSERT_TRUE(host_impl_
.tile_manager() != NULL
);
240 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
242 RunEvictionIteratorConstructAndIterateTest(
243 "32_100x100", 32, gfx::Size(100, 100));
244 RunEvictionIteratorConstructAndIterateTest(
245 "32_500x500", 32, gfx::Size(500, 500));
246 RunEvictionIteratorConstructAndIterateTest(
247 "64_100x100", 64, gfx::Size(100, 100));
248 RunEvictionIteratorConstructAndIterateTest(
249 "64_500x500", 64, gfx::Size(500, 500));
252 TEST_F(PictureLayerImplPerfTest
, LayerEvictionTileIteratorConstruct
) {
253 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
255 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
257 std::vector
<Tile
*> all_tiles
;
258 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
259 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
260 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
261 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
262 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
264 ASSERT_TRUE(host_impl_
.tile_manager() != NULL
);
265 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
267 RunEvictionIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
268 RunEvictionIteratorConstructTest("5000_0_100x100",
269 gfx::Rect(5000, 0, 100, 100));
270 RunEvictionIteratorConstructTest("9999_0_100x100",
271 gfx::Rect(9999, 0, 100, 100));