| 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 "cc/surfaces/compositor_frame_sink_support.h" | 5 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 10 #include "cc/surfaces/frame_sink_id.h" | 10 #include "cc/surfaces/frame_sink_id.h" |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 716 |
| 717 // Verify that the parent Surface has activated and no longer has a pending | 717 // Verify that the parent Surface has activated and no longer has a pending |
| 718 // CompositorFrame. Also verify that |child_id1| is no longer a child | 718 // CompositorFrame. Also verify that |child_id1| is no longer a child |
| 719 // reference of |parent_id|. | 719 // reference of |parent_id|. |
| 720 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 720 EXPECT_TRUE(parent_surface()->HasActiveFrame()); |
| 721 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 721 EXPECT_FALSE(parent_surface()->HasPendingFrame()); |
| 722 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty()); | 722 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty()); |
| 723 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); | 723 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); |
| 724 } | 724 } |
| 725 | 725 |
| 726 // Checks whether the latency info are moved to the new surface from the old |
| 727 // one when LocalSurfaceId changes. No frame has unresolved dependencies. |
| 728 TEST_F(CompositorFrameSinkSupportTest, |
| 729 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { |
| 730 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 731 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 732 const ui::LatencyComponentType latency_type1 = |
| 733 ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 734 const int64_t latency_id1 = 234; |
| 735 const int64_t latency_sequence_number1 = 5645432; |
| 736 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 737 const int64_t latency_id2 = 31434351; |
| 738 const int64_t latency_sequence_number2 = 663788; |
| 739 |
| 740 // Submit a frame with latency info |
| 741 ui::LatencyInfo info; |
| 742 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); |
| 743 |
| 744 CompositorFrame frame; |
| 745 frame.metadata.latency_info.push_back(info); |
| 746 |
| 747 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 748 std::move(frame)); |
| 749 |
| 750 // Verify that the old surface has an active frame and no pending frame. |
| 751 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 752 ASSERT_NE(nullptr, old_surface); |
| 753 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 754 EXPECT_FALSE(old_surface->HasPendingFrame()); |
| 755 |
| 756 // Submit another frame with some other latency info and a different |
| 757 // LocalSurfaceId. |
| 758 ui::LatencyInfo info2; |
| 759 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); |
| 760 |
| 761 CompositorFrame frame2; |
| 762 frame2.metadata.latency_info.push_back(info2); |
| 763 |
| 764 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 765 std::move(frame2)); |
| 766 |
| 767 // Verify that the new surface has an active frame and no pending frames. |
| 768 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 769 ASSERT_NE(nullptr, surface); |
| 770 EXPECT_TRUE(surface->HasActiveFrame()); |
| 771 EXPECT_FALSE(surface->HasPendingFrame()); |
| 772 |
| 773 // Verify that the new surface has both latency info elements. |
| 774 std::vector<ui::LatencyInfo> info_list; |
| 775 surface->TakeLatencyInfo(&info_list); |
| 776 EXPECT_EQ(2u, info_list.size()); |
| 777 |
| 778 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 779 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 780 EXPECT_EQ(2u, aggregated_latency_info.latency_components().size()); |
| 781 |
| 782 ui::LatencyInfo::LatencyComponent comp1; |
| 783 EXPECT_TRUE( |
| 784 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 785 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); |
| 786 } |
| 787 |
| 788 // Checks whether the latency info are moved to the new surface from the old |
| 789 // one when LocalSurfaceId changes. Old surface has unresolved dependencies. |
| 790 TEST_F(CompositorFrameSinkSupportTest, |
| 791 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { |
| 792 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 793 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 794 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
| 795 |
| 796 const ui::LatencyComponentType latency_type1 = |
| 797 ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 798 const int64_t latency_id1 = 234; |
| 799 const int64_t latency_sequence_number1 = 5645432; |
| 800 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 801 const int64_t latency_id2 = 31434351; |
| 802 const int64_t latency_sequence_number2 = 663788; |
| 803 |
| 804 // Submit a frame with no unresolved dependecy. |
| 805 ui::LatencyInfo info; |
| 806 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); |
| 807 |
| 808 CompositorFrame frame; |
| 809 frame.metadata.latency_info.push_back(info); |
| 810 |
| 811 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 812 std::move(frame)); |
| 813 |
| 814 // Submit a frame with unresolved dependencies. |
| 815 ui::LatencyInfo info2; |
| 816 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); |
| 817 |
| 818 CompositorFrame frame2 = MakeCompositorFrame({child_id}); |
| 819 frame2.metadata.latency_info.push_back(info2); |
| 820 |
| 821 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 822 std::move(frame2)); |
| 823 |
| 824 // Verify that the old surface has both an active and a pending frame. |
| 825 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 826 ASSERT_NE(nullptr, old_surface); |
| 827 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 828 EXPECT_TRUE(old_surface->HasPendingFrame()); |
| 829 |
| 830 // Submit a frame with a new local surface id. |
| 831 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 832 CompositorFrame()); |
| 833 |
| 834 // Verify that the new surface has an active frame only. |
| 835 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 836 ASSERT_NE(nullptr, surface); |
| 837 EXPECT_TRUE(surface->HasActiveFrame()); |
| 838 EXPECT_FALSE(surface->HasPendingFrame()); |
| 839 |
| 840 // Verify that the new surface has latency info from both active and pending |
| 841 // frame of the old surface. |
| 842 std::vector<ui::LatencyInfo> info_list; |
| 843 surface->TakeLatencyInfo(&info_list); |
| 844 EXPECT_EQ(2u, info_list.size()); |
| 845 |
| 846 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 847 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 848 EXPECT_EQ(2u, aggregated_latency_info.latency_components().size()); |
| 849 |
| 850 ui::LatencyInfo::LatencyComponent comp1; |
| 851 EXPECT_TRUE( |
| 852 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 853 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); |
| 854 } |
| 855 |
| 856 // Checks whether the latency info are moved to the new surface from the old |
| 857 // one when LocalSurfaceId changes. The new surface has unresolved dependencies. |
| 858 TEST_F(CompositorFrameSinkSupportTest, |
| 859 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { |
| 860 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 861 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 862 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
| 863 |
| 864 const ui::LatencyComponentType latency_type1 = |
| 865 ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 866 const int64_t latency_id1 = 234; |
| 867 const int64_t latency_sequence_number1 = 5645432; |
| 868 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 869 const int64_t latency_id2 = 31434351; |
| 870 const int64_t latency_sequence_number2 = 663788; |
| 871 |
| 872 // Submit a frame with no unresolved dependencies. |
| 873 ui::LatencyInfo info; |
| 874 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); |
| 875 |
| 876 CompositorFrame frame; |
| 877 frame.metadata.latency_info.push_back(info); |
| 878 |
| 879 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 880 std::move(frame)); |
| 881 |
| 882 // Verify that the old surface has an active frame only. |
| 883 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 884 ASSERT_NE(nullptr, old_surface); |
| 885 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 886 EXPECT_FALSE(old_surface->HasPendingFrame()); |
| 887 |
| 888 // Submit a frame with a new local surface id and with unresolved |
| 889 // dependencies. |
| 890 ui::LatencyInfo info2; |
| 891 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); |
| 892 |
| 893 CompositorFrame frame2 = MakeCompositorFrame({child_id}); |
| 894 frame2.metadata.latency_info.push_back(info2); |
| 895 |
| 896 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 897 std::move(frame2)); |
| 898 |
| 899 // Verify that the new surface has a pending frame and no active frame. |
| 900 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 901 ASSERT_NE(nullptr, surface); |
| 902 EXPECT_TRUE(surface->HasPendingFrame()); |
| 903 EXPECT_FALSE(surface->HasActiveFrame()); |
| 904 |
| 905 // Resolve the dependencies. The frame in parent's surface must become active. |
| 906 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
| 907 CompositorFrame()); |
| 908 EXPECT_FALSE(surface->HasPendingFrame()); |
| 909 EXPECT_TRUE(surface->HasActiveFrame()); |
| 910 |
| 911 // Both latency info elements must exist in the now-activated frame of the |
| 912 // new surface. |
| 913 std::vector<ui::LatencyInfo> info_list; |
| 914 surface->TakeLatencyInfo(&info_list); |
| 915 EXPECT_EQ(2u, info_list.size()); |
| 916 |
| 917 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 918 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 919 EXPECT_EQ(2u, aggregated_latency_info.latency_components().size()); |
| 920 |
| 921 ui::LatencyInfo::LatencyComponent comp1; |
| 922 EXPECT_TRUE( |
| 923 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 924 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); |
| 925 } |
| 926 |
| 726 } // namespace test | 927 } // namespace test |
| 727 } // namespace cc | 928 } // namespace cc |
| OLD | NEW |