OLD | NEW |
| (Empty) |
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. | |
4 | |
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_raster_source.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" | |
17 | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 #include "testing/perf/perf_test.h" | |
20 | |
21 namespace cc { | |
22 | |
23 namespace { | |
24 | |
25 static const int kTimeLimitMillis = 2000; | |
26 static const int kWarmupRuns = 5; | |
27 static const int kTimeCheckInterval = 10; | |
28 | |
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_); | |
37 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
38 | |
39 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | |
40 resource_provider_ = FakeResourceProvider::Create( | |
41 output_surface_.get(), shared_bitmap_manager_.get()); | |
42 } | |
43 | |
44 void SetUp() override { | |
45 LayerTreeSettings defaults; | |
46 picture_layer_tiling_client_.SetTileSize(gfx::Size(256, 256)); | |
47 scoped_refptr<FakeRasterSource> raster_source = | |
48 FakeRasterSource::CreateFilled(gfx::Size(256 * 50, 256 * 50)); | |
49 picture_layer_tiling_ = PictureLayerTiling::Create( | |
50 PENDING_TREE, 1.f, raster_source, &picture_layer_tiling_client_, | |
51 defaults.tiling_interest_area_padding, | |
52 defaults.skewport_target_time_in_seconds, | |
53 defaults.skewport_extrapolation_limit_in_content_pixels); | |
54 picture_layer_tiling_->CreateAllTilesForTesting(); | |
55 } | |
56 | |
57 void TearDown() override { picture_layer_tiling_.reset(NULL); } | |
58 | |
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()); | |
65 | |
66 perf_test::PrintResult( | |
67 "invalidation", "", test_name, timer_.LapsPerSecond(), "runs/s", true); | |
68 } | |
69 | |
70 void RunComputeTilePriorityRectsStationaryTest( | |
71 const std::string& test_name, | |
72 const gfx::Transform& transform) { | |
73 gfx::Rect viewport_rect(0, 0, 1024, 768); | |
74 | |
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()); | |
81 | |
82 perf_test::PrintResult("compute_tile_priority_rects_stationary", | |
83 "", | |
84 test_name, | |
85 timer_.LapsPerSecond(), | |
86 "runs/s", | |
87 true); | |
88 } | |
89 | |
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; | |
100 | |
101 timer_.Reset(); | |
102 do { | |
103 picture_layer_tiling_->ComputeTilePriorityRects( | |
104 viewport_rect, 1.f, timer_.NumLaps() + 1, Occlusion()); | |
105 | |
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()); | |
109 | |
110 if (++offset_count > max_offset_count) { | |
111 offset_count = 0; | |
112 offset_index = (offset_index + 1) % 4; | |
113 } | |
114 timer_.NextLap(); | |
115 } while (!timer_.HasTimeLimitExpired()); | |
116 | |
117 perf_test::PrintResult("compute_tile_priority_rects_scrolling", | |
118 "", | |
119 test_name, | |
120 timer_.LapsPerSecond(), | |
121 "runs/s", | |
122 true); | |
123 } | |
124 | |
125 private: | |
126 FakePictureLayerTilingClient picture_layer_tiling_client_; | |
127 std::unique_ptr<PictureLayerTiling> picture_layer_tiling_; | |
128 | |
129 LapTimer timer_; | |
130 | |
131 scoped_refptr<ContextProvider> context_provider_; | |
132 FakeOutputSurfaceClient output_surface_client_; | |
133 std::unique_ptr<FakeOutputSurface> output_surface_; | |
134 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
135 std::unique_ptr<ResourceProvider> resource_provider_; | |
136 }; | |
137 | |
138 TEST_F(PictureLayerTilingPerfTest, Invalidate) { | |
139 Region one_tile(gfx::Rect(256, 256)); | |
140 RunInvalidateTest("1x1", one_tile); | |
141 | |
142 Region half_region(gfx::Rect(25 * 256, 50 * 256)); | |
143 RunInvalidateTest("25x50", half_region); | |
144 | |
145 Region full_region(gfx::Rect(50 * 256, 50 * 256)); | |
146 RunInvalidateTest("50x50", full_region); | |
147 } | |
148 | |
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; | |
156 | |
157 RunComputeTilePriorityRectsStationaryTest("no_transform", transform); | |
158 RunComputeTilePriorityRectsScrollingTest("no_transform", transform); | |
159 | |
160 transform.Rotate(10); | |
161 RunComputeTilePriorityRectsStationaryTest("rotation", transform); | |
162 RunComputeTilePriorityRectsScrollingTest("rotation", transform); | |
163 | |
164 transform.ApplyPerspectiveDepth(10); | |
165 RunComputeTilePriorityRectsStationaryTest("perspective", transform); | |
166 RunComputeTilePriorityRectsScrollingTest("perspective", transform); | |
167 } | |
168 | |
169 } // namespace | |
170 } // namespace cc | |
OLD | NEW |