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 // 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 const SurfaceId& surface_id) const; | 207 const SurfaceId& surface_id) const; |
| 205 | 208 |
| 206 scoped_refptr<SurfaceReferenceFactory> reference_factory() { | 209 scoped_refptr<SurfaceReferenceFactory> reference_factory() { |
| 207 return reference_factory_; | 210 return reference_factory_; |
| 208 } | 211 } |
| 209 | 212 |
| 210 bool using_surface_references() const { | 213 bool using_surface_references() const { |
| 211 return lifetime_type_ == LifetimeType::REFERENCES; | 214 return lifetime_type_ == LifetimeType::REFERENCES; |
| 212 } | 215 } |
| 213 | 216 |
| 217 // Returns true if |surface_id| is in the garbage collector's queue. | |
| 218 bool IsMarkedForDestruction(const SurfaceId& surface_id); | |
|
danakj
2017/06/21 21:24:09
Do we want this to be part of the public API for p
Saman Sami
2017/06/26 20:44:05
I made it private.
| |
| 219 | |
| 214 private: | 220 private: |
| 215 friend class test::SurfaceSynchronizationTest; | 221 friend class test::SurfaceSynchronizationTest; |
| 216 friend class SurfaceManagerRefTest; | 222 friend class SurfaceManagerRefTest; |
| 217 | 223 |
| 218 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; | 224 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
| 219 | 225 |
| 220 struct SurfaceReferenceInfo { | 226 struct SurfaceReferenceInfo { |
| 221 SurfaceReferenceInfo(); | 227 SurfaceReferenceInfo(); |
| 222 ~SurfaceReferenceInfo(); | 228 ~SurfaceReferenceInfo(); |
| 223 | 229 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 254 | 260 |
| 255 // Adds a temporary reference to |surface_id|. The reference will not have an | 261 // Adds a temporary reference to |surface_id|. The reference will not have an |
| 256 // owner initially. | 262 // owner initially. |
| 257 void AddTemporaryReference(const SurfaceId& surface_id); | 263 void AddTemporaryReference(const SurfaceId& surface_id); |
| 258 | 264 |
| 259 // Removes temporary reference to |surface_id|. If |remove_range| is true then | 265 // Removes temporary reference to |surface_id|. If |remove_range| is true then |
| 260 // all temporary references to surfaces with the same FrameSinkId as | 266 // all temporary references to surfaces with the same FrameSinkId as |
| 261 // |surface_id| that were added before |surface_id| will also be removed. | 267 // |surface_id| that were added before |surface_id| will also be removed. |
| 262 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); | 268 void RemoveTemporaryReference(const SurfaceId& surface_id, bool remove_range); |
| 263 | 269 |
| 264 // Called when a surface is destroyed and it needs to be removed from the | 270 // Removes the surface from the surface map and destroys it. |
| 265 // surface map. | 271 void DestroySurfaceInternal(const SurfaceId& surface_id); |
| 266 void UnregisterSurface(const SurfaceId& surface_id); | |
| 267 | 272 |
| 268 #if DCHECK_IS_ON() | 273 #if DCHECK_IS_ON() |
| 269 // Recursively prints surface references starting at |surface_id| to |str|. | 274 // Recursively prints surface references starting at |surface_id| to |str|. |
| 270 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, | 275 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, |
| 271 std::string indent, | 276 std::string indent, |
| 272 std::stringstream* str); | 277 std::stringstream* str); |
| 273 #endif | 278 #endif |
| 274 | 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 using SurfaceMap = base::flat_map<SurfaceId, std::unique_ptr<Surface>>; |
| 281 SurfaceMap surface_map_; | 286 SurfaceMap surface_map_; |
| 282 base::ObserverList<SurfaceObserver> observer_list_; | 287 base::ObserverList<SurfaceObserver> observer_list_; |
| 283 base::ThreadChecker thread_checker_; | 288 base::ThreadChecker thread_checker_; |
| 284 | 289 |
| 285 // List of surfaces to be destroyed, along with what sequences they're still | 290 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 | 291 |
| 290 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 292 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
| 291 // waited on. | 293 // waited on. |
| 292 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 294 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
| 293 | 295 |
| 294 // Root SurfaceId that references display root surfaces. There is no Surface | 296 // Root SurfaceId that references display root surfaces. There is no Surface |
| 295 // with this id, it's for bookkeeping purposes only. | 297 // with this id, it's for bookkeeping purposes only. |
| 296 const SurfaceId root_surface_id_; | 298 const SurfaceId root_surface_id_; |
| 297 | 299 |
| 298 // Always empty set that is returned when there is no entry in |references_| | 300 // 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; | 332 SurfaceDependencyTracker* dependency_tracker_ = nullptr; |
| 331 | 333 |
| 332 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 334 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
| 333 | 335 |
| 334 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 336 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
| 335 }; | 337 }; |
| 336 | 338 |
| 337 } // namespace cc | 339 } // namespace cc |
| 338 | 340 |
| 339 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 341 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
| OLD | NEW |