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

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

Issue 2940183002: cc: Move ownership of surfaces to SurfaceManager (Closed)
Patch Set: Fix test Created 3 years, 6 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"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 BeginFrameSource* begin_frame_source) { 70 BeginFrameSource* begin_frame_source) {
71 if (begin_frame_source_ && added_frame_observer_) { 71 if (begin_frame_source_ && added_frame_observer_) {
72 begin_frame_source_->RemoveObserver(this); 72 begin_frame_source_->RemoveObserver(this);
73 added_frame_observer_ = false; 73 added_frame_observer_ = false;
74 } 74 }
75 begin_frame_source_ = begin_frame_source; 75 begin_frame_source_ = begin_frame_source;
76 UpdateNeedsBeginFramesInternal(); 76 UpdateNeedsBeginFramesInternal();
77 } 77 }
78 78
79 void CompositorFrameSinkSupport::EvictCurrentSurface() { 79 void CompositorFrameSinkSupport::EvictCurrentSurface() {
80 if (!current_surface_) 80 if (!GetCurrentSurface())
Fady Samuel 2017/06/20 17:29:06 This is less efficient than it needs to be. Surfa
Saman Sami 2017/06/20 22:47:10 Done.
81 return; 81 return;
82 DestroyCurrentSurface(); 82 surface_manager_->DestroySurface(GetCurrentSurfaceId());
83 } 83 }
84 84
85 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 85 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
86 needs_begin_frame_ = needs_begin_frame; 86 needs_begin_frame_ = needs_begin_frame;
87 UpdateNeedsBeginFramesInternal(); 87 UpdateNeedsBeginFramesInternal();
88 } 88 }
89 89
90 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { 90 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) {
91 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", 91 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame",
92 "ack.source_id", ack.source_id, "ack.sequence_number", 92 "ack.source_id", ack.source_id, "ack.sequence_number",
93 ack.sequence_number); 93 ack.sequence_number);
94 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); 94 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber);
95 95
96 // |has_damage| is not transmitted, but false by default. 96 // |has_damage| is not transmitted, but false by default.
97 DCHECK(!ack.has_damage); 97 DCHECK(!ack.has_damage);
98 98
99 if (current_surface_) 99 if (GetCurrentSurface())
Fady Samuel 2017/06/20 17:29:06 Surface* current_surface = GetCurrentSurface(); if
Saman Sami 2017/06/20 22:47:10 Done.
100 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); 100 surface_manager_->SurfaceModified(GetCurrentSurfaceId(), ack);
101 if (begin_frame_source_) 101 if (begin_frame_source_)
102 begin_frame_source_->DidFinishFrame(this); 102 begin_frame_source_->DidFinishFrame(this);
103 } 103 }
104 104
105 bool CompositorFrameSinkSupport::SubmitCompositorFrame( 105 bool CompositorFrameSinkSupport::SubmitCompositorFrame(
106 const LocalSurfaceId& local_surface_id, 106 const LocalSurfaceId& local_surface_id,
107 CompositorFrame frame) { 107 CompositorFrame frame) {
108 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); 108 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame");
109 DCHECK(local_surface_id.is_valid()); 109 DCHECK(local_surface_id.is_valid());
110 DCHECK(!frame.render_pass_list.empty()); 110 DCHECK(!frame.render_pass_list.empty());
111 111
112 ++ack_pending_count_; 112 ++ack_pending_count_;
113 113
114 // |has_damage| is not transmitted. 114 // |has_damage| is not transmitted.
115 frame.metadata.begin_frame_ack.has_damage = true; 115 frame.metadata.begin_frame_ack.has_damage = true;
116 BeginFrameAck ack = frame.metadata.begin_frame_ack; 116 BeginFrameAck ack = frame.metadata.begin_frame_ack;
117 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); 117 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, ack.sequence_number);
118 118
119 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info, 119 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info,
120 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { 120 "RenderWidgetHostImpl::OnSwapCompositorFrame")) {
121 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); 121 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info);
122 } 122 }
123 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { 123 for (ui::LatencyInfo& latency : frame.metadata.latency_info) {
124 if (latency.latency_components().size() > 0) { 124 if (latency.latency_components().size() > 0) {
125 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, 125 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT,
126 0, 0); 126 0, 0);
127 } 127 }
128 } 128 }
129 129
130 std::unique_ptr<Surface> surface; 130 Surface* current_surface = GetCurrentSurface();
131 bool create_new_surface = 131 Surface* prev_surface = current_surface;
132 (!current_surface_ || 132 if (!current_surface ||
133 local_surface_id != current_surface_->surface_id().local_surface_id()); 133 surface_manager()->IsMarkedForDestruction(GetCurrentSurfaceId()) ||
Fady Samuel 2017/06/20 17:29:06 replace GetCurrentSurface() => current_surface->su
Saman Sami 2017/06/20 22:47:10 Done.
134 if (!create_new_surface) { 134 local_surface_id != current_local_surface_id_) {
135 surface = std::move(current_surface_);
136 } else {
137 SurfaceId surface_id(frame_sink_id_, local_surface_id); 135 SurfaceId surface_id(frame_sink_id_, local_surface_id);
138 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
139 float device_scale_factor = frame.metadata.device_scale_factor; 137 float device_scale_factor = frame.metadata.device_scale_factor;
140 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); 138 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size);
141 139
142 if (!surface_info.is_valid()) { 140 if (!surface_info.is_valid()) {
143 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", 141 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo",
144 TRACE_EVENT_SCOPE_THREAD); 142 TRACE_EVENT_SCOPE_THREAD);
145 if (current_surface_) 143 if (current_surface)
146 DestroyCurrentSurface(); 144 EvictCurrentSurface();
147 ReturnedResourceArray resources; 145 ReturnedResourceArray resources;
148 TransferableResource::ReturnResources(frame.resource_list, &resources); 146 TransferableResource::ReturnResources(frame.resource_list, &resources);
149 ReturnResources(resources); 147 ReturnResources(resources);
150 DidReceiveCompositorFrameAck(); 148 DidReceiveCompositorFrameAck();
151 return true; 149 return true;
152 } 150 }
153 151
154 surface = CreateSurface(surface_info); 152 current_surface = CreateSurface(surface_info);
153 current_local_surface_id_ = local_surface_id;
155 } 154 }
156 155
157 bool result = surface->QueueFrame( 156 bool result = current_surface->QueueFrame(
158 std::move(frame), 157 std::move(frame),
159 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 158 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
160 weak_factory_.GetWeakPtr()), 159 weak_factory_.GetWeakPtr()),
161 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, 160 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface,
162 weak_factory_.GetWeakPtr())); 161 weak_factory_.GetWeakPtr()));
163 162
164 if (!result) { 163 if (!result) {
165 surface_manager_->DestroySurface(std::move(surface)); 164 EvictCurrentSurface();
166 return false; 165 return false;
167 } 166 }
168 167
169 if (current_surface_) { 168 if (prev_surface && prev_surface != current_surface) {
170 surface->SetPreviousFrameSurface(current_surface_.get()); 169 current_surface->SetPreviousFrameSurface(prev_surface);
171 DestroyCurrentSurface(); 170 surface_manager_->DestroySurface(prev_surface->surface_id());
172 } 171 }
173 current_surface_ = std::move(surface);
174 172
175 if (begin_frame_source_) 173 if (begin_frame_source_)
176 begin_frame_source_->DidFinishFrame(this); 174 begin_frame_source_->DidFinishFrame(this);
177 175
178 return true; 176 return true;
179 } 177 }
180 178
181 void CompositorFrameSinkSupport::UpdateSurfaceReferences( 179 void CompositorFrameSinkSupport::UpdateSurfaceReferences(
182 const LocalSurfaceId& local_surface_id, 180 const LocalSurfaceId& local_surface_id,
183 const std::vector<SurfaceId>& active_referenced_surfaces) { 181 const std::vector<SurfaceId>& active_referenced_surfaces) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 277
280 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { 278 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) {
281 surface_manager_ = surface_manager; 279 surface_manager_ = surface_manager;
282 if (handles_frame_sink_id_invalidation_) 280 if (handles_frame_sink_id_invalidation_)
283 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 281 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
284 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); 282 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this);
285 } 283 }
286 284
287 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { 285 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
288 UpdateNeedsBeginFramesInternal(); 286 UpdateNeedsBeginFramesInternal();
289 if (current_surface_) { 287 if (GetCurrentSurface()) {
Fady Samuel 2017/06/20 17:29:06 Drop the braces: Surface* current_surface = GetCu
Saman Sami 2017/06/20 22:47:10 Done.
290 surface_manager_->SurfaceDamageExpected(current_surface_->surface_id(), 288 surface_manager_->SurfaceDamageExpected(GetCurrentSurfaceId(), args);
291 args);
292 } 289 }
293 last_begin_frame_args_ = args; 290 last_begin_frame_args_ = args;
294 if (client_) 291 if (client_)
295 client_->OnBeginFrame(args); 292 client_->OnBeginFrame(args);
296 } 293 }
297 294
298 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() 295 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs()
299 const { 296 const {
300 return last_begin_frame_args_; 297 return last_begin_frame_args_;
301 } 298 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (needs_begin_frame_ == added_frame_observer_) 330 if (needs_begin_frame_ == added_frame_observer_)
334 return; 331 return;
335 332
336 added_frame_observer_ = needs_begin_frame_; 333 added_frame_observer_ = needs_begin_frame_;
337 if (needs_begin_frame_) 334 if (needs_begin_frame_)
338 begin_frame_source_->AddObserver(this); 335 begin_frame_source_->AddObserver(this);
339 else 336 else
340 begin_frame_source_->RemoveObserver(this); 337 begin_frame_source_->RemoveObserver(this);
341 } 338 }
342 339
343 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( 340 Surface* CompositorFrameSinkSupport::CreateSurface(
344 const SurfaceInfo& surface_info) { 341 const SurfaceInfo& surface_info) {
345 seen_first_frame_activation_ = false; 342 seen_first_frame_activation_ = false;
346 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), 343 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(),
347 surface_info); 344 surface_info);
348 } 345 }
349 346
350 void CompositorFrameSinkSupport::DestroyCurrentSurface() { 347 void CompositorFrameSinkSupport::RequestCopyOfSurface(
351 surface_manager_->DestroySurface(std::move(current_surface_)); 348 std::unique_ptr<CopyOutputRequest> copy_request) {
349 Surface* current_surface = GetCurrentSurface();
350 if (!current_surface)
351 return;
352 DCHECK(current_surface->compositor_frame_sink_support().get() == this);
353 current_surface->RequestCopyOfOutput(std::move(copy_request));
354 BeginFrameAck ack;
355 ack.has_damage = true;
356 if (current_surface->HasActiveFrame())
357 surface_manager_->SurfaceModified(current_surface->surface_id(), ack);
352 } 358 }
353 359
354 void CompositorFrameSinkSupport::RequestCopyOfSurface( 360 Surface* CompositorFrameSinkSupport::GetCurrentSurface() {
355 std::unique_ptr<CopyOutputRequest> copy_request) { 361 return surface_manager_->GetSurfaceForId(GetCurrentSurfaceId());
356 if (!current_surface_) 362 }
357 return;
358 363
359 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); 364 SurfaceId CompositorFrameSinkSupport::GetCurrentSurfaceId() {
Fady Samuel 2017/06/20 17:29:06 Maybe we don't need this?
Saman Sami 2017/06/20 22:47:10 Done.
360 current_surface_->RequestCopyOfOutput(std::move(copy_request)); 365 return SurfaceId(frame_sink_id_, current_local_surface_id_);
361 BeginFrameAck ack;
362 ack.has_damage = true;
363 if (current_surface_->HasActiveFrame())
364 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack);
365 } 366 }
366 367
367 } // namespace cc 368 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698