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

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

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Address nits and rebase 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/surface.h" 5 #include "cc/surfaces/surface.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "cc/output/compositor_frame.h" 13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/copy_output_request.h" 14 #include "cc/output/copy_output_request.h"
15 #include "cc/surfaces/compositor_frame_sink_support.h"
15 #include "cc/surfaces/local_surface_id_allocator.h" 16 #include "cc/surfaces/local_surface_id_allocator.h"
16 #include "cc/surfaces/pending_frame_observer.h" 17 #include "cc/surfaces/pending_frame_observer.h"
17 #include "cc/surfaces/surface_factory.h"
18 #include "cc/surfaces/surface_manager.h" 18 #include "cc/surfaces/surface_manager.h"
19 19
20 namespace cc { 20 namespace cc {
21 21
22 // The frame index starts at 2 so that empty frames will be treated as 22 // The frame index starts at 2 so that empty frames will be treated as
23 // completely damaged the first time they're drawn from. 23 // completely damaged the first time they're drawn from.
24 static const int kFrameIndexStart = 2; 24 static const int kFrameIndexStart = 2;
25 25
26 Surface::Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory) 26 Surface::Surface(
27 const SurfaceId& id,
28 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support)
27 : surface_id_(id), 29 : surface_id_(id),
28 previous_frame_surface_id_(id), 30 previous_frame_surface_id_(id),
29 factory_(factory), 31 compositor_frame_sink_support_(std::move(compositor_frame_sink_support)),
30 frame_index_(kFrameIndexStart), 32 frame_index_(kFrameIndexStart),
31 destroyed_(false) {} 33 destroyed_(false) {}
32 34
33 Surface::~Surface() { 35 Surface::~Surface() {
34 ClearCopyRequests(); 36 ClearCopyRequests();
35 for (auto& observer : observers_) 37 for (auto& observer : observers_)
36 observer.OnSurfaceDiscarded(this); 38 observer.OnSurfaceDiscarded(this);
37 observers_.Clear(); 39 observers_.Clear();
38 40
39 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_)); 41 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_));
40 UnrefFrameResourcesAndRunDrawCallback(std::move(active_frame_data_)); 42 UnrefFrameResourcesAndRunDrawCallback(std::move(active_frame_data_));
41 } 43 }
42 44
43 void Surface::SetPreviousFrameSurface(Surface* surface) { 45 void Surface::SetPreviousFrameSurface(Surface* surface) {
44 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); 46 DCHECK(surface && (HasActiveFrame() || HasPendingFrame()));
45 frame_index_ = surface->frame_index() + 1; 47 frame_index_ = surface->frame_index() + 1;
46 previous_frame_surface_id_ = surface->surface_id(); 48 previous_frame_surface_id_ = surface->surface_id();
47 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame 49 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame
48 : pending_frame_data_->frame; 50 : pending_frame_data_->frame;
49 surface->TakeLatencyInfo(&frame.metadata.latency_info); 51 surface->TakeLatencyInfo(&frame.metadata.latency_info);
50 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 52 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
51 } 53 }
52 54
53 void Surface::QueueFrame(CompositorFrame frame, 55 void Surface::QueueFrame(CompositorFrame frame,
54 const DrawCallback& callback, 56 const base::Closure& callback,
55 const WillDrawCallback& will_draw_callback) { 57 const WillDrawCallback& will_draw_callback) {
56 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 58 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
57 59
58 base::Optional<FrameData> previous_pending_frame_data = 60 base::Optional<FrameData> previous_pending_frame_data =
59 std::move(pending_frame_data_); 61 std::move(pending_frame_data_);
60 pending_frame_data_.reset(); 62 pending_frame_data_.reset();
61 63
62 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); 64 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame);
63 65
64 // Receive and track the resources referenced from the CompositorFrame 66 // Receive and track the resources referenced from the CompositorFrame
65 // regardless of whether it's pending or active. 67 // regardless of whether it's pending or active.
66 factory_->ReceiveFromChild(frame.resource_list); 68 compositor_frame_sink_support_->ReceiveFromChild(frame.resource_list);
67 69
68 bool is_pending_frame = !blocking_surfaces_.empty(); 70 bool is_pending_frame = !blocking_surfaces_.empty();
69 71
70 if (is_pending_frame) { 72 if (is_pending_frame) {
71 pending_frame_data_ = 73 pending_frame_data_ =
72 FrameData(std::move(frame), callback, will_draw_callback); 74 FrameData(std::move(frame), callback, will_draw_callback);
73 // Ask the surface manager to inform |this| when its dependencies are 75 // Ask the surface manager to inform |this| when its dependencies are
74 // resolved. 76 // resolved.
75 factory_->manager()->RequestSurfaceResolution(this); 77 compositor_frame_sink_support_->surface_manager()->RequestSurfaceResolution(
78 this);
76 } else { 79 } else {
77 // If there are no blockers, then immediately activate the frame. 80 // If there are no blockers, then immediately activate the frame.
78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); 81 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback));
79 } 82 }
80 83
81 // Returns resources for the previous pending frame. 84 // Returns resources for the previous pending frame.
82 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); 85 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data));
83 } 86 }
84 87
85 void Surface::RequestCopyOfOutput( 88 void Surface::RequestCopyOfOutput(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return; 136 return;
134 } 137 }
135 138
136 // If a frame is being activated because of a deadline, then clear its set 139 // If a frame is being activated because of a deadline, then clear its set
137 // of blockers. 140 // of blockers.
138 blocking_surfaces_.clear(); 141 blocking_surfaces_.clear();
139 ActivatePendingFrame(); 142 ActivatePendingFrame();
140 } 143 }
141 144
142 Surface::FrameData::FrameData(CompositorFrame&& frame, 145 Surface::FrameData::FrameData(CompositorFrame&& frame,
143 const DrawCallback& draw_callback, 146 const base::Closure& draw_callback,
144 const WillDrawCallback& will_draw_callback) 147 const WillDrawCallback& will_draw_callback)
145 : frame(std::move(frame)), 148 : frame(std::move(frame)),
146 draw_callback(draw_callback), 149 draw_callback(draw_callback),
147 will_draw_callback(will_draw_callback) {} 150 will_draw_callback(will_draw_callback) {}
148 151
149 Surface::FrameData::FrameData(FrameData&& other) = default; 152 Surface::FrameData::FrameData(FrameData&& other) = default;
150 153
151 Surface::FrameData& Surface::FrameData::operator=(FrameData&& other) = default; 154 Surface::FrameData& Surface::FrameData::operator=(FrameData&& other) = default;
152 155
153 Surface::FrameData::~FrameData() = default; 156 Surface::FrameData::~FrameData() = default;
154 157
155 void Surface::ActivatePendingFrame() { 158 void Surface::ActivatePendingFrame() {
156 DCHECK(pending_frame_data_); 159 DCHECK(pending_frame_data_);
157 ActivateFrame(std::move(*pending_frame_data_)); 160 ActivateFrame(std::move(*pending_frame_data_));
158 pending_frame_data_.reset(); 161 pending_frame_data_.reset();
159 } 162 }
160 163
161 // A frame is activated if all its Surface ID dependences are active or a 164 // A frame is activated if all its Surface ID dependences are active or a
162 // deadline has hit and the frame was forcibly activated by the display 165 // deadline has hit and the frame was forcibly activated by the display
163 // compositor. 166 // compositor.
164 void Surface::ActivateFrame(FrameData frame_data) { 167 void Surface::ActivateFrame(FrameData frame_data) {
165 DCHECK(factory_); 168 DCHECK(compositor_frame_sink_support_);
166 169
167 // Save root pass copy requests. 170 // Save root pass copy requests.
168 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests; 171 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests;
169 if (active_frame_data_) { 172 if (active_frame_data_) {
170 std::swap(old_copy_requests, 173 std::swap(old_copy_requests,
171 active_frame_data_->frame.render_pass_list.back()->copy_requests); 174 active_frame_data_->frame.render_pass_list.back()->copy_requests);
172 } 175 }
173 176
174 ClearCopyRequests(); 177 ClearCopyRequests();
175 178
(...skipping 13 matching lines...) Expand all
189 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_frame_data)); 192 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_frame_data));
190 193
191 for (auto& observer : observers_) 194 for (auto& observer : observers_)
192 observer.OnSurfaceActivated(this); 195 observer.OnSurfaceActivated(this);
193 } 196 }
194 197
195 void Surface::UpdateBlockingSurfaces(bool has_previous_pending_frame, 198 void Surface::UpdateBlockingSurfaces(bool has_previous_pending_frame,
196 const CompositorFrame& current_frame) { 199 const CompositorFrame& current_frame) {
197 // If there is no SurfaceDependencyTracker installed then the |current_frame| 200 // If there is no SurfaceDependencyTracker installed then the |current_frame|
198 // does not block on anything. 201 // does not block on anything.
199 if (!factory_->manager()->dependency_tracker()) { 202 if (!compositor_frame_sink_support_->surface_manager()
203 ->dependency_tracker()) {
200 blocking_surfaces_.clear(); 204 blocking_surfaces_.clear();
201 return; 205 return;
202 } 206 }
203 207
204 base::flat_set<SurfaceId> new_blocking_surfaces; 208 base::flat_set<SurfaceId> new_blocking_surfaces;
205 209
206 for (const SurfaceId& surface_id : 210 for (const SurfaceId& surface_id :
207 current_frame.metadata.activation_dependencies) { 211 current_frame.metadata.activation_dependencies) {
208 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id); 212 Surface* surface =
213 compositor_frame_sink_support_->surface_manager()->GetSurfaceForId(
214 surface_id);
209 // If a referenced surface does not have a corresponding active frame in the 215 // If a referenced surface does not have a corresponding active frame in the
210 // display compositor, then it blocks this frame. 216 // display compositor, then it blocks this frame.
211 if (!surface || !surface->HasActiveFrame()) 217 if (!surface || !surface->HasActiveFrame())
212 new_blocking_surfaces.insert(surface_id); 218 new_blocking_surfaces.insert(surface_id);
213 } 219 }
214 220
215 // If this Surface has a previous pending frame, then we must determine the 221 // If this Surface has a previous pending frame, then we must determine the
216 // changes in dependencies so that we can update the SurfaceDependencyTracker 222 // changes in dependencies so that we can update the SurfaceDependencyTracker
217 // map. 223 // map.
218 if (has_previous_pending_frame) { 224 if (has_previous_pending_frame) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 272 }
267 273
268 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { 274 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) {
269 if (!active_frame_data_) 275 if (!active_frame_data_)
270 return; 276 return;
271 TakeLatencyInfoFromFrame(&active_frame_data_->frame, latency_info); 277 TakeLatencyInfoFromFrame(&active_frame_data_->frame, latency_info);
272 } 278 }
273 279
274 void Surface::RunDrawCallback() { 280 void Surface::RunDrawCallback() {
275 if (active_frame_data_ && !active_frame_data_->draw_callback.is_null()) { 281 if (active_frame_data_ && !active_frame_data_->draw_callback.is_null()) {
276 DrawCallback callback = active_frame_data_->draw_callback; 282 base::Closure callback = active_frame_data_->draw_callback;
277 active_frame_data_->draw_callback = DrawCallback(); 283 active_frame_data_->draw_callback = base::Closure();
278 callback.Run(); 284 callback.Run();
279 } 285 }
280 } 286 }
281 287
282 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { 288 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) {
283 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) 289 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null())
284 return; 290 return;
285 291
286 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), 292 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(),
287 damage_rect); 293 damage_rect);
288 } 294 }
289 295
290 void Surface::AddDestructionDependency(SurfaceSequence sequence) { 296 void Surface::AddDestructionDependency(SurfaceSequence sequence) {
291 destruction_dependencies_.push_back(sequence); 297 destruction_dependencies_.push_back(sequence);
292 } 298 }
293 299
294 void Surface::SatisfyDestructionDependencies( 300 void Surface::SatisfyDestructionDependencies(
295 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, 301 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences,
296 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 302 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) {
297 base::EraseIf(destruction_dependencies_, 303 base::EraseIf(destruction_dependencies_,
298 [sequences, valid_frame_sink_ids](SurfaceSequence seq) { 304 [sequences, valid_frame_sink_ids](SurfaceSequence seq) {
299 return (!!sequences->erase(seq) || 305 return (!!sequences->erase(seq) ||
300 !valid_frame_sink_ids->count(seq.frame_sink_id)); 306 !valid_frame_sink_ids->count(seq.frame_sink_id));
301 }); 307 });
302 } 308 }
303 309
304 void Surface::UnrefFrameResourcesAndRunDrawCallback( 310 void Surface::UnrefFrameResourcesAndRunDrawCallback(
305 base::Optional<FrameData> frame_data) { 311 base::Optional<FrameData> frame_data) {
306 if (!frame_data || !factory_) 312 if (!frame_data || !compositor_frame_sink_support_)
307 return; 313 return;
308 314
309 ReturnedResourceArray resources; 315 ReturnedResourceArray resources;
310 TransferableResource::ReturnResources(frame_data->frame.resource_list, 316 TransferableResource::ReturnResources(frame_data->frame.resource_list,
311 &resources); 317 &resources);
312 // No point in returning same sync token to sender. 318 // No point in returning same sync token to sender.
313 for (auto& resource : resources) 319 for (auto& resource : resources)
314 resource.sync_token.Clear(); 320 resource.sync_token.Clear();
315 factory_->UnrefResources(resources); 321 compositor_frame_sink_support_->UnrefResources(resources);
316 322
317 if (!frame_data->draw_callback.is_null()) 323 if (!frame_data->draw_callback.is_null())
318 frame_data->draw_callback.Run(); 324 frame_data->draw_callback.Run();
319 } 325 }
320 326
321 void Surface::ClearCopyRequests() { 327 void Surface::ClearCopyRequests() {
322 if (active_frame_data_) { 328 if (active_frame_data_) {
323 for (const auto& render_pass : active_frame_data_->frame.render_pass_list) { 329 for (const auto& render_pass : active_frame_data_->frame.render_pass_list) {
324 for (const auto& copy_request : render_pass->copy_requests) 330 for (const auto& copy_request : render_pass->copy_requests)
325 copy_request->SendEmptyResult(); 331 copy_request->SendEmptyResult();
(...skipping 16 matching lines...) Expand all
342 frame->metadata.latency_info.swap(*latency_info); 348 frame->metadata.latency_info.swap(*latency_info);
343 return; 349 return;
344 } 350 }
345 std::copy(frame->metadata.latency_info.begin(), 351 std::copy(frame->metadata.latency_info.begin(),
346 frame->metadata.latency_info.end(), 352 frame->metadata.latency_info.end(),
347 std::back_inserter(*latency_info)); 353 std::back_inserter(*latency_info));
348 frame->metadata.latency_info.clear(); 354 frame->metadata.latency_info.clear();
349 } 355 }
350 356
351 } // namespace cc 357 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698