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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // should not acknowledge immediately. Instead, we should update the ack that | 91 // should not acknowledge immediately. Instead, we should update the ack that |
92 // will be sent to DisplayScheduler when the pending frame is activated. | 92 // will be sent to DisplayScheduler when the pending frame is activated. |
93 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); | 93 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); |
94 | 94 |
95 // |has_damage| is not transmitted, but false by default. | 95 // |has_damage| is not transmitted, but false by default. |
96 DCHECK(!ack.has_damage); | 96 DCHECK(!ack.has_damage); |
97 if (begin_frame_source_) | 97 if (begin_frame_source_) |
98 begin_frame_source_->DidFinishFrame(this, ack); | 98 begin_frame_source_->DidFinishFrame(this, ack); |
99 } | 99 } |
100 | 100 |
101 void CompositorFrameSinkSupport::SubmitCompositorFrame( | 101 bool CompositorFrameSinkSupport::SubmitCompositorFrame( |
102 const LocalSurfaceId& local_surface_id, | 102 const LocalSurfaceId& local_surface_id, |
103 CompositorFrame frame) { | 103 CompositorFrame frame) { |
104 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); | 104 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); |
105 DCHECK(local_surface_id.is_valid()); | 105 DCHECK(local_surface_id.is_valid()); |
106 DCHECK_GE(frame.metadata.begin_frame_ack.sequence_number, | 106 DCHECK_GE(frame.metadata.begin_frame_ack.sequence_number, |
107 BeginFrameArgs::kStartingFrameNumber); | 107 BeginFrameArgs::kStartingFrameNumber); |
108 DCHECK(!frame.render_pass_list.empty()); | 108 DCHECK(!frame.render_pass_list.empty()); |
109 | 109 |
110 ++ack_pending_count_; | 110 ++ack_pending_count_; |
111 | 111 |
(...skipping 13 matching lines...) Expand all Loading... |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 std::unique_ptr<Surface> surface; | 128 std::unique_ptr<Surface> surface; |
129 bool create_new_surface = | 129 bool create_new_surface = |
130 (!current_surface_ || | 130 (!current_surface_ || |
131 local_surface_id != current_surface_->surface_id().local_surface_id()); | 131 local_surface_id != current_surface_->surface_id().local_surface_id()); |
132 if (!create_new_surface) { | 132 if (!create_new_surface) { |
133 surface = std::move(current_surface_); | 133 surface = std::move(current_surface_); |
134 } else { | 134 } else { |
135 surface = CreateSurface(local_surface_id); | 135 SurfaceId surface_id(frame_sink_id_, local_surface_id); |
| 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 137 float device_scale_factor = frame.metadata.device_scale_factor; |
| 138 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); |
| 139 |
| 140 if (!surface_info.is_valid()) { |
| 141 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", |
| 142 TRACE_EVENT_SCOPE_THREAD); |
| 143 if (current_surface_) |
| 144 DestroyCurrentSurface(); |
| 145 ReturnedResourceArray resources; |
| 146 TransferableResource::ReturnResources(frame.resource_list, &resources); |
| 147 ReturnResources(resources); |
| 148 DidReceiveCompositorFrameAck(); |
| 149 return true; |
| 150 } |
| 151 |
| 152 surface = CreateSurface(surface_info); |
136 } | 153 } |
137 | 154 |
138 surface->QueueFrame( | 155 bool result = surface->QueueFrame( |
139 std::move(frame), | 156 std::move(frame), |
140 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 157 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
141 weak_factory_.GetWeakPtr()), | 158 weak_factory_.GetWeakPtr()), |
142 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, | 159 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, |
143 weak_factory_.GetWeakPtr())); | 160 weak_factory_.GetWeakPtr())); |
144 | 161 |
| 162 if (!result) |
| 163 return false; |
| 164 |
145 if (current_surface_) { | 165 if (current_surface_) { |
146 surface->SetPreviousFrameSurface(current_surface_.get()); | 166 surface->SetPreviousFrameSurface(current_surface_.get()); |
147 DestroyCurrentSurface(); | 167 DestroyCurrentSurface(); |
148 } | 168 } |
149 current_surface_ = std::move(surface); | 169 current_surface_ = std::move(surface); |
150 | 170 |
151 // TODO(eseckler): The CompositorFrame submitted below might not be activated | 171 // TODO(eseckler): The CompositorFrame submitted below might not be activated |
152 // right away b/c of surface synchronization. We should only send the | 172 // right away b/c of surface synchronization. We should only send the |
153 // BeginFrameAck to DisplayScheduler when it is activated. This also means | 173 // BeginFrameAck to DisplayScheduler when it is activated. This also means |
154 // that we need to stay an active BFO while a CompositorFrame is pending. | 174 // that we need to stay an active BFO while a CompositorFrame is pending. |
155 // See https://crbug.com/703079. | 175 // See https://crbug.com/703079. |
156 if (begin_frame_source_) | 176 if (begin_frame_source_) |
157 begin_frame_source_->DidFinishFrame(this, ack); | 177 begin_frame_source_->DidFinishFrame(this, ack); |
| 178 |
| 179 return true; |
158 } | 180 } |
159 | 181 |
160 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 182 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
161 const SurfaceId& last_surface_id, | 183 const SurfaceId& last_surface_id, |
162 const LocalSurfaceId& local_surface_id) { | 184 const LocalSurfaceId& local_surface_id) { |
163 const bool surface_id_changed = | 185 const bool surface_id_changed = |
164 last_surface_id.local_surface_id() != local_surface_id; | 186 last_surface_id.local_surface_id() != local_surface_id; |
165 | 187 |
166 // If this is a display root surface and the SurfaceId is changing, make the | 188 // If this is a display root surface and the SurfaceId is changing, make the |
167 // new SurfaceId reachable from the top-level root. | 189 // new SurfaceId reachable from the top-level root. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return; | 347 return; |
326 | 348 |
327 added_frame_observer_ = needs_begin_frame_; | 349 added_frame_observer_ = needs_begin_frame_; |
328 if (needs_begin_frame_) | 350 if (needs_begin_frame_) |
329 begin_frame_source_->AddObserver(this); | 351 begin_frame_source_->AddObserver(this); |
330 else | 352 else |
331 begin_frame_source_->RemoveObserver(this); | 353 begin_frame_source_->RemoveObserver(this); |
332 } | 354 } |
333 | 355 |
334 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( | 356 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( |
335 const LocalSurfaceId& local_surface_id) { | 357 const SurfaceInfo& surface_info) { |
336 seen_first_frame_activation_ = false; | 358 seen_first_frame_activation_ = false; |
337 std::unique_ptr<Surface> surface = surface_manager_->CreateSurface( | 359 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), |
338 weak_factory_.GetWeakPtr(), local_surface_id); | 360 surface_info); |
339 return surface; | |
340 } | 361 } |
341 | 362 |
342 void CompositorFrameSinkSupport::DestroyCurrentSurface() { | 363 void CompositorFrameSinkSupport::DestroyCurrentSurface() { |
343 surface_manager_->DestroySurface(std::move(current_surface_)); | 364 surface_manager_->DestroySurface(std::move(current_surface_)); |
344 } | 365 } |
345 | 366 |
346 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 367 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
347 std::unique_ptr<CopyOutputRequest> copy_request) { | 368 std::unique_ptr<CopyOutputRequest> copy_request) { |
348 if (!current_surface_) | 369 if (!current_surface_) |
349 return; | 370 return; |
350 | 371 |
351 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); | 372 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); |
352 current_surface_->RequestCopyOfOutput(std::move(copy_request)); | 373 current_surface_->RequestCopyOfOutput(std::move(copy_request)); |
353 surface_manager_->SurfaceModified(current_surface_->surface_id()); | 374 surface_manager_->SurfaceModified(current_surface_->surface_id()); |
354 } | 375 } |
355 | 376 |
356 } // namespace cc | 377 } // namespace cc |
OLD | NEW |