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

Unified Diff: cc/surfaces/surface_manager.h

Issue 2455663003: Add cc::Surface ref counting. (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: cc/surfaces/surface_manager.h
diff --git a/cc/surfaces/surface_manager.h b/cc/surfaces/surface_manager.h
index 9ba2eea2543043d8f7d06e6a5c9738185924b25d..a7f7de1b3ed0992a7c9ca24235759406b36f157e 100644
--- a/cc/surfaces/surface_manager.h
+++ b/cc/surfaces/surface_manager.h
@@ -66,6 +66,29 @@ class CC_SURFACES_EXPORT SurfaceManager {
// possibly because a renderer process has crashed.
void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id);
+ // Adds a reference from a parent surface to a child surface. This signifies
+ // the parent surface is embedding the child surface and the child surface
+ // is needed until the reference is removed.
+ void AddSurfaceIdReference(const SurfaceId& parent_id,
+ const SurfaceId& child_id);
+
+ // Removes a reference from a parent surface to a child surface. This signals
+ // the parent surface no longer needs the child surface.
+ void RemoveSurfaceIdReference(const SurfaceId& parent_id,
+ const SurfaceId& child_id);
+
+ // Removes all references to and from surfaces that were created for
+ // |frame_sink_id|.
+ void RemoveAllReferencesForFrameSink(const FrameSinkId& frame_sink_id);
+
+ // Returns the number of surfaces that have references to |surface_id|. When
+ // the count is zero nothing is referencing the surface and it may be garbage
+ // collected.
+ int CountSurfaceReferences(const SurfaceId& surface_id) const;
Fady Samuel 2016/10/27 04:14:49 nit: GetSurfaceReferenceCount?
kylechar 2016/10/27 21:14:10 Done.
+
+ // Returns the number of surfaces that |surface_id| refers to.
+ int CountSurfaceReferees(const SurfaceId& surface_id) const;
+
// SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered
// and unregistered in any order with respect to each other.
//
@@ -147,6 +170,17 @@ class CC_SURFACES_EXPORT SurfaceManager {
};
std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash>
frame_sink_source_map_;
+
+ using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>;
+ // References from the child surface to parent surface. If there are zero
+ // entries in the set for a SurfaceId then nothing is referencing the surface
+ // and it can be garbage collected.
+ std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
+ child_to_parent_refs_;
+ // References from the parent surface to child surface.
+ std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
+ parent_to_child_refs_;
+
// Set of which sources are registered to which namespace. Any child
// that is implicitly using this namespace must be reachable by the
// parent in the dag.

Powered by Google App Engine
This is Rietveld 408576698