OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" |
10 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "cc/layers/delegated_renderer_layer.h" | 14 #include "cc/layers/delegated_renderer_layer.h" |
14 #include "cc/layers/delegated_renderer_layer_client.h" | 15 #include "cc/layers/delegated_renderer_layer_client.h" |
15 #include "cc/layers/delegated_renderer_layer_impl.h" | 16 #include "cc/layers/delegated_renderer_layer_impl.h" |
16 #include "cc/output/compositor_frame.h" | 17 #include "cc/output/compositor_frame.h" |
17 #include "cc/output/compositor_frame_ack.h" | 18 #include "cc/output/compositor_frame_ack.h" |
18 #include "cc/output/delegated_frame_data.h" | 19 #include "cc/output/delegated_frame_data.h" |
19 #include "cc/quads/render_pass_draw_quad.h" | 20 #include "cc/quads/render_pass_draw_quad.h" |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 const ResourceProvider::ResourceIdMap& map = | 759 const ResourceProvider::ResourceIdMap& map = |
759 host_impl->resource_provider()->GetChildToParentMap( | 760 host_impl->resource_provider()->GetChildToParentMap( |
760 delegated_impl->ChildId()); | 761 delegated_impl->ChildId()); |
761 | 762 |
762 // Both frames' resources should be in the parent's resource provider. | 763 // Both frames' resources should be in the parent's resource provider. |
763 EXPECT_EQ(2u, map.size()); | 764 EXPECT_EQ(2u, map.size()); |
764 EXPECT_EQ(1u, map.count(999)); | 765 EXPECT_EQ(1u, map.count(999)); |
765 EXPECT_EQ(1u, map.count(555)); | 766 EXPECT_EQ(1u, map.count(555)); |
766 | 767 |
767 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 768 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
768 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 769 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
769 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 770 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
770 | 771 |
771 EndTest(); | 772 EndTest(); |
772 } | 773 } |
773 | 774 |
774 virtual void AfterTest() OVERRIDE {} | 775 virtual void AfterTest() OVERRIDE {} |
775 }; | 776 }; |
776 | 777 |
777 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources); | 778 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources); |
778 | 779 |
779 class LayerTreeHostDelegatedTestRemapResourcesInQuads | 780 class LayerTreeHostDelegatedTestRemapResourcesInQuads |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 case 1: | 844 case 1: |
844 // Generate a frame with two resources in it. | 845 // Generate a frame with two resources in it. |
845 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 846 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
846 AddTextureQuad(frame.get(), 999); | 847 AddTextureQuad(frame.get(), 999); |
847 AddTransferableResource(frame.get(), 999); | 848 AddTransferableResource(frame.get(), 999); |
848 AddTextureQuad(frame.get(), 555); | 849 AddTextureQuad(frame.get(), 555); |
849 AddTransferableResource(frame.get(), 555); | 850 AddTransferableResource(frame.get(), 555); |
850 delegated_->SetFrameData(frame.Pass()); | 851 delegated_->SetFrameData(frame.Pass()); |
851 break; | 852 break; |
852 case 2: | 853 case 2: |
853 // Retrieve unused resources to the main thread. | |
854 // TODO(danakj): Shouldn't need to commit to get resources. | |
855 layer_tree_host()->SetNeedsCommit(); | |
856 return; | |
857 case 3: | |
858 // All of the resources are in use. | 854 // All of the resources are in use. |
859 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 855 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
860 EXPECT_EQ(0u, resources.size()); | 856 EXPECT_EQ(0u, resources.size()); |
861 | 857 |
862 // Keep using 999 but stop using 555. | 858 // Keep using 999 but stop using 555. |
863 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 859 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
864 AddTextureQuad(frame.get(), 999); | 860 AddTextureQuad(frame.get(), 999); |
| 861 AddTransferableResource(frame.get(), 999); |
865 AddTextureQuad(frame.get(), 444); | 862 AddTextureQuad(frame.get(), 444); |
866 AddTransferableResource(frame.get(), 444); | 863 AddTransferableResource(frame.get(), 444); |
867 delegated_->SetFrameData(frame.Pass()); | 864 delegated_->SetFrameData(frame.Pass()); |
868 break; | 865 break; |
869 case 4: | 866 case 3: |
870 // Retrieve unused resources to the main thread. | |
871 // TODO(danakj): Shouldn't need to commit to get resources. | |
872 layer_tree_host()->SetNeedsCommit(); | |
873 return; | |
874 case 5: | |
875 // 555 is no longer in use. | 867 // 555 is no longer in use. |
876 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 868 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
877 { | 869 { |
878 unsigned expected[] = {555}; | 870 unsigned expected[] = {555}; |
879 EXPECT_RESOURCES(expected, resources); | 871 EXPECT_RESOURCES(expected, resources); |
880 } | 872 } |
881 | 873 |
882 // Stop using any resources. | 874 // Stop using any resources. |
883 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 875 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
884 delegated_->SetFrameData(frame.Pass()); | 876 delegated_->SetFrameData(frame.Pass()); |
885 break; | 877 break; |
886 case 6: | 878 case 4: |
887 // Postpone collecting resources for a frame. They should still be there | 879 // Postpone collecting resources for a frame. They should still be there |
888 // the next frame. | 880 // the next frame. |
889 layer_tree_host()->SetNeedsCommit(); | 881 layer_tree_host()->SetNeedsCommit(); |
890 return; | 882 return; |
891 case 7: | 883 case 5: |
892 // 444 and 999 are no longer in use. | 884 // 444 and 999 are no longer in use. We sent two refs to 999, so we |
| 885 // should get two back. |
893 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 886 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
894 { | 887 { |
895 unsigned expected[] = {444, 999}; | 888 unsigned expected[] = {444, 999, 999}; |
896 EXPECT_RESOURCES(expected, resources); | 889 EXPECT_RESOURCES(expected, resources); |
897 } | 890 } |
898 EndTest(); | 891 EndTest(); |
899 break; | 892 break; |
900 } | 893 } |
901 | 894 |
902 // Resource are never immediately released. | 895 // Resource are never immediately released. |
903 ReturnedResourceArray empty_resources; | 896 ReturnedResourceArray empty_resources; |
904 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources); | 897 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources); |
905 EXPECT_TRUE(empty_resources.empty()); | 898 EXPECT_TRUE(empty_resources.empty()); |
(...skipping 28 matching lines...) Expand all Loading... |
934 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 927 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
935 AddTextureQuad(frame.get(), 999); | 928 AddTextureQuad(frame.get(), 999); |
936 AddTransferableResource(frame.get(), 999); | 929 AddTransferableResource(frame.get(), 999); |
937 AddTextureQuad(frame.get(), 555); | 930 AddTextureQuad(frame.get(), 555); |
938 AddTransferableResource(frame.get(), 555); | 931 AddTransferableResource(frame.get(), 555); |
939 AddTextureQuad(frame.get(), 444); | 932 AddTextureQuad(frame.get(), 444); |
940 AddTransferableResource(frame.get(), 444); | 933 AddTransferableResource(frame.get(), 444); |
941 delegated_->SetFrameData(frame.Pass()); | 934 delegated_->SetFrameData(frame.Pass()); |
942 break; | 935 break; |
943 case 2: | 936 case 2: |
944 // Retrieve unused resources to the main thread. | |
945 // TODO(danakj): Shouldn't need to commit to get resources. | |
946 layer_tree_host()->SetNeedsCommit(); | |
947 return; | |
948 case 3: | |
949 // All of the resources are in use. | 937 // All of the resources are in use. |
950 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 938 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
951 EXPECT_EQ(0u, resources.size()); | 939 EXPECT_EQ(0u, resources.size()); |
952 | 940 |
953 // Keep using 999 but stop using 555 and 444. | 941 // Keep using 999 but stop using 555 and 444. |
954 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 942 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
955 AddTextureQuad(frame.get(), 999); | 943 AddTextureQuad(frame.get(), 999); |
| 944 AddTransferableResource(frame.get(), 999); |
956 delegated_->SetFrameData(frame.Pass()); | 945 delegated_->SetFrameData(frame.Pass()); |
957 | 946 |
958 // Resource are not immediately released. | 947 // Resource are not immediately released. |
959 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 948 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
960 EXPECT_EQ(0u, resources.size()); | 949 EXPECT_EQ(0u, resources.size()); |
961 | 950 |
962 // Now using 555 and 444 again, but not 999. | 951 // Now using 555 and 444 again, but not 999. |
963 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 952 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
964 AddTextureQuad(frame.get(), 555); | 953 AddTextureQuad(frame.get(), 555); |
| 954 AddTransferableResource(frame.get(), 555); |
965 AddTextureQuad(frame.get(), 444); | 955 AddTextureQuad(frame.get(), 444); |
| 956 AddTransferableResource(frame.get(), 444); |
966 delegated_->SetFrameData(frame.Pass()); | 957 delegated_->SetFrameData(frame.Pass()); |
967 break; | 958 break; |
968 case 4: | 959 case 3: |
969 // Retrieve unused resources to the main thread. | 960 // The 999 resource is the only unused one. Two references were sent, so |
970 // TODO(danakj): Shouldn't need to commit to get resources. | 961 // two should be returned. |
971 layer_tree_host()->SetNeedsCommit(); | |
972 return; | |
973 case 5: | |
974 // The 999 resource is the only unused one. | |
975 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 962 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
976 { | 963 { |
977 unsigned expected[] = {999}; | 964 unsigned expected[] = {999, 999}; |
978 EXPECT_RESOURCES(expected, resources); | 965 EXPECT_RESOURCES(expected, resources); |
979 } | 966 } |
980 EndTest(); | 967 EndTest(); |
981 break; | 968 break; |
982 } | 969 } |
983 } | 970 } |
984 | 971 |
985 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 972 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
986 bool result) OVERRIDE { | 973 bool result) OVERRIDE { |
987 ReturnUnusedResourcesFromParent(host_impl); | 974 ReturnUnusedResourcesFromParent(host_impl); |
(...skipping 22 matching lines...) Expand all Loading... |
1010 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 997 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1011 AddTextureQuad(frame.get(), 999); | 998 AddTextureQuad(frame.get(), 999); |
1012 AddTransferableResource(frame.get(), 999); | 999 AddTransferableResource(frame.get(), 999); |
1013 AddTextureQuad(frame.get(), 555); | 1000 AddTextureQuad(frame.get(), 555); |
1014 AddTransferableResource(frame.get(), 555); | 1001 AddTransferableResource(frame.get(), 555); |
1015 AddTextureQuad(frame.get(), 444); | 1002 AddTextureQuad(frame.get(), 444); |
1016 AddTransferableResource(frame.get(), 444); | 1003 AddTransferableResource(frame.get(), 444); |
1017 delegated_->SetFrameData(frame.Pass()); | 1004 delegated_->SetFrameData(frame.Pass()); |
1018 break; | 1005 break; |
1019 case 2: | 1006 case 2: |
1020 // Retrieve unused resources to the main thread. | |
1021 // TODO(danakj): Shouldn't need to commit to get resources. | |
1022 layer_tree_host()->SetNeedsCommit(); | |
1023 return; | |
1024 case 3: | |
1025 // All of the resources are in use. | 1007 // All of the resources are in use. |
1026 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1008 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1027 EXPECT_EQ(0u, resources.size()); | 1009 EXPECT_EQ(0u, resources.size()); |
1028 | 1010 |
1029 // Keep using 999 but stop using 555 and 444. | 1011 // Keep using 999 but stop using 555 and 444. |
1030 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1012 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1031 AddTextureQuad(frame.get(), 999); | 1013 AddTextureQuad(frame.get(), 999); |
| 1014 AddTransferableResource(frame.get(), 999); |
1032 delegated_->SetFrameData(frame.Pass()); | 1015 delegated_->SetFrameData(frame.Pass()); |
1033 | 1016 |
1034 // Resource are not immediately released. | 1017 // Resource are not immediately released. |
1035 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1018 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1036 EXPECT_EQ(0u, resources.size()); | 1019 EXPECT_EQ(0u, resources.size()); |
1037 | 1020 |
1038 // The parent compositor (this one) does a commit. | 1021 // The parent compositor (this one) does a commit. |
1039 break; | 1022 break; |
1040 case 4: | 1023 case 3: |
1041 // Retrieve unused resources to the main thread. | |
1042 // TODO(danakj): Shouldn't need to commit to get resources. | |
1043 layer_tree_host()->SetNeedsCommit(); | |
1044 return; | |
1045 case 5: | |
1046 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1024 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1047 { | 1025 { |
1048 unsigned expected[] = {444, 555}; | 1026 unsigned expected[] = {444, 555}; |
1049 EXPECT_RESOURCES(expected, resources); | 1027 EXPECT_RESOURCES(expected, resources); |
1050 } | 1028 } |
1051 | 1029 |
1052 // The child compositor sends a frame before receiving an for the | 1030 // The child compositor sends a frame referring to resources not in the |
1053 // second frame. It uses 999, 444, and 555 again. | 1031 // frame. |
1054 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1032 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1055 AddTextureQuad(frame.get(), 999); | 1033 AddTextureQuad(frame.get(), 999); |
1056 AddTextureQuad(frame.get(), 555); | 1034 AddTextureQuad(frame.get(), 555); |
1057 AddTextureQuad(frame.get(), 444); | 1035 AddTextureQuad(frame.get(), 444); |
1058 delegated_->SetFrameData(frame.Pass()); | 1036 delegated_->SetFrameData(frame.Pass()); |
1059 break; | 1037 break; |
1060 } | 1038 } |
1061 } | 1039 } |
1062 | 1040 |
1063 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1041 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1064 if (host_impl->active_tree()->source_frame_number() != 5) | 1042 if (host_impl->active_tree()->source_frame_number() != 3) |
1065 return; | 1043 return; |
1066 | 1044 |
1067 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 1045 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
1068 FakeDelegatedRendererLayerImpl* delegated_impl = | 1046 FakeDelegatedRendererLayerImpl* delegated_impl = |
1069 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 1047 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
1070 | 1048 |
1071 const ResourceProvider::ResourceIdMap& map = | 1049 const ResourceProvider::ResourceIdMap& map = |
1072 host_impl->resource_provider()->GetChildToParentMap( | 1050 host_impl->resource_provider()->GetChildToParentMap( |
1073 delegated_impl->ChildId()); | 1051 delegated_impl->ChildId()); |
1074 | 1052 |
1075 // The bad frame should be dropped. So we should only have one quad (the | 1053 // The bad frame should be dropped. So we should only have one quad (the |
1076 // one with resource 999) on the impl tree. And only 999 will be present | 1054 // one with resource 999) on the impl tree. And only 999 will be present |
1077 // in the parent's resource provider. | 1055 // in the parent's resource provider. |
1078 EXPECT_EQ(1u, map.size()); | 1056 EXPECT_EQ(1u, map.size()); |
1079 EXPECT_EQ(1u, map.count(999)); | 1057 EXPECT_EQ(1u, map.count(999)); |
1080 | 1058 |
1081 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1059 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1082 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1060 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1083 | 1061 |
1084 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 1062 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
1085 EXPECT_EQ(1u, pass->quad_list.size()); | 1063 EXPECT_EQ(1u, pass->quad_list.size()); |
1086 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( | 1064 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( |
1087 pass->quad_list[0]); | 1065 pass->quad_list[0]); |
1088 EXPECT_EQ(map.find(999)->second, quad->resource_id); | 1066 EXPECT_EQ(map.find(999)->second, quad->resource_id); |
1089 | 1067 |
1090 EndTest(); | 1068 EndTest(); |
1091 } | 1069 } |
1092 | 1070 |
(...skipping 25 matching lines...) Expand all Loading... |
1118 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1096 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1119 AddTextureQuad(frame.get(), 999); | 1097 AddTextureQuad(frame.get(), 999); |
1120 AddTransferableResource(frame.get(), 999); | 1098 AddTransferableResource(frame.get(), 999); |
1121 AddTextureQuad(frame.get(), 555); | 1099 AddTextureQuad(frame.get(), 555); |
1122 AddTransferableResource(frame.get(), 555); | 1100 AddTransferableResource(frame.get(), 555); |
1123 AddTextureQuad(frame.get(), 444); | 1101 AddTextureQuad(frame.get(), 444); |
1124 AddTransferableResource(frame.get(), 444); | 1102 AddTransferableResource(frame.get(), 444); |
1125 delegated_->SetFrameData(frame.Pass()); | 1103 delegated_->SetFrameData(frame.Pass()); |
1126 break; | 1104 break; |
1127 case 2: | 1105 case 2: |
1128 // Retrieve unused resources to the main thread. | |
1129 // TODO(danakj): Shouldn't need to commit to get resources. | |
1130 layer_tree_host()->SetNeedsCommit(); | |
1131 return; | |
1132 case 3: | |
1133 // All of the resources are in use. | 1106 // All of the resources are in use. |
1134 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1107 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1135 EXPECT_EQ(0u, resources.size()); | 1108 EXPECT_EQ(0u, resources.size()); |
1136 | 1109 |
1137 // Keep using 999 but stop using 555 and 444. | 1110 // Keep using 999 but stop using 555 and 444. |
1138 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1111 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1139 AddTextureQuad(frame.get(), 999); | 1112 AddTextureQuad(frame.get(), 999); |
1140 AddTransferableResource(frame.get(), 999); | 1113 AddTransferableResource(frame.get(), 999); |
1141 delegated_->SetFrameData(frame.Pass()); | 1114 delegated_->SetFrameData(frame.Pass()); |
1142 | 1115 |
1143 // Resource are not immediately released. | 1116 // Resource are not immediately released. |
1144 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1117 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1145 EXPECT_EQ(0u, resources.size()); | 1118 EXPECT_EQ(0u, resources.size()); |
1146 | 1119 |
1147 // The parent compositor (this one) does a commit. | 1120 // The parent compositor (this one) does a commit. |
1148 break; | 1121 break; |
1149 case 4: | 1122 case 3: |
1150 // Retrieve unused resources to the main thread. | |
1151 // TODO(danakj): Shouldn't need to commit to get resources. | |
1152 layer_tree_host()->SetNeedsCommit(); | |
1153 return; | |
1154 case 5: | |
1155 // The child compositor sends a frame before taking resources back | 1123 // The child compositor sends a frame before taking resources back |
1156 // from the previous commit. This frame makes use of the resources 555 | 1124 // from the previous commit. This frame makes use of the resources 555 |
1157 // and 444, which were just released during commit. | 1125 // and 444, which were just released during commit. |
1158 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1126 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1159 AddTextureQuad(frame.get(), 999); | 1127 AddTextureQuad(frame.get(), 999); |
1160 AddTransferableResource(frame.get(), 999); | 1128 AddTransferableResource(frame.get(), 999); |
1161 AddTextureQuad(frame.get(), 555); | 1129 AddTextureQuad(frame.get(), 555); |
1162 AddTransferableResource(frame.get(), 555); | 1130 AddTransferableResource(frame.get(), 555); |
1163 AddTextureQuad(frame.get(), 444); | 1131 AddTextureQuad(frame.get(), 444); |
1164 AddTransferableResource(frame.get(), 444); | 1132 AddTransferableResource(frame.get(), 444); |
1165 delegated_->SetFrameData(frame.Pass()); | 1133 delegated_->SetFrameData(frame.Pass()); |
1166 | 1134 |
1167 // The resources are used by the new frame but are returned anyway since | 1135 // The resources are used by the new frame but are returned anyway since |
1168 // we passed them again. | 1136 // we passed them again. |
1169 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1137 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1170 { | 1138 { |
1171 unsigned expected[] = {444, 555}; | 1139 unsigned expected[] = {444, 555}; |
1172 EXPECT_RESOURCES(expected, resources); | 1140 EXPECT_RESOURCES(expected, resources); |
1173 } | 1141 } |
1174 break; | 1142 break; |
1175 case 6: | 1143 case 4: |
1176 // Retrieve unused resources to the main thread. | |
1177 // TODO(danakj): Shouldn't need to commit to get resources. | |
1178 layer_tree_host()->SetNeedsCommit(); | |
1179 return; | |
1180 case 7: | |
1181 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1144 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1182 EXPECT_EQ(0u, resources.size()); | 1145 EXPECT_EQ(0u, resources.size()); |
1183 EndTest(); | 1146 EndTest(); |
1184 break; | 1147 break; |
1185 } | 1148 } |
1186 } | 1149 } |
1187 | 1150 |
1188 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1151 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1189 if (host_impl->active_tree()->source_frame_number() != 5) | 1152 if (host_impl->active_tree()->source_frame_number() != 3) |
1190 return; | 1153 return; |
1191 | 1154 |
1192 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 1155 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
1193 FakeDelegatedRendererLayerImpl* delegated_impl = | 1156 FakeDelegatedRendererLayerImpl* delegated_impl = |
1194 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 1157 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
1195 | 1158 |
1196 const ResourceProvider::ResourceIdMap& map = | 1159 const ResourceProvider::ResourceIdMap& map = |
1197 host_impl->resource_provider()->GetChildToParentMap( | 1160 host_impl->resource_provider()->GetChildToParentMap( |
1198 delegated_impl->ChildId()); | 1161 delegated_impl->ChildId()); |
1199 | 1162 |
1200 // The third frame has all of the resources in it again, the delegated | 1163 // The third frame has all of the resources in it again, the delegated |
1201 // renderer layer should continue to own the resources for it. | 1164 // renderer layer should continue to own the resources for it. |
1202 EXPECT_EQ(3u, map.size()); | 1165 EXPECT_EQ(3u, map.size()); |
1203 EXPECT_EQ(1u, map.count(999)); | 1166 EXPECT_EQ(1u, map.count(999)); |
1204 EXPECT_EQ(1u, map.count(555)); | 1167 EXPECT_EQ(1u, map.count(555)); |
1205 EXPECT_EQ(1u, map.count(444)); | 1168 EXPECT_EQ(1u, map.count(444)); |
1206 | 1169 |
1207 EXPECT_EQ(3u, delegated_impl->Resources().size()); | 1170 EXPECT_EQ(3u, delegated_impl->Resources().size()); |
1208 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1171 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1209 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1172 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1210 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second)); | 1173 EXPECT_EQ(1u, delegated_impl->Resources().count(444)); |
1211 | 1174 |
1212 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 1175 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
1213 EXPECT_EQ(3u, pass->quad_list.size()); | 1176 EXPECT_EQ(3u, pass->quad_list.size()); |
1214 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 1177 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
1215 pass->quad_list[0]); | 1178 pass->quad_list[0]); |
1216 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 1179 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
1217 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 1180 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
1218 pass->quad_list[1]); | 1181 pass->quad_list[1]); |
1219 EXPECT_EQ(map.find(555)->second, quad2->resource_id); | 1182 EXPECT_EQ(map.find(555)->second, quad2->resource_id); |
1220 const TextureDrawQuad* quad3 = TextureDrawQuad::MaterialCast( | 1183 const TextureDrawQuad* quad3 = TextureDrawQuad::MaterialCast( |
(...skipping 28 matching lines...) Expand all Loading... |
1249 case 1: | 1212 case 1: |
1250 // Generate a frame with some resources in it. | 1213 // Generate a frame with some resources in it. |
1251 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1214 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1252 AddTextureQuad(frame.get(), 999); | 1215 AddTextureQuad(frame.get(), 999); |
1253 AddTransferableResource(frame.get(), 999); | 1216 AddTransferableResource(frame.get(), 999); |
1254 AddTextureQuad(frame.get(), 555); | 1217 AddTextureQuad(frame.get(), 555); |
1255 AddTransferableResource(frame.get(), 555); | 1218 AddTransferableResource(frame.get(), 555); |
1256 delegated_->SetFrameData(frame.Pass()); | 1219 delegated_->SetFrameData(frame.Pass()); |
1257 break; | 1220 break; |
1258 case 2: | 1221 case 2: |
1259 // Retrieve unused resources to the main thread. | |
1260 // TODO(danakj): Shouldn't need to commit to get resources. | |
1261 layer_tree_host()->SetNeedsCommit(); | |
1262 return; | |
1263 case 3: | |
1264 // All of the resources are in use. | 1222 // All of the resources are in use. |
1265 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1223 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1266 EXPECT_EQ(0u, resources.size()); | 1224 EXPECT_EQ(0u, resources.size()); |
1267 | 1225 |
1268 // Generate a bad frame with a resource the layer doesn't have. The | 1226 // Generate a bad frame with a resource the layer doesn't have. The |
1269 // 885 and 775 resources are unknown, while ownership of the legit 444 | 1227 // 885 and 775 resources are unknown, while ownership of the legit 444 |
1270 // resource is passed in here. The bad frame does not use any of the | 1228 // resource is passed in here. The bad frame does not use any of the |
1271 // previous resources, 999 or 555. | 1229 // previous resources, 999 or 555. |
1272 // A bad quad is present both before and after the good quad. | 1230 // A bad quad is present both before and after the good quad. |
1273 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1231 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1274 AddTextureQuad(frame.get(), 885); | 1232 AddTextureQuad(frame.get(), 885); |
1275 AddTextureQuad(frame.get(), 444); | 1233 AddTextureQuad(frame.get(), 444); |
1276 AddTransferableResource(frame.get(), 444); | 1234 AddTransferableResource(frame.get(), 444); |
1277 AddTextureQuad(frame.get(), 775); | 1235 AddTextureQuad(frame.get(), 775); |
1278 delegated_->SetFrameData(frame.Pass()); | 1236 delegated_->SetFrameData(frame.Pass()); |
1279 | 1237 |
1280 // The parent compositor (this one) does a commit. | 1238 // The parent compositor (this one) does a commit. |
1281 break; | 1239 break; |
1282 case 4: | 1240 case 3: |
1283 // Retrieve unused resources to the main thread. | |
1284 // TODO(danakj): Shouldn't need to commit to get resources. | |
1285 layer_tree_host()->SetNeedsCommit(); | |
1286 return; | |
1287 case 5: | |
1288 // The bad frame's resource is given back to the child compositor. | 1241 // The bad frame's resource is given back to the child compositor. |
1289 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1242 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1290 { | 1243 { |
1291 unsigned expected[] = {444}; | 1244 unsigned expected[] = {444}; |
1292 EXPECT_RESOURCES(expected, resources); | 1245 EXPECT_RESOURCES(expected, resources); |
1293 } | 1246 } |
1294 | 1247 |
1295 // Now send a good frame with 999 again. | 1248 // Now send a good frame with 999 again. |
1296 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1249 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1297 AddTextureQuad(frame.get(), 999); | 1250 AddTextureQuad(frame.get(), 999); |
1298 delegated_->SetFrameData(frame.Pass()); | 1251 delegated_->SetFrameData(frame.Pass()); |
1299 break; | 1252 break; |
1300 case 6: | 1253 case 4: |
1301 // Retrieve unused resources to the main thread. | |
1302 // TODO(danakj): Shouldn't need to commit to get resources. | |
1303 layer_tree_host()->SetNeedsCommit(); | |
1304 return; | |
1305 case 7: | |
1306 // The unused 555 from the last good frame is now released. | 1254 // The unused 555 from the last good frame is now released. |
1307 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1255 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1308 { | 1256 { |
1309 unsigned expected[] = {555}; | 1257 unsigned expected[] = {555}; |
1310 EXPECT_RESOURCES(expected, resources); | 1258 EXPECT_RESOURCES(expected, resources); |
1311 } | 1259 } |
1312 | 1260 |
1313 EndTest(); | 1261 EndTest(); |
1314 break; | 1262 break; |
1315 } | 1263 } |
(...skipping 16 matching lines...) Expand all Loading... |
1332 | 1280 |
1333 switch (host_impl->active_tree()->source_frame_number()) { | 1281 switch (host_impl->active_tree()->source_frame_number()) { |
1334 case 1: { | 1282 case 1: { |
1335 // We have the first good frame with just 990 and 555 in it. | 1283 // We have the first good frame with just 990 and 555 in it. |
1336 // layer. | 1284 // layer. |
1337 EXPECT_EQ(2u, map.size()); | 1285 EXPECT_EQ(2u, map.size()); |
1338 EXPECT_EQ(1u, map.count(999)); | 1286 EXPECT_EQ(1u, map.count(999)); |
1339 EXPECT_EQ(1u, map.count(555)); | 1287 EXPECT_EQ(1u, map.count(555)); |
1340 | 1288 |
1341 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 1289 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
1342 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1290 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1343 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1291 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1344 | 1292 |
1345 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 1293 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
1346 EXPECT_EQ(2u, pass->quad_list.size()); | 1294 EXPECT_EQ(2u, pass->quad_list.size()); |
1347 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 1295 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
1348 pass->quad_list[0]); | 1296 pass->quad_list[0]); |
1349 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 1297 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
1350 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 1298 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
1351 pass->quad_list[1]); | 1299 pass->quad_list[1]); |
1352 EXPECT_EQ(map.find(555)->second, quad2->resource_id); | 1300 EXPECT_EQ(map.find(555)->second, quad2->resource_id); |
1353 break; | 1301 break; |
1354 } | 1302 } |
1355 case 3: { | 1303 case 2: { |
1356 // We only keep resources from the last valid frame. | 1304 // We only keep resources from the last valid frame. |
1357 EXPECT_EQ(2u, map.size()); | 1305 EXPECT_EQ(2u, map.size()); |
1358 EXPECT_EQ(1u, map.count(999)); | 1306 EXPECT_EQ(1u, map.count(999)); |
1359 EXPECT_EQ(1u, map.count(555)); | 1307 EXPECT_EQ(1u, map.count(555)); |
1360 | 1308 |
1361 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 1309 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
1362 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1310 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1363 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1311 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1364 | 1312 |
1365 // The bad frame is dropped though, we still have the frame with 999 and | 1313 // The bad frame is dropped though, we still have the frame with 999 and |
1366 // 555 in it. | 1314 // 555 in it. |
1367 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 1315 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
1368 EXPECT_EQ(2u, pass->quad_list.size()); | 1316 EXPECT_EQ(2u, pass->quad_list.size()); |
1369 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 1317 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
1370 pass->quad_list[0]); | 1318 pass->quad_list[0]); |
1371 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 1319 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
1372 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 1320 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
1373 pass->quad_list[1]); | 1321 pass->quad_list[1]); |
1374 EXPECT_EQ(map.find(555)->second, quad2->resource_id); | 1322 EXPECT_EQ(map.find(555)->second, quad2->resource_id); |
1375 break; | 1323 break; |
1376 } | 1324 } |
1377 case 5: | 1325 case 3: { |
1378 // Resources given to our parent compositor will be returned now, but | |
1379 // the DelegatedRendererLayerImpl doesn't know about it until the next | |
1380 // commit. | |
1381 // TODO(danakj): Shouldn't need a commit to return resources to the | |
1382 // DelegatedRendererLayerImpl or to the main thread. | |
1383 break; | |
1384 case 6: { | |
1385 // We have the new good frame with just 999 in it. | 1326 // We have the new good frame with just 999 in it. |
1386 EXPECT_EQ(1u, map.size()); | 1327 EXPECT_EQ(1u, map.size()); |
1387 EXPECT_EQ(1u, map.count(999)); | 1328 EXPECT_EQ(1u, map.count(999)); |
1388 | 1329 |
1389 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1330 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1390 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1331 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1391 | 1332 |
1392 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 1333 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
1393 EXPECT_EQ(1u, pass->quad_list.size()); | 1334 EXPECT_EQ(1u, pass->quad_list.size()); |
1394 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 1335 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
1395 pass->quad_list[0]); | 1336 pass->quad_list[0]); |
1396 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 1337 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
1397 break; | 1338 break; |
1398 } | 1339 } |
1399 } | 1340 } |
1400 } | 1341 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 | 1389 |
1449 const ResourceProvider::ResourceIdMap& map = | 1390 const ResourceProvider::ResourceIdMap& map = |
1450 host_impl->resource_provider()->GetChildToParentMap( | 1391 host_impl->resource_provider()->GetChildToParentMap( |
1451 delegated_impl->ChildId()); | 1392 delegated_impl->ChildId()); |
1452 | 1393 |
1453 // The layer only held on to the resource that was used. | 1394 // The layer only held on to the resource that was used. |
1454 EXPECT_EQ(1u, map.size()); | 1395 EXPECT_EQ(1u, map.size()); |
1455 EXPECT_EQ(1u, map.count(555)); | 1396 EXPECT_EQ(1u, map.count(555)); |
1456 | 1397 |
1457 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1398 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1458 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1399 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1459 } | 1400 } |
1460 | 1401 |
1461 virtual void AfterTest() OVERRIDE {} | 1402 virtual void AfterTest() OVERRIDE {} |
1462 }; | 1403 }; |
1463 | 1404 |
1464 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource); | 1405 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource); |
1465 | 1406 |
1466 class LayerTreeHostDelegatedTestDontLeakResource | 1407 class LayerTreeHostDelegatedTestDontLeakResource |
1467 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1408 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
1468 public: | 1409 public: |
1469 virtual void BeginTest() OVERRIDE { | 1410 virtual void BeginTest() OVERRIDE { |
1470 PostSetNeedsCommitToMainThread(); | 1411 PostSetNeedsCommitToMainThread(); |
1471 } | 1412 } |
1472 | 1413 |
1473 virtual void DidCommit() OVERRIDE { | 1414 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1474 scoped_ptr<DelegatedFrameData> frame; | 1415 scoped_ptr<DelegatedFrameData> frame; |
1475 ReturnedResourceArray resources; | 1416 ReturnedResourceArray resources; |
1476 | 1417 |
1477 int next_source_frame_number = layer_tree_host()->source_frame_number(); | 1418 int next_source_frame_number = layer_tree_host()->source_frame_number(); |
1478 switch (next_source_frame_number) { | 1419 switch (next_source_frame_number) { |
1479 case 1: | 1420 case 1: |
1480 // This frame includes two resources in it. | 1421 // This frame includes two resources in it. |
1481 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1422 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1482 AddTextureQuad(frame.get(), 999); | 1423 AddTextureQuad(frame.get(), 999); |
1483 AddTransferableResource(frame.get(), 999); | 1424 AddTransferableResource(frame.get(), 999); |
(...skipping 13 matching lines...) Expand all Loading... |
1497 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1438 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1498 { | 1439 { |
1499 unsigned expected[] = {555, 999}; | 1440 unsigned expected[] = {555, 999}; |
1500 EXPECT_RESOURCES(expected, resources); | 1441 EXPECT_RESOURCES(expected, resources); |
1501 } | 1442 } |
1502 // Send a frame with no resources in it. | 1443 // Send a frame with no resources in it. |
1503 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1444 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1504 delegated_->SetFrameData(frame.Pass()); | 1445 delegated_->SetFrameData(frame.Pass()); |
1505 break; | 1446 break; |
1506 case 3: | 1447 case 3: |
1507 // The impl side will get back the resource at some point. | |
1508 // TODO(piman): The test should work without this. | |
1509 layer_tree_host()->SetNeedsCommit(); | |
1510 break; | |
1511 case 4: | |
1512 // The now unused resource 555 should be returned. | 1448 // The now unused resource 555 should be returned. |
1513 resources.clear(); | 1449 resources.clear(); |
1514 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1450 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1515 { | 1451 { |
1516 unsigned expected[] = {555}; | 1452 unsigned expected[] = {555}; |
1517 EXPECT_RESOURCES(expected, resources); | 1453 EXPECT_RESOURCES(expected, resources); |
1518 } | 1454 } |
1519 EndTest(); | 1455 EndTest(); |
1520 break; | 1456 break; |
1521 } | 1457 } |
1522 } | 1458 } |
1523 | 1459 |
1524 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1460 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1525 if (host_impl->active_tree()->source_frame_number() != 1) | 1461 if (host_impl->active_tree()->source_frame_number() != 1) |
1526 return; | 1462 return; |
1527 | 1463 |
1528 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 1464 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
1529 FakeDelegatedRendererLayerImpl* delegated_impl = | 1465 FakeDelegatedRendererLayerImpl* delegated_impl = |
1530 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 1466 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
1531 | 1467 |
1532 const ResourceProvider::ResourceIdMap& map = | 1468 const ResourceProvider::ResourceIdMap& map = |
1533 host_impl->resource_provider()->GetChildToParentMap( | 1469 host_impl->resource_provider()->GetChildToParentMap( |
1534 delegated_impl->ChildId()); | 1470 delegated_impl->ChildId()); |
1535 | 1471 |
1536 // The layer only held on to the resource that was used. | 1472 // The layer only held on to the resource that was used. |
1537 EXPECT_EQ(1u, map.size()); | 1473 EXPECT_EQ(1u, map.size()); |
1538 EXPECT_EQ(1u, map.count(555)); | 1474 EXPECT_EQ(1u, map.count(555)); |
1539 | 1475 |
1540 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1476 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1541 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1477 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1542 } | 1478 } |
1543 | 1479 |
1544 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1480 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
1545 bool result) OVERRIDE { | 1481 bool result) OVERRIDE { |
1546 ReturnUnusedResourcesFromParent(host_impl); | 1482 ReturnUnusedResourcesFromParent(host_impl); |
1547 } | 1483 } |
1548 | 1484 |
1549 virtual void AfterTest() OVERRIDE {} | 1485 virtual void AfterTest() OVERRIDE {} |
1550 }; | 1486 }; |
1551 | 1487 |
(...skipping 18 matching lines...) Expand all Loading... |
1570 delegated_->SetFrameData(frame.Pass()); | 1506 delegated_->SetFrameData(frame.Pass()); |
1571 break; | 1507 break; |
1572 case 2: | 1508 case 2: |
1573 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1509 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1574 EXPECT_EQ(0u, resources.size()); | 1510 EXPECT_EQ(0u, resources.size()); |
1575 | 1511 |
1576 // 999 is in use in the grandparent compositor, generate a frame without | 1512 // 999 is in use in the grandparent compositor, generate a frame without |
1577 // it present. | 1513 // it present. |
1578 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); | 1514 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
1579 AddTextureQuad(frame.get(), 555); | 1515 AddTextureQuad(frame.get(), 555); |
| 1516 AddTransferableResource(frame.get(), 555); |
1580 delegated_->SetFrameData(frame.Pass()); | 1517 delegated_->SetFrameData(frame.Pass()); |
1581 break; | 1518 break; |
1582 case 3: | 1519 case 3: |
1583 // Since 999 is in the grandparent it is not returned. | 1520 // Since 999 is in the grandparent it is not returned. |
1584 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | 1521 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
1585 EXPECT_EQ(0u, resources.size()); | 1522 EXPECT_EQ(0u, resources.size()); |
1586 | 1523 |
1587 // The impl side will get back the resource at some point. | 1524 // The impl side will get back the resource at some point. |
1588 // TODO(danakj): The test should work without this. | 1525 ImplThreadTaskRunner()->PostTask(FROM_HERE, |
1589 layer_tree_host()->SetNeedsCommit(); | 1526 receive_resource_on_thread_); |
1590 break; | |
1591 case 4: | |
1592 // 999 was returned from the grandparent and could be released. | |
1593 delegated_->TakeUnusedResourcesForChildCompositor(&resources); | |
1594 { | |
1595 unsigned expected[] = {999}; | |
1596 EXPECT_RESOURCES(expected, resources); | |
1597 } | |
1598 | |
1599 EndTest(); | |
1600 break; | 1527 break; |
1601 } | 1528 } |
1602 } | 1529 } |
1603 | 1530 |
| 1531 void ReceiveResourceOnThread(LayerTreeHostImpl* host_impl) { |
| 1532 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 1533 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 1534 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 1535 |
| 1536 const ResourceProvider::ResourceIdMap& map = |
| 1537 host_impl->resource_provider()->GetChildToParentMap( |
| 1538 delegated_impl->ChildId()); |
| 1539 |
| 1540 // Receive 999 back from the grandparent. |
| 1541 CompositorFrameAck ack; |
| 1542 output_surface()->ReturnResource(map.find(999)->second, &ack); |
| 1543 host_impl->ReclaimResources(&ack); |
| 1544 host_impl->OnSwapBuffersComplete(); |
| 1545 |
| 1546 // And then it should be released by the DelegatedRendererLayer. |
| 1547 MainThreadTaskRunner()->PostTask( |
| 1548 FROM_HERE, |
| 1549 base::Bind(&LayerTreeHostDelegatedTestResourceSentToParent:: |
| 1550 DidReceiveResourceOnMainThread, |
| 1551 base::Unretained(this))); |
| 1552 } |
| 1553 |
| 1554 void DidReceiveResourceOnMainThread() { |
| 1555 ReturnedResourceArray resources; |
| 1556 |
| 1557 // 999 was returned from the grandparent and could be released. |
| 1558 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
| 1559 { |
| 1560 unsigned expected[] = {999}; |
| 1561 EXPECT_RESOURCES(expected, resources); |
| 1562 } |
| 1563 |
| 1564 EndTest(); |
| 1565 } |
| 1566 |
1604 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1567 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1605 if (host_impl->active_tree()->source_frame_number() < 1) | 1568 if (host_impl->active_tree()->source_frame_number() < 1) |
1606 return; | 1569 return; |
1607 | 1570 |
1608 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); | 1571 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
1609 FakeDelegatedRendererLayerImpl* delegated_impl = | 1572 FakeDelegatedRendererLayerImpl* delegated_impl = |
1610 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); | 1573 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
1611 | 1574 |
1612 const ResourceProvider::ResourceIdMap& map = | 1575 const ResourceProvider::ResourceIdMap& map = |
1613 host_impl->resource_provider()->GetChildToParentMap( | 1576 host_impl->resource_provider()->GetChildToParentMap( |
1614 delegated_impl->ChildId()); | 1577 delegated_impl->ChildId()); |
1615 | 1578 |
1616 switch (host_impl->active_tree()->source_frame_number()) { | 1579 switch (host_impl->active_tree()->source_frame_number()) { |
1617 case 1: { | 1580 case 1: { |
1618 EXPECT_EQ(2u, map.size()); | 1581 EXPECT_EQ(2u, map.size()); |
1619 EXPECT_EQ(1u, map.count(999)); | 1582 EXPECT_EQ(1u, map.count(999)); |
1620 EXPECT_EQ(1u, map.count(555)); | 1583 EXPECT_EQ(1u, map.count(555)); |
1621 | 1584 |
1622 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 1585 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
1623 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1586 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1624 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1587 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1625 | 1588 |
1626 // The 999 resource will be sent to a grandparent compositor. | 1589 // The 999 resource will be sent to a grandparent compositor. |
1627 break; | 1590 break; |
1628 } | 1591 } |
1629 case 2: { | 1592 case 2: { |
1630 EXPECT_EQ(2u, map.size()); | 1593 EXPECT_EQ(2u, map.size()); |
1631 EXPECT_EQ(1u, map.count(999)); | 1594 EXPECT_EQ(1u, map.count(999)); |
1632 EXPECT_EQ(1u, map.count(555)); | 1595 EXPECT_EQ(1u, map.count(555)); |
1633 | 1596 |
1634 // 999 is in the parent, so not held by delegated renderer layer. | 1597 // 999 is in the parent, so not held by delegated renderer layer. |
1635 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1598 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1636 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1599 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1637 | 1600 |
1638 // Receive 999 back from the grandparent. | 1601 receive_resource_on_thread_ = |
1639 CompositorFrameAck ack; | 1602 base::Bind(&LayerTreeHostDelegatedTestResourceSentToParent:: |
1640 output_surface()->ReturnResource(map.find(999)->second, &ack); | 1603 ReceiveResourceOnThread, |
1641 host_impl->ReclaimResources(&ack); | 1604 base::Unretained(this), |
1642 host_impl->OnSwapBuffersComplete(); | 1605 host_impl); |
1643 break; | 1606 break; |
1644 } | 1607 } |
1645 case 3: | 1608 case 3: |
1646 // 999 should be released. | 1609 // 999 should be released. |
1647 EXPECT_EQ(1u, map.size()); | 1610 EXPECT_EQ(1u, map.size()); |
1648 EXPECT_EQ(1u, map.count(555)); | 1611 EXPECT_EQ(1u, map.count(555)); |
1649 | 1612 |
1650 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1613 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1651 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1614 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); |
1652 break; | 1615 break; |
1653 } | 1616 } |
1654 } | 1617 } |
1655 | 1618 |
1656 virtual void AfterTest() OVERRIDE {} | 1619 virtual void AfterTest() OVERRIDE {} |
1657 | 1620 |
1658 TransferableResource resource_in_grandparent; | 1621 base::Closure receive_resource_on_thread_; |
1659 }; | 1622 }; |
1660 | 1623 |
1661 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F( | 1624 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F( |
1662 LayerTreeHostDelegatedTestResourceSentToParent); | 1625 LayerTreeHostDelegatedTestResourceSentToParent); |
1663 | 1626 |
1664 class LayerTreeHostDelegatedTestCommitWithoutTake | 1627 class LayerTreeHostDelegatedTestCommitWithoutTake |
1665 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1628 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
1666 public: | 1629 public: |
1667 virtual void BeginTest() OVERRIDE { | 1630 virtual void BeginTest() OVERRIDE { |
1668 // Prevent drawing with resources that are sent to the grandparent. | 1631 // Prevent drawing with resources that are sent to the grandparent. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 delegated_impl->ChildId()); | 1709 delegated_impl->ChildId()); |
1747 | 1710 |
1748 switch (host_impl->active_tree()->source_frame_number()) { | 1711 switch (host_impl->active_tree()->source_frame_number()) { |
1749 case 1: | 1712 case 1: |
1750 EXPECT_EQ(3u, map.size()); | 1713 EXPECT_EQ(3u, map.size()); |
1751 EXPECT_EQ(1u, map.count(999)); | 1714 EXPECT_EQ(1u, map.count(999)); |
1752 EXPECT_EQ(1u, map.count(555)); | 1715 EXPECT_EQ(1u, map.count(555)); |
1753 EXPECT_EQ(1u, map.count(444)); | 1716 EXPECT_EQ(1u, map.count(444)); |
1754 | 1717 |
1755 EXPECT_EQ(3u, delegated_impl->Resources().size()); | 1718 EXPECT_EQ(3u, delegated_impl->Resources().size()); |
1756 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1719 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1757 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1720 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1758 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second)); | 1721 EXPECT_EQ(1u, delegated_impl->Resources().count(444)); |
1759 break; | 1722 break; |
1760 case 2: | 1723 case 2: |
1761 EXPECT_EQ(1u, map.size()); | 1724 EXPECT_EQ(1u, map.size()); |
1762 EXPECT_EQ(1u, map.count(555)); | 1725 EXPECT_EQ(1u, map.count(555)); |
1763 | 1726 |
1764 EXPECT_EQ(1u, delegated_impl->Resources().size()); | 1727 EXPECT_EQ(1u, delegated_impl->Resources().size()); |
1765 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1728 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1766 break; | 1729 break; |
1767 case 3: | 1730 case 3: |
1768 EXPECT_EQ(2u, map.size()); | 1731 EXPECT_EQ(2u, map.size()); |
1769 EXPECT_EQ(1u, map.count(999)); | 1732 EXPECT_EQ(1u, map.count(999)); |
1770 EXPECT_EQ(1u, map.count(555)); | 1733 EXPECT_EQ(1u, map.count(555)); |
1771 | 1734 |
1772 EXPECT_EQ(2u, delegated_impl->Resources().size()); | 1735 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
1773 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | 1736 EXPECT_EQ(1u, delegated_impl->Resources().count(999)); |
1774 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | 1737 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); |
1775 } | 1738 } |
1776 } | 1739 } |
1777 | 1740 |
1778 virtual void AfterTest() OVERRIDE {} | 1741 virtual void AfterTest() OVERRIDE {} |
1779 }; | 1742 }; |
1780 | 1743 |
1781 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); | 1744 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); |
1782 | 1745 |
1783 class DelegatedFrameIsActivatedDuringCommit | 1746 class DelegatedFrameIsActivatedDuringCommit |
1784 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 1747 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 base::WaitableEvent wait_event_; | 1840 base::WaitableEvent wait_event_; |
1878 base::Lock activate_lock_; | 1841 base::Lock activate_lock_; |
1879 int activate_count_; | 1842 int activate_count_; |
1880 }; | 1843 }; |
1881 | 1844 |
1882 SINGLE_AND_MULTI_THREAD_TEST_F( | 1845 SINGLE_AND_MULTI_THREAD_TEST_F( |
1883 DelegatedFrameIsActivatedDuringCommit); | 1846 DelegatedFrameIsActivatedDuringCommit); |
1884 | 1847 |
1885 } // namespace | 1848 } // namespace |
1886 } // namespace cc | 1849 } // namespace cc |
OLD | NEW |