| 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..5d719fa1dab4290c2bcdd7c33ffca4ff8adfccf4
|
| --- /dev/null
|
| +++ b/services/ui/ws/display_client_compositor_frame_sink.cc
|
| @@ -0,0 +1,106 @@
|
| +// 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_ = base::MakeUnique<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_->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_->CalledOnValidThread());
|
| + if (!client_)
|
| + return;
|
| + client_->DidReceiveCompositorFrameAck();
|
| +}
|
| +
|
| +void DisplayClientCompositorFrameSink::OnBeginFrame(
|
| + const cc::BeginFrameArgs& begin_frame_args) {
|
| + DCHECK(thread_checker_->CalledOnValidThread());
|
| + begin_frame_source_->OnBeginFrame(begin_frame_args);
|
| +}
|
| +
|
| +void DisplayClientCompositorFrameSink::ReclaimResources(
|
| + const cc::ReturnedResourceArray& resources) {
|
| + 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) {
|
| + DCHECK(thread_checker_->CalledOnValidThread());
|
| + 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
|
|
|