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> |
11 #include <memory> | 11 #include <memory> |
12 #include <unordered_map> | 12 #include <unordered_map> |
13 #include <unordered_set> | 13 #include <unordered_set> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
21 #include "cc/surfaces/frame_sink_id.h" | 21 #include "cc/surfaces/frame_sink_id.h" |
| 22 #include "cc/surfaces/framesink_manager.h" |
22 #include "cc/surfaces/surface_dependency_tracker.h" | 23 #include "cc/surfaces/surface_dependency_tracker.h" |
23 #include "cc/surfaces/surface_id.h" | 24 #include "cc/surfaces/surface_id.h" |
24 #include "cc/surfaces/surface_observer.h" | 25 #include "cc/surfaces/surface_observer.h" |
25 #include "cc/surfaces/surface_reference.h" | 26 #include "cc/surfaces/surface_reference.h" |
26 #include "cc/surfaces/surface_reference_factory.h" | 27 #include "cc/surfaces/surface_reference_factory.h" |
27 #include "cc/surfaces/surface_sequence.h" | 28 #include "cc/surfaces/surface_sequence.h" |
28 #include "cc/surfaces/surfaces_export.h" | 29 #include "cc/surfaces/surfaces_export.h" |
29 | 30 |
30 #if DCHECK_IS_ON() | 31 #if DCHECK_IS_ON() |
31 #include <iosfwd> | 32 #include <iosfwd> |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 bool using_surface_references() const { | 169 bool using_surface_references() const { |
169 return lifetime_type_ == LifetimeType::REFERENCES; | 170 return lifetime_type_ == LifetimeType::REFERENCES; |
170 } | 171 } |
171 | 172 |
172 private: | 173 private: |
173 friend class test::CompositorFrameSinkSupportTest; | 174 friend class test::CompositorFrameSinkSupportTest; |
174 friend class SurfaceManagerRefTest; | 175 friend class SurfaceManagerRefTest; |
175 | 176 |
176 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; | 177 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
177 | 178 |
178 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, | |
179 BeginFrameSource* source); | |
180 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, | |
181 BeginFrameSource* source); | |
182 | |
183 // Returns true if |child namespace| is or has |search_frame_sink_id| as a | |
184 // child. | |
185 bool ChildContains(const FrameSinkId& child_frame_sink_id, | |
186 const FrameSinkId& search_frame_sink_id) const; | |
187 | |
188 // Garbage collects all destroyed surfaces that aren't live. | 179 // Garbage collects all destroyed surfaces that aren't live. |
189 void GarbageCollectSurfaces(); | 180 void GarbageCollectSurfaces(); |
190 | 181 |
191 // Returns set of live surfaces for |lifetime_manager_| is REFERENCES. | 182 // Returns set of live surfaces for |lifetime_manager_| is REFERENCES. |
192 SurfaceIdSet GetLiveSurfacesForReferences(); | 183 SurfaceIdSet GetLiveSurfacesForReferences(); |
193 | 184 |
194 // Returns set of live surfaces for |lifetime_manager_| is SEQUENCES. | 185 // Returns set of live surfaces for |lifetime_manager_| is SEQUENCES. |
195 SurfaceIdSet GetLiveSurfacesForSequences(); | 186 SurfaceIdSet GetLiveSurfacesForSequences(); |
196 | 187 |
197 // Adds a reference from |parent_id| to |child_id| without dealing with | 188 // Adds a reference from |parent_id| to |child_id| without dealing with |
(...skipping 27 matching lines...) Expand all Loading... |
225 #if DCHECK_IS_ON() | 216 #if DCHECK_IS_ON() |
226 // Recursively prints surface references starting at |surface_id| to |str|. | 217 // Recursively prints surface references starting at |surface_id| to |str|. |
227 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, | 218 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, |
228 std::string indent, | 219 std::string indent, |
229 std::stringstream* str); | 220 std::stringstream* str); |
230 #endif | 221 #endif |
231 | 222 |
232 // Use reference or sequence based lifetime management. | 223 // Use reference or sequence based lifetime management. |
233 LifetimeType lifetime_type_; | 224 LifetimeType lifetime_type_; |
234 | 225 |
| 226 FrameSinkManager framesink_manager_; |
| 227 |
235 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 228 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; |
236 SurfaceMap surface_map_; | 229 SurfaceMap surface_map_; |
237 base::ObserverList<SurfaceObserver> observer_list_; | 230 base::ObserverList<SurfaceObserver> observer_list_; |
238 base::ThreadChecker thread_checker_; | 231 base::ThreadChecker thread_checker_; |
239 | 232 |
240 // List of surfaces to be destroyed, along with what sequences they're still | 233 // List of surfaces to be destroyed, along with what sequences they're still |
241 // waiting on. | 234 // waiting on. |
242 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | 235 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; |
243 SurfaceDestroyList surfaces_to_destroy_; | 236 SurfaceDestroyList surfaces_to_destroy_; |
244 | 237 |
245 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 238 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
246 // waited on. | 239 // waited on. |
247 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 240 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
248 | 241 |
249 // Set of valid surface ID namespaces. When a namespace is removed from | |
250 // this set, any remaining sequences with that namespace are considered | |
251 // satisfied. | |
252 std::unordered_set<FrameSinkId, FrameSinkIdHash> valid_frame_sink_ids_; | |
253 | |
254 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient | |
255 // pointers guaranteed alive by callers until unregistered. | |
256 struct FrameSinkSourceMapping { | |
257 FrameSinkSourceMapping(); | |
258 FrameSinkSourceMapping(const FrameSinkSourceMapping& other); | |
259 ~FrameSinkSourceMapping(); | |
260 bool has_children() const { return !children.empty(); } | |
261 // The currently assigned begin frame source for this client. | |
262 BeginFrameSource* source; | |
263 // This represents a dag of parent -> children mapping. | |
264 std::vector<FrameSinkId> children; | |
265 }; | |
266 | |
267 std::unordered_map<FrameSinkId, SurfaceFactoryClient*, FrameSinkIdHash> | |
268 clients_; | |
269 | |
270 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> | |
271 frame_sink_source_map_; | |
272 | |
273 // Tracks references from the child surface to parent surface. If there are | 242 // Tracks references from the child surface to parent surface. If there are |
274 // zero entries in the set for a SurfaceId then nothing is referencing the | 243 // zero entries in the set for a SurfaceId then nothing is referencing the |
275 // surface and it can be garbage collected. | 244 // surface and it can be garbage collected. |
276 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> | 245 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
277 child_to_parent_refs_; | 246 child_to_parent_refs_; |
278 // Tracks references from the parent surface to child surface. Is the inverse | 247 // Tracks references from the parent surface to child surface. Is the inverse |
279 // of |child_to_parent_refs_|. | 248 // of |child_to_parent_refs_|. |
280 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> | 249 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
281 parent_to_child_refs_; | 250 parent_to_child_refs_; |
282 | 251 |
283 // Set of which sources are registered to which namespace. Any child | |
284 // that is implicitly using this namespace must be reachable by the | |
285 // parent in the dag. | |
286 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; | |
287 | |
288 // Root SurfaceId that references display root surfaces. There is no Surface | 252 // Root SurfaceId that references display root surfaces. There is no Surface |
289 // with this id, it's for bookkeeping purposes only. | 253 // with this id, it's for bookkeeping purposes only. |
290 const SurfaceId root_surface_id_; | 254 const SurfaceId root_surface_id_; |
291 | 255 |
292 // The DirectSurfaceReferenceFactory that uses this manager to create surface | 256 // The DirectSurfaceReferenceFactory that uses this manager to create surface |
293 // references. | 257 // references. |
294 scoped_refptr<SurfaceReferenceFactory> reference_factory_; | 258 scoped_refptr<SurfaceReferenceFactory> reference_factory_; |
295 | 259 |
296 // A map of surfaces that have temporary references to them. The key is the | 260 // A map of surfaces that have temporary references to them. The key is the |
297 // SurfaceId and the value is the owner. The owner will initially be empty and | 261 // SurfaceId and the value is the owner. The owner will initially be empty and |
(...skipping 16 matching lines...) Expand all Loading... |
314 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_; | 278 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_; |
315 | 279 |
316 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 280 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
317 | 281 |
318 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 282 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
319 }; | 283 }; |
320 | 284 |
321 } // namespace cc | 285 } // namespace cc |
322 | 286 |
323 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 287 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |