| 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 ~CompositorFrameSinkSupportTest() override { |
| 146 return parent_support().ReferenceTrackerForTesting(); | 111 manager_.RemoveObserver(this); |
| 147 } | 112 support_->EvictFrame(); |
| 148 | 113 } |
| 149 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } | 114 |
| 150 Surface* child_surface1() { | 115 const SurfaceId& last_created_surface_id() const { |
| 151 return child_support1().current_surface_for_testing(); | 116 return last_created_surface_id_; |
| 152 } | 117 } |
| 153 | 118 |
| 154 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } | 119 // SurfaceObserver implementation. |
| 155 Surface* child_surface2() { | 120 void OnSurfaceCreated(const SurfaceInfo& surface_info) override { |
| 156 return child_support2().current_surface_for_testing(); | 121 last_created_surface_id_ = surface_info.id(); |
| 157 } | 122 last_surface_info_ = surface_info; |
| 158 | 123 } |
| 159 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } | 124 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { |
| 160 Surface* surface(int index) { | 125 *changed = true; |
| 161 return support(index).current_surface_for_testing(); | 126 } |
| 162 } | 127 |
| 163 | 128 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 164 SurfaceManager& surface_manager() { return surface_manager_; } | 129 size_t num_resource_ids) { |
| 165 | 130 CompositorFrame frame = MakeCompositorFrame(); |
| 166 // Returns all the references where |surface_id| is the parent. | 131 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 167 const SurfaceManager::SurfaceIdSet& GetChildReferences( | 132 TransferableResource resource; |
| 168 const SurfaceId& surface_id) { | 133 resource.id = resource_ids[i]; |
| 169 return surface_manager().parent_to_child_refs_[surface_id]; | 134 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 170 } | 135 resource.mailbox_holder.sync_token = frame_sync_token_; |
| 171 | 136 frame.resource_list.push_back(resource); |
| 172 // Returns true if there is a temporary reference for |surface_id|. | 137 } |
| 173 bool HasTemporaryReference(const SurfaceId& surface_id) { | 138 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 174 return surface_manager().HasTemporaryReference(surface_id); | 139 EXPECT_EQ(last_created_surface_id_.local_surface_id(), local_surface_id_); |
| 175 } | 140 } |
| 176 | 141 |
| 177 SurfaceDependencyTracker& dependency_tracker() { | 142 void UnrefResources(ResourceId* ids_to_unref, |
| 178 return *surface_manager_.dependency_tracker(); | 143 int* counts_to_unref, |
| 179 } | 144 size_t num_ids_to_unref) { |
| 180 | 145 ReturnedResourceArray unref_array; |
| 181 FakeExternalBeginFrameSource* begin_frame_source() { | 146 for (size_t i = 0; i < num_ids_to_unref; ++i) { |
| 182 return begin_frame_source_.get(); | 147 ReturnedResource resource; |
| 183 } | 148 resource.sync_token = consumer_sync_token_; |
| 184 | 149 resource.id = ids_to_unref[i]; |
| 185 // testing::Test: | 150 resource.count = counts_to_unref[i]; |
| 186 void SetUp() override { | 151 unref_array.push_back(resource); |
| 187 testing::Test::SetUp(); | 152 } |
| 188 constexpr bool is_root = true; | 153 support_->UnrefResources(unref_array); |
| 189 constexpr bool is_child_root = false; | 154 } |
| 190 constexpr bool handles_frame_sink_id_invalidation = true; | 155 |
| 191 constexpr bool needs_sync_points = true; | 156 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids, |
| 192 begin_frame_source_ = | 157 int* expected_returned_counts, |
| 193 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); | 158 size_t expected_resources, |
| 194 surface_manager_.SetDependencyTracker( | 159 gpu::SyncToken expected_sync_token) { |
| 195 base::MakeUnique<SurfaceDependencyTracker>(&surface_manager_, | 160 const ReturnedResourceArray& actual_resources = |
| 196 begin_frame_source_.get())); | 161 fake_support_client_.returned_resources(); |
| 197 surface_manager_.AddObserver(this); | 162 ASSERT_EQ(expected_resources, actual_resources.size()); |
| 198 supports_.push_back(CompositorFrameSinkSupport::Create( | 163 for (size_t i = 0; i < expected_resources; ++i) { |
| 199 &support_client_, &surface_manager_, kDisplayFrameSink, is_root, | 164 ReturnedResource resource = actual_resources[i]; |
| 200 handles_frame_sink_id_invalidation, needs_sync_points)); | 165 EXPECT_EQ(expected_sync_token, resource.sync_token); |
| 201 supports_.push_back(CompositorFrameSinkSupport::Create( | 166 EXPECT_EQ(expected_returned_ids[i], resource.id); |
| 202 &support_client_, &surface_manager_, kParentFrameSink, is_child_root, | 167 EXPECT_EQ(expected_returned_counts[i], resource.count); |
| 203 handles_frame_sink_id_invalidation, needs_sync_points)); | 168 } |
| 204 supports_.push_back(CompositorFrameSinkSupport::Create( | 169 fake_support_client_.clear_returned_resources(); |
| 205 &support_client_, &surface_manager_, kChildFrameSink1, is_child_root, | 170 } |
| 206 handles_frame_sink_id_invalidation, needs_sync_points)); | 171 |
| 207 supports_.push_back(CompositorFrameSinkSupport::Create( | 172 void RefCurrentFrameResources() { |
| 208 &support_client_, &surface_manager_, kChildFrameSink2, is_child_root, | 173 Surface* surface = manager_.GetSurfaceForId( |
| 209 handles_frame_sink_id_invalidation, needs_sync_points)); | 174 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 210 | 175 support_->RefResources(surface->GetActiveFrame().resource_list); |
| 211 // Normally, the BeginFrameSource would be registered by the Display. We | |
| 212 // register it here so that BeginFrames are received by the display support, | |
| 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 } | 176 } |
| 242 | 177 |
| 243 protected: | 178 protected: |
| 244 testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_; | 179 SurfaceManager manager_; |
| 245 | 180 FakeCompositorFrameSinkSupportClient fake_support_client_; |
| 246 private: | 181 std::unique_ptr<CompositorFrameSinkSupport> support_; |
| 247 base::flat_set<SurfaceId> damaged_surfaces_; | 182 LocalSurfaceId local_surface_id_; |
| 248 SurfaceManager surface_manager_; | 183 SurfaceId last_created_surface_id_; |
| 249 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; | 184 SurfaceInfo last_surface_info_; |
| 250 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; | 185 |
| 251 | 186 // This is the sync token submitted with the frame. It should never be |
| 252 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); | 187 // returned to the client. |
| 188 const gpu::SyncToken frame_sync_token_; |
| 189 |
| 190 // This is the sync token returned by the consumer. It should always be |
| 191 // returned to the client. |
| 192 const gpu::SyncToken consumer_sync_token_; |
| 253 }; | 193 }; |
| 254 | 194 |
| 255 // The display root surface should have a surface reference from the top-level | 195 // 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. | 196 // with no resource provider action in between. |
| 257 TEST_F(CompositorFrameSinkSupportTest, RootSurfaceReceivesReferences) { | 197 TEST_F(CompositorFrameSinkSupportTest, ResourceLifetimeSimple) { |
| 258 const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1); | 198 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 259 const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2); | 199 SubmitCompositorFrameWithResources(first_frame_ids, |
| 260 | 200 arraysize(first_frame_ids)); |
| 261 // Submit a CompositorFrame for the first display root surface. | 201 |
| 262 display_support().SubmitCompositorFrame(display_id_first.local_surface_id(), | 202 // All of the resources submitted in the first frame are still in use at this |
| 263 MakeCompositorFrame()); | 203 // time by virtue of being in the pending frame, so none can be returned to |
| 264 | 204 // the client yet. |
| 265 // A surface reference from the top-level root is added and there shouldn't be | 205 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 266 // a temporary reference. | 206 fake_support_client_.clear_returned_resources(); |
| 267 EXPECT_FALSE(HasTemporaryReference(display_id_first)); | 207 |
| 268 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), | 208 // The second frame references no resources of first frame and thus should |
| 269 UnorderedElementsAre(display_id_first)); | 209 // make all resources of first frame available to be returned. |
| 270 | 210 SubmitCompositorFrameWithResources(NULL, 0); |
| 271 // Submit a CompositorFrame for the second display root surface. | 211 |
| 272 display_support().SubmitCompositorFrame(display_id_second.local_surface_id(), | 212 ResourceId expected_returned_ids[] = {1, 2, 3}; |
| 273 MakeCompositorFrame()); | 213 int expected_returned_counts[] = {1, 1, 1}; |
| 274 | 214 // 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 | 215 CheckReturnedResourcesMatchExpected( |
| 276 // be added and the reference to |display_root_first| removed. | 216 expected_returned_ids, expected_returned_counts, |
| 277 EXPECT_FALSE(HasTemporaryReference(display_id_second)); | 217 arraysize(expected_returned_counts), gpu::SyncToken()); |
| 278 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), | 218 |
| 279 UnorderedElementsAre(display_id_second)); | 219 ResourceId third_frame_ids[] = {4, 5, 6}; |
| 280 | 220 SubmitCompositorFrameWithResources(third_frame_ids, |
| 281 // Surface |display_id_first| is unreachable and should get deleted. | 221 arraysize(third_frame_ids)); |
| 282 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(display_id_first)); | 222 |
| 283 } | 223 // All of the resources submitted in the third frame are still in use at this |
| 284 | 224 // 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|. | 225 // the client yet. |
| 286 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { | 226 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 287 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 227 fake_support_client_.clear_returned_resources(); |
| 288 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 228 |
| 289 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 229 // The forth frame references no resources of third frame and thus should |
| 290 | 230 // make all resources of third frame available to be returned. |
| 291 parent_support().SubmitCompositorFrame( | 231 ResourceId forth_frame_ids[] = {7, 8, 9}; |
| 292 parent_id.local_surface_id(), | 232 SubmitCompositorFrameWithResources(forth_frame_ids, |
| 293 MakeCompositorFrame({child_id1, child_id2})); | 233 arraysize(forth_frame_ids)); |
| 294 | 234 |
| 295 // parent_support is blocked on |child_id1| and |child_id2|. | 235 ResourceId forth_expected_returned_ids[] = {4, 5, 6}; |
| 296 EXPECT_TRUE(dependency_tracker().has_deadline()); | 236 int forth_expected_returned_counts[] = {1, 1, 1}; |
| 297 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 237 // Resources were never consumed so no sync token should be set. |
| 298 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 238 CheckReturnedResourcesMatchExpected( |
| 299 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 239 forth_expected_returned_ids, forth_expected_returned_counts, |
| 300 UnorderedElementsAre(child_id1, child_id2)); | 240 arraysize(forth_expected_returned_counts), gpu::SyncToken()); |
| 301 | 241 } |
| 302 // Submit a CompositorFrame without any dependencies to |child_id1|. | 242 |
| 303 // parent_support should now only be blocked on |child_id2|. | 243 // Tests submitting a frame with resources followed by one with no resources |
| 304 child_support1().SubmitCompositorFrame( | 244 // 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, | 245 TEST_F(CompositorFrameSinkSupportTest, |
| 385 DisplayCompositorLockingTwoBlockedOnOne) { | 246 ResourceLifetimeSimpleWithProviderHoldingAlive) { |
| 386 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 247 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 387 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 248 SubmitCompositorFrameWithResources(first_frame_ids, |
| 388 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 249 arraysize(first_frame_ids)); |
| 389 | 250 |
| 390 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | 251 // All of the resources submitted in the first frame are still in use at this |
| 391 MakeCompositorFrame({child_id2})); | 252 // time by virtue of being in the pending frame, so none can be returned to |
| 392 | 253 // the client yet. |
| 393 // parent_support is blocked on |child_id2|. | 254 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 394 EXPECT_TRUE(dependency_tracker().has_deadline()); | 255 fake_support_client_.clear_returned_resources(); |
| 395 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 256 |
| 396 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 257 // Hold on to everything. |
| 397 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 258 RefCurrentFrameResources(); |
| 398 UnorderedElementsAre(child_id2)); | 259 |
| 399 | 260 // The second frame references no resources and thus should make all resources |
| 400 // child_support1 should now be blocked on |child_id2|. | 261 // available to be returned as soon as the resource provider releases them. |
| 401 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | 262 SubmitCompositorFrameWithResources(NULL, 0); |
| 402 MakeCompositorFrame({child_id2})); | 263 |
| 403 | 264 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 404 EXPECT_TRUE(dependency_tracker().has_deadline()); | 265 fake_support_client_.clear_returned_resources(); |
| 405 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | 266 |
| 406 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | 267 int release_counts[] = {1, 1, 1}; |
| 407 EXPECT_THAT(child_surface1()->blocking_surfaces(), | 268 UnrefResources(first_frame_ids, release_counts, arraysize(first_frame_ids)); |
| 408 UnorderedElementsAre(child_id2)); | 269 |
| 409 | 270 // None is returned to the client since DidReceiveCompositorAck is not |
| 410 // The parent should still be blocked on |child_id2|. | 271 // invoked. |
| 411 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 272 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 412 UnorderedElementsAre(child_id2)); | 273 |
| 413 | 274 // Submitting an empty frame causes previous resources referenced by the |
| 414 // Submit a CompositorFrame without any dependencies to |child_id2|. | 275 // previous frame to be returned to client. |
| 415 // parent_support should be activated. | 276 SubmitCompositorFrameWithResources(nullptr, 0); |
| 416 child_support2().SubmitCompositorFrame( | 277 ResourceId expected_returned_ids[] = {1, 2, 3}; |
| 417 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 278 int expected_returned_counts[] = {1, 1, 1}; |
| 418 | 279 CheckReturnedResourcesMatchExpected( |
| 419 EXPECT_FALSE(dependency_tracker().has_deadline()); | 280 expected_returned_ids, expected_returned_counts, |
| 420 | 281 arraysize(expected_returned_counts), consumer_sync_token_); |
| 421 // child_surface1 should now be active. | 282 } |
| 422 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 283 |
| 423 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 284 // Tests referencing a resource, unref'ing it to zero, then using it again |
| 424 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 285 // before returning it to the client. |
| 425 | 286 TEST_F(CompositorFrameSinkSupportTest, ResourceReusedBeforeReturn) { |
| 426 // parent_surface should now be active. | 287 ResourceId first_frame_ids[] = {7}; |
| 427 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 288 SubmitCompositorFrameWithResources(first_frame_ids, |
| 428 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 289 arraysize(first_frame_ids)); |
| 429 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 290 |
| 430 } | 291 // This removes all references to resource id 7. |
| 431 | 292 SubmitCompositorFrameWithResources(NULL, 0); |
| 432 // parent_surface is blocked on |child_id1|, and child_surface2 is blocked on | 293 |
| 433 // |child_id2| until the deadline hits. | 294 // This references id 7 again. |
| 434 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingDeadlineHits) { | 295 SubmitCompositorFrameWithResources(first_frame_ids, |
| 435 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 296 arraysize(first_frame_ids)); |
| 436 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 297 |
| 437 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 298 // This removes it again. |
| 438 | 299 SubmitCompositorFrameWithResources(NULL, 0); |
| 439 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | 300 |
| 440 MakeCompositorFrame({child_id1})); | 301 // Now it should be returned. |
| 441 | 302 // 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|. | 303 // the total returned count matches the submitted count. |
| 443 EXPECT_TRUE(dependency_tracker().has_deadline()); | 304 const ReturnedResourceArray& returned = |
| 444 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 305 fake_support_client_.returned_resources(); |
| 445 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 306 size_t return_count = 0; |
| 446 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 307 for (size_t i = 0; i < returned.size(); ++i) { |
| 447 UnorderedElementsAre(child_id1)); | 308 EXPECT_EQ(7u, returned[i].id); |
| 448 | 309 return_count += returned[i].count; |
| 449 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | 310 } |
| 450 MakeCompositorFrame({child_id2})); | 311 EXPECT_EQ(2u, return_count); |
| 451 | 312 } |
| 452 // child_support1 should now be blocked on |child_id2|. | 313 |
| 453 EXPECT_TRUE(dependency_tracker().has_deadline()); | 314 // Tests having resources referenced multiple times, as if referenced by |
| 454 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | 315 // multiple providers. |
| 455 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | 316 TEST_F(CompositorFrameSinkSupportTest, ResourceRefMultipleTimes) { |
| 456 EXPECT_THAT(child_surface1()->blocking_surfaces(), | 317 ResourceId first_frame_ids[] = {3, 4}; |
| 457 UnorderedElementsAre(child_id2)); | 318 SubmitCompositorFrameWithResources(first_frame_ids, |
| 458 | 319 arraysize(first_frame_ids)); |
| 459 // The parent should still be blocked on |child_id1| because it's pending. | 320 |
| 460 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 321 // Ref resources from the first frame twice. |
| 461 UnorderedElementsAre(child_id1)); | 322 RefCurrentFrameResources(); |
| 462 | 323 RefCurrentFrameResources(); |
| 463 BeginFrameArgs args = | 324 |
| 464 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | 325 ResourceId second_frame_ids[] = {4, 5}; |
| 465 | 326 SubmitCompositorFrameWithResources(second_frame_ids, |
| 466 for (int i = 0; i < 3; ++i) { | 327 arraysize(second_frame_ids)); |
| 467 begin_frame_source()->TestOnBeginFrame(args); | 328 |
| 468 // There is still a looming deadline! Eeek! | 329 // Ref resources from the second frame 3 times. |
| 469 EXPECT_TRUE(dependency_tracker().has_deadline()); | 330 RefCurrentFrameResources(); |
| 470 | 331 RefCurrentFrameResources(); |
| 471 // parent_support is still blocked on |child_id1|. | 332 RefCurrentFrameResources(); |
| 472 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 333 |
| 473 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 334 // Submit a frame with no resources to remove all current frame refs from |
| 474 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 335 // submitted resources. |
| 475 UnorderedElementsAre(child_id1)); | 336 SubmitCompositorFrameWithResources(NULL, 0); |
| 476 | 337 |
| 477 // child_support1 is still blocked on |child_id2|. | 338 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 478 EXPECT_FALSE(child_surface1()->HasActiveFrame()); | 339 fake_support_client_.clear_returned_resources(); |
| 479 EXPECT_TRUE(child_surface1()->HasPendingFrame()); | 340 |
| 480 EXPECT_THAT(child_surface1()->blocking_surfaces(), | 341 // Expected current refs: |
| 481 UnorderedElementsAre(child_id2)); | 342 // 3 -> 2 |
| 482 } | 343 // 4 -> 2 + 3 = 5 |
| 483 | 344 // 5 -> 3 |
| 484 begin_frame_source()->TestOnBeginFrame(args); | 345 { |
| 485 | 346 SCOPED_TRACE("unref all 3"); |
| 486 // The deadline has passed. | 347 ResourceId ids_to_unref[] = {3, 4, 5}; |
| 487 EXPECT_FALSE(dependency_tracker().has_deadline()); | 348 int counts[] = {1, 1, 1}; |
| 488 | 349 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 489 // parent_surface has been activated. | 350 |
| 490 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 351 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 491 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 352 fake_support_client_.clear_returned_resources(); |
| 492 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 353 |
| 493 | 354 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 494 // child_surface1 has been activated. | 355 SubmitCompositorFrameWithResources(nullptr, 0); |
| 495 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 356 ResourceId expected_returned_ids[] = {3}; |
| 496 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 357 int expected_returned_counts[] = {1}; |
| 497 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 358 CheckReturnedResourcesMatchExpected( |
| 498 } | 359 expected_returned_ids, expected_returned_counts, |
| 499 | 360 arraysize(expected_returned_counts), consumer_sync_token_); |
| 500 // Verifies that the deadline does not reset if we submit CompositorFrames | 361 } |
| 501 // to new Surfaces with unresolved dependencies. | 362 |
| 502 TEST_F(CompositorFrameSinkSupportTest, | 363 // Expected refs remaining: |
| 503 DisplayCompositorLockingFramesSubmittedAfterDeadlineSet) { | 364 // 4 -> 3 |
| 504 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); | 365 // 5 -> 1 |
| 505 BeginFrameArgs args = | 366 { |
| 506 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | 367 SCOPED_TRACE("unref 4 and 5"); |
| 507 for (int i = 0; i < 3; ++i) { | 368 ResourceId ids_to_unref[] = {4, 5}; |
| 508 LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); | 369 int counts[] = {1, 1}; |
| 509 support(i).SubmitCompositorFrame(local_surface_id, | 370 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 510 MakeCompositorFrame({arbitrary_id})); | 371 SubmitCompositorFrameWithResources(nullptr, 0); |
| 511 // The deadline has been set. | 372 |
| 512 EXPECT_TRUE(dependency_tracker().has_deadline()); | 373 ResourceId expected_returned_ids[] = {5}; |
| 513 | 374 int expected_returned_counts[] = {1}; |
| 514 // support(i) should be blocked on arbitrary_id. | 375 CheckReturnedResourcesMatchExpected( |
| 515 EXPECT_FALSE(surface(i)->HasActiveFrame()); | 376 expected_returned_ids, expected_returned_counts, |
| 516 EXPECT_TRUE(surface(i)->HasPendingFrame()); | 377 arraysize(expected_returned_counts), consumer_sync_token_); |
| 517 EXPECT_THAT(surface(i)->blocking_surfaces(), | 378 } |
| 518 UnorderedElementsAre(arbitrary_id)); | 379 |
| 519 | 380 // 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. | 381 // the returned count is correct. |
| 521 begin_frame_source()->TestOnBeginFrame(args); | 382 { |
| 522 } | 383 SCOPED_TRACE("unref only 4"); |
| 523 | 384 ResourceId ids_to_unref[] = {4}; |
| 524 // The deadline hits and all the Surfaces should activate. | 385 int counts[] = {2}; |
| 525 begin_frame_source()->TestOnBeginFrame(args); | 386 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 526 for (int i = 0; i < 3; ++i) { | 387 SubmitCompositorFrameWithResources(nullptr, 0); |
| 527 EXPECT_TRUE(surface(i)->HasActiveFrame()); | 388 |
| 528 EXPECT_FALSE(surface(i)->HasPendingFrame()); | 389 ResourceId expected_returned_ids[] = {4}; |
| 529 EXPECT_THAT(surface(i)->blocking_surfaces(), IsEmpty()); | 390 int expected_returned_counts[] = {2}; |
| 530 } | 391 CheckReturnedResourcesMatchExpected( |
| 531 } | 392 expected_returned_ids, expected_returned_counts, |
| 532 | 393 arraysize(expected_returned_counts), consumer_sync_token_); |
| 533 // This test verifies at the Surface activates once a CompositorFrame is | 394 } |
| 534 // submitted that has no unresolved dependencies. | 395 } |
| 535 TEST_F(CompositorFrameSinkSupportTest, | 396 |
| 536 DisplayCompositorLockingNewFrameOverridesOldDependencies) { | 397 TEST_F(CompositorFrameSinkSupportTest, ResourceLifetime) { |
| 537 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 398 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 538 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); | 399 SubmitCompositorFrameWithResources(first_frame_ids, |
| 539 | 400 arraysize(first_frame_ids)); |
| 540 // Submit a CompositorFrame that depends on |arbitrary_id|. | 401 |
| 541 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), | 402 // All of the resources submitted in the first frame are still in use at this |
| 542 MakeCompositorFrame({arbitrary_id})); | 403 // time by virtue of being in the pending frame, so none can be returned to |
| 543 | 404 // the client yet. |
| 544 // Verify that the CompositorFrame is blocked on |arbitrary_id|. | 405 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 545 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 406 fake_support_client_.clear_returned_resources(); |
| 546 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 407 |
| 547 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 408 // The second frame references some of the same resources, but some different |
| 548 UnorderedElementsAre(arbitrary_id)); | 409 // ones. We expect to receive back resource 1 with a count of 1 since it was |
| 549 | 410 // only referenced by the first frame. |
| 550 // Submit a CompositorFrame that has no dependencies. | 411 ResourceId second_frame_ids[] = {2, 3, 4}; |
| 551 parent_support().SubmitCompositorFrame( | 412 SubmitCompositorFrameWithResources(second_frame_ids, |
| 552 parent_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 413 arraysize(second_frame_ids)); |
| 553 | 414 { |
| 554 // Verify that the CompositorFrame has been activated. | 415 SCOPED_TRACE("second frame"); |
| 555 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 416 ResourceId expected_returned_ids[] = {1}; |
| 556 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 417 int expected_returned_counts[] = {1}; |
| 557 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 418 CheckReturnedResourcesMatchExpected( |
| 558 } | 419 expected_returned_ids, expected_returned_counts, |
| 559 | 420 arraysize(expected_returned_counts), gpu::SyncToken()); |
| 560 // This test verifies that a pending CompositorFrame does not affect surface | 421 } |
| 561 // references. A new surface from a child will continue to exist as a temporary | 422 |
| 562 // reference until the parent's frame activates. | 423 // The third frame references a disjoint set of resources, so we expect to |
| 563 TEST_F(CompositorFrameSinkSupportTest, | 424 // receive back all resources from the first and second frames. Resource IDs 2 |
| 564 OnlyActiveFramesAffectSurfaceReferences) { | 425 // and 3 will have counts of 2, since they were used in both frames, and |
| 565 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 426 // resource ID 4 will have a count of 1. |
| 566 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); | 427 ResourceId third_frame_ids[] = {10, 11, 12, 13}; |
| 567 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); | 428 SubmitCompositorFrameWithResources(third_frame_ids, |
| 568 | 429 arraysize(third_frame_ids)); |
| 569 // child_support1 submits a CompositorFrame without any dependencies. | 430 |
| 570 // DidReceiveCompositorFrameAck should call on immediate activation. | 431 { |
| 571 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(1); | 432 SCOPED_TRACE("third frame"); |
| 572 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), | 433 ResourceId expected_returned_ids[] = {2, 3, 4}; |
| 573 MakeCompositorFrame()); | 434 int expected_returned_counts[] = {2, 2, 1}; |
| 574 testing::Mock::VerifyAndClearExpectations(&support_client_); | 435 CheckReturnedResourcesMatchExpected( |
| 575 | 436 expected_returned_ids, expected_returned_counts, |
| 576 // Verify that the child surface is not blocked. | 437 arraysize(expected_returned_counts), gpu::SyncToken()); |
| 577 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 438 } |
| 578 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 439 |
| 579 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 440 // Simulate a ResourceProvider taking a ref on all of the resources. |
| 580 | 441 RefCurrentFrameResources(); |
| 581 // Verify that there's a temporary reference for |child_id1|. | 442 |
| 582 EXPECT_TRUE(HasTemporaryReference(child_id1)); | 443 ResourceId fourth_frame_ids[] = {12, 13}; |
| 583 | 444 SubmitCompositorFrameWithResources(fourth_frame_ids, |
| 584 // parent_support submits a CompositorFrame that depends on |child_id1| | 445 arraysize(fourth_frame_ids)); |
| 585 // (which is already active) and |child_id2|. Thus, the parent should not | 446 |
| 586 // activate immediately. DidReceiveCompositorFrameAck should not be called | 447 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 587 // immediately because the parent CompositorFrame is also blocked on | 448 |
| 588 // |child_id2|. | 449 RefCurrentFrameResources(); |
| 589 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0); | 450 |
| 590 parent_support().SubmitCompositorFrame( | 451 // All resources are still being used by the external reference, so none can |
| 591 parent_id.local_surface_id(), | 452 // be returned to the client. |
| 592 MakeCompositorFrame({child_id1, child_id2})); | 453 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 593 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 454 |
| 594 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 455 // Release resources associated with the first RefCurrentFrameResources() call |
| 595 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 456 // first. |
| 596 UnorderedElementsAre(child_id2)); | 457 { |
| 597 EXPECT_THAT(GetChildReferences(parent_id), IsEmpty()); | 458 ResourceId ids_to_unref[] = {10, 11, 12, 13}; |
| 598 testing::Mock::VerifyAndClearExpectations(&support_client_); | 459 int counts[] = {1, 1, 1, 1}; |
| 599 | 460 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 600 // Verify that there's a temporary reference for |child_id1| that still | 461 } |
| 601 // exists. | 462 |
| 602 EXPECT_TRUE(HasTemporaryReference(child_id1)); | 463 // Nothing is returned to the client yet since DidReceiveCompositorFrameAck |
| 603 | 464 // is not invoked. |
| 604 // child_support2 submits a CompositorFrame without any dependencies. | 465 { |
| 605 // Both the child and the parent should immediately ACK CompositorFrames | 466 SCOPED_TRACE("fourth frame, first unref"); |
| 606 // on activation. | 467 CheckReturnedResourcesMatchExpected(nullptr, nullptr, 0, |
| 607 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2); | 468 consumer_sync_token_); |
| 608 child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), | 469 } |
| 609 MakeCompositorFrame()); | 470 |
| 610 testing::Mock::VerifyAndClearExpectations(&support_client_); | 471 { |
| 611 | 472 ResourceId ids_to_unref[] = {12, 13}; |
| 612 // Verify that the child surface is not blocked. | 473 int counts[] = {1, 1}; |
| 613 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 474 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); |
| 614 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 475 } |
| 615 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 476 |
| 616 | 477 // Resources 12 and 13 are still in use by the current frame, so they |
| 617 // Verify that the parent surface's CompositorFrame has activated and that the | 478 // shouldn't be available to be returned. |
| 618 // temporary reference has been replaced by a permanent one. | 479 EXPECT_EQ(0u, fake_support_client_.returned_resources().size()); |
| 619 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 480 |
| 620 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 481 // If we submit an empty frame, however, they should become available. |
| 621 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 482 // Resources that were previously unref'd also return at this point. |
| 622 EXPECT_FALSE(HasTemporaryReference(child_id1)); | 483 SubmitCompositorFrameWithResources(NULL, 0u); |
| 623 EXPECT_THAT(GetChildReferences(parent_id), | 484 |
| 624 UnorderedElementsAre(child_id1, child_id2)); | 485 { |
| 625 } | 486 SCOPED_TRACE("fourth frame, second unref"); |
| 626 | 487 ResourceId expected_returned_ids[] = {10, 11, 12, 13}; |
| 627 // This test verifies that we do not double count returned resources when a | 488 int expected_returned_counts[] = {1, 1, 2, 2}; |
| 628 // CompositorFrame starts out as pending, then becomes active, and then is | 489 CheckReturnedResourcesMatchExpected( |
| 629 // replaced with another active CompositorFrame. | 490 expected_returned_ids, expected_returned_counts, |
| 630 TEST_F(CompositorFrameSinkSupportTest, | 491 arraysize(expected_returned_counts), consumer_sync_token_); |
| 631 DisplayCompositorLockingResourcesOnlyReturnedOnce) { | 492 } |
| 632 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 493 } |
| 633 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); | 494 |
| 634 | 495 TEST_F(CompositorFrameSinkSupportTest, BlankNoIndexIncrement) { |
| 635 // The parent submits a CompositorFrame that depends on |child_id| before the | 496 LocalSurfaceId local_surface_id(6, kArbitraryToken); |
| 636 // child submits a CompositorFrame. The CompositorFrame also has resources in | 497 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); |
| 637 // its resource list. | 498 support_->SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); |
| 638 TransferableResource resource = | 499 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 639 MakeResource(1337 /* id */, ALPHA_8 /* format */, 1234 /* filter */, | 500 ASSERT_NE(nullptr, surface); |
| 640 gfx::Size(1234, 5678)); | 501 EXPECT_EQ(2, surface->frame_index()); |
| 641 TransferableResourceArray resource_list = {resource}; | 502 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 642 parent_support().SubmitCompositorFrame( | 503 } |
| 643 parent_id.local_surface_id(), | 504 |
| 644 MakeCompositorFrameWithResources({child_id}, resource_list)); | 505 TEST_F(CompositorFrameSinkSupportTest, AddDuringEviction) { |
| 645 | 506 constexpr bool kAddDuringEviction = true; |
| 646 // Verify that the CompositorFrame is blocked on |child_id|. | 507 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 647 EXPECT_FALSE(parent_surface()->HasActiveFrame()); | 508 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 648 EXPECT_TRUE(parent_surface()->HasPendingFrame()); | 509 CompositorFrameSinkSupport::Create( |
| 649 EXPECT_THAT(parent_surface()->blocking_surfaces(), | 510 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 650 UnorderedElementsAre(child_id)); | 511 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 651 | 512 mock_client.set_support(support.get()); |
| 652 child_support1().SubmitCompositorFrame( | 513 LocalSurfaceId local_surface_id(6, kArbitraryToken); |
| 653 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); | 514 |
| 654 | 515 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(0); |
| 655 // Verify that the child CompositorFrame activates immediately. | 516 support->SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); |
| 656 EXPECT_TRUE(child_surface1()->HasActiveFrame()); | 517 |
| 657 EXPECT_FALSE(child_surface1()->HasPendingFrame()); | 518 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)).Times(2); |
| 658 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); | 519 support->EvictFrame(); |
| 659 | 520 } |
| 660 // Verify that the parent has activated. | 521 |
| 661 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 522 // Tests doing an EvictFrame before shutting down the factory. |
| 662 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 523 TEST_F(CompositorFrameSinkSupportTest, EvictFrame) { |
| 663 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 524 constexpr bool kAddDuringEviction = false; |
| 664 | 525 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 665 // The parent submits a CompositorFrame without any dependencies. That frame | 526 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 666 // should activate immediately, replacing the earlier frame. The resource from | 527 CompositorFrameSinkSupport::Create( |
| 667 // the earlier frame should be returned to the client. | 528 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 668 parent_support().SubmitCompositorFrame( | 529 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 669 parent_id.local_surface_id(), MakeCompositorFrame({empty_surface_ids()})); | 530 mock_client.set_support(support.get()); |
| 670 EXPECT_TRUE(parent_surface()->HasActiveFrame()); | 531 LocalSurfaceId local_surface_id(7, kArbitraryToken); |
| 671 EXPECT_FALSE(parent_surface()->HasPendingFrame()); | 532 SurfaceId id(kAnotherArbitraryFrameSinkId, local_surface_id); |
| 672 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); | 533 |
| 673 ReturnedResource returned_resource = resource.ToReturnedResource(); | 534 TransferableResource resource; |
| 674 EXPECT_THAT(support_client_.last_returned_resources(), | 535 resource.id = 1; |
| 675 UnorderedElementsAre(returned_resource)); | 536 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 676 } | |
| 677 | |
| 678 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. | |
| 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(); | 537 CompositorFrame frame = MakeCompositorFrame(); |
| 812 frame.metadata.latency_info.push_back(info); | 538 frame.resource_list.push_back(resource); |
| 813 | 539 support->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 814 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 540 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 815 std::move(frame)); | 541 local_surface_id_ = LocalSurfaceId(); |
| 816 | 542 |
| 817 // Verify that the old surface has an active frame and no pending frame. | 543 ReturnedResourceArray returned_resources = {resource.ToReturnedResource()}; |
| 818 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 544 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 819 ASSERT_NE(nullptr, old_surface); | 545 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(returned_resources)) |
| 820 EXPECT_TRUE(old_surface->HasActiveFrame()); | 546 .Times(1); |
| 821 EXPECT_FALSE(old_surface->HasPendingFrame()); | 547 support->EvictFrame(); |
| 822 | 548 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 823 // Submit another frame with some other latency info and a different | 549 } |
| 824 // LocalSurfaceId. | 550 |
| 825 ui::LatencyInfo info2; | 551 // Tests doing an EvictSurface which has unregistered dependency. |
| 826 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 552 TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceDependencyUnRegistered) { |
| 827 | 553 constexpr bool kAddDuringEviction = false; |
| 828 CompositorFrame frame2 = MakeCompositorFrame(); | 554 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 829 frame2.metadata.latency_info.push_back(info2); | 555 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 830 | 556 CompositorFrameSinkSupport::Create( |
| 831 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 557 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 832 std::move(frame2)); | 558 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 833 | 559 mock_client.set_support(support.get()); |
| 834 // Verify that the new surface has an active frame and no pending frames. | 560 LocalSurfaceId local_surface_id(7, kArbitraryToken); |
| 835 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 561 |
| 836 ASSERT_NE(nullptr, surface); | 562 TransferableResource resource; |
| 837 EXPECT_TRUE(surface->HasActiveFrame()); | 563 resource.id = 1; |
| 838 EXPECT_FALSE(surface->HasPendingFrame()); | 564 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(); | 565 CompositorFrame frame = MakeCompositorFrame(); |
| 884 frame.metadata.latency_info.push_back(info); | 566 frame.resource_list.push_back(resource); |
| 885 | 567 support->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 886 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 568 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 887 std::move(frame)); | 569 local_surface_id_ = LocalSurfaceId(); |
| 888 | 570 |
| 889 // Submit a frame with unresolved dependencies. | 571 SurfaceId surface_id(kAnotherArbitraryFrameSinkId, local_surface_id); |
| 890 ui::LatencyInfo info2; | 572 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 891 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 573 surface->AddDestructionDependency( |
| 892 | 574 SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 893 CompositorFrame frame2 = MakeCompositorFrame({child_id}); | 575 |
| 894 frame2.metadata.latency_info.push_back(info2); | 576 ReturnedResourceArray returned_resource = {resource.ToReturnedResource()}; |
| 895 | 577 |
| 896 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 578 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); |
| 897 std::move(frame2)); | 579 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(returned_resource)) |
| 898 | 580 .Times(1); |
| 899 // Verify that the old surface has both an active and a pending frame. | 581 support->EvictFrame(); |
| 900 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 582 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); |
| 901 ASSERT_NE(nullptr, old_surface); | 583 } |
| 902 EXPECT_TRUE(old_surface->HasActiveFrame()); | 584 |
| 903 EXPECT_TRUE(old_surface->HasPendingFrame()); | 585 // Tests doing an EvictSurface which has registered dependency. |
| 904 | 586 TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceDependencyRegistered) { |
| 905 // Submit a frame with a new local surface id. | 587 constexpr bool kAddDuringEviction = false; |
| 906 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 588 MockCompositorFrameSinkSupportClient mock_client(kAddDuringEviction); |
| 907 MakeCompositorFrame()); | 589 std::unique_ptr<CompositorFrameSinkSupport> support = |
| 908 | 590 CompositorFrameSinkSupport::Create( |
| 909 // Verify that the new surface has an active frame only. | 591 &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, |
| 910 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 592 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 911 ASSERT_NE(nullptr, surface); | 593 mock_client.set_support(support.get()); |
| 912 EXPECT_TRUE(surface->HasActiveFrame()); | 594 LocalSurfaceId local_surface_id(7, kArbitraryToken); |
| 913 EXPECT_FALSE(surface->HasPendingFrame()); | 595 |
| 914 | 596 TransferableResource resource; |
| 915 // Verify that the new surface has latency info from both active and pending | 597 resource.id = 1; |
| 916 // frame of the old surface. | 598 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 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(); | 599 CompositorFrame frame = MakeCompositorFrame(); |
| 960 frame.metadata.latency_info.push_back(info); | 600 frame.resource_list.push_back(resource); |
| 961 | 601 uint32_t execute_count = 0; |
| 962 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), | 602 support->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 963 std::move(frame)); | 603 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 964 | 604 local_surface_id_ = LocalSurfaceId(); |
| 965 // Verify that the old surface has an active frame only. | 605 |
| 966 Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1); | 606 manager_.RegisterFrameSinkId(kYetAnotherArbitraryFrameSinkId); |
| 967 ASSERT_NE(nullptr, old_surface); | 607 |
| 968 EXPECT_TRUE(old_surface->HasActiveFrame()); | 608 SurfaceId surface_id(kAnotherArbitraryFrameSinkId, local_surface_id); |
| 969 EXPECT_FALSE(old_surface->HasPendingFrame()); | 609 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 970 | 610 surface->AddDestructionDependency( |
| 971 // Submit a frame with a new local surface id and with unresolved | 611 SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 972 // dependencies. | 612 |
| 973 ui::LatencyInfo info2; | 613 ReturnedResourceArray returned_resources; |
| 974 info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); | 614 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); |
| 975 | 615 support->EvictFrame(); |
| 976 CompositorFrame frame2 = MakeCompositorFrame({child_id}); | 616 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); |
| 977 frame2.metadata.latency_info.push_back(info2); | 617 EXPECT_EQ(0u, execute_count); |
| 978 | 618 |
| 979 parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), | 619 returned_resources.push_back(resource.ToReturnedResource()); |
| 980 std::move(frame2)); | 620 EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(returned_resources)) |
| 981 | 621 .Times(1); |
| 982 // Verify that the new surface has a pending frame and no active frame. | 622 manager_.SatisfySequence(SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 983 Surface* surface = surface_manager().GetSurfaceForId(parent_id2); | 623 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); |
| 984 ASSERT_NE(nullptr, surface); | 624 } |
| 985 EXPECT_TRUE(surface->HasPendingFrame()); | 625 |
| 986 EXPECT_FALSE(surface->HasActiveFrame()); | 626 TEST_F(CompositorFrameSinkSupportTest, DestroySequence) { |
| 987 | 627 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 988 // Resolve the dependencies. The frame in parent's surface must become active. | 628 std::unique_ptr<CompositorFrameSinkSupport> support2 = |
| 989 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 629 CompositorFrameSinkSupport::Create( |
| 990 MakeCompositorFrame()); | 630 &fake_support_client_, &manager_, kYetAnotherArbitraryFrameSinkId, |
| 991 EXPECT_FALSE(surface->HasPendingFrame()); | 631 kIsChildRoot, kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 992 EXPECT_TRUE(surface->HasActiveFrame()); | 632 SurfaceId id2(kYetAnotherArbitraryFrameSinkId, local_surface_id2); |
| 993 | 633 support2->SubmitCompositorFrame(local_surface_id2, MakeCompositorFrame()); |
| 994 // Both latency info elements must exist in the now-activated frame of the | 634 |
| 995 // new surface. | 635 // Check that waiting before the sequence is satisfied works. |
| 996 std::vector<ui::LatencyInfo> info_list; | 636 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 997 surface->TakeLatencyInfo(&info_list); | 637 SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 998 EXPECT_EQ(2u, info_list.size()); | 638 support2->EvictFrame(); |
| 999 | 639 |
| 1000 ui::LatencyInfo aggregated_latency_info = info_list[0]; | 640 DCHECK(manager_.GetSurfaceForId(id2)); |
| 1001 aggregated_latency_info.AddNewLatencyFrom(info_list[1]); | 641 manager_.SatisfySequence(SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 4)); |
| 1002 | 642 manager_.SatisfySequence(SurfaceSequence(kYetAnotherArbitraryFrameSinkId, 6)); |
| 1003 // Two components are the original ones, and the third one is | 643 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 1004 // DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame | 644 |
| 1005 // submit. | 645 // Check that waiting after the sequence is satisfied works. |
| 1006 EXPECT_EQ(3u, aggregated_latency_info.latency_components().size()); | 646 support2->SubmitCompositorFrame(local_surface_id2, MakeCompositorFrame()); |
| 1007 | 647 DCHECK(manager_.GetSurfaceForId(id2)); |
| 1008 ui::LatencyInfo::LatencyComponent comp1; | 648 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 1009 EXPECT_TRUE( | 649 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); |
| 1010 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); | 650 support2->EvictFrame(); |
| 1011 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); | 651 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 1012 EXPECT_TRUE( | 652 } |
| 1013 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); | 653 |
| 1014 EXPECT_TRUE(aggregated_latency_info.FindLatency( | 654 // Tests that Surface ID namespace invalidation correctly allows |
| 1015 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); | 655 // Sequences to be ignored. |
| 1016 } | 656 TEST_F(CompositorFrameSinkSupportTest, InvalidFrameSinkId) { |
| 1017 | 657 FrameSinkId frame_sink_id(1234, 5678); |
| 1018 TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { | 658 |
| 1019 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); | 659 LocalSurfaceId local_surface_id(5, kArbitraryToken); |
| 1020 | 660 SurfaceId id(support_->frame_sink_id(), local_surface_id); |
| 1021 // Request BeginFrames. | 661 support_->SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); |
| 1022 display_support().SetNeedsBeginFrame(true); | 662 |
| 1023 | 663 manager_.RegisterFrameSinkId(frame_sink_id); |
| 1024 // Issue a BeginFrame. | 664 manager_.GetSurfaceForId(id)->AddDestructionDependency( |
| 1025 BeginFrameArgs args = | 665 SurfaceSequence(frame_sink_id, 4)); |
| 1026 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); | 666 |
| 1027 begin_frame_source()->TestOnBeginFrame(args); | 667 support_->EvictFrame(); |
| 1028 | 668 |
| 1029 // Check that the support forwards a BeginFrameDidNotSwap ack to the | 669 // Verify the dependency has prevented the surface from getting destroyed. |
| 1030 // BeginFrameSource. | 670 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 1031 BeginFrameAck ack(0, 1, 1, false); | 671 |
| 1032 display_support().BeginFrameDidNotSwap(ack); | 672 manager_.InvalidateFrameSinkId(frame_sink_id); |
| 1033 EXPECT_EQ(ack, begin_frame_source()->LastAckForObserver(&display_support())); | 673 |
| 1034 | 674 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 1035 // Issue another BeginFrame. | 675 // to be ignored. |
| 1036 args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 2); | 676 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 1037 begin_frame_source()->TestOnBeginFrame(args); | 677 } |
| 1038 | 678 |
| 1039 // Check that the support forwards the BeginFrameAck attached | 679 TEST_F(CompositorFrameSinkSupportTest, DestroyCycle) { |
| 1040 // to a CompositorFrame to the BeginFrameSource. | 680 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 1041 BeginFrameAck ack2(0, 2, 2, true); | 681 SurfaceId id2(kYetAnotherArbitraryFrameSinkId, local_surface_id2); |
| 682 std::unique_ptr<CompositorFrameSinkSupport> support2 = |
| 683 CompositorFrameSinkSupport::Create( |
| 684 &fake_support_client_, &manager_, kYetAnotherArbitraryFrameSinkId, |
| 685 kIsChildRoot, kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints); |
| 686 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
| 687 // Give id2 a frame that references local_surface_id_. |
| 688 { |
| 689 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 690 CompositorFrame frame = MakeCompositorFrame(); |
| 691 frame.render_pass_list.push_back(std::move(render_pass)); |
| 692 frame.metadata.referenced_surfaces.push_back( |
| 693 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 694 support2->SubmitCompositorFrame(local_surface_id2, std::move(frame)); |
| 695 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id2); |
| 696 } |
| 697 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 698 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 699 support2->EvictFrame(); |
| 700 // Give local_surface_id_ a frame that references id2. |
| 701 { |
| 702 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 703 CompositorFrame frame = MakeCompositorFrame(); |
| 704 frame.render_pass_list.push_back(std::move(render_pass)); |
| 705 frame.metadata.referenced_surfaces.push_back(id2); |
| 706 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 707 } |
| 708 support_->EvictFrame(); |
| 709 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| 710 // local_surface_id_ should be retained by reference from id2. |
| 711 EXPECT_TRUE(manager_.GetSurfaceForId( |
| 712 SurfaceId(support_->frame_sink_id(), local_surface_id_))); |
| 713 |
| 714 // Satisfy last destruction dependency for id2. |
| 715 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 716 |
| 717 // id2 and local_surface_id_ are in a reference cycle that has no surface |
| 718 // sequences holding on to it, so they should be destroyed. |
| 719 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); |
| 720 EXPECT_TRUE(!manager_.GetSurfaceForId( |
| 721 SurfaceId(support_->frame_sink_id(), local_surface_id_))); |
| 722 |
| 723 local_surface_id_ = LocalSurfaceId(); |
| 724 } |
| 725 |
| 726 void CopyRequestTestCallback(bool* called, |
| 727 std::unique_ptr<CopyOutputResult> result) { |
| 728 *called = true; |
| 729 } |
| 730 |
| 731 TEST_F(CompositorFrameSinkSupportTest, DuplicateCopyRequest) { |
| 732 { |
| 733 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 734 CompositorFrame frame = MakeCompositorFrame(); |
| 735 frame.render_pass_list.push_back(std::move(render_pass)); |
| 736 frame.metadata.referenced_surfaces.push_back( |
| 737 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 738 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 739 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id_); |
| 740 } |
| 741 |
| 742 bool called1 = false; |
| 743 std::unique_ptr<CopyOutputRequest> request; |
| 744 request = CopyOutputRequest::CreateRequest( |
| 745 base::Bind(&CopyRequestTestCallback, &called1)); |
| 746 request->set_source(kArbitrarySourceId1); |
| 747 |
| 748 support_->RequestCopyOfSurface(std::move(request)); |
| 749 EXPECT_FALSE(called1); |
| 750 |
| 751 bool called2 = false; |
| 752 request = CopyOutputRequest::CreateRequest( |
| 753 base::Bind(&CopyRequestTestCallback, &called2)); |
| 754 request->set_source(kArbitrarySourceId2); |
| 755 |
| 756 support_->RequestCopyOfSurface(std::move(request)); |
| 757 // Callbacks have different sources so neither should be called. |
| 758 EXPECT_FALSE(called1); |
| 759 EXPECT_FALSE(called2); |
| 760 |
| 761 bool called3 = false; |
| 762 request = CopyOutputRequest::CreateRequest( |
| 763 base::Bind(&CopyRequestTestCallback, &called3)); |
| 764 request->set_source(kArbitrarySourceId1); |
| 765 |
| 766 support_->RequestCopyOfSurface(std::move(request)); |
| 767 // Two callbacks are from source1, so the first should be called. |
| 768 EXPECT_TRUE(called1); |
| 769 EXPECT_FALSE(called2); |
| 770 EXPECT_FALSE(called3); |
| 771 |
| 772 support_->EvictFrame(); |
| 773 local_surface_id_ = LocalSurfaceId(); |
| 774 EXPECT_TRUE(called1); |
| 775 EXPECT_TRUE(called2); |
| 776 EXPECT_TRUE(called3); |
| 777 } |
| 778 |
| 779 // Check whether the SurfaceInfo object is created and populated correctly |
| 780 // after the frame submission. |
| 781 TEST_F(CompositorFrameSinkSupportTest, SurfaceInfo) { |
| 1042 CompositorFrame frame = MakeCompositorFrame(); | 782 CompositorFrame frame = MakeCompositorFrame(); |
| 1043 frame.metadata.begin_frame_ack = ack2; | 783 |
| 1044 display_support().SubmitCompositorFrame(display_id.local_surface_id(), | 784 auto render_pass = RenderPass::Create(); |
| 1045 std::move(frame)); | 785 render_pass->SetNew(1, gfx::Rect(5, 6), gfx::Rect(), gfx::Transform()); |
| 1046 EXPECT_EQ(ack2, begin_frame_source()->LastAckForObserver(&display_support())); | 786 frame.render_pass_list.push_back(std::move(render_pass)); |
| 1047 } | 787 |
| 1048 | 788 render_pass = RenderPass::Create(); |
| 1049 // Checks that resources and ack are sent together if possible. | 789 render_pass->SetNew(2, gfx::Rect(7, 8), gfx::Rect(), gfx::Transform()); |
| 1050 TEST_F(CompositorFrameSinkSupportTest, ReturnResourcesWithAck) { | 790 frame.render_pass_list.push_back(std::move(render_pass)); |
| 1051 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 791 |
| 1052 TransferableResource resource; | 792 frame.metadata.device_scale_factor = 2.5f; |
| 1053 resource.id = 1234; | 793 |
| 1054 parent_support().SubmitCompositorFrame( | 794 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 1055 parent_id.local_surface_id(), | 795 SurfaceId expected_surface_id(support_->frame_sink_id(), local_surface_id_); |
| 1056 MakeCompositorFrameWithResources(empty_surface_ids(), {resource})); | 796 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); |
| 1057 ReturnedResourceArray returned_resources; | 797 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); |
| 1058 TransferableResource::ReturnResources({resource}, &returned_resources); | 798 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 } | 799 } |
| 1323 | 800 |
| 1324 } // namespace test | 801 } // namespace test |
| 1325 } // namespace cc | 802 } // namespace cc |
| OLD | NEW |