| Index: components/exo/compositor_frame_sink.cc
|
| diff --git a/components/exo/compositor_frame_sink.cc b/components/exo/compositor_frame_sink.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2d59b3ec48cd2867abff54c87526eeac7fa1297e
|
| --- /dev/null
|
| +++ b/components/exo/compositor_frame_sink.cc
|
| @@ -0,0 +1,166 @@
|
| +// Copyright 2016 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 "components/exo/compositor_frame_sink.h"
|
| +
|
| +#include "base/debug/stack_trace.h"
|
| +#include "cc/surfaces/surface.h"
|
| +#include "cc/surfaces/surface_manager.h"
|
| +#include "mojo/public/cpp/bindings/strong_binding.h"
|
| +
|
| +namespace exo {
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// ExoComopositorFrameSink, public:
|
| +
|
| +// static
|
| +void CompositorFrameSink::Create(
|
| + const cc::FrameSinkId& frame_sink_id,
|
| + cc::SurfaceManager* surface_manager,
|
| + cc::mojom::MojoCompositorFrameSinkClientPtr client,
|
| + cc::mojom::MojoCompositorFrameSinkRequest request) {
|
| + auto* impl = new CompositorFrameSink(frame_sink_id, surface_manager,
|
| + std::move(client));
|
| + auto binding =
|
| + mojo::MakeStrongBinding(base::WrapUnique(impl), std::move(request));
|
| + impl->binding_ = binding;
|
| +}
|
| +
|
| +CompositorFrameSink::CompositorFrameSink(
|
| + const cc::FrameSinkId& frame_sink_id,
|
| + cc::SurfaceManager* surface_manager,
|
| + cc::mojom::MojoCompositorFrameSinkClientPtr client)
|
| + : frame_sink_id_(frame_sink_id),
|
| + surface_manager_(surface_manager),
|
| + surface_factory_(frame_sink_id, surface_manager, this),
|
| + client_(std::move(client)) {
|
| + surface_manager_->RegisterFrameSinkId(frame_sink_id_);
|
| + surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
|
| +}
|
| +
|
| +CompositorFrameSink::~CompositorFrameSink() {
|
| + surface_factory_.EvictSurface();
|
| + surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
|
| + surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// cc::SurfaceFactoryClient overrides:
|
| +
|
| +void CompositorFrameSink::ReturnResources(
|
| + const cc::ReturnedResourceArray& resources) {
|
| + if (resources.empty())
|
| + return;
|
| +
|
| + if (!ack_pending_count_ && client_) {
|
| + client_->ReclaimResources(resources);
|
| + return;
|
| + }
|
| +
|
| + std::copy(resources.begin(), resources.end(),
|
| + std::back_inserter(surface_returned_resources_));
|
| +}
|
| +
|
| +void CompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id,
|
| + const gfx::Rect& damage_rect) {
|
| + if (client_)
|
| + client_->WillDrawSurface();
|
| +}
|
| +
|
| +void CompositorFrameSink::SetBeginFrameSource(
|
| + cc::BeginFrameSource* begin_frame_source) {
|
| + if (begin_frame_source_ && added_frame_observer_) {
|
| + begin_frame_source_->RemoveObserver(this);
|
| + added_frame_observer_ = false;
|
| + }
|
| + begin_frame_source_ = begin_frame_source;
|
| + UpdateNeedsBeginFrameInternal();
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// cc::mojom::MojoCompositorFrameSink overrides:
|
| +
|
| +void CompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) {
|
| + needs_begin_frame_ = needs_begin_frame;
|
| + UpdateNeedsBeginFrameInternal();
|
| +}
|
| +
|
| +void CompositorFrameSink::SubmitCompositorFrame(
|
| + const cc::LocalFrameId& local_frame_id,
|
| + cc::CompositorFrame frame) {
|
| + ++ack_pending_count_;
|
| + surface_factory_.SubmitCompositorFrame(
|
| + local_frame_id, std::move(frame),
|
| + base::Bind(&CompositorFrameSink::DidReceiveCompositorFrameAck,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +void CompositorFrameSink::EvictFrame() {
|
| + surface_factory_.EvictSurface();
|
| +}
|
| +
|
| +void CompositorFrameSink::Require(const cc::LocalFrameId& local_frame_id,
|
| + const cc::SurfaceSequence& sequence) {
|
| + cc::Surface* surface = surface_manager_->GetSurfaceForId(
|
| + cc::SurfaceId(frame_sink_id_, local_frame_id));
|
| + if (!surface) {
|
| + LOG(ERROR) << "Attempting to require callback on nonexistent surface";
|
| + return;
|
| + }
|
| + surface->AddDestructionDependency(sequence);
|
| +}
|
| +
|
| +void CompositorFrameSink::Satisfy(const cc::SurfaceSequence& sequence) {
|
| + std::vector<uint32_t> sequences;
|
| + sequences.push_back(sequence.sequence);
|
| + surface_manager_->DidSatisfySequences(sequence.frame_sink_id, &sequences);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// cc::BeginFrameObserver overrides:
|
| +
|
| +void CompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) {
|
| + UpdateNeedsBeginFrameInternal();
|
| + last_begin_frame_args_ = args;
|
| + if (client_)
|
| + client_->OnBeginFrame(args);
|
| +}
|
| +
|
| +const cc::BeginFrameArgs& CompositorFrameSink::LastUsedBeginFrameArgs() const {
|
| + return last_begin_frame_args_;
|
| +}
|
| +
|
| +void CompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// ExoComopositorFrameSink, private:
|
| +
|
| +void CompositorFrameSink::UpdateNeedsBeginFrameInternal() {
|
| + if (!begin_frame_source_)
|
| + return;
|
| +
|
| + if (needs_begin_frame_ == added_frame_observer_)
|
| + return;
|
| +
|
| + added_frame_observer_ = needs_begin_frame_;
|
| + if (needs_begin_frame_)
|
| + begin_frame_source_->AddObserver(this);
|
| + else
|
| + begin_frame_source_->RemoveObserver(this);
|
| +}
|
| +
|
| +void CompositorFrameSink::DidReceiveCompositorFrameAck() {
|
| + if (!client_)
|
| + return;
|
| +
|
| + client_->DidReceiveCompositorFrameAck();
|
| + DCHECK_GT(ack_pending_count_, 0);
|
| + if (!surface_returned_resources_.empty()) {
|
| + client_->ReclaimResources(surface_returned_resources_);
|
| + surface_returned_resources_.clear();
|
| + }
|
| + ack_pending_count_--;
|
| +}
|
| +
|
| +} // namespace exo
|
|
|