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> |
12 #include <unordered_map> | 11 #include <unordered_map> |
13 #include <unordered_set> | 12 #include <unordered_set> |
14 #include <vector> | 13 #include <vector> |
15 | 14 |
| 15 #include "base/containers/flat_map.h" |
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" |
22 #include "cc/surfaces/frame_sink_id.h" | 22 #include "cc/surfaces/frame_sink_id.h" |
23 #include "cc/surfaces/frame_sink_manager.h" | 23 #include "cc/surfaces/frame_sink_manager.h" |
24 #include "cc/surfaces/surface_dependency_tracker.h" | 24 #include "cc/surfaces/surface_dependency_tracker.h" |
25 #include "cc/surfaces/surface_id.h" | 25 #include "cc/surfaces/surface_id.h" |
(...skipping 34 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 // Creates a Surface for the given CompositorFrameSinkSupport. The surface |
| 71 // will be destroyed when DestroySurface is called, all of its destruction |
| 72 // dependencies are satisfied, and it is not reachable from the root surface. |
| 73 Surface* CreateSurface( |
71 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, | 74 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, |
72 const SurfaceInfo& surface_info); | 75 const SurfaceInfo& surface_info); |
73 | 76 |
74 // Destroy the Surface once a set of sequence numbers has been satisfied. | 77 // Destroy the Surface once a set of sequence numbers has been satisfied. |
75 void DestroySurface(std::unique_ptr<Surface> surface); | 78 void DestroySurface(const SurfaceId& surface_id); |
76 | 79 |
77 // Called when a surface has been added to the aggregated CompositorFrame | 80 // Called when a surface has been added to the aggregated CompositorFrame |
78 // and will notify observers with SurfaceObserver::OnSurfaceWillDraw. | 81 // and will notify observers with SurfaceObserver::OnSurfaceWillDraw. |
79 void SurfaceWillDraw(const SurfaceId& surface_id); | 82 void SurfaceWillDraw(const SurfaceId& surface_id); |
80 | 83 |
81 Surface* GetSurfaceForId(const SurfaceId& surface_id); | 84 Surface* GetSurfaceForId(const SurfaceId& surface_id); |
82 | 85 |
83 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } | 86 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } |
84 | 87 |
85 void RemoveObserver(SurfaceObserver* obs) { | 88 void RemoveObserver(SurfaceObserver* obs) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 257 |
255 // Adds a temporary reference to |surface_id|. The reference will not have an | 258 // Adds a temporary reference to |surface_id|. The reference will not have an |
256 // owner initially. | 259 // owner initially. |
257 void AddTemporaryReference(const SurfaceId& surface_id); | 260 void AddTemporaryReference(const SurfaceId& surface_id); |
258 | 261 |
259 // Removes temporary reference to |surface_id|. If |remove_range| is true then | 262 // Removes temporary reference to |surface_id|. If |remove_range| is true then |
260 // all temporary references to surfaces with the same FrameSinkId as | 263 // all temporary references to surfaces with the same FrameSinkId as |
261 // |surface_id| that were added before |surface_id| will also be removed. | 264 // |surface_id| that were added before |surface_id| will also be removed. |
262 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); | 265 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); |
263 | 266 |
264 // Called when a surface is destroyed and it needs to be removed from the | 267 // Removes the surface from the surface map and destroys it. |
265 // surface map. | 268 void DestroySurfaceInternal(const SurfaceId& surface_id); |
266 void UnregisterSurface(const SurfaceId& surface_id); | |
267 | 269 |
268 #if DCHECK_IS_ON() | 270 #if DCHECK_IS_ON() |
269 // Recursively prints surface references starting at |surface_id| to |str|. | 271 // Recursively prints surface references starting at |surface_id| to |str|. |
270 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, | 272 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, |
271 std::string indent, | 273 std::string indent, |
272 std::stringstream* str); | 274 std::stringstream* str); |
273 #endif | 275 #endif |
274 | 276 |
| 277 // Returns true if |surface_id| is in the garbage collector's queue. |
| 278 bool IsMarkedForDestruction(const SurfaceId& surface_id); |
| 279 |
275 // Use reference or sequence based lifetime management. | 280 // Use reference or sequence based lifetime management. |
276 LifetimeType lifetime_type_; | 281 LifetimeType lifetime_type_; |
277 | 282 |
278 FrameSinkManager framesink_manager_; | 283 FrameSinkManager framesink_manager_; |
279 | 284 |
280 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 285 base::flat_map<SurfaceId, std::unique_ptr<Surface>> surface_map_; |
281 SurfaceMap surface_map_; | |
282 base::ObserverList<SurfaceObserver> observer_list_; | 286 base::ObserverList<SurfaceObserver> observer_list_; |
283 base::ThreadChecker thread_checker_; | 287 base::ThreadChecker thread_checker_; |
284 | 288 |
285 // List of surfaces to be destroyed, along with what sequences they're still | 289 base::flat_set<SurfaceId> surfaces_to_destroy_; |
286 // waiting on. | |
287 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | |
288 SurfaceDestroyList surfaces_to_destroy_; | |
289 | 290 |
290 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 291 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
291 // waited on. | 292 // waited on. |
292 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 293 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
293 | 294 |
294 // Root SurfaceId that references display root surfaces. There is no Surface | 295 // Root SurfaceId that references display root surfaces. There is no Surface |
295 // with this id, it's for bookkeeping purposes only. | 296 // with this id, it's for bookkeeping purposes only. |
296 const SurfaceId root_surface_id_; | 297 const SurfaceId root_surface_id_; |
297 | 298 |
298 // Always empty set that is returned when there is no entry in |references_| | 299 // 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... |
330 SurfaceDependencyTracker* dependency_tracker_ = nullptr; | 331 SurfaceDependencyTracker* dependency_tracker_ = nullptr; |
331 | 332 |
332 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 333 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
333 | 334 |
334 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 335 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
335 }; | 336 }; |
336 | 337 |
337 } // namespace cc | 338 } // namespace cc |
338 | 339 |
339 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 340 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |