| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/containers/flat_set.h" | 5 #include "base/containers/flat_set.h" |
| 6 #include "cc/surfaces/compositor_frame_sink_support.h" | 6 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 7 #include "cc/surfaces/surface_id.h" | 7 #include "cc/surfaces/surface_id.h" |
| 8 #include "cc/surfaces/surface_manager.h" | 8 #include "cc/surfaces/surface_manager.h" |
| 9 #include "cc/test/begin_frame_args_test.h" | 9 #include "cc/test/begin_frame_args_test.h" |
| 10 #include "cc/test/compositor_frame_helpers.h" | 10 #include "cc/test/compositor_frame_helpers.h" |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 777 |
| 778 // Checks whether the latency info are moved to the new surface from the old | 778 // Checks whether the latency info are moved to the new surface from the old |
| 779 // one when LocalSurfaceId changes. No frame has unresolved dependencies. | 779 // one when LocalSurfaceId changes. No frame has unresolved dependencies. |
| 780 TEST_F(SurfaceSynchronizationTest, | 780 TEST_F(SurfaceSynchronizationTest, |
| 781 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { | 781 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { |
| 782 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | 782 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 783 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | 783 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 784 const ui::LatencyComponentType latency_type1 = | 784 const ui::LatencyComponentType latency_type1 = |
| 785 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; | 785 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 786 const int64_t latency_id1 = 234; | 786 const int64_t latency_id1 = 234; |
| 787 const int64_t latency_sequence_number1 = 5645432; | |
| 788 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; | 787 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 789 const int64_t latency_id2 = 31434351; | 788 const int64_t latency_id2 = 31434351; |
| 790 const int64_t latency_sequence_number2 = 663788; | |
| 791 | 789 |
| 792 // Submit a frame with latency info | 790 // Submit a frame with latency info |
| 793 ui::LatencyInfo info; | 791 ui::LatencyInfo info; |
| 794 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); | 792 info.AddLatencyNumber(latency_type1, latency_id1); |
| 795 | 793 |
| 796 CompositorFrame frame = MakeCompositorFrame(); | 794 CompositorFrame frame = MakeCompositorFrame(); |
| 797 frame.metadata.latency_info.push_back(info); | 795 frame.metadata.latency_info.push_back(info); |
| 798 | 796 |
| 799 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 797 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 800 std::move(frame)); | 798 std::move(frame)); |
| 801 | 799 |
| 802 // Verify that the old surface has an active frame and no pending frame. | 800 // Verify that the old surface has an active frame and no pending frame. |
| 803 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 801 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 804 ASSERT_NE(nullptr, old_surface); | 802 ASSERT_NE(nullptr, old_surface); |
| 805 EXPECT_TRUE(old_surface->HasActiveFrame()); | 803 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 806 EXPECT_FALSE(old_surface->HasPendingFrame()); | 804 EXPECT_FALSE(old_surface->HasPendingFrame()); |
| 807 | 805 |
| 808 // Submit another frame with some other latency info and a different | 806 // Submit another frame with some other latency info and a different |
| 809 // LocalSurfaceId. | 807 // LocalSurfaceId. |
| 810 ui::LatencyInfo info2; | 808 ui::LatencyInfo info2; |
| 811 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 809 info2.AddLatencyNumber(latency_type2, latency_id2); |
| 812 | 810 |
| 813 CompositorFrame frame2 = MakeCompositorFrame(); | 811 CompositorFrame frame2 = MakeCompositorFrame(); |
| 814 frame2.metadata.latency_info.push_back(info2); | 812 frame2.metadata.latency_info.push_back(info2); |
| 815 | 813 |
| 816 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 814 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 817 std::move(frame2)); | 815 std::move(frame2)); |
| 818 | 816 |
| 819 // Verify that the new surface has an active frame and no pending frames. | 817 // Verify that the new surface has an active frame and no pending frames. |
| 820 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 818 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 821 ASSERT_NE(nullptr, surface); | 819 ASSERT_NE(nullptr, surface); |
| 822 EXPECT_TRUE(surface->HasActiveFrame()); | 820 EXPECT_TRUE(surface->HasActiveFrame()); |
| 823 EXPECT_FALSE(surface->HasPendingFrame()); | 821 EXPECT_FALSE(surface->HasPendingFrame()); |
| 824 | 822 |
| 825 // Verify that the new surface has both latency info elements. | 823 // Verify that the new surface has both latency info elements. |
| 826 std::vector<ui::LatencyInfo> info_list; | 824 std::vector<ui::LatencyInfo> info_list; |
| 827 surface->TakeLatencyInfo(&info_list); | 825 surface->TakeLatencyInfo(&info_list); |
| 828 EXPECT_EQ(2u, info_list.size()); | 826 EXPECT_EQ(2u, info_list.size()); |
| 829 | 827 |
| 830 ui::LatencyInfo aggregated_latency_info = info_list[0]; | 828 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 831 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | 829 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 832 | 830 |
| 833 // Two components are the original ones, and the third one is | 831 // Two components are the original ones, and the third one is |
| 834 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | 832 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame |
| 835 // submit. | 833 // submit. |
| 836 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | 834 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); |
| 837 | 835 |
| 838 ui::LatencyInfo::LatencyComponent comp1; | 836 ui::LatencyInfo::LatencyComponent comp1; |
| 839 EXPECT_TRUE( | 837 EXPECT_TRUE( |
| 840 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | 838 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 841 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | |
| 842 EXPECT_TRUE( | 839 EXPECT_TRUE( |
| 843 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | 840 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); |
| 844 EXPECT_TRUE(aggregated_latency_info.FindLatency( | 841 EXPECT_TRUE(aggregated_latency_info.FindLatency( |
| 845 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | 842 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); |
| 846 } | 843 } |
| 847 | 844 |
| 848 // Checks whether the latency info are moved to the new surface from the old | 845 // Checks whether the latency info are moved to the new surface from the old |
| 849 // one when LocalSurfaceId changes. Old surface has unresolved dependencies. | 846 // one when LocalSurfaceId changes. Old surface has unresolved dependencies. |
| 850 TEST_F(SurfaceSynchronizationTest, | 847 TEST_F(SurfaceSynchronizationTest, |
| 851 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { | 848 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { |
| 852 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | 849 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 853 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | 850 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 854 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | 851 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
| 855 | 852 |
| 856 const ui::LatencyComponentType latency_type1 = | 853 const ui::LatencyComponentType latency_type1 = |
| 857 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; | 854 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 858 const int64_t latency_id1 = 234; | 855 const int64_t latency_id1 = 234; |
| 859 const int64_t latency_sequence_number1 = 5645432; | |
| 860 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; | 856 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 861 const int64_t latency_id2 = 31434351; | 857 const int64_t latency_id2 = 31434351; |
| 862 const int64_t latency_sequence_number2 = 663788; | |
| 863 | 858 |
| 864 // Submit a frame with no unresolved dependecy. | 859 // Submit a frame with no unresolved dependecy. |
| 865 ui::LatencyInfo info; | 860 ui::LatencyInfo info; |
| 866 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); | 861 info.AddLatencyNumber(latency_type1, latency_id1); |
| 867 | 862 |
| 868 CompositorFrame frame = MakeCompositorFrame(); | 863 CompositorFrame frame = MakeCompositorFrame(); |
| 869 frame.metadata.latency_info.push_back(info); | 864 frame.metadata.latency_info.push_back(info); |
| 870 | 865 |
| 871 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 866 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 872 std::move(frame)); | 867 std::move(frame)); |
| 873 | 868 |
| 874 // Submit a frame with unresolved dependencies. | 869 // Submit a frame with unresolved dependencies. |
| 875 ui::LatencyInfo info2; | 870 ui::LatencyInfo info2; |
| 876 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 871 info2.AddLatencyNumber(latency_type2, latency_id2); |
| 877 | 872 |
| 878 CompositorFrame frame2 = MakeCompositorFrame({child_id}, empty_surface_ids(), | 873 CompositorFrame frame2 = MakeCompositorFrame({child_id}, empty_surface_ids(), |
| 879 TransferableResourceArray()); | 874 TransferableResourceArray()); |
| 880 frame2.metadata.latency_info.push_back(info2); | 875 frame2.metadata.latency_info.push_back(info2); |
| 881 | 876 |
| 882 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 877 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 883 std::move(frame2)); | 878 std::move(frame2)); |
| 884 | 879 |
| 885 // Verify that the old surface has both an active and a pending frame. | 880 // Verify that the old surface has both an active and a pending frame. |
| 886 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 881 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 908 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | 903 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 909 | 904 |
| 910 // Two components are the original ones, and the third one is | 905 // Two components are the original ones, and the third one is |
| 911 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | 906 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame |
| 912 // submit. | 907 // submit. |
| 913 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | 908 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); |
| 914 | 909 |
| 915 ui::LatencyInfo::LatencyComponent comp1; | 910 ui::LatencyInfo::LatencyComponent comp1; |
| 916 EXPECT_TRUE( | 911 EXPECT_TRUE( |
| 917 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | 912 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 918 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | |
| 919 EXPECT_TRUE( | 913 EXPECT_TRUE( |
| 920 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | 914 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); |
| 921 EXPECT_TRUE(aggregated_latency_info.FindLatency( | 915 EXPECT_TRUE(aggregated_latency_info.FindLatency( |
| 922 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | 916 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); |
| 923 } | 917 } |
| 924 | 918 |
| 925 // Checks whether the latency info are moved to the new surface from the old | 919 // Checks whether the latency info are moved to the new surface from the old |
| 926 // one when LocalSurfaceId changes. The new surface has unresolved dependencies. | 920 // one when LocalSurfaceId changes. The new surface has unresolved dependencies. |
| 927 TEST_F(SurfaceSynchronizationTest, | 921 TEST_F(SurfaceSynchronizationTest, |
| 928 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { | 922 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { |
| 929 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | 923 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 930 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | 924 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 931 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | 925 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
| 932 | 926 |
| 933 const ui::LatencyComponentType latency_type1 = | 927 const ui::LatencyComponentType latency_type1 = |
| 934 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; | 928 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 935 const int64_t latency_id1 = 234; | 929 const int64_t latency_id1 = 234; |
| 936 const int64_t latency_sequence_number1 = 5645432; | |
| 937 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; | 930 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 938 const int64_t latency_id2 = 31434351; | 931 const int64_t latency_id2 = 31434351; |
| 939 const int64_t latency_sequence_number2 = 663788; | |
| 940 | 932 |
| 941 // Submit a frame with no unresolved dependencies. | 933 // Submit a frame with no unresolved dependencies. |
| 942 ui::LatencyInfo info; | 934 ui::LatencyInfo info; |
| 943 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); | 935 info.AddLatencyNumber(latency_type1, latency_id1); |
| 944 | 936 |
| 945 CompositorFrame frame = MakeCompositorFrame(); | 937 CompositorFrame frame = MakeCompositorFrame(); |
| 946 frame.metadata.latency_info.push_back(info); | 938 frame.metadata.latency_info.push_back(info); |
| 947 | 939 |
| 948 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 940 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 949 std::move(frame)); | 941 std::move(frame)); |
| 950 | 942 |
| 951 // Verify that the old surface has an active frame only. | 943 // Verify that the old surface has an active frame only. |
| 952 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 944 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 953 ASSERT_NE(nullptr, old_surface); | 945 ASSERT_NE(nullptr, old_surface); |
| 954 EXPECT_TRUE(old_surface->HasActiveFrame()); | 946 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 955 EXPECT_FALSE(old_surface->HasPendingFrame()); | 947 EXPECT_FALSE(old_surface->HasPendingFrame()); |
| 956 | 948 |
| 957 // Submit a frame with a new local surface id and with unresolved | 949 // Submit a frame with a new local surface id and with unresolved |
| 958 // dependencies. | 950 // dependencies. |
| 959 ui::LatencyInfo info2; | 951 ui::LatencyInfo info2; |
| 960 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 952 info2.AddLatencyNumber(latency_type2, latency_id2); |
| 961 | 953 |
| 962 CompositorFrame frame2 = MakeCompositorFrame({child_id}, empty_surface_ids(), | 954 CompositorFrame frame2 = MakeCompositorFrame({child_id}, empty_surface_ids(), |
| 963 TransferableResourceArray()); | 955 TransferableResourceArray()); |
| 964 frame2.metadata.latency_info.push_back(info2); | 956 frame2.metadata.latency_info.push_back(info2); |
| 965 | 957 |
| 966 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 958 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 967 std::move(frame2)); | 959 std::move(frame2)); |
| 968 | 960 |
| 969 // Verify that the new surface has a pending frame and no active frame. | 961 // Verify that the new surface has a pending frame and no active frame. |
| 970 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 962 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 988 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | 980 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 989 | 981 |
| 990 // Two components are the original ones, and the third one is | 982 // Two components are the original ones, and the third one is |
| 991 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | 983 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame |
| 992 // submit. | 984 // submit. |
| 993 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | 985 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); |
| 994 | 986 |
| 995 ui::LatencyInfo::LatencyComponent comp1; | 987 ui::LatencyInfo::LatencyComponent comp1; |
| 996 EXPECT_TRUE( | 988 EXPECT_TRUE( |
| 997 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | 989 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 998 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | |
| 999 EXPECT_TRUE( | 990 EXPECT_TRUE( |
| 1000 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | 991 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); |
| 1001 EXPECT_TRUE(aggregated_latency_info.FindLatency( | 992 EXPECT_TRUE(aggregated_latency_info.FindLatency( |
| 1002 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | 993 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); |
| 1003 } | 994 } |
| 1004 | 995 |
| 1005 // Checks that resources and ack are sent together if possible. | 996 // Checks that resources and ack are sent together if possible. |
| 1006 TEST_F(SurfaceSynchronizationTest, ReturnResourcesWithAck) { | 997 TEST_F(SurfaceSynchronizationTest, ReturnResourcesWithAck) { |
| 1007 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 998 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
| 1008 TransferableResource resource; | 999 TransferableResource resource; |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 DidReceiveCompositorFrameAck(Eq(returned_resources2))); | 1368 DidReceiveCompositorFrameAck(Eq(returned_resources2))); |
| 1378 child_support1().SubmitCompositorFrame( | 1369 child_support1().SubmitCompositorFrame( |
| 1379 child_id1.local_surface_id(), | 1370 child_id1.local_surface_id(), |
| 1380 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), | 1371 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), |
| 1381 {resource2})); | 1372 {resource2})); |
| 1382 testing::Mock::VerifyAndClearExpectations(&support_client_); | 1373 testing::Mock::VerifyAndClearExpectations(&support_client_); |
| 1383 } | 1374 } |
| 1384 | 1375 |
| 1385 } // namespace test | 1376 } // namespace test |
| 1386 } // namespace cc | 1377 } // namespace cc |
| OLD | NEW |