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