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..a18908b0d13f71867b1452c5797a04f37290ff0d |
--- /dev/null |
+++ b/components/exo/exo_compositor_frame_sink.cc |
@@ -0,0 +1,108 @@ |
+// 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) |
+ : frame_sink_id_(frame_sink_id) { |
+ id_allocator_.reset(new cc::SurfaceIdAllocator()); |
+} |
+ |
+void ExoCompositorFrameSink::Init(cc::SurfaceManager* surface_manager) { |
+ surface_factory_.reset( |
+ new cc::SurfaceFactory(frame_sink_id_, surface_manager, this)); |
+} |
+ |
+void ExoCompositorFrameSink::UnregisterSurface( |
+ const cc::SurfaceId& surface_id) { |
+ if (surface_id.local_frame_id().is_valid()) |
+ surface_factory_->Destroy(surface_id.local_frame_id()); |
+} |
+ |
+const cc::SurfaceId& ExoCompositorFrameSink::CommitToNewSurface( |
+ const cc::LocalFrameId& old_local_frame_id) { |
+ cc::LocalFrameId local_frame_id = id_allocator_->GenerateId(); |
+ surface_factory_->Create(local_frame_id); |
+ |
+ if (old_local_frame_id.is_valid()) { |
+ surface_factory_->SetPreviousFrameSurface(local_frame_id, |
+ old_local_frame_id); |
+ surface_factory_->Destroy(old_local_frame_id); |
+ } |
+ |
+ return std::move(cc::SurfaceId(frame_sink_id_, local_frame_id)); |
Fady Samuel
2016/11/15 16:01:32
This isn't safe. You're returning a reference to a
Alex Z.
2016/11/15 22:27:30
Done.
|
+} |
+//////////////////////////////////////////////////////////////////////////////// |
+// cc::SurfaceFactoryClient overrides: |
+ |
+void ExoCompositorFrameSink::ReturnResources( |
+ const cc::ReturnedResourceArray& resources) { |
+ 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 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(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// 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 (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); |
+} |
+ |
+} // namespace exo |