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

Side by Side Diff: cc/surfaces/surface_manager.h

Issue 2716553004: Add temporary reference ownership to SurfaceManager. (Closed)
Patch Set: Cleanup. 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
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 #ifndef CC_SURFACES_SURFACE_MANAGER_H_ 5 #ifndef CC_SURFACES_SURFACE_MANAGER_H_
6 #define CC_SURFACES_SURFACE_MANAGER_H_ 6 #define CC_SURFACES_SURFACE_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void RegisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, 132 void RegisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id,
133 const FrameSinkId& child_frame_sink_id); 133 const FrameSinkId& child_frame_sink_id);
134 void UnregisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, 134 void UnregisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id,
135 const FrameSinkId& child_frame_sink_id); 135 const FrameSinkId& child_frame_sink_id);
136 136
137 // Returns the top level root SurfaceId. Surfaces that are not reachable 137 // Returns the top level root SurfaceId. Surfaces that are not reachable
138 // from the top level root may be garbage collected. It will not be a valid 138 // from the top level root may be garbage collected. It will not be a valid
139 // SurfaceId and will never correspond to a surface. 139 // SurfaceId and will never correspond to a surface.
140 const SurfaceId& GetRootSurfaceId() const; 140 const SurfaceId& GetRootSurfaceId() const;
141 141
142 // Adds a reference from |parent_id| to |child_id|. If there is a temporary
143 // references for |child_id| then it will be removed.
144 void AddSurfaceReference(const SurfaceId& parent_id,
145 const SurfaceId& child_id);
146
147 // Removes a reference from |parent_id| to |child_id|.
148 void RemoveSurfaceReference(const SurfaceId& parent_id,
149 const SurfaceId& child_id);
150
151 // Adds all surface references in |references|. This will remove any temporary 142 // Adds all surface references in |references|. This will remove any temporary
152 // references for child surface in a surface reference. 143 // references for child surface in a surface reference.
153 void AddSurfaceReferences(const std::vector<SurfaceReference>& references); 144 void AddSurfaceReferences(const std::vector<SurfaceReference>& references);
154 145
155 // Removes all surface references in |references| then runs garbage 146 // Removes all surface references in |references| then runs garbage
156 // collection to delete unreachable surfaces. 147 // collection to delete unreachable surfaces.
157 void RemoveSurfaceReferences(const std::vector<SurfaceReference>& references); 148 void RemoveSurfaceReferences(const std::vector<SurfaceReference>& references);
158 149
150 // Assigns |frame_sink_id| as the owner of the temporary reference to
151 // |surface_id|. If |frame_sink_id| is invalidated the temporary reference
152 // will be removed. If a surface reference has already been added from the
153 // parent to |surface_id| then this will do nothing.
154 void AssignTemporaryReference(const SurfaceId& surface_id,
155 const FrameSinkId& owner);
156
157 // Drops the temporary reference for |surface_id|. If a surface reference has
158 // already been added from the parent to |surface_id| then this will do
159 // nothing.
160 void DropTemporaryReference(const SurfaceId& surface_id);
161
159 scoped_refptr<SurfaceReferenceFactory> reference_factory() { 162 scoped_refptr<SurfaceReferenceFactory> reference_factory() {
160 return reference_factory_; 163 return reference_factory_;
161 } 164 }
162 165
163 bool using_surface_references() const { 166 bool using_surface_references() const {
164 return lifetime_type_ == LifetimeType::REFERENCES; 167 return lifetime_type_ == LifetimeType::REFERENCES;
165 } 168 }
166 169
167 private: 170 private:
168 friend class test::CompositorFrameSinkSupportTest; 171 friend class test::CompositorFrameSinkSupportTest;
(...skipping 26 matching lines...) Expand all
195 const SurfaceId& child_id); 198 const SurfaceId& child_id);
196 199
197 // Removes a reference from a |parent_id| to |child_id|. 200 // Removes a reference from a |parent_id| to |child_id|.
198 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, 201 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id,
199 const SurfaceId& child_id); 202 const SurfaceId& child_id);
200 203
201 // Removes all surface references to or from |surface_id|. Used when the 204 // Removes all surface references to or from |surface_id|. Used when the
202 // surface is about to be deleted. 205 // surface is about to be deleted.
203 void RemoveAllSurfaceReferences(const SurfaceId& surface_id); 206 void RemoveAllSurfaceReferences(const SurfaceId& surface_id);
204 207
208 bool HasTemporaryReference(const SurfaceId& surface_id) const;
209
210 // Adds a temporary reference to |surface_id|. The reference will not have an
211 // owner initially.
212 void AddTemporaryReference(const SurfaceId& surface_id);
213
214 // Removes temporary reference to |surface_id|. If |remove_range| is true then
215 // all temporary references to surfaces with the same FrameSinkId as
216 // |surface_id| that were added before |surface_id| will also be removed.
217 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range);
218
205 #if DCHECK_IS_ON() 219 #if DCHECK_IS_ON()
206 // Recursively prints surface references starting at |surface_id| to |str|. 220 // Recursively prints surface references starting at |surface_id| to |str|.
207 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, 221 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id,
208 std::string indent, 222 std::string indent,
209 std::stringstream* str); 223 std::stringstream* str);
210 #endif 224 #endif
211 225
212 // Use reference or sequence based lifetime management. 226 // Use reference or sequence based lifetime management.
213 LifetimeType lifetime_type_; 227 LifetimeType lifetime_type_;
214 228
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; 278 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_;
265 279
266 // Root SurfaceId that references display root surfaces. There is no Surface 280 // Root SurfaceId that references display root surfaces. There is no Surface
267 // with this id, it's for bookkeeping purposes only. 281 // with this id, it's for bookkeeping purposes only.
268 const SurfaceId root_surface_id_; 282 const SurfaceId root_surface_id_;
269 283
270 // The DirectSurfaceReferenceFactory that uses this manager to create surface 284 // The DirectSurfaceReferenceFactory that uses this manager to create surface
271 // references. 285 // references.
272 scoped_refptr<SurfaceReferenceFactory> reference_factory_; 286 scoped_refptr<SurfaceReferenceFactory> reference_factory_;
273 287
274 // SurfaceIds that have temporary references from top level root so they 288 // A map of surfaces that have temporary references to them. The key is the
275 // aren't GC'd before a real reference is added. This is basically a 289 // SurfaceId and the value is the owner. The owner will initially be empty and
276 // collection of surface ids, for example: 290 // set later by AssignTemporaryReference().
291 std::unordered_map<SurfaceId, base::Optional<FrameSinkId>, SurfaceIdHash>
292 temporary_references_;
293
294 // Range tracking information for temporary references. Each map entry is an
295 // is an ordered list of SurfaceIds that have temporary references with the
296 // same FrameSinkId. A SurfaceId can be reconstructed with:
277 // SurfaceId surface_id(key, value[index]); 297 // SurfaceId surface_id(key, value[index]);
278 // The LocalSurfaceIds are stored in the order the surfaces are created in. 298 // The LocalSurfaceIds are stored in the order the surfaces are created in. If
299 // a reference is added to a later SurfaceId then all temporary references up
300 // to that point will be removed. This is to handle clients getting out of
301 // sync, for example the embedded client producing new SurfaceIds faster than
302 // the embedding client can use them.
279 std::unordered_map<FrameSinkId, std::vector<LocalSurfaceId>, FrameSinkIdHash> 303 std::unordered_map<FrameSinkId, std::vector<LocalSurfaceId>, FrameSinkIdHash>
280 temp_references_; 304 temporary_reference_ranges_;
281 305
282 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_; 306 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_;
283 307
284 base::WeakPtrFactory<SurfaceManager> weak_factory_; 308 base::WeakPtrFactory<SurfaceManager> weak_factory_;
285 309
286 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); 310 DISALLOW_COPY_AND_ASSIGN(SurfaceManager);
287 }; 311 };
288 312
289 } // namespace cc 313 } // namespace cc
290 314
291 #endif // CC_SURFACES_SURFACE_MANAGER_H_ 315 #endif // CC_SURFACES_SURFACE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698