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..5f7e82e0d745d467426c18365f0200d8cdcbc442 |
--- /dev/null |
+++ b/components/exo/exo_compositor_frame_sink.cc |
@@ -0,0 +1,117 @@ |
+// 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" |
+#include "ui/aura/env.h" |
+ |
+namespace exo { |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// ExoComopositorFrameSink, public: |
+ |
+ExoCompositorFrameSink::ExoCompositorFrameSink( |
+ const cc::FrameSinkId& frame_sink_id, |
+ cc::SurfaceManager* surface_manager) |
+ : frame_sink_id_(frame_sink_id), |
+ surface_manager_(surface_manager), |
+ surface_factory_(frame_sink_id, surface_manager, this) { |
+ surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
+ surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// cc::SurfaceFactoryClient overrides: |
+ |
+void ExoCompositorFrameSink::ReturnResources( |
+ const cc::ReturnedResourceArray& resources) { |
+ for (auto& resource : resources) { |
Fady Samuel
2016/11/16 21:29:40
So I see the problem here. This should actually ha
jbauman
2016/11/16 22:01:56
The release callbacks can outlive the exo::Surface
|
+ 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 ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, |
+ const gfx::Rect& damage_rect) {} |
+ |
+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(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// To be cc::mojom::MojoCompositorFrameSink overrides: |
+ |
+void ExoCompositorFrameSink::SubmitCompositorFrame( |
+ cc::CompositorFrame frame, |
+ const cc::LocalFrameId& local_frame_id) { |
+ if (local_frame_id != last_local_frame_id_) { |
+ surface_factory_.Create(local_frame_id); |
+ } |
+ // UpdateSurface(true); // surface_factory.SubmitCompositorFrame happens here |
+ surface_factory_.SubmitCompositorFrame(local_frame_id, std::move(frame), |
+ cc::SurfaceFactory::DrawCallback()); |
+ 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) { |
+ UpdateNeedsBeginFrameInternal(); |
+ last_begin_frame_args_ = args; |
+} |
+ |
+const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs() |
+ const { |
+ return last_begin_frame_args_; |
+} |
+ |
+void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// ExoComopositorFrameSink, private: |
+ |
+ExoCompositorFrameSink::~ExoCompositorFrameSink() { |
+ if (last_local_frame_id_.is_valid()) |
+ surface_factory_.Destroy(last_local_frame_id_); |
+ |
+ if (surface_factory_.manager()) |
+ surface_factory_.manager()->InvalidateFrameSinkId(frame_sink_id_); |
+} |
+ |
+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::DidRecieveCompositorFrameAck() { |
+ // TODO(staraz): Clean up resources |
+ ack_pending_count_--; |
+} |
+ |
+} // namespace exo |