| 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 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 generate_local_surface_id) |
| 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 generate_local_surface_id_(generate_local_surface_id) { |
| 28 DETACH_FROM_THREAD(thread_checker_); | 28 DETACH_FROM_THREAD(thread_checker_); |
| 29 } | 29 } |
| 30 | 30 |
| 31 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} | 31 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} |
| 32 | 32 |
| 33 void ClientCompositorFrameSink::SetSurfaceChangedCallback( |
| 34 const SurfaceChangedCallback& callback) { |
| 35 surface_changed_callback_ = callback; |
| 36 } |
| 37 |
| 33 bool ClientCompositorFrameSink::BindToClient( | 38 bool ClientCompositorFrameSink::BindToClient( |
| 34 cc::CompositorFrameSinkClient* client) { | 39 cc::CompositorFrameSinkClient* client) { |
| 35 if (!cc::CompositorFrameSink::BindToClient(client)) | 40 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 36 return false; | 41 return false; |
| 37 | 42 |
| 38 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 43 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 39 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); | 44 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); |
| 40 client_binding_.reset( | 45 client_binding_.reset( |
| 41 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( | 46 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( |
| 42 this, std::move(client_request_))); | 47 this, std::move(client_request_))); |
| 43 | 48 |
| 44 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 49 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 45 | 50 |
| 46 client->SetBeginFrameSource(begin_frame_source_.get()); | 51 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 47 return true; | 52 return true; |
| 48 } | 53 } |
| 49 | 54 |
| 50 void ClientCompositorFrameSink::DetachFromClient() { | 55 void ClientCompositorFrameSink::DetachFromClient() { |
| 51 client_->SetBeginFrameSource(nullptr); | 56 client_->SetBeginFrameSource(nullptr); |
| 52 begin_frame_source_.reset(); | 57 begin_frame_source_.reset(); |
| 53 client_binding_.reset(); | 58 client_binding_.reset(); |
| 54 compositor_frame_sink_.reset(); | 59 compositor_frame_sink_.reset(); |
| 55 cc::CompositorFrameSink::DetachFromClient(); | 60 cc::CompositorFrameSink::DetachFromClient(); |
| 56 } | 61 } |
| 57 | 62 |
| 58 void ClientCompositorFrameSink::SetLocalSurfaceId( | 63 void ClientCompositorFrameSink::SetLocalSurfaceId( |
| 59 const cc::LocalSurfaceId& local_surface_id) { | 64 const cc::LocalSurfaceId& local_surface_id) { |
| 60 DCHECK(local_surface_id.is_valid()); | 65 DCHECK(local_surface_id.is_valid()); |
| 61 DCHECK(enable_surface_synchronization_); | 66 DCHECK(!generate_local_surface_id_); |
| 62 local_surface_id_ = local_surface_id; | 67 local_surface_id_ = local_surface_id; |
| 63 } | 68 } |
| 64 | 69 |
| 65 void ClientCompositorFrameSink::SubmitCompositorFrame( | 70 void ClientCompositorFrameSink::SubmitCompositorFrame( |
| 66 cc::CompositorFrame frame) { | 71 cc::CompositorFrame frame) { |
| 67 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 72 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 68 if (!compositor_frame_sink_) | 73 if (!compositor_frame_sink_) |
| 69 return; | 74 return; |
| 70 | 75 |
| 71 DCHECK(frame.metadata.begin_frame_ack.has_damage); | 76 DCHECK(frame.metadata.begin_frame_ack.has_damage); |
| 72 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, | 77 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, |
| 73 frame.metadata.begin_frame_ack.sequence_number); | 78 frame.metadata.begin_frame_ack.sequence_number); |
| 74 | 79 |
| 80 bool surface_changed = false; |
| 75 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 81 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 76 if (!local_surface_id_.is_valid() || | 82 if (!local_surface_id_.is_valid() || |
| 77 frame_size != last_submitted_frame_size_) { | 83 frame_size != last_submitted_frame_size_) { |
| 78 last_submitted_frame_size_ = frame_size; | 84 last_submitted_frame_size_ = frame_size; |
| 79 if (!enable_surface_synchronization_) | 85 if (generate_local_surface_id_) { |
| 80 local_surface_id_ = id_allocator_.GenerateId(); | 86 local_surface_id_ = id_allocator_.GenerateId(); |
| 87 surface_changed = true; |
| 88 } |
| 81 } | 89 } |
| 82 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, | 90 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
| 83 std::move(frame)); | 91 std::move(frame)); |
| 92 if (surface_changed && surface_changed_callback_) |
| 93 surface_changed_callback_.Run(local_surface_id_, frame_size); |
| 84 } | 94 } |
| 85 | 95 |
| 86 void ClientCompositorFrameSink::DidNotProduceFrame( | 96 void ClientCompositorFrameSink::DidNotProduceFrame( |
| 87 const cc::BeginFrameAck& ack) { | 97 const cc::BeginFrameAck& ack) { |
| 88 DCHECK(!ack.has_damage); | 98 DCHECK(!ack.has_damage); |
| 89 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); | 99 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); |
| 90 compositor_frame_sink_->DidNotProduceFrame(ack); | 100 compositor_frame_sink_->DidNotProduceFrame(ack); |
| 91 } | 101 } |
| 92 | 102 |
| 93 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( | 103 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 110 if (!client_) | 120 if (!client_) |
| 111 return; | 121 return; |
| 112 client_->ReclaimResources(resources); | 122 client_->ReclaimResources(resources); |
| 113 } | 123 } |
| 114 | 124 |
| 115 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { | 125 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 116 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | 126 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
| 117 } | 127 } |
| 118 | 128 |
| 119 } // namespace viz | 129 } // namespace viz |
| OLD | NEW |