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/compositor_frame_sink_support.h" |
15 #include "cc/surfaces/local_surface_id_allocator.h" | 16 #include "cc/surfaces/local_surface_id_allocator.h" |
16 #include "cc/surfaces/pending_frame_observer.h" | 17 #include "cc/surfaces/pending_frame_observer.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( |
| 27 const SurfaceId& id, |
| 28 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support) |
27 : surface_id_(id), | 29 : surface_id_(id), |
28 previous_frame_surface_id_(id), | 30 previous_frame_surface_id_(id), |
29 factory_(factory), | 31 compositor_frame_sink_support_(compositor_frame_sink_support), |
30 frame_index_(kFrameIndexStart), | 32 frame_index_(kFrameIndexStart), |
31 destroyed_(false) {} | 33 destroyed_(false) {} |
32 | 34 |
33 Surface::~Surface() { | 35 Surface::~Surface() { |
34 ClearCopyRequests(); | 36 ClearCopyRequests(); |
35 if (factory_) { | 37 if (compositor_frame_sink_support_) { |
36 if (pending_frame_) | 38 if (pending_frame_) |
37 UnrefFrameResources(*pending_frame_); | 39 UnrefFrameResources(*pending_frame_); |
38 if (active_frame_) | 40 if (active_frame_) |
39 UnrefFrameResources(*active_frame_); | 41 UnrefFrameResources(*active_frame_); |
40 } | 42 } |
41 if (!draw_callback_.is_null()) | 43 if (!draw_callback_.is_null()) |
42 draw_callback_.Run(); | 44 draw_callback_.Run(); |
43 | 45 |
44 for (auto& observer : observers_) | 46 for (auto& observer : observers_) |
45 observer.OnSurfaceDiscarded(this); | 47 observer.OnSurfaceDiscarded(this); |
(...skipping 13 matching lines...) Expand all Loading... |
59 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 61 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
60 | 62 |
61 base::Optional<CompositorFrame> previous_pending_frame = | 63 base::Optional<CompositorFrame> previous_pending_frame = |
62 std::move(pending_frame_); | 64 std::move(pending_frame_); |
63 pending_frame_.reset(); | 65 pending_frame_.reset(); |
64 | 66 |
65 UpdateBlockingSurfaces(previous_pending_frame, frame); | 67 UpdateBlockingSurfaces(previous_pending_frame, frame); |
66 | 68 |
67 // Receive and track the resources referenced from the CompositorFrame | 69 // Receive and track the resources referenced from the CompositorFrame |
68 // regardless of whether it's pending or active. | 70 // regardless of whether it's pending or active. |
69 factory_->ReceiveFromChild(frame.resource_list); | 71 compositor_frame_sink_support_->ReceiveFromChild(frame.resource_list); |
70 | 72 |
71 if (!blocking_surfaces_.empty()) { | 73 if (!blocking_surfaces_.empty()) { |
72 pending_frame_ = std::move(frame); | 74 pending_frame_ = std::move(frame); |
73 // Ask the surface manager to inform |this| when its dependencies are | 75 // Ask the surface manager to inform |this| when its dependencies are |
74 // resolved. | 76 // resolved. |
75 factory_->manager()->RequestSurfaceResolution(this); | 77 compositor_frame_sink_support_->surface_manager()->RequestSurfaceResolution( |
| 78 this); |
76 | 79 |
77 // We do not have to notify observers that referenced surfaces have changed | 80 // We do not have to notify observers that referenced surfaces have changed |
78 // in the else case because ActivateFrame will notify observers. | 81 // in the else case because ActivateFrame will notify observers. |
79 for (auto& observer : observers_) { | 82 for (auto& observer : observers_) { |
80 observer.OnReferencedSurfacesChanged(this, active_referenced_surfaces(), | 83 observer.OnReferencedSurfacesChanged(this, active_referenced_surfaces(), |
81 pending_referenced_surfaces()); | 84 pending_referenced_surfaces()); |
82 } | 85 } |
83 } else { | 86 } else { |
84 // If there are no blockers, then immediately activate the frame. | 87 // If there are no blockers, then immediately activate the frame. |
85 ActivateFrame(std::move(frame)); | 88 ActivateFrame(std::move(frame)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void Surface::ActivatePendingFrame() { | 162 void Surface::ActivatePendingFrame() { |
160 DCHECK(pending_frame_); | 163 DCHECK(pending_frame_); |
161 ActivateFrame(std::move(pending_frame_.value())); | 164 ActivateFrame(std::move(pending_frame_.value())); |
162 pending_frame_.reset(); | 165 pending_frame_.reset(); |
163 } | 166 } |
164 | 167 |
165 // A frame is activated if all its Surface ID dependences are active or a | 168 // A frame is activated if all its Surface ID dependences are active or a |
166 // deadline has hit and the frame was forcibly activated by the display | 169 // deadline has hit and the frame was forcibly activated by the display |
167 // compositor. | 170 // compositor. |
168 void Surface::ActivateFrame(CompositorFrame frame) { | 171 void Surface::ActivateFrame(CompositorFrame frame) { |
169 DCHECK(factory_); | 172 DCHECK(compositor_frame_sink_support_); |
170 | 173 |
171 // Save root pass copy requests. | 174 // Save root pass copy requests. |
172 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests; | 175 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests; |
173 if (active_frame_ && !active_frame_->render_pass_list.empty()) { | 176 if (active_frame_ && !active_frame_->render_pass_list.empty()) { |
174 std::swap(old_copy_requests, | 177 std::swap(old_copy_requests, |
175 active_frame_->render_pass_list.back()->copy_requests); | 178 active_frame_->render_pass_list.back()->copy_requests); |
176 } | 179 } |
177 | 180 |
178 ClearCopyRequests(); | 181 ClearCopyRequests(); |
179 | 182 |
(...skipping 22 matching lines...) Expand all Loading... |
202 observer.OnReferencedSurfacesChanged(this, active_referenced_surfaces(), | 205 observer.OnReferencedSurfacesChanged(this, active_referenced_surfaces(), |
203 pending_referenced_surfaces()); | 206 pending_referenced_surfaces()); |
204 } | 207 } |
205 } | 208 } |
206 | 209 |
207 void Surface::UpdateBlockingSurfaces( | 210 void Surface::UpdateBlockingSurfaces( |
208 const base::Optional<CompositorFrame>& previous_pending_frame, | 211 const base::Optional<CompositorFrame>& previous_pending_frame, |
209 const CompositorFrame& current_frame) { | 212 const CompositorFrame& current_frame) { |
210 // If there is no SurfaceDependencyTracker installed then the |current_frame| | 213 // If there is no SurfaceDependencyTracker installed then the |current_frame| |
211 // does not block on anything. | 214 // does not block on anything. |
212 if (!factory_->manager()->dependency_tracker()) { | 215 if (!compositor_frame_sink_support_->surface_manager() |
| 216 ->dependency_tracker()) { |
213 blocking_surfaces_.clear(); | 217 blocking_surfaces_.clear(); |
214 return; | 218 return; |
215 } | 219 } |
216 | 220 |
217 base::flat_set<SurfaceId> new_blocking_surfaces; | 221 base::flat_set<SurfaceId> new_blocking_surfaces; |
218 | 222 |
219 for (const SurfaceId& surface_id : | 223 for (const SurfaceId& surface_id : |
220 current_frame.metadata.referenced_surfaces) { | 224 current_frame.metadata.referenced_surfaces) { |
221 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id); | 225 Surface* surface = |
| 226 compositor_frame_sink_support_->surface_manager()->GetSurfaceForId( |
| 227 surface_id); |
222 // If a referenced surface does not have a corresponding active frame in the | 228 // If a referenced surface does not have a corresponding active frame in the |
223 // display compositor, then it blocks this frame. | 229 // display compositor, then it blocks this frame. |
224 if (!surface || !surface->HasActiveFrame()) | 230 if (!surface || !surface->HasActiveFrame()) |
225 new_blocking_surfaces.insert(surface_id); | 231 new_blocking_surfaces.insert(surface_id); |
226 } | 232 } |
227 | 233 |
228 // If this Surface has a previous pending frame, then we must determine the | 234 // If this Surface has a previous pending frame, then we must determine the |
229 // changes in dependencies so that we can update the SurfaceDependencyTracker | 235 // changes in dependencies so that we can update the SurfaceDependencyTracker |
230 // map. | 236 // map. |
231 if (previous_pending_frame.has_value()) { | 237 if (previous_pending_frame.has_value()) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 !valid_frame_sink_ids->count(seq.frame_sink_id)); | 311 !valid_frame_sink_ids->count(seq.frame_sink_id)); |
306 }); | 312 }); |
307 } | 313 } |
308 | 314 |
309 void Surface::UnrefFrameResources(const CompositorFrame& frame) { | 315 void Surface::UnrefFrameResources(const CompositorFrame& frame) { |
310 ReturnedResourceArray resources; | 316 ReturnedResourceArray resources; |
311 TransferableResource::ReturnResources(frame.resource_list, &resources); | 317 TransferableResource::ReturnResources(frame.resource_list, &resources); |
312 // No point in returning same sync token to sender. | 318 // No point in returning same sync token to sender. |
313 for (auto& resource : resources) | 319 for (auto& resource : resources) |
314 resource.sync_token.Clear(); | 320 resource.sync_token.Clear(); |
315 factory_->UnrefResources(resources); | 321 compositor_frame_sink_support_->UnrefResources(resources); |
316 } | 322 } |
317 | 323 |
318 void Surface::ClearCopyRequests() { | 324 void Surface::ClearCopyRequests() { |
319 if (active_frame_) { | 325 if (active_frame_) { |
320 for (const auto& render_pass : active_frame_->render_pass_list) { | 326 for (const auto& render_pass : active_frame_->render_pass_list) { |
321 for (const auto& copy_request : render_pass->copy_requests) | 327 for (const auto& copy_request : render_pass->copy_requests) |
322 copy_request->SendEmptyResult(); | 328 copy_request->SendEmptyResult(); |
323 } | 329 } |
324 } | 330 } |
325 } | 331 } |
(...skipping 13 matching lines...) Expand all Loading... |
339 frame->metadata.latency_info.swap(*latency_info); | 345 frame->metadata.latency_info.swap(*latency_info); |
340 return; | 346 return; |
341 } | 347 } |
342 std::copy(frame->metadata.latency_info.begin(), | 348 std::copy(frame->metadata.latency_info.begin(), |
343 frame->metadata.latency_info.end(), | 349 frame->metadata.latency_info.end(), |
344 std::back_inserter(*latency_info)); | 350 std::back_inserter(*latency_info)); |
345 frame->metadata.latency_info.clear(); | 351 frame->metadata.latency_info.clear(); |
346 } | 352 } |
347 | 353 |
348 } // namespace cc | 354 } // namespace cc |
OLD | NEW |