| 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 678 |
| 679 // Verify that the parent Surface has activated and no longer has a pending | 679 // Verify that the parent Surface has activated and no longer has a pending |
| 680 // CompositorFrame. Also verify that |child_id1| is no longer a child | 680 // CompositorFrame. Also verify that |child_id1| is no longer a child |
| 681 // reference of |parent_id|. | 681 // reference of |parent_id|. |
| 682 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 682 EXPECT_TRUE(parent_surface()->HasActiveFrame()); |
| 683 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 683 EXPECT_FALSE(parent_surface()->HasPendingFrame()); |
| 684 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty()); | 684 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty()); |
| 685 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); | 685 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); |
| 686 } | 686 } |
| 687 | 687 |
| 688 // Checks whether the latency info are moved to the new surface from the old |
| 689 // one when LocalSurfaceId changes. No frame has unresolved dependencies. |
| 690 TEST_F(CompositorFrameSinkSupportTest, |
| 691 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { |
| 692 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 693 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 694 const ui::LatencyComponentType latency_type1 = |
| 695 ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 696 const int64_t latency_id1 = 234; |
| 697 const int64_t latency_sequence_number1 = 5645432; |
| 698 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 699 const int64_t latency_id2 = 31434351; |
| 700 const int64_t latency_sequence_number2 = 663788; |
| 701 |
| 702 // Submit a frame with latency info |
| 703 ui::LatencyInfo info; |
| 704 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); |
| 705 |
| 706 CompositorFrame frame; |
| 707 frame.metadata.latency_info.push_back(info); |
| 708 |
| 709 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 710 std::move(frame)); |
| 711 |
| 712 // Verify that the old surface has an active frame and no pending frame. |
| 713 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 714 ASSERT_NE(nullptr, old_surface); |
| 715 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 716 EXPECT_FALSE(old_surface->HasPendingFrame()); |
| 717 |
| 718 // Submit another frame with some other latency info and a different |
| 719 // LocalSurfaceId. |
| 720 ui::LatencyInfo info2; |
| 721 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); |
| 722 |
| 723 CompositorFrame frame2; |
| 724 frame2.metadata.latency_info.push_back(info2); |
| 725 |
| 726 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 727 std::move(frame2)); |
| 728 |
| 729 // Verify that the new surface has an active frame and no pending frames. |
| 730 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 731 ASSERT_NE(nullptr, surface); |
| 732 EXPECT_TRUE(surface->HasActiveFrame()); |
| 733 EXPECT_FALSE(surface->HasPendingFrame()); |
| 734 |
| 735 // Verify that the new surface has both latency info elements. |
| 736 std::vector<ui::LatencyInfo> info_list; |
| 737 surface->TakeLatencyInfo(&info_list); |
| 738 EXPECT_EQ(2u, info_list.size()); |
| 739 |
| 740 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 741 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 742 EXPECT_EQ(2u, aggregated_latency_info.latency_components().size()); |
| 743 |
| 744 ui::LatencyInfo::LatencyComponent comp1; |
| 745 EXPECT_TRUE( |
| 746 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 747 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); |
| 748 } |
| 749 |
| 750 // Checks whether the latency info are moved to the new surface from the old |
| 751 // one when LocalSurfaceId changes. Old surface has unresolved dependencies. |
| 752 TEST_F(CompositorFrameSinkSupportTest, |
| 753 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { |
| 754 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 755 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 756 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
| 757 |
| 758 const ui::LatencyComponentType latency_type1 = |
| 759 ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 760 const int64_t latency_id1 = 234; |
| 761 const int64_t latency_sequence_number1 = 5645432; |
| 762 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 763 const int64_t latency_id2 = 31434351; |
| 764 const int64_t latency_sequence_number2 = 663788; |
| 765 |
| 766 // Submit a frame with no unresolved dependecy. |
| 767 ui::LatencyInfo info; |
| 768 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); |
| 769 |
| 770 CompositorFrame frame; |
| 771 frame.metadata.latency_info.push_back(info); |
| 772 |
| 773 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 774 std::move(frame)); |
| 775 |
| 776 // Submit a frame with unresolved dependencies. |
| 777 ui::LatencyInfo info2; |
| 778 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); |
| 779 |
| 780 CompositorFrame frame2 = MakeCompositorFrame({child_id}); |
| 781 frame2.metadata.latency_info.push_back(info2); |
| 782 |
| 783 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 784 std::move(frame2)); |
| 785 |
| 786 // Verify that the old surface has both an active and a pending frame. |
| 787 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 788 ASSERT_NE(nullptr, old_surface); |
| 789 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 790 EXPECT_TRUE(old_surface->HasPendingFrame()); |
| 791 |
| 792 // Submit a frame with a new local surface id. |
| 793 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 794 CompositorFrame()); |
| 795 |
| 796 // Verify that the new surface has an active frame only. |
| 797 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 798 ASSERT_NE(nullptr, surface); |
| 799 EXPECT_TRUE(surface->HasActiveFrame()); |
| 800 EXPECT_FALSE(surface->HasPendingFrame()); |
| 801 |
| 802 // Verify that the new surface has latency info from both active and pending |
| 803 // frame of the old surface. |
| 804 std::vector<ui::LatencyInfo> info_list; |
| 805 surface->TakeLatencyInfo(&info_list); |
| 806 EXPECT_EQ(2u, info_list.size()); |
| 807 |
| 808 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 809 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 810 EXPECT_EQ(2u, aggregated_latency_info.latency_components().size()); |
| 811 |
| 812 ui::LatencyInfo::LatencyComponent comp1; |
| 813 EXPECT_TRUE( |
| 814 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 815 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); |
| 816 } |
| 817 |
| 818 // Checks whether the latency info are moved to the new surface from the old |
| 819 // one when LocalSurfaceId changes. The new surface has unresolved dependencies. |
| 820 TEST_F(CompositorFrameSinkSupportTest, |
| 821 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { |
| 822 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| 823 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
| 824 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
| 825 |
| 826 const ui::LatencyComponentType latency_type1 = |
| 827 ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT; |
| 828 const int64_t latency_id1 = 234; |
| 829 const int64_t latency_sequence_number1 = 5645432; |
| 830 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; |
| 831 const int64_t latency_id2 = 31434351; |
| 832 const int64_t latency_sequence_number2 = 663788; |
| 833 |
| 834 // Submit a frame with no unresolved dependencies. |
| 835 ui::LatencyInfo info; |
| 836 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); |
| 837 |
| 838 CompositorFrame frame; |
| 839 frame.metadata.latency_info.push_back(info); |
| 840 |
| 841 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), |
| 842 std::move(frame)); |
| 843 |
| 844 // Verify that the old surface has an active frame only. |
| 845 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); |
| 846 ASSERT_NE(nullptr, old_surface); |
| 847 EXPECT_TRUE(old_surface->HasActiveFrame()); |
| 848 EXPECT_FALSE(old_surface->HasPendingFrame()); |
| 849 |
| 850 // Submit a frame with a new local surface id and with unresolved |
| 851 // dependencies. |
| 852 ui::LatencyInfo info2; |
| 853 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); |
| 854 |
| 855 CompositorFrame frame2 = MakeCompositorFrame({child_id}); |
| 856 frame2.metadata.latency_info.push_back(info2); |
| 857 |
| 858 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), |
| 859 std::move(frame2)); |
| 860 |
| 861 // Verify that the new surface has a pending frame and no active frame. |
| 862 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); |
| 863 ASSERT_NE(nullptr, surface); |
| 864 EXPECT_TRUE(surface->HasPendingFrame()); |
| 865 EXPECT_FALSE(surface->HasActiveFrame()); |
| 866 |
| 867 // Resolve the dependencies. The frame in parent's surface must become active. |
| 868 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
| 869 CompositorFrame()); |
| 870 EXPECT_FALSE(surface->HasPendingFrame()); |
| 871 EXPECT_TRUE(surface->HasActiveFrame()); |
| 872 |
| 873 // Both latency info elements must exist in the now-activated frame of the |
| 874 // new surface. |
| 875 std::vector<ui::LatencyInfo> info_list; |
| 876 surface->TakeLatencyInfo(&info_list); |
| 877 EXPECT_EQ(2u, info_list.size()); |
| 878 |
| 879 ui::LatencyInfo aggregated_latency_info = info_list[0]; |
| 880 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); |
| 881 EXPECT_EQ(2u, aggregated_latency_info.latency_components().size()); |
| 882 |
| 883 ui::LatencyInfo::LatencyComponent comp1; |
| 884 EXPECT_TRUE( |
| 885 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); |
| 886 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); |
| 887 } |
| 888 |
| 688 } // namespace test | 889 } // namespace test |
| 689 } // namespace cc | 890 } // namespace cc |
| OLD | NEW |