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..66ba7c64f72d23dcb0a62576a564b43a506eba7e |
--- /dev/null |
+++ b/components/exo/compositor_frame_sink_holder.cc |
@@ -0,0 +1,128 @@ |
+// 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); |
+} |
+ |
+bool CompositorFrameSinkHolder::IsReleaseCallbacksEmpty() { |
+ return release_callbacks_.size() == 0; |
+} |
+ |
+void CompositorFrameSinkHolder::AddResourceReleaseCallback( |
+ cc::ResourceId id, |
+ std::unique_ptr<cc::SingleReleaseCallback> callback) { |
+ release_callbacks_[id] = std::make_pair(this, std::move(callback)); |
+ compositor_frame_sink_->SetNeedsBeginFrame(true); |
Fady Samuel
2016/11/30 16:41:56
This might not be necessary.
Alex Z.
2016/11/30 20:00:30
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()); |
+} |
+ |
+void CompositorFrameSinkHolder::EvictFrame() { |
+ compositor_frame_sink_->EvictFrame(); |
+} |
+ |
+CompositorFrameSinkHolder::~CompositorFrameSinkHolder() { |
+ begin_frame_source_.reset(); |
Fady Samuel
2016/11/30 16:41:57
Is this necessary?
Alex Z.
2016/11/30 20:00:30
Done.
|
+} |
+ |
+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; |
+ OnNeedsBeginFrames(needs_begin_frame_); |
+} |
+ |
+void CompositorFrameSinkHolder::SetNeedsBeginFrame(bool needs_begin_frame) { |
+ needs_begin_frame_ = needs_begin_frame; |
+ OnNeedsBeginFrames(needs_begin_frame); |
+} |
+ |
+void CompositorFrameSinkHolder::SubmitCompositorFrame( |
+ const cc::LocalFrameId& local_frame_id, |
+ cc::CompositorFrame frame) { |
+ if (compositor_frame_sink_) |
Fady Samuel
2016/11/30 16:41:57
nit: braces for multi-line blocks.
Alex Z.
2016/11/30 20:00:30
Done.
|
+ compositor_frame_sink_->SubmitCompositorFrame(local_frame_id, |
+ std::move(frame)); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// cc::mojom::MojoCompositorFrameSinkClient overrides: |
+ |
+// TODO(staraz): Implement this |
Fady Samuel
2016/11/30 16:41:57
Put the TODO in the body.
Alex Z.
2016/11/30 20:00:30
Done.
|
+void CompositorFrameSinkHolder::DidReceiveCompositorFrameAck() {} |
+ |
+void CompositorFrameSinkHolder::OnBeginFrame(const cc::BeginFrameArgs& args) { |
+ 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(); |
+} |
+ |
+const cc::BeginFrameArgs& CompositorFrameSinkHolder::LastUsedBeginFrameArgs() |
+ const { |
+ return last_begin_frame_args_; |
+} |
+ |
+void CompositorFrameSinkHolder::OnBeginFrameSourcePausedChanged(bool paused) {} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// ExoComopositorFrameSink, private: |
Fady Samuel
2016/11/30 16:41:57
This comment is wrong. This is BeginFrameObserver,
Alex Z.
2016/11/30 20:00:30
Done.
|
+ |
+void CompositorFrameSinkHolder::OnNeedsBeginFrames(bool needs_begin_frames) { |
+ compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
+} |
+ |
+} // namespace exo |