| 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" | 9 #include "cc/output/copy_output_request.h" |
| 10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 public SurfaceObserver { | 94 public SurfaceObserver { |
| 95 public: | 95 public: |
| 96 CompositorFrameSinkSupportTest() | 96 CompositorFrameSinkSupportTest() |
| 97 : support_( | 97 : support_( |
| 98 CompositorFrameSinkSupport::Create(&fake_support_client_, | 98 CompositorFrameSinkSupport::Create(&fake_support_client_, |
| 99 &manager_, | 99 &manager_, |
| 100 kArbitraryFrameSinkId, | 100 kArbitraryFrameSinkId, |
| 101 kIsRoot, | 101 kIsRoot, |
| 102 kHandlesFrameSinkIdInvalidation, | 102 kHandlesFrameSinkIdInvalidation, |
| 103 kNeedsSyncPoints)), | 103 kNeedsSyncPoints)), |
| 104 begin_frame_source_(0.f, false), |
| 104 local_surface_id_(3, kArbitraryToken), | 105 local_surface_id_(3, kArbitraryToken), |
| 105 frame_sync_token_(GenTestSyncToken(4)), | 106 frame_sync_token_(GenTestSyncToken(4)), |
| 106 consumer_sync_token_(GenTestSyncToken(5)) { | 107 consumer_sync_token_(GenTestSyncToken(5)) { |
| 107 manager_.AddObserver(this); | 108 manager_.AddObserver(this); |
| 109 support_->SetBeginFrameSource(&begin_frame_source_); |
| 108 } | 110 } |
| 109 ~CompositorFrameSinkSupportTest() override { | 111 ~CompositorFrameSinkSupportTest() override { |
| 110 manager_.RemoveObserver(this); | 112 manager_.RemoveObserver(this); |
| 111 support_->EvictCurrentSurface(); | 113 support_->EvictCurrentSurface(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 const SurfaceId& last_created_surface_id() const { | 116 const SurfaceId& last_created_surface_id() const { |
| 115 return last_created_surface_id_; | 117 return last_created_surface_id_; |
| 116 } | 118 } |
| 117 | 119 |
| 118 // SurfaceObserver implementation. | 120 // SurfaceObserver implementation. |
| 119 void OnSurfaceCreated(const SurfaceInfo& surface_info) override { | 121 void OnSurfaceCreated(const SurfaceInfo& surface_info) override { |
| 120 last_created_surface_id_ = surface_info.id(); | 122 last_created_surface_id_ = surface_info.id(); |
| 121 last_surface_info_ = surface_info; | 123 last_surface_info_ = surface_info; |
| 122 } | 124 } |
| 123 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { | 125 void OnSurfaceDamaged(const SurfaceId& id, |
| 126 const BeginFrameAck& ack, |
| 127 bool* changed) override { |
| 128 last_begin_frame_ack_ = ack; |
| 124 *changed = true; | 129 *changed = true; |
| 125 } | 130 } |
| 126 void OnSurfaceDiscarded(const SurfaceId& surface_id) override {} | 131 void OnSurfaceDiscarded(const SurfaceId& surface_id) override {} |
| 132 void OnSurfaceDestroyed(const SurfaceId& surface_id) override {} |
| 133 void OnSurfaceDamageExpected(const SurfaceId& surface_id, |
| 134 const BeginFrameArgs& args) override {} |
| 127 | 135 |
| 128 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 136 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 129 size_t num_resource_ids) { | 137 size_t num_resource_ids) { |
| 130 CompositorFrame frame = MakeCompositorFrame(); | 138 CompositorFrame frame = MakeCompositorFrame(); |
| 131 for (size_t i = 0u; i < num_resource_ids; ++i) { | 139 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 132 TransferableResource resource; | 140 TransferableResource resource; |
| 133 resource.id = resource_ids[i]; | 141 resource.id = resource_ids[i]; |
| 134 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 142 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 135 resource.mailbox_holder.sync_token = frame_sync_token_; | 143 resource.mailbox_holder.sync_token = frame_sync_token_; |
| 136 frame.resource_list.push_back(resource); | 144 frame.resource_list.push_back(resource); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 void RefCurrentFrameResources() { | 180 void RefCurrentFrameResources() { |
| 173 Surface* surface = manager_.GetSurfaceForId( | 181 Surface* surface = manager_.GetSurfaceForId( |
| 174 SurfaceId(support_->frame_sink_id(), local_surface_id_)); | 182 SurfaceId(support_->frame_sink_id(), local_surface_id_)); |
| 175 support_->RefResources(surface->GetActiveFrame().resource_list); | 183 support_->RefResources(surface->GetActiveFrame().resource_list); |
| 176 } | 184 } |
| 177 | 185 |
| 178 protected: | 186 protected: |
| 179 SurfaceManager manager_; | 187 SurfaceManager manager_; |
| 180 FakeCompositorFrameSinkSupportClient fake_support_client_; | 188 FakeCompositorFrameSinkSupportClient fake_support_client_; |
| 181 std::unique_ptr<CompositorFrameSinkSupport> support_; | 189 std::unique_ptr<CompositorFrameSinkSupport> support_; |
| 190 FakeExternalBeginFrameSource begin_frame_source_; |
| 182 LocalSurfaceId local_surface_id_; | 191 LocalSurfaceId local_surface_id_; |
| 183 SurfaceId last_created_surface_id_; | 192 SurfaceId last_created_surface_id_; |
| 184 SurfaceInfo last_surface_info_; | 193 SurfaceInfo last_surface_info_; |
| 194 BeginFrameAck last_begin_frame_ack_; |
| 185 | 195 |
| 186 // This is the sync token submitted with the frame. It should never be | 196 // This is the sync token submitted with the frame. It should never be |
| 187 // returned to the client. | 197 // returned to the client. |
| 188 const gpu::SyncToken frame_sync_token_; | 198 const gpu::SyncToken frame_sync_token_; |
| 189 | 199 |
| 190 // This is the sync token returned by the consumer. It should always be | 200 // This is the sync token returned by the consumer. It should always be |
| 191 // returned to the client. | 201 // returned to the client. |
| 192 const gpu::SyncToken consumer_sync_token_; | 202 const gpu::SyncToken consumer_sync_token_; |
| 193 }; | 203 }; |
| 194 | 204 |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 782 |
| 773 frame.metadata.device_scale_factor = 2.5f; | 783 frame.metadata.device_scale_factor = 2.5f; |
| 774 | 784 |
| 775 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); | 785 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 776 SurfaceId expected_surface_id(support_->frame_sink_id(), local_surface_id_); | 786 SurfaceId expected_surface_id(support_->frame_sink_id(), local_surface_id_); |
| 777 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); | 787 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); |
| 778 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); | 788 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); |
| 779 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); | 789 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); |
| 780 } | 790 } |
| 781 | 791 |
| 792 TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { |
| 793 // Request BeginFrames. |
| 794 support_->SetNeedsBeginFrame(true); |
| 795 |
| 796 // Issue a BeginFrame. |
| 797 BeginFrameArgs args = |
| 798 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); |
| 799 begin_frame_source_.TestOnBeginFrame(args); |
| 800 |
| 801 // Check that the support and SurfaceManager forward the BeginFrameAck |
| 802 // attached to a CompositorFrame to the SurfaceObserver. |
| 803 BeginFrameAck ack(0, 1, 1, true); |
| 804 CompositorFrame frame = MakeCompositorFrame(); |
| 805 frame.metadata.begin_frame_ack = ack; |
| 806 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 807 EXPECT_EQ(ack, last_begin_frame_ack_); |
| 808 |
| 809 // Issue another BeginFrame. |
| 810 args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 2); |
| 811 begin_frame_source_.TestOnBeginFrame(args); |
| 812 |
| 813 // Check that the support and SurfaceManager forward a DidNotProduceFrame ack |
| 814 // to the SurfaceObserver. |
| 815 BeginFrameAck ack2(0, 2, 2, false); |
| 816 support_->DidNotProduceFrame(ack2); |
| 817 EXPECT_EQ(ack2, last_begin_frame_ack_); |
| 818 |
| 819 support_->SetNeedsBeginFrame(false); |
| 820 } |
| 821 |
| 782 } // namespace | 822 } // namespace |
| 783 | 823 |
| 784 } // namespace test | 824 } // namespace test |
| 785 | 825 |
| 786 } // namespace cc | 826 } // namespace cc |
| OLD | NEW |