Chromium Code Reviews| Index: services/ui/ws/display_client_compositor_frame_sink.cc |
| diff --git a/services/ui/ws/display_client_compositor_frame_sink.cc b/services/ui/ws/display_client_compositor_frame_sink.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..29c8235831641c86806ee7489e18ed9f460328bc |
| --- /dev/null |
| +++ b/services/ui/ws/display_client_compositor_frame_sink.cc |
| @@ -0,0 +1,107 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "services/ui/ws/display_client_compositor_frame_sink.h" |
| + |
| +#include "base/threading/thread_checker.h" |
| +#include "cc/output/compositor_frame_sink_client.h" |
| + |
| +namespace ui { |
| +namespace ws { |
| + |
| +DisplayClientCompositorFrameSink::DisplayClientCompositorFrameSink( |
| + const cc::FrameSinkId& frame_sink_id, |
| + cc::mojom::MojoCompositorFrameSinkAssociatedPtr compositor_frame_sink, |
| + cc::mojom::DisplayPrivateAssociatedPtr display_private, |
| + cc::mojom::MojoCompositorFrameSinkClientRequest client_request) |
| + : cc::CompositorFrameSink(nullptr, nullptr, nullptr, nullptr), |
| + compositor_frame_sink_(std::move(compositor_frame_sink)), |
| + client_binding_(this, std::move(client_request)), |
| + display_private_(std::move(display_private)), |
| + frame_sink_id_(frame_sink_id) {} |
| + |
| +DisplayClientCompositorFrameSink::~DisplayClientCompositorFrameSink() {} |
| + |
| +bool DisplayClientCompositorFrameSink::BindToClient( |
| + cc::CompositorFrameSinkClient* client) { |
| + if (!cc::CompositorFrameSink::BindToClient(client)) |
| + return false; |
| + DCHECK(!thread_checker_); |
| + thread_checker_.reset(new base::ThreadChecker()); |
| + |
| + begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| + |
| + client->SetBeginFrameSource(begin_frame_source_.get()); |
| + return true; |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::DetachFromClient() { |
| + client_->SetBeginFrameSource(nullptr); |
| + begin_frame_source_.reset(); |
| + cc::CompositorFrameSink::DetachFromClient(); |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::SubmitCompositorFrame( |
| + cc::CompositorFrame frame) { |
| + DCHECK(thread_checker_); |
| + DCHECK(thread_checker_->CalledOnValidThread()); |
| + if (!compositor_frame_sink_) |
| + return; |
| + |
| + gfx::Size frame_size = last_submitted_frame_size_; |
| + if (!frame.render_pass_list.empty()) |
| + frame_size = frame.render_pass_list.back()->output_rect.size(); |
| + |
| + if (!local_surface_id_.is_valid() || |
| + frame_size != last_submitted_frame_size_) { |
| + local_surface_id_ = id_allocator_.GenerateId(); |
| + display_private_->ResizeDisplay(frame_size); |
| + } |
| + display_private_->SetLocalSurfaceId(local_surface_id_, |
| + frame.metadata.device_scale_factor); |
| + compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
| + std::move(frame)); |
| + last_submitted_frame_size_ = frame_size; |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::DidReceiveCompositorFrameAck() { |
| + DCHECK(thread_checker_); |
| + DCHECK(thread_checker_->CalledOnValidThread()); |
| + if (!client_) |
| + return; |
| + client_->DidReceiveCompositorFrameAck(); |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::OnBeginFrame( |
| + const cc::BeginFrameArgs& begin_frame_args) { |
|
Fady Samuel
2017/03/10 19:17:39
DCHECK(thread_checker_);
DCHECK(thread_checker_->C
Alex Z.
2017/03/10 19:28:50
Done.
|
| + begin_frame_source_->OnBeginFrame(begin_frame_args); |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::ReclaimResources( |
| + const cc::ReturnedResourceArray& resources) { |
| + DCHECK(thread_checker_); |
| + DCHECK(thread_checker_->CalledOnValidThread()); |
| + if (!client_) |
| + return; |
| + client_->ReclaimResources(resources); |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::WillDrawSurface( |
| + const cc::LocalSurfaceId& local_surface_id, |
| + const gfx::Rect& damage_rect) { |
| + // TODO(fsamuel, staraz): Implement this. |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::OnNeedsBeginFrames( |
| + bool needs_begin_frames) { |
|
Fady Samuel
2017/03/10 19:17:40
DCHECK(thread_checker_);
DCHECK(thread_checker_->C
Alex Z.
2017/03/10 19:28:50
Done.
|
| + compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
| +} |
| + |
| +void DisplayClientCompositorFrameSink::OnDidFinishFrame( |
| + const cc::BeginFrameAck& ack) { |
| + // TODO(eseckler): Pass on the ack to compositor_frame_sink_. |
| +} |
| + |
| +} // namespace ws |
| +} // namespace ui |