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 LayerTreeSettingsWithLargeInterestArea
: public LayerTreeSettings
{
41 LayerTreeSettingsWithLargeInterestArea() {
42 tiling_interest_area_viewport_multiplier
= 10000;
46 class PictureLayerImplPerfTest
: public testing::Test
{
48 PictureLayerImplPerfTest()
49 : proxy_(base::ThreadTaskRunnerHandle::Get()),
50 host_impl_(LayerTreeSettingsWithLargeInterestArea(),
52 &shared_bitmap_manager_
,
55 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
56 kTimeCheckInterval
) {}
58 void SetUp() override
{
59 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
62 void SetupPendingTree(const gfx::Size
& layer_bounds
,
63 const gfx::Size
& tile_size
) {
64 scoped_refptr
<FakePicturePileImpl
> pile
=
65 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
66 host_impl_
.CreatePendingTree();
67 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
68 pending_tree
->DetachLayerTree();
70 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
71 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, 7, pile
);
72 pending_layer
->SetDrawsContent(true);
73 pending_layer
->SetHasRenderSurface(true);
74 pending_tree
->SetRootLayer(pending_layer
.Pass());
76 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
77 host_impl_
.pending_tree()->LayerById(7));
80 void RunRasterQueueConstructAndIterateTest(const std::string
& test_name
,
82 const gfx::Size
& viewport_size
) {
83 host_impl_
.SetViewportSize(viewport_size
);
84 bool update_lcd_text
= false;
85 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
89 int count
= num_tiles
;
90 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
91 pending_layer_
->picture_layer_tiling_set(), false));
93 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
94 ASSERT_TRUE(queue
->Top().tile()) << "count: " << count
;
98 } while (!timer_
.HasTimeLimitExpired());
100 perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
101 test_name
, timer_
.LapsPerSecond(), "runs/s", true);
104 void RunRasterQueueConstructTest(const std::string
& test_name
,
105 const gfx::Rect
& viewport
) {
106 host_impl_
.SetViewportSize(viewport
.size());
107 pending_layer_
->PushScrollOffsetFromMainThread(
108 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
109 bool update_lcd_text
= false;
110 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
114 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
115 pending_layer_
->picture_layer_tiling_set(), false));
117 } while (!timer_
.HasTimeLimitExpired());
119 perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name
,
120 timer_
.LapsPerSecond(), "runs/s", true);
123 void RunEvictionQueueConstructAndIterateTest(
124 const std::string
& test_name
,
126 const gfx::Size
& viewport_size
) {
127 host_impl_
.SetViewportSize(viewport_size
);
128 bool update_lcd_text
= false;
129 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
133 int count
= num_tiles
;
134 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
135 pending_layer_
->picture_layer_tiling_set()));
137 ASSERT_TRUE(!queue
->IsEmpty()) << "count: " << count
;
138 ASSERT_TRUE(queue
->Top().tile()) << "count: " << count
;
142 } while (!timer_
.HasTimeLimitExpired());
144 perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
145 "", test_name
, timer_
.LapsPerSecond(), "runs/s",
149 void RunEvictionQueueConstructTest(const std::string
& test_name
,
150 const gfx::Rect
& viewport
) {
151 host_impl_
.SetViewportSize(viewport
.size());
152 pending_layer_
->PushScrollOffsetFromMainThread(
153 gfx::ScrollOffset(viewport
.x(), viewport
.y()));
154 bool update_lcd_text
= false;
155 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
159 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
160 pending_layer_
->picture_layer_tiling_set()));
162 } while (!timer_
.HasTimeLimitExpired());
164 perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name
,
165 timer_
.LapsPerSecond(), "runs/s", true);
169 TestSharedBitmapManager shared_bitmap_manager_
;
170 TestTaskGraphRunner task_graph_runner_
;
171 FakeImplProxy proxy_
;
172 FakeLayerTreeHostImpl host_impl_
;
173 FakePictureLayerImpl
* pending_layer_
;
177 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
180 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstructAndIterate
) {
181 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
183 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
185 pending_layer_
->AddTiling(low_res_factor
);
186 pending_layer_
->AddTiling(0.3f
);
187 pending_layer_
->AddTiling(0.7f
);
188 pending_layer_
->AddTiling(1.0f
);
189 pending_layer_
->AddTiling(2.0f
);
191 RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
192 RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
193 RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
194 RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
197 TEST_F(PictureLayerImplPerfTest
, TilingSetRasterQueueConstruct
) {
198 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
200 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
202 pending_layer_
->AddTiling(low_res_factor
);
203 pending_layer_
->AddTiling(0.3f
);
204 pending_layer_
->AddTiling(0.7f
);
205 pending_layer_
->AddTiling(1.0f
);
206 pending_layer_
->AddTiling(2.0f
);
208 RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
209 RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
210 RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
213 TEST_F(PictureLayerImplPerfTest
, TilingSetEvictionQueueConstructAndIterate
) {
214 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
216 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
218 std::vector
<Tile
*> all_tiles
;
219 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
220 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
221 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
222 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
223 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
225 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
226 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
228 RunEvictionQueueConstructAndIterateTest(
229 "32_100x100", 32, gfx::Size(100, 100));
230 RunEvictionQueueConstructAndIterateTest(
231 "32_500x500", 32, gfx::Size(500, 500));
232 RunEvictionQueueConstructAndIterateTest(
233 "64_100x100", 64, gfx::Size(100, 100));
234 RunEvictionQueueConstructAndIterateTest(
235 "64_500x500", 64, gfx::Size(500, 500));
238 TEST_F(PictureLayerImplPerfTest
, TilingSetEvictionQueueConstruct
) {
239 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
241 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
243 std::vector
<Tile
*> all_tiles
;
244 AddTiling(low_res_factor
, pending_layer_
, &all_tiles
);
245 AddTiling(0.3f
, pending_layer_
, &all_tiles
);
246 AddTiling(0.7f
, pending_layer_
, &all_tiles
);
247 AddTiling(1.0f
, pending_layer_
, &all_tiles
);
248 AddTiling(2.0f
, pending_layer_
, &all_tiles
);
250 ASSERT_TRUE(host_impl_
.tile_manager() != nullptr);
251 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
253 RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
254 RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
255 RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));