OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/debug/lap_timer.h" | 5 #include "cc/debug/lap_timer.h" |
6 #include "cc/resources/picture_layer_tiling.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" |
7 #include "cc/test/fake_picture_layer_tiling_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" |
8 | 14 |
9 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/perf/perf_test.h" | 16 #include "testing/perf/perf_test.h" |
11 | 17 |
12 namespace cc { | 18 namespace cc { |
13 | 19 |
14 namespace { | 20 namespace { |
15 | 21 |
16 static const int kTimeLimitMillis = 2000; | 22 static const int kTimeLimitMillis = 2000; |
17 static const int kWarmupRuns = 5; | 23 static const int kWarmupRuns = 5; |
18 static const int kTimeCheckInterval = 10; | 24 static const int kTimeCheckInterval = 10; |
19 | 25 |
20 class PictureLayerTilingPerfTest : public testing::Test { | 26 class PictureLayerTilingPerfTest : public testing::Test { |
21 public: | 27 public: |
22 PictureLayerTilingPerfTest() | 28 PictureLayerTilingPerfTest() |
23 : timer_(kWarmupRuns, | 29 : timer_(kWarmupRuns, |
24 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 30 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
25 kTimeCheckInterval) {} | 31 kTimeCheckInterval), |
| 32 context_provider_(TestContextProvider::Create()) { |
| 33 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); |
| 34 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 35 |
| 36 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
| 37 resource_provider_ = ResourceProvider::Create(output_surface_.get(), |
| 38 shared_bitmap_manager_.get(), |
| 39 0, |
| 40 false, |
| 41 1, |
| 42 false).Pass(); |
| 43 } |
26 | 44 |
27 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
28 picture_layer_tiling_client_.SetTileSize(gfx::Size(256, 256)); | 46 picture_layer_tiling_client_.SetTileSize(gfx::Size(256, 256)); |
29 picture_layer_tiling_client_.set_max_tiles_for_interest_area(250); | 47 picture_layer_tiling_client_.set_max_tiles_for_interest_area(250); |
30 picture_layer_tiling_ = PictureLayerTiling::Create( | 48 picture_layer_tiling_ = PictureLayerTiling::Create( |
31 1, gfx::Size(256 * 50, 256 * 50), &picture_layer_tiling_client_); | 49 1, gfx::Size(256 * 50, 256 * 50), &picture_layer_tiling_client_); |
32 picture_layer_tiling_->CreateAllTilesForTesting(); | 50 picture_layer_tiling_->CreateAllTilesForTesting(); |
33 } | 51 } |
34 | 52 |
35 virtual void TearDown() OVERRIDE { | 53 virtual void TearDown() OVERRIDE { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } while (!timer_.HasTimeLimitExpired()); | 176 } while (!timer_.HasTimeLimitExpired()); |
159 | 177 |
160 perf_test::PrintResult("tiling_raster_tile_iterator_construct_and_iterate", | 178 perf_test::PrintResult("tiling_raster_tile_iterator_construct_and_iterate", |
161 "", | 179 "", |
162 test_name, | 180 test_name, |
163 timer_.LapsPerSecond(), | 181 timer_.LapsPerSecond(), |
164 "runs/s", | 182 "runs/s", |
165 true); | 183 true); |
166 } | 184 } |
167 | 185 |
| 186 void RunEvictionIteratorConstructTest(const std::string& test_name, |
| 187 const gfx::Rect& viewport) { |
| 188 gfx::Size bounds(viewport.size()); |
| 189 picture_layer_tiling_ = |
| 190 PictureLayerTiling::Create(1, bounds, &picture_layer_tiling_client_); |
| 191 picture_layer_tiling_->UpdateTilePriorities( |
| 192 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); |
| 193 |
| 194 timer_.Reset(); |
| 195 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, |
| 196 SMOOTHNESS_TAKES_PRIORITY, |
| 197 NEW_CONTENT_TAKES_PRIORITY}; |
| 198 int priority_count = 0; |
| 199 do { |
| 200 PictureLayerTiling::TilingEvictionTileIterator it( |
| 201 picture_layer_tiling_.get(), priorities[priority_count]); |
| 202 priority_count = (priority_count + 1) % arraysize(priorities); |
| 203 timer_.NextLap(); |
| 204 } while (!timer_.HasTimeLimitExpired()); |
| 205 |
| 206 perf_test::PrintResult("tiling_eviction_tile_iterator_construct", |
| 207 "", |
| 208 test_name, |
| 209 timer_.LapsPerSecond(), |
| 210 "runs/s", |
| 211 true); |
| 212 } |
| 213 |
| 214 void RunEvictionIteratorConstructAndIterateTest(const std::string& test_name, |
| 215 int num_tiles, |
| 216 const gfx::Rect& viewport) { |
| 217 gfx::Size bounds(10000, 10000); |
| 218 picture_layer_tiling_ = |
| 219 PictureLayerTiling::Create(1, bounds, &picture_layer_tiling_client_); |
| 220 picture_layer_tiling_->UpdateTilePriorities( |
| 221 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); |
| 222 |
| 223 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, |
| 224 SMOOTHNESS_TAKES_PRIORITY, |
| 225 NEW_CONTENT_TAKES_PRIORITY}; |
| 226 |
| 227 // Ensure all tiles have resources. |
| 228 std::vector<Tile*> all_tiles = picture_layer_tiling_->AllTilesForTesting(); |
| 229 for (std::vector<Tile*>::iterator tile_it = all_tiles.begin(); |
| 230 tile_it != all_tiles.end(); |
| 231 ++tile_it) { |
| 232 Tile* tile = *tile_it; |
| 233 ManagedTileState::TileVersion& tile_version = |
| 234 tile->GetTileVersionForTesting(tile->GetRasterModeForTesting()); |
| 235 tile_version.SetResourceForTesting( |
| 236 ScopedResource::Create(resource_provider_.get()).Pass()); |
| 237 } |
| 238 |
| 239 int priority_count = 0; |
| 240 timer_.Reset(); |
| 241 do { |
| 242 int count = num_tiles; |
| 243 PictureLayerTiling::TilingEvictionTileIterator it( |
| 244 picture_layer_tiling_.get(), priorities[priority_count]); |
| 245 while (count--) { |
| 246 ASSERT_TRUE(it) << "count: " << count; |
| 247 ASSERT_TRUE(*it != NULL) << "count: " << count; |
| 248 ++it; |
| 249 } |
| 250 priority_count = (priority_count + 1) % arraysize(priorities); |
| 251 timer_.NextLap(); |
| 252 } while (!timer_.HasTimeLimitExpired()); |
| 253 |
| 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::TileVersion& tile_version = |
| 261 tile->GetTileVersionForTesting(tile->GetRasterModeForTesting()); |
| 262 tile_version.SetResourceForTesting(scoped_ptr<ScopedResource>()); |
| 263 } |
| 264 |
| 265 perf_test::PrintResult( |
| 266 "tiling_eviction_tile_iterator_construct_and_iterate", |
| 267 "", |
| 268 test_name, |
| 269 timer_.LapsPerSecond(), |
| 270 "runs/s", |
| 271 true); |
| 272 } |
| 273 |
168 private: | 274 private: |
169 FakePictureLayerTilingClient picture_layer_tiling_client_; | 275 FakePictureLayerTilingClient picture_layer_tiling_client_; |
170 scoped_ptr<PictureLayerTiling> picture_layer_tiling_; | 276 scoped_ptr<PictureLayerTiling> picture_layer_tiling_; |
171 | 277 |
172 LapTimer timer_; | 278 LapTimer timer_; |
| 279 |
| 280 scoped_refptr<ContextProvider> context_provider_; |
| 281 FakeOutputSurfaceClient output_surface_client_; |
| 282 scoped_ptr<FakeOutputSurface> output_surface_; |
| 283 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 284 scoped_ptr<ResourceProvider> resource_provider_; |
173 }; | 285 }; |
174 | 286 |
175 TEST_F(PictureLayerTilingPerfTest, Invalidate) { | 287 TEST_F(PictureLayerTilingPerfTest, Invalidate) { |
176 Region one_tile(gfx::Rect(256, 256)); | 288 Region one_tile(gfx::Rect(256, 256)); |
177 RunInvalidateTest("1x1", one_tile); | 289 RunInvalidateTest("1x1", one_tile); |
178 | 290 |
179 Region half_region(gfx::Rect(25 * 256, 50 * 256)); | 291 Region half_region(gfx::Rect(25 * 256, 50 * 256)); |
180 RunInvalidateTest("25x50", half_region); | 292 RunInvalidateTest("25x50", half_region); |
181 | 293 |
182 Region full_region(gfx::Rect(50 * 256, 50 * 256)); | 294 Region full_region(gfx::Rect(50 * 256, 50 * 256)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 RunRasterIteratorConstructAndIterateTest( | 327 RunRasterIteratorConstructAndIterateTest( |
216 "32_100x100", 32, gfx::Rect(0, 0, 100, 100)); | 328 "32_100x100", 32, gfx::Rect(0, 0, 100, 100)); |
217 RunRasterIteratorConstructAndIterateTest( | 329 RunRasterIteratorConstructAndIterateTest( |
218 "32_500x500", 32, gfx::Rect(0, 0, 500, 500)); | 330 "32_500x500", 32, gfx::Rect(0, 0, 500, 500)); |
219 RunRasterIteratorConstructAndIterateTest( | 331 RunRasterIteratorConstructAndIterateTest( |
220 "64_100x100", 64, gfx::Rect(0, 0, 100, 100)); | 332 "64_100x100", 64, gfx::Rect(0, 0, 100, 100)); |
221 RunRasterIteratorConstructAndIterateTest( | 333 RunRasterIteratorConstructAndIterateTest( |
222 "64_500x500", 64, gfx::Rect(0, 0, 500, 500)); | 334 "64_500x500", 64, gfx::Rect(0, 0, 500, 500)); |
223 } | 335 } |
224 | 336 |
| 337 TEST_F(PictureLayerTilingPerfTest, TilingEvictionTileIteratorConstruct) { |
| 338 RunEvictionIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100)); |
| 339 RunEvictionIteratorConstructTest("50_0_100x100", gfx::Rect(50, 0, 100, 100)); |
| 340 RunEvictionIteratorConstructTest("100_0_100x100", |
| 341 gfx::Rect(100, 0, 100, 100)); |
| 342 RunEvictionIteratorConstructTest("150_0_100x100", |
| 343 gfx::Rect(150, 0, 100, 100)); |
| 344 } |
| 345 |
| 346 TEST_F(PictureLayerTilingPerfTest, |
| 347 TilingEvictionTileIteratorConstructAndIterate) { |
| 348 RunEvictionIteratorConstructAndIterateTest( |
| 349 "32_100x100", 32, gfx::Rect(0, 0, 100, 100)); |
| 350 RunEvictionIteratorConstructAndIterateTest( |
| 351 "32_500x500", 32, gfx::Rect(0, 0, 500, 500)); |
| 352 RunEvictionIteratorConstructAndIterateTest( |
| 353 "64_100x100", 64, gfx::Rect(0, 0, 100, 100)); |
| 354 RunEvictionIteratorConstructAndIterateTest( |
| 355 "64_500x500", 64, gfx::Rect(0, 0, 500, 500)); |
| 356 } |
| 357 |
225 } // namespace | 358 } // namespace |
226 | 359 |
227 } // namespace cc | 360 } // namespace cc |
OLD | NEW |