OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include "cc/test/fake_picture_layer_tiling_client.h" | 7 #include "cc/test/fake_picture_layer_tiling_client.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/rect_conversions.h" | 9 #include "ui/gfx/rect_conversions.h" |
10 #include "ui/gfx/size_conversions.h" | 10 #include "ui/gfx/size_conversions.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // The entire rect must be filled by geometry from the tiling. | 63 // The entire rect must be filled by geometry from the tiling. |
64 EXPECT_TRUE(remaining.IsEmpty()); | 64 EXPECT_TRUE(remaining.IsEmpty()); |
65 } | 65 } |
66 | 66 |
67 void VerifyTilesExactlyCoverRect(float rect_scale, gfx::Rect rect) { | 67 void VerifyTilesExactlyCoverRect(float rect_scale, gfx::Rect rect) { |
68 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); | 68 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); |
69 } | 69 } |
70 | 70 |
71 void VerifyTiles(float rect_scale, | 71 void VerifyTiles(float rect_scale, |
72 gfx::Rect rect, | 72 gfx::Rect rect, |
73 base::Callback<void(Tile*)> callback) { | 73 base::Callback<void(Tile* tile)> callback) { |
74 Region remaining = rect; | 74 Region remaining = rect; |
75 for (PictureLayerTiling::CoverageIterator iter( | 75 for (PictureLayerTiling::CoverageIterator iter( |
76 tiling_.get(), rect_scale, rect); | 76 tiling_.get(), rect_scale, rect); |
77 iter; | 77 iter; |
78 ++iter) { | 78 ++iter) { |
79 remaining.Subtract(iter.geometry_rect()); | 79 remaining.Subtract(iter.geometry_rect()); |
80 callback.Run(*iter); | 80 callback.Run(*iter); |
81 } | 81 } |
82 EXPECT_TRUE(remaining.IsEmpty()); | 82 EXPECT_TRUE(remaining.IsEmpty()); |
83 } | 83 } |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 in, target_area, bounds); | 356 in, target_area, bounds); |
357 EXPECT_EQ(30, out.bottom() - in.bottom()); | 357 EXPECT_EQ(30, out.bottom() - in.bottom()); |
358 EXPECT_EQ(50, in.y() - out.y()); | 358 EXPECT_EQ(50, in.y() - out.y()); |
359 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 359 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
360 EXPECT_LE(out.width() * out.height(), target_area); | 360 EXPECT_LE(out.width() * out.height(), target_area); |
361 EXPECT_GT(out.width() * out.height(), | 361 EXPECT_GT(out.width() * out.height(), |
362 target_area - out.height() * 2); | 362 target_area - out.height() * 2); |
363 EXPECT_TRUE(bounds.Contains(out)); | 363 EXPECT_TRUE(bounds.Contains(out)); |
364 } | 364 } |
365 | 365 |
366 TEST(PictureLayerTilingTest, ExpandRectOutOfBounds) { | 366 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { |
367 gfx::Rect in(40, 50, 100, 200); | 367 gfx::Rect in(400, 500, 100, 200); |
368 gfx::Rect bounds(0, 0, 10, 10); | 368 gfx::Rect bounds(0, 0, 10, 10); |
369 int64 target_area = 400 * 400; | 369 int64 target_area = 400 * 400; |
370 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 370 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
371 in, target_area, bounds); | 371 in, target_area, bounds); |
372 EXPECT_TRUE(out.IsEmpty()); | 372 EXPECT_TRUE(out.IsEmpty()); |
373 } | 373 } |
374 | 374 |
| 375 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedFullyCover) { |
| 376 gfx::Rect in(40, 50, 100, 100); |
| 377 gfx::Rect bounds(0, 0, 10, 10); |
| 378 int64 target_area = 400 * 400; |
| 379 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 380 in, target_area, bounds); |
| 381 EXPECT_EQ(bounds.ToString(), out.ToString()); |
| 382 } |
| 383 |
| 384 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedPartlyCover) { |
| 385 gfx::Rect in(600, 600, 100, 100); |
| 386 gfx::Rect bounds(0, 0, 500, 500); |
| 387 int64 target_area = 400 * 400; |
| 388 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 389 in, target_area, bounds); |
| 390 EXPECT_EQ(bounds.right(), out.right()); |
| 391 EXPECT_EQ(bounds.bottom(), out.bottom()); |
| 392 EXPECT_LE(out.width() * out.height(), target_area); |
| 393 EXPECT_GT(out.width() * out.height(), |
| 394 target_area - out.width() - out.height()); |
| 395 EXPECT_TRUE(bounds.Contains(out)); |
| 396 } |
| 397 |
375 TEST(PictureLayerTilingTest, EmptyStartingRect) { | 398 TEST(PictureLayerTilingTest, EmptyStartingRect) { |
376 // If a layer has a non-invertible transform, then the starting rect | 399 // If a layer has a non-invertible transform, then the starting rect |
377 // for the layer would be empty. | 400 // for the layer would be empty. |
378 gfx::Rect in(40, 40, 0, 0); | 401 gfx::Rect in(40, 40, 0, 0); |
379 gfx::Rect bounds(0, 0, 10, 10); | 402 gfx::Rect bounds(0, 0, 10, 10); |
380 int64 target_area = 400 * 400; | 403 int64 target_area = 400 * 400; |
381 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 404 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
382 in, target_area, bounds); | 405 in, target_area, bounds); |
383 EXPECT_TRUE(out.IsEmpty()); | 406 EXPECT_TRUE(out.IsEmpty()); |
384 } | 407 } |
385 | 408 |
386 static void TileExists(bool live, Tile* tile) { | 409 static void TileExists(bool live, Tile* tile) { |
387 ASSERT_TRUE(tile != NULL); | 410 ASSERT_TRUE(tile != NULL); |
388 EXPECT_EQ(live, tile->priority(ACTIVE_TREE).is_live); | 411 EXPECT_EQ(live, tile->priority(ACTIVE_TREE).is_live); |
389 } | 412 } |
390 | 413 |
391 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 414 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
392 gfx::Size layer_bounds(1099, 801); | 415 gfx::Size layer_bounds(1099, 801); |
393 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 416 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
394 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 417 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
395 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 418 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
396 | 419 |
397 tiling_->UpdateTilePriorities( | 420 tiling_->UpdateTilePriorities( |
398 ACTIVE_TREE, | 421 ACTIVE_TREE, |
399 layer_bounds, // device viewport | 422 layer_bounds, // device viewport |
400 gfx::Rect(layer_bounds), // viewport in layer space | 423 gfx::Rect(layer_bounds), // viewport in layer space |
401 layer_bounds, // last layer bounds | 424 layer_bounds, // last layer bounds |
402 layer_bounds, // current layer bounds | 425 layer_bounds, // current layer bounds |
403 1.f, // last contents scale | 426 1.f, // last contents scale |
404 1.f, // current contents scale | 427 1.f, // current contents scale |
405 gfx::Transform(), // last screen transform | 428 gfx::Transform(), // last screen transform |
406 gfx::Transform(), // current screen transform | 429 gfx::Transform(), // current screen transform |
407 1, // current frame number | 430 1, // current frame number |
408 1.0, // current frame time | 431 1.0, // current frame time |
409 false, // store screen space quads on tiles | 432 false, // store screen space quads on tiles |
410 10000); // max tiles in tile manager | 433 10000); // max tiles in tile manager |
411 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 434 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
412 | 435 |
413 // Make the viewport rect empty. All tiles are killed and become zombies. | 436 // Make the viewport rect empty. All tiles are killed and become zombies. |
414 tiling_->UpdateTilePriorities( | 437 tiling_->UpdateTilePriorities( |
415 ACTIVE_TREE, | 438 ACTIVE_TREE, |
416 layer_bounds, // device viewport | 439 layer_bounds, // device viewport |
417 gfx::Rect(), // viewport in layer space | 440 gfx::Rect(), // viewport in layer space |
418 layer_bounds, // last layer bounds | 441 layer_bounds, // last layer bounds |
419 layer_bounds, // current layer bounds | 442 layer_bounds, // current layer bounds |
420 1.f, // last contents scale | 443 1.f, // last contents scale |
421 1.f, // current contents scale | 444 1.f, // current contents scale |
422 gfx::Transform(), // last screen transform | 445 gfx::Transform(), // last screen transform |
423 gfx::Transform(), // current screen transform | 446 gfx::Transform(), // current screen transform |
424 2, // current frame number | 447 2, // current frame number |
425 2.0, // current frame time | 448 2.0, // current frame time |
426 false, // store screen space quads on tiles | 449 false, // store screen space quads on tiles |
427 10000); // max tiles in tile manager | 450 10000); // max tiles in tile manager |
428 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 451 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
429 } | 452 } |
430 | 453 |
431 } // namespace | 454 } // namespace |
432 } // namespace cc | 455 } // namespace cc |
OLD | NEW |