Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
|
vmpstr
2014/01/31 20:53:38
I'm still working on this file. I'll be adding mor
| |
| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
| 11 #include "cc/test/fake_picture_layer_tiling_client.h" | 11 #include "cc/test/fake_picture_layer_tiling_client.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
| 14 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 static gfx::Rect ViewportInLayerSpace( | 19 static gfx::Rect ViewportInLayerSpace( |
| 20 const gfx::Transform& transform, | 20 const gfx::Transform& transform, |
| 21 const gfx::Size& device_viewport) { | 21 const gfx::Size& device_viewport) { |
| 22 | 22 |
| 23 gfx::Transform inverse; | 23 gfx::Transform inverse; |
| 24 if (!transform.GetInverse(&inverse)) | 24 if (!transform.GetInverse(&inverse)) |
| 25 return gfx::Rect(); | 25 return gfx::Rect(); |
| 26 | 26 |
| 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
| 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
| 29 | |
| 30 return ToEnclosingRect(viewport_in_layer_space); | 29 return ToEnclosingRect(viewport_in_layer_space); |
| 31 } | 30 } |
| 32 | 31 |
| 33 class TestablePictureLayerTiling : public PictureLayerTiling { | 32 class TestablePictureLayerTiling : public PictureLayerTiling { |
| 34 public: | 33 public: |
| 35 using PictureLayerTiling::SetLiveTilesRect; | 34 using PictureLayerTiling::SetLiveTilesRect; |
| 36 using PictureLayerTiling::TileAt; | 35 using PictureLayerTiling::TileAt; |
| 37 | 36 |
| 38 static scoped_ptr<TestablePictureLayerTiling> Create( | 37 static scoped_ptr<TestablePictureLayerTiling> Create( |
| 39 float contents_scale, | 38 float contents_scale, |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 } | 487 } |
| 489 | 488 |
| 490 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 489 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
| 491 gfx::Size layer_bounds(1099, 801); | 490 gfx::Size layer_bounds(1099, 801); |
| 492 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 491 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 493 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 492 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 494 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 493 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 495 | 494 |
| 496 tiling_->UpdateTilePriorities( | 495 tiling_->UpdateTilePriorities( |
| 497 ACTIVE_TREE, | 496 ACTIVE_TREE, |
| 498 layer_bounds, // device viewport | |
| 499 gfx::Rect(layer_bounds), // viewport in layer space | 497 gfx::Rect(layer_bounds), // viewport in layer space |
| 500 gfx::Rect(layer_bounds), // visible content rect | 498 gfx::Rect(layer_bounds), // visible content rect |
| 501 layer_bounds, // last layer bounds | |
| 502 layer_bounds, // current layer bounds | |
| 503 1.f, // last contents scale | |
| 504 1.f, // current contents scale | 499 1.f, // current contents scale |
| 505 gfx::Transform(), // last screen transform | |
| 506 gfx::Transform(), // current screen transform | |
| 507 1.0, // current frame time | 500 1.0, // current frame time |
| 508 10000); // max tiles in tile manager | 501 10000); // max tiles in tile manager |
| 509 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 502 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
| 510 | 503 |
| 511 // Make the viewport rect empty. All tiles are killed and become zombies. | 504 // Make the viewport rect empty. All tiles are killed and become zombies. |
| 512 tiling_->UpdateTilePriorities( | 505 tiling_->UpdateTilePriorities( |
| 513 ACTIVE_TREE, | 506 ACTIVE_TREE, |
| 514 layer_bounds, // device viewport | |
| 515 gfx::Rect(), // viewport in layer space | 507 gfx::Rect(), // viewport in layer space |
| 516 gfx::Rect(), // visible content rect | 508 gfx::Rect(), // visible content rect |
| 517 layer_bounds, // last layer bounds | |
| 518 layer_bounds, // current layer bounds | |
| 519 1.f, // last contents scale | |
| 520 1.f, // current contents scale | 509 1.f, // current contents scale |
| 521 gfx::Transform(), // last screen transform | |
| 522 gfx::Transform(), // current screen transform | |
| 523 2.0, // current frame time | 510 2.0, // current frame time |
| 524 10000); // max tiles in tile manager | 511 10000); // max tiles in tile manager |
| 525 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 512 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 526 } | 513 } |
| 527 | 514 |
| 528 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | 515 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { |
| 529 gfx::Size layer_bounds(1099, 801); | 516 gfx::Size layer_bounds(1099, 801); |
| 530 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 517 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 531 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 518 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 532 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 519 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 533 | 520 |
| 534 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | 521 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); |
| 535 | 522 |
| 536 tiling_->UpdateTilePriorities( | 523 tiling_->UpdateTilePriorities( |
| 537 ACTIVE_TREE, | 524 ACTIVE_TREE, |
| 538 layer_bounds, // device viewport | |
| 539 giant_rect, // viewport in layer space | 525 giant_rect, // viewport in layer space |
| 540 gfx::Rect(layer_bounds), // visible content rect | 526 gfx::Rect(layer_bounds), // visible content rect |
| 541 layer_bounds, // last layer bounds | |
| 542 layer_bounds, // current layer bounds | |
| 543 1.f, // last contents scale | |
| 544 1.f, // current contents scale | 527 1.f, // current contents scale |
| 545 gfx::Transform(), // last screen transform | |
| 546 gfx::Transform(), // current screen transform | |
| 547 1.0, // current frame time | 528 1.0, // current frame time |
| 548 10000); // max tiles in tile manager | 529 10000); // max tiles in tile manager |
| 549 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 530 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
| 550 | 531 |
| 551 // If the visible content rect is empty, it should still have live tiles. | 532 // If the visible content rect is empty, it should still have live tiles. |
| 552 tiling_->UpdateTilePriorities( | 533 tiling_->UpdateTilePriorities( |
| 553 ACTIVE_TREE, | 534 ACTIVE_TREE, |
| 554 layer_bounds, // device viewport | |
| 555 giant_rect, // viewport in layer space | 535 giant_rect, // viewport in layer space |
| 556 gfx::Rect(), // visible content rect | 536 gfx::Rect(), // visible content rect |
| 557 layer_bounds, // last layer bounds | |
| 558 layer_bounds, // current layer bounds | |
| 559 1.f, // last contents scale | |
| 560 1.f, // current contents scale | 537 1.f, // current contents scale |
| 561 gfx::Transform(), // last screen transform | |
| 562 gfx::Transform(), // current screen transform | |
| 563 2.0, // current frame time | 538 2.0, // current frame time |
| 564 10000); // max tiles in tile manager | 539 10000); // max tiles in tile manager |
| 565 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 540 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
| 566 } | 541 } |
| 567 | 542 |
| 568 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { | 543 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { |
| 569 gfx::Size layer_bounds(1099, 801); | 544 gfx::Size layer_bounds(1099, 801); |
| 570 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 545 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 571 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 546 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 572 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 547 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 573 | 548 |
| 574 // This rect does not intersect with the layer, as the layer is outside the | 549 // This rect does not intersect with the layer, as the layer is outside the |
| 575 // viewport. | 550 // viewport. |
| 576 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | 551 gfx::Rect viewport_rect(1100, 0, 1000, 1000); |
| 577 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | 552 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); |
| 578 | 553 |
| 579 tiling_->UpdateTilePriorities( | 554 tiling_->UpdateTilePriorities( |
| 580 ACTIVE_TREE, | 555 ACTIVE_TREE, |
| 581 layer_bounds, // device viewport | |
| 582 viewport_rect, // viewport in layer space | 556 viewport_rect, // viewport in layer space |
| 583 gfx::Rect(), // visible content rect | 557 gfx::Rect(), // visible content rect |
| 584 layer_bounds, // last layer bounds | |
| 585 layer_bounds, // current layer bounds | |
| 586 1.f, // last contents scale | |
| 587 1.f, // current contents scale | 558 1.f, // current contents scale |
| 588 gfx::Transform(), // last screen transform | |
| 589 gfx::Transform(), // current screen transform | |
| 590 1.0, // current frame time | 559 1.0, // current frame time |
| 591 10000); // max tiles in tile manager | 560 10000); // max tiles in tile manager |
| 592 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 561 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
| 593 } | 562 } |
| 594 | 563 |
| 595 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 564 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
| 596 bool intersect_exists, | 565 bool intersect_exists, |
| 597 Tile* tile, | 566 Tile* tile, |
| 598 const gfx::Rect& geometry_rect) { | 567 const gfx::Rect& geometry_rect) { |
| 599 bool intersects = rect.Intersects(geometry_rect); | 568 bool intersects = rect.Intersects(geometry_rect); |
| 600 bool expected_exists = intersect_exists ? intersects : !intersects; | 569 bool expected_exists = intersect_exists ? intersects : !intersects; |
| 601 EXPECT_EQ(expected_exists, tile != NULL) | 570 EXPECT_EQ(expected_exists, tile != NULL) |
| 602 << "Rects intersecting " << rect.ToString() << " should exist. " | 571 << "Rects intersecting " << rect.ToString() << " should exist. " |
| 603 << "Current tile rect is " << geometry_rect.ToString(); | 572 << "Current tile rect is " << geometry_rect.ToString(); |
| 604 } | 573 } |
| 605 | 574 |
| 606 TEST_F(PictureLayerTilingIteratorTest, | 575 TEST_F(PictureLayerTilingIteratorTest, |
| 607 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 576 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
| 608 gfx::Size layer_bounds(10000, 10000); | 577 gfx::Size layer_bounds(10000, 10000); |
| 609 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 578 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 610 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 579 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 611 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 580 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 612 | 581 |
| 613 gfx::Rect visible_rect(8000, 8000, 50, 50); | 582 gfx::Rect visible_rect(8000, 8000, 50, 50); |
| 614 | 583 |
| 615 tiling_->UpdateTilePriorities( | 584 tiling_->UpdateTilePriorities( |
| 616 ACTIVE_TREE, | 585 ACTIVE_TREE, |
| 617 layer_bounds, // device viewport | |
| 618 gfx::Rect(layer_bounds), // viewport in layer space | 586 gfx::Rect(layer_bounds), // viewport in layer space |
| 619 visible_rect, // visible content rect | 587 visible_rect, // visible content rect |
| 620 layer_bounds, // last layer bounds | |
| 621 layer_bounds, // current layer bounds | |
| 622 1.f, // last contents scale | |
| 623 1.f, // current contents scale | 588 1.f, // current contents scale |
| 624 gfx::Transform(), // last screen transform | |
| 625 gfx::Transform(), // current screen transform | |
| 626 1.0, // current frame time | 589 1.0, // current frame time |
| 627 1); // max tiles in tile manager | 590 1); // max tiles in tile manager |
| 628 VerifyTiles(1.f, | 591 VerifyTiles(1.f, |
| 629 gfx::Rect(layer_bounds), | 592 gfx::Rect(layer_bounds), |
| 630 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 593 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
| 631 } | 594 } |
| 632 | 595 |
| 633 static void CountExistingTiles(int *count, | 596 static void CountExistingTiles(int *count, |
| 634 Tile* tile, | 597 Tile* tile, |
| 635 const gfx::Rect& geometry_rect) { | 598 const gfx::Rect& geometry_rect) { |
| 636 if (tile != NULL) | 599 if (tile != NULL) |
| 637 ++(*count); | 600 ++(*count); |
| 638 } | 601 } |
| 639 | 602 |
| 640 TEST_F(PictureLayerTilingIteratorTest, | 603 TEST_F(PictureLayerTilingIteratorTest, |
| 641 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 604 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
| 642 gfx::Size layer_bounds(10000, 10000); | 605 gfx::Size layer_bounds(10000, 10000); |
| 643 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 606 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 644 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 607 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 645 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 608 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 646 | 609 |
| 647 tiling_->UpdateTilePriorities( | 610 tiling_->UpdateTilePriorities( |
| 648 ACTIVE_TREE, | 611 ACTIVE_TREE, |
| 649 layer_bounds, // device viewport | |
| 650 gfx::Rect(layer_bounds), // viewport in layer space | 612 gfx::Rect(layer_bounds), // viewport in layer space |
| 651 gfx::Rect(layer_bounds), // visible content rect | 613 gfx::Rect(layer_bounds), // visible content rect |
| 652 layer_bounds, // last layer bounds | |
| 653 layer_bounds, // current layer bounds | |
| 654 1.f, // last contents scale | |
| 655 1.f, // current contents scale | 614 1.f, // current contents scale |
| 656 gfx::Transform(), // last screen transform | |
| 657 gfx::Transform(), // current screen transform | |
| 658 1.0, // current frame time | 615 1.0, // current frame time |
| 659 1); // max tiles in tile manager | 616 1); // max tiles in tile manager |
| 660 | 617 |
| 661 int num_tiles = 0; | 618 int num_tiles = 0; |
| 662 VerifyTiles(1.f, | 619 VerifyTiles(1.f, |
| 663 gfx::Rect(layer_bounds), | 620 gfx::Rect(layer_bounds), |
| 664 base::Bind(&CountExistingTiles, &num_tiles)); | 621 base::Bind(&CountExistingTiles, &num_tiles)); |
| 665 // If we're making a rect the size of one tile, it can only overlap up to 4 | 622 // If we're making a rect the size of one tile, it can only overlap up to 4 |
| 666 // tiles depending on its position. | 623 // tiles depending on its position. |
| 667 EXPECT_LE(num_tiles, 4); | 624 EXPECT_LE(num_tiles, 4); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 678 | 635 |
| 679 active_set.AddTiling(1.f); | 636 active_set.AddTiling(1.f); |
| 680 | 637 |
| 681 VerifyTiles(active_set.tiling_at(0), | 638 VerifyTiles(active_set.tiling_at(0), |
| 682 1.f, | 639 1.f, |
| 683 gfx::Rect(layer_bounds), | 640 gfx::Rect(layer_bounds), |
| 684 base::Bind(&TileExists, false)); | 641 base::Bind(&TileExists, false)); |
| 685 | 642 |
| 686 active_set.UpdateTilePriorities( | 643 active_set.UpdateTilePriorities( |
| 687 PENDING_TREE, | 644 PENDING_TREE, |
| 688 layer_bounds, // device viewport | |
| 689 gfx::Rect(layer_bounds), // viewport in layer space | 645 gfx::Rect(layer_bounds), // viewport in layer space |
| 690 gfx::Rect(layer_bounds), // visible content rect | 646 gfx::Rect(layer_bounds), // visible content rect |
| 691 layer_bounds, // last layer bounds | |
| 692 layer_bounds, // current layer bounds | |
| 693 1.f, // last contents scale | |
| 694 1.f, // current contents scale | 647 1.f, // current contents scale |
| 695 gfx::Transform(), // last screen transform | |
| 696 gfx::Transform(), // current screen transform | |
| 697 1.0, // current frame time | 648 1.0, // current frame time |
| 698 10000); // max tiles in tile manager | 649 10000); // max tiles in tile manager |
| 699 | 650 |
| 700 // The active tiling has tiles now. | 651 // The active tiling has tiles now. |
| 701 VerifyTiles(active_set.tiling_at(0), | 652 VerifyTiles(active_set.tiling_at(0), |
| 702 1.f, | 653 1.f, |
| 703 gfx::Rect(layer_bounds), | 654 gfx::Rect(layer_bounds), |
| 704 base::Bind(&TileExists, true)); | 655 base::Bind(&TileExists, true)); |
| 705 | 656 |
| 706 // Add the same tilings to the pending set. | 657 // Add the same tilings to the pending set. |
| 707 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 658 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
| 708 Region invalidation; | 659 Region invalidation; |
| 709 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 660 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
| 710 | 661 |
| 711 // The pending tiling starts with no tiles. | 662 // The pending tiling starts with no tiles. |
| 712 VerifyTiles(pending_set.tiling_at(0), | 663 VerifyTiles(pending_set.tiling_at(0), |
| 713 1.f, | 664 1.f, |
| 714 gfx::Rect(layer_bounds), | 665 gfx::Rect(layer_bounds), |
| 715 base::Bind(&TileExists, false)); | 666 base::Bind(&TileExists, false)); |
| 716 | 667 |
| 717 // UpdateTilePriorities on the pending tiling at the same frame time. The | 668 // UpdateTilePriorities on the pending tiling at the same frame time. The |
| 718 // pending tiling should get tiles. | 669 // pending tiling should get tiles. |
| 719 pending_set.UpdateTilePriorities( | 670 pending_set.UpdateTilePriorities( |
| 720 PENDING_TREE, | 671 PENDING_TREE, |
| 721 layer_bounds, // device viewport | |
| 722 gfx::Rect(layer_bounds), // viewport in layer space | 672 gfx::Rect(layer_bounds), // viewport in layer space |
| 723 gfx::Rect(layer_bounds), // visible content rect | 673 gfx::Rect(layer_bounds), // visible content rect |
| 724 layer_bounds, // last layer bounds | |
| 725 layer_bounds, // current layer bounds | |
| 726 1.f, // last contents scale | |
| 727 1.f, // current contents scale | 674 1.f, // current contents scale |
| 728 gfx::Transform(), // last screen transform | |
| 729 gfx::Transform(), // current screen transform | |
| 730 1.0, // current frame time | 675 1.0, // current frame time |
| 731 10000); // max tiles in tile manager | 676 10000); // max tiles in tile manager |
| 732 | 677 |
| 733 VerifyTiles(pending_set.tiling_at(0), | 678 VerifyTiles(pending_set.tiling_at(0), |
| 734 1.f, | 679 1.f, |
| 735 gfx::Rect(layer_bounds), | 680 gfx::Rect(layer_bounds), |
| 736 base::Bind(&TileExists, true)); | 681 base::Bind(&TileExists, true)); |
| 737 } | 682 } |
| 738 | 683 |
| 739 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 684 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
| 740 // The TilePriority of visible tiles should have zero distance_to_visible | 685 // The TilePriority of visible tiles should have zero distance_to_visible |
| 741 // and time_to_visible. | 686 // and time_to_visible. |
| 742 | 687 |
| 743 FakePictureLayerTilingClient client; | 688 FakePictureLayerTilingClient client; |
| 744 scoped_ptr<TestablePictureLayerTiling> tiling; | 689 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 745 | 690 |
| 746 gfx::Size device_viewport(800, 600); | 691 gfx::Size device_viewport(800, 600); |
| 747 gfx::Rect visible_layer_rect(0, 0, 200, 200); | 692 gfx::Rect visible_layer_rect(0, 0, 200, 200); |
| 748 gfx::Size last_layer_bounds(200, 200); | 693 gfx::Size last_layer_bounds(200, 200); |
| 749 gfx::Size current_layer_bounds(200, 200); | 694 gfx::Size current_layer_bounds(200, 200); |
| 750 float last_layer_contents_scale = 1.f; | |
| 751 float current_layer_contents_scale = 1.f; | 695 float current_layer_contents_scale = 1.f; |
| 752 gfx::Transform last_screen_transform; | 696 gfx::Transform last_screen_transform; |
| 753 gfx::Transform current_screen_transform; | 697 gfx::Transform current_screen_transform; |
| 754 double current_frame_time_in_seconds = 1.0; | 698 double current_frame_time_in_seconds = 1.0; |
| 755 size_t max_tiles_for_interest_area = 10000; | 699 size_t max_tiles_for_interest_area = 10000; |
| 756 | 700 |
| 757 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 701 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 758 current_screen_transform, device_viewport); | 702 current_screen_transform, device_viewport); |
| 759 | 703 |
| 760 client.SetTileSize(gfx::Size(100, 100)); | 704 client.SetTileSize(gfx::Size(100, 100)); |
| 761 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 705 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 762 current_layer_bounds, | 706 current_layer_bounds, |
| 763 &client); | 707 &client); |
| 764 | 708 |
| 765 tiling->UpdateTilePriorities( | 709 tiling->UpdateTilePriorities( |
| 766 ACTIVE_TREE, | 710 ACTIVE_TREE, |
| 767 device_viewport, | |
| 768 viewport_in_layer_space, | 711 viewport_in_layer_space, |
| 769 visible_layer_rect, | 712 visible_layer_rect, |
| 770 last_layer_bounds, | |
| 771 current_layer_bounds, | |
| 772 last_layer_contents_scale, | |
| 773 current_layer_contents_scale, | 713 current_layer_contents_scale, |
| 774 last_screen_transform, | |
| 775 current_screen_transform, | |
| 776 current_frame_time_in_seconds, | 714 current_frame_time_in_seconds, |
| 777 max_tiles_for_interest_area); | 715 max_tiles_for_interest_area); |
| 778 | 716 |
| 779 ASSERT_TRUE(tiling->TileAt(0, 0)); | 717 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 780 ASSERT_TRUE(tiling->TileAt(0, 1)); | 718 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 781 ASSERT_TRUE(tiling->TileAt(1, 0)); | 719 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 782 ASSERT_TRUE(tiling->TileAt(1, 1)); | 720 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 783 | 721 |
| 784 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 722 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 723 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 724 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 787 | 725 |
| 788 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 726 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 789 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 727 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 790 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 728 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 791 | 729 |
| 792 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 730 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 793 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 731 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 732 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 795 | 733 |
| 796 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 734 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 797 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 735 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 798 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 736 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 799 } | 737 } |
| 800 | 738 |
| 801 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 739 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
| 802 // The TilePriority of offscreen tiles (without movement) should have nonzero | 740 // The TilePriority of offscreen tiles (without movement) should have nonzero |
| 803 // distance_to_visible and infinite time_to_visible. | 741 // distance_to_visible and infinite time_to_visible. |
| 804 | 742 |
| 805 FakePictureLayerTilingClient client; | 743 FakePictureLayerTilingClient client; |
| 806 scoped_ptr<TestablePictureLayerTiling> tiling; | 744 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 807 | 745 |
| 808 gfx::Size device_viewport(800, 600); | 746 gfx::Size device_viewport(800, 600); |
| 809 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. | 747 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. |
| 810 gfx::Size last_layer_bounds(200, 200); | 748 gfx::Size last_layer_bounds(200, 200); |
| 811 gfx::Size current_layer_bounds(200, 200); | 749 gfx::Size current_layer_bounds(200, 200); |
| 812 float last_layer_contents_scale = 1.f; | |
| 813 float current_layer_contents_scale = 1.f; | 750 float current_layer_contents_scale = 1.f; |
| 814 gfx::Transform last_screen_transform; | 751 gfx::Transform last_screen_transform; |
| 815 gfx::Transform current_screen_transform; | 752 gfx::Transform current_screen_transform; |
| 816 double current_frame_time_in_seconds = 1.0; | 753 double current_frame_time_in_seconds = 1.0; |
| 817 size_t max_tiles_for_interest_area = 10000; | 754 size_t max_tiles_for_interest_area = 10000; |
| 818 | 755 |
| 819 current_screen_transform.Translate(850, 0); | 756 current_screen_transform.Translate(850, 0); |
| 820 last_screen_transform = current_screen_transform; | 757 last_screen_transform = current_screen_transform; |
| 821 | 758 |
| 822 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 759 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 823 current_screen_transform, device_viewport); | 760 current_screen_transform, device_viewport); |
| 824 | 761 |
| 825 client.SetTileSize(gfx::Size(100, 100)); | 762 client.SetTileSize(gfx::Size(100, 100)); |
| 826 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 763 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 827 current_layer_bounds, | 764 current_layer_bounds, |
| 828 &client); | 765 &client); |
| 829 | 766 |
| 830 tiling->UpdateTilePriorities( | 767 tiling->UpdateTilePriorities( |
| 831 ACTIVE_TREE, | 768 ACTIVE_TREE, |
| 832 device_viewport, | |
| 833 viewport_in_layer_space, | 769 viewport_in_layer_space, |
| 834 visible_layer_rect, | 770 visible_layer_rect, |
| 835 last_layer_bounds, | |
| 836 current_layer_bounds, | |
| 837 last_layer_contents_scale, | |
| 838 current_layer_contents_scale, | 771 current_layer_contents_scale, |
| 839 last_screen_transform, | |
| 840 current_screen_transform, | |
| 841 current_frame_time_in_seconds, | 772 current_frame_time_in_seconds, |
| 842 max_tiles_for_interest_area); | 773 max_tiles_for_interest_area); |
| 843 | 774 |
| 844 ASSERT_TRUE(tiling->TileAt(0, 0)); | 775 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 845 ASSERT_TRUE(tiling->TileAt(0, 1)); | 776 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 846 ASSERT_TRUE(tiling->TileAt(1, 0)); | 777 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 847 ASSERT_TRUE(tiling->TileAt(1, 1)); | 778 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 848 | 779 |
| 849 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 780 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 850 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 781 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 851 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 782 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 852 priority.time_to_visible_in_seconds); | |
| 853 | 783 |
| 854 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 784 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 855 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 785 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 856 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 786 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 857 priority.time_to_visible_in_seconds); | |
| 858 | 787 |
| 859 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 788 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 860 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 789 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 861 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 790 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 862 priority.time_to_visible_in_seconds); | |
| 863 | 791 |
| 864 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 792 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 865 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 793 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 866 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 794 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 867 priority.time_to_visible_in_seconds); | |
| 868 | 795 |
| 869 // Furthermore, in this scenario tiles on the right hand side should have a | 796 // Furthermore, in this scenario tiles on the right hand side should have a |
| 870 // larger distance to visible. | 797 // larger distance to visible. |
| 871 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 798 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 872 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 799 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 873 EXPECT_GT(right.distance_to_visible_in_pixels, | 800 EXPECT_GT(right.distance_to_visible, |
| 874 left.distance_to_visible_in_pixels); | 801 left.distance_to_visible); |
| 875 | 802 |
| 876 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 803 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 877 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 804 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 878 EXPECT_GT(right.distance_to_visible_in_pixels, | 805 EXPECT_GT(right.distance_to_visible, |
| 879 left.distance_to_visible_in_pixels); | 806 left.distance_to_visible); |
| 880 } | 807 } |
| 881 | 808 |
| 882 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 809 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
| 883 // Sanity check that a layer with some tiles visible and others offscreen has | 810 // Sanity check that a layer with some tiles visible and others offscreen has |
| 884 // correct TilePriorities for each tile. | 811 // correct TilePriorities for each tile. |
| 885 | 812 |
| 886 FakePictureLayerTilingClient client; | 813 FakePictureLayerTilingClient client; |
| 887 scoped_ptr<TestablePictureLayerTiling> tiling; | 814 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 888 | 815 |
| 889 gfx::Size device_viewport(800, 600); | 816 gfx::Size device_viewport(800, 600); |
| 890 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. | |
| 891 gfx::Size last_layer_bounds(200, 200); | 817 gfx::Size last_layer_bounds(200, 200); |
| 892 gfx::Size current_layer_bounds(200, 200); | 818 gfx::Size current_layer_bounds(200, 200); |
| 893 float last_layer_contents_scale = 1.f; | |
| 894 float current_layer_contents_scale = 1.f; | 819 float current_layer_contents_scale = 1.f; |
| 895 gfx::Transform last_screen_transform; | 820 gfx::Transform last_screen_transform; |
| 896 gfx::Transform current_screen_transform; | 821 gfx::Transform current_screen_transform; |
| 897 double current_frame_time_in_seconds = 1.0; | 822 double current_frame_time_in_seconds = 1.0; |
| 898 size_t max_tiles_for_interest_area = 10000; | 823 size_t max_tiles_for_interest_area = 10000; |
| 899 | 824 |
| 900 current_screen_transform.Translate(705, 505); | 825 current_screen_transform.Translate(705, 505); |
| 901 last_screen_transform = current_screen_transform; | 826 last_screen_transform = current_screen_transform; |
| 902 | 827 |
| 903 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 828 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 904 current_screen_transform, device_viewport); | 829 current_screen_transform, device_viewport); |
| 830 gfx::Rect visible_layer_rect = viewport_in_layer_space; | |
| 831 visible_layer_rect.Intersect( | |
| 832 gfx::Rect(gfx::Point(0, 0), current_layer_bounds)); | |
| 905 | 833 |
| 906 client.SetTileSize(gfx::Size(100, 100)); | 834 client.SetTileSize(gfx::Size(100, 100)); |
| 907 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 835 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 908 current_layer_bounds, | 836 current_layer_bounds, |
| 909 &client); | 837 &client); |
| 910 | 838 |
| 911 tiling->UpdateTilePriorities( | 839 tiling->UpdateTilePriorities( |
| 912 ACTIVE_TREE, | 840 ACTIVE_TREE, |
| 913 device_viewport, | |
| 914 viewport_in_layer_space, | 841 viewport_in_layer_space, |
| 915 visible_layer_rect, | 842 visible_layer_rect, |
| 916 last_layer_bounds, | |
| 917 current_layer_bounds, | |
| 918 last_layer_contents_scale, | |
| 919 current_layer_contents_scale, | 843 current_layer_contents_scale, |
| 920 last_screen_transform, | |
| 921 current_screen_transform, | |
| 922 current_frame_time_in_seconds, | 844 current_frame_time_in_seconds, |
| 923 max_tiles_for_interest_area); | 845 max_tiles_for_interest_area); |
| 924 | 846 |
| 925 ASSERT_TRUE(tiling->TileAt(0, 0)); | 847 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 926 ASSERT_TRUE(tiling->TileAt(0, 1)); | 848 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 927 ASSERT_TRUE(tiling->TileAt(1, 0)); | 849 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 928 ASSERT_TRUE(tiling->TileAt(1, 1)); | 850 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 929 | 851 |
| 930 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 852 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 931 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 853 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 932 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 854 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 933 | 855 |
| 934 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 856 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 935 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 857 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 936 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 858 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 937 priority.time_to_visible_in_seconds); | |
| 938 | 859 |
| 939 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 860 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 940 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 861 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 941 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 862 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 942 priority.time_to_visible_in_seconds); | |
| 943 | 863 |
| 944 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 864 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 945 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 865 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 946 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 866 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 947 priority.time_to_visible_in_seconds); | |
| 948 } | 867 } |
| 949 | 868 |
| 950 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 869 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
| 951 // Each tile of a layer may be affected differently by a transform; Check | 870 // Each tile of a layer may be affected differently by a transform; Check |
| 952 // that UpdateTilePriorities correctly accounts for the transform between | 871 // that UpdateTilePriorities correctly accounts for the transform between |
| 953 // layer space and screen space. | 872 // layer space and screen space. |
| 954 | 873 |
| 955 FakePictureLayerTilingClient client; | 874 FakePictureLayerTilingClient client; |
| 956 scoped_ptr<TestablePictureLayerTiling> tiling; | 875 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 957 | 876 |
| 958 gfx::Size device_viewport(800, 600); | 877 gfx::Size device_viewport(800, 600); |
| 959 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. | |
| 960 gfx::Size last_layer_bounds(200, 200); | 878 gfx::Size last_layer_bounds(200, 200); |
| 961 gfx::Size current_layer_bounds(200, 200); | 879 gfx::Size current_layer_bounds(200, 200); |
| 962 float last_layer_contents_scale = 1.f; | |
| 963 float current_layer_contents_scale = 1.f; | 880 float current_layer_contents_scale = 1.f; |
| 964 gfx::Transform last_screen_transform; | 881 gfx::Transform last_screen_transform; |
| 965 gfx::Transform current_screen_transform; | 882 gfx::Transform current_screen_transform; |
| 966 double current_frame_time_in_seconds = 1.0; | 883 double current_frame_time_in_seconds = 1.0; |
| 967 size_t max_tiles_for_interest_area = 10000; | 884 size_t max_tiles_for_interest_area = 10000; |
| 968 | 885 |
| 969 // A diagonally rotated layer that is partially off the bottom of the screen. | 886 // A diagonally rotated layer that is partially off the bottom of the screen. |
| 970 // In this configuration, only the top-left tile would be visible. | 887 // In this configuration, only the top-left tile would be visible. |
| 971 current_screen_transform.Translate(400, 550); | 888 current_screen_transform.Translate(600, 750); |
| 972 current_screen_transform.RotateAboutZAxis(45); | 889 current_screen_transform.RotateAboutZAxis(45); |
| 973 last_screen_transform = current_screen_transform; | 890 last_screen_transform = current_screen_transform; |
| 974 | 891 |
| 975 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 892 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 976 current_screen_transform, device_viewport); | 893 current_screen_transform, device_viewport); |
| 894 gfx::Rect visible_layer_rect = viewport_in_layer_space; | |
| 895 visible_layer_rect.Intersect( | |
| 896 gfx::Rect(gfx::Point(0, 0), current_layer_bounds)); | |
| 977 | 897 |
| 978 client.SetTileSize(gfx::Size(100, 100)); | 898 client.SetTileSize(gfx::Size(100, 100)); |
| 979 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 899 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 980 current_layer_bounds, | 900 current_layer_bounds, |
| 981 &client); | 901 &client); |
| 982 | 902 |
| 983 tiling->UpdateTilePriorities( | 903 tiling->UpdateTilePriorities( |
| 984 ACTIVE_TREE, | 904 ACTIVE_TREE, |
| 985 device_viewport, | |
| 986 viewport_in_layer_space, | 905 viewport_in_layer_space, |
| 987 visible_layer_rect, | 906 visible_layer_rect, |
| 988 last_layer_bounds, | |
| 989 current_layer_bounds, | |
| 990 last_layer_contents_scale, | |
| 991 current_layer_contents_scale, | 907 current_layer_contents_scale, |
| 992 last_screen_transform, | |
| 993 current_screen_transform, | |
| 994 current_frame_time_in_seconds, | 908 current_frame_time_in_seconds, |
| 995 max_tiles_for_interest_area); | 909 max_tiles_for_interest_area); |
| 996 | 910 |
| 997 ASSERT_TRUE(tiling->TileAt(0, 0)); | 911 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 998 ASSERT_TRUE(tiling->TileAt(0, 1)); | 912 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 999 ASSERT_TRUE(tiling->TileAt(1, 0)); | 913 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1000 ASSERT_TRUE(tiling->TileAt(1, 1)); | 914 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1001 | 915 |
| 1002 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 916 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1003 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 917 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1004 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 918 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1005 | 919 |
| 1006 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 920 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1007 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 921 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1008 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 922 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1009 priority.time_to_visible_in_seconds); | |
| 1010 | 923 |
| 1011 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 924 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1012 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 925 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1013 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 926 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1014 priority.time_to_visible_in_seconds); | |
| 1015 | 927 |
| 1016 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 928 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1017 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 929 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1018 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 930 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1019 priority.time_to_visible_in_seconds); | |
| 1020 | 931 |
| 1021 // Furthermore, in this scenario the bottom-right tile should have the larger | 932 // Furthermore, in this scenario the bottom-right tile should have the larger |
| 1022 // distance to visible. | 933 // distance to visible. |
| 1023 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 934 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1024 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 935 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1025 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | |
| 1026 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 936 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1027 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 937 EXPECT_GT(top_right.distance_to_visible, |
| 1028 top_left.distance_to_visible_in_pixels); | 938 top_left.distance_to_visible); |
| 1029 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | |
| 1030 top_left.distance_to_visible_in_pixels); | |
| 1031 | 939 |
| 1032 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 940 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible); |
| 1033 bottom_left.distance_to_visible_in_pixels); | |
| 1034 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | |
| 1035 top_right.distance_to_visible_in_pixels); | |
| 1036 } | 941 } |
| 1037 | 942 |
| 1038 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 943 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
| 1039 // Perspective transforms need to take a different code path. | 944 // Perspective transforms need to take a different code path. |
| 1040 // This test checks tile priorities of a perspective layer. | 945 // This test checks tile priorities of a perspective layer. |
| 1041 | 946 |
| 1042 FakePictureLayerTilingClient client; | 947 FakePictureLayerTilingClient client; |
| 1043 scoped_ptr<TestablePictureLayerTiling> tiling; | 948 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1044 | 949 |
| 1045 gfx::Size device_viewport(800, 600); | 950 gfx::Size device_viewport(800, 600); |
| 1046 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 951 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1047 gfx::Size last_layer_bounds(200, 200); | 952 gfx::Size last_layer_bounds(200, 200); |
| 1048 gfx::Size current_layer_bounds(200, 200); | 953 gfx::Size current_layer_bounds(200, 200); |
| 1049 float last_layer_contents_scale = 1.f; | |
| 1050 float current_layer_contents_scale = 1.f; | 954 float current_layer_contents_scale = 1.f; |
| 1051 gfx::Transform last_screen_transform; | 955 gfx::Transform last_screen_transform; |
| 1052 gfx::Transform current_screen_transform; | 956 gfx::Transform current_screen_transform; |
| 1053 double current_frame_time_in_seconds = 1.0; | 957 double current_frame_time_in_seconds = 1.0; |
| 1054 size_t max_tiles_for_interest_area = 10000; | 958 size_t max_tiles_for_interest_area = 10000; |
| 1055 | 959 |
| 1056 // A 3d perspective layer rotated about its Y axis, translated to almost | 960 // A 3d perspective layer rotated about its Y axis, translated to almost |
| 1057 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 961 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
| 1058 // the right side, so the top-left tile will technically be closer than the | 962 // the right side, so the top-left tile will technically be closer than the |
| 1059 // top-right. | 963 // top-right. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1077 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 981 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1078 current_screen_transform, device_viewport); | 982 current_screen_transform, device_viewport); |
| 1079 | 983 |
| 1080 client.SetTileSize(gfx::Size(100, 100)); | 984 client.SetTileSize(gfx::Size(100, 100)); |
| 1081 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 985 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1082 current_layer_bounds, | 986 current_layer_bounds, |
| 1083 &client); | 987 &client); |
| 1084 | 988 |
| 1085 tiling->UpdateTilePriorities( | 989 tiling->UpdateTilePriorities( |
| 1086 ACTIVE_TREE, | 990 ACTIVE_TREE, |
| 1087 device_viewport, | |
| 1088 viewport_in_layer_space, | 991 viewport_in_layer_space, |
| 1089 visible_layer_rect, | 992 visible_layer_rect, |
| 1090 last_layer_bounds, | |
| 1091 current_layer_bounds, | |
| 1092 last_layer_contents_scale, | |
| 1093 current_layer_contents_scale, | 993 current_layer_contents_scale, |
| 1094 last_screen_transform, | |
| 1095 current_screen_transform, | |
| 1096 current_frame_time_in_seconds, | 994 current_frame_time_in_seconds, |
| 1097 max_tiles_for_interest_area); | 995 max_tiles_for_interest_area); |
| 1098 | 996 |
| 1099 ASSERT_TRUE(tiling->TileAt(0, 0)); | 997 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1100 ASSERT_TRUE(tiling->TileAt(0, 1)); | 998 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1101 ASSERT_TRUE(tiling->TileAt(1, 0)); | 999 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1102 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1000 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1103 | 1001 |
| 1104 // All tiles will have a positive distance_to_visible | 1002 // All tiles will have a positive distance_to_visible |
| 1105 // and an infinite time_to_visible. | 1003 // and an infinite time_to_visible. |
| 1106 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1004 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1107 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1005 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
| 1108 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1006 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1109 priority.time_to_visible_in_seconds); | |
| 1110 | 1007 |
| 1111 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1008 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1112 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1009 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1113 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1010 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1114 priority.time_to_visible_in_seconds); | |
| 1115 | 1011 |
| 1116 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1012 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1117 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1013 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
| 1118 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1014 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1119 priority.time_to_visible_in_seconds); | |
| 1120 | 1015 |
| 1121 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1016 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1122 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1017 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1123 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1018 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1124 priority.time_to_visible_in_seconds); | |
| 1125 | 1019 |
| 1126 // Furthermore, in this scenario the top-left distance_to_visible | 1020 // Furthermore, in this scenario the top-left distance_to_visible |
| 1127 // will be smallest, followed by top-right. The bottom layers | 1021 // will be smallest, followed by top-right. The bottom layers |
| 1128 // will of course be further than the top layers. | 1022 // will of course be further than the top layers. |
| 1129 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1023 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1130 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1024 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1131 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1025 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1132 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1026 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1133 EXPECT_GT(top_right.distance_to_visible_in_pixels, | |
| 1134 top_left.distance_to_visible_in_pixels); | |
| 1135 | 1027 |
| 1136 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1028 EXPECT_GT(bottom_right.distance_to_visible, |
| 1137 top_right.distance_to_visible_in_pixels); | 1029 top_right.distance_to_visible); |
| 1138 | 1030 |
| 1139 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1031 EXPECT_GT(bottom_left.distance_to_visible, |
| 1140 top_left.distance_to_visible_in_pixels); | 1032 top_left.distance_to_visible); |
| 1141 } | 1033 } |
| 1142 | 1034 |
| 1143 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1035 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
| 1144 // Perspective transforms need to take a different code path. | 1036 // Perspective transforms need to take a different code path. |
| 1145 // This test checks tile priorities of a perspective layer. | 1037 // This test checks tile priorities of a perspective layer. |
| 1146 | 1038 |
| 1147 FakePictureLayerTilingClient client; | 1039 FakePictureLayerTilingClient client; |
| 1148 scoped_ptr<TestablePictureLayerTiling> tiling; | 1040 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1149 | 1041 |
| 1150 gfx::Size device_viewport(800, 600); | 1042 gfx::Size device_viewport(800, 600); |
| 1151 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | |
| 1152 gfx::Size last_layer_bounds(200, 200); | 1043 gfx::Size last_layer_bounds(200, 200); |
| 1153 gfx::Size current_layer_bounds(200, 200); | 1044 gfx::Size current_layer_bounds(200, 200); |
| 1154 float last_layer_contents_scale = 1.f; | |
| 1155 float current_layer_contents_scale = 1.f; | 1045 float current_layer_contents_scale = 1.f; |
| 1156 gfx::Transform last_screen_transform; | 1046 gfx::Transform last_screen_transform; |
| 1157 gfx::Transform current_screen_transform; | 1047 gfx::Transform current_screen_transform; |
| 1158 double current_frame_time_in_seconds = 1.0; | 1048 double current_frame_time_in_seconds = 1.0; |
| 1159 size_t max_tiles_for_interest_area = 10000; | 1049 size_t max_tiles_for_interest_area = 10000; |
| 1160 | 1050 |
| 1161 // A 3d perspective layer rotated about its Y axis, translated to almost | 1051 // A 3d perspective layer rotated about its Y axis, translated to almost |
| 1162 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1052 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
| 1163 // the right side, so the top-left tile will technically be closer than the | 1053 // the right side, so the top-left tile will technically be closer than the |
| 1164 // top-right. | 1054 // top-right. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1180 &clipped); | 1070 &clipped); |
| 1181 ASSERT_TRUE(clipped); | 1071 ASSERT_TRUE(clipped); |
| 1182 | 1072 |
| 1183 MathUtil::MapQuad(current_screen_transform, | 1073 MathUtil::MapQuad(current_screen_transform, |
| 1184 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | 1074 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), |
| 1185 &clipped); | 1075 &clipped); |
| 1186 ASSERT_FALSE(clipped); | 1076 ASSERT_FALSE(clipped); |
| 1187 | 1077 |
| 1188 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1078 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1189 current_screen_transform, device_viewport); | 1079 current_screen_transform, device_viewport); |
| 1080 gfx::Rect visible_layer_rect = viewport_in_layer_space; | |
| 1081 visible_layer_rect.Intersect( | |
| 1082 gfx::Rect(gfx::Point(0, 0), current_layer_bounds)); | |
| 1190 | 1083 |
| 1191 client.SetTileSize(gfx::Size(100, 100)); | 1084 client.SetTileSize(gfx::Size(100, 100)); |
| 1192 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1085 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1193 current_layer_bounds, | 1086 current_layer_bounds, |
| 1194 &client); | 1087 &client); |
| 1195 | 1088 |
| 1196 tiling->UpdateTilePriorities( | 1089 tiling->UpdateTilePriorities( |
| 1197 ACTIVE_TREE, | 1090 ACTIVE_TREE, |
| 1198 device_viewport, | |
| 1199 viewport_in_layer_space, | 1091 viewport_in_layer_space, |
| 1200 visible_layer_rect, | 1092 visible_layer_rect, |
| 1201 last_layer_bounds, | |
| 1202 current_layer_bounds, | |
| 1203 last_layer_contents_scale, | |
| 1204 current_layer_contents_scale, | 1093 current_layer_contents_scale, |
| 1205 last_screen_transform, | |
| 1206 current_screen_transform, | |
| 1207 current_frame_time_in_seconds, | 1094 current_frame_time_in_seconds, |
| 1208 max_tiles_for_interest_area); | 1095 max_tiles_for_interest_area); |
| 1209 | 1096 |
| 1210 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1097 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1211 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1098 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1212 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1099 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1213 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1100 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1214 | 1101 |
| 1215 // Left-side tiles will be clipped by the transform, so we have to assume | 1102 // Left-side tiles will be clipped by the transform, so we have to assume |
| 1216 // they are visible just in case. | 1103 // they are visible just in case. |
| 1217 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1104 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1105 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1106 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1220 | 1107 |
| 1221 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1108 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1222 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1109 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1223 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1110 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1224 | 1111 |
| 1225 // Right-side tiles will have a positive distance_to_visible | 1112 // Right-side tiles will have a positive distance_to_visible |
| 1226 // and an infinite time_to_visible. | 1113 // and an infinite time_to_visible. |
| 1227 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1114 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1228 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1115 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
| 1229 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1116 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1230 priority.time_to_visible_in_seconds); | |
| 1231 | 1117 |
| 1232 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1118 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1233 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1119 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1234 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1120 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1235 priority.time_to_visible_in_seconds); | |
| 1236 } | 1121 } |
| 1237 | 1122 |
| 1238 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1123 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
| 1239 // Test that time_to_visible is computed correctly when | 1124 // Test that time_to_visible is computed correctly when |
| 1240 // there is some motion. | 1125 // there is some motion. |
| 1241 | 1126 |
| 1242 FakePictureLayerTilingClient client; | 1127 FakePictureLayerTilingClient client; |
| 1243 scoped_ptr<TestablePictureLayerTiling> tiling; | 1128 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1244 | 1129 |
| 1245 gfx::Size device_viewport(800, 600); | 1130 gfx::Size device_viewport(800, 600); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1262 current_screen_transform, device_viewport); | 1147 current_screen_transform, device_viewport); |
| 1263 | 1148 |
| 1264 client.SetTileSize(gfx::Size(100, 100)); | 1149 client.SetTileSize(gfx::Size(100, 100)); |
| 1265 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1150 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1266 current_layer_bounds, | 1151 current_layer_bounds, |
| 1267 &client); | 1152 &client); |
| 1268 | 1153 |
| 1269 // previous ("last") frame | 1154 // previous ("last") frame |
| 1270 tiling->UpdateTilePriorities( | 1155 tiling->UpdateTilePriorities( |
| 1271 ACTIVE_TREE, | 1156 ACTIVE_TREE, |
| 1272 device_viewport, | |
| 1273 viewport_in_layer_space, | 1157 viewport_in_layer_space, |
| 1274 visible_layer_rect, | 1158 visible_layer_rect, |
| 1275 last_layer_bounds, | |
| 1276 last_layer_bounds, | |
| 1277 last_layer_contents_scale, | 1159 last_layer_contents_scale, |
| 1278 last_layer_contents_scale, | |
| 1279 last_screen_transform, | |
| 1280 last_screen_transform, | |
| 1281 last_frame_time_in_seconds, | 1160 last_frame_time_in_seconds, |
| 1282 max_tiles_for_interest_area); | 1161 max_tiles_for_interest_area); |
| 1283 | 1162 |
| 1284 // current frame | 1163 // current frame |
| 1285 tiling->UpdateTilePriorities( | 1164 tiling->UpdateTilePriorities( |
| 1286 ACTIVE_TREE, | 1165 ACTIVE_TREE, |
| 1287 device_viewport, | |
| 1288 viewport_in_layer_space, | 1166 viewport_in_layer_space, |
| 1289 visible_layer_rect, | 1167 visible_layer_rect, |
| 1290 last_layer_bounds, | |
| 1291 current_layer_bounds, | |
| 1292 last_layer_contents_scale, | |
| 1293 current_layer_contents_scale, | 1168 current_layer_contents_scale, |
| 1294 last_screen_transform, | |
| 1295 current_screen_transform, | |
| 1296 current_frame_time_in_seconds, | 1169 current_frame_time_in_seconds, |
| 1297 max_tiles_for_interest_area); | 1170 max_tiles_for_interest_area); |
| 1298 | 1171 |
| 1299 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1172 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1300 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1173 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1301 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1174 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1302 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1175 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1303 | 1176 |
| 1304 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1177 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1305 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1178 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1306 EXPECT_FLOAT_EQ(1.f, | 1179 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1307 priority.time_to_visible_in_seconds); | |
| 1308 | 1180 |
| 1309 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1181 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1310 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1182 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1311 EXPECT_FLOAT_EQ(1.f, | 1183 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1312 priority.time_to_visible_in_seconds); | |
| 1313 | 1184 |
| 1314 // time_to_visible for the right hand side layers needs an extra 0.099 | 1185 // time_to_visible for the right hand side layers needs an extra 0.099 |
| 1315 // seconds because this tile is 99 pixels further away. | 1186 // seconds because this tile is 99 pixels further away. |
| 1316 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1187 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1317 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1188 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1318 EXPECT_FLOAT_EQ(1.099f, | 1189 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1319 priority.time_to_visible_in_seconds); | |
| 1320 | 1190 |
| 1321 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1191 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1322 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1192 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1323 EXPECT_FLOAT_EQ(1.099f, | 1193 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1324 priority.time_to_visible_in_seconds); | |
| 1325 } | 1194 } |
| 1326 | 1195 |
| 1327 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1196 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
| 1328 // Each tile of a layer may be affected differently by a transform; Check | 1197 // Each tile of a layer may be affected differently by a transform; Check |
| 1329 // that UpdateTilePriorities correctly accounts for the transform between | 1198 // that UpdateTilePriorities correctly accounts for the transform between |
| 1330 // layer space and screen space. | 1199 // layer space and screen space. |
| 1331 | 1200 |
| 1332 FakePictureLayerTilingClient client; | 1201 FakePictureLayerTilingClient client; |
| 1333 scoped_ptr<TestablePictureLayerTiling> tiling; | 1202 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1334 | 1203 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1360 current_screen_transform, device_viewport); | 1229 current_screen_transform, device_viewport); |
| 1361 | 1230 |
| 1362 client.SetTileSize(gfx::Size(100, 100)); | 1231 client.SetTileSize(gfx::Size(100, 100)); |
| 1363 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1232 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1364 current_layer_bounds, | 1233 current_layer_bounds, |
| 1365 &client); | 1234 &client); |
| 1366 | 1235 |
| 1367 // previous ("last") frame | 1236 // previous ("last") frame |
| 1368 tiling->UpdateTilePriorities( | 1237 tiling->UpdateTilePriorities( |
| 1369 ACTIVE_TREE, | 1238 ACTIVE_TREE, |
| 1370 device_viewport, | |
| 1371 viewport_in_layer_space, | 1239 viewport_in_layer_space, |
| 1372 visible_layer_rect, | 1240 visible_layer_rect, |
| 1373 last_layer_bounds, | |
| 1374 last_layer_bounds, | |
| 1375 last_layer_contents_scale, | 1241 last_layer_contents_scale, |
| 1376 last_layer_contents_scale, | |
| 1377 last_screen_transform, | |
| 1378 last_screen_transform, | |
| 1379 last_frame_time_in_seconds, | 1242 last_frame_time_in_seconds, |
| 1380 max_tiles_for_interest_area); | 1243 max_tiles_for_interest_area); |
| 1381 | 1244 |
| 1382 // current frame | 1245 // current frame |
| 1383 tiling->UpdateTilePriorities( | 1246 tiling->UpdateTilePriorities( |
| 1384 ACTIVE_TREE, | 1247 ACTIVE_TREE, |
| 1385 device_viewport, | |
| 1386 viewport_in_layer_space, | 1248 viewport_in_layer_space, |
| 1387 visible_layer_rect, | 1249 visible_layer_rect, |
| 1388 last_layer_bounds, | |
| 1389 current_layer_bounds, | |
| 1390 last_layer_contents_scale, | |
| 1391 current_layer_contents_scale, | 1250 current_layer_contents_scale, |
| 1392 last_screen_transform, | |
| 1393 current_screen_transform, | |
| 1394 current_frame_time_in_seconds, | 1251 current_frame_time_in_seconds, |
| 1395 max_tiles_for_interest_area); | 1252 max_tiles_for_interest_area); |
| 1396 | 1253 |
| 1397 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1254 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1398 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1255 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1399 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1256 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1400 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1257 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1401 | 1258 |
| 1402 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1259 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1403 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1260 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1404 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1261 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1405 | 1262 |
| 1406 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1263 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1264 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1265 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1409 | 1266 |
| 1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1267 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1268 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1269 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1413 priority.time_to_visible_in_seconds); | |
| 1414 } | 1270 } |
| 1415 | 1271 |
| 1416 } // namespace | 1272 } // namespace |
| 1417 } // namespace cc | 1273 } // namespace cc |
| OLD | NEW |