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

Side by Side Diff: cc/trees/layer_tree_host_unittest_delegated.cc

Issue 23023005: cc: refcount resources as we send them to the parent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 7 years, 4 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/resources/resource_provider_unittest.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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "cc/layers/delegated_renderer_layer.h" 10 #include "cc/layers/delegated_renderer_layer.h"
9 #include "cc/layers/delegated_renderer_layer_client.h" 11 #include "cc/layers/delegated_renderer_layer_client.h"
10 #include "cc/layers/delegated_renderer_layer_impl.h" 12 #include "cc/layers/delegated_renderer_layer_impl.h"
11 #include "cc/output/compositor_frame.h" 13 #include "cc/output/compositor_frame.h"
12 #include "cc/output/compositor_frame_ack.h" 14 #include "cc/output/compositor_frame_ack.h"
13 #include "cc/output/delegated_frame_data.h" 15 #include "cc/output/delegated_frame_data.h"
14 #include "cc/quads/shared_quad_state.h" 16 #include "cc/quads/shared_quad_state.h"
15 #include "cc/quads/texture_draw_quad.h" 17 #include "cc/quads/texture_draw_quad.h"
16 #include "cc/test/fake_delegated_renderer_layer.h" 18 #include "cc/test/fake_delegated_renderer_layer.h"
17 #include "cc/test/fake_delegated_renderer_layer_impl.h" 19 #include "cc/test/fake_delegated_renderer_layer_impl.h"
18 #include "cc/test/fake_output_surface.h" 20 #include "cc/test/fake_output_surface.h"
19 #include "cc/test/layer_tree_test.h" 21 #include "cc/test/layer_tree_test.h"
20 #include "cc/trees/layer_tree_impl.h" 22 #include "cc/trees/layer_tree_impl.h"
21 #include "gpu/GLES2/gl2extchromium.h" 23 #include "gpu/GLES2/gl2extchromium.h"
22 24
23 namespace cc { 25 namespace cc {
24 namespace { 26 namespace {
25 27
28 bool TransferableResourceLower(const TransferableResource& a,
29 const TransferableResource& b) {
30 return a.id < b.id;
31 }
32
33 // Tests if the list of resources matches an expectation, modulo the order.
34 bool ResourcesMatch(TransferableResourceArray actual,
35 unsigned* expected,
36 size_t expected_count) {
37 EXPECT_EQ(expected_count, actual.size());
38 if (expected_count != actual.size())
39 return false;
40
41 std::sort(actual.begin(), actual.end(), TransferableResourceLower);
42 std::sort(expected, expected + expected_count);
43 bool result = true;
44 for (size_t i = 0; i < expected_count; ++i) {
45 EXPECT_EQ(actual[i].id, expected[i]);
46 if (actual[i].id != expected[i])
47 result = false;
48 }
49
50 return result;
51 }
52
53 #define EXPECT_RESOURCES(expected, actual) \
54 EXPECT_TRUE(ResourcesMatch(actual, expected, arraysize(expected)));
55
26 // These tests deal with delegated renderer layers. 56 // These tests deal with delegated renderer layers.
27 class LayerTreeHostDelegatedTest : public LayerTreeTest { 57 class LayerTreeHostDelegatedTest : public LayerTreeTest {
28 protected: 58 protected:
29 scoped_ptr<DelegatedFrameData> CreateFrameData(gfx::Rect root_output_rect, 59 scoped_ptr<DelegatedFrameData> CreateFrameData(gfx::Rect root_output_rect,
30 gfx::Rect root_damage_rect) { 60 gfx::Rect root_damage_rect) {
31 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData); 61 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData);
32 62
33 scoped_ptr<RenderPass> root_pass(RenderPass::Create()); 63 scoped_ptr<RenderPass> root_pass(RenderPass::Create());
34 root_pass->SetNew(RenderPass::Id(1, 1), 64 root_pass->SetNew(RenderPass::Id(1, 1),
35 root_output_rect, 65 root_output_rect,
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 scoped_ptr<DelegatedFrameData> frame1 = 515 scoped_ptr<DelegatedFrameData> frame1 =
486 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 516 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
487 AddTextureQuad(frame1.get(), 999); 517 AddTextureQuad(frame1.get(), 999);
488 AddTransferableResource(frame1.get(), 999); 518 AddTransferableResource(frame1.get(), 999);
489 delegated_->SetFrameData(frame1.Pass()); 519 delegated_->SetFrameData(frame1.Pass());
490 520
491 // The second frame uses resource 999 still, but also adds 555. 521 // The second frame uses resource 999 still, but also adds 555.
492 scoped_ptr<DelegatedFrameData> frame2 = 522 scoped_ptr<DelegatedFrameData> frame2 =
493 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 523 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
494 AddTextureQuad(frame2.get(), 999); 524 AddTextureQuad(frame2.get(), 999);
525 AddTransferableResource(frame2.get(), 999);
495 AddTextureQuad(frame2.get(), 555); 526 AddTextureQuad(frame2.get(), 555);
496 AddTransferableResource(frame2.get(), 555); 527 AddTransferableResource(frame2.get(), 555);
497 delegated_->SetFrameData(frame2.Pass()); 528 delegated_->SetFrameData(frame2.Pass());
498 529
530 TransferableResourceArray returned_resources;
danakj 2013/08/16 16:49:44 // The resource 999 from frame1 is returned since
piman 2013/08/16 20:43:19 Done.
531 delegated_->TakeUnusedResourcesForChildCompositor(&returned_resources);
532 {
533 unsigned expected[] = {999};
534 EXPECT_RESOURCES(expected, returned_resources);
535 }
536
499 PostSetNeedsCommitToMainThread(); 537 PostSetNeedsCommitToMainThread();
500 } 538 }
501 539
502 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 540 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
503 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); 541 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
504 FakeDelegatedRendererLayerImpl* delegated_impl = 542 FakeDelegatedRendererLayerImpl* delegated_impl =
505 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); 543 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
506 544
507 const ResourceProvider::ResourceIdMap& map = 545 const ResourceProvider::ResourceIdMap& map =
508 host_impl->resource_provider()->GetChildToParentMap( 546 host_impl->resource_provider()->GetChildToParentMap(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 delegated_->SetFrameData(frame.Pass()); 654 delegated_->SetFrameData(frame.Pass());
617 break; 655 break;
618 case 4: 656 case 4:
619 // Retrieve unused resources to the main thread. 657 // Retrieve unused resources to the main thread.
620 // TODO(danakj): Shouldn't need to commit to get resources. 658 // TODO(danakj): Shouldn't need to commit to get resources.
621 layer_tree_host()->SetNeedsCommit(); 659 layer_tree_host()->SetNeedsCommit();
622 return; 660 return;
623 case 5: 661 case 5:
624 // 555 is no longer in use. 662 // 555 is no longer in use.
625 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 663 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
626 EXPECT_EQ(1u, resources.size()); 664 {
627 EXPECT_EQ(555u, resources[0].id); 665 unsigned expected[] = {555};
666 EXPECT_RESOURCES(expected, resources);
667 }
628 668
629 // Stop using any resources. 669 // Stop using any resources.
630 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 670 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
631 delegated_->SetFrameData(frame.Pass()); 671 delegated_->SetFrameData(frame.Pass());
632 break; 672 break;
633 case 6: 673 case 6:
634 // Postpone collecting resources for a frame. They should still be there 674 // Postpone collecting resources for a frame. They should still be there
635 // the next frame. 675 // the next frame.
636 layer_tree_host()->SetNeedsCommit(); 676 layer_tree_host()->SetNeedsCommit();
637 return; 677 return;
638 case 7: 678 case 7:
639 // 444 and 999 are no longer in use. 679 // 444 and 999 are no longer in use.
640 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 680 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
641 EXPECT_EQ(2u, resources.size()); 681 {
642 if (resources[0].id == 999) { 682 unsigned expected[] = {444, 999};
643 EXPECT_EQ(999u, resources[0].id); 683 EXPECT_RESOURCES(expected, resources);
644 EXPECT_EQ(444u, resources[1].id);
645 } else {
646 EXPECT_EQ(444u, resources[0].id);
647 EXPECT_EQ(999u, resources[1].id);
648 } 684 }
649 EndTest(); 685 EndTest();
650 break; 686 break;
651 } 687 }
652 688
653 // Resource are never immediately released. 689 // Resource are never immediately released.
654 TransferableResourceArray empty_resources; 690 TransferableResourceArray empty_resources;
655 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources); 691 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources);
656 EXPECT_TRUE(empty_resources.empty()); 692 EXPECT_TRUE(empty_resources.empty());
657 } 693 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 delegated_->SetFrameData(frame.Pass()); 753 delegated_->SetFrameData(frame.Pass());
718 break; 754 break;
719 case 4: 755 case 4:
720 // Retrieve unused resources to the main thread. 756 // Retrieve unused resources to the main thread.
721 // TODO(danakj): Shouldn't need to commit to get resources. 757 // TODO(danakj): Shouldn't need to commit to get resources.
722 layer_tree_host()->SetNeedsCommit(); 758 layer_tree_host()->SetNeedsCommit();
723 return; 759 return;
724 case 5: 760 case 5:
725 // The 999 resource is the only unused one. 761 // The 999 resource is the only unused one.
726 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 762 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
727 EXPECT_EQ(1u, resources.size()); 763 {
728 EXPECT_EQ(999u, resources[0].id); 764 unsigned expected[] = {999};
765 EXPECT_RESOURCES(expected, resources);
766 }
729 EndTest(); 767 EndTest();
730 break; 768 break;
731 } 769 }
732 } 770 }
733 771
734 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 772 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
735 bool result) OVERRIDE { 773 bool result) OVERRIDE {
736 ReturnUnusedResourcesFromParent(host_impl); 774 ReturnUnusedResourcesFromParent(host_impl);
737 } 775 }
738 776
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 824
787 // The parent compositor (this one) does a commit. 825 // The parent compositor (this one) does a commit.
788 break; 826 break;
789 case 4: 827 case 4:
790 // Retrieve unused resources to the main thread. 828 // Retrieve unused resources to the main thread.
791 // TODO(danakj): Shouldn't need to commit to get resources. 829 // TODO(danakj): Shouldn't need to commit to get resources.
792 layer_tree_host()->SetNeedsCommit(); 830 layer_tree_host()->SetNeedsCommit();
793 return; 831 return;
794 case 5: 832 case 5:
795 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 833 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
796 EXPECT_EQ(2u, resources.size()); 834 {
797 if (resources[0].id == 555) { 835 unsigned expected[] = {444, 555};
798 EXPECT_EQ(555u, resources[0].id); 836 EXPECT_RESOURCES(expected, resources);
799 EXPECT_EQ(444u, resources[1].id);
800 } else {
801 EXPECT_EQ(444u, resources[0].id);
802 EXPECT_EQ(555u, resources[1].id);
803 } 837 }
804 838
805 // The child compositor sends a frame before receiving an for the 839 // The child compositor sends a frame before receiving an for the
806 // second frame. It uses 999, 444, and 555 again. 840 // second frame. It uses 999, 444, and 555 again.
807 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 841 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
808 AddTextureQuad(frame.get(), 999); 842 AddTextureQuad(frame.get(), 999);
809 AddTextureQuad(frame.get(), 555); 843 AddTextureQuad(frame.get(), 555);
810 AddTextureQuad(frame.get(), 444); 844 AddTextureQuad(frame.get(), 444);
811 delegated_->SetFrameData(frame.Pass()); 845 delegated_->SetFrameData(frame.Pass());
812 break; 846 break;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 layer_tree_host()->SetNeedsCommit(); 917 layer_tree_host()->SetNeedsCommit();
884 return; 918 return;
885 case 3: 919 case 3:
886 // All of the resources are in use. 920 // All of the resources are in use.
887 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 921 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
888 EXPECT_EQ(0u, resources.size()); 922 EXPECT_EQ(0u, resources.size());
889 923
890 // Keep using 999 but stop using 555 and 444. 924 // Keep using 999 but stop using 555 and 444.
891 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 925 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
892 AddTextureQuad(frame.get(), 999); 926 AddTextureQuad(frame.get(), 999);
927 AddTransferableResource(frame.get(), 999);
893 delegated_->SetFrameData(frame.Pass()); 928 delegated_->SetFrameData(frame.Pass());
894 929
895 // Resource are not immediately released. 930 // Resource are not immediately released.
896 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 931 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
897 EXPECT_EQ(0u, resources.size()); 932 EXPECT_EQ(0u, resources.size());
898 933
899 // The parent compositor (this one) does a commit. 934 // The parent compositor (this one) does a commit.
900 break; 935 break;
901 case 4: 936 case 4:
902 // Retrieve unused resources to the main thread. 937 // Retrieve unused resources to the main thread.
903 // TODO(danakj): Shouldn't need to commit to get resources. 938 // TODO(danakj): Shouldn't need to commit to get resources.
904 layer_tree_host()->SetNeedsCommit(); 939 layer_tree_host()->SetNeedsCommit();
905 return; 940 return;
906 case 5: 941 case 5:
907 // The child compositor sends a frame before taking resources back 942 // The child compositor sends a frame before taking resources back
908 // from the previous commit. This frame makes use of the resources 555 943 // from the previous commit. This frame makes use of the resources 555
909 // and 444, which were just released during commit. 944 // and 444, which were just released during commit.
910 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 945 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
911 AddTextureQuad(frame.get(), 999); 946 AddTextureQuad(frame.get(), 999);
947 AddTransferableResource(frame.get(), 999);
912 AddTextureQuad(frame.get(), 555); 948 AddTextureQuad(frame.get(), 555);
949 AddTransferableResource(frame.get(), 555);
913 AddTextureQuad(frame.get(), 444); 950 AddTextureQuad(frame.get(), 444);
951 AddTransferableResource(frame.get(), 444);
914 delegated_->SetFrameData(frame.Pass()); 952 delegated_->SetFrameData(frame.Pass());
915 953
916 // The resources are used by the new frame so are not returned. 954 // The resources are used by the new frame but are returned anyway since
955 // we passed them again.
917 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 956 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
918 EXPECT_EQ(0u, resources.size()); 957 {
958 unsigned expected[] = {444, 555};
959 EXPECT_RESOURCES(expected, resources);
960 }
919 break; 961 break;
920 case 6: 962 case 6:
921 // Retrieve unused resources to the main thread. 963 // Retrieve unused resources to the main thread.
922 // TODO(danakj): Shouldn't need to commit to get resources. 964 // TODO(danakj): Shouldn't need to commit to get resources.
923 layer_tree_host()->SetNeedsCommit(); 965 layer_tree_host()->SetNeedsCommit();
924 return; 966 return;
925 case 7: 967 case 7:
926 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 968 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
927 EXPECT_EQ(0u, resources.size()); 969 EXPECT_EQ(0u, resources.size());
928 EndTest(); 970 EndTest();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 // The parent compositor (this one) does a commit. 1067 // The parent compositor (this one) does a commit.
1026 break; 1068 break;
1027 case 4: 1069 case 4:
1028 // Retrieve unused resources to the main thread. 1070 // Retrieve unused resources to the main thread.
1029 // TODO(danakj): Shouldn't need to commit to get resources. 1071 // TODO(danakj): Shouldn't need to commit to get resources.
1030 layer_tree_host()->SetNeedsCommit(); 1072 layer_tree_host()->SetNeedsCommit();
1031 return; 1073 return;
1032 case 5: 1074 case 5:
1033 // The bad frame's resource is given back to the child compositor. 1075 // The bad frame's resource is given back to the child compositor.
1034 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1076 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1035 EXPECT_EQ(1u, resources.size()); 1077 {
1036 EXPECT_EQ(444u, resources[0].id); 1078 unsigned expected[] = {444};
1079 EXPECT_RESOURCES(expected, resources);
1080 }
1037 1081
1038 // Now send a good frame with 999 again. 1082 // Now send a good frame with 999 again.
1039 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1083 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1040 AddTextureQuad(frame.get(), 999); 1084 AddTextureQuad(frame.get(), 999);
1041 delegated_->SetFrameData(frame.Pass()); 1085 delegated_->SetFrameData(frame.Pass());
1042 break; 1086 break;
1043 case 6: 1087 case 6:
1044 // Retrieve unused resources to the main thread. 1088 // Retrieve unused resources to the main thread.
1045 // TODO(danakj): Shouldn't need to commit to get resources. 1089 // TODO(danakj): Shouldn't need to commit to get resources.
1046 layer_tree_host()->SetNeedsCommit(); 1090 layer_tree_host()->SetNeedsCommit();
1047 return; 1091 return;
1048 case 7: 1092 case 7:
1049 // The unused 555 from the last good frame is now released. 1093 // The unused 555 from the last good frame is now released.
1050 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1094 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1051 EXPECT_EQ(1u, resources.size()); 1095 {
1052 EXPECT_EQ(555u, resources[0].id); 1096 unsigned expected[] = {555};
1097 EXPECT_RESOURCES(expected, resources);
1098 }
1053 1099
1054 EndTest(); 1100 EndTest();
1055 break; 1101 break;
1056 } 1102 }
1057 } 1103 }
1058 1104
1059 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 1105 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1060 bool result) OVERRIDE { 1106 bool result) OVERRIDE {
1061 if (host_impl->active_tree()->source_frame_number() < 1) 1107 if (host_impl->active_tree()->source_frame_number() < 1)
1062 return; 1108 return;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 // This frame includes two resources in it, but only uses one. 1208 // This frame includes two resources in it, but only uses one.
1163 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1209 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1164 AddTransferableResource(frame.get(), 999); 1210 AddTransferableResource(frame.get(), 999);
1165 AddTextureQuad(frame.get(), 555); 1211 AddTextureQuad(frame.get(), 555);
1166 AddTransferableResource(frame.get(), 555); 1212 AddTransferableResource(frame.get(), 555);
1167 delegated_->SetFrameData(frame.Pass()); 1213 delegated_->SetFrameData(frame.Pass());
1168 break; 1214 break;
1169 case 2: 1215 case 2:
1170 // The unused resource should be returned. 1216 // The unused resource should be returned.
1171 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1217 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1172 EXPECT_EQ(1u, resources.size()); 1218 {
1173 EXPECT_EQ(999u, resources[0].id); 1219 unsigned expected[] = {999};
1220 EXPECT_RESOURCES(expected, resources);
1221 }
1174 1222
1175 EndTest(); 1223 EndTest();
1176 break; 1224 break;
1177 } 1225 }
1178 } 1226 }
1179 1227
1180 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1228 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1181 if (host_impl->active_tree()->source_frame_number() != 1) 1229 if (host_impl->active_tree()->source_frame_number() != 1)
1182 return; 1230 return;
1183 1231
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1268 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1221 AddTextureQuad(frame.get(), 999); 1269 AddTextureQuad(frame.get(), 999);
1222 AddTransferableResource(frame.get(), 999); 1270 AddTransferableResource(frame.get(), 999);
1223 AddTextureQuad(frame.get(), 555); 1271 AddTextureQuad(frame.get(), 555);
1224 AddTransferableResource(frame.get(), 555); 1272 AddTransferableResource(frame.get(), 555);
1225 delegated_->SetFrameData(frame.Pass()); 1273 delegated_->SetFrameData(frame.Pass());
1226 1274
1227 // But then we immediately stop using 999. 1275 // But then we immediately stop using 999.
1228 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1276 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1229 AddTextureQuad(frame.get(), 555); 1277 AddTextureQuad(frame.get(), 555);
1278 AddTransferableResource(frame.get(), 555);
1230 delegated_->SetFrameData(frame.Pass()); 1279 delegated_->SetFrameData(frame.Pass());
1231 break; 1280 break;
1232 case 2: 1281 case 2:
1233 // The unused resource should be returned. 1282 // The unused resources should be returned. 555 is still used, but it's
1283 // returned once to account for the first frame.
1234 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1284 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1235 EXPECT_EQ(1u, resources.size()); 1285 {
1236 EXPECT_EQ(999u, resources[0].id); 1286 unsigned expected[] = {555, 999};
1237 1287 EXPECT_RESOURCES(expected, resources);
1288 }
1289 // Send a frame with no resources in it.
1290 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1291 delegated_->SetFrameData(frame.Pass());
1292 break;
1293 case 3:
1294 // The impl side will get back the resource at some point.
1295 // TODO(piman): The test should work without this.
1296 layer_tree_host()->SetNeedsCommit();
1297 break;
1298 case 4:
1299 // The now unused resource 555 should be returned.
1300 resources.clear();
1301 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1302 {
1303 unsigned expected[] = {555};
1304 EXPECT_RESOURCES(expected, resources);
1305 }
1238 EndTest(); 1306 EndTest();
1239 break; 1307 break;
1240 } 1308 }
1241 } 1309 }
1242 1310
1243 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1311 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1244 if (host_impl->active_tree()->source_frame_number() != 1) 1312 if (host_impl->active_tree()->source_frame_number() != 1)
1245 return; 1313 return;
1246 1314
1247 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); 1315 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
1248 FakeDelegatedRendererLayerImpl* delegated_impl = 1316 FakeDelegatedRendererLayerImpl* delegated_impl =
1249 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); 1317 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
1250 1318
1251 const ResourceProvider::ResourceIdMap& map = 1319 const ResourceProvider::ResourceIdMap& map =
1252 host_impl->resource_provider()->GetChildToParentMap( 1320 host_impl->resource_provider()->GetChildToParentMap(
1253 delegated_impl->ChildId()); 1321 delegated_impl->ChildId());
1254 1322
1255 // The layer only held on to the resource that was used. 1323 // The layer only held on to the resource that was used.
1256 EXPECT_EQ(1u, map.size()); 1324 EXPECT_EQ(1u, map.size());
1257 EXPECT_EQ(1u, map.count(555)); 1325 EXPECT_EQ(1u, map.count(555));
1258 1326
1259 EXPECT_EQ(1u, delegated_impl->Resources().size()); 1327 EXPECT_EQ(1u, delegated_impl->Resources().size());
1260 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); 1328 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1261 } 1329 }
1262 1330
1331 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1332 bool result) OVERRIDE {
1333 ReturnUnusedResourcesFromParent(host_impl);
1334 }
1335
1263 virtual void AfterTest() OVERRIDE {} 1336 virtual void AfterTest() OVERRIDE {}
1264 }; 1337 };
1265 1338
1266 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource); 1339 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource);
1267 1340
1268 class LayerTreeHostDelegatedTestResourceSentToParent 1341 class LayerTreeHostDelegatedTestResourceSentToParent
1269 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { 1342 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
1270 public: 1343 public:
1271 virtual void DidCommitAndDrawFrame() OVERRIDE { 1344 virtual void DidCommitAndDrawFrame() OVERRIDE {
1272 scoped_ptr<DelegatedFrameData> frame; 1345 scoped_ptr<DelegatedFrameData> frame;
(...skipping 25 matching lines...) Expand all
1298 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1371 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1299 EXPECT_EQ(0u, resources.size()); 1372 EXPECT_EQ(0u, resources.size());
1300 1373
1301 // The impl side will get back the resource at some point. 1374 // The impl side will get back the resource at some point.
1302 // TODO(danakj): The test should work without this. 1375 // TODO(danakj): The test should work without this.
1303 layer_tree_host()->SetNeedsCommit(); 1376 layer_tree_host()->SetNeedsCommit();
1304 break; 1377 break;
1305 case 4: 1378 case 4:
1306 // 999 was returned from the grandparent and could be released. 1379 // 999 was returned from the grandparent and could be released.
1307 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1380 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1308 EXPECT_EQ(1u, resources.size()); 1381 {
1309 EXPECT_EQ(999u, resources[0].id); 1382 unsigned expected[] = {999};
1383 EXPECT_RESOURCES(expected, resources);
1384 }
1310 1385
1311 EndTest(); 1386 EndTest();
1312 break; 1387 break;
1313 } 1388 }
1314 } 1389 }
1315 1390
1316 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1391 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1317 if (host_impl->active_tree()->source_frame_number() < 1) 1392 if (host_impl->active_tree()->source_frame_number() < 1)
1318 return; 1393 return;
1319 1394
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 AddTransferableResource(frame.get(), 444); 1472 AddTransferableResource(frame.get(), 444);
1398 delegated_->SetFrameData(frame.Pass()); 1473 delegated_->SetFrameData(frame.Pass());
1399 break; 1474 break;
1400 case 2: 1475 case 2:
1401 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1476 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1402 EXPECT_EQ(0u, resources.size()); 1477 EXPECT_EQ(0u, resources.size());
1403 1478
1404 // Stop using 999 and 444 in this frame and commit. 1479 // Stop using 999 and 444 in this frame and commit.
1405 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1480 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1406 AddTextureQuad(frame.get(), 555); 1481 AddTextureQuad(frame.get(), 555);
1482 AddTransferableResource(frame.get(), 555);
1407 delegated_->SetFrameData(frame.Pass()); 1483 delegated_->SetFrameData(frame.Pass());
1484 // 999 and 444 will be returned for frame 1, but not 555 since it's in
1485 // the current frame.
1408 break; 1486 break;
1409 case 3: 1487 case 3:
1410 // Don't take resources here, but set a new frame that uses 999 again. 1488 // Don't take resources here, but set a new frame that uses 999 again.
1411 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1489 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1412 AddTextureQuad(frame.get(), 999); 1490 AddTextureQuad(frame.get(), 999);
1491 AddTransferableResource(frame.get(), 999);
1413 AddTextureQuad(frame.get(), 555); 1492 AddTextureQuad(frame.get(), 555);
1493 AddTransferableResource(frame.get(), 555);
1414 delegated_->SetFrameData(frame.Pass()); 1494 delegated_->SetFrameData(frame.Pass());
1415 break; 1495 break;
1416 case 4: 1496 case 4:
1417 // 999 and 555 are in use, but 444 should be returned now. 1497 // 555 from frame 1 and 2 isn't returned since it's still in use. 999
1498 // from frame 1 is returned though.
1418 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1499 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1419 EXPECT_EQ(1u, resources.size()); 1500 {
1420 EXPECT_EQ(444u, resources[0].id); 1501 unsigned expected[] = {444, 999};
1502 EXPECT_RESOURCES(expected, resources);
1503 }
1504
1505 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1506 delegated_->SetFrameData(frame.Pass());
1507 // 555 will be returned 3 times for frames 1 2 and 3, and 999 will be
1508 // returned once for frame 3.
1509 break;
1510 case 5:
1511 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1512 {
1513 unsigned expected[] = {555, 555, 555, 999};
1514 EXPECT_RESOURCES(expected, resources);
1515 }
1421 1516
1422 EndTest(); 1517 EndTest();
1423 break; 1518 break;
1424 } 1519 }
1425 } 1520 }
1426 1521
1427 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1522 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1428 if (host_impl->active_tree()->source_frame_number() < 1) 1523 if (host_impl->active_tree()->source_frame_number() < 1)
1429 return; 1524 return;
1430 1525
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 } 1561 }
1467 } 1562 }
1468 1563
1469 virtual void AfterTest() OVERRIDE {} 1564 virtual void AfterTest() OVERRIDE {}
1470 }; 1565 };
1471 1566
1472 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); 1567 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake);
1473 1568
1474 } // namespace 1569 } // namespace
1475 } // namespace cc 1570 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698