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