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

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

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Merge unit tests 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 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_(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_));
(...skipping 16 matching lines...) Expand all
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::EvictFrame() { 88 void Surface::EvictFrame() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void Surface::ActivatePendingFrame() { 164 void Surface::ActivatePendingFrame() {
162 DCHECK(pending_frame_data_); 165 DCHECK(pending_frame_data_);
163 ActivateFrame(std::move(*pending_frame_data_)); 166 ActivateFrame(std::move(*pending_frame_data_));
164 pending_frame_data_.reset(); 167 pending_frame_data_.reset();
165 } 168 }
166 169
167 // A frame is activated if all its Surface ID dependences are active or a 170 // A frame is activated if all its Surface ID dependences are active or a
168 // deadline has hit and the frame was forcibly activated by the display 171 // deadline has hit and the frame was forcibly activated by the display
169 // compositor. 172 // compositor.
170 void Surface::ActivateFrame(FrameData frame_data) { 173 void Surface::ActivateFrame(FrameData frame_data) {
171 DCHECK(factory_); 174 DCHECK(compositor_frame_sink_support_);
172 175
173 // Save root pass copy requests. 176 // Save root pass copy requests.
174 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests; 177 std::vector<std::unique_ptr<CopyOutputRequest>> old_copy_requests;
175 if (active_frame_data_ && 178 if (active_frame_data_ &&
176 !active_frame_data_->frame.render_pass_list.empty()) { 179 !active_frame_data_->frame.render_pass_list.empty()) {
177 std::swap(old_copy_requests, 180 std::swap(old_copy_requests,
178 active_frame_data_->frame.render_pass_list.back()->copy_requests); 181 active_frame_data_->frame.render_pass_list.back()->copy_requests);
179 } 182 }
180 183
181 ClearCopyRequests(); 184 ClearCopyRequests();
(...skipping 17 matching lines...) Expand all
199 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_frame_data)); 202 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_frame_data));
200 203
201 for (auto& observer : observers_) 204 for (auto& observer : observers_)
202 observer.OnSurfaceActivated(this); 205 observer.OnSurfaceActivated(this);
203 } 206 }
204 207
205 void Surface::UpdateBlockingSurfaces(bool has_previous_pending_frame, 208 void Surface::UpdateBlockingSurfaces(bool has_previous_pending_frame,
206 const CompositorFrame& current_frame) { 209 const CompositorFrame& current_frame) {
207 // If there is no SurfaceDependencyTracker installed then the |current_frame| 210 // If there is no SurfaceDependencyTracker installed then the |current_frame|
208 // does not block on anything. 211 // does not block on anything.
209 if (!factory_->manager()->dependency_tracker()) { 212 if (!compositor_frame_sink_support_->surface_manager()
213 ->dependency_tracker()) {
210 blocking_surfaces_.clear(); 214 blocking_surfaces_.clear();
211 return; 215 return;
212 } 216 }
213 217
214 base::flat_set<SurfaceId> new_blocking_surfaces; 218 base::flat_set<SurfaceId> new_blocking_surfaces;
215 219
216 for (const SurfaceId& surface_id : current_frame.metadata.embedded_surfaces) { 220 for (const SurfaceId& surface_id : current_frame.metadata.embedded_surfaces) {
217 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id); 221 Surface* surface =
222 compositor_frame_sink_support_->surface_manager()->GetSurfaceForId(
223 surface_id);
218 // If a referenced surface does not have a corresponding active frame in the 224 // If a referenced surface does not have a corresponding active frame in the
219 // display compositor, then it blocks this frame. 225 // display compositor, then it blocks this frame.
220 if (!surface || !surface->HasActiveFrame()) 226 if (!surface || !surface->HasActiveFrame())
221 new_blocking_surfaces.insert(surface_id); 227 new_blocking_surfaces.insert(surface_id);
222 } 228 }
223 229
224 // If this Surface has a previous pending frame, then we must determine the 230 // If this Surface has a previous pending frame, then we must determine the
225 // changes in dependencies so that we can update the SurfaceDependencyTracker 231 // changes in dependencies so that we can update the SurfaceDependencyTracker
226 // map. 232 // map.
227 if (has_previous_pending_frame) { 233 if (has_previous_pending_frame) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 311 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) {
306 base::EraseIf(destruction_dependencies_, 312 base::EraseIf(destruction_dependencies_,
307 [sequences, valid_frame_sink_ids](SurfaceSequence seq) { 313 [sequences, valid_frame_sink_ids](SurfaceSequence seq) {
308 return (!!sequences->erase(seq) || 314 return (!!sequences->erase(seq) ||
309 !valid_frame_sink_ids->count(seq.frame_sink_id)); 315 !valid_frame_sink_ids->count(seq.frame_sink_id));
310 }); 316 });
311 } 317 }
312 318
313 void Surface::UnrefFrameResourcesAndRunDrawCallback( 319 void Surface::UnrefFrameResourcesAndRunDrawCallback(
314 base::Optional<FrameData> frame_data) { 320 base::Optional<FrameData> frame_data) {
315 if (!frame_data || !factory_) 321 if (!frame_data || !compositor_frame_sink_support_)
316 return; 322 return;
317 323
318 ReturnedResourceArray resources; 324 ReturnedResourceArray resources;
319 TransferableResource::ReturnResources(frame_data->frame.resource_list, 325 TransferableResource::ReturnResources(frame_data->frame.resource_list,
320 &resources); 326 &resources);
321 // No point in returning same sync token to sender. 327 // No point in returning same sync token to sender.
322 for (auto& resource : resources) 328 for (auto& resource : resources)
323 resource.sync_token.Clear(); 329 resource.sync_token.Clear();
324 factory_->UnrefResources(resources); 330 compositor_frame_sink_support_->UnrefResources(resources);
325 331
326 if (!frame_data->draw_callback.is_null()) 332 if (!frame_data->draw_callback.is_null())
327 frame_data->draw_callback.Run(); 333 frame_data->draw_callback.Run();
328 } 334 }
329 335
330 void Surface::ClearCopyRequests() { 336 void Surface::ClearCopyRequests() {
331 if (active_frame_data_) { 337 if (active_frame_data_) {
332 for (const auto& render_pass : active_frame_data_->frame.render_pass_list) { 338 for (const auto& render_pass : active_frame_data_->frame.render_pass_list) {
333 for (const auto& copy_request : render_pass->copy_requests) 339 for (const auto& copy_request : render_pass->copy_requests)
334 copy_request->SendEmptyResult(); 340 copy_request->SendEmptyResult();
(...skipping 16 matching lines...) Expand all
351 frame->metadata.latency_info.swap(*latency_info); 357 frame->metadata.latency_info.swap(*latency_info);
352 return; 358 return;
353 } 359 }
354 std::copy(frame->metadata.latency_info.begin(), 360 std::copy(frame->metadata.latency_info.begin(),
355 frame->metadata.latency_info.end(), 361 frame->metadata.latency_info.end(),
356 std::back_inserter(*latency_info)); 362 std::back_inserter(*latency_info));
357 frame->metadata.latency_info.clear(); 363 frame->metadata.latency_info.clear();
358 } 364 }
359 365
360 } // namespace cc 366 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698