| 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 | 43 |
| 44 for (auto& observer : observers_) | 44 for (auto& observer : observers_) |
| 45 observer.OnSurfaceDiscarded(this); | 45 observer.OnSurfaceDiscarded(this); |
| 46 observers_.Clear(); | 46 observers_.Clear(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void Surface::SetPreviousFrameSurface(Surface* surface) { | 49 void Surface::SetPreviousFrameSurface(Surface* surface) { |
| 50 DCHECK(surface); | 50 DCHECK(surface); |
| 51 frame_index_ = surface->frame_index() + 1; | 51 frame_index_ = surface->frame_index() + 1; |
| 52 previous_frame_surface_id_ = surface->surface_id(); | 52 previous_frame_surface_id_ = surface->surface_id(); |
| 53 CompositorFrame& frame = active_frame_ ? *active_frame_ : *pending_frame_; |
| 54 surface->TakeLatencyInfo(&frame.metadata.latency_info); |
| 55 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) { | 58 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) { |
| 59 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 60 |
| 56 base::Optional<CompositorFrame> previous_pending_frame = | 61 base::Optional<CompositorFrame> previous_pending_frame = |
| 57 std::move(pending_frame_); | 62 std::move(pending_frame_); |
| 58 pending_frame_.reset(); | 63 pending_frame_.reset(); |
| 59 | 64 |
| 60 UpdateBlockingSurfaces(previous_pending_frame, frame); | 65 UpdateBlockingSurfaces(previous_pending_frame, frame); |
| 61 | 66 |
| 62 // Receive and track the resources referenced from the CompositorFrame | 67 // Receive and track the resources referenced from the CompositorFrame |
| 63 // regardless of whether it's pending or active. | 68 // regardless of whether it's pending or active. |
| 64 factory_->ReceiveFromChild(frame.resource_list); | 69 factory_->ReceiveFromChild(frame.resource_list); |
| 65 | 70 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 276 } |
| 272 | 277 |
| 273 const CompositorFrame& Surface::GetPendingFrame() { | 278 const CompositorFrame& Surface::GetPendingFrame() { |
| 274 DCHECK(pending_frame_); | 279 DCHECK(pending_frame_); |
| 275 return pending_frame_.value(); | 280 return pending_frame_.value(); |
| 276 } | 281 } |
| 277 | 282 |
| 278 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { | 283 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { |
| 279 if (!active_frame_) | 284 if (!active_frame_) |
| 280 return; | 285 return; |
| 281 if (latency_info->empty()) { | 286 TakeLatencyInfoFromFrame(&active_frame_.value(), latency_info); |
| 282 active_frame_->metadata.latency_info.swap(*latency_info); | |
| 283 return; | |
| 284 } | |
| 285 std::copy(active_frame_->metadata.latency_info.begin(), | |
| 286 active_frame_->metadata.latency_info.end(), | |
| 287 std::back_inserter(*latency_info)); | |
| 288 active_frame_->metadata.latency_info.clear(); | |
| 289 } | 287 } |
| 290 | 288 |
| 291 void Surface::RunDrawCallbacks() { | 289 void Surface::RunDrawCallbacks() { |
| 292 if (!draw_callback_.is_null()) { | 290 if (!draw_callback_.is_null()) { |
| 293 DrawCallback callback = draw_callback_; | 291 DrawCallback callback = draw_callback_; |
| 294 draw_callback_ = DrawCallback(); | 292 draw_callback_ = DrawCallback(); |
| 295 callback.Run(); | 293 callback.Run(); |
| 296 } | 294 } |
| 297 } | 295 } |
| 298 | 296 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 324 | 322 |
| 325 void Surface::ClearCopyRequests() { | 323 void Surface::ClearCopyRequests() { |
| 326 if (active_frame_) { | 324 if (active_frame_) { |
| 327 for (const auto& render_pass : active_frame_->render_pass_list) { | 325 for (const auto& render_pass : active_frame_->render_pass_list) { |
| 328 for (const auto& copy_request : render_pass->copy_requests) | 326 for (const auto& copy_request : render_pass->copy_requests) |
| 329 copy_request->SendEmptyResult(); | 327 copy_request->SendEmptyResult(); |
| 330 } | 328 } |
| 331 } | 329 } |
| 332 } | 330 } |
| 333 | 331 |
| 332 void Surface::TakeLatencyInfoFromPendingFrame( |
| 333 std::vector<ui::LatencyInfo>* latency_info) { |
| 334 if (!pending_frame_) |
| 335 return; |
| 336 TakeLatencyInfoFromFrame(&pending_frame_.value(), latency_info); |
| 337 } |
| 338 |
| 339 // static |
| 340 void Surface::TakeLatencyInfoFromFrame( |
| 341 CompositorFrame* frame, |
| 342 std::vector<ui::LatencyInfo>* latency_info) { |
| 343 if (latency_info->empty()) { |
| 344 frame->metadata.latency_info.swap(*latency_info); |
| 345 return; |
| 346 } |
| 347 std::copy(frame->metadata.latency_info.begin(), |
| 348 frame->metadata.latency_info.end(), |
| 349 std::back_inserter(*latency_info)); |
| 350 frame->metadata.latency_info.clear(); |
| 351 } |
| 352 |
| 334 } // namespace cc | 353 } // namespace cc |
| OLD | NEW |