Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/test_compositor_frame_sink.h" | 5 #include "cc/test/test_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "cc/output/begin_frame_args.h" | 11 #include "cc/output/begin_frame_args.h" |
| 12 #include "cc/output/compositor_frame_sink_client.h" | 12 #include "cc/output/compositor_frame_sink_client.h" |
| 13 #include "cc/output/copy_output_request.h" | 13 #include "cc/output/copy_output_request.h" |
| 14 #include "cc/output/direct_renderer.h" | 14 #include "cc/output/direct_renderer.h" |
| 15 #include "cc/output/output_surface.h" | 15 #include "cc/output/output_surface.h" |
| 16 #include "cc/output/texture_mailbox_deleter.h" | 16 #include "cc/output/texture_mailbox_deleter.h" |
| 17 #include "cc/surfaces/compositor_frame_sink_support.h" | |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 | 20 |
| 20 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); | 21 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); |
| 21 | 22 |
| 22 TestCompositorFrameSink::TestCompositorFrameSink( | 23 TestCompositorFrameSink::TestCompositorFrameSink( |
| 23 scoped_refptr<ContextProvider> compositor_context_provider, | 24 scoped_refptr<ContextProvider> compositor_context_provider, |
| 24 scoped_refptr<ContextProvider> worker_context_provider, | 25 scoped_refptr<ContextProvider> worker_context_provider, |
| 25 SharedBitmapManager* shared_bitmap_manager, | 26 SharedBitmapManager* shared_bitmap_manager, |
| 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 27 const RendererSettings& renderer_settings, | 28 const RendererSettings& renderer_settings, |
| 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 29 bool synchronous_composite, | 30 bool synchronous_composite, |
| 30 bool force_disable_reclaim_resources) | 31 bool force_disable_reclaim_resources) |
| 31 : CompositorFrameSink(std::move(compositor_context_provider), | 32 : CompositorFrameSink(std::move(compositor_context_provider), |
| 32 std::move(worker_context_provider), | 33 std::move(worker_context_provider), |
| 33 gpu_memory_buffer_manager, | 34 gpu_memory_buffer_manager, |
| 34 shared_bitmap_manager), | 35 shared_bitmap_manager), |
| 35 synchronous_composite_(synchronous_composite), | 36 synchronous_composite_(synchronous_composite), |
| 36 renderer_settings_(renderer_settings), | 37 renderer_settings_(renderer_settings), |
| 37 task_runner_(std::move(task_runner)), | 38 task_runner_(std::move(task_runner)), |
| 38 frame_sink_id_(kCompositorFrameSinkId), | 39 frame_sink_id_(kCompositorFrameSinkId), |
| 39 surface_manager_(new SurfaceManager), | 40 surface_manager_(new SurfaceManager), |
| 40 local_surface_id_allocator_(new LocalSurfaceIdAllocator()), | 41 local_surface_id_allocator_(new LocalSurfaceIdAllocator()), |
| 41 surface_factory_( | 42 external_begin_frame_source_(this), |
| 42 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), | |
| 43 weak_ptr_factory_(this) { | 43 weak_ptr_factory_(this) { |
| 44 // Since this CompositorFrameSink and the Display are tightly coupled and in | 44 // Since this CompositorFrameSink and the Display are tightly coupled and in |
| 45 // the same process/thread, the LayerTreeHostImpl can reclaim resources from | 45 // the same process/thread, the LayerTreeHostImpl can reclaim resources from |
| 46 // the Display. But we allow tests to disable this to mimic an out-of-process | 46 // the Display. But we allow tests to disable this to mimic an out-of-process |
| 47 // Display. | 47 // Display. |
| 48 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; | 48 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; |
| 49 // Always use sync tokens so that code paths in resource provider that deal | 49 // Always use sync tokens so that code paths in resource provider that deal |
| 50 // with sync tokens are tested. | 50 // with sync tokens are tested. |
| 51 capabilities_.delegated_sync_points_required = true; | 51 capabilities_.delegated_sync_points_required = true; |
| 52 } | 52 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 renderer_settings_, frame_sink_id_, begin_frame_source_.get(), | 91 renderer_settings_, frame_sink_id_, begin_frame_source_.get(), |
| 92 std::move(display_output_surface), std::move(scheduler), | 92 std::move(display_output_surface), std::move(scheduler), |
| 93 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get()))); | 93 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get()))); |
| 94 | 94 |
| 95 // We want the Display's OutputSurface to hear about lost context, and when | 95 // We want the Display's OutputSurface to hear about lost context, and when |
| 96 // this shares a context with it we should not be listening for lost context | 96 // this shares a context with it we should not be listening for lost context |
| 97 // callbacks on the context here. | 97 // callbacks on the context here. |
| 98 if (display_context_shared_with_compositor && context_provider()) | 98 if (display_context_shared_with_compositor && context_provider()) |
| 99 context_provider()->SetLostContextCallback(base::Closure()); | 99 context_provider()->SetLostContextCallback(base::Closure()); |
| 100 | 100 |
| 101 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 101 support_ = base::MakeUnique<CompositorFrameSinkSupport>( |
| 102 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 102 this, surface_manager_.get(), frame_sink_id_, false /* is_root */, |
| 103 true /* handles_frame_sink_id_invalidation */, | |
| 104 true /* needs_sync_points */); | |
| 105 client_->SetBeginFrameSource(&external_begin_frame_source_); | |
| 106 | |
| 103 display_->Initialize(this, surface_manager_.get()); | 107 display_->Initialize(this, surface_manager_.get()); |
| 104 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( | 108 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( |
| 105 enlarge_pass_texture_amount_); | 109 enlarge_pass_texture_amount_); |
| 106 display_->SetVisible(true); | 110 display_->SetVisible(true); |
| 107 bound_ = true; | |
| 108 return true; | 111 return true; |
| 109 } | 112 } |
| 110 | 113 |
| 111 void TestCompositorFrameSink::DetachFromClient() { | 114 void TestCompositorFrameSink::DetachFromClient() { |
| 112 // Some tests make BindToClient fail on purpose. ^__^ | 115 client_->SetBeginFrameSource(nullptr); |
| 113 if (bound_) { | 116 support_ = nullptr; |
| 114 surface_factory_->EvictSurface(); | 117 display_ = nullptr; |
| 115 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | |
| 116 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | |
| 117 display_ = nullptr; | |
| 118 bound_ = false; | |
| 119 } | |
| 120 surface_factory_ = nullptr; | |
| 121 local_surface_id_allocator_ = nullptr; | 118 local_surface_id_allocator_ = nullptr; |
| 122 surface_manager_ = nullptr; | 119 surface_manager_ = nullptr; |
| 123 test_client_ = nullptr; | 120 test_client_ = nullptr; |
| 124 CompositorFrameSink::DetachFromClient(); | 121 CompositorFrameSink::DetachFromClient(); |
| 125 } | 122 } |
| 126 | 123 |
| 127 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 124 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
| 128 test_client_->DisplayReceivedCompositorFrame(frame); | 125 test_client_->DisplayReceivedCompositorFrame(frame); |
| 129 | 126 |
| 130 if (!delegated_local_surface_id_.is_valid()) { | 127 if (!delegated_local_surface_id_.is_valid()) { |
| 131 delegated_local_surface_id_ = local_surface_id_allocator_->GenerateId(); | 128 delegated_local_surface_id_ = local_surface_id_allocator_->GenerateId(); |
| 132 } | 129 } |
| 133 display_->SetLocalSurfaceId(delegated_local_surface_id_, | 130 display_->SetLocalSurfaceId(delegated_local_surface_id_, |
| 134 frame.metadata.device_scale_factor); | 131 frame.metadata.device_scale_factor); |
| 135 | 132 |
| 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 133 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 137 display_->Resize(frame_size); | 134 display_->Resize(frame_size); |
| 138 | 135 |
| 139 bool synchronous = !display_->has_scheduler(); | 136 support_->SubmitCompositorFrame(delegated_local_surface_id_, |
| 140 | 137 std::move(frame)); |
| 141 SurfaceFactory::DrawCallback draw_callback; | |
| 142 if (!synchronous) { | |
| 143 // For async draws, we use a callback tell when it is done, but for sync | |
| 144 // draws we don't need one. Unretained is safe here because the callback | |
| 145 // will be run when |surface_factory_| is destroyed which is owned by this | |
| 146 // class. | |
| 147 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback, | |
| 148 base::Unretained(this)); | |
| 149 } | |
| 150 | |
| 151 surface_factory_->SubmitCompositorFrame(delegated_local_surface_id_, | |
| 152 std::move(frame), draw_callback); | |
| 153 | 138 |
| 154 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { | 139 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { |
| 155 surface_factory_->RequestCopyOfSurface(std::move(copy_request)); | 140 support_->RequestCopyOfSurface(std::move(copy_request)); |
| 156 } | 141 } |
| 157 copy_requests_.clear(); | 142 copy_requests_.clear(); |
| 158 | 143 |
| 159 if (synchronous) { | 144 if (!display_->has_scheduler()) { |
| 160 display_->DrawAndSwap(); | 145 display_->DrawAndSwap(); |
| 161 // Post this to get a new stack frame so that we exit this function before | 146 // Post this to get a new stack frame so that we exit this function before |
| 162 // calling the client to tell it that it is done. | 147 // calling the client to tell it that it is done. |
| 163 task_runner_->PostTask(FROM_HERE, | 148 task_runner_->PostTask( |
| 164 base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 149 FROM_HERE, |
| 165 weak_ptr_factory_.GetWeakPtr())); | 150 base::Bind(&TestCompositorFrameSink::SendCompositorFrameAckToClient, |
| 151 weak_ptr_factory_.GetWeakPtr())); | |
| 166 } | 152 } |
| 167 } | 153 } |
| 168 | 154 |
| 169 void TestCompositorFrameSink::DidDrawCallback() { | |
| 170 // This is to unthrottle the next frame, not actually a notice that drawing is | |
| 171 // done. | |
| 172 client_->DidReceiveCompositorFrameAck(); | |
| 173 } | |
| 174 | |
| 175 void TestCompositorFrameSink::ForceReclaimResources() { | 155 void TestCompositorFrameSink::ForceReclaimResources() { |
| 176 if (capabilities_.can_force_reclaim_resources && | 156 if (capabilities_.can_force_reclaim_resources && |
| 177 delegated_local_surface_id_.is_valid()) { | 157 delegated_local_surface_id_.is_valid()) { |
| 178 surface_factory_->ClearSurface(); | 158 support_->ForceReclaimResources(); |
| 179 } | 159 } |
| 180 } | 160 } |
| 181 | 161 |
| 182 void TestCompositorFrameSink::ReturnResources( | 162 void TestCompositorFrameSink::DidReceiveCompositorFrameAck() { |
| 163 // In synchronous mode, we manually send acks and this method should not be | |
| 164 // used. | |
| 165 if (!display_->has_scheduler()) | |
|
danakj
2017/03/02 21:58:54
The other way to do this, since you have have bran
Saman Sami
2017/03/02 22:09:49
Right. I think both approaches are equally good. I
| |
| 166 return; | |
| 167 client_->DidReceiveCompositorFrameAck(); | |
| 168 } | |
| 169 | |
| 170 void TestCompositorFrameSink::OnBeginFrame(const BeginFrameArgs& args) { | |
| 171 external_begin_frame_source_.OnBeginFrame(args); | |
| 172 } | |
| 173 | |
| 174 void TestCompositorFrameSink::ReclaimResources( | |
| 183 const ReturnedResourceArray& resources) { | 175 const ReturnedResourceArray& resources) { |
| 184 client_->ReclaimResources(resources); | 176 client_->ReclaimResources(resources); |
| 185 } | 177 } |
| 186 | 178 |
| 187 void TestCompositorFrameSink::SetBeginFrameSource( | 179 void TestCompositorFrameSink::WillDrawSurface( |
| 188 BeginFrameSource* begin_frame_source) { | 180 const LocalSurfaceId& local_surface_id, |
| 189 client_->SetBeginFrameSource(begin_frame_source); | 181 const gfx::Rect& damage_rect) {} |
| 190 } | |
| 191 | 182 |
| 192 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { | 183 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 193 client_->DidLoseCompositorFrameSink(); | 184 client_->DidLoseCompositorFrameSink(); |
| 194 } | 185 } |
| 195 | 186 |
| 196 void TestCompositorFrameSink::DisplayWillDrawAndSwap( | 187 void TestCompositorFrameSink::DisplayWillDrawAndSwap( |
| 197 bool will_draw_and_swap, | 188 bool will_draw_and_swap, |
| 198 const RenderPassList& render_passes) { | 189 const RenderPassList& render_passes) { |
| 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | 190 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
| 200 } | 191 } |
| 201 | 192 |
| 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 193 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 203 test_client_->DisplayDidDrawAndSwap(); | 194 test_client_->DisplayDidDrawAndSwap(); |
| 204 } | 195 } |
| 205 | 196 |
| 197 void TestCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { | |
| 198 support_->SetNeedsBeginFrame(needs_begin_frames); | |
| 199 } | |
| 200 | |
| 201 void TestCompositorFrameSink::OnDidFinishFrame(const BeginFrameAck& ack) {} | |
| 202 | |
| 203 void TestCompositorFrameSink::SendCompositorFrameAckToClient() { | |
| 204 client_->DidReceiveCompositorFrameAck(); | |
| 205 } | |
| 206 | |
| 206 } // namespace cc | 207 } // namespace cc |
| OLD | NEW |