Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surface.h" | 5 #include "cc/surfaces/surface.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 void Surface::SetPreviousFrameSurface(Surface* surface) { | 43 void Surface::SetPreviousFrameSurface(Surface* surface) { |
| 44 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); | 44 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); |
| 45 frame_index_ = surface->frame_index() + 1; | 45 frame_index_ = surface->frame_index() + 1; |
| 46 previous_frame_surface_id_ = surface->surface_id(); | 46 previous_frame_surface_id_ = surface->surface_id(); |
| 47 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame | 47 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame |
| 48 : pending_frame_data_->frame; | 48 : pending_frame_data_->frame; |
| 49 surface->TakeLatencyInfo(&frame.metadata.latency_info); | 49 surface->TakeLatencyInfo(&frame.metadata.latency_info); |
| 50 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 50 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) { | 53 void Surface::QueueFrame(CompositorFrame frame, |
| 54 const DrawCallback& callback, | |
| 55 const WillDrawCallback& will_draw_callback) { | |
| 54 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 56 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 55 | 57 |
| 56 base::Optional<FrameData> previous_pending_frame_data = | 58 base::Optional<FrameData> previous_pending_frame_data = |
| 57 std::move(pending_frame_data_); | 59 std::move(pending_frame_data_); |
| 58 pending_frame_data_.reset(); | 60 pending_frame_data_.reset(); |
| 59 | 61 |
| 60 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); | 62 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); |
| 61 | 63 |
| 62 // Receive and track the resources referenced from the CompositorFrame | 64 // Receive and track the resources referenced from the CompositorFrame |
| 63 // regardless of whether it's pending or active. | 65 // regardless of whether it's pending or active. |
| 64 factory_->ReceiveFromChild(frame.resource_list); | 66 factory_->ReceiveFromChild(frame.resource_list); |
| 65 | 67 |
| 66 bool is_pending_frame = !blocking_surfaces_.empty(); | 68 bool is_pending_frame = !blocking_surfaces_.empty(); |
| 67 | 69 |
| 68 if (is_pending_frame) { | 70 if (is_pending_frame) { |
| 69 pending_frame_data_ = FrameData(std::move(frame), callback); | 71 pending_frame_data_ = |
| 72 FrameData(std::move(frame), callback, will_draw_callback); | |
| 70 // Ask the surface manager to inform |this| when its dependencies are | 73 // Ask the surface manager to inform |this| when its dependencies are |
| 71 // resolved. | 74 // resolved. |
| 72 factory_->manager()->RequestSurfaceResolution(this); | 75 factory_->manager()->RequestSurfaceResolution(this); |
| 73 } else { | 76 } else { |
| 74 // If there are no blockers, then immediately activate the frame. | 77 // If there are no blockers, then immediately activate the frame. |
| 75 ActivateFrame(FrameData(std::move(frame), callback)); | 78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); |
| 76 } | 79 } |
| 77 | 80 |
| 78 // Returns resources for the previous pending frame. | 81 // Returns resources for the previous pending frame. |
| 79 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); | 82 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void Surface::EvictFrame() { | 85 void Surface::EvictFrame() { |
| 83 QueueFrame(CompositorFrame(), DrawCallback()); | 86 QueueFrame(CompositorFrame(), DrawCallback(), WillDrawCallback()); |
| 84 active_frame_data_.reset(); | 87 active_frame_data_.reset(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void Surface::RequestCopyOfOutput( | 90 void Surface::RequestCopyOfOutput( |
| 88 std::unique_ptr<CopyOutputRequest> copy_request) { | 91 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 89 if (!active_frame_data_ || | 92 if (!active_frame_data_ || |
| 90 active_frame_data_->frame.render_pass_list.empty()) { | 93 active_frame_data_->frame.render_pass_list.empty()) { |
| 91 copy_request->SendEmptyResult(); | 94 copy_request->SendEmptyResult(); |
| 92 return; | 95 return; |
| 93 } | 96 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 return; | 139 return; |
| 137 } | 140 } |
| 138 | 141 |
| 139 // If a frame is being activated because of a deadline, then clear its set | 142 // If a frame is being activated because of a deadline, then clear its set |
| 140 // of blockers. | 143 // of blockers. |
| 141 blocking_surfaces_.clear(); | 144 blocking_surfaces_.clear(); |
| 142 ActivatePendingFrame(); | 145 ActivatePendingFrame(); |
| 143 } | 146 } |
| 144 | 147 |
| 145 Surface::FrameData::FrameData(CompositorFrame&& frame, | 148 Surface::FrameData::FrameData(CompositorFrame&& frame, |
| 146 const DrawCallback& draw_callback) | 149 const DrawCallback& draw_callback, |
| 147 : frame(std::move(frame)), draw_callback(draw_callback) {} | 150 const WillDrawCallback& will_draw_callback) |
| 151 : frame(std::move(frame)), | |
| 152 draw_callback(draw_callback), | |
| 153 will_draw_callback(will_draw_callback) {} | |
| 148 | 154 |
| 149 Surface::FrameData::FrameData(FrameData&& other) = default; | 155 Surface::FrameData::FrameData(FrameData&& other) = default; |
| 150 | 156 |
| 151 Surface::FrameData& Surface::FrameData::operator=(FrameData&& other) = default; | 157 Surface::FrameData& Surface::FrameData::operator=(FrameData&& other) = default; |
| 152 | 158 |
| 153 Surface::FrameData::~FrameData() = default; | 159 Surface::FrameData::~FrameData() = default; |
| 154 | 160 |
| 155 void Surface::ActivatePendingFrame() { | 161 void Surface::ActivatePendingFrame() { |
| 156 DCHECK(pending_frame_data_); | 162 DCHECK(pending_frame_data_); |
| 157 ActivateFrame(std::move(*pending_frame_data_)); | 163 ActivateFrame(std::move(*pending_frame_data_)); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 281 } |
| 276 | 282 |
| 277 void Surface::RunDrawCallbacks() { | 283 void Surface::RunDrawCallbacks() { |
| 278 if (active_frame_data_ && !active_frame_data_->draw_callback.is_null()) { | 284 if (active_frame_data_ && !active_frame_data_->draw_callback.is_null()) { |
| 279 DrawCallback callback = active_frame_data_->draw_callback; | 285 DrawCallback callback = active_frame_data_->draw_callback; |
| 280 active_frame_data_->draw_callback = DrawCallback(); | 286 active_frame_data_->draw_callback = DrawCallback(); |
| 281 callback.Run(); | 287 callback.Run(); |
| 282 } | 288 } |
| 283 } | 289 } |
| 284 | 290 |
| 291 void Surface::RunWillDrawCallbacks(const gfx::Rect& damage_rect) { | |
|
Fady Samuel
2017/04/20 12:45:48
I'm really not sure why this is plural. RunWillDra
danakj
2017/04/20 13:56:45
+1 to RunWillDrawCallback. Early out is fine, but
Alex Z.
2017/04/20 13:58:05
Done. I got the plural form RunDrawCallbacks. I fi
| |
| 292 if (active_frame_data_ && !active_frame_data_->will_draw_callback.is_null()) { | |
| 293 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), | |
| 294 damage_rect); | |
| 295 } | |
| 296 } | |
| 297 | |
| 285 void Surface::AddDestructionDependency(SurfaceSequence sequence) { | 298 void Surface::AddDestructionDependency(SurfaceSequence sequence) { |
| 286 destruction_dependencies_.push_back(sequence); | 299 destruction_dependencies_.push_back(sequence); |
| 287 } | 300 } |
| 288 | 301 |
| 289 void Surface::SatisfyDestructionDependencies( | 302 void Surface::SatisfyDestructionDependencies( |
| 290 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, | 303 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, |
| 291 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { | 304 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { |
| 292 base::EraseIf(destruction_dependencies_, | 305 base::EraseIf(destruction_dependencies_, |
| 293 [sequences, valid_frame_sink_ids](SurfaceSequence seq) { | 306 [sequences, valid_frame_sink_ids](SurfaceSequence seq) { |
| 294 return (!!sequences->erase(seq) || | 307 return (!!sequences->erase(seq) || |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 frame->metadata.latency_info.swap(*latency_info); | 350 frame->metadata.latency_info.swap(*latency_info); |
| 338 return; | 351 return; |
| 339 } | 352 } |
| 340 std::copy(frame->metadata.latency_info.begin(), | 353 std::copy(frame->metadata.latency_info.begin(), |
| 341 frame->metadata.latency_info.end(), | 354 frame->metadata.latency_info.end(), |
| 342 std::back_inserter(*latency_info)); | 355 std::back_inserter(*latency_info)); |
| 343 frame->metadata.latency_info.clear(); | 356 frame->metadata.latency_info.clear(); |
| 344 } | 357 } |
| 345 | 358 |
| 346 } // namespace cc | 359 } // namespace cc |
| OLD | NEW |