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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 class SurfaceSynchronizationTest : public testing::Test { | 70 class SurfaceSynchronizationTest : public testing::Test { |
71 public: | 71 public: |
72 SurfaceSynchronizationTest() | 72 SurfaceSynchronizationTest() |
73 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES), | 73 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES), |
74 surface_observer_(false) {} | 74 surface_observer_(false) {} |
75 ~SurfaceSynchronizationTest() override {} | 75 ~SurfaceSynchronizationTest() override {} |
76 | 76 |
77 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } | 77 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } |
78 Surface* display_surface() { | 78 Surface* display_surface() { |
79 return display_support().current_surface_for_testing(); | 79 return display_support().GetCurrentSurfaceForTesting(); |
80 } | 80 } |
81 | 81 |
82 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } | 82 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } |
83 Surface* parent_surface() { | 83 Surface* parent_surface() { |
84 return parent_support().current_surface_for_testing(); | 84 return parent_support().GetCurrentSurfaceForTesting(); |
85 } | 85 } |
86 | 86 |
87 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } | 87 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } |
88 Surface* child_surface1() { | 88 Surface* child_surface1() { |
89 return child_support1().current_surface_for_testing(); | 89 return child_support1().GetCurrentSurfaceForTesting(); |
90 } | 90 } |
91 | 91 |
92 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } | 92 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } |
93 Surface* child_surface2() { | 93 Surface* child_surface2() { |
94 return child_support2().current_surface_for_testing(); | 94 return child_support2().GetCurrentSurfaceForTesting(); |
95 } | 95 } |
96 | 96 |
97 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } | 97 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } |
98 Surface* surface(int index) { | 98 Surface* surface(int index) { |
99 return support(index).current_surface_for_testing(); | 99 return support(index).GetCurrentSurfaceForTesting(); |
100 } | 100 } |
101 | 101 |
102 SurfaceManager& surface_manager() { return surface_manager_; } | 102 SurfaceManager& surface_manager() { return surface_manager_; } |
103 | 103 |
104 // Returns all the references where |surface_id| is the parent. | 104 // Returns all the references where |surface_id| is the parent. |
105 const base::flat_set<SurfaceId>& GetChildReferences( | 105 const base::flat_set<SurfaceId>& GetChildReferences( |
106 const SurfaceId& surface_id) { | 106 const SurfaceId& surface_id) { |
107 return surface_manager().GetSurfacesReferencedByParent(surface_id); | 107 return surface_manager().GetSurfacesReferencedByParent(surface_id); |
108 } | 108 } |
109 | 109 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // SurfaceDependencyTracker depends on this BeginFrameSource and so it must | 170 // SurfaceDependencyTracker depends on this BeginFrameSource and so it must |
171 // be destroyed AFTER the dependency tracker is destroyed. | 171 // be destroyed AFTER the dependency tracker is destroyed. |
172 begin_frame_source_->SetClient(nullptr); | 172 begin_frame_source_->SetClient(nullptr); |
173 begin_frame_source_.reset(); | 173 begin_frame_source_.reset(); |
174 | 174 |
175 supports_.clear(); | 175 supports_.clear(); |
176 | 176 |
177 surface_observer_.Reset(); | 177 surface_observer_.Reset(); |
178 } | 178 } |
179 | 179 |
| 180 bool IsMarkedForDestruction(const SurfaceId& surface_id) { |
| 181 return surface_manager_.IsMarkedForDestruction(surface_id); |
| 182 } |
| 183 |
180 protected: | 184 protected: |
181 testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_; | 185 testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_; |
182 | 186 |
183 private: | 187 private: |
184 SurfaceManager surface_manager_; | 188 SurfaceManager surface_manager_; |
185 FakeSurfaceObserver surface_observer_; | 189 FakeSurfaceObserver surface_observer_; |
186 FakeExternalBeginFrameSourceClient begin_frame_source_client_; | 190 FakeExternalBeginFrameSourceClient begin_frame_source_client_; |
187 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; | 191 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; |
188 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_; | 192 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_; |
189 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; | 193 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 // Add a reference from the parent to the child. | 1038 // Add a reference from the parent to the child. |
1035 parent_support().SubmitCompositorFrame( | 1039 parent_support().SubmitCompositorFrame( |
1036 parent_id.local_surface_id(), | 1040 parent_id.local_surface_id(), |
1037 MakeCompositorFrame({child_id}, {child_id}, TransferableResourceArray())); | 1041 MakeCompositorFrame({child_id}, {child_id}, TransferableResourceArray())); |
1038 | 1042 |
1039 // Attempt to destroy the child surface. The surface must still exist since | 1043 // Attempt to destroy the child surface. The surface must still exist since |
1040 // the parent needs it but it will be marked as destroyed. | 1044 // the parent needs it but it will be marked as destroyed. |
1041 child_support1().EvictCurrentSurface(); | 1045 child_support1().EvictCurrentSurface(); |
1042 surface = surface_manager().GetSurfaceForId(child_id); | 1046 surface = surface_manager().GetSurfaceForId(child_id); |
1043 EXPECT_NE(nullptr, surface); | 1047 EXPECT_NE(nullptr, surface); |
1044 EXPECT_TRUE(surface->destroyed()); | 1048 EXPECT_TRUE(IsMarkedForDestruction(child_id)); |
1045 | 1049 |
1046 // Child submits another frame to the same local surface id that is marked | 1050 // Child submits another frame to the same local surface id that is marked |
1047 // destroyed. | 1051 // destroyed. |
1048 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 1052 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
1049 MakeCompositorFrame()); | 1053 MakeCompositorFrame()); |
1050 | 1054 |
1051 // Verify that the surface that was marked destroyed is recovered and is being | 1055 // Verify that the surface that was marked destroyed is recovered and is being |
1052 // used again. | 1056 // used again. |
1053 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); | 1057 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); |
1054 EXPECT_EQ(surface, surface2); | 1058 EXPECT_EQ(surface, surface2); |
1055 EXPECT_FALSE(surface2->destroyed()); | 1059 EXPECT_FALSE(IsMarkedForDestruction(child_id)); |
1056 } | 1060 } |
1057 | 1061 |
1058 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist | 1062 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist |
1059 // anymore, it can still be reused for new surfaces. | 1063 // anymore, it can still be reused for new surfaces. |
1060 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { | 1064 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { |
1061 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 1065 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
1062 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); | 1066 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); |
1063 | 1067 |
1064 // Submit the first frame. Creates the surface. | 1068 // Submit the first frame. Creates the surface. |
1065 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 1069 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 DidReceiveCompositorFrameAck(Eq(returned_resources2))); | 1377 DidReceiveCompositorFrameAck(Eq(returned_resources2))); |
1374 child_support1().SubmitCompositorFrame( | 1378 child_support1().SubmitCompositorFrame( |
1375 child_id1.local_surface_id(), | 1379 child_id1.local_surface_id(), |
1376 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), | 1380 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), |
1377 {resource2})); | 1381 {resource2})); |
1378 testing::Mock::VerifyAndClearExpectations(&support_client_); | 1382 testing::Mock::VerifyAndClearExpectations(&support_client_); |
1379 } | 1383 } |
1380 | 1384 |
1381 } // namespace test | 1385 } // namespace test |
1382 } // namespace cc | 1386 } // namespace cc |
OLD | NEW |