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

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: nits 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 // The resource 999 from frame1 is returned since it is still on the main
531 // thread.
532 TransferableResourceArray returned_resources;
533 delegated_->TakeUnusedResourcesForChildCompositor(&returned_resources);
534 {
535 unsigned expected[] = {999};
536 EXPECT_RESOURCES(expected, returned_resources);
537 }
538
499 PostSetNeedsCommitToMainThread(); 539 PostSetNeedsCommitToMainThread();
500 } 540 }
501 541
502 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 542 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
503 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); 543 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
504 FakeDelegatedRendererLayerImpl* delegated_impl = 544 FakeDelegatedRendererLayerImpl* delegated_impl =
505 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); 545 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
506 546
507 const ResourceProvider::ResourceIdMap& map = 547 const ResourceProvider::ResourceIdMap& map =
508 host_impl->resource_provider()->GetChildToParentMap( 548 host_impl->resource_provider()->GetChildToParentMap(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 delegated_->SetFrameData(frame.Pass()); 656 delegated_->SetFrameData(frame.Pass());
617 break; 657 break;
618 case 4: 658 case 4:
619 // Retrieve unused resources to the main thread. 659 // Retrieve unused resources to the main thread.
620 // TODO(danakj): Shouldn't need to commit to get resources. 660 // TODO(danakj): Shouldn't need to commit to get resources.
621 layer_tree_host()->SetNeedsCommit(); 661 layer_tree_host()->SetNeedsCommit();
622 return; 662 return;
623 case 5: 663 case 5:
624 // 555 is no longer in use. 664 // 555 is no longer in use.
625 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 665 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
626 EXPECT_EQ(1u, resources.size()); 666 {
627 EXPECT_EQ(555u, resources[0].id); 667 unsigned expected[] = {555};
668 EXPECT_RESOURCES(expected, resources);
669 }
628 670
629 // Stop using any resources. 671 // Stop using any resources.
630 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 672 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
631 delegated_->SetFrameData(frame.Pass()); 673 delegated_->SetFrameData(frame.Pass());
632 break; 674 break;
633 case 6: 675 case 6:
634 // Postpone collecting resources for a frame. They should still be there 676 // Postpone collecting resources for a frame. They should still be there
635 // the next frame. 677 // the next frame.
636 layer_tree_host()->SetNeedsCommit(); 678 layer_tree_host()->SetNeedsCommit();
637 return; 679 return;
638 case 7: 680 case 7:
639 // 444 and 999 are no longer in use. 681 // 444 and 999 are no longer in use.
640 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 682 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
641 EXPECT_EQ(2u, resources.size()); 683 {
642 if (resources[0].id == 999) { 684 unsigned expected[] = {444, 999};
643 EXPECT_EQ(999u, resources[0].id); 685 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 } 686 }
649 EndTest(); 687 EndTest();
650 break; 688 break;
651 } 689 }
652 690
653 // Resource are never immediately released. 691 // Resource are never immediately released.
654 TransferableResourceArray empty_resources; 692 TransferableResourceArray empty_resources;
655 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources); 693 delegated_->TakeUnusedResourcesForChildCompositor(&empty_resources);
656 EXPECT_TRUE(empty_resources.empty()); 694 EXPECT_TRUE(empty_resources.empty());
657 } 695 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 delegated_->SetFrameData(frame.Pass()); 755 delegated_->SetFrameData(frame.Pass());
718 break; 756 break;
719 case 4: 757 case 4:
720 // Retrieve unused resources to the main thread. 758 // Retrieve unused resources to the main thread.
721 // TODO(danakj): Shouldn't need to commit to get resources. 759 // TODO(danakj): Shouldn't need to commit to get resources.
722 layer_tree_host()->SetNeedsCommit(); 760 layer_tree_host()->SetNeedsCommit();
723 return; 761 return;
724 case 5: 762 case 5:
725 // The 999 resource is the only unused one. 763 // The 999 resource is the only unused one.
726 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 764 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
727 EXPECT_EQ(1u, resources.size()); 765 {
728 EXPECT_EQ(999u, resources[0].id); 766 unsigned expected[] = {999};
767 EXPECT_RESOURCES(expected, resources);
768 }
729 EndTest(); 769 EndTest();
730 break; 770 break;
731 } 771 }
732 } 772 }
733 773
734 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 774 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
735 bool result) OVERRIDE { 775 bool result) OVERRIDE {
736 ReturnUnusedResourcesFromParent(host_impl); 776 ReturnUnusedResourcesFromParent(host_impl);
737 } 777 }
738 778
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 826
787 // The parent compositor (this one) does a commit. 827 // The parent compositor (this one) does a commit.
788 break; 828 break;
789 case 4: 829 case 4:
790 // Retrieve unused resources to the main thread. 830 // Retrieve unused resources to the main thread.
791 // TODO(danakj): Shouldn't need to commit to get resources. 831 // TODO(danakj): Shouldn't need to commit to get resources.
792 layer_tree_host()->SetNeedsCommit(); 832 layer_tree_host()->SetNeedsCommit();
793 return; 833 return;
794 case 5: 834 case 5:
795 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 835 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
796 EXPECT_EQ(2u, resources.size()); 836 {
797 if (resources[0].id == 555) { 837 unsigned expected[] = {444, 555};
798 EXPECT_EQ(555u, resources[0].id); 838 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 } 839 }
804 840
805 // The child compositor sends a frame before receiving an for the 841 // The child compositor sends a frame before receiving an for the
806 // second frame. It uses 999, 444, and 555 again. 842 // second frame. It uses 999, 444, and 555 again.
807 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 843 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
808 AddTextureQuad(frame.get(), 999); 844 AddTextureQuad(frame.get(), 999);
809 AddTextureQuad(frame.get(), 555); 845 AddTextureQuad(frame.get(), 555);
810 AddTextureQuad(frame.get(), 444); 846 AddTextureQuad(frame.get(), 444);
811 delegated_->SetFrameData(frame.Pass()); 847 delegated_->SetFrameData(frame.Pass());
812 break; 848 break;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 layer_tree_host()->SetNeedsCommit(); 919 layer_tree_host()->SetNeedsCommit();
884 return; 920 return;
885 case 3: 921 case 3:
886 // All of the resources are in use. 922 // All of the resources are in use.
887 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 923 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
888 EXPECT_EQ(0u, resources.size()); 924 EXPECT_EQ(0u, resources.size());
889 925
890 // Keep using 999 but stop using 555 and 444. 926 // Keep using 999 but stop using 555 and 444.
891 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));
892 AddTextureQuad(frame.get(), 999); 928 AddTextureQuad(frame.get(), 999);
929 AddTransferableResource(frame.get(), 999);
893 delegated_->SetFrameData(frame.Pass()); 930 delegated_->SetFrameData(frame.Pass());
894 931
895 // Resource are not immediately released. 932 // Resource are not immediately released.
896 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 933 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
897 EXPECT_EQ(0u, resources.size()); 934 EXPECT_EQ(0u, resources.size());
898 935
899 // The parent compositor (this one) does a commit. 936 // The parent compositor (this one) does a commit.
900 break; 937 break;
901 case 4: 938 case 4:
902 // Retrieve unused resources to the main thread. 939 // Retrieve unused resources to the main thread.
903 // TODO(danakj): Shouldn't need to commit to get resources. 940 // TODO(danakj): Shouldn't need to commit to get resources.
904 layer_tree_host()->SetNeedsCommit(); 941 layer_tree_host()->SetNeedsCommit();
905 return; 942 return;
906 case 5: 943 case 5:
907 // The child compositor sends a frame before taking resources back 944 // The child compositor sends a frame before taking resources back
908 // from the previous commit. This frame makes use of the resources 555 945 // from the previous commit. This frame makes use of the resources 555
909 // and 444, which were just released during commit. 946 // and 444, which were just released during commit.
910 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 947 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
911 AddTextureQuad(frame.get(), 999); 948 AddTextureQuad(frame.get(), 999);
949 AddTransferableResource(frame.get(), 999);
912 AddTextureQuad(frame.get(), 555); 950 AddTextureQuad(frame.get(), 555);
951 AddTransferableResource(frame.get(), 555);
913 AddTextureQuad(frame.get(), 444); 952 AddTextureQuad(frame.get(), 444);
953 AddTransferableResource(frame.get(), 444);
914 delegated_->SetFrameData(frame.Pass()); 954 delegated_->SetFrameData(frame.Pass());
915 955
916 // The resources are used by the new frame so are not returned. 956 // The resources are used by the new frame but are returned anyway since
957 // we passed them again.
917 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 958 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
918 EXPECT_EQ(0u, resources.size()); 959 {
960 unsigned expected[] = {444, 555};
961 EXPECT_RESOURCES(expected, resources);
962 }
919 break; 963 break;
920 case 6: 964 case 6:
921 // Retrieve unused resources to the main thread. 965 // Retrieve unused resources to the main thread.
922 // TODO(danakj): Shouldn't need to commit to get resources. 966 // TODO(danakj): Shouldn't need to commit to get resources.
923 layer_tree_host()->SetNeedsCommit(); 967 layer_tree_host()->SetNeedsCommit();
924 return; 968 return;
925 case 7: 969 case 7:
926 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 970 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
927 EXPECT_EQ(0u, resources.size()); 971 EXPECT_EQ(0u, resources.size());
928 EndTest(); 972 EndTest();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 // The parent compositor (this one) does a commit. 1069 // The parent compositor (this one) does a commit.
1026 break; 1070 break;
1027 case 4: 1071 case 4:
1028 // Retrieve unused resources to the main thread. 1072 // Retrieve unused resources to the main thread.
1029 // TODO(danakj): Shouldn't need to commit to get resources. 1073 // TODO(danakj): Shouldn't need to commit to get resources.
1030 layer_tree_host()->SetNeedsCommit(); 1074 layer_tree_host()->SetNeedsCommit();
1031 return; 1075 return;
1032 case 5: 1076 case 5:
1033 // The bad frame's resource is given back to the child compositor. 1077 // The bad frame's resource is given back to the child compositor.
1034 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1078 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1035 EXPECT_EQ(1u, resources.size()); 1079 {
1036 EXPECT_EQ(444u, resources[0].id); 1080 unsigned expected[] = {444};
1081 EXPECT_RESOURCES(expected, resources);
1082 }
1037 1083
1038 // Now send a good frame with 999 again. 1084 // Now send a good frame with 999 again.
1039 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1085 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1040 AddTextureQuad(frame.get(), 999); 1086 AddTextureQuad(frame.get(), 999);
1041 delegated_->SetFrameData(frame.Pass()); 1087 delegated_->SetFrameData(frame.Pass());
1042 break; 1088 break;
1043 case 6: 1089 case 6:
1044 // Retrieve unused resources to the main thread. 1090 // Retrieve unused resources to the main thread.
1045 // TODO(danakj): Shouldn't need to commit to get resources. 1091 // TODO(danakj): Shouldn't need to commit to get resources.
1046 layer_tree_host()->SetNeedsCommit(); 1092 layer_tree_host()->SetNeedsCommit();
1047 return; 1093 return;
1048 case 7: 1094 case 7:
1049 // The unused 555 from the last good frame is now released. 1095 // The unused 555 from the last good frame is now released.
1050 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1096 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1051 EXPECT_EQ(1u, resources.size()); 1097 {
1052 EXPECT_EQ(555u, resources[0].id); 1098 unsigned expected[] = {555};
1099 EXPECT_RESOURCES(expected, resources);
1100 }
1053 1101
1054 EndTest(); 1102 EndTest();
1055 break; 1103 break;
1056 } 1104 }
1057 } 1105 }
1058 1106
1059 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 1107 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1060 bool result) OVERRIDE { 1108 bool result) OVERRIDE {
1061 if (host_impl->active_tree()->source_frame_number() < 1) 1109 if (host_impl->active_tree()->source_frame_number() < 1)
1062 return; 1110 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. 1210 // 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)); 1211 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1164 AddTransferableResource(frame.get(), 999); 1212 AddTransferableResource(frame.get(), 999);
1165 AddTextureQuad(frame.get(), 555); 1213 AddTextureQuad(frame.get(), 555);
1166 AddTransferableResource(frame.get(), 555); 1214 AddTransferableResource(frame.get(), 555);
1167 delegated_->SetFrameData(frame.Pass()); 1215 delegated_->SetFrameData(frame.Pass());
1168 break; 1216 break;
1169 case 2: 1217 case 2:
1170 // The unused resource should be returned. 1218 // The unused resource should be returned.
1171 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1219 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1172 EXPECT_EQ(1u, resources.size()); 1220 {
1173 EXPECT_EQ(999u, resources[0].id); 1221 unsigned expected[] = {999};
1222 EXPECT_RESOURCES(expected, resources);
1223 }
1174 1224
1175 EndTest(); 1225 EndTest();
1176 break; 1226 break;
1177 } 1227 }
1178 } 1228 }
1179 1229
1180 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1230 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1181 if (host_impl->active_tree()->source_frame_number() != 1) 1231 if (host_impl->active_tree()->source_frame_number() != 1)
1182 return; 1232 return;
1183 1233
(...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)); 1270 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1221 AddTextureQuad(frame.get(), 999); 1271 AddTextureQuad(frame.get(), 999);
1222 AddTransferableResource(frame.get(), 999); 1272 AddTransferableResource(frame.get(), 999);
1223 AddTextureQuad(frame.get(), 555); 1273 AddTextureQuad(frame.get(), 555);
1224 AddTransferableResource(frame.get(), 555); 1274 AddTransferableResource(frame.get(), 555);
1225 delegated_->SetFrameData(frame.Pass()); 1275 delegated_->SetFrameData(frame.Pass());
1226 1276
1227 // But then we immediately stop using 999. 1277 // But then we immediately stop using 999.
1228 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1278 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1229 AddTextureQuad(frame.get(), 555); 1279 AddTextureQuad(frame.get(), 555);
1280 AddTransferableResource(frame.get(), 555);
1230 delegated_->SetFrameData(frame.Pass()); 1281 delegated_->SetFrameData(frame.Pass());
1231 break; 1282 break;
1232 case 2: 1283 case 2:
1233 // The unused resource should be returned. 1284 // The unused resources should be returned. 555 is still used, but it's
1285 // returned once to account for the first frame.
1234 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1286 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1235 EXPECT_EQ(1u, resources.size()); 1287 {
1236 EXPECT_EQ(999u, resources[0].id); 1288 unsigned expected[] = {555, 999};
1237 1289 EXPECT_RESOURCES(expected, resources);
1290 }
1291 // Send a frame with no resources in it.
1292 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1293 delegated_->SetFrameData(frame.Pass());
1294 break;
1295 case 3:
1296 // The impl side will get back the resource at some point.
1297 // TODO(piman): The test should work without this.
1298 layer_tree_host()->SetNeedsCommit();
1299 break;
1300 case 4:
1301 // The now unused resource 555 should be returned.
1302 resources.clear();
1303 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1304 {
1305 unsigned expected[] = {555};
1306 EXPECT_RESOURCES(expected, resources);
1307 }
1238 EndTest(); 1308 EndTest();
1239 break; 1309 break;
1240 } 1310 }
1241 } 1311 }
1242 1312
1243 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1313 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1244 if (host_impl->active_tree()->source_frame_number() != 1) 1314 if (host_impl->active_tree()->source_frame_number() != 1)
1245 return; 1315 return;
1246 1316
1247 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); 1317 LayerImpl* root_impl = host_impl->active_tree()->root_layer();
1248 FakeDelegatedRendererLayerImpl* delegated_impl = 1318 FakeDelegatedRendererLayerImpl* delegated_impl =
1249 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); 1319 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
1250 1320
1251 const ResourceProvider::ResourceIdMap& map = 1321 const ResourceProvider::ResourceIdMap& map =
1252 host_impl->resource_provider()->GetChildToParentMap( 1322 host_impl->resource_provider()->GetChildToParentMap(
1253 delegated_impl->ChildId()); 1323 delegated_impl->ChildId());
1254 1324
1255 // The layer only held on to the resource that was used. 1325 // The layer only held on to the resource that was used.
1256 EXPECT_EQ(1u, map.size()); 1326 EXPECT_EQ(1u, map.size());
1257 EXPECT_EQ(1u, map.count(555)); 1327 EXPECT_EQ(1u, map.count(555));
1258 1328
1259 EXPECT_EQ(1u, delegated_impl->Resources().size()); 1329 EXPECT_EQ(1u, delegated_impl->Resources().size());
1260 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); 1330 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
1261 } 1331 }
1262 1332
1333 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1334 bool result) OVERRIDE {
1335 ReturnUnusedResourcesFromParent(host_impl);
1336 }
1337
1263 virtual void AfterTest() OVERRIDE {} 1338 virtual void AfterTest() OVERRIDE {}
1264 }; 1339 };
1265 1340
1266 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource); 1341 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource);
1267 1342
1268 class LayerTreeHostDelegatedTestResourceSentToParent 1343 class LayerTreeHostDelegatedTestResourceSentToParent
1269 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { 1344 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
1270 public: 1345 public:
1271 virtual void DidCommitAndDrawFrame() OVERRIDE { 1346 virtual void DidCommitAndDrawFrame() OVERRIDE {
1272 scoped_ptr<DelegatedFrameData> frame; 1347 scoped_ptr<DelegatedFrameData> frame;
(...skipping 25 matching lines...) Expand all
1298 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1373 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1299 EXPECT_EQ(0u, resources.size()); 1374 EXPECT_EQ(0u, resources.size());
1300 1375
1301 // The impl side will get back the resource at some point. 1376 // The impl side will get back the resource at some point.
1302 // TODO(danakj): The test should work without this. 1377 // TODO(danakj): The test should work without this.
1303 layer_tree_host()->SetNeedsCommit(); 1378 layer_tree_host()->SetNeedsCommit();
1304 break; 1379 break;
1305 case 4: 1380 case 4:
1306 // 999 was returned from the grandparent and could be released. 1381 // 999 was returned from the grandparent and could be released.
1307 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1382 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1308 EXPECT_EQ(1u, resources.size()); 1383 {
1309 EXPECT_EQ(999u, resources[0].id); 1384 unsigned expected[] = {999};
1385 EXPECT_RESOURCES(expected, resources);
1386 }
1310 1387
1311 EndTest(); 1388 EndTest();
1312 break; 1389 break;
1313 } 1390 }
1314 } 1391 }
1315 1392
1316 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1393 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1317 if (host_impl->active_tree()->source_frame_number() < 1) 1394 if (host_impl->active_tree()->source_frame_number() < 1)
1318 return; 1395 return;
1319 1396
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 AddTransferableResource(frame.get(), 444); 1474 AddTransferableResource(frame.get(), 444);
1398 delegated_->SetFrameData(frame.Pass()); 1475 delegated_->SetFrameData(frame.Pass());
1399 break; 1476 break;
1400 case 2: 1477 case 2:
1401 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1478 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1402 EXPECT_EQ(0u, resources.size()); 1479 EXPECT_EQ(0u, resources.size());
1403 1480
1404 // Stop using 999 and 444 in this frame and commit. 1481 // 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)); 1482 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1406 AddTextureQuad(frame.get(), 555); 1483 AddTextureQuad(frame.get(), 555);
1484 AddTransferableResource(frame.get(), 555);
1407 delegated_->SetFrameData(frame.Pass()); 1485 delegated_->SetFrameData(frame.Pass());
1486 // 999 and 444 will be returned for frame 1, but not 555 since it's in
1487 // the current frame.
1408 break; 1488 break;
1409 case 3: 1489 case 3:
1410 // Don't take resources here, but set a new frame that uses 999 again. 1490 // 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)); 1491 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1412 AddTextureQuad(frame.get(), 999); 1492 AddTextureQuad(frame.get(), 999);
1493 AddTransferableResource(frame.get(), 999);
1413 AddTextureQuad(frame.get(), 555); 1494 AddTextureQuad(frame.get(), 555);
1495 AddTransferableResource(frame.get(), 555);
1414 delegated_->SetFrameData(frame.Pass()); 1496 delegated_->SetFrameData(frame.Pass());
1415 break; 1497 break;
1416 case 4: 1498 case 4:
1417 // 999 and 555 are in use, but 444 should be returned now. 1499 // 555 from frame 1 and 2 isn't returned since it's still in use. 999
1500 // from frame 1 is returned though.
1418 delegated_->TakeUnusedResourcesForChildCompositor(&resources); 1501 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1419 EXPECT_EQ(1u, resources.size()); 1502 {
1420 EXPECT_EQ(444u, resources[0].id); 1503 unsigned expected[] = {444, 999};
1504 EXPECT_RESOURCES(expected, resources);
1505 }
1506
1507 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1508 delegated_->SetFrameData(frame.Pass());
1509 // 555 will be returned 3 times for frames 1 2 and 3, and 999 will be
1510 // returned once for frame 3.
1511 break;
1512 case 5:
1513 delegated_->TakeUnusedResourcesForChildCompositor(&resources);
1514 {
1515 unsigned expected[] = {555, 555, 555, 999};
1516 EXPECT_RESOURCES(expected, resources);
1517 }
1421 1518
1422 EndTest(); 1519 EndTest();
1423 break; 1520 break;
1424 } 1521 }
1425 } 1522 }
1426 1523
1427 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1524 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1428 if (host_impl->active_tree()->source_frame_number() < 1) 1525 if (host_impl->active_tree()->source_frame_number() < 1)
1429 return; 1526 return;
1430 1527
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 } 1563 }
1467 } 1564 }
1468 1565
1469 virtual void AfterTest() OVERRIDE {} 1566 virtual void AfterTest() OVERRIDE {}
1470 }; 1567 };
1471 1568
1472 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); 1569 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake);
1473 1570
1474 } // namespace 1571 } // namespace
1475 } // namespace cc 1572 } // 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