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/trees/layer_tree_impl.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/perf/perf_test.h"
23 static const int kTimeLimitMillis
= 2000;
24 static const int kWarmupRuns
= 5;
25 static const int kTimeCheckInterval
= 10;
27 void AddTiling(float scale
,
28 FakePictureLayerImpl
* layer
,
29 std::vector
<Tile
*>* all_tiles
) {
30 PictureLayerTiling
* tiling
= layer
->AddTiling(scale
);
32 tiling
->CreateAllTilesForTesting();
33 std::vector
<Tile
*> tiling_tiles
= tiling
->AllTilesForTesting();
35 tiling_tiles
.begin(), tiling_tiles
.end(), std::back_inserter(*all_tiles
));
38 class PictureLayerImplPerfTest
: public testing::Test
{
40 PictureLayerImplPerfTest()
41 : proxy_(base::MessageLoopProxy::current()),
42 host_impl_(ImplSidePaintingSettings(),
44 &shared_bitmap_manager_
),
46 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
47 kTimeCheckInterval
) {}
49 void SetUp() override
{
50 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
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::CreateWithRasterSource(pending_tree
, 7, pile
);
63 pending_layer
->SetDrawsContent(true);
64 pending_layer
->SetHasRenderSurface(true);
65 pending_tree
->SetRootLayer(pending_layer
.Pass());
67 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
68 host_impl_
.pending_tree()->LayerById(7));
71 void RunRasterQueueConstructAndIterateTest(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 scoped_ptr
<TilingSetRasterQueue
> queue(new TilingSetRasterQueueAll(
81 pending_layer_
->picture_layer_tiling_set(), false));
83 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
84 ASSERT_TRUE(queue
->Top() != nullptr) << "count: " << count
;
88 } while (!timer_
.HasTimeLimitExpired());
90 perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
91 test_name
, timer_
.LapsPerSecond(), "runs/s", true);
94 void RunRasterQueueConstructTest(const std::string
& test_name
,
95 const gfx::Rect
& viewport
) {
96 host_impl_
.SetViewportSize(viewport
.size());
97 pending_layer_
->SetScrollOffset(
98 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
99 host_impl_
.pending_tree()->UpdateDrawProperties();
103 scoped_ptr
<TilingSetRasterQueue
> queue(new TilingSetRasterQueueAll(
104 pending_layer_
->picture_layer_tiling_set(), false));
106 } while (!timer_
.HasTimeLimitExpired());
108 perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name
,
109 timer_
.LapsPerSecond(), "runs/s", true);
112 void RunEvictionQueueConstructAndIterateTest(
113 const std::string
& test_name
,
115 const gfx::Size
& viewport_size
) {
116 host_impl_
.SetViewportSize(viewport_size
);
117 host_impl_
.pending_tree()->UpdateDrawProperties();
119 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
120 SMOOTHNESS_TAKES_PRIORITY
,
121 NEW_CONTENT_TAKES_PRIORITY
};
122 int priority_count
= 0;
125 int count
= num_tiles
;
126 scoped_ptr
<TilingSetEvictionQueue
> queue(
127 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set(),
128 priorities
[priority_count
], false));
130 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
131 ASSERT_TRUE(queue
->Top() != nullptr) << "count: " << count
;
134 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
136 } while (!timer_
.HasTimeLimitExpired());
138 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
139 "", test_name
, timer_
.LapsPerSecond(), "runs/s",
143 void RunEvictionQueueConstructTest(const std::string
& test_name
,
144 const gfx::Rect
& viewport
) {
145 host_impl_
.SetViewportSize(viewport
.size());
146 pending_layer_
->SetScrollOffset(
147 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
148 host_impl_
.pending_tree()->UpdateDrawProperties();
150 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
151 SMOOTHNESS_TAKES_PRIORITY
,
152 NEW_CONTENT_TAKES_PRIORITY
};
153 int priority_count
= 0;
156 scoped_ptr
<TilingSetEvictionQueue
> queue(
157 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set(),
158 priorities
[priority_count
], false));
159 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
161 } while (!timer_
.HasTimeLimitExpired());
163 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name
,
164 timer_
.LapsPerSecond(), "runs/s", true);
168 TestSharedBitmapManager shared_bitmap_manager_
;
169 FakeImplProxy proxy_
;
170 FakeLayerTreeHostImpl host_impl_
;
171 FakePictureLayerImpl
* pending_layer_
;
175 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
178 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstructAndIterate
) {
179 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
181 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
183 pending_layer_
->AddTiling(low_res_factor
);
184 pending_layer_
->AddTiling(0.3f
);
185 pending_layer_
->AddTiling(0.7f
);
186 pending_layer_
->AddTiling(1.0f
);
187 pending_layer_
->AddTiling(2.0f
);
189 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
190 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
191 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
192 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
195 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstruct
) {
196 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
198 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
200 pending_layer_
->AddTiling(low_res_factor
);
201 pending_layer_
->AddTiling(0.3f
);
202 pending_layer_
->AddTiling(0.7f
);
203 pending_layer_
->AddTiling(1.0f
);
204 pending_layer_
->AddTiling(2.0f
);
206 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
207 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
208 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
211 TEST_F(PictureLayerImplPerfTest
, TilingSetEvictionQueueConstructAndIterate
) {
212 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
214 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
216 std::vector
<Tile
*> all_tiles
;
217 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
218 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
219 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
220 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
221 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
223 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
224 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
226 RunEvictionQueueConstructAndIterateTest(
227 "32_100x100", 32, gfx::Size(100, 100));
228 RunEvictionQueueConstructAndIterateTest(
229 "32_500x500", 32, gfx::Size(500, 500));
230 RunEvictionQueueConstructAndIterateTest(
231 "64_100x100", 64, gfx::Size(100, 100));
232 RunEvictionQueueConstructAndIterateTest(
233 "64_500x500", 64, gfx::Size(500, 500));
236 TEST_F(PictureLayerImplPerfTest
, TilingSetEvictionQueueConstruct
) {
237 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
239 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
241 std::vector
<Tile
*> all_tiles
;
242 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
243 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
244 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
245 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
246 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
248 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
249 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
251 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
252 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
253 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));