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 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 852 |
853 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 853 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
854 EXPECT_FLOAT_EQ(30.f, priority.distance_to_visible); | 854 EXPECT_FLOAT_EQ(30.f, priority.distance_to_visible); |
855 } | 855 } |
856 | 856 |
857 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 857 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
858 gfx::Rect in(40, 50, 100, 200); | 858 gfx::Rect in(40, 50, 100, 200); |
859 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 859 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
860 int64 target_area = 100 * 200; | 860 int64 target_area = 100 * 200; |
861 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 861 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
862 in, target_area, bounds, NULL); | 862 in, target_area, bounds, nullptr); |
863 EXPECT_EQ(in.ToString(), out.ToString()); | 863 EXPECT_EQ(in.ToString(), out.ToString()); |
864 } | 864 } |
865 | 865 |
866 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 866 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
867 gfx::Rect in(40, 50, 100, 200); | 867 gfx::Rect in(40, 50, 100, 200); |
868 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 868 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
869 int64 target_area = 100 * 100; | 869 int64 target_area = 100 * 100; |
870 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 870 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
871 in, target_area, bounds, NULL); | 871 in, target_area, bounds, nullptr); |
872 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 872 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
873 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 873 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
874 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); | 874 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); |
875 | 875 |
876 // |in| represents the visible rect, and |out| represents the eventually rect. | 876 // |in| represents the visible rect, and |out| represents the eventually rect. |
877 // If the eventually rect doesn't contain the visible rect, we will start | 877 // If the eventually rect doesn't contain the visible rect, we will start |
878 // losing tiles. | 878 // losing tiles. |
879 EXPECT_TRUE(out.Contains(in)); | 879 EXPECT_TRUE(out.Contains(in)); |
880 EXPECT_TRUE(bounds.Contains(out)); | 880 EXPECT_TRUE(bounds.Contains(out)); |
881 } | 881 } |
882 | 882 |
883 TEST(PictureLayerTilingTest, ExpandRectUnbounded) { | 883 TEST(PictureLayerTilingTest, ExpandRectUnbounded) { |
884 gfx::Rect in(40, 50, 100, 200); | 884 gfx::Rect in(40, 50, 100, 200); |
885 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 885 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
886 int64 target_area = 200 * 200; | 886 int64 target_area = 200 * 200; |
887 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 887 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
888 in, target_area, bounds, NULL); | 888 in, target_area, bounds, nullptr); |
889 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 889 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
890 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 890 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
891 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); | 891 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); |
892 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100); | 892 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100); |
893 EXPECT_TRUE(bounds.Contains(out)); | 893 EXPECT_TRUE(bounds.Contains(out)); |
894 } | 894 } |
895 | 895 |
896 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) { | 896 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) { |
897 gfx::Rect in(40, 50, 100, 200); | 897 gfx::Rect in(40, 50, 100, 200); |
898 gfx::Rect bounds(50, 60, 40, 30); | 898 gfx::Rect bounds(50, 60, 40, 30); |
899 int64 target_area = 200 * 200; | 899 int64 target_area = 200 * 200; |
900 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 900 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
901 in, target_area, bounds, NULL); | 901 in, target_area, bounds, nullptr); |
902 EXPECT_EQ(bounds.ToString(), out.ToString()); | 902 EXPECT_EQ(bounds.ToString(), out.ToString()); |
903 } | 903 } |
904 | 904 |
905 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) { | 905 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) { |
906 gfx::Rect in(40, 50, 100, 200); | 906 gfx::Rect in(40, 50, 100, 200); |
907 gfx::Rect bounds = in; | 907 gfx::Rect bounds = in; |
908 int64 target_area = 200 * 200; | 908 int64 target_area = 200 * 200; |
909 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 909 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
910 in, target_area, bounds, NULL); | 910 in, target_area, bounds, nullptr); |
911 EXPECT_EQ(bounds.ToString(), out.ToString()); | 911 EXPECT_EQ(bounds.ToString(), out.ToString()); |
912 } | 912 } |
913 | 913 |
914 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) { | 914 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) { |
915 gfx::Rect in(40, 50, 100, 200); | 915 gfx::Rect in(40, 50, 100, 200); |
916 gfx::Rect bounds(45, 0, 90, 300); | 916 gfx::Rect bounds(45, 0, 90, 300); |
917 int64 target_area = 200 * 200; | 917 int64 target_area = 200 * 200; |
918 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 918 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
919 in, target_area, bounds, NULL); | 919 in, target_area, bounds, nullptr); |
920 EXPECT_EQ(bounds.ToString(), out.ToString()); | 920 EXPECT_EQ(bounds.ToString(), out.ToString()); |
921 } | 921 } |
922 | 922 |
923 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) { | 923 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) { |
924 gfx::Rect in(40, 50, 100, 200); | 924 gfx::Rect in(40, 50, 100, 200); |
925 gfx::Rect bounds(40, 0, 100, 300); | 925 gfx::Rect bounds(40, 0, 100, 300); |
926 int64 target_area = 200 * 200; | 926 int64 target_area = 200 * 200; |
927 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 927 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
928 in, target_area, bounds, NULL); | 928 in, target_area, bounds, nullptr); |
929 EXPECT_EQ(bounds.ToString(), out.ToString()); | 929 EXPECT_EQ(bounds.ToString(), out.ToString()); |
930 } | 930 } |
931 | 931 |
932 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) { | 932 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) { |
933 gfx::Rect in(40, 50, 100, 200); | 933 gfx::Rect in(40, 50, 100, 200); |
934 gfx::Rect bounds(0, 55, 180, 190); | 934 gfx::Rect bounds(0, 55, 180, 190); |
935 int64 target_area = 200 * 200; | 935 int64 target_area = 200 * 200; |
936 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 936 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
937 in, target_area, bounds, NULL); | 937 in, target_area, bounds, nullptr); |
938 EXPECT_EQ(bounds.ToString(), out.ToString()); | 938 EXPECT_EQ(bounds.ToString(), out.ToString()); |
939 } | 939 } |
940 | 940 |
941 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) { | 941 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) { |
942 gfx::Rect in(40, 50, 100, 200); | 942 gfx::Rect in(40, 50, 100, 200); |
943 gfx::Rect bounds(0, 50, 180, 200); | 943 gfx::Rect bounds(0, 50, 180, 200); |
944 int64 target_area = 200 * 200; | 944 int64 target_area = 200 * 200; |
945 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 945 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
946 in, target_area, bounds, NULL); | 946 in, target_area, bounds, nullptr); |
947 EXPECT_EQ(bounds.ToString(), out.ToString()); | 947 EXPECT_EQ(bounds.ToString(), out.ToString()); |
948 } | 948 } |
949 | 949 |
950 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) { | 950 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) { |
951 gfx::Rect in(40, 50, 100, 200); | 951 gfx::Rect in(40, 50, 100, 200); |
952 gfx::Rect bounds(20, -1000, 10000, 10000); | 952 gfx::Rect bounds(20, -1000, 10000, 10000); |
953 int64 target_area = 200 * 200; | 953 int64 target_area = 200 * 200; |
954 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 954 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
955 in, target_area, bounds, NULL); | 955 in, target_area, bounds, nullptr); |
956 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 956 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
957 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); | 957 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); |
958 EXPECT_LE(out.width() * out.height(), target_area); | 958 EXPECT_LE(out.width() * out.height(), target_area); |
959 EXPECT_GT(out.width() * out.height(), | 959 EXPECT_GT(out.width() * out.height(), |
960 target_area - out.width() - out.height() * 2); | 960 target_area - out.width() - out.height() * 2); |
961 EXPECT_TRUE(bounds.Contains(out)); | 961 EXPECT_TRUE(bounds.Contains(out)); |
962 } | 962 } |
963 | 963 |
964 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { | 964 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { |
965 gfx::Rect in(40, 50, 100, 200); | 965 gfx::Rect in(40, 50, 100, 200); |
966 gfx::Rect bounds(-1000, -1000, 1000+120, 10000); | 966 gfx::Rect bounds(-1000, -1000, 1000+120, 10000); |
967 int64 target_area = 200 * 200; | 967 int64 target_area = 200 * 200; |
968 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 968 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
969 in, target_area, bounds, NULL); | 969 in, target_area, bounds, nullptr); |
970 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 970 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
971 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); | 971 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); |
972 EXPECT_LE(out.width() * out.height(), target_area); | 972 EXPECT_LE(out.width() * out.height(), target_area); |
973 EXPECT_GT(out.width() * out.height(), | 973 EXPECT_GT(out.width() * out.height(), |
974 target_area - out.width() - out.height() * 2); | 974 target_area - out.width() - out.height() * 2); |
975 EXPECT_TRUE(bounds.Contains(out)); | 975 EXPECT_TRUE(bounds.Contains(out)); |
976 } | 976 } |
977 | 977 |
978 TEST(PictureLayerTilingTest, ExpandRectBoundedTop) { | 978 TEST(PictureLayerTilingTest, ExpandRectBoundedTop) { |
979 gfx::Rect in(40, 50, 100, 200); | 979 gfx::Rect in(40, 50, 100, 200); |
980 gfx::Rect bounds(-1000, 30, 10000, 10000); | 980 gfx::Rect bounds(-1000, 30, 10000, 10000); |
981 int64 target_area = 200 * 200; | 981 int64 target_area = 200 * 200; |
982 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 982 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
983 in, target_area, bounds, NULL); | 983 in, target_area, bounds, nullptr); |
984 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 984 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
985 EXPECT_EQ(out.right() - in.right(), out.bottom() - in.bottom()); | 985 EXPECT_EQ(out.right() - in.right(), out.bottom() - in.bottom()); |
986 EXPECT_LE(out.width() * out.height(), target_area); | 986 EXPECT_LE(out.width() * out.height(), target_area); |
987 EXPECT_GT(out.width() * out.height(), | 987 EXPECT_GT(out.width() * out.height(), |
988 target_area - out.width() * 2 - out.height()); | 988 target_area - out.width() * 2 - out.height()); |
989 EXPECT_TRUE(bounds.Contains(out)); | 989 EXPECT_TRUE(bounds.Contains(out)); |
990 } | 990 } |
991 | 991 |
992 TEST(PictureLayerTilingTest, ExpandRectBoundedBottom) { | 992 TEST(PictureLayerTilingTest, ExpandRectBoundedBottom) { |
993 gfx::Rect in(40, 50, 100, 200); | 993 gfx::Rect in(40, 50, 100, 200); |
994 gfx::Rect bounds(-1000, -1000, 10000, 1000 + 220); | 994 gfx::Rect bounds(-1000, -1000, 10000, 1000 + 220); |
995 int64 target_area = 200 * 200; | 995 int64 target_area = 200 * 200; |
996 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 996 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
997 in, target_area, bounds, NULL); | 997 in, target_area, bounds, nullptr); |
998 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 998 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
999 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); | 999 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); |
1000 EXPECT_LE(out.width() * out.height(), target_area); | 1000 EXPECT_LE(out.width() * out.height(), target_area); |
1001 EXPECT_GT(out.width() * out.height(), | 1001 EXPECT_GT(out.width() * out.height(), |
1002 target_area - out.width() * 2 - out.height()); | 1002 target_area - out.width() * 2 - out.height()); |
1003 EXPECT_TRUE(bounds.Contains(out)); | 1003 EXPECT_TRUE(bounds.Contains(out)); |
1004 } | 1004 } |
1005 | 1005 |
1006 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { | 1006 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { |
1007 gfx::Rect in(40, 50, 100, 200); | 1007 gfx::Rect in(40, 50, 100, 200); |
1008 gfx::Rect bounds(0, -4000, 100+40+20, 100000); | 1008 gfx::Rect bounds(0, -4000, 100+40+20, 100000); |
1009 int64 target_area = 400 * 400; | 1009 int64 target_area = 400 * 400; |
1010 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1010 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1011 in, target_area, bounds, NULL); | 1011 in, target_area, bounds, nullptr); |
1012 EXPECT_EQ(20, out.right() - in.right()); | 1012 EXPECT_EQ(20, out.right() - in.right()); |
1013 EXPECT_EQ(40, in.x() - out.x()); | 1013 EXPECT_EQ(40, in.x() - out.x()); |
1014 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 1014 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
1015 EXPECT_LE(out.width() * out.height(), target_area); | 1015 EXPECT_LE(out.width() * out.height(), target_area); |
1016 EXPECT_GT(out.width() * out.height(), | 1016 EXPECT_GT(out.width() * out.height(), |
1017 target_area - out.width() * 2); | 1017 target_area - out.width() * 2); |
1018 EXPECT_TRUE(bounds.Contains(out)); | 1018 EXPECT_TRUE(bounds.Contains(out)); |
1019 } | 1019 } |
1020 | 1020 |
1021 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { | 1021 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { |
1022 gfx::Rect in(40, 50, 100, 200); | 1022 gfx::Rect in(40, 50, 100, 200); |
1023 gfx::Rect bounds(-4000, 0, 100000, 200+50+30); | 1023 gfx::Rect bounds(-4000, 0, 100000, 200+50+30); |
1024 int64 target_area = 400 * 400; | 1024 int64 target_area = 400 * 400; |
1025 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1025 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1026 in, target_area, bounds, NULL); | 1026 in, target_area, bounds, nullptr); |
1027 EXPECT_EQ(30, out.bottom() - in.bottom()); | 1027 EXPECT_EQ(30, out.bottom() - in.bottom()); |
1028 EXPECT_EQ(50, in.y() - out.y()); | 1028 EXPECT_EQ(50, in.y() - out.y()); |
1029 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 1029 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
1030 EXPECT_LE(out.width() * out.height(), target_area); | 1030 EXPECT_LE(out.width() * out.height(), target_area); |
1031 EXPECT_GT(out.width() * out.height(), | 1031 EXPECT_GT(out.width() * out.height(), |
1032 target_area - out.height() * 2); | 1032 target_area - out.height() * 2); |
1033 EXPECT_TRUE(bounds.Contains(out)); | 1033 EXPECT_TRUE(bounds.Contains(out)); |
1034 } | 1034 } |
1035 | 1035 |
1036 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { | 1036 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { |
1037 gfx::Rect in(400, 500, 100, 200); | 1037 gfx::Rect in(400, 500, 100, 200); |
1038 gfx::Rect bounds(0, 0, 10, 10); | 1038 gfx::Rect bounds(0, 0, 10, 10); |
1039 int64 target_area = 400 * 400; | 1039 int64 target_area = 400 * 400; |
1040 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1040 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1041 in, target_area, bounds, NULL); | 1041 in, target_area, bounds, nullptr); |
1042 EXPECT_TRUE(out.IsEmpty()); | 1042 EXPECT_TRUE(out.IsEmpty()); |
1043 } | 1043 } |
1044 | 1044 |
1045 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedFullyCover) { | 1045 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedFullyCover) { |
1046 gfx::Rect in(40, 50, 100, 100); | 1046 gfx::Rect in(40, 50, 100, 100); |
1047 gfx::Rect bounds(0, 0, 10, 10); | 1047 gfx::Rect bounds(0, 0, 10, 10); |
1048 int64 target_area = 400 * 400; | 1048 int64 target_area = 400 * 400; |
1049 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1049 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1050 in, target_area, bounds, NULL); | 1050 in, target_area, bounds, nullptr); |
1051 EXPECT_EQ(bounds.ToString(), out.ToString()); | 1051 EXPECT_EQ(bounds.ToString(), out.ToString()); |
1052 } | 1052 } |
1053 | 1053 |
1054 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedPartlyCover) { | 1054 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedPartlyCover) { |
1055 gfx::Rect in(600, 600, 100, 100); | 1055 gfx::Rect in(600, 600, 100, 100); |
1056 gfx::Rect bounds(0, 0, 500, 500); | 1056 gfx::Rect bounds(0, 0, 500, 500); |
1057 int64 target_area = 400 * 400; | 1057 int64 target_area = 400 * 400; |
1058 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1058 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1059 in, target_area, bounds, NULL); | 1059 in, target_area, bounds, nullptr); |
1060 EXPECT_EQ(bounds.right(), out.right()); | 1060 EXPECT_EQ(bounds.right(), out.right()); |
1061 EXPECT_EQ(bounds.bottom(), out.bottom()); | 1061 EXPECT_EQ(bounds.bottom(), out.bottom()); |
1062 EXPECT_LE(out.width() * out.height(), target_area); | 1062 EXPECT_LE(out.width() * out.height(), target_area); |
1063 EXPECT_GT(out.width() * out.height(), | 1063 EXPECT_GT(out.width() * out.height(), |
1064 target_area - out.width() - out.height()); | 1064 target_area - out.width() - out.height()); |
1065 EXPECT_TRUE(bounds.Contains(out)); | 1065 EXPECT_TRUE(bounds.Contains(out)); |
1066 } | 1066 } |
1067 | 1067 |
1068 TEST(PictureLayerTilingTest, EmptyStartingRect) { | 1068 TEST(PictureLayerTilingTest, EmptyStartingRect) { |
1069 // If a layer has a non-invertible transform, then the starting rect | 1069 // If a layer has a non-invertible transform, then the starting rect |
1070 // for the layer would be empty. | 1070 // for the layer would be empty. |
1071 gfx::Rect in(40, 40, 0, 0); | 1071 gfx::Rect in(40, 40, 0, 0); |
1072 gfx::Rect bounds(0, 0, 10, 10); | 1072 gfx::Rect bounds(0, 0, 10, 10); |
1073 int64 target_area = 400 * 400; | 1073 int64 target_area = 400 * 400; |
1074 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1074 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1075 in, target_area, bounds, NULL); | 1075 in, target_area, bounds, nullptr); |
1076 EXPECT_TRUE(out.IsEmpty()); | 1076 EXPECT_TRUE(out.IsEmpty()); |
1077 } | 1077 } |
1078 | 1078 |
1079 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { | 1079 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { |
1080 FakePictureLayerTilingClient client; | 1080 FakePictureLayerTilingClient client; |
1081 scoped_ptr<TestablePictureLayerTiling> tiling; | 1081 scoped_ptr<TestablePictureLayerTiling> tiling; |
1082 | 1082 |
1083 gfx::Rect viewport(50, 50, 100, 100); | 1083 gfx::Rect viewport(50, 50, 100, 100); |
1084 gfx::Size layer_bounds(800, 800); | 1084 gfx::Size layer_bounds(800, 800); |
1085 | 1085 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); | 1200 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); |
1201 tiling->ComputeTilePriorityRects( | 1201 tiling->ComputeTilePriorityRects( |
1202 ACTIVE_TREE, moved_viewport, 1.0f, 2.0, Occlusion()); | 1202 ACTIVE_TREE, moved_viewport, 1.0f, 2.0, Occlusion()); |
1203 tiling->UpdateAllTilePrioritiesForTesting(); | 1203 tiling->UpdateAllTilePrioritiesForTesting(); |
1204 | 1204 |
1205 gfx::Rect soon_rect = moved_viewport; | 1205 gfx::Rect soon_rect = moved_viewport; |
1206 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 1206 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
1207 | 1207 |
1208 // There are 3 bins in TilePriority. | 1208 // There are 3 bins in TilePriority. |
1209 bool have_tiles[3] = {}; | 1209 bool have_tiles[3] = {}; |
1210 Tile* last_tile = NULL; | 1210 Tile* last_tile = nullptr; |
1211 int eventually_bin_order_correct_count = 0; | 1211 int eventually_bin_order_correct_count = 0; |
1212 int eventually_bin_order_incorrect_count = 0; | 1212 int eventually_bin_order_incorrect_count = 0; |
1213 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); it; | 1213 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); it; |
1214 ++it) { | 1214 ++it) { |
1215 if (!last_tile) | 1215 if (!last_tile) |
1216 last_tile = *it; | 1216 last_tile = *it; |
1217 | 1217 |
1218 Tile* new_tile = *it; | 1218 Tile* new_tile = *it; |
1219 | 1219 |
1220 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); | 1220 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); |
(...skipping 22 matching lines...) Expand all Loading... |
1243 EXPECT_GT(eventually_bin_order_correct_count, | 1243 EXPECT_GT(eventually_bin_order_correct_count, |
1244 eventually_bin_order_incorrect_count); | 1244 eventually_bin_order_incorrect_count); |
1245 | 1245 |
1246 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | 1246 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
1247 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | 1247 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
1248 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | 1248 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
1249 } | 1249 } |
1250 | 1250 |
1251 static void TileExists(bool exists, Tile* tile, | 1251 static void TileExists(bool exists, Tile* tile, |
1252 const gfx::Rect& geometry_rect) { | 1252 const gfx::Rect& geometry_rect) { |
1253 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 1253 EXPECT_EQ(exists, tile != nullptr) << geometry_rect.ToString(); |
1254 } | 1254 } |
1255 | 1255 |
1256 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorStaticViewport) { | 1256 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorStaticViewport) { |
1257 FakeOutputSurfaceClient output_surface_client; | 1257 FakeOutputSurfaceClient output_surface_client; |
1258 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); | 1258 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); |
1259 CHECK(output_surface->BindToClient(&output_surface_client)); | 1259 CHECK(output_surface->BindToClient(&output_surface_client)); |
1260 TestSharedBitmapManager shared_bitmap_manager; | 1260 TestSharedBitmapManager shared_bitmap_manager; |
1261 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( | 1261 scoped_ptr<ResourceProvider> resource_provider = |
1262 output_surface.get(), &shared_bitmap_manager, NULL, 0, false, 1, false); | 1262 ResourceProvider::Create(output_surface.get(), |
| 1263 &shared_bitmap_manager, |
| 1264 nullptr, |
| 1265 0, |
| 1266 false, |
| 1267 1, |
| 1268 false); |
1263 | 1269 |
1264 FakePictureLayerTilingClient client(resource_provider.get()); | 1270 FakePictureLayerTilingClient client(resource_provider.get()); |
1265 scoped_ptr<TestablePictureLayerTiling> tiling; | 1271 scoped_ptr<TestablePictureLayerTiling> tiling; |
1266 | 1272 |
1267 gfx::Rect viewport(50, 50, 100, 100); | 1273 gfx::Rect viewport(50, 50, 100, 100); |
1268 gfx::Size layer_bounds(2000, 2000); | 1274 gfx::Size layer_bounds(2000, 2000); |
1269 | 1275 |
1270 client.SetTileSize(gfx::Size(30, 30)); | 1276 client.SetTileSize(gfx::Size(30, 30)); |
1271 client.set_tree(ACTIVE_TREE); | 1277 client.set_tree(ACTIVE_TREE); |
1272 | 1278 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 Occlusion()); | 1414 Occlusion()); |
1409 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1415 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1410 } | 1416 } |
1411 | 1417 |
1412 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 1418 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
1413 bool intersect_exists, | 1419 bool intersect_exists, |
1414 Tile* tile, | 1420 Tile* tile, |
1415 const gfx::Rect& geometry_rect) { | 1421 const gfx::Rect& geometry_rect) { |
1416 bool intersects = rect.Intersects(geometry_rect); | 1422 bool intersects = rect.Intersects(geometry_rect); |
1417 bool expected_exists = intersect_exists ? intersects : !intersects; | 1423 bool expected_exists = intersect_exists ? intersects : !intersects; |
1418 EXPECT_EQ(expected_exists, tile != NULL) | 1424 EXPECT_EQ(expected_exists, tile != nullptr) |
1419 << "Rects intersecting " << rect.ToString() << " should exist. " | 1425 << "Rects intersecting " << rect.ToString() << " should exist. " |
1420 << "Current tile rect is " << geometry_rect.ToString(); | 1426 << "Current tile rect is " << geometry_rect.ToString(); |
1421 } | 1427 } |
1422 | 1428 |
1423 TEST_F(PictureLayerTilingIteratorTest, | 1429 TEST_F(PictureLayerTilingIteratorTest, |
1424 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 1430 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
1425 gfx::Size layer_bounds(10000, 10000); | 1431 gfx::Size layer_bounds(10000, 10000); |
1426 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1432 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
1427 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1433 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
1428 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1434 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2086 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; | 2092 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; |
2087 recycle_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 2093 recycle_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
2088 gfx::Size(10000, 10000), | 2094 gfx::Size(10000, 10000), |
2089 &recycle_client); | 2095 &recycle_client); |
2090 | 2096 |
2091 // Create all tiles on the second tiling. All tiles should be shared. | 2097 // Create all tiles on the second tiling. All tiles should be shared. |
2092 recycle_tiling->ComputeTilePriorityRects( | 2098 recycle_tiling->ComputeTilePriorityRects( |
2093 PENDING_TREE, gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, Occlusion()); | 2099 PENDING_TREE, gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, Occlusion()); |
2094 | 2100 |
2095 // Set the second tiling as recycled. | 2101 // Set the second tiling as recycled. |
2096 active_client.set_twin_tiling(NULL); | 2102 active_client.set_twin_tiling(nullptr); |
2097 active_client.set_recycled_twin_tiling(recycle_tiling.get()); | 2103 active_client.set_recycled_twin_tiling(recycle_tiling.get()); |
2098 recycle_client.set_twin_tiling(NULL); | 2104 recycle_client.set_twin_tiling(nullptr); |
2099 | 2105 |
2100 // Verify that tiles exist and are shared. | 2106 // Verify that tiles exist and are shared. |
2101 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | 2107 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
2102 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); | 2108 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); |
2103 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); | 2109 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
2104 | 2110 |
2105 // Move the viewport far away from the (0, 0) tile. | 2111 // Move the viewport far away from the (0, 0) tile. |
2106 active_tiling->ComputeTilePriorityRects( | 2112 active_tiling->ComputeTilePriorityRects( |
2107 ACTIVE_TREE, gfx::Rect(9000, 9000, 100, 100), 1.0f, 2.0, Occlusion()); | 2113 ACTIVE_TREE, gfx::Rect(9000, 9000, 100, 100), 1.0f, 2.0, Occlusion()); |
2108 // Ensure the tile was deleted on both tilings. | 2114 // Ensure the tile was deleted on both tilings. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; | 2146 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; |
2141 recycle_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 2147 recycle_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
2142 gfx::Size(100, 100), | 2148 gfx::Size(100, 100), |
2143 &recycle_client); | 2149 &recycle_client); |
2144 | 2150 |
2145 // Create all tiles on the recycle tiling. All tiles should be shared. | 2151 // Create all tiles on the recycle tiling. All tiles should be shared. |
2146 recycle_tiling->ComputeTilePriorityRects( | 2152 recycle_tiling->ComputeTilePriorityRects( |
2147 PENDING_TREE, gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, Occlusion()); | 2153 PENDING_TREE, gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, Occlusion()); |
2148 | 2154 |
2149 // Set the second tiling as recycled. | 2155 // Set the second tiling as recycled. |
2150 active_client.set_twin_tiling(NULL); | 2156 active_client.set_twin_tiling(nullptr); |
2151 active_client.set_recycled_twin_tiling(recycle_tiling.get()); | 2157 active_client.set_recycled_twin_tiling(recycle_tiling.get()); |
2152 recycle_client.set_twin_tiling(NULL); | 2158 recycle_client.set_twin_tiling(nullptr); |
2153 | 2159 |
2154 // Verify that tiles exist and are shared. | 2160 // Verify that tiles exist and are shared. |
2155 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | 2161 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
2156 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); | 2162 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); |
2157 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); | 2163 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
2158 | 2164 |
2159 // Reset the active tiling. The recycle tiles should be released too. | 2165 // Reset the active tiling. The recycle tiles should be released too. |
2160 active_tiling->Reset(); | 2166 active_tiling->Reset(); |
2161 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | 2167 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
2162 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | 2168 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
2163 } | 2169 } |
2164 | 2170 |
2165 } // namespace | 2171 } // namespace |
2166 } // namespace cc | 2172 } // namespace cc |
OLD | NEW |