Chromium Code Reviews| 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 Surface* CreateSurface( |
|
Fady Samuel
2017/06/20 17:29:07
nit: Comment explaining ownership of Surface.
Saman Sami
2017/06/20 22:47:10
Done.
| |
| 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(const SurfaceId& surface_id); |
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 const SurfaceId& surface_id) const; | 200 const SurfaceId& surface_id) const; |
| 201 | 201 |
| 202 scoped_refptr<SurfaceReferenceFactory> reference_factory() { | 202 scoped_refptr<SurfaceReferenceFactory> reference_factory() { |
| 203 return reference_factory_; | 203 return reference_factory_; |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool using_surface_references() const { | 206 bool using_surface_references() const { |
| 207 return lifetime_type_ == LifetimeType::REFERENCES; | 207 return lifetime_type_ == LifetimeType::REFERENCES; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Returns true if |surface_id| is in the garbage collector's queue. | |
| 211 bool IsMarkedForDestruction(const SurfaceId& surface_id); | |
| 212 | |
| 210 private: | 213 private: |
| 211 friend class test::SurfaceSynchronizationTest; | 214 friend class test::SurfaceSynchronizationTest; |
| 212 friend class SurfaceManagerRefTest; | 215 friend class SurfaceManagerRefTest; |
| 213 | 216 |
| 214 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; | 217 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
| 215 | 218 |
| 216 struct SurfaceReferenceInfo { | 219 struct SurfaceReferenceInfo { |
| 217 SurfaceReferenceInfo(); | 220 SurfaceReferenceInfo(); |
| 218 ~SurfaceReferenceInfo(); | 221 ~SurfaceReferenceInfo(); |
| 219 | 222 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 250 | 253 |
| 251 // Adds a temporary reference to |surface_id|. The reference will not have an | 254 // Adds a temporary reference to |surface_id|. The reference will not have an |
| 252 // owner initially. | 255 // owner initially. |
| 253 void AddTemporaryReference(const SurfaceId& surface_id); | 256 void AddTemporaryReference(const SurfaceId& surface_id); |
| 254 | 257 |
| 255 // Removes temporary reference to |surface_id|. If |remove_range| is true then | 258 // Removes temporary reference to |surface_id|. If |remove_range| is true then |
| 256 // all temporary references to surfaces with the same FrameSinkId as | 259 // all temporary references to surfaces with the same FrameSinkId as |
| 257 // |surface_id| that were added before |surface_id| will also be removed. | 260 // |surface_id| that were added before |surface_id| will also be removed. |
| 258 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); | 261 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); |
| 259 | 262 |
| 260 // Called when a surface is destroyed and it needs to be removed from the | 263 // Removes the surface from the surface map and destroys it. |
| 261 // surface map. | 264 void DestroySurfaceInternal(const SurfaceId& surface_id); |
| 262 void UnregisterSurface(const SurfaceId& surface_id); | |
| 263 | 265 |
| 264 #if DCHECK_IS_ON() | 266 #if DCHECK_IS_ON() |
| 265 // Recursively prints surface references starting at |surface_id| to |str|. | 267 // Recursively prints surface references starting at |surface_id| to |str|. |
| 266 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, | 268 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, |
| 267 std::string indent, | 269 std::string indent, |
| 268 std::stringstream* str); | 270 std::stringstream* str); |
| 269 #endif | 271 #endif |
| 270 | 272 |
| 271 // Use reference or sequence based lifetime management. | 273 // Use reference or sequence based lifetime management. |
| 272 LifetimeType lifetime_type_; | 274 LifetimeType lifetime_type_; |
| 273 | 275 |
| 274 FrameSinkManager framesink_manager_; | 276 FrameSinkManager framesink_manager_; |
| 275 | 277 |
| 276 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 278 using SurfaceMap = base::flat_map<SurfaceId, std::unique_ptr<Surface>>; |
| 277 SurfaceMap surface_map_; | 279 SurfaceMap surface_map_; |
| 278 base::ObserverList<SurfaceObserver> observer_list_; | 280 base::ObserverList<SurfaceObserver> observer_list_; |
| 279 base::ThreadChecker thread_checker_; | 281 base::ThreadChecker thread_checker_; |
| 280 | 282 |
| 281 // List of surfaces to be destroyed, along with what sequences they're still | 283 base::flat_set<SurfaceId> surfaces_to_destroy_; |
| 282 // waiting on. | |
| 283 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | |
| 284 SurfaceDestroyList surfaces_to_destroy_; | |
| 285 | 284 |
| 286 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 285 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
| 287 // waited on. | 286 // waited on. |
| 288 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 287 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
| 289 | 288 |
| 290 // Root SurfaceId that references display root surfaces. There is no Surface | 289 // Root SurfaceId that references display root surfaces. There is no Surface |
| 291 // with this id, it's for bookkeeping purposes only. | 290 // with this id, it's for bookkeeping purposes only. |
| 292 const SurfaceId root_surface_id_; | 291 const SurfaceId root_surface_id_; |
| 293 | 292 |
| 294 // Always empty set that is returned when there is no entry in |references_| | 293 // 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; | 325 SurfaceDependencyTracker* dependency_tracker_ = nullptr; |
| 327 | 326 |
| 328 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 327 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
| 329 | 328 |
| 330 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 329 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
| 331 }; | 330 }; |
| 332 | 331 |
| 333 } // namespace cc | 332 } // namespace cc |
| 334 | 333 |
| 335 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 334 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
| OLD | NEW |