Chromium Code Reviews| Index: cc/surfaces/surface_manager.h |
| diff --git a/cc/surfaces/surface_manager.h b/cc/surfaces/surface_manager.h |
| index 9ba2eea2543043d8f7d06e6a5c9738185924b25d..f9c817d3e81c6e21ef4f7da0607bd1abb87bdf2a 100644 |
| --- a/cc/surfaces/surface_manager.h |
| +++ b/cc/surfaces/surface_manager.h |
| @@ -30,6 +30,10 @@ class SurfaceFactoryClient; |
| class CC_SURFACES_EXPORT SurfaceManager { |
| public: |
| + // Root SurfaceId that references display root surfaces. There is no Surface |
| + // with this id, it's for bookkeeping purposes only. |
| + static const SurfaceId kRootSurfaceId; |
| + |
| SurfaceManager(); |
| ~SurfaceManager(); |
| @@ -66,6 +70,27 @@ 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. Any surface |
| + // embedding a child surface should have a reference added so that the child |
| + // surface is not garbage collected until after the parent surface. |
| + void AddSurfaceReference(const SurfaceId& parent_id, |
| + const SurfaceId& child_id); |
| + |
| + // Removes a reference from a parent surface to a child surface. If |
| + // |should_run_gc| is true and the child surface drops to zero references then |
| + // GC will run. |
| + void RemoveSurfaceReference(const SurfaceId& parent_id, |
| + const SurfaceId& child_id, |
| + bool should_run_gc = true); |
| + |
| + // 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. |
| + size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const; |
| + |
| + // Returns the number of surfaces that |surface_id| has references to. |
| + size_t GetSurfaceRefereeCount(const SurfaceId& surface_id) const; |
|
Fady Samuel
2016/11/02 03:10:36
I'm not a fan of the name, maybe GetReferencedSurf
kylechar
2016/11/02 13:58:59
Done.
|
| + |
| // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered |
| // and unregistered in any order with respect to each other. |
| // |
| @@ -147,6 +172,18 @@ class CC_SURFACES_EXPORT SurfaceManager { |
| }; |
| std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> |
| frame_sink_source_map_; |
| + |
| + using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
| + // Tracks 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_; |
| + // Tracks references from the parent surface to child surface. Is the inverse |
| + // of |child_to_parent_refs_|. |
| + 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. |