Chromium Code Reviews| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 } | 148 } |
| 149 | 149 |
| 150 SurfaceDependencyTracker& dependency_tracker() { | 150 SurfaceDependencyTracker& dependency_tracker() { |
| 151 return *surface_manager_.dependency_tracker(); | 151 return *surface_manager_.dependency_tracker(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 FakeExternalBeginFrameSource* begin_frame_source() { | 154 FakeExternalBeginFrameSource* begin_frame_source() { |
| 155 return begin_frame_source_.get(); | 155 return begin_frame_source_.get(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 std::unique_ptr<CompositorFrameSinkSupport> CreateCompositorFrameSinkSupport( | |
| 159 FrameSinkId frame_sink_id, | |
| 160 bool is_root = false) { | |
| 161 return base::MakeUnique<CompositorFrameSinkSupport>( | |
| 162 &support_client_, &surface_manager_, frame_sink_id, is_root, | |
| 163 true /* handles_frame_sink_id_invalidation */, | |
| 164 true /* needs_sync_points */); | |
| 165 } | |
| 166 | |
| 158 // testing::Test: | 167 // testing::Test: |
| 159 void SetUp() override { | 168 void SetUp() override { |
| 160 testing::Test::SetUp(); | 169 testing::Test::SetUp(); |
| 161 begin_frame_source_ = | 170 begin_frame_source_ = |
| 162 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); | 171 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); |
| 163 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( | 172 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( |
| 164 new SurfaceDependencyTracker(&surface_manager_, | 173 new SurfaceDependencyTracker(&surface_manager_, |
| 165 begin_frame_source_.get())); | 174 begin_frame_source_.get())); |
| 166 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); | 175 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); |
| 167 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | 176 supports_.push_back(CreateCompositorFrameSinkSupport(kDisplayFrameSink, |
| 168 &support_client_, &surface_manager_, kDisplayFrameSink, | 177 true /* is_root */)); |
| 169 true /* is_root */, true /* handles_frame_sink_id_invalidation */, | 178 supports_.push_back(CreateCompositorFrameSinkSupport(kParentFrameSink)); |
| 170 true /* needs_sync_points */)); | 179 supports_.push_back(CreateCompositorFrameSinkSupport(kChildFrameSink1)); |
| 171 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | 180 supports_.push_back(CreateCompositorFrameSinkSupport(kChildFrameSink2)); |
| 172 &support_client_, &surface_manager_, kParentFrameSink, | |
| 173 false /* is_root */, true /* handles_frame_sink_id_invalidation */, | |
| 174 true /* needs_sync_points */)); | |
| 175 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | |
| 176 &support_client_, &surface_manager_, kChildFrameSink1, | |
| 177 false /* is_root */, true /* handles_frame_sink_id_invalidation */, | |
| 178 true /* needs_sync_points */)); | |
| 179 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( | |
| 180 &support_client_, &surface_manager_, kChildFrameSink2, | |
| 181 false /* is_root */, true /* handles_frame_sink_id_invalidation */, | |
| 182 true /* needs_sync_points */)); | |
| 183 | |
| 184 // Normally, the BeginFrameSource would be registered by the Display. We | 181 // Normally, the BeginFrameSource would be registered by the Display. We |
| 185 // register it here so that BeginFrames are received by the display support, | 182 // register it here so that BeginFrames are received by the display support, |
| 186 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive | 183 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive |
| 187 // BeginFrames, since the frame sink hierarchy is not set up in this test. | 184 // BeginFrames, since the frame sink hierarchy is not set up in this test. |
| 188 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(), | 185 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(), |
| 189 kDisplayFrameSink); | 186 kDisplayFrameSink); |
| 190 } | 187 } |
| 191 | 188 |
| 192 void TearDown() override { | 189 void TearDown() override { |
| 193 surface_manager_.SetDependencyTracker(nullptr); | 190 surface_manager_.SetDependencyTracker(nullptr); |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 child_support1().EvictFrame(); | 1042 child_support1().EvictFrame(); |
| 1046 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); | 1043 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); |
| 1047 | 1044 |
| 1048 // Submit another frame with the same local surface id. This should work fine | 1045 // Submit another frame with the same local surface id. This should work fine |
| 1049 // and a new surface must be created. | 1046 // and a new surface must be created. |
| 1050 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 1047 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
| 1051 CompositorFrame()); | 1048 CompositorFrame()); |
| 1052 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); | 1049 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); |
| 1053 } | 1050 } |
| 1054 | 1051 |
| 1052 // Checks whether a LocalSurfaceId can be reused after the | |
| 1053 // CompositorFrameSinkSupport is destroyed and recreated with the same | |
| 1054 // FrameSinkId. | |
| 1055 TEST_F(CompositorFrameSinkSupportTest, ReuseSurfaceAfterSupportDestroyed) { | |
| 1056 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | |
| 1057 const SurfaceId child_id = MakeSurfaceId(kArbitraryFrameSink, 1); | |
| 1058 std::unique_ptr<CompositorFrameSinkSupport> child_support = | |
| 1059 CreateCompositorFrameSinkSupport(kArbitraryFrameSink); | |
| 1060 | |
| 1061 // Add a reference from parent to child to preserve the child surface. | |
| 1062 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 1063 MakeCompositorFrame({child_id})); | |
| 1064 | |
| 1065 // Submit the first frame. A surface must be created. | |
| 1066 child_support->SubmitCompositorFrame( | |
| 1067 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 1068 Surface* surface = surface_manager().GetSurfaceForId(child_id); | |
| 1069 ASSERT_TRUE(surface); | |
| 1070 base::WeakPtr<SurfaceFactory> factory = surface->factory(); | |
| 1071 EXPECT_TRUE(factory); | |
| 1072 EXPECT_FALSE(surface->destroyed()); | |
| 1073 | |
| 1074 // Recreate child_support. The surface must be marked as destroyed and its | |
| 1075 // factory must be gone. | |
| 1076 child_support.reset(); | |
| 1077 child_support = CreateCompositorFrameSinkSupport(kArbitraryFrameSink); | |
| 1078 EXPECT_EQ(surface, surface_manager().GetSurfaceForId(child_id)); | |
| 1079 EXPECT_FALSE(factory); | |
| 1080 EXPECT_TRUE(surface->destroyed()); | |
| 1081 | |
| 1082 // Submit another frame for the same local surface id. The same surface must | |
| 1083 // be used and destroyed() must return false. The surface must have a factory. | |
| 1084 child_support->SubmitCompositorFrame(child_id.local_surface_id(), | |
| 1085 CompositorFrame()); | |
|
Fady Samuel
2017/03/17 01:01:10
Oops, here too: MakeCompositorFrame(empty_surface_
Saman Sami
2017/03/20 16:26:09
Done.
| |
| 1086 EXPECT_EQ(surface, surface_manager().GetSurfaceForId(child_id)); | |
| 1087 EXPECT_TRUE(surface->factory()); | |
| 1088 EXPECT_FALSE(surface->destroyed()); | |
| 1089 } | |
| 1090 | |
| 1055 } // namespace test | 1091 } // namespace test |
| 1056 } // namespace cc | 1092 } // namespace cc |
| OLD | NEW |