| 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 "components/viz/client/client_compositor_frame_sink.h" | 5 #include "components/viz/client/client_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/output/begin_frame_args.h" | 9 #include "cc/output/begin_frame_args.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/compositor_frame_sink_client.h" | 11 #include "cc/output/compositor_frame_sink_client.h" |
| 12 | 12 |
| 13 namespace viz { | 13 namespace viz { |
| 14 | 14 |
| 15 ClientCompositorFrameSink::ClientCompositorFrameSink( | 15 ClientCompositorFrameSink::ClientCompositorFrameSink( |
| 16 scoped_refptr<cc::ContextProvider> context_provider, | 16 scoped_refptr<cc::ContextProvider> context_provider, |
| 17 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 17 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 18 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 19 cc::SharedBitmapManager* shared_bitmap_manager, |
| 20 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source, |
| 18 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, | 21 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, |
| 19 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, | 22 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, |
| 20 bool enable_surface_synchronization) | 23 bool enable_surface_synchronization) |
| 21 : cc::CompositorFrameSink(std::move(context_provider), | 24 : cc::CompositorFrameSink(std::move(context_provider), |
| 22 nullptr, | 25 std::move(worker_context_provider), |
| 23 gpu_memory_buffer_manager, | 26 gpu_memory_buffer_manager, |
| 24 nullptr), | 27 shared_bitmap_manager), |
| 28 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)), |
| 25 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), | 29 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), |
| 26 client_request_(std::move(client_request)), | 30 client_request_(std::move(client_request)), |
| 31 client_binding_(this), |
| 27 enable_surface_synchronization_(enable_surface_synchronization) { | 32 enable_surface_synchronization_(enable_surface_synchronization) { |
| 28 DETACH_FROM_THREAD(thread_checker_); | 33 DETACH_FROM_THREAD(thread_checker_); |
| 29 } | 34 } |
| 35 |
| 36 ClientCompositorFrameSink::ClientCompositorFrameSink( |
| 37 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 38 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source, |
| 39 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, |
| 40 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, |
| 41 bool enable_surface_synchronization) |
| 42 : cc::CompositorFrameSink(std::move(vulkan_context_provider)), |
| 43 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)), |
| 44 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), |
| 45 client_request_(std::move(client_request)), |
| 46 client_binding_(this), |
| 47 enable_surface_synchronization_(enable_surface_synchronization) { |
| 48 DETACH_FROM_THREAD(thread_checker_); |
| 49 } |
| 30 | 50 |
| 31 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} | 51 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} |
| 32 | 52 |
| 33 bool ClientCompositorFrameSink::BindToClient( | 53 bool ClientCompositorFrameSink::BindToClient( |
| 34 cc::CompositorFrameSinkClient* client) { | 54 cc::CompositorFrameSinkClient* client) { |
| 55 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 56 |
| 35 if (!cc::CompositorFrameSink::BindToClient(client)) | 57 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 36 return false; | 58 return false; |
| 37 | 59 |
| 38 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 39 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); | 60 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); |
| 40 client_binding_.reset( | 61 client_binding_.Bind(std::move(client_request_)); |
| 41 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( | |
| 42 this, std::move(client_request_))); | |
| 43 | 62 |
| 44 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 63 if (synthetic_begin_frame_source_) { |
| 64 client->SetBeginFrameSource(synthetic_begin_frame_source_.get()); |
| 65 } else { |
| 66 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 67 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 68 } |
| 45 | 69 |
| 46 client->SetBeginFrameSource(begin_frame_source_.get()); | |
| 47 return true; | 70 return true; |
| 48 } | 71 } |
| 49 | 72 |
| 50 void ClientCompositorFrameSink::DetachFromClient() { | 73 void ClientCompositorFrameSink::DetachFromClient() { |
| 74 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 51 client_->SetBeginFrameSource(nullptr); | 75 client_->SetBeginFrameSource(nullptr); |
| 52 begin_frame_source_.reset(); | 76 begin_frame_source_.reset(); |
| 53 client_binding_.reset(); | 77 synthetic_begin_frame_source_.reset(); |
| 78 client_binding_.Close(); |
| 54 compositor_frame_sink_.reset(); | 79 compositor_frame_sink_.reset(); |
| 55 cc::CompositorFrameSink::DetachFromClient(); | 80 cc::CompositorFrameSink::DetachFromClient(); |
| 56 } | 81 } |
| 57 | 82 |
| 58 void ClientCompositorFrameSink::SetLocalSurfaceId( | 83 void ClientCompositorFrameSink::SetLocalSurfaceId( |
| 59 const cc::LocalSurfaceId& local_surface_id) { | 84 const cc::LocalSurfaceId& local_surface_id) { |
| 60 DCHECK(local_surface_id.is_valid()); | 85 DCHECK(local_surface_id.is_valid()); |
| 61 DCHECK(enable_surface_synchronization_); | 86 DCHECK(enable_surface_synchronization_); |
| 62 local_surface_id_ = local_surface_id; | 87 local_surface_id_ = local_surface_id; |
| 63 } | 88 } |
| 64 | 89 |
| 65 void ClientCompositorFrameSink::SubmitCompositorFrame( | 90 void ClientCompositorFrameSink::SubmitCompositorFrame( |
| 66 cc::CompositorFrame frame) { | 91 cc::CompositorFrame frame) { |
| 67 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 92 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 68 if (!compositor_frame_sink_) | |
| 69 return; | |
| 70 | |
| 71 DCHECK(frame.metadata.begin_frame_ack.has_damage); | 93 DCHECK(frame.metadata.begin_frame_ack.has_damage); |
| 72 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, | 94 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, |
| 73 frame.metadata.begin_frame_ack.sequence_number); | 95 frame.metadata.begin_frame_ack.sequence_number); |
| 74 | 96 |
| 75 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 97 if (!enable_surface_synchronization_ && |
| 76 if (!local_surface_id_.is_valid() || | 98 (!local_surface_id_.is_valid() || ShouldAllocateNewLocalSurfaceId(frame))) |
| 77 frame_size != last_submitted_frame_size_) { | 99 local_surface_id_ = id_allocator_.GenerateId(); |
| 78 last_submitted_frame_size_ = frame_size; | 100 |
| 79 if (!enable_surface_synchronization_) | 101 surface_size_ = frame.render_pass_list.back()->output_rect.size(); |
| 80 local_surface_id_ = id_allocator_.GenerateId(); | 102 device_scale_factor_ = frame.metadata.device_scale_factor; |
| 81 } | 103 |
| 82 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, | 104 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
| 83 std::move(frame)); | 105 std::move(frame)); |
| 84 } | 106 } |
| 85 | 107 |
| 86 void ClientCompositorFrameSink::DidNotProduceFrame( | 108 void ClientCompositorFrameSink::DidNotProduceFrame( |
| 87 const cc::BeginFrameAck& ack) { | 109 const cc::BeginFrameAck& ack) { |
| 88 DCHECK(!ack.has_damage); | 110 DCHECK(!ack.has_damage); |
| 89 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); | 111 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); |
| 90 compositor_frame_sink_->DidNotProduceFrame(ack); | 112 compositor_frame_sink_->DidNotProduceFrame(ack); |
| 91 } | 113 } |
| 92 | 114 |
| 93 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( | 115 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( |
| 94 const cc::ReturnedResourceArray& resources) { | 116 const cc::ReturnedResourceArray& resources) { |
| 95 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 117 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 96 if (!client_) | |
| 97 return; | |
| 98 client_->ReclaimResources(resources); | 118 client_->ReclaimResources(resources); |
| 99 client_->DidReceiveCompositorFrameAck(); | 119 client_->DidReceiveCompositorFrameAck(); |
| 100 } | 120 } |
| 101 | 121 |
| 102 void ClientCompositorFrameSink::OnBeginFrame( | 122 void ClientCompositorFrameSink::OnBeginFrame( |
| 103 const cc::BeginFrameArgs& begin_frame_args) { | 123 const cc::BeginFrameArgs& begin_frame_args) { |
| 104 begin_frame_source_->OnBeginFrame(begin_frame_args); | 124 if (begin_frame_source_) |
| 125 begin_frame_source_->OnBeginFrame(begin_frame_args); |
| 105 } | 126 } |
| 106 | 127 |
| 107 void ClientCompositorFrameSink::ReclaimResources( | 128 void ClientCompositorFrameSink::ReclaimResources( |
| 108 const cc::ReturnedResourceArray& resources) { | 129 const cc::ReturnedResourceArray& resources) { |
| 109 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 130 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 110 if (!client_) | |
| 111 return; | |
| 112 client_->ReclaimResources(resources); | 131 client_->ReclaimResources(resources); |
| 113 } | 132 } |
| 114 | 133 |
| 134 bool ClientCompositorFrameSink::ShouldAllocateNewLocalSurfaceId( |
| 135 const cc::CompositorFrame& frame) { |
| 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 137 return frame_size != surface_size_ || |
| 138 device_scale_factor_ != frame.metadata.device_scale_factor; |
| 139 } |
| 140 |
| 115 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { | 141 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 116 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | 142 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
| 117 } | 143 } |
| 118 | 144 |
| 119 } // namespace viz | 145 } // namespace viz |
| OLD | NEW |