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 submitted to surfaces referenced from this |
| 88 // CompositorFrame as fallbacks. This saves some CPU cycles to allow |
| 89 // children to catch up to the parent. |
| 90 base::flat_set<FrameSinkId> frame_sink_ids_for_dependencies; |
| 91 for (const SurfaceId& surface_id : frame.metadata.activation_dependencies) |
| 92 frame_sink_ids_for_dependencies.insert(surface_id.frame_sink_id()); |
| 93 for (const SurfaceId& surface_id : frame.metadata.referenced_surfaces) { |
| 94 // A surface ID in |referenced_surfaces| that has a corresponding surface |
| 95 // ID in |activation_dependencies| with the same frame sink ID is said to |
| 96 // be a fallback surface that can be used in place of the primary surface |
| 97 // if the deadline passes before the dependency becomes available. |
| 98 bool is_fallback_surface = |
| 99 frame_sink_ids_for_dependencies.count(surface_id.frame_sink_id()) > 0; |
| 100 if (is_fallback_surface) { |
| 101 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id); |
| 102 DCHECK(surface); |
| 103 surface->Close(); |
| 104 } |
| 105 } |
71 pending_frame_data_ = | 106 pending_frame_data_ = |
72 FrameData(std::move(frame), callback, will_draw_callback); | 107 FrameData(std::move(frame), callback, will_draw_callback); |
73 // Ask the surface manager to inform |this| when its dependencies are | 108 // Ask the surface manager to inform |this| when its dependencies are |
74 // resolved. | 109 // resolved. |
75 factory_->manager()->RequestSurfaceResolution(this); | 110 factory_->manager()->RequestSurfaceResolution(this); |
76 } else { | 111 } else { |
77 // If there are no blockers, then immediately activate the frame. | 112 // If there are no blockers, then immediately activate the frame. |
78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); | 113 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); |
79 } | 114 } |
80 | 115 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 frame->metadata.latency_info.swap(*latency_info); | 377 frame->metadata.latency_info.swap(*latency_info); |
343 return; | 378 return; |
344 } | 379 } |
345 std::copy(frame->metadata.latency_info.begin(), | 380 std::copy(frame->metadata.latency_info.begin(), |
346 frame->metadata.latency_info.end(), | 381 frame->metadata.latency_info.end(), |
347 std::back_inserter(*latency_info)); | 382 std::back_inserter(*latency_info)); |
348 frame->metadata.latency_info.clear(); | 383 frame->metadata.latency_info.clear(); |
349 } | 384 } |
350 | 385 |
351 } // namespace cc | 386 } // namespace cc |
OLD | NEW |