| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return; | 79 return; |
| 80 DestroyCurrentSurface(); | 80 DestroyCurrentSurface(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 83 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 84 needs_begin_frame_ = needs_begin_frame; | 84 needs_begin_frame_ = needs_begin_frame; |
| 85 UpdateNeedsBeginFramesInternal(); | 85 UpdateNeedsBeginFramesInternal(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { | 88 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { |
| 89 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", |
| 90 "ack.source_id", ack.source_id, "ack.sequence_number", |
| 91 ack.sequence_number); |
| 89 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); | 92 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); |
| 90 | 93 |
| 91 // |has_damage| is not transmitted, but false by default. | 94 // |has_damage| is not transmitted, but false by default. |
| 92 DCHECK(!ack.has_damage); | 95 DCHECK(!ack.has_damage); |
| 93 | 96 |
| 94 // TODO(eseckler): Forward |ack| via SurfaceObservers. | 97 if (current_surface_) |
| 95 | 98 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); |
| 96 if (begin_frame_source_) | 99 if (begin_frame_source_) |
| 97 begin_frame_source_->DidFinishFrame(this); | 100 begin_frame_source_->DidFinishFrame(this); |
| 98 } | 101 } |
| 99 | 102 |
| 100 bool CompositorFrameSinkSupport::SubmitCompositorFrame( | 103 bool CompositorFrameSinkSupport::SubmitCompositorFrame( |
| 101 const LocalSurfaceId& local_surface_id, | 104 const LocalSurfaceId& local_surface_id, |
| 102 CompositorFrame frame) { | 105 CompositorFrame frame) { |
| 103 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); | 106 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); |
| 104 DCHECK(local_surface_id.is_valid()); | 107 DCHECK(local_surface_id.is_valid()); |
| 105 DCHECK(!frame.render_pass_list.empty()); | 108 DCHECK(!frame.render_pass_list.empty()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 157 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 155 weak_factory_.GetWeakPtr()), | 158 weak_factory_.GetWeakPtr()), |
| 156 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, | 159 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, |
| 157 weak_factory_.GetWeakPtr())); | 160 weak_factory_.GetWeakPtr())); |
| 158 | 161 |
| 159 if (!result) { | 162 if (!result) { |
| 160 surface_manager_->DestroySurface(std::move(surface)); | 163 surface_manager_->DestroySurface(std::move(surface)); |
| 161 return false; | 164 return false; |
| 162 } | 165 } |
| 163 | 166 |
| 167 surface_manager_->SurfaceDamageExpected(surface->surface_id(), |
| 168 last_begin_frame_args_); |
| 169 |
| 164 if (current_surface_) { | 170 if (current_surface_) { |
| 165 surface->SetPreviousFrameSurface(current_surface_.get()); | 171 surface->SetPreviousFrameSurface(current_surface_.get()); |
| 166 DestroyCurrentSurface(); | 172 DestroyCurrentSurface(); |
| 167 } | 173 } |
| 168 current_surface_ = std::move(surface); | 174 current_surface_ = std::move(surface); |
| 169 | 175 |
| 170 // TODO(eseckler): Forward |ack| via SurfaceObservers. | |
| 171 | |
| 172 if (begin_frame_source_) | 176 if (begin_frame_source_) |
| 173 begin_frame_source_->DidFinishFrame(this); | 177 begin_frame_source_->DidFinishFrame(this); |
| 174 | 178 |
| 175 return true; | 179 return true; |
| 176 } | 180 } |
| 177 | 181 |
| 178 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 182 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
| 179 const SurfaceId& last_surface_id, | 183 const SurfaceId& last_surface_id, |
| 180 const LocalSurfaceId& local_surface_id) { | 184 const LocalSurfaceId& local_surface_id) { |
| 181 const bool surface_id_changed = | 185 const bool surface_id_changed = |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 296 |
| 293 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { | 297 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { |
| 294 surface_manager_ = surface_manager; | 298 surface_manager_ = surface_manager; |
| 295 if (handles_frame_sink_id_invalidation_) | 299 if (handles_frame_sink_id_invalidation_) |
| 296 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 300 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 297 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); | 301 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); |
| 298 } | 302 } |
| 299 | 303 |
| 300 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { | 304 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { |
| 301 UpdateNeedsBeginFramesInternal(); | 305 UpdateNeedsBeginFramesInternal(); |
| 306 if (current_surface_) { |
| 307 surface_manager_->SurfaceDamageExpected(current_surface_->surface_id(), |
| 308 args); |
| 309 } |
| 302 last_begin_frame_args_ = args; | 310 last_begin_frame_args_ = args; |
| 303 if (client_) | 311 if (client_) |
| 304 client_->OnBeginFrame(args); | 312 client_->OnBeginFrame(args); |
| 305 } | 313 } |
| 306 | 314 |
| 307 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() | 315 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() |
| 308 const { | 316 const { |
| 309 return last_begin_frame_args_; | 317 return last_begin_frame_args_; |
| 310 } | 318 } |
| 311 | 319 |
| 312 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} | 320 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} |
| 313 | 321 |
| 314 void CompositorFrameSinkSupport::OnSurfaceActivated(Surface* surface) { | 322 void CompositorFrameSinkSupport::OnSurfaceActivated(Surface* surface) { |
| 315 DCHECK(surface->HasActiveFrame()); | 323 DCHECK(surface->HasActiveFrame()); |
| 324 const CompositorFrame& frame = surface->GetActiveFrame(); |
| 316 if (!seen_first_frame_activation_) { | 325 if (!seen_first_frame_activation_) { |
| 326 // SurfaceCreated only applies for the first Surface activation. |
| 317 seen_first_frame_activation_ = true; | 327 seen_first_frame_activation_ = true; |
| 318 | 328 |
| 319 const CompositorFrame& frame = surface->GetActiveFrame(); | |
| 320 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 329 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 321 | |
| 322 // SurfaceCreated only applies for the first Surface activation. Thus, | |
| 323 // SurfaceFactory stops observing new activations after the first one. | |
| 324 surface_manager_->SurfaceCreated(SurfaceInfo( | 330 surface_manager_->SurfaceCreated(SurfaceInfo( |
| 325 surface->surface_id(), frame.metadata.device_scale_factor, frame_size)); | 331 surface->surface_id(), frame.metadata.device_scale_factor, frame_size)); |
| 326 } | 332 } |
| 327 // Fire SurfaceCreated first so that a temporary reference is added before it | 333 // Fire SurfaceCreated first so that a temporary reference is added before it |
| 328 // is potentially transformed into a real reference by the client. | 334 // is potentially transformed into a real reference by the client. |
| 329 ReferencedSurfacesChanged(surface->surface_id().local_surface_id(), | 335 ReferencedSurfacesChanged(surface->surface_id().local_surface_id(), |
| 330 surface->active_referenced_surfaces()); | 336 surface->active_referenced_surfaces()); |
| 331 if (!surface_manager_->SurfaceModified(surface->surface_id())) { | 337 if (!surface_manager_->SurfaceModified(surface->surface_id(), |
| 338 frame.metadata.begin_frame_ack)) { |
| 332 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 339 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
| 333 surface->RunDrawCallback(); | 340 surface->RunDrawCallback(); |
| 334 } | 341 } |
| 335 surface_manager_->SurfaceActivated(surface); | 342 surface_manager_->SurfaceActivated(surface); |
| 336 } | 343 } |
| 337 | 344 |
| 338 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { | 345 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { |
| 339 if (!begin_frame_source_) | 346 if (!begin_frame_source_) |
| 340 return; | 347 return; |
| 341 | 348 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 360 surface_manager_->DestroySurface(std::move(current_surface_)); | 367 surface_manager_->DestroySurface(std::move(current_surface_)); |
| 361 } | 368 } |
| 362 | 369 |
| 363 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 370 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
| 364 std::unique_ptr<CopyOutputRequest> copy_request) { | 371 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 365 if (!current_surface_) | 372 if (!current_surface_) |
| 366 return; | 373 return; |
| 367 | 374 |
| 368 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); | 375 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); |
| 369 current_surface_->RequestCopyOfOutput(std::move(copy_request)); | 376 current_surface_->RequestCopyOfOutput(std::move(copy_request)); |
| 370 surface_manager_->SurfaceModified(current_surface_->surface_id()); | 377 BeginFrameAck ack; |
| 378 ack.has_damage = true; |
| 379 if (current_surface_->HasActiveFrame()) |
| 380 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); |
| 371 } | 381 } |
| 372 | 382 |
| 373 } // namespace cc | 383 } // namespace cc |
| OLD | NEW |