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

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

Issue 2807653003: Move Work From CompositorFrameSinkSupport() To Init() (Closed)
Patch Set: Set needs_sync_points 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 CompositorFrameSinkSupport::CompositorFrameSinkSupport(
21 CompositorFrameSinkSupportClient* client, 21 CompositorFrameSinkSupportClient* client,
22 SurfaceManager* surface_manager,
23 const FrameSinkId& frame_sink_id, 22 const FrameSinkId& frame_sink_id,
24 bool is_root, 23 bool is_root,
25 bool handles_frame_sink_id_invalidation, 24 bool handles_frame_sink_id_invalidation)
26 bool needs_sync_points)
27 : client_(client), 25 : client_(client),
28 surface_manager_(surface_manager),
boliu 2017/04/11 20:49:13 this still needs to be initialized to null, though
Alex Z. 2017/04/11 20:57:17 Done.
29 frame_sink_id_(frame_sink_id), 26 frame_sink_id_(frame_sink_id),
30 surface_factory_(frame_sink_id_, surface_manager_, this),
31 reference_tracker_(frame_sink_id), 27 reference_tracker_(frame_sink_id),
32 is_root_(is_root), 28 is_root_(is_root),
33 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), 29 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation),
34 weak_factory_(this) { 30 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 }
40 31
41 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { 32 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {
42 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does 33 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does
43 // not call into |this| after it's deleted. 34 // not call into |this| after it's deleted.
44 SetNeedsBeginFrame(false); 35 SetNeedsBeginFrame(false);
45 36
46 // For display root surfaces, the surface is no longer going to be visible 37 // For display root surfaces, the surface is no longer going to be visible
47 // so make it unreachable from the top-level root. 38 // so make it unreachable from the top-level root.
48 if (surface_manager_->using_surface_references() && is_root_ && 39 if (surface_manager_->using_surface_references() && is_root_ &&
49 reference_tracker_.current_surface_id().is_valid()) 40 reference_tracker_.current_surface_id().is_valid())
50 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); 41 RemoveTopLevelRootReference(reference_tracker_.current_surface_id());
51 42
52 // SurfaceFactory's destructor will attempt to return resources which will 43 // SurfaceFactory's destructor will attempt to return resources which will
53 // call back into here and access |client_| so we should destroy 44 // call back into here and access |client_| so we should destroy
54 // |surface_factory_|'s resources early on. 45 // |surface_factory_|'s resources early on.
55 surface_factory_.EvictSurface(); 46 surface_factory_->EvictSurface();
56 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 47 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
57 if (handles_frame_sink_id_invalidation_) 48 if (handles_frame_sink_id_invalidation_)
58 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); 49 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
59 } 50 }
60 51
52 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager,
53 bool needs_sync_points) {
54 surface_manager_ = surface_manager;
55 surface_factory_ =
56 base::MakeUnique<SurfaceFactory>(frame_sink_id_, surface_manager_, this);
57 if (handles_frame_sink_id_invalidation_)
58 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
59 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
60 surface_factory_->set_needs_sync_points(needs_sync_points);
61 }
62
61 void CompositorFrameSinkSupport::ReferencedSurfacesChanged( 63 void CompositorFrameSinkSupport::ReferencedSurfacesChanged(
62 const LocalSurfaceId& local_surface_id, 64 const LocalSurfaceId& local_surface_id,
63 const std::vector<SurfaceId>* active_referenced_surfaces, 65 const std::vector<SurfaceId>* active_referenced_surfaces,
64 const std::vector<SurfaceId>* pending_referenced_surfaces) { 66 const std::vector<SurfaceId>* pending_referenced_surfaces) {
65 if (!surface_manager_->using_surface_references()) 67 if (!surface_manager_->using_surface_references())
66 return; 68 return;
67 69
68 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); 70 SurfaceId last_surface_id = reference_tracker_.current_surface_id();
69 71
70 // Populate list of surface references to add and remove based on reference 72 // Populate list of surface references to add and remove based on reference
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 105 }
104 106
105 void CompositorFrameSinkSupport::WillDrawSurface( 107 void CompositorFrameSinkSupport::WillDrawSurface(
106 const LocalSurfaceId& local_surface_id, 108 const LocalSurfaceId& local_surface_id,
107 const gfx::Rect& damage_rect) { 109 const gfx::Rect& damage_rect) {
108 if (client_) 110 if (client_)
109 client_->WillDrawSurface(local_surface_id, damage_rect); 111 client_->WillDrawSurface(local_surface_id, damage_rect);
110 } 112 }
111 113
112 void CompositorFrameSinkSupport::EvictFrame() { 114 void CompositorFrameSinkSupport::EvictFrame() {
113 surface_factory_.EvictSurface(); 115 DCHECK(surface_factory_);
116 surface_factory_->EvictSurface();
114 } 117 }
115 118
116 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { 119 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
117 needs_begin_frame_ = needs_begin_frame; 120 needs_begin_frame_ = needs_begin_frame;
118 UpdateNeedsBeginFramesInternal(); 121 UpdateNeedsBeginFramesInternal();
119 } 122 }
120 123
121 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( 124 void CompositorFrameSinkSupport::BeginFrameDidNotSwap(
122 const BeginFrameAck& ack) { 125 const BeginFrameAck& ack) {
123 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we 126 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we
124 // should not acknowledge immediately. Instead, we should update the ack that 127 // should not acknowledge immediately. Instead, we should update the ack that
125 // will be sent to DisplayScheduler when the pending frame is activated. 128 // will be sent to DisplayScheduler when the pending frame is activated.
126 if (ack.sequence_number < BeginFrameArgs::kStartingFrameNumber) { 129 if (ack.sequence_number < BeginFrameArgs::kStartingFrameNumber) {
127 DLOG(ERROR) << "Received BeginFrameDidNotSwap with invalid BeginFrameAck."; 130 DLOG(ERROR) << "Received BeginFrameDidNotSwap with invalid BeginFrameAck.";
128 return; 131 return;
129 } 132 }
130 133
131 // |has_damage| is not transmitted, but false by default. 134 // |has_damage| is not transmitted, but false by default.
132 DCHECK(!ack.has_damage); 135 DCHECK(!ack.has_damage);
133 if (begin_frame_source_) 136 if (begin_frame_source_)
134 begin_frame_source_->DidFinishFrame(this, ack); 137 begin_frame_source_->DidFinishFrame(this, ack);
135 } 138 }
136 139
137 void CompositorFrameSinkSupport::SubmitCompositorFrame( 140 void CompositorFrameSinkSupport::SubmitCompositorFrame(
138 const LocalSurfaceId& local_surface_id, 141 const LocalSurfaceId& local_surface_id,
139 CompositorFrame frame) { 142 CompositorFrame frame) {
143 DCHECK(surface_factory_);
140 ++ack_pending_count_; 144 ++ack_pending_count_;
141 145
142 if (frame.metadata.begin_frame_ack.sequence_number < 146 if (frame.metadata.begin_frame_ack.sequence_number <
143 BeginFrameArgs::kStartingFrameNumber) { 147 BeginFrameArgs::kStartingFrameNumber) {
144 DLOG(ERROR) << "Received CompositorFrame with invalid BeginFrameAck."; 148 DLOG(ERROR) << "Received CompositorFrame with invalid BeginFrameAck.";
145 frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId; 149 frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId;
146 frame.metadata.begin_frame_ack.sequence_number = 150 frame.metadata.begin_frame_ack.sequence_number =
147 BeginFrameArgs::kStartingFrameNumber; 151 BeginFrameArgs::kStartingFrameNumber;
148 } 152 }
149 // |has_damage| is not transmitted. 153 // |has_damage| is not transmitted.
150 frame.metadata.begin_frame_ack.has_damage = true; 154 frame.metadata.begin_frame_ack.has_damage = true;
151 155
152 BeginFrameAck ack = frame.metadata.begin_frame_ack; 156 BeginFrameAck ack = frame.metadata.begin_frame_ack;
153 surface_factory_.SubmitCompositorFrame( 157 surface_factory_->SubmitCompositorFrame(
154 local_surface_id, std::move(frame), 158 local_surface_id, std::move(frame),
155 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, 159 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
156 weak_factory_.GetWeakPtr())); 160 weak_factory_.GetWeakPtr()));
157 161
158 // TODO(eseckler): The CompositorFrame submitted below might not be activated 162 // TODO(eseckler): The CompositorFrame submitted below might not be activated
159 // right away b/c of surface synchronization. We should only send the 163 // right away b/c of surface synchronization. We should only send the
160 // BeginFrameAck to DisplayScheduler when it is activated. This also means 164 // BeginFrameAck to DisplayScheduler when it is activated. This also means
161 // that we need to stay an active BFO while a CompositorFrame is pending. 165 // that we need to stay an active BFO while a CompositorFrame is pending.
162 // See https://crbug.com/703079. 166 // See https://crbug.com/703079.
163 if (begin_frame_source_) 167 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 223 // We return the resources before sending an ack so they can be reused in
220 // making the next CompositorFrame. 224 // making the next CompositorFrame.
221 if (!surface_returned_resources_.empty()) { 225 if (!surface_returned_resources_.empty()) {
222 client_->ReclaimResources(surface_returned_resources_); 226 client_->ReclaimResources(surface_returned_resources_);
223 surface_returned_resources_.clear(); 227 surface_returned_resources_.clear();
224 } 228 }
225 client_->DidReceiveCompositorFrameAck(); 229 client_->DidReceiveCompositorFrameAck();
226 } 230 }
227 231
228 void CompositorFrameSinkSupport::ForceReclaimResources() { 232 void CompositorFrameSinkSupport::ForceReclaimResources() {
229 surface_factory_.ClearSurface(); 233 DCHECK(surface_factory_);
234 surface_factory_->ClearSurface();
230 } 235 }
231 236
232 void CompositorFrameSinkSupport::ClaimTemporaryReference( 237 void CompositorFrameSinkSupport::ClaimTemporaryReference(
233 const SurfaceId& surface_id) { 238 const SurfaceId& surface_id) {
234 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); 239 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_);
235 } 240 }
236 241
237 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { 242 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
238 UpdateNeedsBeginFramesInternal(); 243 UpdateNeedsBeginFramesInternal();
239 last_begin_frame_args_ = args; 244 last_begin_frame_args_ = args;
(...skipping 17 matching lines...) Expand all
257 262
258 added_frame_observer_ = needs_begin_frame_; 263 added_frame_observer_ = needs_begin_frame_;
259 if (needs_begin_frame_) 264 if (needs_begin_frame_)
260 begin_frame_source_->AddObserver(this); 265 begin_frame_source_->AddObserver(this);
261 else 266 else
262 begin_frame_source_->RemoveObserver(this); 267 begin_frame_source_->RemoveObserver(this);
263 } 268 }
264 269
265 void CompositorFrameSinkSupport::RequestCopyOfSurface( 270 void CompositorFrameSinkSupport::RequestCopyOfSurface(
266 std::unique_ptr<CopyOutputRequest> request) { 271 std::unique_ptr<CopyOutputRequest> request) {
267 surface_factory_.RequestCopyOfSurface(std::move(request)); 272 DCHECK(surface_factory_);
273 surface_factory_->RequestCopyOfSurface(std::move(request));
268 } 274 }
269 275
270 } // namespace cc 276 } // 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