Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / cc / resources / picture_layer_tiling_perftest.cc
blob4db7fe6e62221302cb226b5038059be7f371df29
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/fake_picture_pile_impl.h"
13 #include "cc/test/test_context_provider.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
19 namespace cc {
21 namespace {
23 static const int kTimeLimitMillis = 2000;
24 static const int kWarmupRuns = 5;
25 static const int kTimeCheckInterval = 10;
27 class PictureLayerTilingPerfTest : public testing::Test {
28 public:
29 PictureLayerTilingPerfTest()
30 : timer_(kWarmupRuns,
31 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
32 kTimeCheckInterval),
33 context_provider_(TestContextProvider::Create()) {
34 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass();
35 CHECK(output_surface_->BindToClient(&output_surface_client_));
37 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
38 resource_provider_ = ResourceProvider::Create(output_surface_.get(),
39 shared_bitmap_manager_.get(),
40 NULL,
41 NULL,
43 false,
44 1).Pass();
47 void SetUp() override {
48 LayerTreeSettings defaults;
49 picture_layer_tiling_client_.SetTileSize(gfx::Size(256, 256));
50 picture_layer_tiling_client_.set_tree(PENDING_TREE);
51 scoped_refptr<FakePicturePileImpl> pile =
52 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
53 gfx::Size(256 * 50, 256 * 50));
54 picture_layer_tiling_ = PictureLayerTiling::Create(
55 1, pile, &picture_layer_tiling_client_,
56 defaults.max_tiles_for_interest_area,
57 defaults.skewport_target_time_in_seconds,
58 defaults.skewport_extrapolation_limit_in_content_pixels);
59 picture_layer_tiling_->CreateAllTilesForTesting();
62 void TearDown() override { picture_layer_tiling_.reset(NULL); }
64 void RunInvalidateTest(const std::string& test_name, const Region& region) {
65 timer_.Reset();
66 do {
67 picture_layer_tiling_->Invalidate(region);
68 timer_.NextLap();
69 } while (!timer_.HasTimeLimitExpired());
71 perf_test::PrintResult(
72 "invalidation", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
75 void RunComputeTilePriorityRectsStationaryTest(
76 const std::string& test_name,
77 const gfx::Transform& transform) {
78 gfx::Rect viewport_rect(0, 0, 1024, 768);
80 timer_.Reset();
81 do {
82 picture_layer_tiling_->ComputeTilePriorityRects(
83 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
84 timer_.NextLap();
85 } while (!timer_.HasTimeLimitExpired());
87 perf_test::PrintResult("compute_tile_priority_rects_stationary",
88 "",
89 test_name,
90 timer_.LapsPerSecond(),
91 "runs/s",
92 true);
95 void RunComputeTilePriorityRectsScrollingTest(
96 const std::string& test_name,
97 const gfx::Transform& transform) {
98 gfx::Size viewport_size(1024, 768);
99 gfx::Rect viewport_rect(viewport_size);
100 int xoffsets[] = {10, 0, -10, 0};
101 int yoffsets[] = {0, 10, 0, -10};
102 int offsetIndex = 0;
103 int offsetCount = 0;
104 const int maxOffsetCount = 1000;
106 timer_.Reset();
107 do {
108 picture_layer_tiling_->ComputeTilePriorityRects(
109 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
111 viewport_rect = gfx::Rect(viewport_rect.x() + xoffsets[offsetIndex],
112 viewport_rect.y() + yoffsets[offsetIndex],
113 viewport_rect.width(),
114 viewport_rect.height());
116 if (++offsetCount > maxOffsetCount) {
117 offsetCount = 0;
118 offsetIndex = (offsetIndex + 1) % 4;
120 timer_.NextLap();
121 } while (!timer_.HasTimeLimitExpired());
123 perf_test::PrintResult("compute_tile_priority_rects_scrolling",
125 test_name,
126 timer_.LapsPerSecond(),
127 "runs/s",
128 true);
131 private:
132 FakePictureLayerTilingClient picture_layer_tiling_client_;
133 scoped_ptr<PictureLayerTiling> picture_layer_tiling_;
135 LapTimer timer_;
137 scoped_refptr<ContextProvider> context_provider_;
138 FakeOutputSurfaceClient output_surface_client_;
139 scoped_ptr<FakeOutputSurface> output_surface_;
140 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
141 scoped_ptr<ResourceProvider> resource_provider_;
144 TEST_F(PictureLayerTilingPerfTest, Invalidate) {
145 Region one_tile(gfx::Rect(256, 256));
146 RunInvalidateTest("1x1", one_tile);
148 Region half_region(gfx::Rect(25 * 256, 50 * 256));
149 RunInvalidateTest("25x50", half_region);
151 Region full_region(gfx::Rect(50 * 256, 50 * 256));
152 RunInvalidateTest("50x50", full_region);
155 #if defined(OS_ANDROID)
156 // TODO(vmpstr): Investigate why this is noisy (crbug.com/310220).
157 TEST_F(PictureLayerTilingPerfTest, DISABLED_ComputeTilePriorityRects) {
158 #else
159 TEST_F(PictureLayerTilingPerfTest, ComputeTilePriorityRects) {
160 #endif // defined(OS_ANDROID)
161 gfx::Transform transform;
163 RunComputeTilePriorityRectsStationaryTest("no_transform", transform);
164 RunComputeTilePriorityRectsScrollingTest("no_transform", transform);
166 transform.Rotate(10);
167 RunComputeTilePriorityRectsStationaryTest("rotation", transform);
168 RunComputeTilePriorityRectsScrollingTest("rotation", transform);
170 transform.ApplyPerspectiveDepth(10);
171 RunComputeTilePriorityRectsStationaryTest("perspective", transform);
172 RunComputeTilePriorityRectsScrollingTest("perspective", transform);
175 } // namespace
176 } // namespace cc