| OLD | NEW |
| 1 // Copyright 2014 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 "services/ui/public/cpp/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 ui { | 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 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 17 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 18 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, | 18 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, |
| 19 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, | 19 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, |
| 20 bool enable_surface_synchronization) | 20 bool enable_surface_synchronization) |
| 21 : cc::CompositorFrameSink(std::move(context_provider), | 21 : cc::CompositorFrameSink(std::move(context_provider), |
| 22 nullptr, | 22 nullptr, |
| 23 gpu_memory_buffer_manager, | 23 gpu_memory_buffer_manager, |
| 24 nullptr), | 24 nullptr), |
| 25 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), | 25 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), |
| 26 client_request_(std::move(client_request)), | 26 client_request_(std::move(client_request)), |
| 27 enable_surface_synchronization_(enable_surface_synchronization) {} | 27 enable_surface_synchronization_(enable_surface_synchronization) { |
| 28 DETACH_FROM_THREAD(thread_checker_); |
| 29 } |
| 28 | 30 |
| 29 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} | 31 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} |
| 30 | 32 |
| 31 bool ClientCompositorFrameSink::BindToClient( | 33 bool ClientCompositorFrameSink::BindToClient( |
| 32 cc::CompositorFrameSinkClient* client) { | 34 cc::CompositorFrameSinkClient* client) { |
| 33 if (!cc::CompositorFrameSink::BindToClient(client)) | 35 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 34 return false; | 36 return false; |
| 35 | 37 |
| 36 DCHECK(!thread_checker_); | 38 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 37 thread_checker_.reset(new base::ThreadChecker()); | |
| 38 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); | 39 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); |
| 39 client_binding_.reset( | 40 client_binding_.reset( |
| 40 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( | 41 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( |
| 41 this, std::move(client_request_))); | 42 this, std::move(client_request_))); |
| 42 | 43 |
| 43 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 44 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 44 | 45 |
| 45 client->SetBeginFrameSource(begin_frame_source_.get()); | 46 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 | 49 |
| 49 void ClientCompositorFrameSink::DetachFromClient() { | 50 void ClientCompositorFrameSink::DetachFromClient() { |
| 50 client_->SetBeginFrameSource(nullptr); | 51 client_->SetBeginFrameSource(nullptr); |
| 51 begin_frame_source_.reset(); | 52 begin_frame_source_.reset(); |
| 52 client_binding_.reset(); | 53 client_binding_.reset(); |
| 53 compositor_frame_sink_.reset(); | 54 compositor_frame_sink_.reset(); |
| 54 cc::CompositorFrameSink::DetachFromClient(); | 55 cc::CompositorFrameSink::DetachFromClient(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void ClientCompositorFrameSink::SetLocalSurfaceId( | 58 void ClientCompositorFrameSink::SetLocalSurfaceId( |
| 58 const cc::LocalSurfaceId& local_surface_id) { | 59 const cc::LocalSurfaceId& local_surface_id) { |
| 59 DCHECK(local_surface_id.is_valid()); | 60 DCHECK(local_surface_id.is_valid()); |
| 60 DCHECK(enable_surface_synchronization_); | 61 DCHECK(enable_surface_synchronization_); |
| 61 local_surface_id_ = local_surface_id; | 62 local_surface_id_ = local_surface_id; |
| 62 } | 63 } |
| 63 | 64 |
| 64 void ClientCompositorFrameSink::SubmitCompositorFrame( | 65 void ClientCompositorFrameSink::SubmitCompositorFrame( |
| 65 cc::CompositorFrame frame) { | 66 cc::CompositorFrame frame) { |
| 66 DCHECK(thread_checker_); | 67 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 67 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 68 if (!compositor_frame_sink_) | 68 if (!compositor_frame_sink_) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 DCHECK(frame.metadata.begin_frame_ack.has_damage); | 71 DCHECK(frame.metadata.begin_frame_ack.has_damage); |
| 72 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, | 72 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, |
| 73 frame.metadata.begin_frame_ack.sequence_number); | 73 frame.metadata.begin_frame_ack.sequence_number); |
| 74 | 74 |
| 75 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 75 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 76 if (!local_surface_id_.is_valid() || | 76 if (!local_surface_id_.is_valid() || |
| 77 frame_size != last_submitted_frame_size_) { | 77 frame_size != last_submitted_frame_size_) { |
| 78 last_submitted_frame_size_ = frame_size; | 78 last_submitted_frame_size_ = frame_size; |
| 79 if (!enable_surface_synchronization_) | 79 if (!enable_surface_synchronization_) |
| 80 local_surface_id_ = id_allocator_.GenerateId(); | 80 local_surface_id_ = id_allocator_.GenerateId(); |
| 81 } | 81 } |
| 82 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, | 82 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
| 83 std::move(frame)); | 83 std::move(frame)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void ClientCompositorFrameSink::DidNotProduceFrame( | 86 void ClientCompositorFrameSink::DidNotProduceFrame( |
| 87 const cc::BeginFrameAck& ack) { | 87 const cc::BeginFrameAck& ack) { |
| 88 DCHECK(!ack.has_damage); | 88 DCHECK(!ack.has_damage); |
| 89 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); | 89 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); |
| 90 compositor_frame_sink_->DidNotProduceFrame(ack); | 90 compositor_frame_sink_->DidNotProduceFrame(ack); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( | 93 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( |
| 94 const cc::ReturnedResourceArray& resources) { | 94 const cc::ReturnedResourceArray& resources) { |
| 95 DCHECK(thread_checker_); | 95 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 96 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 97 if (!client_) | 96 if (!client_) |
| 98 return; | 97 return; |
| 99 client_->ReclaimResources(resources); | 98 client_->ReclaimResources(resources); |
| 100 client_->DidReceiveCompositorFrameAck(); | 99 client_->DidReceiveCompositorFrameAck(); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void ClientCompositorFrameSink::OnBeginFrame( | 102 void ClientCompositorFrameSink::OnBeginFrame( |
| 104 const cc::BeginFrameArgs& begin_frame_args) { | 103 const cc::BeginFrameArgs& begin_frame_args) { |
| 105 begin_frame_source_->OnBeginFrame(begin_frame_args); | 104 begin_frame_source_->OnBeginFrame(begin_frame_args); |
| 106 } | 105 } |
| 107 | 106 |
| 108 void ClientCompositorFrameSink::ReclaimResources( | 107 void ClientCompositorFrameSink::ReclaimResources( |
| 109 const cc::ReturnedResourceArray& resources) { | 108 const cc::ReturnedResourceArray& resources) { |
| 110 DCHECK(thread_checker_); | 109 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 111 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 112 if (!client_) | 110 if (!client_) |
| 113 return; | 111 return; |
| 114 client_->ReclaimResources(resources); | 112 client_->ReclaimResources(resources); |
| 115 } | 113 } |
| 116 | 114 |
| 117 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { | 115 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 118 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | 116 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
| 119 } | 117 } |
| 120 | 118 |
| 121 } // namespace ui | 119 } // namespace viz |
| OLD | NEW |