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 #include <set> | |
8 | 9 |
9 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
10 #include "cc/resources/picture_layer_tiling_set.h" | 11 #include "cc/resources/picture_layer_tiling_set.h" |
12 #include "cc/test/fake_output_surface.h" | |
13 #include "cc/test/fake_output_surface_client.h" | |
11 #include "cc/test/fake_picture_layer_tiling_client.h" | 14 #include "cc/test/fake_picture_layer_tiling_client.h" |
15 #include "cc/test/test_context_provider.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/rect_conversions.h" | 17 #include "ui/gfx/rect_conversions.h" |
14 #include "ui/gfx/size_conversions.h" | 18 #include "ui/gfx/size_conversions.h" |
15 | 19 |
16 namespace cc { | 20 namespace cc { |
17 namespace { | 21 namespace { |
18 | 22 |
19 static gfx::Rect ViewportInLayerSpace( | 23 static gfx::Rect ViewportInLayerSpace( |
20 const gfx::Transform& transform, | 24 const gfx::Transform& transform, |
21 const gfx::Size& device_viewport) { | 25 const gfx::Size& device_viewport) { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 bool have_soon = false; | 489 bool have_soon = false; |
486 | 490 |
487 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | 491 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and |
488 // some EVENTUALLY tiles. | 492 // some EVENTUALLY tiles. |
489 for (int i = 0; i < 6; ++i) { | 493 for (int i = 0; i < 6; ++i) { |
490 for (int j = 0; j < 6; ++j) { | 494 for (int j = 0; j < 6; ++j) { |
491 Tile* tile = tiling->TileAt(i, j); | 495 Tile* tile = tiling->TileAt(i, j); |
492 TilePriority priority = tile->priority(ACTIVE_TREE); | 496 TilePriority priority = tile->priority(ACTIVE_TREE); |
493 | 497 |
494 if (viewport_in_content_space.Intersects(tile->content_rect())) { | 498 if (viewport_in_content_space.Intersects(tile->content_rect())) { |
495 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 499 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i |
496 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 500 << " j: " << j; |
501 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i | |
502 << " j: " << j; | |
497 have_now = true; | 503 have_now = true; |
498 } else if (skewport.Intersects(tile->content_rect())) { | 504 } else if (skewport.Intersects(tile->content_rect())) { |
499 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); | 505 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i |
500 EXPECT_GT(priority.distance_to_visible, 0.f); | 506 << " j: " << j; |
507 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | |
508 << " j: " << j; | |
501 have_soon = true; | 509 have_soon = true; |
502 } else { | 510 } else { |
503 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); | 511 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin) |
504 EXPECT_GT(priority.distance_to_visible, 0.f); | 512 << "i: " << i << " j: " << j; |
513 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | |
514 << " j: " << j; | |
505 have_eventually = true; | 515 have_eventually = true; |
506 } | 516 } |
507 } | 517 } |
508 } | 518 } |
509 | 519 |
510 EXPECT_TRUE(have_now); | 520 EXPECT_TRUE(have_now); |
511 EXPECT_TRUE(have_soon); | 521 EXPECT_TRUE(have_soon); |
512 EXPECT_TRUE(have_eventually); | 522 EXPECT_TRUE(have_eventually); |
513 | 523 |
514 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 524 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 // If a layer has a non-invertible transform, then the starting rect | 754 // If a layer has a non-invertible transform, then the starting rect |
745 // for the layer would be empty. | 755 // for the layer would be empty. |
746 gfx::Rect in(40, 40, 0, 0); | 756 gfx::Rect in(40, 40, 0, 0); |
747 gfx::Rect bounds(0, 0, 10, 10); | 757 gfx::Rect bounds(0, 0, 10, 10); |
748 int64 target_area = 400 * 400; | 758 int64 target_area = 400 * 400; |
749 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 759 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
750 in, target_area, bounds, NULL); | 760 in, target_area, bounds, NULL); |
751 EXPECT_TRUE(out.IsEmpty()); | 761 EXPECT_TRUE(out.IsEmpty()); |
752 } | 762 } |
753 | 763 |
764 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { | |
765 FakePictureLayerTilingClient client; | |
766 scoped_ptr<TestablePictureLayerTiling> tiling; | |
767 | |
768 gfx::Rect viewport(50, 50, 100, 100); | |
769 gfx::Size layer_bounds(200, 200); | |
770 | |
771 client.SetTileSize(gfx::Size(10, 10)); | |
772 | |
773 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); | |
774 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); | |
775 | |
776 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | |
777 EXPECT_FALSE(empty_iterator); | |
778 | |
779 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | |
780 | |
781 // Sanity check. | |
782 EXPECT_EQ(36u, all_tiles.size()); | |
783 | |
784 for (int i = 0; i < 3; ++i) { | |
epennerAtGoogle
2014/03/05 00:05:50
Might help to say why there is three passes.
vmpstr
2014/03/05 00:37:21
I'll add a comment.
| |
785 PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); | |
786 | |
787 // There are 3 bins in TilePriority. | |
epennerAtGoogle
2014/03/05 00:05:50
Can we add a TilePriority::NUM_PRIORITIES, or is t
vmpstr
2014/03/05 00:37:21
There was a bit of a discussion a while back on th
| |
788 bool have_tiles[3] = {}; | |
789 | |
790 EXPECT_TRUE(it); | |
791 std::set<Tile*> unique_tiles; | |
792 unique_tiles.insert(*it); | |
793 Tile* last_tile = *it; | |
794 have_tiles[last_tile->priority(ACTIVE_TREE).priority_bin] = true; | |
795 | |
796 // On the second iteration, mark everything as ready to draw (solid color). | |
epennerAtGoogle
2014/03/05 00:05:50
It wasn't super clear to me what impact this shoul
vmpstr
2014/03/05 00:37:21
I agree that this part is a bit confusing (and thi
| |
797 if (i == 1) { | |
798 ManagedTileState::TileVersion& tile_version = | |
799 last_tile->GetTileVersionForTesting( | |
800 last_tile->DetermineRasterModeForTree(ACTIVE_TREE)); | |
801 tile_version.SetSolidColorForTesting(SK_ColorRED); | |
802 } | |
803 ++it; | |
804 int eventually_bin_order_correct_count = 0; | |
805 int eventually_bin_order_incorrect_count = 0; | |
806 while (it) { | |
807 Tile* new_tile = *it; | |
808 ++it; | |
809 unique_tiles.insert(new_tile); | |
epennerAtGoogle
2014/03/05 00:05:50
Should this check that the tile is not already in
vmpstr
2014/03/05 00:37:21
This goes with the check on line 848 that ensures
| |
810 | |
811 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); | |
812 TilePriority new_priority = new_tile->priority(ACTIVE_TREE); | |
813 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin); | |
814 if (last_priority.priority_bin == new_priority.priority_bin) { | |
815 if (last_priority.priority_bin == TilePriority::EVENTUALLY) { | |
816 bool order_correct = last_priority.distance_to_visible <= | |
817 new_priority.distance_to_visible; | |
818 eventually_bin_order_correct_count += order_correct; | |
819 eventually_bin_order_incorrect_count += !order_correct; | |
820 } else { | |
821 EXPECT_LE(last_priority.distance_to_visible, | |
822 new_priority.distance_to_visible); | |
823 } | |
824 } | |
825 have_tiles[new_priority.priority_bin] = true; | |
826 | |
827 last_tile = new_tile; | |
828 | |
829 // On the second iteration, mark everything as ready to draw (solid | |
830 // color). | |
831 if (i == 1) { | |
832 ManagedTileState::TileVersion& tile_version = | |
833 last_tile->GetTileVersionForTesting( | |
834 last_tile->DetermineRasterModeForTree(ACTIVE_TREE)); | |
835 tile_version.SetSolidColorForTesting(SK_ColorRED); | |
836 } | |
837 } | |
838 | |
839 EXPECT_GT(eventually_bin_order_correct_count, | |
840 eventually_bin_order_incorrect_count); | |
epennerAtGoogle
2014/03/05 00:05:50
I've looked at the above code but this is still co
vmpstr
2014/03/05 00:37:21
This part is a consequence of the spiral iterator.
| |
841 | |
842 // We should have now and eventually tiles, but not soon tiles because the | |
843 // viewport is static. | |
844 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | |
845 EXPECT_FALSE(have_tiles[TilePriority::SOON]); | |
846 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | |
847 | |
848 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); | |
849 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, i + 2); | |
850 } | |
851 } | |
852 | |
853 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { | |
854 FakePictureLayerTilingClient client; | |
855 scoped_ptr<TestablePictureLayerTiling> tiling; | |
856 | |
857 gfx::Rect viewport(50, 0, 100, 100); | |
858 gfx::Size layer_bounds(500, 500); | |
859 | |
860 client.SetTileSize(gfx::Size(30, 30)); | |
861 | |
862 tiling = TestablePictureLayerTiling::Create(1.f, layer_bounds, &client); | |
863 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); | |
864 | |
865 viewport = gfx::Rect(50, 50, 100, 100); | |
866 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.1); | |
867 | |
868 // There are 3 bins in TilePriority. | |
epennerAtGoogle
2014/03/05 00:05:50
Same here.
| |
869 bool have_tiles[3] = {}; | |
870 Tile* last_tile = NULL; | |
871 int eventually_bin_order_correct_count = 0; | |
872 int eventually_bin_order_incorrect_count = 0; | |
873 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); it; | |
874 ++it) { | |
875 if (!last_tile) | |
876 last_tile = *it; | |
877 | |
878 Tile* new_tile = *it; | |
879 | |
880 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); | |
881 TilePriority new_priority = new_tile->priority(ACTIVE_TREE); | |
882 | |
883 have_tiles[new_priority.priority_bin] = true; | |
884 | |
885 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin); | |
886 if (last_priority.priority_bin == new_priority.priority_bin) { | |
887 if (last_priority.priority_bin == TilePriority::EVENTUALLY) { | |
888 bool order_correct = last_priority.distance_to_visible <= | |
889 new_priority.distance_to_visible; | |
890 eventually_bin_order_correct_count += order_correct; | |
891 eventually_bin_order_incorrect_count += !order_correct; | |
892 } else { | |
893 EXPECT_LE(last_priority.distance_to_visible, | |
894 new_priority.distance_to_visible); | |
895 } | |
896 } | |
897 last_tile = new_tile; | |
898 } | |
899 | |
900 EXPECT_GT(eventually_bin_order_correct_count, | |
901 eventually_bin_order_incorrect_count); | |
902 | |
903 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | |
904 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | |
905 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | |
906 } | |
907 | |
754 static void TileExists(bool exists, Tile* tile, | 908 static void TileExists(bool exists, Tile* tile, |
755 const gfx::Rect& geometry_rect) { | 909 const gfx::Rect& geometry_rect) { |
756 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 910 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
757 } | 911 } |
758 | 912 |
759 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 913 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
760 gfx::Size layer_bounds(1099, 801); | 914 gfx::Size layer_bounds(1099, 801); |
761 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 915 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
762 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 916 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
763 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 917 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1613 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1460 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1614 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1461 | 1615 |
1462 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1616 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1463 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1617 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1464 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1618 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1465 } | 1619 } |
1466 | 1620 |
1467 } // namespace | 1621 } // namespace |
1468 } // namespace cc | 1622 } // namespace cc |
OLD | NEW |