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

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

Issue 2807653003: Move Work From CompositorFrameSinkSupport() To Init() (Closed)
Patch Set: Add CompositorFrameSinkSupport::Create Created 3 years, 8 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_manager.h" 15 #include "cc/surfaces/surface_manager.h"
16 #include "cc/surfaces/surface_reference.h" 16 #include "cc/surfaces/surface_reference.h"
17 17
18 namespace cc { 18 namespace cc {
19 19
20 CompositorFrameSinkSupport::CompositorFrameSinkSupport( 20 // static
21 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create(
21 CompositorFrameSinkSupportClient* client, 22 CompositorFrameSinkSupportClient* client,
22 SurfaceManager* surface_manager, 23 SurfaceManager* surface_manager,
23 const FrameSinkId& frame_sink_id, 24 const FrameSinkId& frame_sink_id,
24 bool is_root, 25 bool is_root,
25 bool handles_frame_sink_id_invalidation, 26 bool handles_frame_sink_id_invalidation,
26 bool needs_sync_points) 27 bool needs_sync_points) {
27 : client_(client), 28 std::unique_ptr<CompositorFrameSinkSupport> support =
28 surface_manager_(surface_manager), 29 base::WrapUnique(new CompositorFrameSinkSupport(
29 frame_sink_id_(frame_sink_id), 30 client, frame_sink_id, is_root, handles_frame_sink_id_invalidation));
30 surface_factory_(frame_sink_id_, surface_manager_, this), 31 support->Init(surface_manager, needs_sync_points);
31 reference_tracker_(frame_sink_id), 32 return support;
32 is_root_(is_root),
33 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation),
34 weak_factory_(this) {
35 surface_factory_.set_needs_sync_points(needs_sync_points);
36 if (handles_frame_sink_id_invalidation_)
37 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
38 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
39 } 33 }
40 34
41 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { 35 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {
42 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does 36 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does
43 // not call into |this| after it's deleted. 37 // not call into |this| after it's deleted.
44 SetNeedsBeginFrame(false); 38 SetNeedsBeginFrame(false);
45 39
46 // For display root surfaces, the surface is no longer going to be visible 40 // For display root surfaces, the surface is no longer going to be visible
47 // so make it unreachable from the top-level root. 41 // so make it unreachable from the top-level root.
48 if (surface_manager_->using_surface_references() && is_root_ && 42 if (surface_manager_->using_surface_references() && is_root_ &&
49 reference_tracker_.current_surface_id().is_valid()) 43 reference_tracker_.current_surface_id().is_valid())
50 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); 44 RemoveTopLevelRootReference(reference_tracker_.current_surface_id());
51 45
52 // SurfaceFactory's destructor will attempt to return resources which will 46 // SurfaceFactory's destructor will attempt to return resources which will
53 // call back into here and access |client_| so we should destroy 47 // call back into here and access |client_| so we should destroy
54 // |surface_factory_|'s resources early on. 48 // |surface_factory_|'s resources early on.
55 surface_factory_.EvictSurface(); 49 surface_factory_->EvictSurface();
56 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 50 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
57 if (handles_frame_sink_id_invalidation_) 51 if (handles_frame_sink_id_invalidation_)
58 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); 52 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
59 } 53 }
60 54
61 void CompositorFrameSinkSupport::ReferencedSurfacesChanged( 55 void CompositorFrameSinkSupport::ReferencedSurfacesChanged(
62 const LocalSurfaceId& local_surface_id, 56 const LocalSurfaceId& local_surface_id,
63 const std::vector<SurfaceId>* active_referenced_surfaces, 57 const std::vector<SurfaceId>* active_referenced_surfaces,
64 const std::vector<SurfaceId>* pending_referenced_surfaces) { 58 const std::vector<SurfaceId>* pending_referenced_surfaces) {
65 if (!surface_manager_->using_surface_references()) 59 if (!surface_manager_->using_surface_references())
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 97 }
104 98
105 void CompositorFrameSinkSupport::WillDrawSurface( 99 void CompositorFrameSinkSupport::WillDrawSurface(
106 const LocalSurfaceId& local_surface_id, 100 const LocalSurfaceId& local_surface_id,
107 const gfx::Rect& damage_rect) { 101 const gfx::Rect& damage_rect) {
108 if (client_) 102 if (client_)
109 client_->WillDrawSurface(local_surface_id, damage_rect); 103 client_->WillDrawSurface(local_surface_id, damage_rect);
110 } 104 }
111 105
112 void CompositorFrameSinkSupport::EvictFrame() { 106 void CompositorFrameSinkSupport::EvictFrame() {
113 surface_factory_.EvictSurface(); 107 DCHECK(surface_factory_);
108 surface_factory_->EvictSurface();
114 } 109 }
115 110
116 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 111 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
117 needs_begin_frame_ = needs_begin_frame; 112 needs_begin_frame_ = needs_begin_frame;
118 UpdateNeedsBeginFramesInternal(); 113 UpdateNeedsBeginFramesInternal();
119 } 114 }
120 115
121 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( 116 void CompositorFrameSinkSupport::BeginFrameDidNotSwap(
122 const BeginFrameAck& ack) { 117 const BeginFrameAck& ack) {
123 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we 118 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we
124 // should not acknowledge immediately. Instead, we should update the ack that 119 // should not acknowledge immediately. Instead, we should update the ack that
125 // will be sent to DisplayScheduler when the pending frame is activated. 120 // will be sent to DisplayScheduler when the pending frame is activated.
126 if (ack.sequence_number < BeginFrameArgs::kStartingFrameNumber) { 121 if (ack.sequence_number < BeginFrameArgs::kStartingFrameNumber) {
127 DLOG(ERROR) << "Received BeginFrameDidNotSwap with invalid BeginFrameAck."; 122 DLOG(ERROR) << "Received BeginFrameDidNotSwap with invalid BeginFrameAck.";
128 return; 123 return;
129 } 124 }
130 125
131 // |has_damage| is not transmitted, but false by default. 126 // |has_damage| is not transmitted, but false by default.
132 DCHECK(!ack.has_damage); 127 DCHECK(!ack.has_damage);
133 if (begin_frame_source_) 128 if (begin_frame_source_)
134 begin_frame_source_->DidFinishFrame(this, ack); 129 begin_frame_source_->DidFinishFrame(this, ack);
135 } 130 }
136 131
137 void CompositorFrameSinkSupport::SubmitCompositorFrame( 132 void CompositorFrameSinkSupport::SubmitCompositorFrame(
138 const LocalSurfaceId& local_surface_id, 133 const LocalSurfaceId& local_surface_id,
139 CompositorFrame frame) { 134 CompositorFrame frame) {
135 DCHECK(surface_factory_);
140 ++ack_pending_count_; 136 ++ack_pending_count_;
141 137
142 if (frame.metadata.begin_frame_ack.sequence_number < 138 if (frame.metadata.begin_frame_ack.sequence_number <
143 BeginFrameArgs::kStartingFrameNumber) { 139 BeginFrameArgs::kStartingFrameNumber) {
144 DLOG(ERROR) << "Received CompositorFrame with invalid BeginFrameAck."; 140 DLOG(ERROR) << "Received CompositorFrame with invalid BeginFrameAck.";
145 frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId; 141 frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId;
146 frame.metadata.begin_frame_ack.sequence_number = 142 frame.metadata.begin_frame_ack.sequence_number =
147 BeginFrameArgs::kStartingFrameNumber; 143 BeginFrameArgs::kStartingFrameNumber;
148 } 144 }
149 // |has_damage| is not transmitted. 145 // |has_damage| is not transmitted.
150 frame.metadata.begin_frame_ack.has_damage = true; 146 frame.metadata.begin_frame_ack.has_damage = true;
151 147
152 BeginFrameAck ack = frame.metadata.begin_frame_ack; 148 BeginFrameAck ack = frame.metadata.begin_frame_ack;
153 surface_factory_.SubmitCompositorFrame( 149 surface_factory_->SubmitCompositorFrame(
154 local_surface_id, std::move(frame), 150 local_surface_id, std::move(frame),
155 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 151 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
156 weak_factory_.GetWeakPtr())); 152 weak_factory_.GetWeakPtr()));
157 153
158 // TODO(eseckler): The CompositorFrame submitted below might not be activated 154 // TODO(eseckler): The CompositorFrame submitted below might not be activated
159 // right away b/c of surface synchronization. We should only send the 155 // right away b/c of surface synchronization. We should only send the
160 // BeginFrameAck to DisplayScheduler when it is activated. This also means 156 // BeginFrameAck to DisplayScheduler when it is activated. This also means
161 // that we need to stay an active BFO while a CompositorFrame is pending. 157 // that we need to stay an active BFO while a CompositorFrame is pending.
162 // See https://crbug.com/703079. 158 // See https://crbug.com/703079.
163 if (begin_frame_source_) 159 if (begin_frame_source_)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // We return the resources before sending an ack so they can be reused in 215 // We return the resources before sending an ack so they can be reused in
220 // making the next CompositorFrame. 216 // making the next CompositorFrame.
221 if (!surface_returned_resources_.empty()) { 217 if (!surface_returned_resources_.empty()) {
222 client_->ReclaimResources(surface_returned_resources_); 218 client_->ReclaimResources(surface_returned_resources_);
223 surface_returned_resources_.clear(); 219 surface_returned_resources_.clear();
224 } 220 }
225 client_->DidReceiveCompositorFrameAck(); 221 client_->DidReceiveCompositorFrameAck();
226 } 222 }
227 223
228 void CompositorFrameSinkSupport::ForceReclaimResources() { 224 void CompositorFrameSinkSupport::ForceReclaimResources() {
229 surface_factory_.ClearSurface(); 225 DCHECK(surface_factory_);
226 surface_factory_->ClearSurface();
230 } 227 }
231 228
232 void CompositorFrameSinkSupport::ClaimTemporaryReference( 229 void CompositorFrameSinkSupport::ClaimTemporaryReference(
233 const SurfaceId& surface_id) { 230 const SurfaceId& surface_id) {
234 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); 231 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_);
235 } 232 }
236 233
234 CompositorFrameSinkSupport::CompositorFrameSinkSupport(
235 CompositorFrameSinkSupportClient* client,
236 const FrameSinkId& frame_sink_id,
237 bool is_root,
238 bool handles_frame_sink_id_invalidation)
239 : client_(client),
240 frame_sink_id_(frame_sink_id),
241 reference_tracker_(frame_sink_id),
242 is_root_(is_root),
243 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation),
244 weak_factory_(this) {}
245
246 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager,
247 bool needs_sync_points) {
248 surface_manager_ = surface_manager;
249 surface_factory_ =
250 base::MakeUnique<SurfaceFactory>(frame_sink_id_, surface_manager_, this);
251 if (handles_frame_sink_id_invalidation_)
252 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
253 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
254 surface_factory_->set_needs_sync_points(needs_sync_points);
255 }
256
237 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { 257 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
238 UpdateNeedsBeginFramesInternal(); 258 UpdateNeedsBeginFramesInternal();
239 last_begin_frame_args_ = args; 259 last_begin_frame_args_ = args;
240 if (client_) 260 if (client_)
241 client_->OnBeginFrame(args); 261 client_->OnBeginFrame(args);
242 } 262 }
243 263
244 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() 264 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs()
245 const { 265 const {
246 return last_begin_frame_args_; 266 return last_begin_frame_args_;
(...skipping 10 matching lines...) Expand all
257 277
258 added_frame_observer_ = needs_begin_frame_; 278 added_frame_observer_ = needs_begin_frame_;
259 if (needs_begin_frame_) 279 if (needs_begin_frame_)
260 begin_frame_source_->AddObserver(this); 280 begin_frame_source_->AddObserver(this);
261 else 281 else
262 begin_frame_source_->RemoveObserver(this); 282 begin_frame_source_->RemoveObserver(this);
263 } 283 }
264 284
265 void CompositorFrameSinkSupport::RequestCopyOfSurface( 285 void CompositorFrameSinkSupport::RequestCopyOfSurface(
266 std::unique_ptr<CopyOutputRequest> request) { 286 std::unique_ptr<CopyOutputRequest> request) {
267 surface_factory_.RequestCopyOfSurface(std::move(request)); 287 DCHECK(surface_factory_);
288 surface_factory_->RequestCopyOfSurface(std::move(request));
268 } 289 }
269 290
270 } // namespace cc 291 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/compositor_frame_sink_support_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698