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