OLD | NEW |
---|---|
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 14 matching lines...) Expand all Loading... | |
25 #include "cc/surfaces/surface_reference_factory.h" | 25 #include "cc/surfaces/surface_reference_factory.h" |
26 #include "cc/surfaces/surface_sequence.h" | 26 #include "cc/surfaces/surface_sequence.h" |
27 #include "cc/surfaces/surfaces_export.h" | 27 #include "cc/surfaces/surfaces_export.h" |
28 | 28 |
29 #if DCHECK_IS_ON() | 29 #if DCHECK_IS_ON() |
30 #include <iosfwd> | 30 #include <iosfwd> |
31 #include <string> | 31 #include <string> |
32 #endif | 32 #endif |
33 | 33 |
34 namespace cc { | 34 namespace cc { |
35 class BeginFrameSource; | |
36 class CompositorFrame; | |
37 class Surface; | 35 class Surface; |
38 class SurfaceFactoryClient; | |
39 | 36 |
40 class CC_SURFACES_EXPORT SurfaceManager { | 37 class CC_SURFACES_EXPORT SurfaceManager { |
41 public: | 38 public: |
42 enum class LifetimeType { | 39 enum class LifetimeType { |
43 REFERENCES, | 40 REFERENCES, |
44 SEQUENCES, | 41 SEQUENCES, |
45 }; | 42 }; |
46 | 43 |
47 explicit SurfaceManager(LifetimeType lifetime_type = LifetimeType::SEQUENCES); | 44 explicit SurfaceManager(LifetimeType lifetime_type = LifetimeType::SEQUENCES); |
48 ~SurfaceManager(); | 45 ~SurfaceManager(); |
(...skipping 25 matching lines...) Expand all Loading... | |
74 | 71 |
75 // Require that the given sequence number must be satisfied (using | 72 // Require that the given sequence number must be satisfied (using |
76 // SatisfySequence) before the given surface can be destroyed. | 73 // SatisfySequence) before the given surface can be destroyed. |
77 void RequireSequence(const SurfaceId& surface_id, | 74 void RequireSequence(const SurfaceId& surface_id, |
78 const SurfaceSequence& sequence); | 75 const SurfaceSequence& sequence); |
79 | 76 |
80 // Satisfies the given sequence number. Once all sequence numbers that | 77 // Satisfies the given sequence number. Once all sequence numbers that |
81 // a surface depends on are satisfied, the surface can be destroyed. | 78 // a surface depends on are satisfied, the surface can be destroyed. |
82 void SatisfySequence(const SurfaceSequence& sequence); | 79 void SatisfySequence(const SurfaceSequence& sequence); |
83 | 80 |
84 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); | 81 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); |
Fady Samuel
2017/02/12 19:04:08
It seems strange to leave this here. What about mo
k.devara
2017/02/13 06:52:00
Yes- sorry I think the dfn still stayed back in su
| |
85 | 82 |
86 // Invalidate a frame_sink_id that might still have associated sequences, | |
87 // possibly because a renderer process has crashed. | |
88 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id); | |
89 | |
90 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered | |
91 // and unregistered in any order with respect to each other. | |
92 // | |
93 // This happens in practice, e.g. the relationship to between ui::Compositor / | |
94 // DelegatedFrameHost is known before ui::Compositor has a surface/client). | |
95 // However, DelegatedFrameHost can register itself as a client before its | |
96 // relationship with the ui::Compositor is known. | |
97 | |
98 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it | |
99 // uses. | |
100 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. | |
101 // Caller guarantees the client is alive between register/unregister. | |
102 // Reregistering the same namespace when a previous client is active is not | |
103 // valid. | |
104 void RegisterSurfaceFactoryClient(const FrameSinkId& frame_sink_id, | |
105 SurfaceFactoryClient* client); | |
106 void UnregisterSurfaceFactoryClient(const FrameSinkId& frame_sink_id); | |
107 | |
108 // Associates a |source| with a particular namespace. That namespace and | |
109 // any children of that namespace with valid clients can potentially use | |
110 // that |source|. | |
111 void RegisterBeginFrameSource(BeginFrameSource* source, | |
112 const FrameSinkId& frame_sink_id); | |
113 void UnregisterBeginFrameSource(BeginFrameSource* source); | |
114 | |
115 // Register a relationship between two namespaces. This relationship means | |
116 // that surfaces from the child namespace will be displayed in the parent. | |
117 // Children are allowed to use any begin frame source that their parent can | |
118 // use. | |
119 void RegisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, | |
120 const FrameSinkId& child_frame_sink_id); | |
121 void UnregisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, | |
122 const FrameSinkId& child_frame_sink_id); | |
123 | |
124 // Returns the top level root SurfaceId. Surfaces that are not reachable | 83 // Returns the top level root SurfaceId. Surfaces that are not reachable |
125 // from the top level root may be garbage collected. It will not be a valid | 84 // from the top level root may be garbage collected. It will not be a valid |
126 // SurfaceId and will never correspond to a surface. | 85 // SurfaceId and will never correspond to a surface. |
127 const SurfaceId& GetRootSurfaceId() const; | 86 const SurfaceId& GetRootSurfaceId() const; |
128 | 87 |
129 // Adds a reference from |parent_id| to |child_id|. If there is a temporary | 88 // Adds a reference from |parent_id| to |child_id|. If there is a temporary |
130 // references for |child_id| then it will be removed. | 89 // references for |child_id| then it will be removed. |
131 void AddSurfaceReference(const SurfaceId& parent_id, | 90 void AddSurfaceReference(const SurfaceId& parent_id, |
132 const SurfaceId& child_id); | 91 const SurfaceId& child_id); |
133 | 92 |
(...skipping 11 matching lines...) Expand all Loading... | |
145 | 104 |
146 scoped_refptr<SurfaceReferenceFactory> reference_factory() { | 105 scoped_refptr<SurfaceReferenceFactory> reference_factory() { |
147 return reference_factory_; | 106 return reference_factory_; |
148 } | 107 } |
149 | 108 |
150 private: | 109 private: |
151 friend class SurfaceManagerRefTest; | 110 friend class SurfaceManagerRefTest; |
152 | 111 |
153 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; | 112 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
154 | 113 |
155 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, | |
156 BeginFrameSource* source); | |
157 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, | |
158 BeginFrameSource* source); | |
159 | |
160 // Returns true if |child namespace| is or has |search_frame_sink_id| as a | |
161 // child. | |
162 bool ChildContains(const FrameSinkId& child_frame_sink_id, | |
163 const FrameSinkId& search_frame_sink_id) const; | |
164 | |
165 // Garbage collects all destroyed surfaces that aren't live. | 114 // Garbage collects all destroyed surfaces that aren't live. |
166 void GarbageCollectSurfaces(); | 115 void GarbageCollectSurfaces(); |
167 | 116 |
168 // Returns set of live surfaces for |lifetime_manager_| is REFERENCES. | 117 // Returns set of live surfaces for |lifetime_manager_| is REFERENCES. |
169 SurfaceIdSet GetLiveSurfacesForReferences(); | 118 SurfaceIdSet GetLiveSurfacesForReferences(); |
170 | 119 |
171 // Returns set of live surfaces for |lifetime_manager_| is SEQUENCES. | 120 // Returns set of live surfaces for |lifetime_manager_| is SEQUENCES. |
172 SurfaceIdSet GetLiveSurfacesForSequences(); | 121 SurfaceIdSet GetLiveSurfacesForSequences(); |
173 | 122 |
174 // Adds a reference from |parent_id| to |child_id| without dealing with | 123 // Adds a reference from |parent_id| to |child_id| without dealing with |
(...skipping 26 matching lines...) Expand all Loading... | |
201 | 150 |
202 // List of surfaces to be destroyed, along with what sequences they're still | 151 // List of surfaces to be destroyed, along with what sequences they're still |
203 // waiting on. | 152 // waiting on. |
204 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | 153 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; |
205 SurfaceDestroyList surfaces_to_destroy_; | 154 SurfaceDestroyList surfaces_to_destroy_; |
206 | 155 |
207 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 156 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
208 // waited on. | 157 // waited on. |
209 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 158 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
210 | 159 |
211 // Set of valid surface ID namespaces. When a namespace is removed from | |
212 // this set, any remaining sequences with that namespace are considered | |
213 // satisfied. | |
214 std::unordered_set<FrameSinkId, FrameSinkIdHash> valid_frame_sink_ids_; | |
215 | |
216 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient | |
217 // pointers guaranteed alive by callers until unregistered. | |
218 struct FrameSinkSourceMapping { | |
219 FrameSinkSourceMapping(); | |
220 FrameSinkSourceMapping(const FrameSinkSourceMapping& other); | |
221 ~FrameSinkSourceMapping(); | |
222 bool is_empty() const { return !client && children.empty(); } | |
223 // The client that's responsible for creating this namespace. Never null. | |
224 SurfaceFactoryClient* client; | |
225 // The currently assigned begin frame source for this client. | |
226 BeginFrameSource* source; | |
227 // This represents a dag of parent -> children mapping. | |
228 std::vector<FrameSinkId> children; | |
229 }; | |
230 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> | |
231 frame_sink_source_map_; | |
232 | |
233 // Tracks references from the child surface to parent surface. If there are | 160 // Tracks references from the child surface to parent surface. If there are |
234 // zero entries in the set for a SurfaceId then nothing is referencing the | 161 // zero entries in the set for a SurfaceId then nothing is referencing the |
235 // surface and it can be garbage collected. | 162 // surface and it can be garbage collected. |
236 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> | 163 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
237 child_to_parent_refs_; | 164 child_to_parent_refs_; |
238 // Tracks references from the parent surface to child surface. Is the inverse | 165 // Tracks references from the parent surface to child surface. Is the inverse |
239 // of |child_to_parent_refs_|. | 166 // of |child_to_parent_refs_|. |
240 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> | 167 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
241 parent_to_child_refs_; | 168 parent_to_child_refs_; |
242 | 169 |
243 // Set of which sources are registered to which namespace. Any child | |
244 // that is implicitly using this namespace must be reachable by the | |
245 // parent in the dag. | |
246 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; | |
247 | |
248 // Root SurfaceId that references display root surfaces. There is no Surface | 170 // Root SurfaceId that references display root surfaces. There is no Surface |
249 // with this id, it's for bookkeeping purposes only. | 171 // with this id, it's for bookkeeping purposes only. |
250 const SurfaceId root_surface_id_; | 172 const SurfaceId root_surface_id_; |
251 | 173 |
252 // The DirectSurfaceReferenceFactory that uses this manager to create surface | 174 // The DirectSurfaceReferenceFactory that uses this manager to create surface |
253 // references. | 175 // references. |
254 scoped_refptr<SurfaceReferenceFactory> reference_factory_; | 176 scoped_refptr<SurfaceReferenceFactory> reference_factory_; |
255 | 177 |
256 // SurfaceIds that have temporary references from top level root so they | 178 // SurfaceIds that have temporary references from top level root so they |
257 // aren't GC'd before a real reference is added. This is basically a | 179 // aren't GC'd before a real reference is added. This is basically a |
258 // collection of surface ids, for example: | 180 // collection of surface ids, for example: |
259 // SurfaceId surface_id(key, value[index]); | 181 // SurfaceId surface_id(key, value[index]); |
260 // The LocalSurfaceIds are stored in the order the surfaces are created in. | 182 // The LocalSurfaceIds are stored in the order the surfaces are created in. |
261 std::unordered_map<FrameSinkId, std::vector<LocalSurfaceId>, FrameSinkIdHash> | 183 std::unordered_map<FrameSinkId, std::vector<LocalSurfaceId>, FrameSinkIdHash> |
262 temp_references_; | 184 temp_references_; |
263 | 185 |
264 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 186 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
265 | 187 |
266 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 188 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
267 }; | 189 }; |
268 | 190 |
269 } // namespace cc | 191 } // namespace cc |
270 | 192 |
271 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 193 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |