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

Side by Side Diff: cc/surfaces/compositor_frame_sink_support.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/compositor_frame_sink_support.h" 5 #include "cc/surfaces/compositor_frame_sink_support.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/scheduler/begin_frame_source.h" 11 #include "cc/scheduler/begin_frame_source.h"
12 #include "cc/surfaces/compositor_frame_sink_support_client.h" 12 #include "cc/surfaces/compositor_frame_sink_support_client.h"
13 #include "cc/surfaces/display.h" 13 #include "cc/surfaces/display.h"
14 #include "cc/surfaces/surface.h" 14 #include "cc/surfaces/surface.h"
15 #include "cc/surfaces/surface_info.h"
15 #include "cc/surfaces/surface_manager.h" 16 #include "cc/surfaces/surface_manager.h"
16 #include "cc/surfaces/surface_reference.h" 17 #include "cc/surfaces/surface_reference.h"
17 18
18 namespace cc { 19 namespace cc {
19 20
20 // static 21 // static
21 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create( 22 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create(
22 CompositorFrameSinkSupportClient* client, 23 CompositorFrameSinkSupportClient* client,
23 SurfaceManager* surface_manager, 24 SurfaceManager* surface_manager,
24 const FrameSinkId& frame_sink_id, 25 const FrameSinkId& frame_sink_id,
(...skipping 11 matching lines...) Expand all
36 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does 37 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does
37 // not call into |this| after it's deleted. 38 // not call into |this| after it's deleted.
38 SetNeedsBeginFrame(false); 39 SetNeedsBeginFrame(false);
39 40
40 // For display root surfaces, the surface is no longer going to be visible 41 // For display root surfaces, the surface is no longer going to be visible
41 // so make it unreachable from the top-level root. 42 // so make it unreachable from the top-level root.
42 if (surface_manager_->using_surface_references() && is_root_ && 43 if (surface_manager_->using_surface_references() && is_root_ &&
43 reference_tracker_.current_surface_id().is_valid()) 44 reference_tracker_.current_surface_id().is_valid())
44 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); 45 RemoveTopLevelRootReference(reference_tracker_.current_surface_id());
45 46
46 // SurfaceFactory's destructor will attempt to return resources which will 47 EvictFrame();
47 // call back into here and access |client_| so we should destroy
48 // |surface_factory_|'s resources early on.
49 surface_factory_->EvictSurface();
50 surface_manager_->UnregisterFrameSinkManagerClient(frame_sink_id_); 48 surface_manager_->UnregisterFrameSinkManagerClient(frame_sink_id_);
51 if (handles_frame_sink_id_invalidation_) 49 if (handles_frame_sink_id_invalidation_)
52 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); 50 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
53 } 51 }
54 52
55 void CompositorFrameSinkSupport::ReferencedSurfacesChanged(
56 const LocalSurfaceId& local_surface_id,
57 const std::vector<SurfaceId>* active_referenced_surfaces) {
58 if (!surface_manager_->using_surface_references())
59 return;
60
61 SurfaceId last_surface_id = reference_tracker_.current_surface_id();
62
63 // Populate list of surface references to add and remove based on reference
64 // surfaces in current frame compared with the last frame. The list of
65 // surface references includes references from both the pending and active
66 // frame if any.
67 reference_tracker_.UpdateReferences(local_surface_id,
68 active_referenced_surfaces);
69
70 UpdateSurfaceReferences(last_surface_id, local_surface_id);
71 }
72
73 void CompositorFrameSinkSupport::ReturnResources( 53 void CompositorFrameSinkSupport::ReturnResources(
74 const ReturnedResourceArray& resources) { 54 const ReturnedResourceArray& resources) {
75 if (resources.empty()) 55 if (resources.empty())
76 return; 56 return;
77 if (!ack_pending_count_ && client_) { 57 if (!ack_pending_count_ && client_) {
78 client_->ReclaimResources(resources); 58 client_->ReclaimResources(resources);
79 return; 59 return;
80 } 60 }
81 61
82 std::copy(resources.begin(), resources.end(), 62 std::copy(resources.begin(), resources.end(),
83 std::back_inserter(surface_returned_resources_)); 63 std::back_inserter(surface_returned_resources_));
84 } 64 }
85 65
86 void CompositorFrameSinkSupport::SetBeginFrameSource( 66 void CompositorFrameSinkSupport::SetBeginFrameSource(
87 BeginFrameSource* begin_frame_source) { 67 BeginFrameSource* begin_frame_source) {
88 if (begin_frame_source_ && added_frame_observer_) { 68 if (begin_frame_source_ && added_frame_observer_) {
89 begin_frame_source_->RemoveObserver(this); 69 begin_frame_source_->RemoveObserver(this);
90 added_frame_observer_ = false; 70 added_frame_observer_ = false;
91 } 71 }
92 begin_frame_source_ = begin_frame_source; 72 begin_frame_source_ = begin_frame_source;
93 UpdateNeedsBeginFramesInternal(); 73 UpdateNeedsBeginFramesInternal();
94 } 74 }
95 75
96 void CompositorFrameSinkSupport::EvictFrame() { 76 void CompositorFrameSinkSupport::EvictFrame() {
97 DCHECK(surface_factory_); 77 if (!current_surface_)
98 surface_factory_->EvictSurface(); 78 return;
79 DestroyCurrentSurface();
99 } 80 }
100 81
101 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 82 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
102 needs_begin_frame_ = needs_begin_frame; 83 needs_begin_frame_ = needs_begin_frame;
103 UpdateNeedsBeginFramesInternal(); 84 UpdateNeedsBeginFramesInternal();
104 } 85 }
105 86
106 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( 87 void CompositorFrameSinkSupport::BeginFrameDidNotSwap(
107 const BeginFrameAck& ack) { 88 const BeginFrameAck& ack) {
108 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we 89 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we
109 // should not acknowledge immediately. Instead, we should update the ack that 90 // should not acknowledge immediately. Instead, we should update the ack that
110 // will be sent to DisplayScheduler when the pending frame is activated. 91 // will be sent to DisplayScheduler when the pending frame is activated.
111 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); 92 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber);
112 93
113 // |has_damage| is not transmitted, but false by default. 94 // |has_damage| is not transmitted, but false by default.
114 DCHECK(!ack.has_damage); 95 DCHECK(!ack.has_damage);
115 if (begin_frame_source_) 96 if (begin_frame_source_)
116 begin_frame_source_->DidFinishFrame(this, ack); 97 begin_frame_source_->DidFinishFrame(this, ack);
117 } 98 }
118 99
119 void CompositorFrameSinkSupport::SubmitCompositorFrame( 100 void CompositorFrameSinkSupport::SubmitCompositorFrame(
120 const LocalSurfaceId& local_surface_id, 101 const LocalSurfaceId& local_surface_id,
121 CompositorFrame frame) { 102 CompositorFrame frame) {
122 DCHECK(surface_factory_); 103 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame");
104 DCHECK(local_surface_id.is_valid());
123 ++ack_pending_count_; 105 ++ack_pending_count_;
124 106
125 DCHECK_GE(frame.metadata.begin_frame_ack.sequence_number, 107 DCHECK_GE(frame.metadata.begin_frame_ack.sequence_number,
126 BeginFrameArgs::kStartingFrameNumber); 108 BeginFrameArgs::kStartingFrameNumber);
127 109
128 // |has_damage| is not transmitted. 110 // |has_damage| is not transmitted.
129 frame.metadata.begin_frame_ack.has_damage = true; 111 frame.metadata.begin_frame_ack.has_damage = true;
130 112
131 BeginFrameAck ack = frame.metadata.begin_frame_ack; 113 BeginFrameAck ack = frame.metadata.begin_frame_ack;
132 surface_factory_->SubmitCompositorFrame( 114 for (ui::LatencyInfo& latency : frame.metadata.latency_info) {
133 local_surface_id, std::move(frame), 115 if (latency.latency_components().size() > 0) {
116 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT,
117 0, 0);
118 }
119 }
120
121 std::unique_ptr<Surface> surface;
122 bool create_new_surface =
123 (!current_surface_ ||
124 local_surface_id != current_surface_->surface_id().local_surface_id());
125 if (!create_new_surface) {
126 surface = std::move(current_surface_);
127 } else {
128 surface = CreateSurface(local_surface_id);
129 }
130 surface->QueueFrame(
131 std::move(frame),
134 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 132 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
135 weak_factory_.GetWeakPtr()), 133 weak_factory_.GetWeakPtr()),
136 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, 134 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface,
137 weak_factory_.GetWeakPtr())); 135 weak_factory_.GetWeakPtr()));
138 136
137 if (current_surface_ && create_new_surface) {
138 surface->SetPreviousFrameSurface(current_surface_.get());
139 DestroyCurrentSurface();
140 }
141 current_surface_ = std::move(surface);
142
139 // TODO(eseckler): The CompositorFrame submitted below might not be activated 143 // TODO(eseckler): The CompositorFrame submitted below might not be activated
140 // right away b/c of surface synchronization. We should only send the 144 // right away b/c of surface synchronization. We should only send the
141 // BeginFrameAck to DisplayScheduler when it is activated. This also means 145 // BeginFrameAck to DisplayScheduler when it is activated. This also means
142 // that we need to stay an active BFO while a CompositorFrame is pending. 146 // that we need to stay an active BFO while a CompositorFrame is pending.
143 // See https://crbug.com/703079. 147 // See https://crbug.com/703079.
144 if (begin_frame_source_) 148 if (begin_frame_source_)
145 begin_frame_source_->DidFinishFrame(this, ack); 149 begin_frame_source_->DidFinishFrame(this, ack);
146 } 150 }
147 151
148 void CompositorFrameSinkSupport::UpdateSurfaceReferences( 152 void CompositorFrameSinkSupport::UpdateSurfaceReferences(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id); 187 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
184 surface_manager_->AddSurfaceReferences({reference}); 188 surface_manager_->AddSurfaceReferences({reference});
185 } 189 }
186 190
187 void CompositorFrameSinkSupport::RemoveTopLevelRootReference( 191 void CompositorFrameSinkSupport::RemoveTopLevelRootReference(
188 const SurfaceId& surface_id) { 192 const SurfaceId& surface_id) {
189 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id); 193 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
190 surface_manager_->RemoveSurfaceReferences({reference}); 194 surface_manager_->RemoveSurfaceReferences({reference});
191 } 195 }
192 196
197 void CompositorFrameSinkSupport::ReferencedSurfacesChanged(
198 const LocalSurfaceId& local_surface_id,
199 const std::vector<SurfaceId>* active_referenced_surfaces) {
200 if (!surface_manager_->using_surface_references())
201 return;
202
203 SurfaceId last_surface_id = reference_tracker_.current_surface_id();
204
205 // Populate list of surface references to add and remove based on reference
206 // surfaces in current frame compared with the last frame. The list of
207 // surface references includes references from both the pending and active
208 // frame if any.
209 reference_tracker_.UpdateReferences(local_surface_id,
210 active_referenced_surfaces);
211
212 UpdateSurfaceReferences(last_surface_id, local_surface_id);
213 }
214
193 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { 215 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() {
194 DCHECK_GT(ack_pending_count_, 0); 216 DCHECK_GT(ack_pending_count_, 0);
195 ack_pending_count_--; 217 ack_pending_count_--;
196 if (!client_) 218 if (!client_)
197 return; 219 return;
220
198 client_->DidReceiveCompositorFrameAck(surface_returned_resources_); 221 client_->DidReceiveCompositorFrameAck(surface_returned_resources_);
199 surface_returned_resources_.clear(); 222 surface_returned_resources_.clear();
200 } 223 }
201 224
202 void CompositorFrameSinkSupport::WillDrawSurface( 225 void CompositorFrameSinkSupport::WillDrawSurface(
203 const LocalSurfaceId& local_surface_id, 226 const LocalSurfaceId& local_surface_id,
204 const gfx::Rect& damage_rect) { 227 const gfx::Rect& damage_rect) {
205 if (client_) 228 if (client_)
206 client_->WillDrawSurface(local_surface_id, damage_rect); 229 client_->WillDrawSurface(local_surface_id, damage_rect);
207 } 230 }
208 231
209 void CompositorFrameSinkSupport::ClaimTemporaryReference( 232 void CompositorFrameSinkSupport::ClaimTemporaryReference(
210 const SurfaceId& surface_id) { 233 const SurfaceId& surface_id) {
211 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); 234 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_);
212 } 235 }
213 236
237 void CompositorFrameSinkSupport::ReceiveFromChild(
238 const TransferableResourceArray& resources) {
239 surface_resource_holder_.ReceiveFromChild(resources);
240 }
241
242 void CompositorFrameSinkSupport::RefResources(
243 const TransferableResourceArray& resources) {
244 surface_resource_holder_.RefResources(resources);
245 }
246
247 void CompositorFrameSinkSupport::UnrefResources(
248 const ReturnedResourceArray& resources) {
249 surface_resource_holder_.UnrefResources(resources);
250 }
251
214 CompositorFrameSinkSupport::CompositorFrameSinkSupport( 252 CompositorFrameSinkSupport::CompositorFrameSinkSupport(
215 CompositorFrameSinkSupportClient* client, 253 CompositorFrameSinkSupportClient* client,
216 const FrameSinkId& frame_sink_id, 254 const FrameSinkId& frame_sink_id,
217 bool is_root, 255 bool is_root,
218 bool handles_frame_sink_id_invalidation) 256 bool handles_frame_sink_id_invalidation)
219 : client_(client), 257 : client_(client),
220 frame_sink_id_(frame_sink_id), 258 frame_sink_id_(frame_sink_id),
259 surface_resource_holder_(this),
221 reference_tracker_(frame_sink_id), 260 reference_tracker_(frame_sink_id),
222 is_root_(is_root), 261 is_root_(is_root),
223 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), 262 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation),
224 weak_factory_(this) {} 263 weak_factory_(this) {}
225 264
226 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager, 265 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager,
227 bool needs_sync_points) { 266 bool needs_sync_points) {
228 surface_manager_ = surface_manager; 267 surface_manager_ = surface_manager;
229 surface_factory_ = base::MakeUnique<SurfaceFactory>(
230 frame_sink_id_, surface_manager_, this, this);
231 if (handles_frame_sink_id_invalidation_) 268 if (handles_frame_sink_id_invalidation_)
232 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 269 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
233 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); 270 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this);
234 surface_factory_->set_needs_sync_points(needs_sync_points); 271 needs_sync_points_ = needs_sync_points;
235 } 272 }
236 273
237 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { 274 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
238 UpdateNeedsBeginFramesInternal(); 275 UpdateNeedsBeginFramesInternal();
239 last_begin_frame_args_ = args; 276 last_begin_frame_args_ = args;
240 if (client_) 277 if (client_)
241 client_->OnBeginFrame(args); 278 client_->OnBeginFrame(args);
242 } 279 }
243 280
244 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() 281 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs()
245 const { 282 const {
246 return last_begin_frame_args_; 283 return last_begin_frame_args_;
247 } 284 }
248 285
249 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} 286 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {}
250 287
288 void CompositorFrameSinkSupport::OnSurfaceActivated(Surface* surface) {
289 DCHECK(surface->HasActiveFrame());
290 // TODO(staraz): Notify BeginFrameSource about the last activated sequence
291 // number.
292 if (!seen_first_frame_activation_) {
293 seen_first_frame_activation_ = true;
294
295 const CompositorFrame& frame = surface->GetActiveFrame();
296 // CompositorFrames might not be populated with a RenderPass in unit tests.
297 gfx::Size frame_size;
298 if (!frame.render_pass_list.empty())
299 frame_size = frame.render_pass_list.back()->output_rect.size();
300
301 // SurfaceCreated only applies for the first Surface activation. Thus,
302 // SurfaceFactory stops observing new activations after the first one.
303 surface_manager_->SurfaceCreated(SurfaceInfo(
304 surface->surface_id(), frame.metadata.device_scale_factor, frame_size));
305 }
306 // Fire SurfaceCreated first so that a temporary reference is added before it
307 // is potentially transformed into a real reference by the client.
308 ReferencedSurfacesChanged(surface->surface_id().local_surface_id(),
309 surface->active_referenced_surfaces());
310 if (!surface_manager_->SurfaceModified(surface->surface_id())) {
311 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
312 surface->RunDrawCallback();
313 }
314 }
315
316 void CompositorFrameSinkSupport::OnSurfaceDependenciesChanged(
317 Surface* surface,
318 const SurfaceDependencies& added_dependencies,
319 const SurfaceDependencies& removed_dependencies) {}
320
321 void CompositorFrameSinkSupport::OnSurfaceDiscarded(Surface* surface) {}
322
251 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { 323 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() {
252 if (!begin_frame_source_) 324 if (!begin_frame_source_)
253 return; 325 return;
254 326
255 if (needs_begin_frame_ == added_frame_observer_) 327 if (needs_begin_frame_ == added_frame_observer_)
256 return; 328 return;
257 329
258 added_frame_observer_ = needs_begin_frame_; 330 added_frame_observer_ = needs_begin_frame_;
259 if (needs_begin_frame_) 331 if (needs_begin_frame_)
260 begin_frame_source_->AddObserver(this); 332 begin_frame_source_->AddObserver(this);
261 else 333 else
262 begin_frame_source_->RemoveObserver(this); 334 begin_frame_source_->RemoveObserver(this);
263 } 335 }
264 336
337 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface(
338 const LocalSurfaceId& local_surface_id) {
339 seen_first_frame_activation_ = false;
340 std::unique_ptr<Surface> surface = surface_manager_->CreateSurface(
341 weak_factory_.GetWeakPtr(), local_surface_id);
342 surface->AddObserver(this);
343 return surface;
344 }
345
346 void CompositorFrameSinkSupport::DestroyCurrentSurface() {
347 current_surface_->RemoveObserver(this);
348 surface_manager_->DestroySurface(std::move(current_surface_));
349 }
350
265 void CompositorFrameSinkSupport::RequestCopyOfSurface( 351 void CompositorFrameSinkSupport::RequestCopyOfSurface(
266 std::unique_ptr<CopyOutputRequest> request) { 352 std::unique_ptr<CopyOutputRequest> copy_request) {
267 DCHECK(surface_factory_); 353 if (!current_surface_) {
268 surface_factory_->RequestCopyOfSurface(std::move(request)); 354 copy_request->SendEmptyResult();
danakj 2017/04/28 17:44:23 The destructor already does this https://cs.chromi
Alex Z. 2017/05/01 14:48:34 Done.
355 return;
356 }
357 DCHECK(current_surface_->compositor_frame_sink_support().get() == this);
358 current_surface_->RequestCopyOfOutput(std::move(copy_request));
359 surface_manager_->SurfaceModified(current_surface_->surface_id());
269 } 360 }
270 361
271 } // namespace cc 362 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698