GN (Android): Fix packaging excess libs when target_cpu is changed
[chromium-blink-merge.git] / cc / tiles / picture_layer_tiling_perftest.cc
blob13db6343438b18b67066094f804a4b3ba8127379
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"
16 #include "cc/trees/layer_tree_settings.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/perf/perf_test.h"
21 namespace cc {
23 namespace {
25 static const int kTimeLimitMillis = 2000;
26 static const int kWarmupRuns = 5;
27 static const int kTimeCheckInterval = 10;
29 class PictureLayerTilingPerfTest : public testing::Test {
30 public:
31 PictureLayerTilingPerfTest()
32 : timer_(kWarmupRuns,
33 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
34 kTimeCheckInterval),
35 context_provider_(TestContextProvider::Create()) {
36 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass();
37 CHECK(output_surface_->BindToClient(&output_surface_client_));
39 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
40 resource_provider_ = FakeResourceProvider::Create(
41 output_surface_.get(), shared_bitmap_manager_.get());
44 void SetUp() override {
45 LayerTreeSettings defaults;
46 picture_layer_tiling_client_.SetTileSize(gfx::Size(256, 256));
47 scoped_refptr<FakePicturePileImpl> pile =
48 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
49 gfx::Size(256 * 50, 256 * 50));
50 picture_layer_tiling_ = PictureLayerTiling::Create(
51 PENDING_TREE, 1.f, pile, &picture_layer_tiling_client_,
52 defaults.tiling_interest_area_padding,
53 defaults.skewport_target_time_in_seconds,
54 defaults.skewport_extrapolation_limit_in_content_pixels);
55 picture_layer_tiling_->CreateAllTilesForTesting();
58 void TearDown() override { picture_layer_tiling_.reset(NULL); }
60 void RunInvalidateTest(const std::string& test_name, const Region& region) {
61 timer_.Reset();
62 do {
63 picture_layer_tiling_->Invalidate(region);
64 timer_.NextLap();
65 } while (!timer_.HasTimeLimitExpired());
67 perf_test::PrintResult(
68 "invalidation", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
71 void RunComputeTilePriorityRectsStationaryTest(
72 const std::string& test_name,
73 const gfx::Transform& transform) {
74 gfx::Rect viewport_rect(0, 0, 1024, 768);
76 timer_.Reset();
77 do {
78 picture_layer_tiling_->ComputeTilePriorityRects(
79 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
80 timer_.NextLap();
81 } while (!timer_.HasTimeLimitExpired());
83 perf_test::PrintResult("compute_tile_priority_rects_stationary",
84 "",
85 test_name,
86 timer_.LapsPerSecond(),
87 "runs/s",
88 true);
91 void RunComputeTilePriorityRectsScrollingTest(
92 const std::string& test_name,
93 const gfx::Transform& transform) {
94 gfx::Size viewport_size(1024, 768);
95 gfx::Rect viewport_rect(viewport_size);
96 int xoffsets[] = {10, 0, -10, 0};
97 int yoffsets[] = {0, 10, 0, -10};
98 int offset_index = 0;
99 int offset_count = 0;
100 const int max_offset_count = 1000;
102 timer_.Reset();
103 do {
104 picture_layer_tiling_->ComputeTilePriorityRects(
105 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion());
107 viewport_rect = gfx::Rect(viewport_rect.x() + xoffsets[offset_index],
108 viewport_rect.y() + yoffsets[offset_index],
109 viewport_rect.width(), viewport_rect.height());
111 if (++offset_count > max_offset_count) {
112 offset_count = 0;
113 offset_index = (offset_index + 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 private:
127 FakePictureLayerTilingClient picture_layer_tiling_client_;
128 scoped_ptr<PictureLayerTiling> picture_layer_tiling_;
130 LapTimer timer_;
132 scoped_refptr<ContextProvider> context_provider_;
133 FakeOutputSurfaceClient output_surface_client_;
134 scoped_ptr<FakeOutputSurface> output_surface_;
135 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
136 scoped_ptr<ResourceProvider> resource_provider_;
139 TEST_F(PictureLayerTilingPerfTest, Invalidate) {
140 Region one_tile(gfx::Rect(256, 256));
141 RunInvalidateTest("1x1", one_tile);
143 Region half_region(gfx::Rect(25 * 256, 50 * 256));
144 RunInvalidateTest("25x50", half_region);
146 Region full_region(gfx::Rect(50 * 256, 50 * 256));
147 RunInvalidateTest("50x50", full_region);
150 #if defined(OS_ANDROID)
151 // TODO(vmpstr): Investigate why this is noisy (crbug.com/310220).
152 TEST_F(PictureLayerTilingPerfTest, DISABLED_ComputeTilePriorityRects) {
153 #else
154 TEST_F(PictureLayerTilingPerfTest, ComputeTilePriorityRects) {
155 #endif // defined(OS_ANDROID)
156 gfx::Transform transform;
158 RunComputeTilePriorityRectsStationaryTest("no_transform", transform);
159 RunComputeTilePriorityRectsScrollingTest("no_transform", transform);
161 transform.Rotate(10);
162 RunComputeTilePriorityRectsStationaryTest("rotation", transform);
163 RunComputeTilePriorityRectsScrollingTest("rotation", transform);
165 transform.ApplyPerspectiveDepth(10);
166 RunComputeTilePriorityRectsStationaryTest("perspective", transform);
167 RunComputeTilePriorityRectsScrollingTest("perspective", transform);
170 } // namespace
171 } // namespace cc