| 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/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 Loading... |
| 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()); | |
| 369 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | |
| 370 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | |
| 371 | |
| 372 endTest(); | 367 endTest(); |
| 373 } | 368 } |
| 374 | 369 |
| 375 virtual void afterTest() OVERRIDE {} | 370 virtual void afterTest() OVERRIDE {} |
| 376 }; | 371 }; |
| 377 | 372 |
| 378 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources) | 373 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources) |
| 379 | 374 |
| 380 class LayerTreeHostDelegatedTestRemapResourcesInQuads | 375 class LayerTreeHostDelegatedTestRemapResourcesInQuads |
| 381 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { | 376 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 const ResourceProvider::ResourceIdMap& map = | 625 const ResourceProvider::ResourceIdMap& map = |
| 631 host_impl->resourceProvider()->getChildToParentMap( | 626 host_impl->resourceProvider()->getChildToParentMap( |
| 632 delegated_impl->ChildId()); | 627 delegated_impl->ChildId()); |
| 633 | 628 |
| 634 // The bad frame should be dropped. So we should only have one quad (the | 629 // The bad frame should be dropped. So we should only have one quad (the |
| 635 // one with resource 999) on the impl tree. And only 999 will be present | 630 // one with resource 999) on the impl tree. And only 999 will be present |
| 636 // in the parent's resource provider. | 631 // in the parent's resource provider. |
| 637 EXPECT_EQ(1u, map.size()); | 632 EXPECT_EQ(1u, map.size()); |
| 638 EXPECT_EQ(1u, map.count(999)); | 633 EXPECT_EQ(1u, map.count(999)); |
| 639 | 634 |
| 640 EXPECT_EQ(1u, delegated_impl->Resources().size()); | |
| 641 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | |
| 642 | |
| 643 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 635 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
| 644 EXPECT_EQ(1u, pass->quad_list.size()); | 636 EXPECT_EQ(1u, pass->quad_list.size()); |
| 645 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( | 637 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( |
| 646 pass->quad_list[0]); | 638 pass->quad_list[0]); |
| 647 EXPECT_EQ(map.find(999)->second, quad->resource_id); | 639 EXPECT_EQ(map.find(999)->second, quad->resource_id); |
| 648 | 640 |
| 649 endTest(); | 641 endTest(); |
| 650 } | 642 } |
| 651 | 643 |
| 652 virtual void afterTest() OVERRIDE {} | 644 virtual void afterTest() OVERRIDE {} |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 const ResourceProvider::ResourceIdMap& map = | 728 const ResourceProvider::ResourceIdMap& map = |
| 737 host_impl->resourceProvider()->getChildToParentMap( | 729 host_impl->resourceProvider()->getChildToParentMap( |
| 738 delegated_impl->ChildId()); | 730 delegated_impl->ChildId()); |
| 739 | 731 |
| 740 // The bad frame should be dropped. So we should only have one quad (the | 732 // The bad frame should be dropped. So we should only have one quad (the |
| 741 // one with resource 999) on the impl tree. And only 999 will be present | 733 // one with resource 999) on the impl tree. And only 999 will be present |
| 742 // in the parent's resource provider. | 734 // in the parent's resource provider. |
| 743 EXPECT_EQ(1u, map.size()); | 735 EXPECT_EQ(1u, map.size()); |
| 744 EXPECT_EQ(1u, map.count(999)); | 736 EXPECT_EQ(1u, map.count(999)); |
| 745 | 737 |
| 746 EXPECT_EQ(1u, delegated_impl->Resources().size()); | |
| 747 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | |
| 748 | |
| 749 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 738 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
| 750 EXPECT_EQ(1u, pass->quad_list.size()); | 739 EXPECT_EQ(1u, pass->quad_list.size()); |
| 751 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( | 740 const TextureDrawQuad* quad = TextureDrawQuad::MaterialCast( |
| 752 pass->quad_list[0]); | 741 pass->quad_list[0]); |
| 753 EXPECT_EQ(map.find(999)->second, quad->resource_id); | 742 EXPECT_EQ(map.find(999)->second, quad->resource_id); |
| 754 } | 743 } |
| 755 | 744 |
| 756 virtual void afterTest() OVERRIDE {} | 745 virtual void afterTest() OVERRIDE {} |
| 757 }; | 746 }; |
| 758 | 747 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 delegated_impl->ChildId()); | 831 delegated_impl->ChildId()); |
| 843 | 832 |
| 844 switch (host_impl->activeTree()->source_frame_number()) { | 833 switch (host_impl->activeTree()->source_frame_number()) { |
| 845 case 1: { | 834 case 1: { |
| 846 // We have the first good frame with just 990 and 555 in it. | 835 // We have the first good frame with just 990 and 555 in it. |
| 847 // layer. | 836 // layer. |
| 848 EXPECT_EQ(2u, map.size()); | 837 EXPECT_EQ(2u, map.size()); |
| 849 EXPECT_EQ(1u, map.count(999)); | 838 EXPECT_EQ(1u, map.count(999)); |
| 850 EXPECT_EQ(1u, map.count(555)); | 839 EXPECT_EQ(1u, map.count(555)); |
| 851 | 840 |
| 852 EXPECT_EQ(2u, delegated_impl->Resources().size()); | |
| 853 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | |
| 854 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | |
| 855 | |
| 856 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 841 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
| 857 EXPECT_EQ(2u, pass->quad_list.size()); | 842 EXPECT_EQ(2u, pass->quad_list.size()); |
| 858 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 843 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
| 859 pass->quad_list[0]); | 844 pass->quad_list[0]); |
| 860 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 845 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
| 861 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 846 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
| 862 pass->quad_list[1]); | 847 pass->quad_list[1]); |
| 863 EXPECT_EQ(map.find(555)->second, quad2->resource_id); | 848 EXPECT_EQ(map.find(555)->second, quad2->resource_id); |
| 864 break; | 849 break; |
| 865 } | 850 } |
| 866 case 2: { | 851 case 2: { |
| 867 // We have all resources whose ownership has been given to the delegated | 852 // We have all resources whose ownership has been given to the delegated |
| 868 // layer. | 853 // layer. |
| 869 EXPECT_EQ(3u, map.size()); | 854 EXPECT_EQ(3u, map.size()); |
| 870 EXPECT_EQ(1u, map.count(999)); | 855 EXPECT_EQ(1u, map.count(999)); |
| 871 EXPECT_EQ(1u, map.count(555)); | 856 EXPECT_EQ(1u, map.count(555)); |
| 872 EXPECT_EQ(1u, map.count(444)); | 857 EXPECT_EQ(1u, map.count(444)); |
| 873 | 858 |
| 874 EXPECT_EQ(3u, delegated_impl->Resources().size()); | |
| 875 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | |
| 876 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); | |
| 877 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second)); | |
| 878 | |
| 879 // The bad frame is dropped though, we still have the frame with 999 and | 859 // The bad frame is dropped though, we still have the frame with 999 and |
| 880 // 555 in it. | 860 // 555 in it. |
| 881 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 861 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
| 882 EXPECT_EQ(2u, pass->quad_list.size()); | 862 EXPECT_EQ(2u, pass->quad_list.size()); |
| 883 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 863 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
| 884 pass->quad_list[0]); | 864 pass->quad_list[0]); |
| 885 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 865 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
| 886 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( | 866 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
| 887 pass->quad_list[1]); | 867 pass->quad_list[1]); |
| 888 EXPECT_EQ(map.find(555)->second, quad2->resource_id); | 868 EXPECT_EQ(map.find(555)->second, quad2->resource_id); |
| 889 break; | 869 break; |
| 890 } | 870 } |
| 891 case 3: { | 871 case 3: { |
| 892 // We have the new good frame with just 999 in it. | 872 // We have the new good frame with just 999 in it. |
| 893 EXPECT_EQ(1u, map.size()); | 873 EXPECT_EQ(1u, map.size()); |
| 894 EXPECT_EQ(1u, map.count(999)); | 874 EXPECT_EQ(1u, map.count(999)); |
| 895 | 875 |
| 896 EXPECT_EQ(1u, delegated_impl->Resources().size()); | |
| 897 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); | |
| 898 | |
| 899 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; | 876 const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0]; |
| 900 EXPECT_EQ(1u, pass->quad_list.size()); | 877 EXPECT_EQ(1u, pass->quad_list.size()); |
| 901 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( | 878 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
| 902 pass->quad_list[0]); | 879 pass->quad_list[0]); |
| 903 EXPECT_EQ(map.find(999)->second, quad1->resource_id); | 880 EXPECT_EQ(map.find(999)->second, quad1->resource_id); |
| 904 break; | 881 break; |
| 905 } | 882 } |
| 906 } | 883 } |
| 907 } | 884 } |
| 908 | 885 |
| 909 virtual void afterTest() OVERRIDE {} | 886 virtual void afterTest() OVERRIDE {} |
| 910 }; | 887 }; |
| 911 | 888 |
| 912 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame) | 889 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame) |
| 913 | 890 |
| 891 class LayerTreeHostDelegatedTestUnnamedResource |
| 892 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 893 public: |
| 894 virtual void beginTest() OVERRIDE { |
| 895 postSetNeedsCommitToMainThread(); |
| 896 } |
| 897 |
| 898 virtual void didCommit() OVERRIDE { |
| 899 scoped_ptr<DelegatedFrameData> frame; |
| 900 TransferableResourceArray resources; |
| 901 |
| 902 int next_source_frame_number = m_layerTreeHost->commitNumber(); |
| 903 switch (next_source_frame_number) { |
| 904 case 1: |
| 905 // This frame includes two resources in it, but only uses one. |
| 906 frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 907 AddTransferableResource(frame.get(), 999); |
| 908 AddTextureQuad(frame.get(), 555); |
| 909 AddTransferableResource(frame.get(), 555); |
| 910 delegated_->SetFrameData(frame.Pass()); |
| 911 break; |
| 912 case 2: |
| 913 // The unused resource should be returned. |
| 914 delegated_->TakeUnusedResourcesForChildCompositor(&resources); |
| 915 EXPECT_EQ(1u, resources.size()); |
| 916 EXPECT_EQ(999, resources[0].id); |
| 917 |
| 918 endTest(); |
| 919 break; |
| 920 } |
| 921 } |
| 922 |
| 923 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 924 if (host_impl->activeTree()->source_frame_number() != 1) |
| 925 return; |
| 926 |
| 927 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); |
| 928 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 929 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 930 |
| 931 const ResourceProvider::ResourceIdMap& map = |
| 932 host_impl->resourceProvider()->getChildToParentMap( |
| 933 delegated_impl->ChildId()); |
| 934 |
| 935 // The layer only held on to the resource that was used. |
| 936 EXPECT_EQ(1u, map.size()); |
| 937 EXPECT_EQ(1u, map.count(555)); |
| 938 } |
| 939 |
| 940 virtual void afterTest() OVERRIDE {} |
| 941 }; |
| 942 |
| 943 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource) |
| 944 |
| 914 } // namespace | 945 } // namespace |
| 915 } // namespace cc | 946 } // namespace cc |
| OLD | NEW |