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

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

Issue 2455663003: Add cc::Surface ref counting. (Closed)
Patch Set: Address CL comments. Created 4 years, 1 month 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 12 matching lines...) Expand all
23 #include "cc/surfaces/surfaces_export.h" 23 #include "cc/surfaces/surfaces_export.h"
24 24
25 namespace cc { 25 namespace cc {
26 class BeginFrameSource; 26 class BeginFrameSource;
27 class CompositorFrame; 27 class CompositorFrame;
28 class Surface; 28 class Surface;
29 class SurfaceFactoryClient; 29 class SurfaceFactoryClient;
30 30
31 class CC_SURFACES_EXPORT SurfaceManager { 31 class CC_SURFACES_EXPORT SurfaceManager {
32 public: 32 public:
33 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>;
34
33 SurfaceManager(); 35 SurfaceManager();
34 ~SurfaceManager(); 36 ~SurfaceManager();
35 37
36 void RegisterSurface(Surface* surface); 38 void RegisterSurface(Surface* surface);
37 void DeregisterSurface(const SurfaceId& surface_id); 39 void DeregisterSurface(const SurfaceId& surface_id);
38 40
39 // Destroy the Surface once a set of sequence numbers has been satisfied. 41 // Destroy the Surface once a set of sequence numbers has been satisfied.
40 void Destroy(std::unique_ptr<Surface> surface); 42 void Destroy(std::unique_ptr<Surface> surface);
41 43
42 Surface* GetSurfaceForId(const SurfaceId& surface_id); 44 Surface* GetSurfaceForId(const SurfaceId& surface_id);
(...skipping 16 matching lines...) Expand all
59 // id namespace. 61 // id namespace.
60 void DidSatisfySequences(const FrameSinkId& frame_sink_id, 62 void DidSatisfySequences(const FrameSinkId& frame_sink_id,
61 std::vector<uint32_t>* sequence); 63 std::vector<uint32_t>* sequence);
62 64
63 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); 65 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id);
64 66
65 // Invalidate a frame_sink_id that might still have associated sequences, 67 // Invalidate a frame_sink_id that might still have associated sequences,
66 // possibly because a renderer process has crashed. 68 // possibly because a renderer process has crashed.
67 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id); 69 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id);
68 70
71 // Adds a reference from a parent surface to a child surface. This signifies
72 // the parent surface is embedding the child surface and the child surface
73 // is needed until the reference is removed.
74 void AddSurfaceIdReference(const SurfaceId& parent_id,
75 const SurfaceId& child_id);
76
77 // Removes a reference from a parent surface to a child surface. This signals
78 // the parent surface no longer needs the child surface. Will run GC if
79 // |should_run_gc| is true and child surface drops to zero references.
80 void RemoveSurfaceIdReference(const SurfaceId& parent_id,
81 const SurfaceId& child_id,
82 bool should_run_gc = true);
83
84 // Removes all references to and from surfaces that were created for
85 // |frame_sink_id|.
86 void RemoveAllReferencesForFrameSink(const FrameSinkId& frame_sink_id);
87 void RemoveAllReferencesForSurfaceId(const SurfaceId& surface_id);
88
89 // Returns the number of surfaces that have references to |surface_id|. When
90 // the count is zero nothing is referencing the surface and it may be garbage
91 // collected.
92 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const;
93
94 // Returns the number of surfaces that |surface_id| refers to.
95 size_t GetSurfaceRefereeCount(const SurfaceId& surface_id) const;
96
69 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered 97 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered
70 // and unregistered in any order with respect to each other. 98 // and unregistered in any order with respect to each other.
71 // 99 //
72 // This happens in practice, e.g. the relationship to between ui::Compositor / 100 // This happens in practice, e.g. the relationship to between ui::Compositor /
73 // DelegatedFrameHost is known before ui::Compositor has a surface/client). 101 // DelegatedFrameHost is known before ui::Compositor has a surface/client).
74 // However, DelegatedFrameHost can register itself as a client before its 102 // However, DelegatedFrameHost can register itself as a client before its
75 // relationship with the ui::Compositor is known. 103 // relationship with the ui::Compositor is known.
76 104
77 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it 105 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it
78 // uses. 106 // uses.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bool is_empty() const { return !client && children.empty(); } 168 bool is_empty() const { return !client && children.empty(); }
141 // The client that's responsible for creating this namespace. Never null. 169 // The client that's responsible for creating this namespace. Never null.
142 SurfaceFactoryClient* client; 170 SurfaceFactoryClient* client;
143 // The currently assigned begin frame source for this client. 171 // The currently assigned begin frame source for this client.
144 BeginFrameSource* source; 172 BeginFrameSource* source;
145 // This represents a dag of parent -> children mapping. 173 // This represents a dag of parent -> children mapping.
146 std::vector<FrameSinkId> children; 174 std::vector<FrameSinkId> children;
147 }; 175 };
148 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> 176 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash>
149 frame_sink_source_map_; 177 frame_sink_source_map_;
178
179 // References from the child surface to parent surface. If there are zero
180 // entries in the set for a SurfaceId then nothing is referencing the surface
181 // and it can be garbage collected.
182 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
183 child_to_parent_refs_;
184 // References from the parent surface to child surface.
185 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
186 parent_to_child_refs_;
187
150 // Set of which sources are registered to which namespace. Any child 188 // Set of which sources are registered to which namespace. Any child
151 // that is implicitly using this namespace must be reachable by the 189 // that is implicitly using this namespace must be reachable by the
152 // parent in the dag. 190 // parent in the dag.
153 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; 191 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_;
154 192
155 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); 193 DISALLOW_COPY_AND_ASSIGN(SurfaceManager);
156 }; 194 };
157 195
158 } // namespace cc 196 } // namespace cc
159 197
160 #endif // CC_SURFACES_SURFACE_MANAGER_H_ 198 #endif // CC_SURFACES_SURFACE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698