Chromium Code Reviews| Index: components/exo/compositor_frame_sink_holder.cc |
| diff --git a/components/exo/compositor_frame_sink_holder.cc b/components/exo/compositor_frame_sink_holder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8a92cbb25fb33ae9ee5ba3496cf70952beeee424 |
| --- /dev/null |
| +++ b/components/exo/compositor_frame_sink_holder.cc |
| @@ -0,0 +1,107 @@ |
| +// 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_holder.h" |
| + |
| +#include "cc/resources/returned_resource.h" |
| +#include "components/exo/surface.h" |
| + |
| +namespace exo { |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// CompositorFrameSinkHolder, public: |
| +CompositorFrameSinkHolder::CompositorFrameSinkHolder( |
| + std::unique_ptr<ExoCompositorFrameSink> compositor_frame_sink, |
| + base::WeakPtr<Surface> surface, |
| + cc::mojom::MojoCompositorFrameSinkClientRequest request) |
| + : compositor_frame_sink_(std::move(compositor_frame_sink)), |
| + surface_(surface), |
| + begin_frame_source_(base::MakeUnique<cc::ExternalBeginFrameSource>(this)), |
| + binding_(this, std::move(request)) {} |
| + |
| +bool CompositorFrameSinkHolder::HasReleaseCallbacks(cc::ResourceId id) { |
| + return release_callbacks_.count(id); |
| +} |
| + |
| +void CompositorFrameSinkHolder::AddResourceReleaseCallback( |
| + cc::ResourceId id, |
| + std::unique_ptr<cc::SingleReleaseCallback> callback) { |
| + release_callbacks_[id] = std::make_pair(this, std::move(callback)); |
|
Fady Samuel
2016/11/23 21:14:48
compositor_frame_sink_->SetNeedsBeginFrame(true);
Alex Z.
2016/11/24 18:58:45
Done.
|
| +} |
| + |
| +void CompositorFrameSinkHolder::ActivateFrameCallbacks( |
| + std::list<FrameCallback>& frame_callbacks) { |
| + active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| + frame_callbacks); |
| +} |
| + |
| +void CompositorFrameSinkHolder::CancelFrameCallbacks() { |
| + // Call pending frame callbacks with a null frame time to indicate that they |
| + // have been cancelled. |
| + for (const auto& frame_callback : active_frame_callbacks_) |
| + frame_callback.Run(base::TimeTicks()); |
| +} |
| + |
| +CompositorFrameSinkHolder::~CompositorFrameSinkHolder() { |
| + begin_frame_source_.reset(); |
| +} |
| + |
| +void CompositorFrameSinkHolder::UpdateNeedsBeginFrame() { |
| + if (!begin_frame_source_) |
| + return; |
| + |
| + bool needs_begin_frame = !active_frame_callbacks_.empty(); |
| + if (needs_begin_frame == needs_begin_frame_) |
| + return; |
| + |
| + needs_begin_frame_ = needs_begin_frame; |
| +} |
| + |
| +void CompositorFrameSinkHolder::SubmitCompositorFrame( |
| + const cc::LocalFrameId& local_frame_id, |
| + cc::CompositorFrame frame) { |
| + if (compositor_frame_sink_) |
| + compositor_frame_sink_->SubmitCompositorFrame(local_frame_id, |
| + std::move(frame)); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// cc::mojom::MojoCompositorFrameSinkClient overrides: |
| + |
| +// TODO(staraz): Implement this |
| +void CompositorFrameSinkHolder::DidReceiveCompositorFrameAck() {} |
| + |
| +void CompositorFrameSinkHolder::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| + // Run active frame callbacks here |
| + while (!active_frame_callbacks_.empty()) { |
| + active_frame_callbacks_.front().Run(args.frame_time); |
| + active_frame_callbacks_.pop_front(); |
| + } |
| + begin_frame_source_->OnBeginFrame(args); |
| +} |
| + |
| +void CompositorFrameSinkHolder::ReclaimResources( |
| + const cc::ReturnedResourceArray& resources) { |
| + scoped_refptr<CompositorFrameSinkHolder> holder(this); |
| + for (auto& resource : resources) { |
| + auto it = release_callbacks_.find(resource.id); |
| + DCHECK(it != release_callbacks_.end()); |
| + it->second.second->Run(resource.sync_token, resource.lost); |
| + release_callbacks_.erase(it); |
| + } |
| +} |
| + |
| +void CompositorFrameSinkHolder::WillDrawSurface() { |
| + if (surface_) |
| + surface_->WillDraw(); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ExoComopositorFrameSink, private: |
| + |
| +void CompositorFrameSinkHolder::OnNeedsBeginFrames(bool needs_begin_frames) { |
| + compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
| +} |
| + |
| +} // namespace exo |