1 // Copyright 2013 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/debug/lap_timer.h"
6 #include "cc/resources/picture_layer_tiling.h"
7 #include "cc/resources/resource_provider.h"
8 #include "cc/resources/scoped_resource.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_output_surface_client.h"
11 #include "cc/test/fake_picture_layer_tiling_client.h"
12 #include "cc/test/test_context_provider.h"
13 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #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 class PictureLayerTilingPerfTest
: public testing::Test
{
28 PictureLayerTilingPerfTest()
30 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
32 context_provider_(TestContextProvider::Create()) {
33 output_surface_
= FakeOutputSurface::Create3d(context_provider_
).Pass();
34 CHECK(output_surface_
->BindToClient(&output_surface_client_
));
36 shared_bitmap_manager_
.reset(new TestSharedBitmapManager());
37 resource_provider_
= ResourceProvider::Create(output_surface_
.get(),
38 shared_bitmap_manager_
.get(),
46 void SetUp() override
{
47 picture_layer_tiling_client_
.SetTileSize(gfx::Size(256, 256));
48 picture_layer_tiling_client_
.set_max_tiles_for_interest_area(250);
49 picture_layer_tiling_client_
.set_tree(PENDING_TREE
);
50 picture_layer_tiling_
= PictureLayerTiling::Create(
51 1, gfx::Size(256 * 50, 256 * 50), &picture_layer_tiling_client_
);
52 picture_layer_tiling_
->CreateAllTilesForTesting();
55 void TearDown() override
{ picture_layer_tiling_
.reset(NULL
); }
57 void RunInvalidateTest(const std::string
& test_name
, const Region
& region
) {
60 picture_layer_tiling_
->UpdateTilesToCurrentRasterSource(
61 picture_layer_tiling_client_
.raster_source(), region
,
62 picture_layer_tiling_
->tiling_size());
64 } while (!timer_
.HasTimeLimitExpired());
66 perf_test::PrintResult(
67 "invalidation", "", test_name
, timer_
.LapsPerSecond(), "runs/s", true);
70 void RunComputeTilePriorityRectsStationaryTest(
71 const std::string
& test_name
,
72 const gfx::Transform
& transform
) {
73 gfx::Rect
viewport_rect(0, 0, 1024, 768);
77 picture_layer_tiling_
->ComputeTilePriorityRects(
78 viewport_rect
, 1.f
, timer_
.NumLaps() + 1, Occlusion());
80 } while (!timer_
.HasTimeLimitExpired());
82 perf_test::PrintResult("compute_tile_priority_rects_stationary",
85 timer_
.LapsPerSecond(),
90 void RunComputeTilePriorityRectsScrollingTest(
91 const std::string
& test_name
,
92 const gfx::Transform
& transform
) {
93 gfx::Size
viewport_size(1024, 768);
94 gfx::Rect
viewport_rect(viewport_size
);
95 int xoffsets
[] = {10, 0, -10, 0};
96 int yoffsets
[] = {0, 10, 0, -10};
99 const int maxOffsetCount
= 1000;
103 picture_layer_tiling_
->ComputeTilePriorityRects(
104 viewport_rect
, 1.f
, timer_
.NumLaps() + 1, Occlusion());
106 viewport_rect
= gfx::Rect(viewport_rect
.x() + xoffsets
[offsetIndex
],
107 viewport_rect
.y() + yoffsets
[offsetIndex
],
108 viewport_rect
.width(),
109 viewport_rect
.height());
111 if (++offsetCount
> maxOffsetCount
) {
113 offsetIndex
= (offsetIndex
+ 1) % 4;
116 } while (!timer_
.HasTimeLimitExpired());
118 perf_test::PrintResult("compute_tile_priority_rects_scrolling",
121 timer_
.LapsPerSecond(),
126 void RunRasterIteratorConstructTest(const std::string
& test_name
,
127 const gfx::Rect
& viewport
) {
128 gfx::Size
bounds(viewport
.size());
129 picture_layer_tiling_
=
130 PictureLayerTiling::Create(1, bounds
, &picture_layer_tiling_client_
);
131 picture_layer_tiling_client_
.set_tree(ACTIVE_TREE
);
132 picture_layer_tiling_
->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
137 PictureLayerTiling::TilingRasterTileIterator
it(
138 picture_layer_tiling_
.get());
140 } while (!timer_
.HasTimeLimitExpired());
142 perf_test::PrintResult("tiling_raster_tile_iterator_construct",
145 timer_
.LapsPerSecond(),
150 void RunRasterIteratorConstructAndIterateTest(const std::string
& test_name
,
152 const gfx::Rect
& viewport
) {
153 gfx::Size
bounds(10000, 10000);
154 picture_layer_tiling_
=
155 PictureLayerTiling::Create(1, bounds
, &picture_layer_tiling_client_
);
156 picture_layer_tiling_client_
.set_tree(ACTIVE_TREE
);
157 picture_layer_tiling_
->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
162 int count
= num_tiles
;
163 PictureLayerTiling::TilingRasterTileIterator
it(
164 picture_layer_tiling_
.get());
166 ASSERT_TRUE(it
) << "count: " << count
;
167 ASSERT_TRUE(*it
!= NULL
) << "count: " << count
;
171 } while (!timer_
.HasTimeLimitExpired());
173 perf_test::PrintResult("tiling_raster_tile_iterator_construct_and_iterate",
176 timer_
.LapsPerSecond(),
181 void RunEvictionIteratorConstructTest(const std::string
& test_name
,
182 const gfx::Rect
& viewport
) {
183 gfx::Size
bounds(viewport
.size());
184 picture_layer_tiling_
=
185 PictureLayerTiling::Create(1, bounds
, &picture_layer_tiling_client_
);
186 picture_layer_tiling_client_
.set_tree(ACTIVE_TREE
);
187 picture_layer_tiling_
->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
191 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
192 SMOOTHNESS_TAKES_PRIORITY
,
193 NEW_CONTENT_TAKES_PRIORITY
};
194 int priority_count
= 0;
196 PictureLayerTiling::TilingEvictionTileIterator
it(
197 picture_layer_tiling_
.get(),
198 priorities
[priority_count
],
199 PictureLayerTiling::NOW
);
200 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
202 } while (!timer_
.HasTimeLimitExpired());
204 perf_test::PrintResult("tiling_eviction_tile_iterator_construct",
207 timer_
.LapsPerSecond(),
212 void RunEvictionIteratorConstructAndIterateTest(const std::string
& test_name
,
214 const gfx::Rect
& viewport
) {
215 gfx::Size
bounds(10000, 10000);
216 picture_layer_tiling_
=
217 PictureLayerTiling::Create(1, bounds
, &picture_layer_tiling_client_
);
218 picture_layer_tiling_client_
.set_tree(ACTIVE_TREE
);
219 picture_layer_tiling_
->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
222 TreePriority priorities
[] = {SAME_PRIORITY_FOR_BOTH_TREES
,
223 SMOOTHNESS_TAKES_PRIORITY
,
224 NEW_CONTENT_TAKES_PRIORITY
};
226 // Ensure all tiles have resources.
227 std::vector
<Tile
*> all_tiles
= picture_layer_tiling_
->AllTilesForTesting();
228 for (std::vector
<Tile
*>::iterator tile_it
= all_tiles
.begin();
229 tile_it
!= all_tiles
.end();
231 Tile
* tile
= *tile_it
;
232 ManagedTileState::DrawInfo
& draw_info
= tile
->draw_info();
233 draw_info
.SetResourceForTesting(
234 ScopedResource::Create(resource_provider_
.get()).Pass());
237 int priority_count
= 0;
240 int count
= num_tiles
;
241 PictureLayerTiling::TilingEvictionTileIterator
it(
242 picture_layer_tiling_
.get(),
243 priorities
[priority_count
],
244 PictureLayerTiling::EVENTUALLY
);
246 ASSERT_TRUE(it
) << "count: " << count
;
247 ASSERT_TRUE(*it
!= NULL
) << "count: " << count
;
250 priority_count
= (priority_count
+ 1) % arraysize(priorities
);
252 } while (!timer_
.HasTimeLimitExpired());
254 // Remove all resources from tiles to make sure the tile version destructor
256 for (std::vector
<Tile
*>::iterator tile_it
= all_tiles
.begin();
257 tile_it
!= all_tiles
.end();
259 Tile
* tile
= *tile_it
;
260 ManagedTileState::DrawInfo
& draw_info
= tile
->draw_info();
261 draw_info
.SetResourceForTesting(nullptr);
264 perf_test::PrintResult(
265 "tiling_eviction_tile_iterator_construct_and_iterate",
268 timer_
.LapsPerSecond(),
274 FakePictureLayerTilingClient picture_layer_tiling_client_
;
275 scoped_ptr
<PictureLayerTiling
> picture_layer_tiling_
;
279 scoped_refptr
<ContextProvider
> context_provider_
;
280 FakeOutputSurfaceClient output_surface_client_
;
281 scoped_ptr
<FakeOutputSurface
> output_surface_
;
282 scoped_ptr
<SharedBitmapManager
> shared_bitmap_manager_
;
283 scoped_ptr
<ResourceProvider
> resource_provider_
;
286 TEST_F(PictureLayerTilingPerfTest
, Invalidate
) {
287 Region
one_tile(gfx::Rect(256, 256));
288 RunInvalidateTest("1x1", one_tile
);
290 Region
half_region(gfx::Rect(25 * 256, 50 * 256));
291 RunInvalidateTest("25x50", half_region
);
293 Region
full_region(gfx::Rect(50 * 256, 50 * 256));
294 RunInvalidateTest("50x50", full_region
);
297 #if defined(OS_ANDROID)
298 // TODO(vmpstr): Investigate why this is noisy (crbug.com/310220).
299 TEST_F(PictureLayerTilingPerfTest
, DISABLED_ComputeTilePriorityRects
) {
301 TEST_F(PictureLayerTilingPerfTest
, ComputeTilePriorityRects
) {
302 #endif // defined(OS_ANDROID)
303 gfx::Transform transform
;
305 RunComputeTilePriorityRectsStationaryTest("no_transform", transform
);
306 RunComputeTilePriorityRectsScrollingTest("no_transform", transform
);
308 transform
.Rotate(10);
309 RunComputeTilePriorityRectsStationaryTest("rotation", transform
);
310 RunComputeTilePriorityRectsScrollingTest("rotation", transform
);
312 transform
.ApplyPerspectiveDepth(10);
313 RunComputeTilePriorityRectsStationaryTest("perspective", transform
);
314 RunComputeTilePriorityRectsScrollingTest("perspective", transform
);
317 TEST_F(PictureLayerTilingPerfTest
, TilingRasterTileIteratorConstruct
) {
318 RunRasterIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
319 RunRasterIteratorConstructTest("50_0_100x100", gfx::Rect(50, 0, 100, 100));
320 RunRasterIteratorConstructTest("100_0_100x100", gfx::Rect(100, 0, 100, 100));
321 RunRasterIteratorConstructTest("150_0_100x100", gfx::Rect(150, 0, 100, 100));
324 TEST_F(PictureLayerTilingPerfTest
,
325 TilingRasterTileIteratorConstructAndIterate
) {
326 RunRasterIteratorConstructAndIterateTest(
327 "32_100x100", 32, gfx::Rect(0, 0, 100, 100));
328 RunRasterIteratorConstructAndIterateTest(
329 "32_500x500", 32, gfx::Rect(0, 0, 500, 500));
330 RunRasterIteratorConstructAndIterateTest(
331 "64_100x100", 64, gfx::Rect(0, 0, 100, 100));
332 RunRasterIteratorConstructAndIterateTest(
333 "64_500x500", 64, gfx::Rect(0, 0, 500, 500));
336 TEST_F(PictureLayerTilingPerfTest
, TilingEvictionTileIteratorConstruct
) {
337 RunEvictionIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
338 RunEvictionIteratorConstructTest("50_0_100x100", gfx::Rect(50, 0, 100, 100));
339 RunEvictionIteratorConstructTest("100_0_100x100",
340 gfx::Rect(100, 0, 100, 100));
341 RunEvictionIteratorConstructTest("150_0_100x100",
342 gfx::Rect(150, 0, 100, 100));
345 TEST_F(PictureLayerTilingPerfTest
,
346 TilingEvictionTileIteratorConstructAndIterate
) {
347 RunEvictionIteratorConstructAndIterateTest(
348 "32_100x100", 32, gfx::Rect(0, 0, 100, 100));
349 RunEvictionIteratorConstructAndIterateTest(
350 "32_500x500", 32, gfx::Rect(0, 0, 500, 500));
351 RunEvictionIteratorConstructAndIterateTest(
352 "64_100x100", 64, gfx::Rect(0, 0, 100, 100));
353 RunEvictionIteratorConstructAndIterateTest(
354 "64_500x500", 64, gfx::Rect(0, 0, 500, 500));