Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / resources / picture_layer_tiling_perftest.cc
blob55d495be92e431ed2807d6839b8a0fad70d135a3
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"
18 namespace cc {
20 namespace {
22 static const int kTimeLimitMillis = 2000;
23 static const int kWarmupRuns = 5;
24 static const int kTimeCheckInterval = 10;
26 class PictureLayerTilingPerfTest : public testing::Test {
27 public:
28 PictureLayerTilingPerfTest()
29 : timer_(kWarmupRuns,
30 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
31 kTimeCheckInterval),
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(),
39 NULL,
40 NULL,
42 false,
43 1).Pass();
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) {
58 timer_.Reset();
59 do {
60 picture_layer_tiling_->UpdateTilesToCurrentRasterSource(
61 picture_layer_tiling_client_.raster_source(), region,
62 picture_layer_tiling_->tiling_size());
63 timer_.NextLap();
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);
75 timer_.Reset();
76 do {
77 picture_layer_tiling_->ComputeTilePriorityRects(
78 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
79 timer_.NextLap();
80 } while (!timer_.HasTimeLimitExpired());
82 perf_test::PrintResult("compute_tile_priority_rects_stationary",
83 "",
84 test_name,
85 timer_.LapsPerSecond(),
86 "runs/s",
87 true);
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};
97 int offsetIndex = 0;
98 int offsetCount = 0;
99 const int maxOffsetCount = 1000;
101 timer_.Reset();
102 do {
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) {
112 offsetCount = 0;
113 offsetIndex = (offsetIndex + 1) % 4;
115 timer_.NextLap();
116 } while (!timer_.HasTimeLimitExpired());
118 perf_test::PrintResult("compute_tile_priority_rects_scrolling",
120 test_name,
121 timer_.LapsPerSecond(),
122 "runs/s",
123 true);
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,
133 Occlusion());
135 timer_.Reset();
136 do {
137 PictureLayerTiling::TilingRasterTileIterator it(
138 picture_layer_tiling_.get());
139 timer_.NextLap();
140 } while (!timer_.HasTimeLimitExpired());
142 perf_test::PrintResult("tiling_raster_tile_iterator_construct",
144 test_name,
145 timer_.LapsPerSecond(),
146 "runs/s",
147 true);
150 void RunRasterIteratorConstructAndIterateTest(const std::string& test_name,
151 int num_tiles,
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,
158 Occlusion());
160 timer_.Reset();
161 do {
162 int count = num_tiles;
163 PictureLayerTiling::TilingRasterTileIterator it(
164 picture_layer_tiling_.get());
165 while (count--) {
166 ASSERT_TRUE(it) << "count: " << count;
167 ASSERT_TRUE(*it != NULL) << "count: " << count;
168 ++it;
170 timer_.NextLap();
171 } while (!timer_.HasTimeLimitExpired());
173 perf_test::PrintResult("tiling_raster_tile_iterator_construct_and_iterate",
175 test_name,
176 timer_.LapsPerSecond(),
177 "runs/s",
178 true);
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,
188 Occlusion());
190 timer_.Reset();
191 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
192 SMOOTHNESS_TAKES_PRIORITY,
193 NEW_CONTENT_TAKES_PRIORITY};
194 int priority_count = 0;
195 do {
196 PictureLayerTiling::TilingEvictionTileIterator it(
197 picture_layer_tiling_.get(),
198 priorities[priority_count],
199 PictureLayerTiling::NOW);
200 priority_count = (priority_count + 1) % arraysize(priorities);
201 timer_.NextLap();
202 } while (!timer_.HasTimeLimitExpired());
204 perf_test::PrintResult("tiling_eviction_tile_iterator_construct",
206 test_name,
207 timer_.LapsPerSecond(),
208 "runs/s",
209 true);
212 void RunEvictionIteratorConstructAndIterateTest(const std::string& test_name,
213 int num_tiles,
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,
220 Occlusion());
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();
230 ++tile_it) {
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;
238 timer_.Reset();
239 do {
240 int count = num_tiles;
241 PictureLayerTiling::TilingEvictionTileIterator it(
242 picture_layer_tiling_.get(),
243 priorities[priority_count],
244 PictureLayerTiling::EVENTUALLY);
245 while (count--) {
246 ASSERT_TRUE(it) << "count: " << count;
247 ASSERT_TRUE(*it != NULL) << "count: " << count;
248 ++it;
250 priority_count = (priority_count + 1) % arraysize(priorities);
251 timer_.NextLap();
252 } while (!timer_.HasTimeLimitExpired());
254 // Remove all resources from tiles to make sure the tile version destructor
255 // doesn't complain.
256 for (std::vector<Tile*>::iterator tile_it = all_tiles.begin();
257 tile_it != all_tiles.end();
258 ++tile_it) {
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",
267 test_name,
268 timer_.LapsPerSecond(),
269 "runs/s",
270 true);
273 private:
274 FakePictureLayerTilingClient picture_layer_tiling_client_;
275 scoped_ptr<PictureLayerTiling> picture_layer_tiling_;
277 LapTimer timer_;
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) {
300 #else
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));
357 } // namespace
359 } // namespace cc