[Do not revert] Roll-back V8 to version 4.4.63.
[chromium-blink-merge.git] / cc / resources / picture_layer_tiling_perftest.cc
blobef07078733387b67e0978bcf98373fd9f3d4b836
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 scoped_refptr<FakePicturePileImpl> pile =
51 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
52 gfx::Size(256 * 50, 256 * 50));
53 picture_layer_tiling_ = PictureLayerTiling::Create(
54 PENDING_TREE, 1.f, pile, &picture_layer_tiling_client_,
55 defaults.max_tiles_for_interest_area,
56 defaults.skewport_target_time_in_seconds,
57 defaults.skewport_extrapolation_limit_in_content_pixels);
58 picture_layer_tiling_->CreateAllTilesForTesting();
61 void TearDown() override { picture_layer_tiling_.reset(NULL); }
63 void RunInvalidateTest(const std::string& test_name, const Region& region) {
64 timer_.Reset();
65 do {
66 picture_layer_tiling_->Invalidate(region);
67 timer_.NextLap();
68 } while (!timer_.HasTimeLimitExpired());
70 perf_test::PrintResult(
71 "invalidation", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
74 void RunComputeTilePriorityRectsStationaryTest(
75 const std::string& test_name,
76 const gfx::Transform& transform) {
77 gfx::Rect viewport_rect(0, 0, 1024, 768);
79 timer_.Reset();
80 do {
81 picture_layer_tiling_->ComputeTilePriorityRects(
82 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
83 timer_.NextLap();
84 } while (!timer_.HasTimeLimitExpired());
86 perf_test::PrintResult("compute_tile_priority_rects_stationary",
87 "",
88 test_name,
89 timer_.LapsPerSecond(),
90 "runs/s",
91 true);
94 void RunComputeTilePriorityRectsScrollingTest(
95 const std::string& test_name,
96 const gfx::Transform& transform) {
97 gfx::Size viewport_size(1024, 768);
98 gfx::Rect viewport_rect(viewport_size);
99 int xoffsets[] = {10, 0, -10, 0};
100 int yoffsets[] = {0, 10, 0, -10};
101 int offset_index = 0;
102 int offset_count = 0;
103 const int max_offset_count = 1000;
105 timer_.Reset();
106 do {
107 picture_layer_tiling_->ComputeTilePriorityRects(
108 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
110 viewport_rect = gfx::Rect(viewport_rect.x() + xoffsets[offset_index],
111 viewport_rect.y() + yoffsets[offset_index],
112 viewport_rect.width(), viewport_rect.height());
114 if (++offset_count > max_offset_count) {
115 offset_count = 0;
116 offset_index = (offset_index + 1) % 4;
118 timer_.NextLap();
119 } while (!timer_.HasTimeLimitExpired());
121 perf_test::PrintResult("compute_tile_priority_rects_scrolling",
123 test_name,
124 timer_.LapsPerSecond(),
125 "runs/s",
126 true);
129 private:
130 FakePictureLayerTilingClient picture_layer_tiling_client_;
131 scoped_ptr<PictureLayerTiling> picture_layer_tiling_;
133 LapTimer timer_;
135 scoped_refptr<ContextProvider> context_provider_;
136 FakeOutputSurfaceClient output_surface_client_;
137 scoped_ptr<FakeOutputSurface> output_surface_;
138 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
139 scoped_ptr<ResourceProvider> resource_provider_;
142 TEST_F(PictureLayerTilingPerfTest, Invalidate) {
143 Region one_tile(gfx::Rect(256, 256));
144 RunInvalidateTest("1x1", one_tile);
146 Region half_region(gfx::Rect(25 * 256, 50 * 256));
147 RunInvalidateTest("25x50", half_region);
149 Region full_region(gfx::Rect(50 * 256, 50 * 256));
150 RunInvalidateTest("50x50", full_region);
153 #if defined(OS_ANDROID)
154 // TODO(vmpstr): Investigate why this is noisy (crbug.com/310220).
155 TEST_F(PictureLayerTilingPerfTest, DISABLED_ComputeTilePriorityRects) {
156 #else
157 TEST_F(PictureLayerTilingPerfTest, ComputeTilePriorityRects) {
158 #endif // defined(OS_ANDROID)
159 gfx::Transform transform;
161 RunComputeTilePriorityRectsStationaryTest("no_transform", transform);
162 RunComputeTilePriorityRectsScrollingTest("no_transform", transform);
164 transform.Rotate(10);
165 RunComputeTilePriorityRectsStationaryTest("rotation", transform);
166 RunComputeTilePriorityRectsScrollingTest("rotation", transform);
168 transform.ApplyPerspectiveDepth(10);
169 RunComputeTilePriorityRectsStationaryTest("perspective", transform);
170 RunComputeTilePriorityRectsScrollingTest("perspective", transform);
173 } // namespace
174 } // namespace cc