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> |
| 11 | 11 |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/compositor_frame.h" |
| 14 #include "cc/output/copy_output_request.h" | 14 #include "cc/output/copy_output_request.h" |
| 15 #include "cc/surfaces/local_surface_id_allocator.h" | 15 #include "cc/surfaces/local_surface_id_allocator.h" |
| 16 #include "cc/surfaces/pending_frame_observer.h" | 16 #include "cc/surfaces/pending_frame_observer.h" |
| 17 #include "cc/surfaces/surface_factory.h" | 17 #include "cc/surfaces/surface_factory.h" |
| 18 #include "cc/surfaces/surface_manager.h" | 18 #include "cc/surfaces/surface_manager.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 | 21 |
| 22 // The frame index starts at 2 so that empty frames will be treated as | 22 // The frame index starts at 2 so that empty frames will be treated as |
| 23 // completely damaged the first time they're drawn from. | 23 // completely damaged the first time they're drawn from. |
| 24 static const int kFrameIndexStart = 2; | 24 static const int kFrameIndexStart = 2; |
| 25 | 25 |
| 26 Surface::Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory) | 26 Surface::Surface(const SurfaceInfo& info, base::WeakPtr<SurfaceFactory> factory) |
| 27 : surface_id_(id), | 27 : surface_info_(info), |
| 28 previous_frame_surface_id_(id), | 28 previous_frame_surface_id_(info.id()), |
| 29 factory_(factory), | 29 factory_(factory), |
| 30 frame_index_(kFrameIndexStart), | 30 frame_index_(kFrameIndexStart), |
| 31 destroyed_(false) {} | 31 destroyed_(false) {} |
| 32 | 32 |
| 33 Surface::~Surface() { | 33 Surface::~Surface() { |
| 34 ClearCopyRequests(); | 34 ClearCopyRequests(); |
| 35 for (auto& observer : observers_) | 35 for (auto& observer : observers_) |
| 36 observer.OnSurfaceDiscarded(this); | 36 observer.OnSurfaceDiscarded(this); |
| 37 observers_.Clear(); | 37 observers_.Clear(); |
| 38 | 38 |
| 39 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_)); | 39 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_)); |
| 40 UnrefFrameResourcesAndRunDrawCallback(std::move(active_frame_data_)); | 40 UnrefFrameResourcesAndRunDrawCallback(std::move(active_frame_data_)); |
| 41 } | 41 } |
| 42 | 42 |
| 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, | 53 void Surface::QueueFrame(CompositorFrame frame, |
| 54 const DrawCallback& callback, | 54 const DrawCallback& callback, |
| 55 const WillDrawCallback& will_draw_callback) { | 55 const WillDrawCallback& will_draw_callback) { |
| 56 if (!frame.render_pass_list.empty()) { | |
|
Fady Samuel
2017/05/07 18:16:51
Not necessary any more right?
Saman Sami
2017/05/08 20:40:32
Done.
| |
| 57 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | |
| 58 float device_scale_factor = frame.metadata.device_scale_factor; | |
| 59 if (frame_size != surface_info_.size_in_pixels() || | |
| 60 device_scale_factor != surface_info_.device_scale_factor()) { | |
|
Fady Samuel
2017/05/01 20:36:54
Return resources and call the callback too.
Fady Samuel
2017/05/07 18:16:51
I'd love to move this test into a common place bec
Saman Sami
2017/05/08 20:40:32
That'll be nice, yes.
Saman Sami
2017/05/16 18:55:46
Actually, I'm not sure how much that will help. I
| |
| 61 DLOG(ERROR) << "Frame size doesn't match surface size."; | |
| 62 return; | |
| 63 } | |
| 64 } | |
| 65 | |
| 56 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 66 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 57 | 67 |
| 58 base::Optional<FrameData> previous_pending_frame_data = | 68 base::Optional<FrameData> previous_pending_frame_data = |
| 59 std::move(pending_frame_data_); | 69 std::move(pending_frame_data_); |
| 60 pending_frame_data_.reset(); | 70 pending_frame_data_.reset(); |
| 61 | 71 |
| 62 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); | 72 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); |
| 63 | 73 |
| 64 // Receive and track the resources referenced from the CompositorFrame | 74 // Receive and track the resources referenced from the CompositorFrame |
| 65 // regardless of whether it's pending or active. | 75 // regardless of whether it's pending or active. |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 DrawCallback callback = active_frame_data_->draw_callback; | 290 DrawCallback callback = active_frame_data_->draw_callback; |
| 281 active_frame_data_->draw_callback = DrawCallback(); | 291 active_frame_data_->draw_callback = DrawCallback(); |
| 282 callback.Run(); | 292 callback.Run(); |
| 283 } | 293 } |
| 284 } | 294 } |
| 285 | 295 |
| 286 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { | 296 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { |
| 287 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) | 297 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) |
| 288 return; | 298 return; |
| 289 | 299 |
| 290 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), | 300 active_frame_data_->will_draw_callback.Run(surface_id().local_surface_id(), |
| 291 damage_rect); | 301 damage_rect); |
| 292 } | 302 } |
| 293 | 303 |
| 294 void Surface::AddDestructionDependency(SurfaceSequence sequence) { | 304 void Surface::AddDestructionDependency(SurfaceSequence sequence) { |
| 295 destruction_dependencies_.push_back(sequence); | 305 destruction_dependencies_.push_back(sequence); |
| 296 } | 306 } |
| 297 | 307 |
| 298 void Surface::SatisfyDestructionDependencies( | 308 void Surface::SatisfyDestructionDependencies( |
| 299 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, | 309 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, |
| 300 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { | 310 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 frame->metadata.latency_info.swap(*latency_info); | 356 frame->metadata.latency_info.swap(*latency_info); |
| 347 return; | 357 return; |
| 348 } | 358 } |
| 349 std::copy(frame->metadata.latency_info.begin(), | 359 std::copy(frame->metadata.latency_info.begin(), |
| 350 frame->metadata.latency_info.end(), | 360 frame->metadata.latency_info.end(), |
| 351 std::back_inserter(*latency_info)); | 361 std::back_inserter(*latency_info)); |
| 352 frame->metadata.latency_info.clear(); | 362 frame->metadata.latency_info.clear(); |
| 353 } | 363 } |
| 354 | 364 |
| 355 } // namespace cc | 365 } // namespace cc |
| OLD | NEW |