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" |
11 #include "cc/surfaces/surface_id.h" | 11 #include "cc/surfaces/surface_id.h" |
12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
13 #include "cc/test/begin_frame_args_test.h" | 13 #include "cc/test/begin_frame_args_test.h" |
14 #include "cc/test/fake_external_begin_frame_source.h" | 14 #include "cc/test/fake_external_begin_frame_source.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 using testing::UnorderedElementsAre; | 18 using testing::UnorderedElementsAre; |
19 using testing::IsEmpty; | 19 using testing::IsEmpty; |
20 using testing::SizeIs; | 20 using testing::SizeIs; |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 namespace test { | 23 namespace test { |
24 namespace { | 24 namespace { |
25 | 25 |
26 constexpr FrameSinkId kParentFrameSink(2, 1); | 26 constexpr FrameSinkId kDisplayFrameSink(2, 0); |
27 constexpr FrameSinkId kChildFrameSink1(65563, 1); | 27 constexpr FrameSinkId kParentFrameSink(3, 0); |
28 constexpr FrameSinkId kChildFrameSink2(65564, 1); | 28 constexpr FrameSinkId kChildFrameSink1(65563, 0); |
| 29 constexpr FrameSinkId kChildFrameSink2(65564, 0); |
29 constexpr FrameSinkId kArbitraryFrameSink(1337, 7331); | 30 constexpr FrameSinkId kArbitraryFrameSink(1337, 7331); |
30 | 31 |
31 std::vector<SurfaceId> empty_surface_ids() { | 32 std::vector<SurfaceId> empty_surface_ids() { |
32 return std::vector<SurfaceId>(); | 33 return std::vector<SurfaceId>(); |
33 } | 34 } |
34 | 35 |
35 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { | 36 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { |
36 return SurfaceId( | 37 return SurfaceId( |
37 frame_sink_id, | 38 frame_sink_id, |
38 LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); | 39 LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 71 |
71 } // namespace | 72 } // namespace |
72 | 73 |
73 class CompositorFrameSinkSupportTest : public testing::Test, | 74 class CompositorFrameSinkSupportTest : public testing::Test, |
74 public CompositorFrameSinkSupportClient { | 75 public CompositorFrameSinkSupportClient { |
75 public: | 76 public: |
76 CompositorFrameSinkSupportTest() | 77 CompositorFrameSinkSupportTest() |
77 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} | 78 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} |
78 ~CompositorFrameSinkSupportTest() override {} | 79 ~CompositorFrameSinkSupportTest() override {} |
79 | 80 |
80 CompositorFrameSinkSupport& parent_support() { return *supports_[0]; } | 81 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } |
| 82 |
| 83 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } |
81 Surface* parent_surface() { | 84 Surface* parent_surface() { |
82 return parent_support().current_surface_for_testing(); | 85 return parent_support().current_surface_for_testing(); |
83 } | 86 } |
84 const ReferencedSurfaceTracker& parent_reference_tracker() { | 87 const ReferencedSurfaceTracker& parent_reference_tracker() { |
85 return parent_support().ReferenceTrackerForTesting(); | 88 return parent_support().ReferenceTrackerForTesting(); |
86 } | 89 } |
87 | 90 |
88 CompositorFrameSinkSupport& child_support1() { return *supports_[1]; } | 91 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } |
89 Surface* child_surface1() { | 92 Surface* child_surface1() { |
90 return child_support1().current_surface_for_testing(); | 93 return child_support1().current_surface_for_testing(); |
91 } | 94 } |
92 | 95 |
93 CompositorFrameSinkSupport& child_support2() { return *supports_[2]; } | 96 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } |
94 Surface* child_surface2() { | 97 Surface* child_surface2() { |
95 return child_support2().current_surface_for_testing(); | 98 return child_support2().current_surface_for_testing(); |
96 } | 99 } |
97 | 100 |
98 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } | 101 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } |
99 Surface* surface(int index) { | 102 Surface* surface(int index) { |
100 return support(index).current_surface_for_testing(); | 103 return support(index).current_surface_for_testing(); |
101 } | 104 } |
102 | 105 |
103 SurfaceManager& surface_manager() { return surface_manager_; } | 106 SurfaceManager& surface_manager() { return surface_manager_; } |
(...skipping 25 matching lines...) Expand all Loading... |
129 // testing::Test: | 132 // testing::Test: |
130 void SetUp() override { | 133 void SetUp() override { |
131 testing::Test::SetUp(); | 134 testing::Test::SetUp(); |
132 begin_frame_source_ = | 135 begin_frame_source_ = |
133 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); | 136 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); |
134 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( | 137 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( |
135 new SurfaceDependencyTracker(&surface_manager_, | 138 new SurfaceDependencyTracker(&surface_manager_, |
136 begin_frame_source_.get())); | 139 begin_frame_source_.get())); |
137 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); | 140 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); |
138 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | 141 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
| 142 this, &surface_manager_, kDisplayFrameSink, true /* is_root */, |
| 143 true /* handles_frame_sink_id_invalidation */, |
| 144 true /* needs_sync_points */)); |
| 145 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
139 this, &surface_manager_, kParentFrameSink, false /* is_root */, | 146 this, &surface_manager_, kParentFrameSink, false /* is_root */, |
140 true /* handles_frame_sink_id_invalidation */, | 147 true /* handles_frame_sink_id_invalidation */, |
141 true /* needs_sync_points */)); | 148 true /* needs_sync_points */)); |
142 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | 149 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
143 this, &surface_manager_, kChildFrameSink1, false /* is_root */, | 150 this, &surface_manager_, kChildFrameSink1, false /* is_root */, |
144 true /* handles_frame_sink_id_invalidation */, | 151 true /* handles_frame_sink_id_invalidation */, |
145 true /* needs_sync_points */)); | 152 true /* needs_sync_points */)); |
146 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | 153 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
147 this, &surface_manager_, kChildFrameSink2, false /* is_root */, | 154 this, &surface_manager_, kChildFrameSink2, false /* is_root */, |
148 true /* handles_frame_sink_id_invalidation */, | 155 true /* handles_frame_sink_id_invalidation */, |
(...skipping 21 matching lines...) Expand all Loading... |
170 | 177 |
171 private: | 178 private: |
172 SurfaceManager surface_manager_; | 179 SurfaceManager surface_manager_; |
173 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; | 180 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; |
174 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; | 181 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; |
175 ReturnedResourceArray last_returned_resources_; | 182 ReturnedResourceArray last_returned_resources_; |
176 | 183 |
177 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); | 184 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); |
178 }; | 185 }; |
179 | 186 |
| 187 // The display root surface should have a surface reference from the top-level |
| 188 // root added/removed when a CompositorFrame is submitted with a new SurfaceId. |
| 189 TEST_F(CompositorFrameSinkSupportTest, RootSurfaceReceivesReferences) { |
| 190 const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1); |
| 191 const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2); |
| 192 |
| 193 // Submit a CompositorFrame for the first display root surface. |
| 194 display_support().SubmitCompositorFrame( |
| 195 display_id_first.local_surface_id(), |
| 196 MakeCompositorFrame({MakeSurfaceId(kParentFrameSink, 1)})); |
| 197 |
| 198 // A surface reference from the top-level root is added and there shouldn't be |
| 199 // a temporary reference. |
| 200 EXPECT_THAT(GetTempReferences(kDisplayFrameSink), IsEmpty()); |
| 201 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), |
| 202 UnorderedElementsAre(display_id_first)); |
| 203 |
| 204 // Submit a CompositorFrame for the second display root surface. |
| 205 display_support().SubmitCompositorFrame( |
| 206 display_id_second.local_surface_id(), |
| 207 MakeCompositorFrame({MakeSurfaceId(kParentFrameSink, 2)})); |
| 208 |
| 209 // A surface reference from the top-level root to |display_id_second| should |
| 210 // be added and the reference to |display_root_first| removed. |
| 211 EXPECT_THAT(GetTempReferences(kDisplayFrameSink), IsEmpty()); |
| 212 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), |
| 213 UnorderedElementsAre(display_id_second)); |
| 214 |
| 215 // Surface |display_id_first| is unreachable and should get deleted. |
| 216 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(display_id_first)); |
| 217 } |
| 218 |
180 // The parent Surface is blocked on |child_id1| and |child_id2|. | 219 // The parent Surface is blocked on |child_id1| and |child_id2|. |
181 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { | 220 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { |
182 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 221 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
183 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 222 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
184 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 223 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
185 | 224 |
186 parent_support().SubmitCompositorFrame( | 225 parent_support().SubmitCompositorFrame( |
187 parent_id.local_surface_id(), | 226 parent_id.local_surface_id(), |
188 MakeCompositorFrame({child_id1, child_id2})); | 227 MakeCompositorFrame({child_id1, child_id2})); |
189 | 228 |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 // CompositorFrame. Also verify that |child_id1| is no longer a child | 719 // CompositorFrame. Also verify that |child_id1| is no longer a child |
681 // reference of |parent_id|. | 720 // reference of |parent_id|. |
682 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 721 EXPECT_TRUE(parent_surface()->HasActiveFrame()); |
683 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 722 EXPECT_FALSE(parent_surface()->HasPendingFrame()); |
684 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty()); | 723 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty()); |
685 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); | 724 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); |
686 } | 725 } |
687 | 726 |
688 } // namespace test | 727 } // namespace test |
689 } // namespace cc | 728 } // namespace cc |
OLD | NEW |