Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/exo/exo_compositor_frame_sink.h" | |
| 6 | |
| 7 #include "cc/surfaces/surface_manager.h" | |
| 8 #include "components/exo/compositor_frame_sink_holder.h" | |
| 9 #include "ui/aura/env.h" | |
| 10 | |
| 11 namespace exo { | |
| 12 | |
| 13 //////////////////////////////////////////////////////////////////////////////// | |
| 14 // ExoComopositorFrameSink, public: | |
| 15 | |
| 16 ExoCompositorFrameSink::ExoCompositorFrameSink( | |
| 17 const cc::FrameSinkId& frame_sink_id, | |
| 18 cc::SurfaceManager* surface_manager, | |
| 19 CompositorFrameSinkHolder* client) | |
| 20 : frame_sink_id_(frame_sink_id), | |
| 21 surface_manager_(surface_manager), | |
| 22 surface_factory_(frame_sink_id, surface_manager, this), | |
| 23 client_(std::move(client)) { | |
| 24 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | |
| 25 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | |
| 26 } | |
| 27 | |
| 28 //////////////////////////////////////////////////////////////////////////////// | |
| 29 // cc::SurfaceFactoryClient overrides: | |
| 30 | |
| 31 void ExoCompositorFrameSink::ReturnResources( | |
| 32 const cc::ReturnedResourceArray& resources) { | |
| 33 // TODO(staraz): !ack_pending_count_ | |
|
Fady Samuel
2016/11/17 21:42:54
Fix this now? This should be a copy-and-paste from
Alex Z.
2016/11/23 14:25:04
Done.
| |
| 34 if (client_) { | |
| 35 client_->ReclaimResources(resources); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, | |
| 40 const gfx::Rect& damage_rect) {} | |
| 41 | |
| 42 void ExoCompositorFrameSink::SetBeginFrameSource( | |
| 43 cc::BeginFrameSource* begin_frame_source) { | |
| 44 if (begin_frame_source_ && added_frame_observer_) { | |
| 45 begin_frame_source_->RemoveObserver(this); | |
| 46 added_frame_observer_ = false; | |
| 47 } | |
| 48 begin_frame_source_ = begin_frame_source; | |
| 49 UpdateNeedsBeginFrameInternal(); | |
| 50 } | |
| 51 | |
| 52 //////////////////////////////////////////////////////////////////////////////// | |
| 53 // To be cc::mojom::MojoCompositorFrameSink overrides: | |
| 54 | |
| 55 void ExoCompositorFrameSink::SubmitCompositorFrame( | |
| 56 const cc::LocalFrameId& local_frame_id, | |
| 57 cc::CompositorFrame frame) { | |
| 58 if (local_frame_id != last_local_frame_id_) { | |
| 59 surface_factory_.Create(local_frame_id); | |
| 60 } | |
| 61 ++ack_pending_count_; | |
| 62 surface_factory_.SubmitCompositorFrame(local_frame_id, std::move(frame), | |
| 63 cc::SurfaceFactory::DrawCallback()); | |
| 64 if (last_local_frame_id_.is_valid() && | |
| 65 local_frame_id != last_local_frame_id_) { | |
| 66 surface_factory_.SetPreviousFrameSurface(local_frame_id, | |
| 67 last_local_frame_id_); | |
| 68 surface_factory_.Destroy(last_local_frame_id_); | |
| 69 } | |
| 70 last_local_frame_id_ = local_frame_id; | |
| 71 } | |
| 72 | |
| 73 //////////////////////////////////////////////////////////////////////////////// | |
| 74 // cc::BeginFrameObserver overrides: | |
| 75 | |
| 76 void ExoCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
| 77 UpdateNeedsBeginFrameInternal(); | |
| 78 last_begin_frame_args_ = args; | |
| 79 } | |
| 80 | |
| 81 const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs() | |
| 82 const { | |
| 83 return last_begin_frame_args_; | |
| 84 } | |
| 85 | |
| 86 void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} | |
| 87 | |
| 88 //////////////////////////////////////////////////////////////////////////////// | |
| 89 // ExoComopositorFrameSink, private: | |
| 90 | |
| 91 ExoCompositorFrameSink::~ExoCompositorFrameSink() { | |
| 92 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | |
| 93 if (last_local_frame_id_.is_valid()) | |
|
Fady Samuel
2016/11/17 21:42:54
do this before UnregisterSurfaceFactoryClient.
Alex Z.
2016/11/23 14:25:04
Done.
| |
| 94 surface_factory_.Destroy(last_local_frame_id_); | |
| 95 | |
| 96 if (surface_factory_.manager()) | |
| 97 surface_factory_.manager()->InvalidateFrameSinkId(frame_sink_id_); | |
| 98 } | |
| 99 | |
| 100 void ExoCompositorFrameSink::UpdateNeedsBeginFrameInternal() { | |
| 101 if (!begin_frame_source_) | |
| 102 return; | |
| 103 | |
| 104 if (needs_begin_frame_ == added_frame_observer_) | |
| 105 return; | |
| 106 | |
| 107 added_frame_observer_ = needs_begin_frame_; | |
| 108 if (needs_begin_frame_) | |
| 109 begin_frame_source_->AddObserver(this); | |
| 110 else | |
| 111 begin_frame_source_->RemoveObserver(this); | |
| 112 } | |
| 113 | |
| 114 void ExoCompositorFrameSink::DidRecieveCompositorFrameAck() { | |
| 115 // TODO(staraz): Clean up resources | |
| 116 // What should call this? | |
| 117 if (!client_) | |
| 118 return; | |
| 119 client_->DidReceiveCompositorFrameAck(); | |
| 120 DCHECK_GT(ack_pending_count_, 0); | |
| 121 if (!surface_returned_resources_.empty()) { | |
| 122 client_->ReclaimResources(surface_returned_resources_); | |
| 123 } | |
| 124 ack_pending_count_--; | |
| 125 } | |
| 126 | |
| 127 } // namespace exo | |
| OLD | NEW |