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

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

Issue 2940183002: cc: Move ownership of surfaces to SurfaceManager (Closed)
Patch Set: c 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 Surface* current_surface = GetCurrentSurface();
danakj 2017/06/21 21:24:09 It feels like in general this class is dealing wit
Saman Sami 2017/06/26 20:44:05 I just keep the current SurfaceId and reset it whe
81 if (!current_surface)
81 return; 82 return;
82 DestroyCurrentSurface(); 83 surface_manager_->DestroySurface(current_surface->surface_id());
danakj 2017/06/21 21:24:09 This could take a surface id and just ignore ids t
Saman Sami 2017/06/26 20:44:05 I'll just check current_surface_id_ is valid.
83 } 84 }
84 85
85 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 86 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
86 needs_begin_frame_ = needs_begin_frame; 87 needs_begin_frame_ = needs_begin_frame;
87 UpdateNeedsBeginFramesInternal(); 88 UpdateNeedsBeginFramesInternal();
88 } 89 }
89 90
90 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) { 91 void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) {
91 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame", 92 TRACE_EVENT2("cc", "CompositorFrameSinkSupport::DidNotProduceFrame",
92 "ack.source_id", ack.source_id, "ack.sequence_number", 93 "ack.source_id", ack.source_id, "ack.sequence_number",
93 ack.sequence_number); 94 ack.sequence_number);
94 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber); 95 DCHECK_GE(ack.sequence_number, BeginFrameArgs::kStartingFrameNumber);
95 96
96 // |has_damage| is not transmitted, but false by default. 97 // |has_damage| is not transmitted, but false by default.
97 DCHECK(!ack.has_damage); 98 DCHECK(!ack.has_damage);
98 99
99 if (current_surface_) 100 Surface* current_surface = GetCurrentSurface();
100 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack); 101 if (current_surface)
102 surface_manager_->SurfaceModified(current_surface->surface_id(), ack);
danakj 2017/06/21 21:24:09 This could also early out if the surface didn't ex
Saman Sami 2017/06/26 20:44:05 I'll just check current_surface_id_ is valid.
103
101 if (begin_frame_source_) 104 if (begin_frame_source_)
102 begin_frame_source_->DidFinishFrame(this); 105 begin_frame_source_->DidFinishFrame(this);
103 } 106 }
104 107
105 bool CompositorFrameSinkSupport::SubmitCompositorFrame( 108 bool CompositorFrameSinkSupport::SubmitCompositorFrame(
106 const LocalSurfaceId& local_surface_id, 109 const LocalSurfaceId& local_surface_id,
107 CompositorFrame frame) { 110 CompositorFrame frame) {
108 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); 111 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame");
109 DCHECK(local_surface_id.is_valid()); 112 DCHECK(local_surface_id.is_valid());
110 DCHECK(!frame.render_pass_list.empty()); 113 DCHECK(!frame.render_pass_list.empty());
111 114
112 ++ack_pending_count_; 115 ++ack_pending_count_;
113 116
114 // |has_damage| is not transmitted. 117 // |has_damage| is not transmitted.
115 frame.metadata.begin_frame_ack.has_damage = true; 118 frame.metadata.begin_frame_ack.has_damage = true;
116 BeginFrameAck ack = frame.metadata.begin_frame_ack; 119 BeginFrameAck ack = frame.metadata.begin_frame_ack;
117 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); 120 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, ack.sequence_number);
118 121
119 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info, 122 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info,
120 "RenderWidgetHostImpl::OnSwapCompositorFrame")) { 123 "RenderWidgetHostImpl::OnSwapCompositorFrame")) {
121 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info); 124 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info);
122 } 125 }
123 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { 126 for (ui::LatencyInfo& latency : frame.metadata.latency_info) {
124 if (latency.latency_components().size() > 0) { 127 if (latency.latency_components().size() > 0) {
125 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, 128 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT,
126 0, 0); 129 0, 0);
127 } 130 }
128 } 131 }
129 132
130 std::unique_ptr<Surface> surface; 133 Surface* current_surface = GetCurrentSurface();
131 bool create_new_surface = 134 Surface* prev_surface = current_surface;
132 (!current_surface_ || 135 if (!current_surface ||
133 local_surface_id != current_surface_->surface_id().local_surface_id()); 136 surface_manager()->IsMarkedForDestruction(
134 if (!create_new_surface) { 137 current_surface->surface_id()) ||
135 surface = std::move(current_surface_); 138 local_surface_id != current_local_surface_id_) {
136 } else {
137 SurfaceId surface_id(frame_sink_id_, local_surface_id); 139 SurfaceId surface_id(frame_sink_id_, local_surface_id);
138 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); 140 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
139 float device_scale_factor = frame.metadata.device_scale_factor; 141 float device_scale_factor = frame.metadata.device_scale_factor;
140 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size); 142 SurfaceInfo surface_info(surface_id, device_scale_factor, frame_size);
141 143
142 if (!surface_info.is_valid()) { 144 if (!surface_info.is_valid()) {
143 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo", 145 TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo",
144 TRACE_EVENT_SCOPE_THREAD); 146 TRACE_EVENT_SCOPE_THREAD);
145 if (current_surface_) 147 if (current_surface)
146 DestroyCurrentSurface(); 148 EvictCurrentSurface();
147 ReturnedResourceArray resources; 149 ReturnedResourceArray resources;
148 TransferableResource::ReturnResources(frame.resource_list, &resources); 150 TransferableResource::ReturnResources(frame.resource_list, &resources);
149 ReturnResources(resources); 151 ReturnResources(resources);
150 DidReceiveCompositorFrameAck(); 152 DidReceiveCompositorFrameAck();
151 return true; 153 return true;
152 } 154 }
153 155
154 surface = CreateSurface(surface_info); 156 current_surface = CreateSurface(surface_info);
155 surface_manager_->SurfaceDamageExpected(surface->surface_id(), 157 current_local_surface_id_ = local_surface_id;
158 surface_manager_->SurfaceDamageExpected(current_surface->surface_id(),
156 last_begin_frame_args_); 159 last_begin_frame_args_);
157 } 160 }
158 161
159 bool result = surface->QueueFrame( 162 bool result = current_surface->QueueFrame(
160 std::move(frame), 163 std::move(frame),
161 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 164 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
162 weak_factory_.GetWeakPtr()), 165 weak_factory_.GetWeakPtr()),
163 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, 166 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface,
164 weak_factory_.GetWeakPtr())); 167 weak_factory_.GetWeakPtr()));
165 168
166 if (!result) { 169 if (!result) {
167 surface_manager_->DestroySurface(std::move(surface)); 170 EvictCurrentSurface();
168 return false; 171 return false;
169 } 172 }
170 173
171 if (current_surface_) { 174 if (prev_surface && prev_surface != current_surface) {
172 surface->SetPreviousFrameSurface(current_surface_.get()); 175 current_surface->SetPreviousFrameSurface(prev_surface);
173 DestroyCurrentSurface(); 176 surface_manager_->DestroySurface(prev_surface->surface_id());
174 } 177 }
175 current_surface_ = std::move(surface);
176 178
177 if (begin_frame_source_) 179 if (begin_frame_source_)
178 begin_frame_source_->DidFinishFrame(this); 180 begin_frame_source_->DidFinishFrame(this);
179 181
180 return true; 182 return true;
181 } 183 }
182 184
183 void CompositorFrameSinkSupport::UpdateSurfaceReferences( 185 void CompositorFrameSinkSupport::UpdateSurfaceReferences(
184 const LocalSurfaceId& local_surface_id, 186 const LocalSurfaceId& local_surface_id,
185 const std::vector<SurfaceId>& active_referenced_surfaces) { 187 const std::vector<SurfaceId>& active_referenced_surfaces) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 283
282 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) { 284 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) {
283 surface_manager_ = surface_manager; 285 surface_manager_ = surface_manager;
284 if (handles_frame_sink_id_invalidation_) 286 if (handles_frame_sink_id_invalidation_)
285 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 287 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
286 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); 288 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this);
287 } 289 }
288 290
289 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { 291 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
290 UpdateNeedsBeginFramesInternal(); 292 UpdateNeedsBeginFramesInternal();
291 if (current_surface_) { 293 Surface* current_surface = GetCurrentSurface();
292 surface_manager_->SurfaceDamageExpected(current_surface_->surface_id(), 294 if (current_surface)
295 surface_manager_->SurfaceDamageExpected(current_surface->surface_id(),
293 args); 296 args);
294 }
295 last_begin_frame_args_ = args; 297 last_begin_frame_args_ = args;
296 if (client_) 298 if (client_)
297 client_->OnBeginFrame(args); 299 client_->OnBeginFrame(args);
298 } 300 }
299 301
300 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() 302 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs()
301 const { 303 const {
302 return last_begin_frame_args_; 304 return last_begin_frame_args_;
303 } 305 }
304 306
(...skipping 30 matching lines...) Expand all
335 if (needs_begin_frame_ == added_frame_observer_) 337 if (needs_begin_frame_ == added_frame_observer_)
336 return; 338 return;
337 339
338 added_frame_observer_ = needs_begin_frame_; 340 added_frame_observer_ = needs_begin_frame_;
339 if (needs_begin_frame_) 341 if (needs_begin_frame_)
340 begin_frame_source_->AddObserver(this); 342 begin_frame_source_->AddObserver(this);
341 else 343 else
342 begin_frame_source_->RemoveObserver(this); 344 begin_frame_source_->RemoveObserver(this);
343 } 345 }
344 346
345 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( 347 Surface* CompositorFrameSinkSupport::CreateSurface(
346 const SurfaceInfo& surface_info) { 348 const SurfaceInfo& surface_info) {
347 seen_first_frame_activation_ = false; 349 seen_first_frame_activation_ = false;
348 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(), 350 return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(),
349 surface_info); 351 surface_info);
350 } 352 }
351 353
352 void CompositorFrameSinkSupport::DestroyCurrentSurface() { 354 void CompositorFrameSinkSupport::RequestCopyOfSurface(
353 surface_manager_->DestroySurface(std::move(current_surface_)); 355 std::unique_ptr<CopyOutputRequest> copy_request) {
356 Surface* current_surface = GetCurrentSurface();
357 if (!current_surface)
358 return;
359 DCHECK(current_surface->compositor_frame_sink_support().get() == this);
360 current_surface->RequestCopyOfOutput(std::move(copy_request));
361 BeginFrameAck ack;
362 ack.has_damage = true;
363 if (current_surface->HasActiveFrame())
364 surface_manager_->SurfaceModified(current_surface->surface_id(), ack);
354 } 365 }
355 366
356 void CompositorFrameSinkSupport::RequestCopyOfSurface( 367 Surface* CompositorFrameSinkSupport::GetCurrentSurface() {
357 std::unique_ptr<CopyOutputRequest> copy_request) { 368 return surface_manager_->GetSurfaceForId(
358 if (!current_surface_) 369 SurfaceId(frame_sink_id_, current_local_surface_id_));
359 return;
360
361 DCHECK(current_surface_->compositor_frame_sink_support().get() == this);
362 current_surface_->RequestCopyOfOutput(std::move(copy_request));
363 BeginFrameAck ack;
364 ack.has_damage = true;
365 if (current_surface_->HasActiveFrame())
366 surface_manager_->SurfaceModified(current_surface_->surface_id(), ack);
367 } 370 }
368 371
369 } // namespace cc 372 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698