| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_) |
| 81 return; | 81 return; |
| 82 DestroyCurrentSurface(); | 82 surface_manager_->DestroySurface(current_surface_); |
| 83 current_surface_ = nullptr; |
| 83 } | 84 } |
| 84 | 85 |
| 85 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 86 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 86 needs_begin_frame_ = needs_begin_frame; | 87 needs_begin_frame_ = needs_begin_frame; |
| 87 UpdateNeedsBeginFramesInternal(); | 88 UpdateNeedsBeginFramesInternal(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { | 91 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { |
| 91 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", | 92 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", |
| 92 "ack.source_id", ack.source_id, "ack.sequence_number", | 93 "ack.source_id", ack.source_id, "ack.sequence_number", |
| (...skipping 27 matching lines...) Expand all Loading... |
| 120 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { | 121 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { |
| 121 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); | 122 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); |
| 122 } | 123 } |
| 123 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { | 124 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { |
| 124 if (latency.latency_components().size() > 0) { | 125 if (latency.latency_components().size() > 0) { |
| 125 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, | 126 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, |
| 126 0, 0); | 127 0, 0); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 std::unique_ptr<Surface> surface; | 131 Surface* prev_surface = current_surface_; |
| 131 bool create_new_surface = | 132 if (!current_surface_ || |
| 132 (!current_surface_ || | 133 local_surface_id != current_surface_->surface_id().local_surface_id()) { |
| 133 local_surface_id != current_surface_->surface_id().local_surface_id()); | |
| 134 if (!create_new_surface) { | |
| 135 surface = std::move(current_surface_); | |
| 136 } else { | |
| 137 SurfaceId surface_id(frame_sink_id_, local_surface_id); | 134 SurfaceId surface_id(frame_sink_id_, local_surface_id); |
| 138 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 135 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 139 float device_scale_factor = frame.metadata.device_scale_factor; | 136 float device_scale_factor = frame.metadata.device_scale_factor; |
| 140 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); | 137 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); |
| 141 | 138 |
| 142 if (!surface_info.is_valid()) { | 139 if (!surface_info.is_valid()) { |
| 143 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", | 140 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", |
| 144 TRACE_EVENT_SCOPE_THREAD); | 141 TRACE_EVENT_SCOPE_THREAD); |
| 145 if (current_surface_) | 142 if (current_surface_) |
| 146 DestroyCurrentSurface(); | 143 EvictCurrentSurface(); |
| 147 ReturnedResourceArray resources; | 144 ReturnedResourceArray resources; |
| 148 TransferableResource::ReturnResources(frame.resource_list, &resources); | 145 TransferableResource::ReturnResources(frame.resource_list, &resources); |
| 149 ReturnResources(resources); | 146 ReturnResources(resources); |
| 150 DidReceiveCompositorFrameAck(); | 147 DidReceiveCompositorFrameAck(); |
| 151 return true; | 148 return true; |
| 152 } | 149 } |
| 153 | 150 |
| 154 surface = CreateSurface(surface_info); | 151 current_surface_ = CreateSurface(surface_info); |
| 155 } | 152 } |
| 156 | 153 |
| 157 bool result = surface->QueueFrame( | 154 bool result = current_surface_->QueueFrame( |
| 158 std::move(frame), | 155 std::move(frame), |
| 159 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 156 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 160 weak_factory_.GetWeakPtr()), | 157 weak_factory_.GetWeakPtr()), |
| 161 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, | 158 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, |
| 162 weak_factory_.GetWeakPtr())); | 159 weak_factory_.GetWeakPtr())); |
| 163 | 160 |
| 164 if (!result) { | 161 if (!result) { |
| 165 surface_manager_->DestroySurface(std::move(surface)); | 162 EvictCurrentSurface(); |
| 166 return false; | 163 return false; |
| 167 } | 164 } |
| 168 | 165 |
| 169 if (current_surface_) { | 166 if (prev_surface && prev_surface != current_surface_) { |
| 170 surface->SetPreviousFrameSurface(current_surface_.get()); | 167 current_surface_->SetPreviousFrameSurface(prev_surface); |
| 171 DestroyCurrentSurface(); | 168 surface_manager_->DestroySurface(prev_surface); |
| 172 } | 169 } |
| 173 current_surface_ = std::move(surface); | |
| 174 | 170 |
| 175 if (begin_frame_source_) | 171 if (begin_frame_source_) |
| 176 begin_frame_source_->DidFinishFrame(this); | 172 begin_frame_source_->DidFinishFrame(this); |
| 177 | 173 |
| 178 return true; | 174 return true; |
| 179 } | 175 } |
| 180 | 176 |
| 181 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 177 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
| 182 const LocalSurfaceId& local_surface_id, | 178 const LocalSurfaceId& local_surface_id, |
| 183 const std::vector<SurfaceId>& active_referenced_surfaces) { | 179 const std::vector<SurfaceId>& active_referenced_surfaces) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 if (needs_begin_frame_ == added_frame_observer_) | 329 if (needs_begin_frame_ == added_frame_observer_) |
| 334 return; | 330 return; |
| 335 | 331 |
| 336 added_frame_observer_ = needs_begin_frame_; | 332 added_frame_observer_ = needs_begin_frame_; |
| 337 if (needs_begin_frame_) | 333 if (needs_begin_frame_) |
| 338 begin_frame_source_->AddObserver(this); | 334 begin_frame_source_->AddObserver(this); |
| 339 else | 335 else |
| 340 begin_frame_source_->RemoveObserver(this); | 336 begin_frame_source_->RemoveObserver(this); |
| 341 } | 337 } |
| 342 | 338 |
| 343 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( | 339 Surface* CompositorFrameSinkSupport::CreateSurface( |
| 344 const SurfaceInfo& surface_info) { | 340 const SurfaceInfo& surface_info) { |
| 345 seen_first_frame_activation_ = false; | 341 seen_first_frame_activation_ = false; |
| 346 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), | 342 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), |
| 347 surface_info); | 343 surface_info); |
| 348 } | 344 } |
| 349 | 345 |
| 350 void CompositorFrameSinkSupport::DestroyCurrentSurface() { | |
| 351 surface_manager_->DestroySurface(std::move(current_surface_)); | |
| 352 } | |
| 353 | |
| 354 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 346 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
| 355 std::unique_ptr<CopyOutputRequest> copy_request) { | 347 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 356 if (!current_surface_) | 348 if (!current_surface_) |
| 357 return; | 349 return; |
| 358 | 350 |
| 359 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); | 351 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); |
| 360 current_surface_->RequestCopyOfOutput(std::move(copy_request)); | 352 current_surface_->RequestCopyOfOutput(std::move(copy_request)); |
| 361 BeginFrameAck ack; | 353 BeginFrameAck ack; |
| 362 ack.has_damage = true; | 354 ack.has_damage = true; |
| 363 if (current_surface_->HasActiveFrame()) | 355 if (current_surface_->HasActiveFrame()) |
| 364 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); | 356 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); |
| 365 } | 357 } |
| 366 | 358 |
| 367 } // namespace cc | 359 } // namespace cc |
| OLD | NEW |