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" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 BeginFrameSource* begin_frame_source) { | 70 BeginFrameSource* begin_frame_source) { |
71 if (begin_frame_source_ && added_frame_observer_) { | 71 if (begin_frame_source_ && added_frame_observer_) { |
72 begin_frame_source_->RemoveObserver(this); | 72 begin_frame_source_->RemoveObserver(this); |
73 added_frame_observer_ = false; | 73 added_frame_observer_ = false; |
74 } | 74 } |
75 begin_frame_source_ = begin_frame_source; | 75 begin_frame_source_ = begin_frame_source; |
76 UpdateNeedsBeginFramesInternal(); | 76 UpdateNeedsBeginFramesInternal(); |
77 } | 77 } |
78 | 78 |
79 void CompositorFrameSinkSupport::EvictCurrentSurface() { | 79 void CompositorFrameSinkSupport::EvictCurrentSurface() { |
80 if (!current_surface_) | 80 if (!current_surface_id_.is_valid()) |
81 return; | 81 return; |
82 DestroyCurrentSurface(); | 82 SurfaceId current_surface_id = current_surface_id_; |
danakj
2017/06/27 18:21:31
give this a name that differs from the member var
Saman Sami
2017/06/28 14:19:43
Done.
| |
83 current_surface_id_ = SurfaceId(); | |
84 surface_manager_->DestroySurface(current_surface_id); | |
83 } | 85 } |
84 | 86 |
85 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 87 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
86 needs_begin_frame_ = needs_begin_frame; | 88 needs_begin_frame_ = needs_begin_frame; |
87 UpdateNeedsBeginFramesInternal(); | 89 UpdateNeedsBeginFramesInternal(); |
88 } | 90 } |
89 | 91 |
90 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { | 92 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { |
91 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", | 93 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", |
92 "ack.source_id", ack.source_id, "ack.sequence_number", | 94 "ack.source_id", ack.source_id, "ack.sequence_number", |
93 ack.sequence_number); | 95 ack.sequence_number); |
94 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); | 96 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); |
95 | 97 |
96 // |has_damage| is not transmitted, but false by default. | 98 // |has_damage| is not transmitted, but false by default. |
97 DCHECK(!ack.has_damage); | 99 DCHECK(!ack.has_damage); |
98 | 100 |
99 if (current_surface_) | 101 if (current_surface_id_.is_valid()) |
100 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); | 102 surface_manager_->SurfaceModified(current_surface_id_, ack); |
103 | |
101 if (begin_frame_source_) | 104 if (begin_frame_source_) |
102 begin_frame_source_->DidFinishFrame(this); | 105 begin_frame_source_->DidFinishFrame(this); |
103 } | 106 } |
104 | 107 |
105 bool CompositorFrameSinkSupport::SubmitCompositorFrame( | 108 bool CompositorFrameSinkSupport::SubmitCompositorFrame( |
106 const LocalSurfaceId& local_surface_id, | 109 const LocalSurfaceId& local_surface_id, |
107 CompositorFrame frame) { | 110 CompositorFrame frame) { |
108 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); | 111 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); |
109 DCHECK(local_surface_id.is_valid()); | 112 DCHECK(local_surface_id.is_valid()); |
110 DCHECK(!frame.render_pass_list.empty()); | 113 DCHECK(!frame.render_pass_list.empty()); |
111 | 114 |
112 ++ack_pending_count_; | 115 ++ack_pending_count_; |
113 | 116 |
114 // |has_damage| is not transmitted. | 117 // |has_damage| is not transmitted. |
115 frame.metadata.begin_frame_ack.has_damage = true; | 118 frame.metadata.begin_frame_ack.has_damage = true; |
116 BeginFrameAck ack = frame.metadata.begin_frame_ack; | 119 BeginFrameAck ack = frame.metadata.begin_frame_ack; |
117 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); | 120 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); |
118 | 121 |
119 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info, | 122 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info, |
120 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { | 123 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { |
121 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); | 124 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); |
122 } | 125 } |
123 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { | 126 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { |
124 if (latency.latency_components().size() > 0) { | 127 if (latency.latency_components().size() > 0) { |
125 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, | 128 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, |
126 0, 0); | 129 0, 0); |
127 } | 130 } |
128 } | 131 } |
129 | 132 |
130 std::unique_ptr<Surface> surface; | 133 Surface* current_surface = |
danakj
2017/06/27 18:21:31
give this a name that differs from the member vari
Saman Sami
2017/06/28 14:19:43
But there is no current_surface_? There is only a
danakj
2017/06/28 15:59:45
Ah that's true, I was reading the old code too.
| |
131 bool create_new_surface = | 134 surface_manager_->GetSurfaceForId(current_surface_id_); |
danakj
2017/06/27 18:21:31
can you use if/else to only call this when we woul
Saman Sami
2017/06/28 14:19:43
I don't think I fully understand your suggestion.
danakj
2017/06/28 15:59:45
T* t = MakeSomeTea();
if (foo) {
t = MakeSomeOth
Saman Sami
2017/06/28 18:01:00
Done.
| |
132 (!current_surface_ || | 135 Surface* prev_surface = current_surface; |
133 local_surface_id != current_surface_->surface_id().local_surface_id()); | 136 if (!current_surface_id_.is_valid() || |
134 if (!create_new_surface) { | 137 local_surface_id != current_surface_id_.local_surface_id()) { |
135 surface = std::move(current_surface_); | |
136 } else { | |
137 SurfaceId surface_id(frame_sink_id_, local_surface_id); | 138 SurfaceId surface_id(frame_sink_id_, local_surface_id); |
138 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 139 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
139 float device_scale_factor = frame.metadata.device_scale_factor; | 140 float device_scale_factor = frame.metadata.device_scale_factor; |
140 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); | 141 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); |
141 | 142 |
142 if (!surface_info.is_valid()) { | 143 if (!surface_info.is_valid()) { |
143 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", | 144 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", |
144 TRACE_EVENT_SCOPE_THREAD); | 145 TRACE_EVENT_SCOPE_THREAD); |
145 if (current_surface_) | 146 if (current_surface) |
146 DestroyCurrentSurface(); | 147 EvictCurrentSurface(); |
147 ReturnedResourceArray resources; | 148 ReturnedResourceArray resources; |
148 TransferableResource::ReturnResources(frame.resource_list, &resources); | 149 TransferableResource::ReturnResources(frame.resource_list, &resources); |
149 ReturnResources(resources); | 150 ReturnResources(resources); |
150 DidReceiveCompositorFrameAck(); | 151 DidReceiveCompositorFrameAck(); |
151 return true; | 152 return true; |
152 } | 153 } |
153 | 154 |
154 surface = CreateSurface(surface_info); | 155 current_surface = CreateSurface(surface_info); |
155 surface_manager_->SurfaceDamageExpected(surface->surface_id(), | 156 current_surface_id_ = SurfaceId(frame_sink_id_, local_surface_id); |
157 surface_manager_->SurfaceDamageExpected(current_surface->surface_id(), | |
156 last_begin_frame_args_); | 158 last_begin_frame_args_); |
157 } | 159 } |
158 | 160 |
159 bool result = surface->QueueFrame( | 161 bool result = current_surface->QueueFrame( |
160 std::move(frame), | 162 std::move(frame), |
161 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 163 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
162 weak_factory_.GetWeakPtr()), | 164 weak_factory_.GetWeakPtr()), |
163 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, | 165 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, |
164 weak_factory_.GetWeakPtr())); | 166 weak_factory_.GetWeakPtr())); |
165 | 167 |
166 if (!result) { | 168 if (!result) { |
167 surface_manager_->DestroySurface(std::move(surface)); | 169 EvictCurrentSurface(); |
168 return false; | 170 return false; |
169 } | 171 } |
170 | 172 |
171 if (current_surface_) { | 173 if (prev_surface && prev_surface != current_surface) { |
172 surface->SetPreviousFrameSurface(current_surface_.get()); | 174 current_surface->SetPreviousFrameSurface(prev_surface); |
173 DestroyCurrentSurface(); | 175 surface_manager_->DestroySurface(prev_surface->surface_id()); |
174 } | 176 } |
175 current_surface_ = std::move(surface); | |
176 | 177 |
177 if (begin_frame_source_) | 178 if (begin_frame_source_) |
178 begin_frame_source_->DidFinishFrame(this); | 179 begin_frame_source_->DidFinishFrame(this); |
179 | 180 |
180 return true; | 181 return true; |
181 } | 182 } |
182 | 183 |
183 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 184 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
184 const LocalSurfaceId& local_surface_id, | 185 const LocalSurfaceId& local_surface_id, |
185 const std::vector<SurfaceId>& active_referenced_surfaces) { | 186 const std::vector<SurfaceId>& active_referenced_surfaces) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 | 282 |
282 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { | 283 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { |
283 surface_manager_ = surface_manager; | 284 surface_manager_ = surface_manager; |
284 if (handles_frame_sink_id_invalidation_) | 285 if (handles_frame_sink_id_invalidation_) |
285 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 286 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
286 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); | 287 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); |
287 } | 288 } |
288 | 289 |
289 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { | 290 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { |
290 UpdateNeedsBeginFramesInternal(); | 291 UpdateNeedsBeginFramesInternal(); |
291 if (current_surface_) { | 292 if (current_surface_id_.is_valid()) { |
292 surface_manager_->SurfaceDamageExpected(current_surface_->surface_id(), | 293 surface_manager_->SurfaceDamageExpected(current_surface_id_, args); |
293 args); | |
294 } | 294 } |
295 last_begin_frame_args_ = args; | 295 last_begin_frame_args_ = args; |
296 if (client_) | 296 if (client_) |
297 client_->OnBeginFrame(args); | 297 client_->OnBeginFrame(args); |
298 } | 298 } |
299 | 299 |
300 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() | 300 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() |
301 const { | 301 const { |
302 return last_begin_frame_args_; | 302 return last_begin_frame_args_; |
303 } | 303 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 if (needs_begin_frame_ == added_frame_observer_) | 335 if (needs_begin_frame_ == added_frame_observer_) |
336 return; | 336 return; |
337 | 337 |
338 added_frame_observer_ = needs_begin_frame_; | 338 added_frame_observer_ = needs_begin_frame_; |
339 if (needs_begin_frame_) | 339 if (needs_begin_frame_) |
340 begin_frame_source_->AddObserver(this); | 340 begin_frame_source_->AddObserver(this); |
341 else | 341 else |
342 begin_frame_source_->RemoveObserver(this); | 342 begin_frame_source_->RemoveObserver(this); |
343 } | 343 } |
344 | 344 |
345 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( | 345 Surface* CompositorFrameSinkSupport::CreateSurface( |
Fady Samuel
2017/06/26 20:46:43
Would it be simpler if this was void?
Saman Sami
2017/06/26 20:56:24
Then we would have to call GetSurfaceForId after c
| |
346 const SurfaceInfo& surface_info) { | 346 const SurfaceInfo& surface_info) { |
347 seen_first_frame_activation_ = false; | 347 seen_first_frame_activation_ = false; |
348 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), | 348 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), |
Fady Samuel
2017/06/26 20:46:43
Would it be simpler if this was void?
| |
349 surface_info); | 349 surface_info); |
350 } | 350 } |
351 | 351 |
352 void CompositorFrameSinkSupport::DestroyCurrentSurface() { | 352 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
353 surface_manager_->DestroySurface(std::move(current_surface_)); | 353 std::unique_ptr<CopyOutputRequest> copy_request) { |
354 if (!current_surface_id_.is_valid()) | |
355 return; | |
356 Surface* current_surface = | |
357 surface_manager_->GetSurfaceForId(current_surface_id_); | |
358 DCHECK(current_surface->compositor_frame_sink_support().get() == this); | |
danakj
2017/06/27 18:21:31
DCHECK_EQ
Saman Sami
2017/06/28 14:19:43
Done.
| |
359 current_surface->RequestCopyOfOutput(std::move(copy_request)); | |
360 BeginFrameAck ack; | |
361 ack.has_damage = true; | |
362 if (current_surface->HasActiveFrame()) | |
363 surface_manager_->SurfaceModified(current_surface->surface_id(), ack); | |
354 } | 364 } |
355 | 365 |
356 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 366 Surface* CompositorFrameSinkSupport::GetCurrentSurfaceForTesting() { |
357 std::unique_ptr<CopyOutputRequest> copy_request) { | 367 return surface_manager_->GetSurfaceForId(current_surface_id_); |
358 if (!current_surface_) | |
359 return; | |
360 | |
361 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); | |
362 current_surface_->RequestCopyOfOutput(std::move(copy_request)); | |
363 BeginFrameAck ack; | |
364 ack.has_damage = true; | |
365 if (current_surface_->HasActiveFrame()) | |
366 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); | |
367 } | 368 } |
368 | 369 |
369 } // namespace cc | 370 } // namespace cc |
OLD | NEW |