| 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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 // If a layer has a non-invertible transform, then the starting rect | 748 // If a layer has a non-invertible transform, then the starting rect |
| 745 // for the layer would be empty. | 749 // for the layer would be empty. |
| 746 gfx::Rect in(40, 40, 0, 0); | 750 gfx::Rect in(40, 40, 0, 0); |
| 747 gfx::Rect bounds(0, 0, 10, 10); | 751 gfx::Rect bounds(0, 0, 10, 10); |
| 748 int64 target_area = 400 * 400; | 752 int64 target_area = 400 * 400; |
| 749 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 753 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 750 in, target_area, bounds, NULL); | 754 in, target_area, bounds, NULL); |
| 751 EXPECT_TRUE(out.IsEmpty()); | 755 EXPECT_TRUE(out.IsEmpty()); |
| 752 } | 756 } |
| 753 | 757 |
| 758 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { |
| 759 FakePictureLayerTilingClient client; |
| 760 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 761 |
| 762 gfx::Rect viewport(50, 50, 100, 100); |
| 763 gfx::Size layer_bounds(200, 200); |
| 764 |
| 765 client.SetTileSize(gfx::Size(10, 10)); |
| 766 |
| 767 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); |
| 768 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 769 |
| 770 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
| 771 EXPECT_FALSE(empty_iterator); |
| 772 |
| 773 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
| 774 |
| 775 // Sanity check. |
| 776 EXPECT_EQ(36u, all_tiles.size()); |
| 777 |
| 778 for (int i = 0; i < 3; ++i) { |
| 779 PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); |
| 780 |
| 781 // On the third iteration, everything is marked as ready to draw so we |
| 782 // should get a NULL immediately. |
| 783 if (i == 2) { |
| 784 EXPECT_FALSE(it); |
| 785 break; |
| 786 } |
| 787 |
| 788 // There are 3 bins in TilePriority. |
| 789 bool have_tiles[3] = {}; |
| 790 |
| 791 EXPECT_TRUE(it); |
| 792 std::set<Tile*> unique_tiles; |
| 793 unique_tiles.insert(*it); |
| 794 Tile* last_tile = *it; |
| 795 have_tiles[last_tile->priority(ACTIVE_TREE).priority_bin] = true; |
| 796 |
| 797 // On the second iteration, mark everything as ready to draw (solid color). |
| 798 if (i == 1) { |
| 799 ManagedTileState::TileVersion& tile_version = |
| 800 last_tile->GetTileVersionForTesting( |
| 801 last_tile->DetermineRasterModeForTree(ACTIVE_TREE)); |
| 802 tile_version.SetSolidColorForTesting(SK_ColorRED); |
| 803 } |
| 804 ++it; |
| 805 while (it) { |
| 806 Tile* new_tile = *it; |
| 807 ++it; |
| 808 unique_tiles.insert(new_tile); |
| 809 |
| 810 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); |
| 811 TilePriority new_priority = new_tile->priority(ACTIVE_TREE); |
| 812 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin); |
| 813 if (last_priority.priority_bin == new_priority.priority_bin) { |
| 814 EXPECT_LE(last_priority.distance_to_visible, |
| 815 new_priority.distance_to_visible); |
| 816 } |
| 817 have_tiles[new_priority.priority_bin] = true; |
| 818 |
| 819 last_tile = new_tile; |
| 820 |
| 821 // On the second iteration, mark everything as ready to draw (solid |
| 822 // color). |
| 823 if (i == 1) { |
| 824 ManagedTileState::TileVersion& tile_version = |
| 825 last_tile->GetTileVersionForTesting( |
| 826 last_tile->DetermineRasterModeForTree(ACTIVE_TREE)); |
| 827 tile_version.SetSolidColorForTesting(SK_ColorRED); |
| 828 } |
| 829 } |
| 830 |
| 831 // We should have now and eventually tiles, but not soon tiles because the |
| 832 // viewport is static. |
| 833 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
| 834 EXPECT_FALSE(have_tiles[TilePriority::SOON]); |
| 835 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
| 836 |
| 837 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); |
| 838 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, i + 2); |
| 839 } |
| 840 } |
| 841 |
| 842 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { |
| 843 FakePictureLayerTilingClient client; |
| 844 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 845 |
| 846 gfx::Rect viewport(50, 0, 100, 100); |
| 847 gfx::Size layer_bounds(500, 500); |
| 848 |
| 849 client.SetTileSize(gfx::Size(30, 30)); |
| 850 |
| 851 tiling = TestablePictureLayerTiling::Create(1.f, layer_bounds, &client); |
| 852 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 853 |
| 854 viewport = gfx::Rect(50, 50, 100, 100); |
| 855 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.1); |
| 856 |
| 857 // There are 3 bins in TilePriority. |
| 858 bool have_tiles[3] = {}; |
| 859 Tile* last_tile = NULL; |
| 860 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); it; |
| 861 ++it) { |
| 862 if (!last_tile) |
| 863 last_tile = *it; |
| 864 |
| 865 Tile* new_tile = *it; |
| 866 |
| 867 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); |
| 868 TilePriority new_priority = new_tile->priority(ACTIVE_TREE); |
| 869 |
| 870 have_tiles[new_priority.priority_bin] = true; |
| 871 |
| 872 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin); |
| 873 if (last_priority.priority_bin == new_priority.priority_bin) { |
| 874 EXPECT_LE(last_priority.distance_to_visible, |
| 875 new_priority.distance_to_visible); |
| 876 } |
| 877 last_tile = new_tile; |
| 878 } |
| 879 |
| 880 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
| 881 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
| 882 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
| 883 } |
| 884 |
| 885 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorNoResources) { |
| 886 FakePictureLayerTilingClient client; |
| 887 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 888 |
| 889 gfx::Rect viewport(50, 0, 100, 100); |
| 890 gfx::Size layer_bounds(500, 500); |
| 891 |
| 892 client.SetTileSize(gfx::Size(30, 30)); |
| 893 |
| 894 tiling = TestablePictureLayerTiling::Create(1.f, layer_bounds, &client); |
| 895 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 896 |
| 897 viewport = gfx::Rect(50, 50, 100, 100); |
| 898 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.1); |
| 899 |
| 900 PictureLayerTiling::TilingEvictionTileIterator it(tiling.get()); |
| 901 EXPECT_FALSE(it); |
| 902 } |
| 903 |
| 904 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorSomeResources) { |
| 905 scoped_refptr<TestContextProvider> context_provider = |
| 906 TestContextProvider::Create(); |
| 907 scoped_ptr<FakeOutputSurface> output_surface = |
| 908 FakeOutputSurface::Create3d(context_provider).Pass(); |
| 909 FakeOutputSurfaceClient output_surface_client; |
| 910 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 911 scoped_ptr<ResourceProvider> resource_provider = |
| 912 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1).Pass(); |
| 913 |
| 914 FakePictureLayerTilingClient client(resource_provider.get()); |
| 915 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 916 |
| 917 gfx::Rect viewport(50, 0, 100, 100); |
| 918 gfx::Size layer_bounds(500, 500); |
| 919 |
| 920 client.SetTileSize(gfx::Size(30, 30)); |
| 921 |
| 922 tiling = TestablePictureLayerTiling::Create(1.f, layer_bounds, &client); |
| 923 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 924 |
| 925 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
| 926 |
| 927 std::vector<Tile*> resource_tiles; |
| 928 for (size_t i = 0; i < all_tiles.size(); ++i) { |
| 929 if (i % 2) |
| 930 continue; |
| 931 resource_tiles.push_back(all_tiles[i]); |
| 932 } |
| 933 |
| 934 client.tile_manager()->InitializeTilesWithResourcesForTesting( |
| 935 resource_tiles, resource_provider.get()); |
| 936 |
| 937 viewport = gfx::Rect(50, 50, 100, 100); |
| 938 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.1); |
| 939 |
| 940 size_t count = 0; |
| 941 std::set<Tile*> unique_tiles; |
| 942 for (PictureLayerTiling::TilingEvictionTileIterator it(tiling.get()); it; |
| 943 ++it) { |
| 944 ++count; |
| 945 EXPECT_TRUE(it); |
| 946 unique_tiles.insert(*it); |
| 947 } |
| 948 |
| 949 EXPECT_EQ(resource_tiles.size(), count); |
| 950 EXPECT_EQ(count, unique_tiles.size()); |
| 951 } |
| 952 |
| 754 static void TileExists(bool exists, Tile* tile, | 953 static void TileExists(bool exists, Tile* tile, |
| 755 const gfx::Rect& geometry_rect) { | 954 const gfx::Rect& geometry_rect) { |
| 756 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 955 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
| 757 } | 956 } |
| 758 | 957 |
| 759 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 958 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
| 760 gfx::Size layer_bounds(1099, 801); | 959 gfx::Size layer_bounds(1099, 801); |
| 761 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 960 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 762 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 961 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 763 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 962 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); | 1658 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1460 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1659 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1461 | 1660 |
| 1462 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1661 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1463 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1662 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1464 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1663 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1465 } | 1664 } |
| 1466 | 1665 |
| 1467 } // namespace | 1666 } // namespace |
| 1468 } // namespace cc | 1667 } // namespace cc |
| OLD | NEW |