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

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

Issue 2683953004: Revert of Move surface reference code to CompositorFrameSinkSupport. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/referenced_surface_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
8 #include <utility>
9 #include <vector>
10
11 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
12 #include "cc/scheduler/begin_frame_source.h" 8 #include "cc/scheduler/begin_frame_source.h"
13 #include "cc/surfaces/compositor_frame_sink_support_client.h" 9 #include "cc/surfaces/compositor_frame_sink_support_client.h"
14 #include "cc/surfaces/display.h" 10 #include "cc/surfaces/display.h"
15 #include "cc/surfaces/surface.h" 11 #include "cc/surfaces/surface.h"
16 #include "cc/surfaces/surface_manager.h" 12 #include "cc/surfaces/surface_manager.h"
17 #include "cc/surfaces/surface_reference.h"
18 13
19 namespace cc { 14 namespace cc {
20 15
21 CompositorFrameSinkSupport::CompositorFrameSinkSupport( 16 CompositorFrameSinkSupport::CompositorFrameSinkSupport(
22 CompositorFrameSinkSupportClient* client, 17 CompositorFrameSinkSupportClient* client,
23 SurfaceManager* surface_manager, 18 SurfaceManager* surface_manager,
24 const FrameSinkId& frame_sink_id, 19 const FrameSinkId& frame_sink_id,
25 Display* display, 20 Display* display,
26 bool handles_frame_sink_id_invalidation, 21 bool handles_frame_sink_id_invalidation,
27 bool needs_sync_points) 22 bool needs_sync_points)
28 : client_(client), 23 : client_(client),
29 surface_manager_(surface_manager), 24 surface_manager_(surface_manager),
30 frame_sink_id_(frame_sink_id), 25 frame_sink_id_(frame_sink_id),
31 display_(display), 26 display_(display),
32 surface_factory_(frame_sink_id_, surface_manager_, this), 27 surface_factory_(frame_sink_id_, surface_manager_, this),
33 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), 28 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation),
34 reference_tracker_(frame_sink_id),
35 weak_factory_(this) { 29 weak_factory_(this) {
36 if (handles_frame_sink_id_invalidation_) 30 if (handles_frame_sink_id_invalidation_)
37 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 31 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
38 32
39 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); 33 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
40 surface_factory_.set_needs_sync_points(needs_sync_points); 34 surface_factory_.set_needs_sync_points(needs_sync_points);
41 35
42 if (display_) 36 if (display_)
43 display_->Initialize(this, surface_manager_); 37 display_->Initialize(this, surface_manager_);
44 } 38 }
45 39
46 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { 40 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() {
47 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does 41 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does
48 // not call into |this| after it's deleted. 42 // not call into |this| after it's deleted.
49 SetNeedsBeginFrame(false); 43 SetNeedsBeginFrame(false);
50 44
51 // For display root surfaces, the surface is no longer going to be visible
52 // so make it unreachable from the top-level root.
53 if (surface_manager_->using_surface_references() && display_ &&
54 reference_tracker_.current_surface_id().is_valid())
55 RemoveTopLevelRootReference(reference_tracker_.current_surface_id());
56
57 for (auto& child_frame_sink_id : child_frame_sinks_) { 45 for (auto& child_frame_sink_id : child_frame_sinks_) {
58 DCHECK(child_frame_sink_id.is_valid()); 46 DCHECK(child_frame_sink_id.is_valid());
59 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, 47 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_,
60 child_frame_sink_id); 48 child_frame_sink_id);
61 } 49 }
62 // SurfaceFactory's destructor will attempt to return resources which will 50 // SurfaceFactory's destructor will attempt to return resources which will
63 // call back into here and access |client_| so we should destroy 51 // call back into here and access |client_| so we should destroy
64 // |surface_factory_|'s resources early on. 52 // |surface_factory_|'s resources early on.
65 surface_factory_.EvictSurface(); 53 surface_factory_.EvictSurface();
66 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 54 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
(...skipping 11 matching lines...) Expand all
78 } 66 }
79 67
80 void CompositorFrameSinkSupport::SubmitCompositorFrame( 68 void CompositorFrameSinkSupport::SubmitCompositorFrame(
81 const LocalSurfaceId& local_surface_id, 69 const LocalSurfaceId& local_surface_id,
82 CompositorFrame frame) { 70 CompositorFrame frame) {
83 ++ack_pending_count_; 71 ++ack_pending_count_;
84 if (display_) { 72 if (display_) {
85 display_->SetLocalSurfaceId(local_surface_id, 73 display_->SetLocalSurfaceId(local_surface_id,
86 frame.metadata.device_scale_factor); 74 frame.metadata.device_scale_factor);
87 } 75 }
88 76 surface_factory_.SubmitCompositorFrame(
89 if (surface_manager_->using_surface_references()) { 77 local_surface_id, std::move(frame),
90 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); 78 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
91 79 weak_factory_.GetWeakPtr()));
92 // Populate surface references to add/remove based on reference surfaces in
93 // current frame compared with the last frame.
94 reference_tracker_.UpdateReferences(local_surface_id,
95 frame.metadata.referenced_surfaces);
96
97 surface_factory_.SubmitCompositorFrame(
98 local_surface_id, std::move(frame),
99 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
100 weak_factory_.GetWeakPtr()));
101
102 UpdateSurfaceReferences(last_surface_id, local_surface_id);
103 } else {
104 surface_factory_.SubmitCompositorFrame(
105 local_surface_id, std::move(frame),
106 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
107 weak_factory_.GetWeakPtr()));
108 }
109 } 80 }
110 81
111 void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id, 82 void CompositorFrameSinkSupport::Require(const LocalSurfaceId& local_surface_id,
112 const SurfaceSequence& sequence) { 83 const SurfaceSequence& sequence) {
113 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_surface_id), 84 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_surface_id),
114 sequence); 85 sequence);
115 } 86 }
116 87
117 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { 88 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) {
118 surface_manager_->SatisfySequence(sequence); 89 surface_manager_->SatisfySequence(sequence);
119 } 90 }
120 91
121 void CompositorFrameSinkSupport::UpdateSurfaceReferences(
122 const SurfaceId& last_surface_id,
123 const LocalSurfaceId& local_surface_id) {
124 const bool surface_id_changed =
125 last_surface_id.local_surface_id() != local_surface_id;
126
127 // If this is a display root surface and the SurfaceId is changing, make the
128 // new SurfaceId reachable from the top-level root.
129 if (display_ && surface_id_changed)
130 AddTopLevelRootReference(reference_tracker_.current_surface_id());
131
132 // Add references based on CompositorFrame referenced surfaces. If the
133 // SurfaceId has changed all referenced surfaces will be in this list.
134 if (!reference_tracker_.references_to_add().empty()) {
135 surface_manager_->AddSurfaceReferences(
136 reference_tracker_.references_to_add());
137 }
138
139 // If this is a display root surface and the SurfaceId is changing, make the
140 // old SurfaceId unreachable from the top-level root. This needs to happen
141 // after adding all references for the new SurfaceId.
142 if (display_ && surface_id_changed && last_surface_id.is_valid())
143 RemoveTopLevelRootReference(last_surface_id);
144
145 // Remove references based on CompositorFrame referenced surfaces. If the
146 // SurfaceId has changed this list will be empty.
147 if (!reference_tracker_.references_to_remove().empty()) {
148 DCHECK(!surface_id_changed);
149 surface_manager_->RemoveSurfaceReferences(
150 reference_tracker_.references_to_remove());
151 }
152 }
153
154 void CompositorFrameSinkSupport::AddTopLevelRootReference(
155 const SurfaceId& surface_id) {
156 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
157 surface_manager_->AddSurfaceReferences({reference});
158 }
159
160 void CompositorFrameSinkSupport::RemoveTopLevelRootReference(
161 const SurfaceId& surface_id) {
162 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id);
163 surface_manager_->RemoveSurfaceReferences({reference});
164 }
165
166 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { 92 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() {
167 DCHECK_GT(ack_pending_count_, 0); 93 DCHECK_GT(ack_pending_count_, 0);
168 ack_pending_count_--; 94 ack_pending_count_--;
169 95
170 if (!client_) 96 if (!client_)
171 return; 97 return;
172 client_->DidReceiveCompositorFrameAck(); 98 client_->DidReceiveCompositorFrameAck();
173 if (!surface_returned_resources_.empty()) { 99 if (!surface_returned_resources_.empty()) {
174 client_->ReclaimResources(surface_returned_resources_); 100 client_->ReclaimResources(surface_returned_resources_);
175 surface_returned_resources_.clear(); 101 surface_returned_resources_.clear();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return; 184 return;
259 185
260 added_frame_observer_ = needs_begin_frame_; 186 added_frame_observer_ = needs_begin_frame_;
261 if (needs_begin_frame_) 187 if (needs_begin_frame_)
262 begin_frame_source_->AddObserver(this); 188 begin_frame_source_->AddObserver(this);
263 else 189 else
264 begin_frame_source_->RemoveObserver(this); 190 begin_frame_source_->RemoveObserver(this);
265 } 191 }
266 192
267 } // namespace cc 193 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.h ('k') | cc/surfaces/referenced_surface_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698