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 "base/debug/stack_trace.h" |
| 8 #include "cc/surfaces/surface_manager.h" |
| 9 |
| 10 namespace exo { |
| 11 |
| 12 //////////////////////////////////////////////////////////////////////////////// |
| 13 // ExoComopositorFrameSink, public: |
| 14 |
| 15 ExoCompositorFrameSink::ExoCompositorFrameSink( |
| 16 const cc::FrameSinkId& frame_sink_id, |
| 17 cc::SurfaceManager* surface_manager, |
| 18 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
| 19 : frame_sink_id_(frame_sink_id), |
| 20 surface_manager_(surface_manager), |
| 21 surface_factory_(frame_sink_id, surface_manager, this), |
| 22 client_(std::move(client)) { |
| 23 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 24 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 25 } |
| 26 |
| 27 ExoCompositorFrameSink::~ExoCompositorFrameSink() { |
| 28 surface_factory_.EvictSurface(); |
| 29 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 30 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 31 } |
| 32 |
| 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 // cc::SurfaceFactoryClient overrides: |
| 35 |
| 36 void ExoCompositorFrameSink::ReturnResources( |
| 37 const cc::ReturnedResourceArray& resources) { |
| 38 if (resources.empty()) |
| 39 return; |
| 40 |
| 41 if (!ack_pending_count_ && client_) { |
| 42 client_->ReclaimResources(resources); |
| 43 return; |
| 44 } |
| 45 |
| 46 std::copy(resources.begin(), resources.end(), |
| 47 std::back_inserter(surface_returned_resources_)); |
| 48 } |
| 49 |
| 50 void ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, |
| 51 const gfx::Rect& damage_rect) { |
| 52 if (client_) |
| 53 client_->WillDrawSurface(); |
| 54 } |
| 55 |
| 56 void ExoCompositorFrameSink::SetBeginFrameSource( |
| 57 cc::BeginFrameSource* begin_frame_source) { |
| 58 if (begin_frame_source_ && added_frame_observer_) { |
| 59 begin_frame_source_->RemoveObserver(this); |
| 60 added_frame_observer_ = false; |
| 61 } |
| 62 begin_frame_source_ = begin_frame_source; |
| 63 UpdateNeedsBeginFrameInternal(); |
| 64 } |
| 65 |
| 66 //////////////////////////////////////////////////////////////////////////////// |
| 67 // cc::mojom::MojoCompositorFrameSink overrides: |
| 68 |
| 69 void ExoCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 70 needs_begin_frame_ = needs_begin_frame; |
| 71 UpdateNeedsBeginFrameInternal(); |
| 72 } |
| 73 |
| 74 void ExoCompositorFrameSink::SubmitCompositorFrame( |
| 75 const cc::LocalFrameId& local_frame_id, |
| 76 cc::CompositorFrame frame) { |
| 77 ++ack_pending_count_; |
| 78 surface_factory_.SubmitCompositorFrame( |
| 79 local_frame_id, std::move(frame), |
| 80 base::Bind(&ExoCompositorFrameSink::DidReceiveCompositorFrameAck, |
| 81 base::Unretained(this))); |
| 82 last_local_frame_id_ = local_frame_id; |
| 83 } |
| 84 |
| 85 void ExoCompositorFrameSink::EvictFrame() { |
| 86 surface_factory_.EvictSurface(); |
| 87 } |
| 88 |
| 89 //////////////////////////////////////////////////////////////////////////////// |
| 90 // cc::BeginFrameObserver overrides: |
| 91 |
| 92 void ExoCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 93 UpdateNeedsBeginFrameInternal(); |
| 94 last_begin_frame_args_ = args; |
| 95 if (client_) |
| 96 client_->OnBeginFrame(args); |
| 97 } |
| 98 |
| 99 const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs() |
| 100 const { |
| 101 return last_begin_frame_args_; |
| 102 } |
| 103 |
| 104 void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} |
| 105 |
| 106 //////////////////////////////////////////////////////////////////////////////// |
| 107 // ExoComopositorFrameSink, private: |
| 108 |
| 109 void ExoCompositorFrameSink::UpdateNeedsBeginFrameInternal() { |
| 110 if (!begin_frame_source_) |
| 111 return; |
| 112 |
| 113 if (needs_begin_frame_ == added_frame_observer_) |
| 114 return; |
| 115 |
| 116 added_frame_observer_ = needs_begin_frame_; |
| 117 if (needs_begin_frame_) |
| 118 begin_frame_source_->AddObserver(this); |
| 119 else |
| 120 begin_frame_source_->RemoveObserver(this); |
| 121 } |
| 122 |
| 123 void ExoCompositorFrameSink::DidReceiveCompositorFrameAck() { |
| 124 if (!client_) |
| 125 return; |
| 126 client_->DidReceiveCompositorFrameAck(); |
| 127 DCHECK_GT(ack_pending_count_, 0); |
| 128 if (!surface_returned_resources_.empty()) { |
| 129 client_->ReclaimResources(surface_returned_resources_); |
| 130 surface_returned_resources_.clear(); |
| 131 } |
| 132 ack_pending_count_--; |
| 133 } |
| 134 |
| 135 } // namespace exo |
OLD | NEW |