| 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/output/copy_output_request.h" |
| 10 #include "cc/output/copy_output_result.h" |
| 11 #include "cc/resources/resource_provider.h" |
| 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 12 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 10 #include "cc/surfaces/frame_sink_id.h" | 13 #include "cc/surfaces/frame_sink_id.h" |
| 11 #include "cc/surfaces/surface_id.h" | 14 #include "cc/surfaces/surface_id.h" |
| 15 #include "cc/surfaces/surface_info.h" |
| 12 #include "cc/surfaces/surface_manager.h" | 16 #include "cc/surfaces/surface_manager.h" |
| 13 #include "cc/test/begin_frame_args_test.h" | 17 #include "cc/test/begin_frame_args_test.h" |
| 14 #include "cc/test/fake_external_begin_frame_source.h" | 18 #include "cc/test/fake_external_begin_frame_source.h" |
| 19 #include "cc/test/mock_compositor_frame_sink_support_client.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 22 |
| 18 using testing::UnorderedElementsAre; | 23 using testing::UnorderedElementsAre; |
| 19 using testing::IsEmpty; | 24 using testing::IsEmpty; |
| 20 using testing::SizeIs; | 25 using testing::SizeIs; |
| 21 using testing::Invoke; | 26 using testing::Invoke; |
| 22 using testing::_; | 27 using testing::_; |
| 23 using testing::Eq; | 28 using testing::Eq; |
| 24 | 29 |
| 25 namespace cc { | 30 namespace cc { |
| 26 namespace test { | 31 namespace test { |
| 27 namespace { | 32 namespace { |
| 28 | 33 |
| 29 constexpr FrameSinkId kDisplayFrameSink(2, 0); | 34 constexpr bool kIsRoot = true; |
| 30 constexpr FrameSinkId kParentFrameSink(3, 0); | 35 constexpr bool kIsChildRoot = false; |
| 31 constexpr FrameSinkId kChildFrameSink1(65563, 0); | 36 constexpr bool kHandlesFrameSinkIdInvalidation = true; |
| 32 constexpr FrameSinkId kChildFrameSink2(65564, 0); | 37 constexpr bool kNeedsSyncPoints = true; |
| 33 constexpr FrameSinkId kArbitraryFrameSink(1337, 7331); | |
| 34 | 38 |
| 35 class MockCompositorFrameSinkSupportClient | 39 constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
| 40 constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); |
| 41 constexpr FrameSinkId kYetAnotherArbitraryFrameSinkId(3, 3); |
| 42 |
| 43 const base::UnguessableToken kArbitraryToken = base::UnguessableToken::Create(); |
| 44 const base::UnguessableToken kArbitrarySourceId1 = |
| 45 base::UnguessableToken::Deserialize(0xdead, 0xbeef); |
| 46 const base::UnguessableToken kArbitrarySourceId2 = |
| 47 base::UnguessableToken::Deserialize(0xdead, 0xbee0); |
| 48 |
| 49 gpu::SyncToken GenTestSyncToken(int id) { |
| 50 gpu::SyncToken token; |
| 51 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 52 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
| 53 return token; |
| 54 } |
| 55 |
| 56 class FakeCompositorFrameSinkSupportClient |
| 36 : public CompositorFrameSinkSupportClient { | 57 : public CompositorFrameSinkSupportClient { |
| 37 public: | 58 public: |
| 38 MockCompositorFrameSinkSupportClient() { | 59 FakeCompositorFrameSinkSupportClient() = default; |
| 39 ON_CALL(*this, ReclaimResources(_)) | 60 ~FakeCompositorFrameSinkSupportClient() override = default; |
| 40 .WillByDefault(Invoke( | 61 |
| 41 this, | 62 void DidReceiveCompositorFrameAck( |
| 42 &MockCompositorFrameSinkSupportClient::ReclaimResourcesInternal)); | 63 const ReturnedResourceArray& resources) override { |
| 43 ON_CALL(*this, DidReceiveCompositorFrameAck(_)) | 64 InsertResources(resources); |
| 44 .WillByDefault(Invoke( | |
| 45 this, | |
| 46 &MockCompositorFrameSinkSupportClient::ReclaimResourcesInternal)); | |
| 47 } | 65 } |
| 48 | 66 |
| 49 ReturnedResourceArray& last_returned_resources() { | 67 void OnBeginFrame(const BeginFrameArgs& args) override {} |
| 50 return last_returned_resources_; | 68 |
| 69 void ReclaimResources(const ReturnedResourceArray& resources) override { |
| 70 InsertResources(resources); |
| 51 } | 71 } |
| 52 | 72 |
| 53 // CompositorFrameSinkSupportClient implementation. | 73 void WillDrawSurface(const LocalSurfaceId& local_surface_id, |
| 54 MOCK_METHOD1(DidReceiveCompositorFrameAck, | 74 const gfx::Rect& damage_rect) override {} |
| 55 void(const ReturnedResourceArray&)); | 75 |
| 56 MOCK_METHOD1(OnBeginFrame, void(const BeginFrameArgs&)); | 76 void clear_returned_resources() { returned_resources_.clear(); } |
| 57 MOCK_METHOD1(ReclaimResources, void(const ReturnedResourceArray&)); | 77 const ReturnedResourceArray& returned_resources() { |
| 58 MOCK_METHOD2(WillDrawSurface, void(const LocalSurfaceId&, const gfx::Rect&)); | 78 return returned_resources_; |
| 79 } |
| 59 | 80 |
| 60 private: | 81 private: |
| 61 void ReclaimResourcesInternal(const ReturnedResourceArray& resources) { | 82 void InsertResources(const ReturnedResourceArray& resources) { |
| 62 last_returned_resources_ = resources; | 83 returned_resources_.insert(returned_resources_.end(), resources.begin(), |
| 84 resources.end()); |
| 63 } | 85 } |
| 64 | 86 |
| 65 ReturnedResourceArray last_returned_resources_; | 87 ReturnedResourceArray returned_resources_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(FakeCompositorFrameSinkSupportClient); |
| 66 }; | 90 }; |
| 67 | 91 |
| 68 std::vector<SurfaceId> empty_surface_ids() { | |
| 69 return std::vector<SurfaceId>(); | |
| 70 } | |
| 71 | |
| 72 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { | |
| 73 return SurfaceId( | |
| 74 frame_sink_id, | |
| 75 LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); | |
| 76 } | |
| 77 | |
| 78 CompositorFrame MakeCompositorFrame(std::vector<SurfaceId> embedded_surfaces, | |
| 79 std::vector<SurfaceId> referenced_surfaces, | |
| 80 TransferableResourceArray resource_list) { | |
| 81 CompositorFrame compositor_frame; | |
| 82 compositor_frame.metadata.begin_frame_ack = BeginFrameAck(0, 1, 1, true); | |
| 83 compositor_frame.metadata.embedded_surfaces = std::move(embedded_surfaces); | |
| 84 compositor_frame.metadata.referenced_surfaces = | |
| 85 std::move(referenced_surfaces); | |
| 86 compositor_frame.resource_list = std::move(resource_list); | |
| 87 return compositor_frame; | |
| 88 } | |
| 89 | |
| 90 CompositorFrame MakeCompositorFrame() { | |
| 91 return MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), | |
| 92 TransferableResourceArray()); | |
| 93 } | |
| 94 | |
| 95 CompositorFrame MakeCompositorFrame(std::vector<SurfaceId> embedded_surfaces) { | |
| 96 return MakeCompositorFrame(embedded_surfaces, embedded_surfaces, | |
| 97 TransferableResourceArray()); | |
| 98 } | |
| 99 | |
| 100 CompositorFrame MakeCompositorFrame( | |
| 101 std::vector<SurfaceId> embedded_surfaces, | |
| 102 std::vector<SurfaceId> referenced_surfaces) { | |
| 103 return MakeCompositorFrame(std::move(embedded_surfaces), | |
| 104 std::move(referenced_surfaces), | |
| 105 TransferableResourceArray()); | |
| 106 } | |
| 107 | |
| 108 CompositorFrame MakeCompositorFrameWithResources( | |
| 109 std::vector<SurfaceId> embedded_surfaces, | |
| 110 TransferableResourceArray resource_list) { | |
| 111 return MakeCompositorFrame(embedded_surfaces, embedded_surfaces, | |
| 112 std::move(resource_list)); | |
| 113 } | |
| 114 | |
| 115 TransferableResource MakeResource(ResourceId id, | |
| 116 ResourceFormat format, | |
| 117 uint32_t filter, | |
| 118 const gfx::Size& size) { | |
| 119 TransferableResource resource; | |
| 120 resource.id = id; | |
| 121 resource.format = format; | |
| 122 resource.filter = filter; | |
| 123 resource.size = size; | |
| 124 return resource; | |
| 125 } | |
| 126 | |
| 127 } // namespace | 92 } // namespace |
| 128 | 93 |
| 129 class CompositorFrameSinkSupportTest : public testing::Test, | 94 class CompositorFrameSinkSupportTest : public testing::Test, |
| 130 public SurfaceObserver { | 95 public SurfaceObserver { |
| 131 public: | 96 public: |
| 132 CompositorFrameSinkSupportTest() | 97 CompositorFrameSinkSupportTest() |
| 133 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} | 98 : support_( |
| 134 ~CompositorFrameSinkSupportTest() override {} | 99 CompositorFrameSinkSupport::Create(&fake_support_client_, |
| 135 | 100 &manager_, |
| 136 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } | 101 kArbitraryFrameSinkId, |
| 137 Surface* display_surface() { | 102 kIsRoot, |
| 138 return display_support().current_surface_for_testing(); | 103 kHandlesFrameSinkIdInvalidation, |
| 139 } | 104 kNeedsSyncPoints)), |
| 140 | 105 local_surface_id_(3, kArbitraryToken), |
| 141 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } | 106 frame_sync_token_(GenTestSyncToken(4)), |
| 142 Surface* parent_surface() { | 107 consumer_sync_token_(GenTestSyncToken(5)) { |
| 143 return parent_support().current_surface_for_testing(); | 108 manager_.AddObserver(this); |
| 144 } | 109 } |
| 145 const ReferencedSurfaceTracker& parent_reference_tracker() { | 110 |
| 146 return parent_support().ReferenceTrackerForTesting(); | 111 const SurfaceId& last_created_surface_id() const { |
| 147 } | 112 return last_created_surface_id_; |
| 148 | 113 } |
| 149 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } | 114 |
| 150 Surface* child_surface1() { | 115 // SurfaceObserver implementation. |
| 151 return child_support1().current_surface_for_testing(); | 116 void OnSurfaceCreated(const SurfaceInfo& surface_info) override { |
| 152 } | 117 last_created_surface_id_ = surface_info.id(); |
| 153 | 118 last_surface_info_ = surface_info; |
| 154 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } | 119 } |
| 155 Surface* child_surface2() { | 120 |
| 156 return child_support2().current_surface_for_testing(); | 121 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { |
| 157 } | 122 *changed = true; |
| 158 | 123 } |
| 159 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } | 124 |
| 160 Surface* surface(int index) { | 125 ~CompositorFrameSinkSupportTest() override { |
| 161 return support(index).current_surface_for_testing(); | 126 manager_.RemoveObserver(this); |
| 162 } | 127 support_->EvictFrame(); |
| 163 | 128 } |
| 164 SurfaceManager& surface_manager() { return surface_manager_; } | 129 |
| 165 | 130 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 166 // Returns all the references where |surface_id| is the parent. | 131 size_t num_resource_ids) { |
| 167 const SurfaceManager::SurfaceIdSet& GetChildReferences( | 132 CompositorFrame frame = MakeCompositorFrame(); |
| 168 const SurfaceId& surface_id) { | 133 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 169 return surface_manager().parent_to_child_refs_[surface_id]; | 134 TransferableResource resource; |
| 170 } | 135 resource.id = resource_ids[i]; |
| 171 | 136 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 172 // Returns true if there is a temporary reference for |surface_id|. | 137 resource.mailbox_holder.sync_token = frame_sync_token_; |
| 173 bool HasTemporaryReference(const SurfaceId& surface_id) { | 138 frame.resource_list.push_back(resource); |
| 174 return surface_manager().HasTemporaryReference(surface_id); | 139 } |
| 175 } | 140 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 176 | 141 EXPECT_EQ(last_created_surface_id_.local_surface_id(), local_surface_id_); |
| 177 SurfaceDependencyTracker& dependency_tracker() { | 142 } |
| 178 return *surface_manager_.dependency_tracker(); | 143 |
| 179 } | 144 void UnrefResources(ResourceId* ids_to_unref, |
| 180 | 145 int* counts_to_unref, |
| 181 FakeExternalBeginFrameSource* begin_frame_source() { | 146 size_t num_ids_to_unref) { |
| 182 return begin_frame_source_.get(); | 147 ReturnedResourceArray unref_array; |
| 183 } | 148 for (size_t i = 0; i < num_ids_to_unref; ++i) { |
| 184 | 149 ReturnedResource resource; |
| 185 // testing::Test: | 150 resource.sync_token = consumer_sync_token_; |
| 186 void SetUp() override { | 151 resource.id = ids_to_unref[i]; |
| 187 testing::Test::SetUp(); | 152 resource.count = counts_to_unref[i]; |
| 188 constexpr bool is_root = true; | 153 unref_array.push_back(resource); |
| 189 constexpr bool is_child_root = false; | 154 } |
| 190 constexpr bool handles_frame_sink_id_invalidation = true; | 155 support_->UnrefResources(unref_array); |
| 191 constexpr bool needs_sync_points = true; | 156 } |
| 192 begin_frame_source_ = | 157 |
| 193 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); | 158 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids, |
| 194 surface_manager_.SetDependencyTracker( | 159 int* expected_returned_counts, |
| 195 base::MakeUnique<SurfaceDependencyTracker>(&surface_manager_, | 160 size_t expected_resources, |
| 196 begin_frame_source_.get())); | 161 gpu::SyncToken expected_sync_token) { |
| 197 surface_manager_.AddObserver(this); | 162 const ReturnedResourceArray& actual_resources = |
| 198 supports_.push_back(CompositorFrameSinkSupport::Create( | 163 fake_support_client_.returned_resources(); |
| 199 &support_client_, &surface_manager_, kDisplayFrameSink, is_root, | 164 ASSERT_EQ(expected_resources, actual_resources.size()); |
| 200 handles_frame_sink_id_invalidation, needs_sync_points)); | 165 for (size_t i = 0; i < expected_resources; ++i) { |
| 201 supports_.push_back(CompositorFrameSinkSupport::Create( | 166 ReturnedResource resource = actual_resources[i]; |
| 202 &support_client_, &surface_manager_, kParentFrameSink, is_child_root, | 167 EXPECT_EQ(expected_sync_token, resource.sync_token); |
| 203 handles_frame_sink_id_invalidation, needs_sync_points)); | 168 EXPECT_EQ(expected_returned_ids[i], resource.id); |
| 204 supports_.push_back(CompositorFrameSinkSupport::Create( | 169 EXPECT_EQ(expected_returned_counts[i], resource.count); |
| 205 &support_client_, &surface_manager_, kChildFrameSink1, is_child_root, | 170 } |
| 206 handles_frame_sink_id_invalidation, needs_sync_points)); | 171 fake_support_client_.clear_returned_resources(); |
| 207 supports_.push_back(CompositorFrameSinkSupport::Create( | 172 } |
| 208 &support_client_, &surface_manager_, kChildFrameSink2, is_child_root, | 173 |
| 209 handles_frame_sink_id_invalidation, needs_sync_points)); | 174 void RefCurrentFrameResources() { |
| 210 | 175 Surface* surface = manager_.GetSurfaceForId( |
| 211 // Normally, the BeginFrameSource would be registered by the Display. We | 176 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 212 // register it here so that BeginFrames are received by the display support, | 177 support_->RefResources(surface->GetActiveFrame().resource_list); |
| 213 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive | |
| 214 // BeginFrames, since the frame sink hierarchy is not set up in this test. | |
| 215 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(), | |
| 216 kDisplayFrameSink); | |
| 217 } | |
| 218 | |
| 219 void TearDown() override { | |
| 220 surface_manager_.RemoveObserver(this); | |
| 221 surface_manager_.SetDependencyTracker(nullptr); | |
| 222 surface_manager_.UnregisterBeginFrameSource(begin_frame_source_.get()); | |
| 223 | |
| 224 // SurfaceDependencyTracker depends on this BeginFrameSource and so it must | |
| 225 // be destroyed AFTER the dependency tracker is destroyed. | |
| 226 begin_frame_source_.reset(); | |
| 227 | |
| 228 supports_.clear(); | |
| 229 | |
| 230 damaged_surfaces_.clear(); | |
| 231 } | |
| 232 | |
| 233 bool IsSurfaceDamaged(const SurfaceId& surface_id) const { | |
| 234 return damaged_surfaces_.count(surface_id) > 0; | |
| 235 } | |
| 236 | |
| 237 // SurfaceObserver implementation: | |
| 238 void OnSurfaceCreated(const SurfaceInfo& surface_info) override {} | |
| 239 void OnSurfaceDamaged(const SurfaceId& surface_id, bool* changed) override { | |
| 240 damaged_surfaces_.insert(surface_id); | |
| 241 } | 178 } |
| 242 | 179 |
| 243 protected: | 180 protected: |
| 244 testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_; | 181 SurfaceManager manager_; |
| 245 | 182 FakeCompositorFrameSinkSupportClient fake_support_client_; |
| 246 private: | 183 std::unique_ptr<CompositorFrameSinkSupport> support_; |
| 247 base::flat_set<SurfaceId> damaged_surfaces_; | 184 LocalSurfaceId local_surface_id_; |
| 248 SurfaceManager surface_manager_; | 185 SurfaceId last_created_surface_id_; |
| 249 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; | 186 SurfaceInfo last_surface_info_; |
| 250 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; | 187 |
| 251 | 188 // This is the sync token submitted with the frame. It should never be |
| 252 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); | 189 // returned to the client. |
| 190 const gpu::SyncToken frame_sync_token_; |
| 191 |
| 192 // This is the sync token returned by the consumer. It should always be |
| 193 // returned to the client. |
| 194 const gpu::SyncToken consumer_sync_token_; |
| 253 }; | 195 }; |
| 254 | 196 |
| 255 // The display root surface should have a surface reference from the top-level | 197 // Tests submitting a frame with resources followed by one with no resources |
| 256 // root added/removed when a CompositorFrame is submitted with a new SurfaceId. | 198 // with no resource provider action in between. |
| 257 TEST_F(CompositorFrameSinkSupportTest, RootSurfaceReceivesReferences) { | 199 TEST_F(CompositorFrameSinkSupportTest, ResourceLifetimeSimple) { |
| 258 const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1); | 200 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 259 const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2); | 201 SubmitCompositorFrameWithResources(first_frame_ids, |
| 260 | 202 arraysize(first_frame_ids)); |
| 261 // Submit a CompositorFrame for the first display root surface. | 203 |
| 262 display_support().SubmitCompositorFrame(display_id_first.local_surface_id(), | 204 // All of the resources submitted in the first frame are still in use at this |
| 263 MakeCompositorFrame()); | 205 // time by virtue of being in the pending frame, so none can be returned to |
| 264 | 206 // the client yet. |
| 265 // A surface reference from the top-level root is added and there shouldn't be | 207 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 266 // a temporary reference. | 208 fake_support_client_.clear_returned_resources(); |
| 267 EXPECT_FALSE(HasTemporaryReference(display_id_first)); | 209 |
| 268 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), | 210 // The second frame references no resources of first frame and thus should |
| 269 UnorderedElementsAre(display_id_first)); | 211 // make all resources of first frame available to be returned. |
| 270 | 212 SubmitCompositorFrameWithResources(NULL, 0); |
| 271 // Submit a CompositorFrame for the second display root surface. | 213 |
| 272 display_support().SubmitCompositorFrame(display_id_second.local_surface_id(), | 214 ResourceId expected_returned_ids[] = {1, 2, 3}; |
| 273 MakeCompositorFrame()); | 215 int expected_returned_counts[] = {1, 1, 1}; |
| 274 | 216 // Resources were never consumed so no sync token should be set. |
| 275 // A surface reference from the top-level root to |display_id_second| should | 217 CheckReturnedResourcesMatchExpected( |
| 276 // be added and the reference to |display_root_first| removed. | 218 expected_returned_ids, expected_returned_counts, |
| 277 EXPECT_FALSE(HasTemporaryReference(display_id_second)); | 219 arraysize(expected_returned_counts), gpu::SyncToken()); |
| 278 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), | 220 |
| 279 UnorderedElementsAre(display_id_second)); | 221 ResourceId third_frame_ids[] = {4, 5, 6}; |
| 280 | 222 SubmitCompositorFrameWithResources(third_frame_ids, |
| 281 // Surface |display_id_first| is unreachable and should get deleted. | 223 arraysize(third_frame_ids)); |
| 282 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(display_id_first)); | 224 |
| 283 } | 225 // All of the resources submitted in the third frame are still in use at this |
| 284 | 226 // time by virtue of being in the pending frame, so none can be returned to |
| 285 // The parent Surface is blocked on |child_id1| and |child_id2|. | 227 // the client yet. |
| 286 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { | 228 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 287 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 229 fake_support_client_.clear_returned_resources(); |
| 288 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 230 |
| 289 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 231 // The forth frame references no resources of third frame and thus should |
| 290 | 232 // make all resources of third frame available to be returned. |
| 291 parent_support().SubmitCompositorFrame( | 233 ResourceId forth_frame_ids[] = {7, 8, 9}; |
| 292 parent_id.local_surface_id(), | 234 SubmitCompositorFrameWithResources(forth_frame_ids, |
| 293 MakeCompositorFrame({child_id1, child_id2})); | 235 arraysize(forth_frame_ids)); |
| 294 | 236 |
| 295 // parent_support is blocked on |child_id1| and |child_id2|. | 237 ResourceId forth_expected_returned_ids[] = {4, 5, 6}; |
| 296 EXPECT_TRUE(dependency_tracker().has_deadline()); | 238 int forth_expected_returned_counts[] = {1, 1, 1}; |
| 297 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 239 // Resources were never consumed so no sync token should be set. |
| 298 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 240 CheckReturnedResourcesMatchExpected( |
| 299 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 241 forth_expected_returned_ids, forth_expected_returned_counts, |
| 300 UnorderedElementsAre(child_id1, child_id2)); | 242 arraysize(forth_expected_returned_counts), gpu::SyncToken()); |
| 301 | 243 } |
| 302 // Submit a CompositorFrame without any dependencies to |child_id1|. | 244 |
| 303 // parent_support should now only be blocked on |child_id2|. | 245 // Tests submitting a frame with resources followed by one with no resources |
| 304 child_support1().SubmitCompositorFrame( | 246 // with the resource provider holding everything alive. |
| 305 child_id1.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 306 | |
| 307 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 308 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | |
| 309 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | |
| 310 EXPECT_THAT(parent_surface()->blocking_surfaces(), | |
| 311 UnorderedElementsAre(child_id2)); | |
| 312 | |
| 313 // Submit a CompositorFrame without any dependencies to |child_id2|. | |
| 314 // parent_support should be activated. | |
| 315 child_support2().SubmitCompositorFrame( | |
| 316 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 317 | |
| 318 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 319 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 320 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 321 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | |
| 322 } | |
| 323 | |
| 324 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. | |
| 325 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedChain) { | |
| 326 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | |
| 327 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | |
| 328 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | |
| 329 | |
| 330 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 331 MakeCompositorFrame({child_id1})); | |
| 332 | |
| 333 // parent_support is blocked on |child_id1|. | |
| 334 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 335 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | |
| 336 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | |
| 337 EXPECT_THAT(parent_surface()->blocking_surfaces(), | |
| 338 UnorderedElementsAre(child_id1)); | |
| 339 // The parent should not report damage until it activates. | |
| 340 EXPECT_FALSE(IsSurfaceDamaged(parent_id)); | |
| 341 | |
| 342 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | |
| 343 MakeCompositorFrame({child_id2})); | |
| 344 | |
| 345 // child_support1 should now be blocked on |child_id2|. | |
| 346 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 347 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | |
| 348 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | |
| 349 EXPECT_THAT(child_surface1()->blocking_surfaces(), | |
| 350 UnorderedElementsAre(child_id2)); | |
| 351 // The parent and child should not report damage until they activate. | |
| 352 EXPECT_FALSE(IsSurfaceDamaged(parent_id)); | |
| 353 EXPECT_FALSE(IsSurfaceDamaged(child_id1)); | |
| 354 | |
| 355 // The parent should still be blocked on |child_id1| because it's pending. | |
| 356 EXPECT_THAT(parent_surface()->blocking_surfaces(), | |
| 357 UnorderedElementsAre(child_id1)); | |
| 358 | |
| 359 // Submit a CompositorFrame without any dependencies to |child_id2|. | |
| 360 // parent_support should be activated. | |
| 361 child_support2().SubmitCompositorFrame( | |
| 362 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 363 | |
| 364 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 365 | |
| 366 // child_surface1 should now be active. | |
| 367 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | |
| 368 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | |
| 369 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | |
| 370 | |
| 371 // parent_surface should now be active. | |
| 372 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 373 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 374 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | |
| 375 | |
| 376 // All three surfaces |parent_id|, |child_id1|, and |child_id2| should | |
| 377 // now report damage. This would trigger a new display frame. | |
| 378 EXPECT_TRUE(IsSurfaceDamaged(parent_id)); | |
| 379 EXPECT_TRUE(IsSurfaceDamaged(child_id1)); | |
| 380 EXPECT_TRUE(IsSurfaceDamaged(child_id2)); | |
| 381 } | |
| 382 | |
| 383 // parent_surface and child_surface1 are blocked on |child_id2|. | |
| 384 TEST_F(CompositorFrameSinkSupportTest, | 247 TEST_F(CompositorFrameSinkSupportTest, |
| 385 DisplayCompositorLockingTwoBlockedOnOne) { | 248 ResourceLifetimeSimpleWithProviderHoldingAlive) { |
| 386 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 249 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 387 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 250 SubmitCompositorFrameWithResources(first_frame_ids, |
| 388 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 251 arraysize(first_frame_ids)); |
| 389 | 252 |
| 390 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | 253 // All of the resources submitted in the first frame are still in use at this |
| 391 MakeCompositorFrame({child_id2})); | 254 // time by virtue of being in the pending frame, so none can be returned to |
| 392 | 255 // the client yet. |
| 393 // parent_support is blocked on |child_id2|. | 256 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 394 EXPECT_TRUE(dependency_tracker().has_deadline()); | 257 fake_support_client_.clear_returned_resources(); |
| 395 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 258 |
| 396 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 259 // Hold on to everything. |
| 397 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 260 RefCurrentFrameResources(); |
| 398 UnorderedElementsAre(child_id2)); | 261 |
| 399 | 262 // The second frame references no resources and thus should make all resources |
| 400 // child_support1 should now be blocked on |child_id2|. | 263 // available to be returned as soon as the resource provider releases them. |
| 401 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | 264 SubmitCompositorFrameWithResources(NULL, 0); |
| 402 MakeCompositorFrame({child_id2})); | 265 |
| 403 | 266 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 404 EXPECT_TRUE(dependency_tracker().has_deadline()); | 267 fake_support_client_.clear_returned_resources(); |
| 405 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | 268 |
| 406 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | 269 int release_counts[] = {1, 1, 1}; |
| 407 EXPECT_THAT(child_surface1()->blocking_surfaces(), | 270 UnrefResources(first_frame_ids, release_counts, arraysize(first_frame_ids)); |
| 408 UnorderedElementsAre(child_id2)); | 271 |
| 409 | 272 // None is returned to the client since DidReceiveCompositorAck is not |
| 410 // The parent should still be blocked on |child_id2|. | 273 // invoked. |
| 411 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 274 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 412 UnorderedElementsAre(child_id2)); | 275 |
| 413 | 276 // Submitting an empty frame causes previous resources referenced by the |
| 414 // Submit a CompositorFrame without any dependencies to |child_id2|. | 277 // previous frame to be returned to client. |
| 415 // parent_support should be activated. | 278 SubmitCompositorFrameWithResources(nullptr, 0); |
| 416 child_support2().SubmitCompositorFrame( | 279 ResourceId expected_returned_ids[] = {1, 2, 3}; |
| 417 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 280 int expected_returned_counts[] = {1, 1, 1}; |
| 418 | 281 CheckReturnedResourcesMatchExpected( |
| 419 EXPECT_FALSE(dependency_tracker().has_deadline()); | 282 expected_returned_ids, expected_returned_counts, |
| 420 | 283 arraysize(expected_returned_counts), consumer_sync_token_); |
| 421 // child_surface1 should now be active. | 284 } |
| 422 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 285 |
| 423 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 286 // Tests referencing a resource, unref'ing it to zero, then using it again |
| 424 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 287 // before returning it to the client. |
| 425 | 288 TEST_F(CompositorFrameSinkSupportTest, ResourceReusedBeforeReturn) { |
| 426 // parent_surface should now be active. | 289 ResourceId first_frame_ids[] = {7}; |
| 427 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 290 SubmitCompositorFrameWithResources(first_frame_ids, |
| 428 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 291 arraysize(first_frame_ids)); |
| 429 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 292 |
| 430 } | 293 // This removes all references to resource id 7. |
| 431 | 294 SubmitCompositorFrameWithResources(NULL, 0); |
| 432 // parent_surface is blocked on |child_id1|, and child_surface2 is blocked on | 295 |
| 433 // |child_id2| until the deadline hits. | 296 // This references id 7 again. |
| 434 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingDeadlineHits) { | 297 SubmitCompositorFrameWithResources(first_frame_ids, |
| 435 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 298 arraysize(first_frame_ids)); |
| 436 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 299 |
| 437 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 300 // This removes it again. |
| 438 | 301 SubmitCompositorFrameWithResources(NULL, 0); |
| 439 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | 302 |
| 440 MakeCompositorFrame({child_id1})); | 303 // Now it should be returned. |
| 441 | 304 // We don't care how many entries are in the returned array for 7, so long as |
| 442 // parent_support is blocked on |child_id1|. | 305 // the total returned count matches the submitted count. |
| 443 EXPECT_TRUE(dependency_tracker().has_deadline()); | 306 const ReturnedResourceArray& returned = |
| 444 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 307 fake_support_client_.returned_resources(); |
| 445 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 308 size_t return_count = 0; |
| 446 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 309 for (size_t i = 0; i < returned.size(); ++i) { |
| 447 UnorderedElementsAre(child_id1)); | 310 EXPECT_EQ(7u, returned[i].id); |
| 448 | 311 return_count += returned[i].count; |
| 449 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | 312 } |
| 450 MakeCompositorFrame({child_id2})); | 313 EXPECT_EQ(2u, return_count); |
| 451 | 314 } |
| 452 // child_support1 should now be blocked on |child_id2|. | 315 |
| 453 EXPECT_TRUE(dependency_tracker().has_deadline()); | 316 // Tests having resources referenced multiple times, as if referenced by |
| 454 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | 317 // multiple providers. |
| 455 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | 318 TEST_F(CompositorFrameSinkSupportTest, ResourceRefMultipleTimes) { |
| 456 EXPECT_THAT(child_surface1()->blocking_surfaces(), | 319 ResourceId first_frame_ids[] = {3, 4}; |
| 457 UnorderedElementsAre(child_id2)); | 320 SubmitCompositorFrameWithResources(first_frame_ids, |
| 458 | 321 arraysize(first_frame_ids)); |
| 459 // The parent should still be blocked on |child_id1| because it's pending. | 322 |
| 460 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 323 // Ref resources from the first frame twice. |
| 461 UnorderedElementsAre(child_id1)); | 324 RefCurrentFrameResources(); |
| 462 | 325 RefCurrentFrameResources(); |
| 463 BeginFrameArgs args = | 326 |
| 464 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | 327 ResourceId second_frame_ids[] = {4, 5}; |
| 465 | 328 SubmitCompositorFrameWithResources(second_frame_ids, |
| 466 for (int i = 0; i < 3; ++i) { | 329 arraysize(second_frame_ids)); |
| 467 begin_frame_source()->TestOnBeginFrame(args); | 330 |
| 468 // There is still a looming deadline! Eeek! | 331 // Ref resources from the second frame 3 times. |
| 469 EXPECT_TRUE(dependency_tracker().has_deadline()); | 332 RefCurrentFrameResources(); |
| 470 | 333 RefCurrentFrameResources(); |
| 471 // parent_support is still blocked on |child_id1|. | 334 RefCurrentFrameResources(); |
| 472 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 335 |
| 473 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 336 // Submit a frame with no resources to remove all current frame refs from |
| 474 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 337 // submitted resources. |
| 475 UnorderedElementsAre(child_id1)); | 338 SubmitCompositorFrameWithResources(NULL, 0); |
| 476 | 339 |
| 477 // child_support1 is still blocked on |child_id2|. | 340 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 478 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | 341 fake_support_client_.clear_returned_resources(); |
| 479 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | 342 |
| 480 EXPECT_THAT(child_surface1()->blocking_surfaces(), | 343 // Expected current refs: |
| 481 UnorderedElementsAre(child_id2)); | 344 // 3 -> 2 |
| 482 } | 345 // 4 -> 2 + 3 = 5 |
| 483 | 346 // 5 -> 3 |
| 484 begin_frame_source()->TestOnBeginFrame(args); | 347 { |
| 485 | 348 SCOPED_TRACE("unref all 3"); |
| 486 // The deadline has passed. | 349 ResourceId ids_to_unref[] = {3, 4, 5}; |
| 487 EXPECT_FALSE(dependency_tracker().has_deadline()); | 350 int counts[] = {1, 1, 1}; |
| 488 | 351 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 489 // parent_surface has been activated. | 352 |
| 490 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 353 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 491 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 354 fake_support_client_.clear_returned_resources(); |
| 492 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 355 |
| 493 | 356 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 494 // child_surface1 has been activated. | 357 SubmitCompositorFrameWithResources(nullptr, 0); |
| 495 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 358 ResourceId expected_returned_ids[] = {3}; |
| 496 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 359 int expected_returned_counts[] = {1}; |
| 497 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 360 CheckReturnedResourcesMatchExpected( |
| 498 } | 361 expected_returned_ids, expected_returned_counts, |
| 499 | 362 arraysize(expected_returned_counts), consumer_sync_token_); |
| 500 // Verifies that the deadline does not reset if we submit CompositorFrames | 363 } |
| 501 // to new Surfaces with unresolved dependencies. | 364 |
| 502 TEST_F(CompositorFrameSinkSupportTest, | 365 // Expected refs remaining: |
| 503 DisplayCompositorLockingFramesSubmittedAfterDeadlineSet) { | 366 // 4 -> 3 |
| 504 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); | 367 // 5 -> 1 |
| 505 BeginFrameArgs args = | 368 { |
| 506 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | 369 SCOPED_TRACE("unref 4 and 5"); |
| 507 for (int i = 0; i < 3; ++i) { | 370 ResourceId ids_to_unref[] = {4, 5}; |
| 508 LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); | 371 int counts[] = {1, 1}; |
| 509 support(i).SubmitCompositorFrame(local_surface_id, | 372 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 510 MakeCompositorFrame({arbitrary_id})); | 373 SubmitCompositorFrameWithResources(nullptr, 0); |
| 511 // The deadline has been set. | 374 |
| 512 EXPECT_TRUE(dependency_tracker().has_deadline()); | 375 ResourceId expected_returned_ids[] = {5}; |
| 513 | 376 int expected_returned_counts[] = {1}; |
| 514 // support(i) should be blocked on arbitrary_id. | 377 CheckReturnedResourcesMatchExpected( |
| 515 EXPECT_FALSE(surface(i)->HasActiveFrame()); | 378 expected_returned_ids, expected_returned_counts, |
| 516 EXPECT_TRUE(surface(i)->HasPendingFrame()); | 379 arraysize(expected_returned_counts), consumer_sync_token_); |
| 517 EXPECT_THAT(surface(i)->blocking_surfaces(), | 380 } |
| 518 UnorderedElementsAre(arbitrary_id)); | 381 |
| 519 | 382 // Now, just 2 refs remaining on resource 4. Unref both at once and make sure |
| 520 // Issue a BeginFrame to get closer to the deadline. | 383 // the returned count is correct. |
| 521 begin_frame_source()->TestOnBeginFrame(args); | 384 { |
| 522 } | 385 SCOPED_TRACE("unref only 4"); |
| 523 | 386 ResourceId ids_to_unref[] = {4}; |
| 524 // The deadline hits and all the Surfaces should activate. | 387 int counts[] = {2}; |
| 525 begin_frame_source()->TestOnBeginFrame(args); | 388 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 526 for (int i = 0; i < 3; ++i) { | 389 SubmitCompositorFrameWithResources(nullptr, 0); |
| 527 EXPECT_TRUE(surface(i)->HasActiveFrame()); | 390 |
| 528 EXPECT_FALSE(surface(i)->HasPendingFrame()); | 391 ResourceId expected_returned_ids[] = {4}; |
| 529 EXPECT_THAT(surface(i)->blocking_surfaces(), IsEmpty()); | 392 int expected_returned_counts[] = {2}; |
| 530 } | 393 CheckReturnedResourcesMatchExpected( |
| 531 } | 394 expected_returned_ids, expected_returned_counts, |
| 532 | 395 arraysize(expected_returned_counts), consumer_sync_token_); |
| 533 // This test verifies at the Surface activates once a CompositorFrame is | 396 } |
| 534 // submitted that has no unresolved dependencies. | 397 } |
| 535 TEST_F(CompositorFrameSinkSupportTest, | 398 |
| 536 DisplayCompositorLockingNewFrameOverridesOldDependencies) { | 399 TEST_F(CompositorFrameSinkSupportTest, ResourceLifetime) { |
| 537 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 400 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 538 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); | 401 SubmitCompositorFrameWithResources(first_frame_ids, |
| 539 | 402 arraysize(first_frame_ids)); |
| 540 // Submit a CompositorFrame that depends on |arbitrary_id|. | 403 |
| 541 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | 404 // All of the resources submitted in the first frame are still in use at this |
| 542 MakeCompositorFrame({arbitrary_id})); | 405 // time by virtue of being in the pending frame, so none can be returned to |
| 543 | 406 // the client yet. |
| 544 // Verify that the CompositorFrame is blocked on |arbitrary_id|. | 407 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 545 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 408 fake_support_client_.clear_returned_resources(); |
| 546 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 409 |
| 547 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 410 // The second frame references some of the same resources, but some different |
| 548 UnorderedElementsAre(arbitrary_id)); | 411 // ones. We expect to receive back resource 1 with a count of 1 since it was |
| 549 | 412 // only referenced by the first frame. |
| 550 // Submit a CompositorFrame that has no dependencies. | 413 ResourceId second_frame_ids[] = {2, 3, 4}; |
| 551 parent_support().SubmitCompositorFrame( | 414 SubmitCompositorFrameWithResources(second_frame_ids, |
| 552 parent_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 415 arraysize(second_frame_ids)); |
| 553 | 416 { |
| 554 // Verify that the CompositorFrame has been activated. | 417 SCOPED_TRACE("second frame"); |
| 555 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 418 ResourceId expected_returned_ids[] = {1}; |
| 556 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 419 int expected_returned_counts[] = {1}; |
| 557 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 420 CheckReturnedResourcesMatchExpected( |
| 558 } | 421 expected_returned_ids, expected_returned_counts, |
| 559 | 422 arraysize(expected_returned_counts), gpu::SyncToken()); |
| 560 // This test verifies that a pending CompositorFrame does not affect surface | 423 } |
| 561 // references. A new surface from a child will continue to exist as a temporary | 424 |
| 562 // reference until the parent's frame activates. | 425 // The third frame references a disjoint set of resources, so we expect to |
| 563 TEST_F(CompositorFrameSinkSupportTest, | 426 // receive back all resources from the first and second frames. Resource IDs 2 |
| 564 OnlyActiveFramesAffectSurfaceReferences) { | 427 // and 3 will have counts of 2, since they were used in both frames, and |
| 565 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 428 // resource ID 4 will have a count of 1. |
| 566 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 429 ResourceId third_frame_ids[] = {10, 11, 12, 13}; |
| 567 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 430 SubmitCompositorFrameWithResources(third_frame_ids, |
| 568 | 431 arraysize(third_frame_ids)); |
| 569 // child_support1 submits a CompositorFrame without any dependencies. | 432 |
| 570 // DidReceiveCompositorFrameAck should call on immediate activation. | 433 { |
| 571 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(1); | 434 SCOPED_TRACE("third frame"); |
| 572 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | 435 ResourceId expected_returned_ids[] = {2, 3, 4}; |
| 573 MakeCompositorFrame()); | 436 int expected_returned_counts[] = {2, 2, 1}; |
| 574 testing::Mock::VerifyAndClearExpectations(&support_client_); | 437 CheckReturnedResourcesMatchExpected( |
| 575 | 438 expected_returned_ids, expected_returned_counts, |
| 576 // Verify that the child surface is not blocked. | 439 arraysize(expected_returned_counts), gpu::SyncToken()); |
| 577 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 440 } |
| 578 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 441 |
| 579 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 442 // Simulate a ResourceProvider taking a ref on all of the resources. |
| 580 | 443 RefCurrentFrameResources(); |
| 581 // Verify that there's a temporary reference for |child_id1|. | 444 |
| 582 EXPECT_TRUE(HasTemporaryReference(child_id1)); | 445 ResourceId fourth_frame_ids[] = {12, 13}; |
| 583 | 446 SubmitCompositorFrameWithResources(fourth_frame_ids, |
| 584 // parent_support submits a CompositorFrame that depends on |child_id1| | 447 arraysize(fourth_frame_ids)); |
| 585 // (which is already active) and |child_id2|. Thus, the parent should not | 448 |
| 586 // activate immediately. DidReceiveCompositorFrameAck should not be called | 449 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 587 // immediately because the parent CompositorFrame is also blocked on | 450 |
| 588 // |child_id2|. | 451 RefCurrentFrameResources(); |
| 589 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0); | 452 |
| 590 parent_support().SubmitCompositorFrame( | 453 // All resources are still being used by the external reference, so none can |
| 591 parent_id.local_surface_id(), | 454 // be returned to the client. |
| 592 MakeCompositorFrame({child_id1, child_id2})); | 455 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 593 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 456 |
| 594 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 457 // Release resources associated with the first RefCurrentFrameResources() call |
| 595 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 458 // first. |
| 596 UnorderedElementsAre(child_id2)); | 459 { |
| 597 EXPECT_THAT(GetChildReferences(parent_id), IsEmpty()); | 460 ResourceId ids_to_unref[] = {10, 11, 12, 13}; |
| 598 testing::Mock::VerifyAndClearExpectations(&support_client_); | 461 int counts[] = {1, 1, 1, 1}; |
| 599 | 462 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 600 // Verify that there's a temporary reference for |child_id1| that still | 463 } |
| 601 // exists. | 464 |
| 602 EXPECT_TRUE(HasTemporaryReference(child_id1)); | 465 // Nothing is returned to the client yet since DidReceiveCompositorFrameAck |
| 603 | 466 // is not invoked. |
| 604 // child_support2 submits a CompositorFrame without any dependencies. | 467 { |
| 605 // Both the child and the parent should immediately ACK CompositorFrames | 468 SCOPED_TRACE("fourth frame, first unref"); |
| 606 // on activation. | 469 ResourceId expected_returned_ids[] = {}; |
| 607 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2); | 470 int expected_returned_counts[] = {}; |
| 608 child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), | 471 CheckReturnedResourcesMatchExpected(expected_returned_ids, |
| 609 MakeCompositorFrame()); | 472 expected_returned_counts, 0, |
| 610 testing::Mock::VerifyAndClearExpectations(&support_client_); | 473 consumer_sync_token_); |
| 611 | 474 } |
| 612 // Verify that the child surface is not blocked. | 475 |
| 613 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 476 { |
| 614 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 477 ResourceId ids_to_unref[] = {12, 13}; |
| 615 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 478 int counts[] = {1, 1}; |
| 616 | 479 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 617 // Verify that the parent surface's CompositorFrame has activated and that the | 480 } |
| 618 // temporary reference has been replaced by a permanent one. | 481 |
| 619 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 482 // Resources 12 and 13 are still in use by the current frame, so they |
| 620 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 483 // shouldn't be available to be returned. |
| 621 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 484 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 622 EXPECT_FALSE(HasTemporaryReference(child_id1)); | 485 |
| 623 EXPECT_THAT(GetChildReferences(parent_id), | 486 // If we submit an empty frame, however, they should become available. |
| 624 UnorderedElementsAre(child_id1, child_id2)); | 487 // Resources that were previously unref'd also return at this point. |
| 625 } | 488 SubmitCompositorFrameWithResources(NULL, 0u); |
| 626 | 489 |
| 627 // This test verifies that we do not double count returned resources when a | 490 { |
| 628 // CompositorFrame starts out as pending, then becomes active, and then is | 491 SCOPED_TRACE("fourth frame, second unref"); |
| 629 // replaced with another active CompositorFrame. | 492 ResourceId expected_returned_ids[] = {10, 11, 12, 13}; |
| 630 TEST_F(CompositorFrameSinkSupportTest, | 493 int expected_returned_counts[] = {1, 1, 2, 2}; |
| 631 DisplayCompositorLockingResourcesOnlyReturnedOnce) { | 494 CheckReturnedResourcesMatchExpected( |
| 632 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 495 expected_returned_ids, expected_returned_counts, |
| 633 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | 496 arraysize(expected_returned_counts), consumer_sync_token_); |
| 634 | 497 } |
| 635 // The parent submits a CompositorFrame that depends on |child_id| before the | 498 } |
| 636 // child submits a CompositorFrame. The CompositorFrame also has resources in | 499 |
| 637 // its resource list. | 500 TEST_F(CompositorFrameSinkSupportTest, BlankNoIndexIncrement) { |
| 638 TransferableResource resource = | 501 LocalSurfaceId local_surface_id(6, kArbitraryToken); |
| 639 MakeResource(1337 /* id */, ALPHA_8 /* format */, 1234 /* filter */, | 502 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); |
| 640 gfx::Size(1234, 5678)); | 503 support_->SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); |
| 641 TransferableResourceArray resource_list = {resource}; | 504 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 642 parent_support().SubmitCompositorFrame( | 505 ASSERT_NE(nullptr, surface); |
| 643 parent_id.local_surface_id(), | 506 EXPECT_EQ(2, surface->frame_index()); |
| 644 MakeCompositorFrameWithResources({child_id}, resource_list)); | 507 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 645 | 508 } |
| 646 // Verify that the CompositorFrame is blocked on |child_id|. | 509 |
| 647 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 510 TEST_F(CompositorFrameSinkSupportTest, AddDuringEviction) { |
| 648 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 511 constexpr bool kAddDuringEviction = true; |
| 649 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 512 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 650 UnorderedElementsAre(child_id)); | 513 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 651 | 514 CompositorFrameSinkSupport::Create( |
| 652 child_support1().SubmitCompositorFrame( | 515 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 653 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 516 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 654 | 517 mock_client.set_support(support.get()); |
| 655 // Verify that the child CompositorFrame activates immediately. | 518 LocalSurfaceId local_surface_id(6, kArbitraryToken); |
| 656 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 519 |
| 657 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 520 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(0); |
| 658 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 521 support->SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); |
| 659 | 522 |
| 660 // Verify that the parent has activated. | 523 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(2); |
| 661 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 524 support->EvictFrame(); |
| 662 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 525 } |
| 663 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 526 |
| 664 | 527 // Tests doing an EvictFrame before shutting down the factory. |
| 665 // The parent submits a CompositorFrame without any dependencies. That frame | 528 TEST_F(CompositorFrameSinkSupportTest, EvictFrame) { |
| 666 // should activate immediately, replacing the earlier frame. The resource from | 529 constexpr bool kAddDuringEviction = false; |
| 667 // the earlier frame should be returned to the client. | 530 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 668 parent_support().SubmitCompositorFrame( | 531 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 669 parent_id.local_surface_id(), MakeCompositorFrame({empty_surface_ids()})); | 532 CompositorFrameSinkSupport::Create( |
| 670 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 533 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 671 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 534 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 672 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 535 mock_client.set_support(support.get()); |
| 673 ReturnedResource returned_resource = resource.ToReturnedResource(); | 536 LocalSurfaceId local_surface_id(7, kArbitraryToken); |
| 674 EXPECT_THAT(support_client_.last_returned_resources(), | 537 SurfaceId id(kAnotherArbitraryFrameSinkId, local_surface_id); |
| 675 UnorderedElementsAre(returned_resource)); | 538 |
| 676 } | 539 TransferableResource resource; |
| 677 | 540 resource.id = 1; |
| 678 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. | 541 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 679 // child_support1 evicts its blocked Surface. The parent surface should | |
| 680 // activate. | |
| 681 TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceWithPendingFrame) { | |
| 682 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 683 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | |
| 684 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | |
| 685 | |
| 686 // Submit a CompositorFrame that depends on |child_id1|. | |
| 687 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | |
| 688 MakeCompositorFrame({child_id1})); | |
| 689 | |
| 690 // Verify that the CompositorFrame is blocked on |child_id1|. | |
| 691 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | |
| 692 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | |
| 693 EXPECT_THAT(parent_surface()->blocking_surfaces(), | |
| 694 UnorderedElementsAre(child_id1)); | |
| 695 | |
| 696 // Submit a CompositorFrame that depends on |child_id2|. | |
| 697 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | |
| 698 MakeCompositorFrame({child_id2})); | |
| 699 | |
| 700 // Verify that the CompositorFrame is blocked on |child_id2|. | |
| 701 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | |
| 702 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | |
| 703 EXPECT_THAT(child_surface1()->blocking_surfaces(), | |
| 704 UnorderedElementsAre(child_id2)); | |
| 705 | |
| 706 // Evict child_support1's current Surface. | |
| 707 // TODO(fsamuel): EvictFrame => EvictCurrentSurface. | |
| 708 child_support1().EvictFrame(); | |
| 709 | |
| 710 // The parent Surface should immediately activate. | |
| 711 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 712 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 713 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | |
| 714 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 715 } | |
| 716 | |
| 717 // This test verifies that if a surface has both a pending and active | |
| 718 // CompositorFrame and the pending CompositorFrame activates, replacing the | |
| 719 // existing active CompositorFrame, then the surface reference hierarchy will be | |
| 720 // updated allowing garbage collection of surfaces that are no longer | |
| 721 // referenced. | |
| 722 TEST_F(CompositorFrameSinkSupportTest, DropStaleReferencesAfterActivation) { | |
| 723 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | |
| 724 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | |
| 725 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | |
| 726 | |
| 727 // The parent submits a CompositorFrame that depends on |child_id1| before the | |
| 728 // child submits a CompositorFrame. | |
| 729 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0); | |
| 730 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 731 MakeCompositorFrame({child_id1})); | |
| 732 | |
| 733 // Verify that the CompositorFrame is blocked on |child_id|. | |
| 734 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | |
| 735 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | |
| 736 EXPECT_THAT(parent_surface()->blocking_surfaces(), | |
| 737 UnorderedElementsAre(child_id1)); | |
| 738 testing::Mock::VerifyAndClearExpectations(&support_client_); | |
| 739 | |
| 740 // Verify that no references are added while the CompositorFrame is pending. | |
| 741 EXPECT_THAT(GetChildReferences(parent_id), IsEmpty()); | |
| 742 | |
| 743 // DidReceiveCompositorFrameAck should get called twice: once for the child | |
| 744 // and once for the now active parent CompositorFrame. | |
| 745 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2); | |
| 746 child_support1().SubmitCompositorFrame( | |
| 747 child_id1.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 748 testing::Mock::VerifyAndClearExpectations(&support_client_); | |
| 749 | |
| 750 // Verify that the child CompositorFrame activates immediately. | |
| 751 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | |
| 752 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | |
| 753 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | |
| 754 | |
| 755 // Verify that the parent Surface has activated. | |
| 756 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 757 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 758 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | |
| 759 | |
| 760 // Verify that there is no temporary reference for the child and that | |
| 761 // the reference from the parent to the child still exists. | |
| 762 EXPECT_FALSE(HasTemporaryReference(child_id1)); | |
| 763 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id1)); | |
| 764 | |
| 765 // The parent submits another CompositorFrame that depends on |child_id2|. | |
| 766 // Submitting a pending CompositorFrame will not trigger a CompositorFrameAck. | |
| 767 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0); | |
| 768 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 769 MakeCompositorFrame({child_id2})); | |
| 770 testing::Mock::VerifyAndClearExpectations(&support_client_); | |
| 771 | |
| 772 // The parent surface should now have both a pending and activate | |
| 773 // CompositorFrame. Verify that the set of child references from | |
| 774 // |parent_id| are only from the active CompositorFrame. | |
| 775 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 776 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | |
| 777 EXPECT_THAT(parent_surface()->blocking_surfaces(), | |
| 778 UnorderedElementsAre(child_id2)); | |
| 779 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id1)); | |
| 780 | |
| 781 child_support2().SubmitCompositorFrame( | |
| 782 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 783 | |
| 784 // Verify that the parent Surface has activated and no longer has a pending | |
| 785 // CompositorFrame. Also verify that |child_id1| is no longer a child | |
| 786 // reference of |parent_id|. | |
| 787 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 788 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 789 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | |
| 790 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); | |
| 791 } | |
| 792 | |
| 793 // Checks whether the latency info are moved to the new surface from the old | |
| 794 // one when LocalSurfaceId changes. No frame has unresolved dependencies. | |
| 795 TEST_F(CompositorFrameSinkSupportTest, | |
| 796 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { | |
| 797 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 798 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | |
| 799 const ui::LatencyComponentType latency_type1 = | |
| 800 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; | |
| 801 const int64_t latency_id1 = 234; | |
| 802 const int64_t latency_sequence_number1 = 5645432; | |
| 803 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; | |
| 804 const int64_t latency_id2 = 31434351; | |
| 805 const int64_t latency_sequence_number2 = 663788; | |
| 806 | |
| 807 // Submit a frame with latency info | |
| 808 ui::LatencyInfo info; | |
| 809 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); | |
| 810 | |
| 811 CompositorFrame frame = MakeCompositorFrame(); | 542 CompositorFrame frame = MakeCompositorFrame(); |
| 812 frame.metadata.latency_info.push_back(info); | 543 frame.resource_list.push_back(resource); |
| 813 | 544 support->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 814 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 545 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 815 std::move(frame)); | 546 local_surface_id_ = LocalSurfaceId(); |
| 816 | 547 |
| 817 // Verify that the old surface has an active frame and no pending frame. | 548 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 818 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 549 EXPECT_TRUE(mock_client.last_returned_resources().empty()); |
| 819 ASSERT_NE(nullptr, old_surface); | 550 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(1); |
| 820 EXPECT_TRUE(old_surface->HasActiveFrame()); | 551 support->EvictFrame(); |
| 821 EXPECT_FALSE(old_surface->HasPendingFrame()); | 552 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 822 | 553 EXPECT_FALSE(mock_client.last_returned_resources().empty()); |
| 823 // Submit another frame with some other latency info and a different | 554 } |
| 824 // LocalSurfaceId. | 555 |
| 825 ui::LatencyInfo info2; | 556 // Tests doing an EvictSurface which has unregistered dependency. |
| 826 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 557 TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceDependencyUnRegistered) { |
| 827 | 558 constexpr bool kAddDuringEviction = false; |
| 828 CompositorFrame frame2 = MakeCompositorFrame(); | 559 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 829 frame2.metadata.latency_info.push_back(info2); | 560 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 830 | 561 CompositorFrameSinkSupport::Create( |
| 831 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 562 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 832 std::move(frame2)); | 563 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 833 | 564 mock_client.set_support(support.get()); |
| 834 // Verify that the new surface has an active frame and no pending frames. | 565 LocalSurfaceId local_surface_id(7, kArbitraryToken); |
| 835 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 566 |
| 836 ASSERT_NE(nullptr, surface); | 567 TransferableResource resource; |
| 837 EXPECT_TRUE(surface->HasActiveFrame()); | 568 resource.id = 1; |
| 838 EXPECT_FALSE(surface->HasPendingFrame()); | 569 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 839 | |
| 840 // Verify that the new surface has both latency info elements. | |
| 841 std::vector<ui::LatencyInfo> info_list; | |
| 842 surface->TakeLatencyInfo(&info_list); | |
| 843 EXPECT_EQ(2u, info_list.size()); | |
| 844 | |
| 845 ui::LatencyInfo aggregated_latency_info = info_list[0]; | |
| 846 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | |
| 847 | |
| 848 // Two components are the original ones, and the third one is | |
| 849 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | |
| 850 // submit. | |
| 851 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | |
| 852 | |
| 853 ui::LatencyInfo::LatencyComponent comp1; | |
| 854 EXPECT_TRUE( | |
| 855 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | |
| 856 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | |
| 857 EXPECT_TRUE( | |
| 858 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | |
| 859 EXPECT_TRUE(aggregated_latency_info.FindLatency( | |
| 860 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | |
| 861 } | |
| 862 | |
| 863 // Checks whether the latency info are moved to the new surface from the old | |
| 864 // one when LocalSurfaceId changes. Old surface has unresolved dependencies. | |
| 865 TEST_F(CompositorFrameSinkSupportTest, | |
| 866 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { | |
| 867 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 868 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | |
| 869 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | |
| 870 | |
| 871 const ui::LatencyComponentType latency_type1 = | |
| 872 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; | |
| 873 const int64_t latency_id1 = 234; | |
| 874 const int64_t latency_sequence_number1 = 5645432; | |
| 875 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; | |
| 876 const int64_t latency_id2 = 31434351; | |
| 877 const int64_t latency_sequence_number2 = 663788; | |
| 878 | |
| 879 // Submit a frame with no unresolved dependecy. | |
| 880 ui::LatencyInfo info; | |
| 881 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); | |
| 882 | |
| 883 CompositorFrame frame = MakeCompositorFrame(); | 570 CompositorFrame frame = MakeCompositorFrame(); |
| 884 frame.metadata.latency_info.push_back(info); | 571 frame.resource_list.push_back(resource); |
| 885 | 572 support->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 886 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 573 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 887 std::move(frame)); | 574 local_surface_id_ = LocalSurfaceId(); |
| 888 | 575 |
| 889 // Submit a frame with unresolved dependencies. | 576 SurfaceId surface_id(kAnotherArbitraryFrameSinkId, local_surface_id); |
| 890 ui::LatencyInfo info2; | 577 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 891 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 578 surface->AddDestructionDependency( |
| 892 | 579 SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 893 CompositorFrame frame2 = MakeCompositorFrame({child_id}); | 580 |
| 894 frame2.metadata.latency_info.push_back(info2); | 581 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); |
| 895 | 582 EXPECT_TRUE(mock_client.last_returned_resources().empty()); |
| 896 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 583 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(1); |
| 897 std::move(frame2)); | 584 support->EvictFrame(); |
| 898 | 585 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); |
| 899 // Verify that the old surface has both an active and a pending frame. | 586 EXPECT_FALSE(mock_client.last_returned_resources().empty()); |
| 900 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 587 } |
| 901 ASSERT_NE(nullptr, old_surface); | 588 |
| 902 EXPECT_TRUE(old_surface->HasActiveFrame()); | 589 // Tests doing an EvictSurface which has registered dependency. |
| 903 EXPECT_TRUE(old_surface->HasPendingFrame()); | 590 TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceDependencyRegistered) { |
| 904 | 591 constexpr bool kAddDuringEviction = false; |
| 905 // Submit a frame with a new local surface id. | 592 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 906 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 593 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 907 MakeCompositorFrame()); | 594 CompositorFrameSinkSupport::Create( |
| 908 | 595 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 909 // Verify that the new surface has an active frame only. | 596 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 910 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 597 mock_client.set_support(support.get()); |
| 911 ASSERT_NE(nullptr, surface); | 598 LocalSurfaceId local_surface_id(7, kArbitraryToken); |
| 912 EXPECT_TRUE(surface->HasActiveFrame()); | 599 |
| 913 EXPECT_FALSE(surface->HasPendingFrame()); | 600 TransferableResource resource; |
| 914 | 601 resource.id = 1; |
| 915 // Verify that the new surface has latency info from both active and pending | 602 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 916 // frame of the old surface. | |
| 917 std::vector<ui::LatencyInfo> info_list; | |
| 918 surface->TakeLatencyInfo(&info_list); | |
| 919 EXPECT_EQ(2u, info_list.size()); | |
| 920 | |
| 921 ui::LatencyInfo aggregated_latency_info = info_list[0]; | |
| 922 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | |
| 923 | |
| 924 // Two components are the original ones, and the third one is | |
| 925 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | |
| 926 // submit. | |
| 927 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | |
| 928 | |
| 929 ui::LatencyInfo::LatencyComponent comp1; | |
| 930 EXPECT_TRUE( | |
| 931 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | |
| 932 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | |
| 933 EXPECT_TRUE( | |
| 934 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | |
| 935 EXPECT_TRUE(aggregated_latency_info.FindLatency( | |
| 936 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | |
| 937 } | |
| 938 | |
| 939 // Checks whether the latency info are moved to the new surface from the old | |
| 940 // one when LocalSurfaceId changes. The new surface has unresolved dependencies. | |
| 941 TEST_F(CompositorFrameSinkSupportTest, | |
| 942 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { | |
| 943 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 944 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | |
| 945 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | |
| 946 | |
| 947 const ui::LatencyComponentType latency_type1 = | |
| 948 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; | |
| 949 const int64_t latency_id1 = 234; | |
| 950 const int64_t latency_sequence_number1 = 5645432; | |
| 951 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; | |
| 952 const int64_t latency_id2 = 31434351; | |
| 953 const int64_t latency_sequence_number2 = 663788; | |
| 954 | |
| 955 // Submit a frame with no unresolved dependencies. | |
| 956 ui::LatencyInfo info; | |
| 957 info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); | |
| 958 | |
| 959 CompositorFrame frame = MakeCompositorFrame(); | 603 CompositorFrame frame = MakeCompositorFrame(); |
| 960 frame.metadata.latency_info.push_back(info); | 604 frame.resource_list.push_back(resource); |
| 961 | 605 uint32_t execute_count = 0; |
| 962 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 606 support->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 963 std::move(frame)); | 607 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 964 | 608 local_surface_id_ = LocalSurfaceId(); |
| 965 // Verify that the old surface has an active frame only. | 609 |
| 966 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 610 manager_.RegisterFrameSinkId(kYetAnotherArbitraryFrameSinkId); |
| 967 ASSERT_NE(nullptr, old_surface); | 611 |
| 968 EXPECT_TRUE(old_surface->HasActiveFrame()); | 612 SurfaceId surface_id(kAnotherArbitraryFrameSinkId, local_surface_id); |
| 969 EXPECT_FALSE(old_surface->HasPendingFrame()); | 613 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 970 | 614 surface->AddDestructionDependency( |
| 971 // Submit a frame with a new local surface id and with unresolved | 615 SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 972 // dependencies. | 616 |
| 973 ui::LatencyInfo info2; | 617 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); |
| 974 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 618 EXPECT_TRUE(mock_client.last_returned_resources().empty()); |
| 975 | 619 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(1); |
| 976 CompositorFrame frame2 = MakeCompositorFrame({child_id}); | 620 support->EvictFrame(); |
| 977 frame2.metadata.latency_info.push_back(info2); | 621 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); |
| 978 | 622 EXPECT_TRUE(mock_client.last_returned_resources().empty()); |
| 979 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 623 EXPECT_EQ(0u, execute_count); |
| 980 std::move(frame2)); | 624 |
| 981 | 625 manager_.SatisfySequence(SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 982 // Verify that the new surface has a pending frame and no active frame. | 626 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); |
| 983 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 627 EXPECT_FALSE(mock_client.last_returned_resources().empty()); |
| 984 ASSERT_NE(nullptr, surface); | 628 } |
| 985 EXPECT_TRUE(surface->HasPendingFrame()); | 629 |
| 986 EXPECT_FALSE(surface->HasActiveFrame()); | 630 TEST_F(CompositorFrameSinkSupportTest, DestroySequence) { |
| 987 | 631 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 988 // Resolve the dependencies. The frame in parent's surface must become active. | 632 std::unique_ptr<CompositorFrameSinkSupport> support2 = |
| 989 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 633 CompositorFrameSinkSupport::Create( |
| 990 MakeCompositorFrame()); | 634 &fake_support_client_, &manager_, kYetAnotherArbitraryFrameSinkId, |
| 991 EXPECT_FALSE(surface->HasPendingFrame()); | 635 kIsChildRoot, kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 992 EXPECT_TRUE(surface->HasActiveFrame()); | 636 SurfaceId id2(kYetAnotherArbitraryFrameSinkId, local_surface_id2); |
| 993 | 637 support2->SubmitCompositorFrame(local_surface_id2, MakeCompositorFrame()); |
| 994 // Both latency info elements must exist in the now-activated frame of the | 638 |
| 995 // new surface. | 639 // Check that waiting before the sequence is satisfied works. |
| 996 std::vector<ui::LatencyInfo> info_list; | 640 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 997 surface->TakeLatencyInfo(&info_list); | 641 SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 998 EXPECT_EQ(2u, info_list.size()); | 642 support2->EvictFrame(); |
| 999 | 643 |
| 1000 ui::LatencyInfo aggregated_latency_info = info_list[0]; | 644 DCHECK(manager_.GetSurfaceForId(id2)); |
| 1001 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | 645 manager_.SatisfySequence(SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 1002 | 646 manager_.SatisfySequence(SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 6)); |
| 1003 // Two components are the original ones, and the third one is | 647 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 1004 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | 648 |
| 1005 // submit. | 649 // Check that waiting after the sequence is satisfied works. |
| 1006 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | 650 support2->SubmitCompositorFrame(local_surface_id2, MakeCompositorFrame()); |
| 1007 | 651 DCHECK(manager_.GetSurfaceForId(id2)); |
| 1008 ui::LatencyInfo::LatencyComponent comp1; | 652 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 1009 EXPECT_TRUE( | 653 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); |
| 1010 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | 654 support2->EvictFrame(); |
| 1011 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | 655 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 1012 EXPECT_TRUE( | 656 } |
| 1013 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | 657 |
| 1014 EXPECT_TRUE(aggregated_latency_info.FindLatency( | 658 // Tests that Surface ID namespace invalidation correctly allows |
| 1015 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | 659 // Sequences to be ignored. |
| 1016 } | 660 TEST_F(CompositorFrameSinkSupportTest, InvalidFrameSinkId) { |
| 1017 | 661 FrameSinkId frame_sink_id(1234, 5678); |
| 1018 TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { | 662 |
| 1019 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | 663 LocalSurfaceId local_surface_id(5, kArbitraryToken); |
| 1020 | 664 SurfaceId id(support_->frame_sink_id(), local_surface_id); |
| 1021 // Request BeginFrames. | 665 support_->SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); |
| 1022 display_support().SetNeedsBeginFrame(true); | 666 |
| 1023 | 667 manager_.RegisterFrameSinkId(frame_sink_id); |
| 1024 // Issue a BeginFrame. | 668 manager_.GetSurfaceForId(id)->AddDestructionDependency( |
| 1025 BeginFrameArgs args = | 669 SurfaceSequence(frame_sink_id, 4)); |
| 1026 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | 670 |
| 1027 begin_frame_source()->TestOnBeginFrame(args); | 671 support_->EvictFrame(); |
| 1028 | 672 |
| 1029 // Check that the support forwards a BeginFrameDidNotSwap ack to the | 673 // Verify the dependency has prevented the surface from getting destroyed. |
| 1030 // BeginFrameSource. | 674 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 1031 BeginFrameAck ack(0, 1, 1, false); | 675 |
| 1032 display_support().BeginFrameDidNotSwap(ack); | 676 manager_.InvalidateFrameSinkId(frame_sink_id); |
| 1033 EXPECT_EQ(ack, begin_frame_source()->LastAckForObserver(&display_support())); | 677 |
| 1034 | 678 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 1035 // Issue another BeginFrame. | 679 // to be ignored. |
| 1036 args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 2); | 680 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 1037 begin_frame_source()->TestOnBeginFrame(args); | 681 } |
| 1038 | 682 |
| 1039 // Check that the support forwards the BeginFrameAck attached | 683 TEST_F(CompositorFrameSinkSupportTest, DestroyCycle) { |
| 1040 // to a CompositorFrame to the BeginFrameSource. | 684 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 1041 BeginFrameAck ack2(0, 2, 2, true); | 685 SurfaceId id2(kYetAnotherArbitraryFrameSinkId, local_surface_id2); |
| 686 std::unique_ptr<CompositorFrameSinkSupport> support2 = |
| 687 CompositorFrameSinkSupport::Create( |
| 688 &fake_support_client_, &manager_, kYetAnotherArbitraryFrameSinkId, |
| 689 kIsChildRoot, kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 690 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
| 691 // Give id2 a frame that references local_surface_id_. |
| 692 { |
| 693 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 694 CompositorFrame frame = MakeCompositorFrame(); |
| 695 frame.render_pass_list.push_back(std::move(render_pass)); |
| 696 frame.metadata.referenced_surfaces.push_back( |
| 697 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 698 support2->SubmitCompositorFrame(local_surface_id2, std::move(frame)); |
| 699 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id2); |
| 700 } |
| 701 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 702 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 703 support2->EvictFrame(); |
| 704 // Give local_surface_id_ a frame that references id2. |
| 705 { |
| 706 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 707 CompositorFrame frame = MakeCompositorFrame(); |
| 708 frame.render_pass_list.push_back(std::move(render_pass)); |
| 709 frame.metadata.referenced_surfaces.push_back(id2); |
| 710 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 711 } |
| 712 support_->EvictFrame(); |
| 713 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| 714 // local_surface_id_ should be retained by reference from id2. |
| 715 EXPECT_TRUE(manager_.GetSurfaceForId( |
| 716 SurfaceId(support_->frame_sink_id(), local_surface_id_))); |
| 717 |
| 718 // Satisfy last destruction dependency for id2. |
| 719 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 720 |
| 721 // id2 and local_surface_id_ are in a reference cycle that has no surface |
| 722 // sequences holding on to it, so they should be destroyed. |
| 723 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); |
| 724 EXPECT_TRUE(!manager_.GetSurfaceForId( |
| 725 SurfaceId(support_->frame_sink_id(), local_surface_id_))); |
| 726 |
| 727 local_surface_id_ = LocalSurfaceId(); |
| 728 } |
| 729 |
| 730 void CopyRequestTestCallback(bool* called, |
| 731 std::unique_ptr<CopyOutputResult> result) { |
| 732 *called = true; |
| 733 } |
| 734 |
| 735 TEST_F(CompositorFrameSinkSupportTest, DuplicateCopyRequest) { |
| 736 { |
| 737 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 738 CompositorFrame frame = MakeCompositorFrame(); |
| 739 frame.render_pass_list.push_back(std::move(render_pass)); |
| 740 frame.metadata.referenced_surfaces.push_back( |
| 741 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 742 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 743 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id_); |
| 744 } |
| 745 |
| 746 bool called1 = false; |
| 747 std::unique_ptr<CopyOutputRequest> request; |
| 748 request = CopyOutputRequest::CreateRequest( |
| 749 base::Bind(&CopyRequestTestCallback, &called1)); |
| 750 request->set_source(kArbitrarySourceId1); |
| 751 |
| 752 support_->RequestCopyOfSurface(std::move(request)); |
| 753 EXPECT_FALSE(called1); |
| 754 |
| 755 bool called2 = false; |
| 756 request = CopyOutputRequest::CreateRequest( |
| 757 base::Bind(&CopyRequestTestCallback, &called2)); |
| 758 request->set_source(kArbitrarySourceId2); |
| 759 |
| 760 support_->RequestCopyOfSurface(std::move(request)); |
| 761 // Callbacks have different sources so neither should be called. |
| 762 EXPECT_FALSE(called1); |
| 763 EXPECT_FALSE(called2); |
| 764 |
| 765 bool called3 = false; |
| 766 request = CopyOutputRequest::CreateRequest( |
| 767 base::Bind(&CopyRequestTestCallback, &called3)); |
| 768 request->set_source(kArbitrarySourceId1); |
| 769 |
| 770 support_->RequestCopyOfSurface(std::move(request)); |
| 771 // Two callbacks are from source1, so the first should be called. |
| 772 EXPECT_TRUE(called1); |
| 773 EXPECT_FALSE(called2); |
| 774 EXPECT_FALSE(called3); |
| 775 |
| 776 support_->EvictFrame(); |
| 777 local_surface_id_ = LocalSurfaceId(); |
| 778 EXPECT_TRUE(called1); |
| 779 EXPECT_TRUE(called2); |
| 780 EXPECT_TRUE(called3); |
| 781 } |
| 782 |
| 783 // Check whether the SurfaceInfo object is created and populated correctly |
| 784 // after the frame submission. |
| 785 TEST_F(CompositorFrameSinkSupportTest, SurfaceInfo) { |
| 1042 CompositorFrame frame = MakeCompositorFrame(); | 786 CompositorFrame frame = MakeCompositorFrame(); |
| 1043 frame.metadata.begin_frame_ack = ack2; | 787 |
| 1044 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | 788 auto render_pass = RenderPass::Create(); |
| 1045 std::move(frame)); | 789 render_pass->SetNew(1, gfx::Rect(5, 6), gfx::Rect(), gfx::Transform()); |
| 1046 EXPECT_EQ(ack2, begin_frame_source()->LastAckForObserver(&display_support())); | 790 frame.render_pass_list.push_back(std::move(render_pass)); |
| 1047 } | 791 |
| 1048 | 792 render_pass = RenderPass::Create(); |
| 1049 // Checks that resources and ack are sent together if possible. | 793 render_pass->SetNew(2, gfx::Rect(7, 8), gfx::Rect(), gfx::Transform()); |
| 1050 TEST_F(CompositorFrameSinkSupportTest, ReturnResourcesWithAck) { | 794 frame.render_pass_list.push_back(std::move(render_pass)); |
| 1051 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 795 |
| 1052 TransferableResource resource; | 796 frame.metadata.device_scale_factor = 2.5f; |
| 1053 resource.id = 1234; | 797 |
| 1054 parent_support().SubmitCompositorFrame( | 798 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 1055 parent_id.local_surface_id(), | 799 SurfaceId expected_surface_id(support_->frame_sink_id(), local_surface_id_); |
| 1056 MakeCompositorFrameWithResources(empty_surface_ids(), {resource})); | 800 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); |
| 1057 ReturnedResourceArray returned_resources; | 801 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); |
| 1058 TransferableResource::ReturnResources({resource}, &returned_resources); | 802 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); |
| 1059 EXPECT_CALL(support_client_, ReclaimResources(_)).Times(0); | |
| 1060 EXPECT_CALL(support_client_, | |
| 1061 DidReceiveCompositorFrameAck(Eq(returned_resources))); | |
| 1062 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 1063 MakeCompositorFrame()); | |
| 1064 } | |
| 1065 | |
| 1066 // Verifies that if a surface is marked destroyed and a new frame arrives for | |
| 1067 // it, it will be recovered. | |
| 1068 TEST_F(CompositorFrameSinkSupportTest, SurfaceResurrection) { | |
| 1069 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | |
| 1070 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); | |
| 1071 | |
| 1072 // Add a reference from the parent to the child. | |
| 1073 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 1074 MakeCompositorFrame({child_id})); | |
| 1075 | |
| 1076 // Create the child surface by submitting a frame to it. | |
| 1077 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); | |
| 1078 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | |
| 1079 MakeCompositorFrame()); | |
| 1080 | |
| 1081 // Verify that the child surface is created. | |
| 1082 Surface* surface = surface_manager().GetSurfaceForId(child_id); | |
| 1083 EXPECT_NE(nullptr, surface); | |
| 1084 | |
| 1085 // Attempt to destroy the child surface. The surface must still exist since | |
| 1086 // the parent needs it but it will be marked as destroyed. | |
| 1087 child_support1().EvictFrame(); | |
| 1088 surface = surface_manager().GetSurfaceForId(child_id); | |
| 1089 EXPECT_NE(nullptr, surface); | |
| 1090 EXPECT_TRUE(surface->destroyed()); | |
| 1091 | |
| 1092 // Child submits another frame to the same local surface id that is marked | |
| 1093 // destroyed. | |
| 1094 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | |
| 1095 MakeCompositorFrame()); | |
| 1096 | |
| 1097 // Verify that the surface that was marked destroyed is recovered and is being | |
| 1098 // used again. | |
| 1099 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); | |
| 1100 EXPECT_EQ(surface, surface2); | |
| 1101 EXPECT_FALSE(surface2->destroyed()); | |
| 1102 } | |
| 1103 | |
| 1104 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist | |
| 1105 // anymore, it can still be reused for new surfaces. | |
| 1106 TEST_F(CompositorFrameSinkSupportTest, LocalSurfaceIdIsReusable) { | |
| 1107 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | |
| 1108 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); | |
| 1109 | |
| 1110 // Add a reference from parent. | |
| 1111 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 1112 MakeCompositorFrame({child_id})); | |
| 1113 | |
| 1114 // Submit the first frame. Creates the surface. | |
| 1115 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | |
| 1116 MakeCompositorFrame()); | |
| 1117 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); | |
| 1118 | |
| 1119 // Remove the reference from parant. This allows us to destroy the surface. | |
| 1120 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | |
| 1121 MakeCompositorFrame()); | |
| 1122 | |
| 1123 // Destroy the surface. | |
| 1124 child_support1().EvictFrame(); | |
| 1125 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); | |
| 1126 | |
| 1127 // Submit another frame with the same local surface id. This should work fine | |
| 1128 // and a new surface must be created. | |
| 1129 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | |
| 1130 MakeCompositorFrame()); | |
| 1131 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); | |
| 1132 } | |
| 1133 | |
| 1134 // This test verifies that a crash does not occur if garbage collection is | |
| 1135 // triggered during surface dependency resolution. This test triggers garbage | |
| 1136 // collection during surface resolution, by causing an activation to remove | |
| 1137 // a surface subtree from the root. Both the old subtree and the new | |
| 1138 // activated subtree refer to the same dependency. The old subtree was activated | |
| 1139 // by deadline, and the new subtree was activated by a dependency finally | |
| 1140 // resolving. | |
| 1141 TEST_F(CompositorFrameSinkSupportTest, DependencyTrackingGarbageCollection) { | |
| 1142 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
| 1143 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 1144 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | |
| 1145 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | |
| 1146 | |
| 1147 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | |
| 1148 MakeCompositorFrame({child_id})); | |
| 1149 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | |
| 1150 MakeCompositorFrame({parent_id1})); | |
| 1151 | |
| 1152 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1153 | |
| 1154 BeginFrameArgs args = | |
| 1155 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | |
| 1156 | |
| 1157 // Advance BeginFrames to trigger a deadline. | |
| 1158 for (int i = 0; i < 3; ++i) { | |
| 1159 begin_frame_source()->TestOnBeginFrame(args); | |
| 1160 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1161 } | |
| 1162 begin_frame_source()->TestOnBeginFrame(args); | |
| 1163 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 1164 | |
| 1165 EXPECT_TRUE(display_surface()->HasActiveFrame()); | |
| 1166 EXPECT_FALSE(display_surface()->HasPendingFrame()); | |
| 1167 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 1168 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 1169 | |
| 1170 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | |
| 1171 MakeCompositorFrame({child_id})); | |
| 1172 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | |
| 1173 MakeCompositorFrame({parent_id2})); | |
| 1174 | |
| 1175 // The display surface now has two CompositorFrames. One that is pending, | |
| 1176 // indirectly blocked on child_id and one that is active, also indirectly | |
| 1177 // referring to child_id, but activated due to the deadline above. | |
| 1178 EXPECT_TRUE(display_surface()->HasActiveFrame()); | |
| 1179 EXPECT_TRUE(display_surface()->HasPendingFrame()); | |
| 1180 | |
| 1181 // Submitting a CompositorFrame will trigger garbage collection of the | |
| 1182 // |parent_id1| subtree. This should not crash. | |
| 1183 child_support1().SubmitCompositorFrame( | |
| 1184 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | |
| 1185 } | |
| 1186 | |
| 1187 // This test verifies that a crash does not occur if garbage collection is | |
| 1188 // triggered when a deadline forces frame activation. This test triggers garbage | |
| 1189 // collection during deadline activation by causing the activation of a display | |
| 1190 // frame to replace a previously activated display frame that was referring to | |
| 1191 // a now-unreachable surface subtree. That subtree gets garbage collected during | |
| 1192 // deadline activation. SurfaceDependencyTracker is also tracking a surface | |
| 1193 // from that subtree due to an unresolved dependency. This test verifies that | |
| 1194 // this dependency resolution does not crash. | |
| 1195 TEST_F(CompositorFrameSinkSupportTest, GarbageCollectionOnDeadline) { | |
| 1196 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
| 1197 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 1198 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | |
| 1199 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | |
| 1200 | |
| 1201 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | |
| 1202 MakeCompositorFrame({parent_id1})); | |
| 1203 | |
| 1204 EXPECT_TRUE(display_surface()->HasPendingFrame()); | |
| 1205 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1206 EXPECT_FALSE(display_surface()->HasActiveFrame()); | |
| 1207 | |
| 1208 // Advance BeginFrames to trigger a deadline. This activates the | |
| 1209 // CompositorFrame submitted above. | |
| 1210 BeginFrameArgs args = | |
| 1211 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | |
| 1212 for (int i = 0; i < 3; ++i) { | |
| 1213 begin_frame_source()->TestOnBeginFrame(args); | |
| 1214 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1215 } | |
| 1216 begin_frame_source()->TestOnBeginFrame(args); | |
| 1217 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 1218 EXPECT_FALSE(display_surface()->HasPendingFrame()); | |
| 1219 EXPECT_TRUE(display_surface()->HasActiveFrame()); | |
| 1220 | |
| 1221 // |parent_id1| is blocked on |child_id|, but |display_id|'s CompositorFrame | |
| 1222 // has activated due to a deadline. |parent_id1| will be tracked by the | |
| 1223 // SurfaceDependencyTracker. | |
| 1224 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | |
| 1225 MakeCompositorFrame({child_id})); | |
| 1226 | |
| 1227 // By submitting a display CompositorFrame, and replacing the parent's | |
| 1228 // CompositorFrame with another surface ID, parent_id1 becomes unreachable and | |
| 1229 // a candidate for garbage collection. | |
| 1230 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | |
| 1231 MakeCompositorFrame({parent_id2})); | |
| 1232 | |
| 1233 // Now |parent_id1| is only kept alive by the active |display_id| frame. | |
| 1234 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | |
| 1235 MakeCompositorFrame({child_id})); | |
| 1236 | |
| 1237 // SurfaceDependencyTracker should now be tracking |display_id|, |parent_id1| | |
| 1238 // and |parent_id2|. By activating the pending |display_id| frame by deadline, | |
| 1239 // |parent_id1| becomes unreachable and is garbage collected while | |
| 1240 // SurfaceDependencyTracker is in the process of activating surfaces. This | |
| 1241 // should not cause a crash or use-after-free. | |
| 1242 for (int i = 0; i < 3; ++i) { | |
| 1243 begin_frame_source()->TestOnBeginFrame(args); | |
| 1244 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1245 } | |
| 1246 begin_frame_source()->TestOnBeginFrame(args); | |
| 1247 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 1248 } | |
| 1249 | |
| 1250 // This test verifies that a CompositorFrame will only blocked on embedded | |
| 1251 // surfaces but not on other retained surface IDs in the CompositorFrame. | |
| 1252 TEST_F(CompositorFrameSinkSupportTest, OnlyBlockOnEmbeddedSurfaces) { | |
| 1253 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
| 1254 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 1255 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); | |
| 1256 | |
| 1257 display_support().SubmitCompositorFrame( | |
| 1258 display_id.local_surface_id(), | |
| 1259 MakeCompositorFrame({parent_id1}, {parent_id1, parent_id2})); | |
| 1260 | |
| 1261 EXPECT_TRUE(display_surface()->HasPendingFrame()); | |
| 1262 EXPECT_FALSE(display_surface()->HasActiveFrame()); | |
| 1263 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1264 | |
| 1265 // Verify that the display CompositorFrame will only block on |parent_id1| but | |
| 1266 // not |parent_id2|. | |
| 1267 EXPECT_THAT(display_surface()->blocking_surfaces(), | |
| 1268 UnorderedElementsAre(parent_id1)); | |
| 1269 // Verify that the display surface holds no references while its | |
| 1270 // CompositorFrame is pending. | |
| 1271 EXPECT_THAT(GetChildReferences(display_id), IsEmpty()); | |
| 1272 | |
| 1273 // Submitting a CompositorFrame with |parent_id1| should unblock the display | |
| 1274 // CompositorFrame. | |
| 1275 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | |
| 1276 MakeCompositorFrame()); | |
| 1277 | |
| 1278 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 1279 EXPECT_FALSE(display_surface()->HasPendingFrame()); | |
| 1280 EXPECT_TRUE(display_surface()->HasActiveFrame()); | |
| 1281 EXPECT_THAT(display_surface()->blocking_surfaces(), IsEmpty()); | |
| 1282 | |
| 1283 // Only a reference to |parent_id1| is added because |parent_id2| does not | |
| 1284 // exist. | |
| 1285 EXPECT_THAT(GetChildReferences(display_id), UnorderedElementsAre(parent_id1)); | |
| 1286 } | |
| 1287 | |
| 1288 // This test verifies that a late arriving CompositorFrame activates immediately | |
| 1289 // and does not trigger a new deadline. | |
| 1290 TEST_F(CompositorFrameSinkSupportTest, LateArrivingDependency) { | |
| 1291 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
| 1292 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); | |
| 1293 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | |
| 1294 | |
| 1295 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | |
| 1296 MakeCompositorFrame({parent_id1})); | |
| 1297 | |
| 1298 EXPECT_TRUE(display_surface()->HasPendingFrame()); | |
| 1299 EXPECT_FALSE(display_surface()->HasActiveFrame()); | |
| 1300 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1301 | |
| 1302 // Advance BeginFrames to trigger a deadline. This activates the | |
| 1303 // CompositorFrame submitted above. | |
| 1304 BeginFrameArgs args = | |
| 1305 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | |
| 1306 for (int i = 0; i < 3; ++i) { | |
| 1307 begin_frame_source()->TestOnBeginFrame(args); | |
| 1308 EXPECT_TRUE(dependency_tracker().has_deadline()); | |
| 1309 } | |
| 1310 begin_frame_source()->TestOnBeginFrame(args); | |
| 1311 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 1312 EXPECT_FALSE(display_surface()->HasPendingFrame()); | |
| 1313 EXPECT_TRUE(display_surface()->HasActiveFrame()); | |
| 1314 | |
| 1315 // A late arriving CompositorFrame should activate immediately without | |
| 1316 // scheduling a deadline and without waiting for dependencies to resolve. | |
| 1317 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | |
| 1318 MakeCompositorFrame({child_id1})); | |
| 1319 EXPECT_FALSE(dependency_tracker().has_deadline()); | |
| 1320 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | |
| 1321 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | |
| 1322 } | 803 } |
| 1323 | 804 |
| 1324 } // namespace test | 805 } // namespace test |
| 1325 } // namespace cc | 806 } // namespace cc |
| OLD | NEW |