OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/surfaces/compositor_frame_sink_support.h" | 5 #include "cc/surfaces/compositor_frame_sink_support.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
11 #include "cc/scheduler/begin_frame_source.h" | 11 #include "cc/scheduler/begin_frame_source.h" |
12 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 12 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
13 #include "cc/surfaces/display.h" | 13 #include "cc/surfaces/display.h" |
14 #include "cc/surfaces/surface.h" | |
15 #include "cc/surfaces/surface_info.h" | 14 #include "cc/surfaces/surface_info.h" |
16 #include "cc/surfaces/surface_manager.h" | 15 #include "cc/surfaces/surface_manager.h" |
17 #include "cc/surfaces/surface_reference.h" | 16 #include "cc/surfaces/surface_reference.h" |
18 | 17 |
19 namespace cc { | 18 namespace cc { |
20 | 19 |
21 // static | 20 // static |
22 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create( | 21 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create( |
23 CompositorFrameSinkSupportClient* client, | 22 CompositorFrameSinkSupportClient* client, |
24 SurfaceManager* surface_manager, | 23 SurfaceManager* surface_manager, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 DestroyCurrentSurface(); | 79 DestroyCurrentSurface(); |
81 } | 80 } |
82 | 81 |
83 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 82 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
84 needs_begin_frame_ = needs_begin_frame; | 83 needs_begin_frame_ = needs_begin_frame; |
85 UpdateNeedsBeginFramesInternal(); | 84 UpdateNeedsBeginFramesInternal(); |
86 } | 85 } |
87 | 86 |
88 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( | 87 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( |
89 const BeginFrameAck& ack) { | 88 const BeginFrameAck& ack) { |
89 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::BeginFrameDidNotSwap", | |
90 "ack.source_id", ack.source_id, "ack.sequence_number", | |
91 ack.sequence_number); | |
90 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we | 92 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we |
91 // should not acknowledge immediately. Instead, we should update the ack that | 93 // should not acknowledge immediately. Instead, we should update the ack that |
92 // will be sent to DisplayScheduler when the pending frame is activated. | 94 // will be sent to DisplayScheduler when the pending frame is activated. |
93 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); | 95 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); |
94 | 96 |
95 // |has_damage| is not transmitted, but false by default. | 97 // |has_damage| is not transmitted, but false by default. |
96 DCHECK(!ack.has_damage); | 98 DCHECK(!ack.has_damage); |
99 | |
100 last_begin_frame_ack_ = ack; | |
101 | |
102 if (producer_state_ == Surface::PENDING && | |
sunnyps
2017/05/19 03:46:33
I was thinking more along the lines of plumbing th
| |
103 last_begin_frame_args_.source_id == ack.source_id && | |
104 last_begin_frame_args_.sequence_number == ack.sequence_number) { | |
105 SetProducerState(Surface::IDLE); | |
106 } | |
97 if (begin_frame_source_) | 107 if (begin_frame_source_) |
98 begin_frame_source_->DidFinishFrame(this, ack); | 108 begin_frame_source_->DidFinishFrame(this, ack); |
99 } | 109 } |
100 | 110 |
101 void CompositorFrameSinkSupport::SubmitCompositorFrame( | 111 void CompositorFrameSinkSupport::SubmitCompositorFrame( |
102 const LocalSurfaceId& local_surface_id, | 112 const LocalSurfaceId& local_surface_id, |
103 CompositorFrame frame) { | 113 CompositorFrame frame) { |
104 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); | 114 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); |
105 DCHECK(local_surface_id.is_valid()); | 115 DCHECK(local_surface_id.is_valid()); |
106 DCHECK_GE(frame.metadata.begin_frame_ack.sequence_number, | 116 DCHECK_GE(frame.metadata.begin_frame_ack.sequence_number, |
107 BeginFrameArgs::kStartingFrameNumber); | 117 BeginFrameArgs::kStartingFrameNumber); |
108 DCHECK(!frame.render_pass_list.empty()); | 118 DCHECK(!frame.render_pass_list.empty()); |
109 | 119 |
110 ++ack_pending_count_; | 120 ++ack_pending_count_; |
111 | 121 |
112 // |has_damage| is not transmitted. | 122 // |has_damage| is not transmitted. |
113 frame.metadata.begin_frame_ack.has_damage = true; | 123 frame.metadata.begin_frame_ack.has_damage = true; |
114 | 124 |
115 BeginFrameAck ack = frame.metadata.begin_frame_ack; | 125 last_begin_frame_ack_ = frame.metadata.begin_frame_ack; |
116 | 126 |
117 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info, | 127 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info, |
118 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { | 128 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { |
119 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); | 129 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); |
120 } | 130 } |
121 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { | 131 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { |
122 if (latency.latency_components().size() > 0) { | 132 if (latency.latency_components().size() > 0) { |
123 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, | 133 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, |
124 0, 0); | 134 0, 0); |
125 } | 135 } |
(...skipping 15 matching lines...) Expand all Loading... | |
141 weak_factory_.GetWeakPtr()), | 151 weak_factory_.GetWeakPtr()), |
142 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, | 152 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, |
143 weak_factory_.GetWeakPtr())); | 153 weak_factory_.GetWeakPtr())); |
144 | 154 |
145 if (current_surface_) { | 155 if (current_surface_) { |
146 surface->SetPreviousFrameSurface(current_surface_.get()); | 156 surface->SetPreviousFrameSurface(current_surface_.get()); |
147 DestroyCurrentSurface(); | 157 DestroyCurrentSurface(); |
148 } | 158 } |
149 current_surface_ = std::move(surface); | 159 current_surface_ = std::move(surface); |
150 | 160 |
161 SetProducerState(Surface::READY); | |
sunnyps
2017/05/19 03:46:34
Similarly here we already plumb surface activation
| |
162 | |
151 // TODO(eseckler): The CompositorFrame submitted below might not be activated | 163 // TODO(eseckler): The CompositorFrame submitted below might not be activated |
152 // right away b/c of surface synchronization. We should only send the | 164 // right away b/c of surface synchronization. We should only send the |
153 // BeginFrameAck to DisplayScheduler when it is activated. This also means | 165 // BeginFrameAck to DisplayScheduler when it is activated. This also means |
154 // that we need to stay an active BFO while a CompositorFrame is pending. | 166 // that we need to stay an active BFO while a CompositorFrame is pending. |
155 // See https://crbug.com/703079. | 167 // See https://crbug.com/703079. |
156 if (begin_frame_source_) | 168 if (begin_frame_source_) |
157 begin_frame_source_->DidFinishFrame(this, ack); | 169 begin_frame_source_->DidFinishFrame(this, last_begin_frame_ack_); |
158 } | 170 } |
159 | 171 |
160 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 172 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
161 const SurfaceId& last_surface_id, | 173 const SurfaceId& last_surface_id, |
162 const LocalSurfaceId& local_surface_id) { | 174 const LocalSurfaceId& local_surface_id) { |
163 const bool surface_id_changed = | 175 const bool surface_id_changed = |
164 last_surface_id.local_surface_id() != local_surface_id; | 176 last_surface_id.local_surface_id() != local_surface_id; |
165 | 177 |
166 // If this is a display root surface and the SurfaceId is changing, make the | 178 // If this is a display root surface and the SurfaceId is changing, make the |
167 // new SurfaceId reachable from the top-level root. | 179 // new SurfaceId reachable from the top-level root. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 // frame if any. | 228 // frame if any. |
217 reference_tracker_.UpdateReferences(local_surface_id, | 229 reference_tracker_.UpdateReferences(local_surface_id, |
218 active_referenced_surfaces); | 230 active_referenced_surfaces); |
219 | 231 |
220 UpdateSurfaceReferences(last_surface_id, local_surface_id); | 232 UpdateSurfaceReferences(last_surface_id, local_surface_id); |
221 } | 233 } |
222 | 234 |
223 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { | 235 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { |
224 DCHECK_GT(ack_pending_count_, 0); | 236 DCHECK_GT(ack_pending_count_, 0); |
225 ack_pending_count_--; | 237 ack_pending_count_--; |
238 | |
sunnyps
2017/05/19 03:46:34
See my later comments in DisplayScheduler first.
| |
239 if (ack_pending_count_ == 0 && added_frame_observer_ && | |
240 (last_begin_frame_args_.source_id != last_begin_frame_ack_.source_id || | |
241 last_begin_frame_args_.sequence_number != | |
242 last_begin_frame_ack_.sequence_number)) { | |
243 SetProducerState(Surface::PENDING); | |
244 } else { | |
245 SetProducerState(Surface::IDLE); | |
246 } | |
247 | |
226 if (!client_) | 248 if (!client_) |
227 return; | 249 return; |
228 | 250 |
229 client_->DidReceiveCompositorFrameAck(surface_returned_resources_); | 251 client_->DidReceiveCompositorFrameAck(surface_returned_resources_); |
230 surface_returned_resources_.clear(); | 252 surface_returned_resources_.clear(); |
231 } | 253 } |
232 | 254 |
233 void CompositorFrameSinkSupport::WillDrawSurface( | 255 void CompositorFrameSinkSupport::WillDrawSurface( |
234 const LocalSurfaceId& local_surface_id, | 256 const LocalSurfaceId& local_surface_id, |
235 const gfx::Rect& damage_rect) { | 257 const gfx::Rect& damage_rect) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 296 |
275 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { | 297 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { |
276 surface_manager_ = surface_manager; | 298 surface_manager_ = surface_manager; |
277 if (handles_frame_sink_id_invalidation_) | 299 if (handles_frame_sink_id_invalidation_) |
278 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 300 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
279 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); | 301 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); |
280 } | 302 } |
281 | 303 |
282 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { | 304 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { |
283 UpdateNeedsBeginFramesInternal(); | 305 UpdateNeedsBeginFramesInternal(); |
306 if (producer_state_ == Surface::IDLE) | |
307 SetProducerState(Surface::PENDING); | |
284 last_begin_frame_args_ = args; | 308 last_begin_frame_args_ = args; |
285 if (client_) | 309 if (client_) |
286 client_->OnBeginFrame(args); | 310 client_->OnBeginFrame(args); |
287 } | 311 } |
288 | 312 |
289 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() | 313 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() |
290 const { | 314 const { |
291 return last_begin_frame_args_; | 315 return last_begin_frame_args_; |
292 } | 316 } |
293 | 317 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 | 357 |
334 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( | 358 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( |
335 const LocalSurfaceId& local_surface_id) { | 359 const LocalSurfaceId& local_surface_id) { |
336 seen_first_frame_activation_ = false; | 360 seen_first_frame_activation_ = false; |
337 std::unique_ptr<Surface> surface = surface_manager_->CreateSurface( | 361 std::unique_ptr<Surface> surface = surface_manager_->CreateSurface( |
338 weak_factory_.GetWeakPtr(), local_surface_id); | 362 weak_factory_.GetWeakPtr(), local_surface_id); |
339 return surface; | 363 return surface; |
340 } | 364 } |
341 | 365 |
342 void CompositorFrameSinkSupport::DestroyCurrentSurface() { | 366 void CompositorFrameSinkSupport::DestroyCurrentSurface() { |
367 SetProducerState(Surface::IDLE); | |
343 surface_manager_->DestroySurface(std::move(current_surface_)); | 368 surface_manager_->DestroySurface(std::move(current_surface_)); |
344 } | 369 } |
345 | 370 |
371 void CompositorFrameSinkSupport::SetProducerState( | |
372 Surface::ProducerState state) { | |
373 TRACE_EVENT1("cc", "CompositorFrameSinkSupport::SetProducerState", "state", | |
374 state); | |
375 producer_state_ = state; | |
376 if (current_surface_) | |
377 current_surface_->SetProducerState(state); | |
378 } | |
379 | |
346 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 380 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
347 std::unique_ptr<CopyOutputRequest> copy_request) { | 381 std::unique_ptr<CopyOutputRequest> copy_request) { |
348 if (!current_surface_) | 382 if (!current_surface_) |
349 return; | 383 return; |
350 | 384 |
351 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); | 385 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); |
352 current_surface_->RequestCopyOfOutput(std::move(copy_request)); | 386 current_surface_->RequestCopyOfOutput(std::move(copy_request)); |
353 surface_manager_->SurfaceModified(current_surface_->surface_id()); | 387 surface_manager_->SurfaceModified(current_surface_->surface_id()); |
354 } | 388 } |
355 | 389 |
356 } // namespace cc | 390 } // namespace cc |
OLD | NEW |