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> | |
11 #include <memory> | 10 #include <memory> |
11 #include <set> | |
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/containers/flat_set.h" | 16 #include "base/containers/flat_set.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
21 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 #if DCHECK_IS_ON() | 60 #if DCHECK_IS_ON() |
61 // Returns a string representation of all reachable surface references. | 61 // Returns a string representation of all reachable surface references. |
62 std::string SurfaceReferencesToString(); | 62 std::string SurfaceReferencesToString(); |
63 #endif | 63 #endif |
64 | 64 |
65 void SetDependencyTracker(SurfaceDependencyTracker* dependency_tracker); | 65 void SetDependencyTracker(SurfaceDependencyTracker* dependency_tracker); |
66 SurfaceDependencyTracker* dependency_tracker() { return dependency_tracker_; } | 66 SurfaceDependencyTracker* dependency_tracker() { return dependency_tracker_; } |
67 | 67 |
68 void RequestSurfaceResolution(Surface* pending_surface); | 68 void RequestSurfaceResolution(Surface* pending_surface); |
69 | 69 |
70 std::unique_ptr<Surface> CreateSurface( | 70 base::WeakPtr<Surface> CreateSurface( |
71 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, | 71 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, |
72 const SurfaceInfo& surface_info); | 72 const SurfaceInfo& surface_info); |
73 | 73 |
74 // Destroy the Surface once a set of sequence numbers has been satisfied. | 74 // Destroy the Surface once a set of sequence numbers has been satisfied. |
75 void DestroySurface(std::unique_ptr<Surface> surface); | 75 void DestroySurface(Surface* surface); |
kylechar
2017/06/16 19:13:30
Can this just take a SurfaceId instead of a Surfac
Saman Sami
2017/06/19 22:16:46
Done.
| |
76 | 76 |
77 Surface* GetSurfaceForId(const SurfaceId& surface_id); | 77 Surface* GetSurfaceForId(const SurfaceId& surface_id); |
78 | 78 |
79 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } | 79 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } |
80 | 80 |
81 void RemoveObserver(SurfaceObserver* obs) { | 81 void RemoveObserver(SurfaceObserver* obs) { |
82 observer_list_.RemoveObserver(obs); | 82 observer_list_.RemoveObserver(obs); |
83 } | 83 } |
84 | 84 |
85 // Called when a Surface is modified, e.g. when a CompositorFrame is | 85 // Called when a Surface is modified, e.g. when a CompositorFrame is |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 | 250 |
251 // Adds a temporary reference to |surface_id|. The reference will not have an | 251 // Adds a temporary reference to |surface_id|. The reference will not have an |
252 // owner initially. | 252 // owner initially. |
253 void AddTemporaryReference(const SurfaceId& surface_id); | 253 void AddTemporaryReference(const SurfaceId& surface_id); |
254 | 254 |
255 // Removes temporary reference to |surface_id|. If |remove_range| is true then | 255 // Removes temporary reference to |surface_id|. If |remove_range| is true then |
256 // all temporary references to surfaces with the same FrameSinkId as | 256 // all temporary references to surfaces with the same FrameSinkId as |
257 // |surface_id| that were added before |surface_id| will also be removed. | 257 // |surface_id| that were added before |surface_id| will also be removed. |
258 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); | 258 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); |
259 | 259 |
260 // Called when a surface is destroyed and it needs to be removed from the | 260 // Called by the garbage collector when a surafce needs to be destroyed. |
261 // surface map. | 261 void DestroySurfaceInternal(const SurfaceId& surface_id); |
262 void UnregisterSurface(const SurfaceId& surface_id); | |
263 | 262 |
264 #if DCHECK_IS_ON() | 263 #if DCHECK_IS_ON() |
265 // Recursively prints surface references starting at |surface_id| to |str|. | 264 // Recursively prints surface references starting at |surface_id| to |str|. |
266 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, | 265 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, |
267 std::string indent, | 266 std::string indent, |
268 std::stringstream* str); | 267 std::stringstream* str); |
269 #endif | 268 #endif |
270 | 269 |
271 // Use reference or sequence based lifetime management. | 270 // Use reference or sequence based lifetime management. |
272 LifetimeType lifetime_type_; | 271 LifetimeType lifetime_type_; |
273 | 272 |
274 FrameSinkManager framesink_manager_; | 273 FrameSinkManager framesink_manager_; |
275 | 274 |
276 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 275 using SurfaceMap = |
276 std::unordered_map<SurfaceId, std::unique_ptr<Surface>, SurfaceIdHash>; | |
277 SurfaceMap surface_map_; | 277 SurfaceMap surface_map_; |
278 base::ObserverList<SurfaceObserver> observer_list_; | 278 base::ObserverList<SurfaceObserver> observer_list_; |
279 base::ThreadChecker thread_checker_; | 279 base::ThreadChecker thread_checker_; |
280 | 280 |
281 // List of surfaces to be destroyed, along with what sequences they're still | 281 std::set<Surface*> surfaces_to_destroy_; |
kylechar
2017/06/16 19:13:30
Can you use base::flat_set here? This should almos
Saman Sami
2017/06/19 22:16:46
Done.
| |
282 // waiting on. | |
283 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | |
284 SurfaceDestroyList surfaces_to_destroy_; | |
285 | 282 |
286 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 283 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
287 // waited on. | 284 // waited on. |
288 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 285 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
289 | 286 |
290 // Root SurfaceId that references display root surfaces. There is no Surface | 287 // Root SurfaceId that references display root surfaces. There is no Surface |
291 // with this id, it's for bookkeeping purposes only. | 288 // with this id, it's for bookkeeping purposes only. |
292 const SurfaceId root_surface_id_; | 289 const SurfaceId root_surface_id_; |
293 | 290 |
294 // Always empty set that is returned when there is no entry in |references_| | 291 // Always empty set that is returned when there is no entry in |references_| |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 SurfaceDependencyTracker* dependency_tracker_ = nullptr; | 323 SurfaceDependencyTracker* dependency_tracker_ = nullptr; |
327 | 324 |
328 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 325 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
329 | 326 |
330 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 327 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
331 }; | 328 }; |
332 | 329 |
333 } // namespace cc | 330 } // namespace cc |
334 | 331 |
335 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 332 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |