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_factory_client.h" | |
| 18 #include "cc/surfaces/surface_manager.h" | 19 #include "cc/surfaces/surface_manager.h" |
| 20 #include "cc/surfaces/surface_resource_holder_client.h" | |
| 19 | 21 |
| 20 namespace cc { | 22 namespace cc { |
| 21 | 23 |
| 22 // The frame index starts at 2 so that empty frames will be treated as | 24 // The frame index starts at 2 so that empty frames will be treated as |
| 23 // completely damaged the first time they're drawn from. | 25 // completely damaged the first time they're drawn from. |
| 24 static const int kFrameIndexStart = 2; | 26 static const int kFrameIndexStart = 2; |
| 25 | 27 |
| 26 Surface::Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory) | 28 Surface::Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory) |
| 27 : surface_id_(id), | 29 : surface_id_(id), |
| 28 previous_frame_surface_id_(id), | 30 previous_frame_surface_id_(id), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 43 void Surface::SetPreviousFrameSurface(Surface* surface) { | 45 void Surface::SetPreviousFrameSurface(Surface* surface) { |
| 44 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); | 46 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); |
| 45 frame_index_ = surface->frame_index() + 1; | 47 frame_index_ = surface->frame_index() + 1; |
| 46 previous_frame_surface_id_ = surface->surface_id(); | 48 previous_frame_surface_id_ = surface->surface_id(); |
| 47 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame | 49 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame |
| 48 : pending_frame_data_->frame; | 50 : pending_frame_data_->frame; |
| 49 surface->TakeLatencyInfo(&frame.metadata.latency_info); | 51 surface->TakeLatencyInfo(&frame.metadata.latency_info); |
| 50 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 52 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 51 } | 53 } |
| 52 | 54 |
| 55 void Surface::Close() { | |
| 56 closed_ = true; | |
| 57 } | |
| 58 | |
| 53 void Surface::QueueFrame(CompositorFrame frame, | 59 void Surface::QueueFrame(CompositorFrame frame, |
| 54 const DrawCallback& callback, | 60 const DrawCallback& callback, |
| 55 const WillDrawCallback& will_draw_callback) { | 61 const WillDrawCallback& will_draw_callback) { |
| 62 if (closed_) { | |
| 63 if (factory_ && factory_->resource_holder_client()) { | |
| 64 ReturnedResourceArray resources; | |
| 65 TransferableResource::ReturnResources(frame.resource_list, &resources); | |
| 66 factory_->resource_holder_client()->ReturnResources(resources); | |
| 67 } | |
| 68 callback.Run(); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 56 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 72 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
| 57 | 73 |
| 58 base::Optional<FrameData> previous_pending_frame_data = | 74 base::Optional<FrameData> previous_pending_frame_data = |
| 59 std::move(pending_frame_data_); | 75 std::move(pending_frame_data_); |
| 60 pending_frame_data_.reset(); | 76 pending_frame_data_.reset(); |
| 61 | 77 |
| 62 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); | 78 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); |
| 63 | 79 |
| 64 // Receive and track the resources referenced from the CompositorFrame | 80 // Receive and track the resources referenced from the CompositorFrame |
| 65 // regardless of whether it's pending or active. | 81 // regardless of whether it's pending or active. |
| 66 factory_->ReceiveFromChild(frame.resource_list); | 82 factory_->ReceiveFromChild(frame.resource_list); |
| 67 | 83 |
| 68 bool is_pending_frame = !blocking_surfaces_.empty(); | 84 bool is_pending_frame = !blocking_surfaces_.empty(); |
| 69 | 85 |
| 70 if (is_pending_frame) { | 86 if (is_pending_frame) { |
| 87 // Reject CompositorFrames to surfaces referenced from CompositorFrame while | |
|
danakj
2017/05/04 21:39:13
CompositorFrame is a type, you're using it in this
Fady Samuel
2017/05/04 22:44:04
I'm not sure what you mean. I do agree this is con
| |
| 88 // it is blocked. This saves some CPU cycles to allow children to catch up | |
| 89 // to this surface's client. | |
| 90 base::flat_set<FrameSinkId> embedded_frame_sink_ids; | |
| 91 for (const SurfaceId& surface_id : frame.metadata.embedded_surfaces) | |
| 92 embedded_frame_sink_ids.insert(surface_id.frame_sink_id()); | |
| 93 for (const SurfaceId& surface_id : frame.metadata.referenced_surfaces) { | |
| 94 // If this surface is a fallback surface, then we close the fallback to | |
| 95 // accepting new frames. | |
| 96 bool is_fallback_surface = | |
| 97 embedded_frame_sink_ids.count(surface_id.frame_sink_id()) > 0; | |
|
danakj
2017/05/04 21:39:13
Didnt ur other CL just make it not possible to be
Fady Samuel
2017/05/04 22:44:04
I'm comparing FrameSinkIds not SurfaceIds.
Basica
| |
| 98 if (is_fallback_surface) { | |
| 99 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id); | |
| 100 DCHECK(surface); | |
| 101 surface->Close(); | |
| 102 } | |
| 103 } | |
| 71 pending_frame_data_ = | 104 pending_frame_data_ = |
| 72 FrameData(std::move(frame), callback, will_draw_callback); | 105 FrameData(std::move(frame), callback, will_draw_callback); |
| 73 // Ask the surface manager to inform |this| when its dependencies are | 106 // Ask the surface manager to inform |this| when its dependencies are |
| 74 // resolved. | 107 // resolved. |
| 75 factory_->manager()->RequestSurfaceResolution(this); | 108 factory_->manager()->RequestSurfaceResolution(this); |
| 76 } else { | 109 } else { |
| 77 // If there are no blockers, then immediately activate the frame. | 110 // If there are no blockers, then immediately activate the frame. |
| 78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); | 111 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); |
| 79 } | 112 } |
| 80 | 113 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 frame->metadata.latency_info.swap(*latency_info); | 379 frame->metadata.latency_info.swap(*latency_info); |
| 347 return; | 380 return; |
| 348 } | 381 } |
| 349 std::copy(frame->metadata.latency_info.begin(), | 382 std::copy(frame->metadata.latency_info.begin(), |
| 350 frame->metadata.latency_info.end(), | 383 frame->metadata.latency_info.end(), |
| 351 std::back_inserter(*latency_info)); | 384 std::back_inserter(*latency_info)); |
| 352 frame->metadata.latency_info.clear(); | 385 frame->metadata.latency_info.clear(); |
| 353 } | 386 } |
| 354 | 387 |
| 355 } // namespace cc | 388 } // namespace cc |
| OLD | NEW |