Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: cc/layer_tree_host_unittest_delegated.cc

Issue 12385085: cc: Unused resources should be given back to the child compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/delegated_renderer_layer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/layer_tree_host.h" 5 #include "cc/layer_tree_host.h"
6 6
7 #include "cc/delegated_frame_data.h" 7 #include "cc/delegated_frame_data.h"
8 #include "cc/delegated_renderer_layer.h" 8 #include "cc/delegated_renderer_layer.h"
9 #include "cc/delegated_renderer_layer_impl.h" 9 #include "cc/delegated_renderer_layer_impl.h"
10 #include "cc/layer_tree_impl.h" 10 #include "cc/layer_tree_impl.h"
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 357
358 const ResourceProvider::ResourceIdMap& map = 358 const ResourceProvider::ResourceIdMap& map =
359 host_impl->resourceProvider()->getChildToParentMap( 359 host_impl->resourceProvider()->getChildToParentMap(
360 delegated_impl->ChildId()); 360 delegated_impl->ChildId());
361 361
362 // Both frames' resources should be in the parent's resource provider. 362 // Both frames' resources should be in the parent's resource provider.
363 EXPECT_EQ(2u, map.size()); 363 EXPECT_EQ(2u, map.size());
364 EXPECT_EQ(1u, map.count(999)); 364 EXPECT_EQ(1u, map.count(999));
365 EXPECT_EQ(1u, map.count(555)); 365 EXPECT_EQ(1u, map.count(555));
366 366
367 // Both frames' resources should be saved on the layer.
368 EXPECT_EQ(2u, delegated_impl->Resources().size()); 367 EXPECT_EQ(2u, delegated_impl->Resources().size());
369 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); 368 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
370 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); 369 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
371 370
372 endTest(); 371 endTest();
373 } 372 }
374 373
375 virtual void afterTest() OVERRIDE {} 374 virtual void afterTest() OVERRIDE {}
376 }; 375 };
377 376
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 case 3: 696 case 3:
698 // The child compositor sends a frame before taking resources back 697 // The child compositor sends a frame before taking resources back
699 // from the previous commit. This frame makes use of the resources 555 698 // from the previous commit. This frame makes use of the resources 555
700 // and 444, which were just released during commit. 699 // and 444, which were just released during commit.
701 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 700 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
702 AddTextureQuad(frame.get(), 999); 701 AddTextureQuad(frame.get(), 999);
703 AddTextureQuad(frame.get(), 555); 702 AddTextureQuad(frame.get(), 555);
704 AddTextureQuad(frame.get(), 444); 703 AddTextureQuad(frame.get(), 444);
705 delegated_->SetFrameData(frame.Pass()); 704 delegated_->SetFrameData(frame.Pass());
706 705
707 // When we take resources, it should have the resources that were 706 // The resources are used by the new frame so are not returned.
708 // released during the last valid frame committed.
709 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 707 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
710 EXPECT_EQ(2u, resources.size()); 708 EXPECT_EQ(0u, resources.size());
711 if (resources[0].id == 555) {
712 EXPECT_EQ(555, resources[0].id);
713 EXPECT_EQ(444, resources[1].id);
714 } else {
715 EXPECT_EQ(444, resources[0].id);
716 EXPECT_EQ(555, resources[1].id);
717 }
718 break; 709 break;
719 case 4: 710 case 4:
720 // The invalid frame doesn't cause anything to be released.
721 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 711 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
722 EXPECT_EQ(0u, resources.size()); 712 EXPECT_EQ(0u, resources.size());
723 endTest(); 713 endTest();
724 break; 714 break;
725 } 715 }
726 } 716 }
727 717
728 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 718 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
729 if (host_impl->activeTree()->source_frame_number() != 3) 719 if (host_impl->activeTree()->source_frame_number() != 3)
730 return; 720 return;
731 721
732 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); 722 LayerImpl* root_impl = host_impl->activeTree()->RootLayer();
733 FakeDelegatedRendererLayerImpl* delegated_impl = 723 FakeDelegatedRendererLayerImpl* delegated_impl =
734 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); 724 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
735 725
736 const ResourceProvider::ResourceIdMap& map = 726 const ResourceProvider::ResourceIdMap& map =
737 host_impl->resourceProvider()->getChildToParentMap( 727 host_impl->resourceProvider()->getChildToParentMap(
738 delegated_impl->ChildId()); 728 delegated_impl->ChildId());
739 729
740 // The bad frame should be dropped. So we should only have one quad (the 730 // The third frame has all of the resources in it again, the delegated
741 // one with resource 999) on the impl tree. And only 999 will be present 731 // renderer layer should continue to own the resources for it.
742 // in the parent's resource provider. 732 EXPECT_EQ(3u, map.size());
743 EXPECT_EQ(1u, map.size());
744 EXPECT_EQ(1u, map.count(999)); 733 EXPECT_EQ(1u, map.count(999));
734 EXPECT_EQ(1u, map.count(555));
735 EXPECT_EQ(1u, map.count(444));
745 736
746 EXPECT_EQ(1u, delegated_impl->Resources().size()); 737 EXPECT_EQ(3u, delegated_impl->Resources().size());
747 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); 738 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
739 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
740 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second));
748 741
749 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; 742 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0];
750 EXPECT_EQ(1u, pass->quad_list.size()); 743 EXPECT_EQ(3u, pass->quad_list.size());
751 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( 744 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast(
752 pass->quad_list[0]); 745 pass->quad_list[0]);
753 EXPECT_EQ(map.find(999)->second, quad->resource_id); 746 EXPECT_EQ(map.find(999)->second, quad1->resource_id);
747 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast(
748 pass->quad_list[1]);
749 EXPECT_EQ(map.find(555)->second, quad2->resource_id);
750 const TextureDrawQuad* quad3 = TextureDrawQuad::MaterialCast(
751 pass->quad_list[2]);
752 EXPECT_EQ(map.find(444)->second, quad3->resource_id);
754 } 753 }
755 754
756 virtual void afterTest() OVERRIDE {} 755 virtual void afterTest() OVERRIDE {}
757 }; 756 };
758 757
759 SINGLE_AND_MULTI_THREAD_TEST_F( 758 SINGLE_AND_MULTI_THREAD_TEST_F(
760 LayerTreeHostDelegatedTestFrameBeforeTakeResources) 759 LayerTreeHostDelegatedTestFrameBeforeTakeResources)
761 760
762 class LayerTreeHostDelegatedTestBadFrame 761 class LayerTreeHostDelegatedTestBadFrame
763 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { 762 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
(...skipping 30 matching lines...) Expand all
794 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 793 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
795 AddTextureQuad(frame.get(), 885); 794 AddTextureQuad(frame.get(), 885);
796 AddTextureQuad(frame.get(), 444); 795 AddTextureQuad(frame.get(), 444);
797 AddTransferableResource(frame.get(), 444); 796 AddTransferableResource(frame.get(), 444);
798 AddTextureQuad(frame.get(), 775); 797 AddTextureQuad(frame.get(), 775);
799 delegated_->SetFrameData(frame.Pass()); 798 delegated_->SetFrameData(frame.Pass());
800 799
801 // The parent compositor (this one) does a commit. 800 // The parent compositor (this one) does a commit.
802 break; 801 break;
803 case 3: 802 case 3:
804 // The bad frame does not cause resources to be released, and the 803 // The bad frame's resource is given back to the child compositor.
805 // resources given in it are held onto.
806 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 804 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
807 EXPECT_EQ(0u, resources.size()); 805 EXPECT_EQ(1u, resources.size());
806 EXPECT_EQ(444, resources[0].id);
808 807
809 // Now send a good frame with 999 again. 808 // Now send a good frame with 999 again.
810 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 809 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
811 AddTextureQuad(frame.get(), 999); 810 AddTextureQuad(frame.get(), 999);
812 delegated_->SetFrameData(frame.Pass()); 811 delegated_->SetFrameData(frame.Pass());
813 break; 812 break;
814 case 4: 813 case 4:
815 // The unused 444 resource from the bad frame will be released along 814 // The unused 555 from the last good frame is now released.
816 // with the unused 555.
817 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 815 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
818 EXPECT_EQ(2u, resources.size()); 816 EXPECT_EQ(1u, resources.size());
819 if (resources[0].id == 555) { 817 EXPECT_EQ(555, resources[0].id);
820 EXPECT_EQ(555, resources[0].id);
821 EXPECT_EQ(444, resources[1].id);
822 } else {
823 EXPECT_EQ(444, resources[0].id);
824 EXPECT_EQ(555, resources[1].id);
825 }
826 818
827 endTest(); 819 endTest();
828 break; 820 break;
829 } 821 }
830 } 822 }
831 823
832 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 824 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
833 if (host_impl->activeTree()->source_frame_number() < 1) 825 if (host_impl->activeTree()->source_frame_number() < 1)
834 return; 826 return;
835 827
(...skipping 21 matching lines...) Expand all
857 EXPECT_EQ(2u, pass->quad_list.size()); 849 EXPECT_EQ(2u, pass->quad_list.size());
858 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( 850 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast(
859 pass->quad_list[0]); 851 pass->quad_list[0]);
860 EXPECT_EQ(map.find(999)->second, quad1->resource_id); 852 EXPECT_EQ(map.find(999)->second, quad1->resource_id);
861 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( 853 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast(
862 pass->quad_list[1]); 854 pass->quad_list[1]);
863 EXPECT_EQ(map.find(555)->second, quad2->resource_id); 855 EXPECT_EQ(map.find(555)->second, quad2->resource_id);
864 break; 856 break;
865 } 857 }
866 case 2: { 858 case 2: {
867 // We have all resources whose ownership has been given to the delegated 859 // We only keep resources from the last valid frame.
868 // layer. 860 EXPECT_EQ(2u, map.size());
869 EXPECT_EQ(3u, map.size());
870 EXPECT_EQ(1u, map.count(999)); 861 EXPECT_EQ(1u, map.count(999));
871 EXPECT_EQ(1u, map.count(555)); 862 EXPECT_EQ(1u, map.count(555));
872 EXPECT_EQ(1u, map.count(444));
873 863
874 EXPECT_EQ(3u, delegated_impl->Resources().size()); 864 EXPECT_EQ(2u, delegated_impl->Resources().size());
875 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); 865 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
876 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); 866 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
877 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second));
878 867
879 // The bad frame is dropped though, we still have the frame with 999 and 868 // The bad frame is dropped though, we still have the frame with 999 and
880 // 555 in it. 869 // 555 in it.
881 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; 870 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0];
882 EXPECT_EQ(2u, pass->quad_list.size()); 871 EXPECT_EQ(2u, pass->quad_list.size());
883 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( 872 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast(
884 pass->quad_list[0]); 873 pass->quad_list[0]);
885 EXPECT_EQ(map.find(999)->second, quad1->resource_id); 874 EXPECT_EQ(map.find(999)->second, quad1->resource_id);
886 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( 875 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast(
887 pass->quad_list[1]); 876 pass->quad_list[1]);
(...skipping 16 matching lines...) Expand all
904 break; 893 break;
905 } 894 }
906 } 895 }
907 } 896 }
908 897
909 virtual void afterTest() OVERRIDE {} 898 virtual void afterTest() OVERRIDE {}
910 }; 899 };
911 900
912 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame) 901 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame)
913 902
903 class LayerTreeHostDelegatedTestUnnamedResource
904 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
905 public:
906 virtual void beginTest() OVERRIDE {
907 postSetNeedsCommitToMainThread();
908 }
909
910 virtual void didCommit() OVERRIDE {
911 scoped_ptr<DelegatedFrameData> frame;
912 TransferableResourceArray resources;
913
914 int next_source_frame_number = m_layerTreeHost->commitNumber();
915 switch (next_source_frame_number) {
916 case 1:
917 // This frame includes two resources in it, but only uses one.
918 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
919 AddTransferableResource(frame.get(), 999);
920 AddTextureQuad(frame.get(), 555);
921 AddTransferableResource(frame.get(), 555);
922 delegated_->SetFrameData(frame.Pass());
923 break;
924 case 2:
925 // The unused resource should be returned.
926 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
927 EXPECT_EQ(1u, resources.size());
928 EXPECT_EQ(999, resources[0].id);
929
930 endTest();
931 break;
932 }
933 }
934
935 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
936 if (host_impl->activeTree()->source_frame_number() != 1)
937 return;
938
939 LayerImpl* root_impl = host_impl->activeTree()->RootLayer();
940 FakeDelegatedRendererLayerImpl* delegated_impl =
941 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
942
943 const ResourceProvider::ResourceIdMap& map =
944 host_impl->resourceProvider()->getChildToParentMap(
945 delegated_impl->ChildId());
946
947 // The layer only held on to the resource that was used.
948 EXPECT_EQ(1u, map.size());
949 EXPECT_EQ(1u, map.count(555));
950
951 EXPECT_EQ(1u, delegated_impl->Resources().size());
952 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
953 }
954
955 virtual void afterTest() OVERRIDE {}
956 };
957
958 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource)
959
960 class LayerTreeHostDelegatedTestDontLeakResource
961 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
962 public:
963 virtual void beginTest() OVERRIDE {
964 postSetNeedsCommitToMainThread();
965 }
966
967 virtual void didCommit() OVERRIDE {
968 scoped_ptr<DelegatedFrameData> frame;
969 TransferableResourceArray resources;
970
971 int next_source_frame_number = m_layerTreeHost->commitNumber();
972 switch (next_source_frame_number) {
973 case 1:
974 // This frame includes two resources in it.
975 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
976 AddTextureQuad(frame.get(), 999);
977 AddTransferableResource(frame.get(), 999);
978 AddTextureQuad(frame.get(), 555);
979 AddTransferableResource(frame.get(), 555);
980 delegated_->SetFrameData(frame.Pass());
981
982 // But then we immediately stop using 999.
983 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
984 AddTextureQuad(frame.get(), 555);
985 delegated_->SetFrameData(frame.Pass());
986 break;
987 case 2:
988 // The unused resource should be returned.
989 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
990 EXPECT_EQ(1u, resources.size());
991 EXPECT_EQ(999, resources[0].id);
992
993 endTest();
994 break;
995 }
996 }
997
998 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
999 if (host_impl->activeTree()->source_frame_number() != 1)
1000 return;
1001
1002 LayerImpl* root_impl = host_impl->activeTree()->RootLayer();
1003 FakeDelegatedRendererLayerImpl* delegated_impl =
1004 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
1005
1006 const ResourceProvider::ResourceIdMap& map =
1007 host_impl->resourceProvider()->getChildToParentMap(
1008 delegated_impl->ChildId());
1009
1010 // The layer only held on to the resource that was used.
1011 EXPECT_EQ(1u, map.size());
1012 EXPECT_EQ(1u, map.count(555));
1013
1014 EXPECT_EQ(1u, delegated_impl->Resources().size());
1015 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1016 }
1017
1018 virtual void afterTest() OVERRIDE {}
1019 };
1020
1021 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource)
1022
1023 class LayerTreeHostDelegatedTestResourceSentToParent
1024 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
1025 public:
1026 virtual void beginTest() OVERRIDE {
1027 // Prevent drawing with resources that are sent to the grandparent.
1028 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size());
1029 postSetNeedsCommitToMainThread();
1030 }
1031
1032 virtual void didCommit() OVERRIDE {
1033 scoped_ptr<DelegatedFrameData> frame;
1034 TransferableResourceArray resources;
1035
1036 int next_source_frame_number = m_layerTreeHost->commitNumber();
1037 switch (next_source_frame_number) {
1038 case 1:
1039 // This frame includes two resources in it.
1040 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1041 AddTextureQuad(frame.get(), 999);
1042 AddTransferableResource(frame.get(), 999);
1043 AddTextureQuad(frame.get(), 555);
1044 AddTransferableResource(frame.get(), 555);
1045 delegated_->SetFrameData(frame.Pass());
1046 break;
1047 case 2:
1048 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1049 EXPECT_EQ(0u, resources.size());
1050
1051 // 999 is in use in the grandparent compositor, generate a frame without
1052 // it present.
1053 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1054 AddTextureQuad(frame.get(), 555);
1055 delegated_->SetFrameData(frame.Pass());
1056 break;
1057 case 3:
1058 // Since 999 is in the grandparent it is not returned.
1059 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1060 EXPECT_EQ(0u, resources.size());
1061
1062 m_layerTreeHost->setNeedsCommit();
1063 break;
1064 case 4:
1065 // 999 was returned from the grandparent and could be released.
1066 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1067 EXPECT_EQ(1u, resources.size());
1068 EXPECT_EQ(999, resources[0].id);
1069
1070 endTest();
1071 break;
1072 }
1073 }
1074
1075 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1076 if (host_impl->activeTree()->source_frame_number() < 1)
1077 return;
1078
1079 LayerImpl* root_impl = host_impl->activeTree()->RootLayer();
1080 FakeDelegatedRendererLayerImpl* delegated_impl =
1081 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
1082
1083 const ResourceProvider::ResourceIdMap& map =
1084 host_impl->resourceProvider()->getChildToParentMap(
1085 delegated_impl->ChildId());
1086
1087 switch (host_impl->activeTree()->source_frame_number()) {
1088 case 1: {
1089 EXPECT_EQ(2u, map.size());
1090 EXPECT_EQ(1u, map.count(999));
1091 EXPECT_EQ(1u, map.count(555));
1092
1093 EXPECT_EQ(2u, delegated_impl->Resources().size());
1094 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
1095 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1096
1097 // The 999 resource is sent to a grandparent compositor.
1098 ResourceProvider::ResourceIdArray resources_for_parent;
1099 resources_for_parent.push_back(map.find(999)->second);
1100 TransferableResourceArray transferable_resources;
1101 host_impl->resourceProvider()->prepareSendToParent(
1102 resources_for_parent, &transferable_resources);
1103 break;
1104 }
1105 case 2: {
1106 EXPECT_EQ(2u, map.size());
1107 EXPECT_EQ(1u, map.count(999));
1108 EXPECT_EQ(1u, map.count(555));
1109
1110 /// 999 is in the parent, so not held by delegated renderer layer.
1111 EXPECT_EQ(1u, delegated_impl->Resources().size());
1112 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1113
1114 // Receive 999 back from the grandparent.
1115 TransferableResource resource;
1116 resource.id = map.find(999)->second;
1117 TransferableResourceArray transferable_resources;
1118 transferable_resources.push_back(resource);
1119 host_impl->resourceProvider()->receiveFromParent(
1120 transferable_resources);
1121 break;
1122 }
1123 case 3:
1124 // 999 should be released.
1125 EXPECT_EQ(1u, map.size());
1126 EXPECT_EQ(1u, map.count(555));
1127
1128 EXPECT_EQ(1u, delegated_impl->Resources().size());
1129 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1130 }
1131 }
1132
1133 virtual void afterTest() OVERRIDE {}
1134 };
1135
1136 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestResourceSentToParent)
1137
1138 class LayerTreeHostDelegatedTestCommitWithoutTake
1139 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
1140 public:
1141 virtual void beginTest() OVERRIDE {
1142 // Prevent drawing with resources that are sent to the grandparent.
1143 m_layerTreeHost->setViewportSize(gfx::Size(10, 10), gfx::Size());
1144 postSetNeedsCommitToMainThread();
1145 }
1146
1147 virtual void didCommit() OVERRIDE {
1148 scoped_ptr<DelegatedFrameData> frame;
1149 TransferableResourceArray resources;
1150
1151 int next_source_frame_number = m_layerTreeHost->commitNumber();
1152 switch (next_source_frame_number) {
1153 case 1:
1154 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1155 AddTextureQuad(frame.get(), 999);
1156 AddTransferableResource(frame.get(), 999);
1157 AddTextureQuad(frame.get(), 555);
1158 AddTransferableResource(frame.get(), 555);
1159 AddTextureQuad(frame.get(), 444);
1160 AddTransferableResource(frame.get(), 444);
1161 delegated_->SetFrameData(frame.Pass());
1162 break;
1163 case 2:
1164 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1165 EXPECT_EQ(0u, resources.size());
1166
1167 // Stop using 999 and 444 in this frame and commit.
1168 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1169 AddTextureQuad(frame.get(), 555);
1170 delegated_->SetFrameData(frame.Pass());
1171 break;
1172 case 3:
1173 // Don't take resources here, but set a new frame that uses 999 again.
1174 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1175 AddTextureQuad(frame.get(), 999);
1176 AddTextureQuad(frame.get(), 555);
1177 delegated_->SetFrameData(frame.Pass());
1178 break;
1179 case 4:
1180 // 999 and 555 are in use, but 444 should be returned now.
1181 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1182 EXPECT_EQ(1u, resources.size());
1183 EXPECT_EQ(444, resources[0].id);
1184
1185 endTest();
1186 break;
1187 }
1188 }
1189
1190 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1191 if (host_impl->activeTree()->source_frame_number() < 1)
1192 return;
1193
1194 LayerImpl* root_impl = host_impl->activeTree()->RootLayer();
1195 FakeDelegatedRendererLayerImpl* delegated_impl =
1196 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
1197
1198 const ResourceProvider::ResourceIdMap& map =
1199 host_impl->resourceProvider()->getChildToParentMap(
1200 delegated_impl->ChildId());
1201
1202 switch (host_impl->activeTree()->source_frame_number()) {
1203 case 1:
1204 EXPECT_EQ(3u, map.size());
1205 EXPECT_EQ(1u, map.count(999));
1206 EXPECT_EQ(1u, map.count(555));
1207 EXPECT_EQ(1u, map.count(444));
1208
1209 EXPECT_EQ(3u, delegated_impl->Resources().size());
1210 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
1211 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1212 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second));
1213 break;
1214 case 2:
1215 EXPECT_EQ(1u, map.size());
1216 EXPECT_EQ(1u, map.count(555));
1217
1218 EXPECT_EQ(1u, delegated_impl->Resources().size());
1219 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1220 break;
1221 case 3:
1222 EXPECT_EQ(2u, map.size());
1223 EXPECT_EQ(1u, map.count(999));
1224 EXPECT_EQ(1u, map.count(555));
1225
1226 EXPECT_EQ(2u, delegated_impl->Resources().size());
1227 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
1228 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1229 }
1230 }
1231
1232 virtual void afterTest() OVERRIDE {}
1233 };
1234
1235 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake)
1236
914 } // namespace 1237 } // namespace
915 } // namespace cc 1238 } // namespace cc
OLDNEW
« no previous file with comments | « cc/delegated_renderer_layer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698