Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: cc/surfaces/surface.cc

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Use range in for loop Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 for (auto& observer : observers_) 37 for (auto& observer : observers_)
36 observer.OnSurfaceDiscarded(this); 38 observer.OnSurfaceDiscarded(this);
37 observers_.Clear(); 39 observers_.Clear();
38 40
39 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_)); 41 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_));
(...skipping 16 matching lines...) Expand all
56 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 58 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
57 59
58 base::Optional<FrameData> previous_pending_frame_data = 60 base::Optional<FrameData> previous_pending_frame_data =
59 std::move(pending_frame_data_); 61 std::move(pending_frame_data_);
60 pending_frame_data_.reset(); 62 pending_frame_data_.reset();
61 63
62 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); 64 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame);
63 65
64 // Receive and track the resources referenced from the CompositorFrame 66 // Receive and track the resources referenced from the CompositorFrame
65 // regardless of whether it's pending or active. 67 // regardless of whether it's pending or active.
66 factory_->ReceiveFromChild(frame.resource_list); 68 compositor_frame_sink_support_->ReceiveFromChild(frame.resource_list);
67 69
68 bool is_pending_frame = !blocking_surfaces_.empty(); 70 bool is_pending_frame = !blocking_surfaces_.empty();
69 71
70 if (is_pending_frame) { 72 if (is_pending_frame) {
71 pending_frame_data_ = 73 pending_frame_data_ =
72 FrameData(std::move(frame), callback, will_draw_callback); 74 FrameData(std::move(frame), callback, will_draw_callback);
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 } else { 79 } else {
77 // If there are no blockers, then immediately activate the frame. 80 // If there are no blockers, then immediately activate the frame.
78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); 81 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback));
79 } 82 }
80 83
81 // Returns resources for the previous pending frame. 84 // Returns resources for the previous pending frame.
82 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); 85 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data));
83 } 86 }
84 87
85 void Surface::RequestCopyOfOutput( 88 void Surface::RequestCopyOfOutput(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void Surface::ActivatePendingFrame() { 159 void Surface::ActivatePendingFrame() {
157 DCHECK(pending_frame_data_); 160 DCHECK(pending_frame_data_);
158 ActivateFrame(std::move(*pending_frame_data_)); 161 ActivateFrame(std::move(*pending_frame_data_));
159 pending_frame_data_.reset(); 162 pending_frame_data_.reset();
160 } 163 }
161 164
162 // A frame is activated if all its Surface ID dependences are active or a 165 // A frame is activated if all its Surface ID dependences are active or a
163 // deadline has hit and the frame was forcibly activated by the display 166 // deadline has hit and the frame was forcibly activated by the display
164 // compositor. 167 // compositor.
165 void Surface::ActivateFrame(FrameData frame_data) { 168 void Surface::ActivateFrame(FrameData frame_data) {
166 DCHECK(factory_); 169 DCHECK(compositor_frame_sink_support_);
167 170
168 // Save root pass copy requests. 171 // Save root pass copy requests.
169 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests; 172 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests;
170 if (active_frame_data_ && 173 if (active_frame_data_ &&
171 !active_frame_data_->frame.render_pass_list.empty()) { 174 !active_frame_data_->frame.render_pass_list.empty()) {
172 std::swap(old_copy_requests, 175 std::swap(old_copy_requests,
173 active_frame_data_->frame.render_pass_list.back()->copy_requests); 176 active_frame_data_->frame.render_pass_list.back()->copy_requests);
174 } 177 }
175 178
176 ClearCopyRequests(); 179 ClearCopyRequests();
(...skipping 17 matching lines...) Expand all
194 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_frame_data)); 197 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_frame_data));
195 198
196 for (auto& observer : observers_) 199 for (auto& observer : observers_)
197 observer.OnSurfaceActivated(this); 200 observer.OnSurfaceActivated(this);
198 } 201 }
199 202
200 void Surface::UpdateBlockingSurfaces(bool has_previous_pending_frame, 203 void Surface::UpdateBlockingSurfaces(bool has_previous_pending_frame,
201 const CompositorFrame& current_frame) { 204 const CompositorFrame& current_frame) {
202 // If there is no SurfaceDependencyTracker installed then the |current_frame| 205 // If there is no SurfaceDependencyTracker installed then the |current_frame|
203 // does not block on anything. 206 // does not block on anything.
204 if (!factory_->manager()->dependency_tracker()) { 207 if (!compositor_frame_sink_support_->surface_manager()
208 ->dependency_tracker()) {
205 blocking_surfaces_.clear(); 209 blocking_surfaces_.clear();
206 return; 210 return;
207 } 211 }
208 212
209 base::flat_set<SurfaceId> new_blocking_surfaces; 213 base::flat_set<SurfaceId> new_blocking_surfaces;
210 214
211 for (const SurfaceId& surface_id : current_frame.metadata.embedded_surfaces) { 215 for (const SurfaceId& surface_id : current_frame.metadata.embedded_surfaces) {
212 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id); 216 Surface* surface =
217 compositor_frame_sink_support_->surface_manager()->GetSurfaceForId(
218 surface_id);
213 // If a referenced surface does not have a corresponding active frame in the 219 // If a referenced surface does not have a corresponding active frame in the
214 // display compositor, then it blocks this frame. 220 // display compositor, then it blocks this frame.
215 if (!surface || !surface->HasActiveFrame()) 221 if (!surface || !surface->HasActiveFrame())
216 new_blocking_surfaces.insert(surface_id); 222 new_blocking_surfaces.insert(surface_id);
217 } 223 }
218 224
219 // If this Surface has a previous pending frame, then we must determine the 225 // If this Surface has a previous pending frame, then we must determine the
220 // changes in dependencies so that we can update the SurfaceDependencyTracker 226 // changes in dependencies so that we can update the SurfaceDependencyTracker
221 // map. 227 // map.
222 if (has_previous_pending_frame) { 228 if (has_previous_pending_frame) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 306 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) {
301 base::EraseIf(destruction_dependencies_, 307 base::EraseIf(destruction_dependencies_,
302 [sequences, valid_frame_sink_ids](SurfaceSequence seq) { 308 [sequences, valid_frame_sink_ids](SurfaceSequence seq) {
303 return (!!sequences->erase(seq) || 309 return (!!sequences->erase(seq) ||
304 !valid_frame_sink_ids->count(seq.frame_sink_id)); 310 !valid_frame_sink_ids->count(seq.frame_sink_id));
305 }); 311 });
306 } 312 }
307 313
308 void Surface::UnrefFrameResourcesAndRunDrawCallback( 314 void Surface::UnrefFrameResourcesAndRunDrawCallback(
309 base::Optional<FrameData> frame_data) { 315 base::Optional<FrameData> frame_data) {
310 if (!frame_data || !factory_) 316 if (!frame_data || !compositor_frame_sink_support_)
311 return; 317 return;
312 318
313 ReturnedResourceArray resources; 319 ReturnedResourceArray resources;
314 TransferableResource::ReturnResources(frame_data->frame.resource_list, 320 TransferableResource::ReturnResources(frame_data->frame.resource_list,
315 &resources); 321 &resources);
316 // No point in returning same sync token to sender. 322 // No point in returning same sync token to sender.
317 for (auto& resource : resources) 323 for (auto& resource : resources)
318 resource.sync_token.Clear(); 324 resource.sync_token.Clear();
319 factory_->UnrefResources(resources); 325 compositor_frame_sink_support_->UnrefResources(resources);
320 326
321 if (!frame_data->draw_callback.is_null()) 327 if (!frame_data->draw_callback.is_null())
322 frame_data->draw_callback.Run(); 328 frame_data->draw_callback.Run();
323 } 329 }
324 330
325 void Surface::ClearCopyRequests() { 331 void Surface::ClearCopyRequests() {
326 if (active_frame_data_) { 332 if (active_frame_data_) {
327 for (const auto& render_pass : active_frame_data_->frame.render_pass_list) { 333 for (const auto& render_pass : active_frame_data_->frame.render_pass_list) {
328 for (const auto& copy_request : render_pass->copy_requests) 334 for (const auto& copy_request : render_pass->copy_requests)
329 copy_request->SendEmptyResult(); 335 copy_request->SendEmptyResult();
(...skipping 16 matching lines...) Expand all
346 frame->metadata.latency_info.swap(*latency_info); 352 frame->metadata.latency_info.swap(*latency_info);
347 return; 353 return;
348 } 354 }
349 std::copy(frame->metadata.latency_info.begin(), 355 std::copy(frame->metadata.latency_info.begin(),
350 frame->metadata.latency_info.end(), 356 frame->metadata.latency_info.end(),
351 std::back_inserter(*latency_info)); 357 std::back_inserter(*latency_info));
352 frame->metadata.latency_info.clear(); 358 frame->metadata.latency_info.clear();
353 } 359 }
354 360
355 } // namespace cc 361 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698