| 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/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/logging.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 19 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
| 21 #include "cc/surfaces/frame_sink_id.h" | 22 #include "cc/surfaces/frame_sink_id.h" |
| 22 #include "cc/surfaces/surface_id.h" | 23 #include "cc/surfaces/surface_id.h" |
| 23 #include "cc/surfaces/surface_observer.h" | 24 #include "cc/surfaces/surface_observer.h" |
| 24 #include "cc/surfaces/surface_reference_factory.h" | 25 #include "cc/surfaces/surface_reference_factory.h" |
| 25 #include "cc/surfaces/surface_reference_manager.h" | 26 #include "cc/surfaces/surface_reference_manager.h" |
| 26 #include "cc/surfaces/surface_sequence.h" | 27 #include "cc/surfaces/surface_sequence.h" |
| 27 #include "cc/surfaces/surfaces_export.h" | 28 #include "cc/surfaces/surfaces_export.h" |
| 28 | 29 |
| 30 #if DCHECK_IS_ON() |
| 31 #include <iosfwd> |
| 32 #include <string> |
| 33 #endif |
| 34 |
| 29 namespace cc { | 35 namespace cc { |
| 30 class BeginFrameSource; | 36 class BeginFrameSource; |
| 31 class CompositorFrame; | 37 class CompositorFrame; |
| 32 class Surface; | 38 class Surface; |
| 33 class SurfaceFactoryClient; | 39 class SurfaceFactoryClient; |
| 34 | 40 |
| 35 class CC_SURFACES_EXPORT SurfaceManager | 41 class CC_SURFACES_EXPORT SurfaceManager |
| 36 : public NON_EXPORTED_BASE(SurfaceReferenceManager) { | 42 : public NON_EXPORTED_BASE(SurfaceReferenceManager) { |
| 37 public: | 43 public: |
| 38 enum class LifetimeType { | 44 enum class LifetimeType { |
| 39 REFERENCES, | 45 REFERENCES, |
| 40 SEQUENCES, | 46 SEQUENCES, |
| 41 }; | 47 }; |
| 42 | 48 |
| 43 explicit SurfaceManager(LifetimeType lifetime_type = LifetimeType::SEQUENCES); | 49 explicit SurfaceManager(LifetimeType lifetime_type = LifetimeType::SEQUENCES); |
| 44 ~SurfaceManager() override; | 50 ~SurfaceManager() override; |
| 45 | 51 |
| 52 #if DCHECK_IS_ON() |
| 53 // Returns a string representation of all reachable surface references. |
| 54 std::string SurfaceReferencesToString(); |
| 55 #endif |
| 56 |
| 46 void RegisterSurface(Surface* surface); | 57 void RegisterSurface(Surface* surface); |
| 47 void DeregisterSurface(const SurfaceId& surface_id); | 58 void DeregisterSurface(const SurfaceId& surface_id); |
| 48 | 59 |
| 49 // Destroy the Surface once a set of sequence numbers has been satisfied. | 60 // Destroy the Surface once a set of sequence numbers has been satisfied. |
| 50 void Destroy(std::unique_ptr<Surface> surface); | 61 void Destroy(std::unique_ptr<Surface> surface); |
| 51 | 62 |
| 52 Surface* GetSurfaceForId(const SurfaceId& surface_id); | 63 Surface* GetSurfaceForId(const SurfaceId& surface_id); |
| 53 | 64 |
| 54 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } | 65 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } |
| 55 | 66 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 void RemoveSurfaceReference(const SurfaceId& parent_id, | 130 void RemoveSurfaceReference(const SurfaceId& parent_id, |
| 120 const SurfaceId& child_id) override; | 131 const SurfaceId& child_id) override; |
| 121 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const override; | 132 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const override; |
| 122 size_t GetReferencedSurfaceCount(const SurfaceId& surface_id) const override; | 133 size_t GetReferencedSurfaceCount(const SurfaceId& surface_id) const override; |
| 123 | 134 |
| 124 scoped_refptr<SurfaceReferenceFactory> reference_factory() { | 135 scoped_refptr<SurfaceReferenceFactory> reference_factory() { |
| 125 return reference_factory_; | 136 return reference_factory_; |
| 126 } | 137 } |
| 127 | 138 |
| 128 private: | 139 private: |
| 140 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
| 141 |
| 129 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, | 142 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, |
| 130 BeginFrameSource* source); | 143 BeginFrameSource* source); |
| 131 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, | 144 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, |
| 132 BeginFrameSource* source); | 145 BeginFrameSource* source); |
| 133 // Returns true if |child namespace| is or has |search_frame_sink_id| as a | 146 // Returns true if |child namespace| is or has |search_frame_sink_id| as a |
| 134 // child. | 147 // child. |
| 135 bool ChildContains(const FrameSinkId& child_frame_sink_id, | 148 bool ChildContains(const FrameSinkId& child_frame_sink_id, |
| 136 const FrameSinkId& search_frame_sink_id) const; | 149 const FrameSinkId& search_frame_sink_id) const; |
| 137 | 150 |
| 138 // Garbage collects all destroyed surfaces not reachable from the root. Used | 151 // Garbage collects all destroyed surfaces not reachable from the root. Used |
| 139 // when |use_references_| is true. | 152 // when |use_references_| is true. |
| 140 void GarbageCollectSurfacesFromRoot(); | 153 void GarbageCollectSurfacesFromRoot(); |
| 141 void GarbageCollectSurfaces(); | 154 void GarbageCollectSurfaces(); |
| 142 | 155 |
| 143 // Removes reference from a parent surface to a child surface. Used to remove | 156 // Removes reference from a parent surface to a child surface. Used to remove |
| 144 // references without triggered GC. | 157 // references without triggered GC. |
| 145 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, | 158 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, |
| 146 const SurfaceId& child_id); | 159 const SurfaceId& child_id); |
| 147 | 160 |
| 161 #if DCHECK_IS_ON() |
| 162 // Recursively prints surface references starting at |surface_id| to |str|. |
| 163 void SurfaceReferencesToStringImpl(const SurfaceId& surface_id, |
| 164 std::string indent, |
| 165 std::stringstream* str); |
| 166 #endif |
| 167 |
| 148 // Use reference or sequence based lifetime management. | 168 // Use reference or sequence based lifetime management. |
| 149 LifetimeType lifetime_type_; | 169 LifetimeType lifetime_type_; |
| 150 | 170 |
| 151 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 171 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; |
| 152 SurfaceMap surface_map_; | 172 SurfaceMap surface_map_; |
| 153 base::ObserverList<SurfaceObserver> observer_list_; | 173 base::ObserverList<SurfaceObserver> observer_list_; |
| 154 base::ThreadChecker thread_checker_; | 174 base::ThreadChecker thread_checker_; |
| 155 | 175 |
| 156 // List of surfaces to be destroyed, along with what sequences they're still | 176 // List of surfaces to be destroyed, along with what sequences they're still |
| 157 // waiting on. | 177 // waiting on. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 177 // The client that's responsible for creating this namespace. Never null. | 197 // The client that's responsible for creating this namespace. Never null. |
| 178 SurfaceFactoryClient* client; | 198 SurfaceFactoryClient* client; |
| 179 // The currently assigned begin frame source for this client. | 199 // The currently assigned begin frame source for this client. |
| 180 BeginFrameSource* source; | 200 BeginFrameSource* source; |
| 181 // This represents a dag of parent -> children mapping. | 201 // This represents a dag of parent -> children mapping. |
| 182 std::vector<FrameSinkId> children; | 202 std::vector<FrameSinkId> children; |
| 183 }; | 203 }; |
| 184 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> | 204 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> |
| 185 frame_sink_source_map_; | 205 frame_sink_source_map_; |
| 186 | 206 |
| 187 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; | |
| 188 // Tracks references from the child surface to parent surface. If there are | 207 // Tracks references from the child surface to parent surface. If there are |
| 189 // zero entries in the set for a SurfaceId then nothing is referencing the | 208 // zero entries in the set for a SurfaceId then nothing is referencing the |
| 190 // surface and it can be garbage collected. | 209 // surface and it can be garbage collected. |
| 191 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> | 210 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
| 192 child_to_parent_refs_; | 211 child_to_parent_refs_; |
| 193 // Tracks references from the parent surface to child surface. Is the inverse | 212 // Tracks references from the parent surface to child surface. Is the inverse |
| 194 // of |child_to_parent_refs_|. | 213 // of |child_to_parent_refs_|. |
| 195 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> | 214 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
| 196 parent_to_child_refs_; | 215 parent_to_child_refs_; |
| 197 | 216 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 209 scoped_refptr<SurfaceReferenceFactory> reference_factory_; | 228 scoped_refptr<SurfaceReferenceFactory> reference_factory_; |
| 210 | 229 |
| 211 base::WeakPtrFactory<SurfaceManager> weak_factory_; | 230 base::WeakPtrFactory<SurfaceManager> weak_factory_; |
| 212 | 231 |
| 213 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 232 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
| 214 }; | 233 }; |
| 215 | 234 |
| 216 } // namespace cc | 235 } // namespace cc |
| 217 | 236 |
| 218 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 237 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
| OLD | NEW |