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..dcd64ea89f1bb8024a207cbdbbf8c1043fb17856 |
| --- /dev/null |
| +++ b/components/exo/exo_compositor_frame_sink.cc |
| @@ -0,0 +1,119 @@ |
| +// 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 { |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ExoCompositorFrameSink, public: |
| + |
| +ExoCompositorFrameSink::ExoCompositorFrameSink() |
| + : frame_sink_id_( |
| + aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()) { |
|
Fady Samuel
2016/11/14 23:29:41
Don't allocate the FrameSinkId in here. Instead, t
Alex Z.
2016/11/15 15:53:58
Done.
|
| + 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)); |
| +} |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// cc::SurfaceFactoryClient overrides: |
| + |
| +void ExoCompositorFrameSink::ReturnResources( |
| + const cc::ReturnedResourceArray& resources) { |
| + scoped_refptr<ExoCompositorFrameSink> 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 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::mojom::MojoCompositorFrameSink overrides: |
| + |
| +void ExoCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { |
| + needs_begin_frame_ = needs_begin_frame; |
| + UpdateNeedsBeginFrameInternal(); |
| +} |
| + |
| +void ExoCompositorFrameSink::SubmitCompositorFrame(cc::CompositorFrame frame) {} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// 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) {} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ExoCompositorFrameSink, 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 |