OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/gpu/gpu_memory_allocation.h" | 5 #include "content/common/gpu/gpu_memory_allocation.h" |
6 #include "content/common/gpu/gpu_memory_manager.h" | 6 #include "content/common/gpu/gpu_memory_manager.h" |
7 #include "content/common/gpu/gpu_memory_manager_client.h" | 7 #include "content/common/gpu/gpu_memory_manager_client.h" |
8 #include "content/common/gpu/gpu_memory_tracking.h" | 8 #include "content/common/gpu/gpu_memory_tracking.h" |
9 #include "ui/gfx/size_conversions.h" | 9 #include "ui/gfx/size_conversions.h" |
10 | 10 |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 stub1.BytesWhenNotVisible()); | 776 stub1.BytesWhenNotVisible()); |
777 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 777 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), |
778 stub2.BytesWhenNotVisible()); | 778 stub2.BytesWhenNotVisible()); |
779 } | 779 } |
780 | 780 |
781 // Test GpuMemoryManager's background MRU behavior | 781 // Test GpuMemoryManager's background MRU behavior |
782 TEST_F(GpuMemoryManagerTest, TestBackgroundMru) { | 782 TEST_F(GpuMemoryManagerTest, TestBackgroundMru) { |
783 memmgr_.TestingSetAvailableGpuMemory(64); | 783 memmgr_.TestingSetAvailableGpuMemory(64); |
784 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); | 784 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
785 | 785 |
| 786 uint64 bytes_when_not_visible_expected = |
| 787 memmgr_.GetCurrentNonvisibleAvailableGpuMemory(); |
| 788 #if defined (OS_ANDROID) |
| 789 bytes_when_not_visible_expected = 0; |
| 790 #endif |
| 791 |
786 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 792 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
787 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); | 793 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); |
788 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); | 794 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); |
789 | 795 |
790 // When all are visible, they should all be allowed to have memory | 796 // When all are visible, they should all be allowed to have memory |
791 // should they become nonvisible. | 797 // should they become nonvisible. |
792 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); | 798 stub1.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); |
793 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); | 799 stub2.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); |
794 stub3.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); | 800 stub3.SetManagedMemoryStats(GpuManagedMemoryStats(7, 24, 7, false)); |
795 Manage(); | 801 Manage(); |
796 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, | 802 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
797 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); | 803 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
798 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 804 EXPECT_EQ(stub1.BytesWhenNotVisible(), |
799 stub1.BytesWhenNotVisible()); | 805 bytes_when_not_visible_expected); |
800 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 806 EXPECT_EQ(stub2.BytesWhenNotVisible(), |
801 stub2.BytesWhenNotVisible()); | 807 bytes_when_not_visible_expected); |
802 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 808 EXPECT_EQ(stub3.BytesWhenNotVisible(), |
803 stub3.BytesWhenNotVisible()); | 809 bytes_when_not_visible_expected); |
804 | |
805 | 810 |
806 // Background stubs 1 and 2, and they should fit | 811 // Background stubs 1 and 2, and they should fit |
807 stub2.SetVisible(false); | 812 stub2.SetVisible(false); |
808 stub1.SetVisible(false); | 813 stub1.SetVisible(false); |
809 Manage(); | 814 Manage(); |
810 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, | 815 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
811 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); | 816 bytes_when_not_visible_expected); |
812 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 817 EXPECT_EQ(stub1.BytesWhenNotVisible(), |
813 stub1.BytesWhenNotVisible()); | 818 bytes_when_not_visible_expected); |
814 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 819 EXPECT_EQ(stub2.BytesWhenNotVisible(), |
815 stub2.BytesWhenNotVisible()); | 820 bytes_when_not_visible_expected); |
816 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 821 EXPECT_EQ(stub3.BytesWhenNotVisible(), |
817 stub3.BytesWhenNotVisible()); | 822 bytes_when_not_visible_expected); |
818 | 823 |
819 // Now background stub 3, and it should cause stub 2 to be | 824 // Now background stub 3, and it should cause stub 2 to be |
820 // evicted because it was set non-visible first | 825 // evicted because it was set non-visible first |
821 stub3.SetVisible(false); | 826 stub3.SetVisible(false); |
822 Manage(); | 827 Manage(); |
823 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, | 828 EXPECT_EQ(memmgr_.bytes_nonvisible_available_gpu_memory_, |
824 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); | 829 memmgr_.GetCurrentNonvisibleAvailableGpuMemory()); |
825 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 830 EXPECT_EQ(stub1.BytesWhenNotVisible(), |
826 stub1.BytesWhenNotVisible()); | 831 bytes_when_not_visible_expected); |
827 EXPECT_EQ(0ul, | 832 EXPECT_EQ(stub2.BytesWhenNotVisible(), |
828 stub2.BytesWhenNotVisible()); | 833 0ul); |
829 EXPECT_EQ(memmgr_.GetCurrentNonvisibleAvailableGpuMemory(), | 834 EXPECT_EQ(stub3.BytesWhenNotVisible(), |
830 stub3.BytesWhenNotVisible()); | 835 bytes_when_not_visible_expected); |
831 } | 836 } |
832 | 837 |
833 // Test GpuMemoryManager's tracking of unmanaged (e.g, WebGL) memory. | 838 // Test GpuMemoryManager's tracking of unmanaged (e.g, WebGL) memory. |
834 TEST_F(GpuMemoryManagerTest, TestUnmanagedTracking) { | 839 TEST_F(GpuMemoryManagerTest, TestUnmanagedTracking) { |
835 memmgr_.TestingSetAvailableGpuMemory(64); | 840 memmgr_.TestingSetAvailableGpuMemory(64); |
836 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); | 841 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
837 memmgr_.TestingSetUnmanagedLimitStep(16); | 842 memmgr_.TestingSetUnmanagedLimitStep(16); |
838 memmgr_.TestingSetMinimumClientAllocation(8); | 843 memmgr_.TestingSetMinimumClientAllocation(8); |
839 | 844 |
840 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 845 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 | 892 |
888 // Test nonvisible MRU behavior (the most recently used nonvisible clients | 893 // Test nonvisible MRU behavior (the most recently used nonvisible clients |
889 // keep their contents). | 894 // keep their contents). |
890 TEST_F(GpuMemoryManagerTestNonuniform, BackgroundMru) { | 895 TEST_F(GpuMemoryManagerTestNonuniform, BackgroundMru) { |
891 // Set memory manager constants for this test | 896 // Set memory manager constants for this test |
892 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); | 897 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); |
893 memmgr_.TestingSetAvailableGpuMemory(64); | 898 memmgr_.TestingSetAvailableGpuMemory(64); |
894 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); | 899 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
895 memmgr_.TestingSetMinimumClientAllocation(8); | 900 memmgr_.TestingSetMinimumClientAllocation(8); |
896 | 901 |
| 902 uint64 bytes_when_not_visible_expected = 6u; |
| 903 #if defined (OS_ANDROID) |
| 904 bytes_when_not_visible_expected = 0; |
| 905 #endif |
| 906 |
897 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 907 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
898 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); | 908 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); |
899 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); | 909 FakeClient stub3(&memmgr_, GenerateUniqueSurfaceId(), true); |
900 | 910 |
901 // When all are visible, they should all be allowed to have memory | 911 // When all are visible, they should all be allowed to have memory |
902 // should they become nonvisible. | 912 // should they become nonvisible. |
903 SetClientStats(&stub1, 6, 23); | 913 SetClientStats(&stub1, 6, 23); |
904 SetClientStats(&stub2, 6, 23); | 914 SetClientStats(&stub2, 6, 23); |
905 SetClientStats(&stub3, 6, 23); | 915 SetClientStats(&stub3, 6, 23); |
906 Manage(); | 916 Manage(); |
907 EXPECT_GE(stub1.BytesWhenVisible(), 20u); | 917 EXPECT_GE(stub1.BytesWhenVisible(), 20u); |
908 EXPECT_GE(stub2.BytesWhenVisible(), 20u); | 918 EXPECT_GE(stub2.BytesWhenVisible(), 20u); |
909 EXPECT_GE(stub3.BytesWhenVisible(), 20u); | 919 EXPECT_GE(stub3.BytesWhenVisible(), 20u); |
910 EXPECT_LT(stub1.BytesWhenVisible(), 22u); | 920 EXPECT_LT(stub1.BytesWhenVisible(), 22u); |
911 EXPECT_LT(stub2.BytesWhenVisible(), 22u); | 921 EXPECT_LT(stub2.BytesWhenVisible(), 22u); |
912 EXPECT_LT(stub3.BytesWhenVisible(), 22u); | 922 EXPECT_LT(stub3.BytesWhenVisible(), 22u); |
913 EXPECT_GE(stub1.BytesWhenNotVisible(), 6u); | 923 EXPECT_GE(stub1.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
914 EXPECT_GE(stub2.BytesWhenNotVisible(), 6u); | 924 EXPECT_GE(stub2.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
915 EXPECT_GE(stub3.BytesWhenNotVisible(), 6u); | 925 EXPECT_GE(stub3.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
916 | 926 |
917 // Background stubs 1 and 2, and they should fit. All stubs should | 927 // Background stubs 1 and 2, and they should fit. All stubs should |
918 // have their full nicetohave budget should they become visible. | 928 // have their full nicetohave budget should they become visible. |
919 stub2.SetVisible(false); | 929 stub2.SetVisible(false); |
920 stub1.SetVisible(false); | 930 stub1.SetVisible(false); |
921 Manage(); | 931 Manage(); |
922 EXPECT_GE(stub1.BytesWhenVisible(), 23u); | 932 EXPECT_GE(stub1.BytesWhenVisible(), 23u); |
923 EXPECT_GE(stub2.BytesWhenVisible(), 23u); | 933 EXPECT_GE(stub2.BytesWhenVisible(), 23u); |
924 EXPECT_GE(stub3.BytesWhenVisible(), 23u); | 934 EXPECT_GE(stub3.BytesWhenVisible(), 23u); |
925 EXPECT_LT(stub1.BytesWhenVisible(), 32u); | 935 EXPECT_LT(stub1.BytesWhenVisible(), 32u); |
926 EXPECT_LT(stub2.BytesWhenVisible(), 32u); | 936 EXPECT_LT(stub2.BytesWhenVisible(), 32u); |
927 EXPECT_LT(stub3.BytesWhenVisible(), 32u); | 937 EXPECT_GE(stub1.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
928 EXPECT_GE(stub1.BytesWhenNotVisible(), 6u); | 938 EXPECT_GE(stub2.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
929 EXPECT_GE(stub2.BytesWhenNotVisible(), 6u); | 939 EXPECT_GE(stub3.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
930 EXPECT_GE(stub3.BytesWhenNotVisible(), 6u); | |
931 | 940 |
932 // Now background stub 3, and it should cause stub 2 to be | 941 // Now background stub 3, and it should cause stub 2 to be |
933 // evicted because it was set non-visible first | 942 // evicted because it was set non-visible first |
934 stub3.SetVisible(false); | 943 stub3.SetVisible(false); |
935 Manage(); | 944 Manage(); |
936 EXPECT_GE(stub1.BytesWhenNotVisible(), 6u); | 945 EXPECT_GE(stub1.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
937 EXPECT_EQ(stub2.BytesWhenNotVisible(), 0u); | 946 EXPECT_EQ(stub2.BytesWhenNotVisible(), 0u); |
938 EXPECT_GE(stub3.BytesWhenNotVisible(), 6u); | 947 EXPECT_GE(stub3.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
939 } | 948 } |
940 | 949 |
941 // Test that once a backgrounded client has dropped its resources, it | 950 // Test that once a backgrounded client has dropped its resources, it |
942 // doesn't get them back until it becomes visible again. | 951 // doesn't get them back until it becomes visible again. |
943 TEST_F(GpuMemoryManagerTestNonuniform, BackgroundDiscardPersistent) { | 952 TEST_F(GpuMemoryManagerTestNonuniform, BackgroundDiscardPersistent) { |
944 // Set memory manager constants for this test | 953 // Set memory manager constants for this test |
945 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); | 954 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); |
946 memmgr_.TestingSetAvailableGpuMemory(64); | 955 memmgr_.TestingSetAvailableGpuMemory(64); |
947 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); | 956 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
948 memmgr_.TestingSetMinimumClientAllocation(8); | 957 memmgr_.TestingSetMinimumClientAllocation(8); |
949 | 958 |
| 959 uint64 bytes_when_not_visible_expected = 10ul; |
| 960 #if defined (OS_ANDROID) |
| 961 bytes_when_not_visible_expected = 0; |
| 962 #endif |
| 963 |
950 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 964 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
951 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); | 965 FakeClient stub2(&memmgr_, GenerateUniqueSurfaceId(), true); |
952 | 966 |
953 // Both clients should be able to keep their contents should one of | 967 // Both clients should be able to keep their contents should one of |
954 // them become nonvisible. | 968 // them become nonvisible. |
955 SetClientStats(&stub1, 10, 20); | 969 SetClientStats(&stub1, 10, 20); |
956 SetClientStats(&stub2, 10, 20); | 970 SetClientStats(&stub2, 10, 20); |
957 Manage(); | 971 Manage(); |
958 EXPECT_GE(stub1.BytesWhenNotVisible(), 10u); | 972 EXPECT_GE(stub1.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
959 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u); | 973 EXPECT_GE(stub2.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
960 | 974 |
961 // If they both go nonvisible, then only the most recently used client | 975 // If they both go nonvisible, then only the most recently used client |
962 // should keep its contents. | 976 // should keep its contents. |
963 stub1.SetVisible(false); | 977 stub1.SetVisible(false); |
964 stub2.SetVisible(false); | 978 stub2.SetVisible(false); |
965 Manage(); | 979 Manage(); |
966 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); | 980 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); |
967 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u); | 981 EXPECT_GE(stub2.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
968 | 982 |
969 // When becoming visible, stub 2 should get its contents back, and | 983 // When becoming visible, stub 2 should get its contents back, and |
970 // retain them next time it is made nonvisible. | 984 // retain them next time it is made nonvisible. |
971 stub2.SetVisible(true); | 985 stub2.SetVisible(true); |
972 Manage(); | 986 Manage(); |
973 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u); | 987 EXPECT_GE(stub2.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
974 stub2.SetVisible(false); | 988 stub2.SetVisible(false); |
975 Manage(); | 989 Manage(); |
976 EXPECT_GE(stub2.BytesWhenNotVisible(), 10u); | 990 EXPECT_GE(stub2.BytesWhenNotVisible(), bytes_when_not_visible_expected); |
977 } | 991 } |
978 | 992 |
979 // Test tracking of unmanaged (e.g, WebGL) memory. | 993 // Test tracking of unmanaged (e.g, WebGL) memory. |
980 TEST_F(GpuMemoryManagerTestNonuniform, UnmanagedTracking) { | 994 TEST_F(GpuMemoryManagerTestNonuniform, UnmanagedTracking) { |
981 // Set memory manager constants for this test | 995 // Set memory manager constants for this test |
982 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); | 996 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); |
983 memmgr_.TestingSetAvailableGpuMemory(64); | 997 memmgr_.TestingSetAvailableGpuMemory(64); |
984 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); | 998 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
985 memmgr_.TestingSetMinimumClientAllocation(8); | 999 memmgr_.TestingSetMinimumClientAllocation(8); |
986 memmgr_.TestingSetUnmanagedLimitStep(16); | 1000 memmgr_.TestingSetUnmanagedLimitStep(16); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 TEST_F(GpuMemoryManagerTestNonuniform, DefaultAllocation) { | 1048 TEST_F(GpuMemoryManagerTestNonuniform, DefaultAllocation) { |
1035 // Set memory manager constants for this test | 1049 // Set memory manager constants for this test |
1036 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); | 1050 memmgr_.TestingSetUseNonuniformMemoryPolicy(true); |
1037 memmgr_.TestingSetAvailableGpuMemory(64); | 1051 memmgr_.TestingSetAvailableGpuMemory(64); |
1038 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); | 1052 memmgr_.TestingSetNonvisibleAvailableGpuMemory(16); |
1039 memmgr_.TestingSetMinimumClientAllocation(8); | 1053 memmgr_.TestingSetMinimumClientAllocation(8); |
1040 memmgr_.TestingSetDefaultClientAllocation(16); | 1054 memmgr_.TestingSetDefaultClientAllocation(16); |
1041 | 1055 |
1042 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); | 1056 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true); |
1043 | 1057 |
1044 // Expect that a client which has not sent stats receive the | 1058 // Expect that a client which has not sent stats receive at |
1045 // default allocation. | 1059 // least the default allocation. |
1046 Manage(); | 1060 Manage(); |
1047 EXPECT_EQ(stub1.BytesWhenVisible(), | 1061 EXPECT_GE(stub1.BytesWhenVisible(), |
1048 memmgr_.GetDefaultClientAllocation()); | 1062 memmgr_.GetDefaultClientAllocation()); |
1049 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); | 1063 EXPECT_EQ(stub1.BytesWhenNotVisible(), 0u); |
1050 } | 1064 } |
1051 | 1065 |
1052 } // namespace content | 1066 } // namespace content |
OLD | NEW |