Chromium Code Reviews| Index: components/exo/exo_compositor_frame_sink.cc |
| diff --git a/components/exo/exo_compositor_frame_sink.cc b/components/exo/exo_compositor_frame_sink.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..58555e3cf70bb3921976fe4838bde82f9ba52d1e |
| --- /dev/null |
| +++ b/components/exo/exo_compositor_frame_sink.cc |
| @@ -0,0 +1,146 @@ |
| +// 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/exo_compositor_frame_sink.h" |
| + |
| +#include "cc/surfaces/surface_manager.h" |
| + |
| +namespace exo { |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ExoComopositorFrameSink, public: |
| + |
| +ExoCompositorFrameSink::ExoCompositorFrameSink( |
| + 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); |
| +} |
| + |
| +ExoCompositorFrameSink::~ExoCompositorFrameSink() { |
| + if (begin_frame_source_ && needs_begin_frame_) |
| + begin_frame_source_->RemoveObserver(this); |
| + |
| + if (last_local_frame_id_.is_valid()) |
| + surface_factory_.Destroy(last_local_frame_id_); |
| + |
| + surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| + |
| + surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// cc::SurfaceFactoryClient overrides: |
| + |
| +void ExoCompositorFrameSink::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 ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, |
| + const gfx::Rect& damage_rect) { |
| + if (client_) |
| + client_->WillDrawSurface(); |
| +} |
| + |
| +void ExoCompositorFrameSink::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 ExoCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { |
| + needs_begin_frame_ = needs_begin_frame; |
| + UpdateNeedsBeginFrameInternal(); |
| +} |
| + |
| +void ExoCompositorFrameSink::SubmitCompositorFrame( |
| + const cc::LocalFrameId& local_frame_id, |
| + cc::CompositorFrame frame) { |
| + if (local_frame_id != last_local_frame_id_) { |
| + surface_factory_.Create(local_frame_id); |
| + } |
| + ++ack_pending_count_; |
| + surface_factory_.SubmitCompositorFrame( |
| + local_frame_id, std::move(frame), |
| + base::Bind(&ExoCompositorFrameSink::DidReceiveCompositorFrameAck, |
| + base::Unretained(this))); |
| + if (last_local_frame_id_.is_valid() && |
| + local_frame_id != last_local_frame_id_) { |
| + surface_factory_.SetPreviousFrameSurface(local_frame_id, |
| + last_local_frame_id_); |
| + surface_factory_.Destroy(last_local_frame_id_); |
| + } |
| + last_local_frame_id_ = local_frame_id; |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// cc::BeginFrameObserver overrides: |
| + |
| +void ExoCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| + // TODO(staraz): Add active_farme_callbacks stuff from Surface |
| + |
| + UpdateNeedsBeginFrameInternal(); |
| + last_begin_frame_args_ = args; |
|
Fady Samuel
2016/11/23 21:14:48
You should call out to the client from here:
if (
Alex Z.
2016/11/24 18:58:45
Done.
|
| +} |
| + |
| +const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs() |
| + const { |
| + return last_begin_frame_args_; |
| +} |
| + |
| +void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ExoComopositorFrameSink, private: |
| + |
| +void ExoCompositorFrameSink::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 ExoCompositorFrameSink::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 |