Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / tiles / picture_layer_tiling_perftest.cc
blob35f2551302069d37d46063822afd7051ebc2dc71
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"
20 namespace cc {
22 namespace {
24 static const int kTimeLimitMillis = 2000;
25 static const int kWarmupRuns = 5;
26 static const int kTimeCheckInterval = 10;
28 class PictureLayerTilingPerfTest : public testing::Test {
29 public:
30 PictureLayerTilingPerfTest()
31 : timer_(kWarmupRuns,
32 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
33 kTimeCheckInterval),
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) {
60 timer_.Reset();
61 do {
62 picture_layer_tiling_->Invalidate(region);
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 offset_index = 0;
98 int offset_count = 0;
99 const int max_offset_count = 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[offset_index],
107 viewport_rect.y() + yoffsets[offset_index],
108 viewport_rect.width(), viewport_rect.height());
110 if (++offset_count > max_offset_count) {
111 offset_count = 0;
112 offset_index = (offset_index + 1) % 4;
114 timer_.NextLap();
115 } while (!timer_.HasTimeLimitExpired());
117 perf_test::PrintResult("compute_tile_priority_rects_scrolling",
119 test_name,
120 timer_.LapsPerSecond(),
121 "runs/s",
122 true);
125 private:
126 FakePictureLayerTilingClient picture_layer_tiling_client_;
127 scoped_ptr<PictureLayerTiling> picture_layer_tiling_;
129 LapTimer timer_;
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) {
152 #else
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);
169 } // namespace
170 } // namespace cc