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 cc::mojom::MojoCompositorFrameSinkClientPtr 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 if (resources.empty()) |
| 34 return; |
| 35 |
| 36 if (!ack_pending_count_ && client_) { |
| 37 client_->ReclaimResources(resources); |
| 38 return; |
| 39 } |
| 40 |
| 41 std::copy(resources.begin(), resources.end(), |
| 42 std::back_inserter(surface_returned_resources_)); |
| 43 } |
| 44 |
| 45 void ExoCompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, |
| 46 const gfx::Rect& damage_rect) {} |
| 47 |
| 48 void ExoCompositorFrameSink::SetBeginFrameSource( |
| 49 cc::BeginFrameSource* begin_frame_source) { |
| 50 if (begin_frame_source_ && added_frame_observer_) { |
| 51 begin_frame_source_->RemoveObserver(this); |
| 52 added_frame_observer_ = false; |
| 53 } |
| 54 begin_frame_source_ = begin_frame_source; |
| 55 UpdateNeedsBeginFrameInternal(); |
| 56 } |
| 57 |
| 58 //////////////////////////////////////////////////////////////////////////////// |
| 59 // To be cc::mojom::MojoCompositorFrameSink overrides: |
| 60 |
| 61 void ExoCompositorFrameSink::SubmitCompositorFrame( |
| 62 const cc::LocalFrameId& local_frame_id, |
| 63 cc::CompositorFrame frame) { |
| 64 if (local_frame_id != last_local_frame_id_) { |
| 65 surface_factory_.Create(local_frame_id); |
| 66 } |
| 67 ++ack_pending_count_; |
| 68 surface_factory_.SubmitCompositorFrame( |
| 69 local_frame_id, std::move(frame), |
| 70 base::Bind(&ExoCompositorFrameSink::DidReceiveCompositorFrameAck, |
| 71 base::Unretained(this))); |
| 72 if (last_local_frame_id_.is_valid() && |
| 73 local_frame_id != last_local_frame_id_) { |
| 74 surface_factory_.SetPreviousFrameSurface(local_frame_id, |
| 75 last_local_frame_id_); |
| 76 surface_factory_.Destroy(last_local_frame_id_); |
| 77 } |
| 78 last_local_frame_id_ = local_frame_id; |
| 79 } |
| 80 |
| 81 //////////////////////////////////////////////////////////////////////////////// |
| 82 // cc::BeginFrameObserver overrides: |
| 83 |
| 84 void ExoCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 85 UpdateNeedsBeginFrameInternal(); |
| 86 last_begin_frame_args_ = args; |
| 87 } |
| 88 |
| 89 const cc::BeginFrameArgs& ExoCompositorFrameSink::LastUsedBeginFrameArgs() |
| 90 const { |
| 91 return last_begin_frame_args_; |
| 92 } |
| 93 |
| 94 void ExoCompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} |
| 95 |
| 96 //////////////////////////////////////////////////////////////////////////////// |
| 97 // ExoComopositorFrameSink, private: |
| 98 |
| 99 ExoCompositorFrameSink::~ExoCompositorFrameSink() { |
| 100 if (last_local_frame_id_.is_valid()) |
| 101 surface_factory_.Destroy(last_local_frame_id_); |
| 102 |
| 103 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 104 |
| 105 if (surface_factory_.manager()) |
| 106 surface_factory_.manager()->InvalidateFrameSinkId(frame_sink_id_); |
| 107 } |
| 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 |