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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 Surface::Surface(SurfaceId id, SurfaceFactory* factory) | 25 Surface::Surface(SurfaceId id, SurfaceFactory* factory) |
26 : surface_id_(id), | 26 : surface_id_(id), |
27 previous_frame_surface_id_(id), | 27 previous_frame_surface_id_(id), |
28 factory_(factory->AsWeakPtr()), | 28 factory_(factory->AsWeakPtr()), |
29 frame_index_(kFrameIndexStart), | 29 frame_index_(kFrameIndexStart), |
30 destroyed_(false) {} | 30 destroyed_(false) {} |
31 | 31 |
32 Surface::~Surface() { | 32 Surface::~Surface() { |
33 ClearCopyRequests(); | 33 ClearCopyRequests(); |
34 if (current_frame_.delegated_frame_data && factory_) { | 34 if (current_frame_ && factory_) { |
35 UnrefFrameResources(current_frame_.delegated_frame_data.get()); | 35 UnrefFrameResources(current_frame_->delegated_frame_data.get()); |
36 } | 36 } |
37 if (!draw_callback_.is_null()) | 37 if (!draw_callback_.is_null()) |
38 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); | 38 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); |
39 } | 39 } |
40 | 40 |
41 void Surface::SetPreviousFrameSurface(Surface* surface) { | 41 void Surface::SetPreviousFrameSurface(Surface* surface) { |
42 DCHECK(surface); | 42 DCHECK(surface); |
43 frame_index_ = surface->frame_index() + 1; | 43 frame_index_ = surface->frame_index() + 1; |
44 previous_frame_surface_id_ = surface->surface_id(); | 44 previous_frame_surface_id_ = surface->surface_id(); |
45 } | 45 } |
46 | 46 |
47 void Surface::SetGpuMemoryBufferClientId(int gpu_memory_buffer_client_id) { | 47 void Surface::SetGpuMemoryBufferClientId(int gpu_memory_buffer_client_id) { |
48 // This should only be set once. | 48 // This should only be set once. |
49 DCHECK_EQ(-1, gpu_memory_buffer_client_id_); | 49 DCHECK_EQ(-1, gpu_memory_buffer_client_id_); |
50 DCHECK_NE(gpu_memory_buffer_client_id, gpu_memory_buffer_client_id_); | 50 DCHECK_NE(gpu_memory_buffer_client_id, gpu_memory_buffer_client_id_); |
51 gpu_memory_buffer_client_id_ = gpu_memory_buffer_client_id; | 51 gpu_memory_buffer_client_id_ = gpu_memory_buffer_client_id; |
52 } | 52 } |
53 | 53 |
54 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) { | 54 void Surface::QueueFrame(std::unique_ptr<CompositorFrame> frame, |
| 55 const DrawCallback& callback) { |
55 DCHECK(factory_); | 56 DCHECK(factory_); |
56 ClearCopyRequests(); | 57 ClearCopyRequests(); |
57 | 58 |
58 if (frame.delegated_frame_data) { | 59 if (frame) { |
59 TakeLatencyInfo(&frame.metadata.latency_info); | 60 TakeLatencyInfo(&frame->metadata.latency_info); |
60 } | 61 } |
61 | 62 |
62 CompositorFrame previous_frame = std::move(current_frame_); | 63 std::unique_ptr<CompositorFrame> previous_frame = std::move(current_frame_); |
63 current_frame_ = std::move(frame); | 64 current_frame_ = std::move(frame); |
64 | 65 |
65 if (current_frame_.delegated_frame_data) { | 66 if (current_frame_) { |
66 factory_->ReceiveFromChild( | 67 factory_->ReceiveFromChild( |
67 current_frame_.delegated_frame_data->resource_list); | 68 current_frame_->delegated_frame_data->resource_list); |
68 } | 69 } |
69 | 70 |
70 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't | 71 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't |
71 // increment frame index for them. | 72 // increment frame index for them. |
72 if (current_frame_.delegated_frame_data && | 73 if (current_frame_ && |
73 !current_frame_.delegated_frame_data->render_pass_list.empty()) { | 74 !current_frame_->delegated_frame_data->render_pass_list.empty()) |
74 ++frame_index_; | 75 ++frame_index_; |
75 } | |
76 | 76 |
77 previous_frame_surface_id_ = surface_id(); | 77 previous_frame_surface_id_ = surface_id(); |
78 | 78 |
79 std::vector<SurfaceId> new_referenced_surfaces; | 79 std::vector<SurfaceId> new_referenced_surfaces; |
80 new_referenced_surfaces = current_frame_.metadata.referenced_surfaces; | 80 if (current_frame_) { |
| 81 new_referenced_surfaces = current_frame_->metadata.referenced_surfaces; |
| 82 } |
81 | 83 |
82 if (previous_frame.delegated_frame_data) | 84 if (previous_frame) { |
83 UnrefFrameResources(previous_frame.delegated_frame_data.get()); | 85 UnrefFrameResources(previous_frame->delegated_frame_data.get()); |
84 | 86 } |
85 if (!draw_callback_.is_null()) | 87 if (!draw_callback_.is_null()) |
86 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); | 88 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); |
87 draw_callback_ = callback; | 89 draw_callback_ = callback; |
88 | 90 |
89 bool referenced_surfaces_changed = | 91 bool referenced_surfaces_changed = |
90 (referenced_surfaces_ != new_referenced_surfaces); | 92 (referenced_surfaces_ != new_referenced_surfaces); |
91 referenced_surfaces_ = new_referenced_surfaces; | 93 referenced_surfaces_ = new_referenced_surfaces; |
92 std::vector<uint32_t> satisfies_sequences = | 94 std::vector<uint32_t> satisfies_sequences; |
93 std::move(current_frame_.metadata.satisfies_sequences); | 95 if (current_frame_) |
94 | 96 current_frame_->metadata.satisfies_sequences.swap(satisfies_sequences); |
95 if (referenced_surfaces_changed || !satisfies_sequences.empty()) { | 97 if (referenced_surfaces_changed || !satisfies_sequences.empty()) { |
96 // Notify the manager that sequences were satisfied either if some new | 98 // Notify the manager that sequences were satisfied either if some new |
97 // sequences were satisfied, or if the set of referenced surfaces changed | 99 // sequences were satisfied, or if the set of referenced surfaces changed |
98 // to force a GC to happen. | 100 // to force a GC to happen. |
99 factory_->manager()->DidSatisfySequences(surface_id_.id_namespace(), | 101 factory_->manager()->DidSatisfySequences(surface_id_.id_namespace(), |
100 &satisfies_sequences); | 102 &satisfies_sequences); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 void Surface::RequestCopyOfOutput( | 106 void Surface::RequestCopyOfOutput( |
105 std::unique_ptr<CopyOutputRequest> copy_request) { | 107 std::unique_ptr<CopyOutputRequest> copy_request) { |
106 if (current_frame_.delegated_frame_data && | 108 if (current_frame_ && |
107 !current_frame_.delegated_frame_data->render_pass_list.empty()) { | 109 !current_frame_->delegated_frame_data->render_pass_list.empty()) { |
108 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = | 110 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = |
109 current_frame_.delegated_frame_data->render_pass_list.back() | 111 current_frame_->delegated_frame_data->render_pass_list.back() |
110 ->copy_requests; | 112 ->copy_requests; |
111 | 113 |
112 if (void* source = copy_request->source()) { | 114 if (void* source = copy_request->source()) { |
113 // Remove existing CopyOutputRequests made on the Surface by the same | 115 // Remove existing CopyOutputRequests made on the Surface by the same |
114 // source. | 116 // source. |
115 auto to_remove = | 117 auto to_remove = |
116 std::remove_if(copy_requests.begin(), copy_requests.end(), | 118 std::remove_if(copy_requests.begin(), copy_requests.end(), |
117 [source](const std::unique_ptr<CopyOutputRequest>& x) { | 119 [source](const std::unique_ptr<CopyOutputRequest>& x) { |
118 return x->source() == source; | 120 return x->source() == source; |
119 }); | 121 }); |
120 copy_requests.erase(to_remove, copy_requests.end()); | 122 copy_requests.erase(to_remove, copy_requests.end()); |
121 } | 123 } |
122 copy_requests.push_back(std::move(copy_request)); | 124 copy_requests.push_back(std::move(copy_request)); |
123 } else { | 125 } else { |
124 copy_request->SendEmptyResult(); | 126 copy_request->SendEmptyResult(); |
125 } | 127 } |
126 } | 128 } |
127 | 129 |
128 void Surface::TakeCopyOutputRequests( | 130 void Surface::TakeCopyOutputRequests( |
129 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>* | 131 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>* |
130 copy_requests) { | 132 copy_requests) { |
131 DCHECK(copy_requests->empty()); | 133 DCHECK(copy_requests->empty()); |
132 if (current_frame_.delegated_frame_data) { | 134 if (current_frame_) { |
133 for (const auto& render_pass : | 135 for (const auto& render_pass : |
134 current_frame_.delegated_frame_data->render_pass_list) { | 136 current_frame_->delegated_frame_data->render_pass_list) { |
135 for (auto& request : render_pass->copy_requests) { | 137 for (auto& request : render_pass->copy_requests) { |
136 copy_requests->insert( | 138 copy_requests->insert( |
137 std::make_pair(render_pass->id, std::move(request))); | 139 std::make_pair(render_pass->id, std::move(request))); |
138 } | 140 } |
139 render_pass->copy_requests.clear(); | 141 render_pass->copy_requests.clear(); |
140 } | 142 } |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 const CompositorFrame& Surface::GetEligibleFrame() { | 146 const CompositorFrame* Surface::GetEligibleFrame() { |
145 return current_frame_; | 147 return current_frame_.get(); |
146 } | 148 } |
147 | 149 |
148 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { | 150 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { |
149 if (!current_frame_.delegated_frame_data) | 151 if (!current_frame_) |
150 return; | 152 return; |
151 if (latency_info->empty()) { | 153 if (latency_info->empty()) { |
152 current_frame_.metadata.latency_info.swap(*latency_info); | 154 current_frame_->metadata.latency_info.swap(*latency_info); |
153 return; | 155 return; |
154 } | 156 } |
155 std::copy(current_frame_.metadata.latency_info.begin(), | 157 std::copy(current_frame_->metadata.latency_info.begin(), |
156 current_frame_.metadata.latency_info.end(), | 158 current_frame_->metadata.latency_info.end(), |
157 std::back_inserter(*latency_info)); | 159 std::back_inserter(*latency_info)); |
158 current_frame_.metadata.latency_info.clear(); | 160 current_frame_->metadata.latency_info.clear(); |
159 } | 161 } |
160 | 162 |
161 void Surface::RunDrawCallbacks(SurfaceDrawStatus drawn) { | 163 void Surface::RunDrawCallbacks(SurfaceDrawStatus drawn) { |
162 if (!draw_callback_.is_null()) { | 164 if (!draw_callback_.is_null()) { |
163 DrawCallback callback = draw_callback_; | 165 DrawCallback callback = draw_callback_; |
164 draw_callback_ = DrawCallback(); | 166 draw_callback_ = DrawCallback(); |
165 callback.Run(drawn); | 167 callback.Run(drawn); |
166 } | 168 } |
167 } | 169 } |
168 | 170 |
(...skipping 17 matching lines...) Expand all Loading... |
186 void Surface::UnrefFrameResources(DelegatedFrameData* frame_data) { | 188 void Surface::UnrefFrameResources(DelegatedFrameData* frame_data) { |
187 ReturnedResourceArray resources; | 189 ReturnedResourceArray resources; |
188 TransferableResource::ReturnResources(frame_data->resource_list, &resources); | 190 TransferableResource::ReturnResources(frame_data->resource_list, &resources); |
189 // No point in returning same sync token to sender. | 191 // No point in returning same sync token to sender. |
190 for (auto& resource : resources) | 192 for (auto& resource : resources) |
191 resource.sync_token.Clear(); | 193 resource.sync_token.Clear(); |
192 factory_->UnrefResources(resources); | 194 factory_->UnrefResources(resources); |
193 } | 195 } |
194 | 196 |
195 void Surface::ClearCopyRequests() { | 197 void Surface::ClearCopyRequests() { |
196 if (current_frame_.delegated_frame_data) { | 198 if (current_frame_) { |
197 for (const auto& render_pass : | 199 for (const auto& render_pass : |
198 current_frame_.delegated_frame_data->render_pass_list) { | 200 current_frame_->delegated_frame_data->render_pass_list) { |
199 for (const auto& copy_request : render_pass->copy_requests) | 201 for (const auto& copy_request : render_pass->copy_requests) |
200 copy_request->SendEmptyResult(); | 202 copy_request->SendEmptyResult(); |
201 } | 203 } |
202 } | 204 } |
203 } | 205 } |
204 | 206 |
205 } // namespace cc | 207 } // namespace cc |
OLD | NEW |