| 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/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 10 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 SurfaceDependencyTracker& dependency_tracker() { | 161 SurfaceDependencyTracker& dependency_tracker() { |
| 162 return *surface_manager_.dependency_tracker(); | 162 return *surface_manager_.dependency_tracker(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 FakeExternalBeginFrameSource* begin_frame_source() { | 165 FakeExternalBeginFrameSource* begin_frame_source() { |
| 166 return begin_frame_source_.get(); | 166 return begin_frame_source_.get(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 std::unique_ptr<CompositorFrameSinkSupport> CreateCompositorFrameSinkSupport( | |
| 170 FrameSinkId frame_sink_id, | |
| 171 bool is_root = false) { | |
| 172 return base::MakeUnique<CompositorFrameSinkSupport>( | |
| 173 &support_client_, &surface_manager_, frame_sink_id, is_root, | |
| 174 true /* handles_frame_sink_id_invalidation */, | |
| 175 true /* needs_sync_points */); | |
| 176 } | |
| 177 | |
| 178 // testing::Test: | 169 // testing::Test: |
| 179 void SetUp() override { | 170 void SetUp() override { |
| 180 testing::Test::SetUp(); | 171 testing::Test::SetUp(); |
| 181 begin_frame_source_ = | 172 begin_frame_source_ = |
| 182 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); | 173 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); |
| 183 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( | 174 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( |
| 184 new SurfaceDependencyTracker(&surface_manager_, | 175 new SurfaceDependencyTracker(&surface_manager_, |
| 185 begin_frame_source_.get())); | 176 begin_frame_source_.get())); |
| 186 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); | 177 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); |
| 187 supports_.push_back(CreateCompositorFrameSinkSupport(kDisplayFrameSink, | 178 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
| 188 true /* is_root */)); | 179 &support_client_, &surface_manager_, kDisplayFrameSink, |
| 189 supports_.push_back(CreateCompositorFrameSinkSupport(kParentFrameSink)); | 180 true /* is_root */, true /* handles_frame_sink_id_invalidation */, |
| 190 supports_.push_back(CreateCompositorFrameSinkSupport(kChildFrameSink1)); | 181 true /* needs_sync_points */)); |
| 191 supports_.push_back(CreateCompositorFrameSinkSupport(kChildFrameSink2)); | 182 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
| 183 &support_client_, &surface_manager_, kParentFrameSink, |
| 184 false /* is_root */, true /* handles_frame_sink_id_invalidation */, |
| 185 true /* needs_sync_points */)); |
| 186 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
| 187 &support_client_, &surface_manager_, kChildFrameSink1, |
| 188 false /* is_root */, true /* handles_frame_sink_id_invalidation */, |
| 189 true /* needs_sync_points */)); |
| 190 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( |
| 191 &support_client_, &surface_manager_, kChildFrameSink2, |
| 192 false /* is_root */, true /* handles_frame_sink_id_invalidation */, |
| 193 true /* needs_sync_points */)); |
| 194 |
| 192 // Normally, the BeginFrameSource would be registered by the Display. We | 195 // Normally, the BeginFrameSource would be registered by the Display. We |
| 193 // register it here so that BeginFrames are received by the display support, | 196 // register it here so that BeginFrames are received by the display support, |
| 194 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive | 197 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive |
| 195 // BeginFrames, since the frame sink hierarchy is not set up in this test. | 198 // BeginFrames, since the frame sink hierarchy is not set up in this test. |
| 196 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(), | 199 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(), |
| 197 kDisplayFrameSink); | 200 kDisplayFrameSink); |
| 198 } | 201 } |
| 199 | 202 |
| 200 void TearDown() override { | 203 void TearDown() override { |
| 201 surface_manager_.SetDependencyTracker(nullptr); | 204 surface_manager_.SetDependencyTracker(nullptr); |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 child_support1().EvictFrame(); | 1060 child_support1().EvictFrame(); |
| 1058 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); | 1061 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); |
| 1059 | 1062 |
| 1060 // Submit another frame with the same local surface id. This should work fine | 1063 // Submit another frame with the same local surface id. This should work fine |
| 1061 // and a new surface must be created. | 1064 // and a new surface must be created. |
| 1062 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 1065 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
| 1063 MakeCompositorFrame()); | 1066 MakeCompositorFrame()); |
| 1064 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); | 1067 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); |
| 1065 } | 1068 } |
| 1066 | 1069 |
| 1067 // Checks whether a LocalSurfaceId can be reused after the | |
| 1068 // CompositorFrameSinkSupport is destroyed and recreated with the same | |
| 1069 // FrameSinkId. | |
| 1070 TEST_F(CompositorFrameSinkSupportTest, ReuseSurfaceAfterSupportDestroyed) { | |
| 1071 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | |
| 1072 const SurfaceId child_id = MakeSurfaceId(kArbitraryFrameSink, 1); | |
| 1073 std::unique_ptr<CompositorFrameSinkSupport> child_support = | |
| 1074 CreateCompositorFrameSinkSupport(kArbitraryFrameSink); | |
| 1075 | |
| 1076 // Add a reference from parent to child to preserve the child surface. | |
| 1077 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 1078 MakeCompositorFrame({child_id})); | |
| 1079 | |
| 1080 // Submit the first frame. A surface must be created. | |
| 1081 child_support->SubmitCompositorFrame( | |
| 1082 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 1083 Surface* surface = surface_manager().GetSurfaceForId(child_id); | |
| 1084 ASSERT_TRUE(surface); | |
| 1085 base::WeakPtr<SurfaceFactory> factory = surface->factory(); | |
| 1086 EXPECT_TRUE(factory); | |
| 1087 EXPECT_FALSE(surface->destroyed()); | |
| 1088 | |
| 1089 // Recreate child_support. The surface must be marked as destroyed and its | |
| 1090 // factory must be gone. | |
| 1091 child_support.reset(); | |
| 1092 child_support = CreateCompositorFrameSinkSupport(kArbitraryFrameSink); | |
| 1093 EXPECT_EQ(surface, surface_manager().GetSurfaceForId(child_id)); | |
| 1094 EXPECT_FALSE(factory); | |
| 1095 EXPECT_TRUE(surface->destroyed()); | |
| 1096 | |
| 1097 // Submit another frame for the same local surface id. The same surface must | |
| 1098 // be used and destroyed() must return false. The surface must have a factory. | |
| 1099 child_support->SubmitCompositorFrame( | |
| 1100 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 1101 EXPECT_EQ(surface, surface_manager().GetSurfaceForId(child_id)); | |
| 1102 EXPECT_TRUE(surface->factory()); | |
| 1103 EXPECT_FALSE(surface->destroyed()); | |
| 1104 } | |
| 1105 | |
| 1106 // This test verifies that a crash does not occur if garbage collection is | 1070 // This test verifies that a crash does not occur if garbage collection is |
| 1107 // triggered during surface dependency resolution. This test triggers garbage | 1071 // triggered during surface dependency resolution. This test triggers garbage |
| 1108 // collection during surface resolution, by causing an activation to remove | 1072 // collection during surface resolution, by causing an activation to remove |
| 1109 // a surface subtree from the root. Both the old subtree and the new | 1073 // a surface subtree from the root. Both the old subtree and the new |
| 1110 // activated subtree refer to the same dependency. The old subtree was activated | 1074 // activated subtree refer to the same dependency. The old subtree was activated |
| 1111 // by deadline, and the new subtree was activated by a dependency finally | 1075 // by deadline, and the new subtree was activated by a dependency finally |
| 1112 // resolving. | 1076 // resolving. |
| 1113 TEST_F(CompositorFrameSinkSupportTest, DependencyTrackingGarbageCollection) { | 1077 TEST_F(CompositorFrameSinkSupportTest, DependencyTrackingGarbageCollection) { |
| 1114 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | 1078 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); |
| 1115 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | 1079 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 EXPECT_TRUE(display_surface()->HasPendingFrame()); | 1115 EXPECT_TRUE(display_surface()->HasPendingFrame()); |
| 1152 | 1116 |
| 1153 // Submitting a CompositorFrame will trigger garbage collection of the | 1117 // Submitting a CompositorFrame will trigger garbage collection of the |
| 1154 // |parent_id1| subtree. This should not crash. | 1118 // |parent_id1| subtree. This should not crash. |
| 1155 child_support1().SubmitCompositorFrame( | 1119 child_support1().SubmitCompositorFrame( |
| 1156 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 1120 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); |
| 1157 } | 1121 } |
| 1158 | 1122 |
| 1159 } // namespace test | 1123 } // namespace test |
| 1160 } // namespace cc | 1124 } // namespace cc |
| OLD | NEW |