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/resource_provider.h"
7 #include "cc/resources/scoped_resource.h"
8 #include "cc/test/fake_output_surface.h"
9 #include "cc/test/fake_output_surface_client.h"
10 #include "cc/test/fake_picture_layer_tiling_client.h"
11 #include "cc/test/fake_picture_pile_impl.h"
12 #include "cc/test/fake_resource_provider.h"
13 #include "cc/test/test_context_provider.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/tiles/picture_layer_tiling.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #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 class PictureLayerTilingPerfTest
: public testing::Test
{
30 PictureLayerTilingPerfTest()
32 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
34 context_provider_(TestContextProvider::Create()) {
35 output_surface_
= FakeOutputSurface::Create3d(context_provider_
).Pass();
36 CHECK(output_surface_
->BindToClient(&output_surface_client_
));
38 shared_bitmap_manager_
.reset(new TestSharedBitmapManager());
39 resource_provider_
= FakeResourceProvider::Create(
40 output_surface_
.get(), shared_bitmap_manager_
.get());
43 void SetUp() override
{
44 LayerTreeSettings defaults
;
45 picture_layer_tiling_client_
.SetTileSize(gfx::Size(256, 256));
46 scoped_refptr
<FakePicturePileImpl
> pile
=
47 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
48 gfx::Size(256 * 50, 256 * 50));
49 picture_layer_tiling_
= PictureLayerTiling::Create(
50 PENDING_TREE
, 1.f
, pile
, &picture_layer_tiling_client_
,
51 defaults
.tiling_interest_area_viewport_multiplier
,
52 defaults
.skewport_target_time_in_seconds
,
53 defaults
.skewport_extrapolation_limit_in_content_pixels
);
54 picture_layer_tiling_
->CreateAllTilesForTesting();
57 void TearDown() override
{ picture_layer_tiling_
.reset(NULL
); }
59 void RunInvalidateTest(const std::string
& test_name
, const Region
& region
) {
62 picture_layer_tiling_
->Invalidate(region
);
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 max_offset_count
= 1000;
103 picture_layer_tiling_
->ComputeTilePriorityRects(
104 viewport_rect
, 1.f
, timer_
.NumLaps() + 1, Occlusion());
106 viewport_rect
= gfx::Rect(viewport_rect
.x() + xoffsets
[offset_index
],
107 viewport_rect
.y() + yoffsets
[offset_index
],
108 viewport_rect
.width(), viewport_rect
.height());
110 if (++offset_count
> max_offset_count
) {
112 offset_index
= (offset_index
+ 1) % 4;
115 } while (!timer_
.HasTimeLimitExpired());
117 perf_test::PrintResult("compute_tile_priority_rects_scrolling",
120 timer_
.LapsPerSecond(),
126 FakePictureLayerTilingClient picture_layer_tiling_client_
;
127 scoped_ptr
<PictureLayerTiling
> picture_layer_tiling_
;
131 scoped_refptr
<ContextProvider
> context_provider_
;
132 FakeOutputSurfaceClient output_surface_client_
;
133 scoped_ptr
<FakeOutputSurface
> output_surface_
;
134 scoped_ptr
<SharedBitmapManager
> shared_bitmap_manager_
;
135 scoped_ptr
<ResourceProvider
> resource_provider_
;
138 TEST_F(PictureLayerTilingPerfTest
, Invalidate
) {
139 Region
one_tile(gfx::Rect(256, 256));
140 RunInvalidateTest("1x1", one_tile
);
142 Region
half_region(gfx::Rect(25 * 256, 50 * 256));
143 RunInvalidateTest("25x50", half_region
);
145 Region
full_region(gfx::Rect(50 * 256, 50 * 256));
146 RunInvalidateTest("50x50", full_region
);
149 #if defined(OS_ANDROID)
150 // TODO(vmpstr): Investigate why this is noisy (crbug.com/310220).
151 TEST_F(PictureLayerTilingPerfTest
, DISABLED_ComputeTilePriorityRects
) {
153 TEST_F(PictureLayerTilingPerfTest
, ComputeTilePriorityRects
) {
154 #endif // defined(OS_ANDROID)
155 gfx::Transform transform
;
157 RunComputeTilePriorityRectsStationaryTest("no_transform", transform
);
158 RunComputeTilePriorityRectsScrollingTest("no_transform", transform
);
160 transform
.Rotate(10);
161 RunComputeTilePriorityRectsStationaryTest("rotation", transform
);
162 RunComputeTilePriorityRectsScrollingTest("rotation", transform
);
164 transform
.ApplyPerspectiveDepth(10);
165 RunComputeTilePriorityRectsStationaryTest("perspective", transform
);
166 RunComputeTilePriorityRectsScrollingTest("perspective", transform
);