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