| 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> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "cc/surfaces/surfaces_export.h" | 23 #include "cc/surfaces/surfaces_export.h" |
| 24 | 24 |
| 25 namespace cc { | 25 namespace cc { |
| 26 class BeginFrameSource; | 26 class BeginFrameSource; |
| 27 class CompositorFrame; | 27 class CompositorFrame; |
| 28 class Surface; | 28 class Surface; |
| 29 class SurfaceFactoryClient; | 29 class SurfaceFactoryClient; |
| 30 | 30 |
| 31 class CC_SURFACES_EXPORT SurfaceManager { | 31 class CC_SURFACES_EXPORT SurfaceManager { |
| 32 public: | 32 public: |
| 33 // Root SurfaceId that references display root surfaces. There is no Surface |
| 34 // with this id, it's for bookkeeping purposes only. |
| 35 static const SurfaceId kRootSurfaceId; |
| 36 |
| 33 SurfaceManager(); | 37 SurfaceManager(); |
| 34 ~SurfaceManager(); | 38 ~SurfaceManager(); |
| 35 | 39 |
| 36 void RegisterSurface(Surface* surface); | 40 void RegisterSurface(Surface* surface); |
| 37 void DeregisterSurface(const SurfaceId& surface_id); | 41 void DeregisterSurface(const SurfaceId& surface_id); |
| 38 | 42 |
| 39 // Destroy the Surface once a set of sequence numbers has been satisfied. | 43 // Destroy the Surface once a set of sequence numbers has been satisfied. |
| 40 void Destroy(std::unique_ptr<Surface> surface); | 44 void Destroy(std::unique_ptr<Surface> surface); |
| 41 | 45 |
| 42 Surface* GetSurfaceForId(const SurfaceId& surface_id); | 46 Surface* GetSurfaceForId(const SurfaceId& surface_id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 59 // id namespace. | 63 // id namespace. |
| 60 void DidSatisfySequences(const FrameSinkId& frame_sink_id, | 64 void DidSatisfySequences(const FrameSinkId& frame_sink_id, |
| 61 std::vector<uint32_t>* sequence); | 65 std::vector<uint32_t>* sequence); |
| 62 | 66 |
| 63 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); | 67 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); |
| 64 | 68 |
| 65 // Invalidate a frame_sink_id that might still have associated sequences, | 69 // Invalidate a frame_sink_id that might still have associated sequences, |
| 66 // possibly because a renderer process has crashed. | 70 // possibly because a renderer process has crashed. |
| 67 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id); | 71 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id); |
| 68 | 72 |
| 73 // Adds a reference from a parent surface to a child surface. Any surface |
| 74 // embedding a child surface should have a reference added so that the child |
| 75 // surface is not garbage collected until after the parent surface. |
| 76 void AddSurfaceReference(const SurfaceId& parent_id, |
| 77 const SurfaceId& child_id); |
| 78 |
| 79 // Removes a reference from a parent surface to a child surface. |
| 80 void RemoveSurfaceReference(const SurfaceId& parent_id, |
| 81 const SurfaceId& child_id); |
| 82 |
| 83 // Returns the number of surfaces that have references to |surface_id|. When |
| 84 // the count is zero nothing is referencing the surface and it may be garbage |
| 85 // collected. |
| 86 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const; |
| 87 |
| 88 // Returns the number of surfaces that |surface_id| has references to. |
| 89 size_t GetReferencedSurfaceCount(const SurfaceId& surface_id) const; |
| 90 |
| 69 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered | 91 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered |
| 70 // and unregistered in any order with respect to each other. | 92 // and unregistered in any order with respect to each other. |
| 71 // | 93 // |
| 72 // This happens in practice, e.g. the relationship to between ui::Compositor / | 94 // This happens in practice, e.g. the relationship to between ui::Compositor / |
| 73 // DelegatedFrameHost is known before ui::Compositor has a surface/client). | 95 // DelegatedFrameHost is known before ui::Compositor has a surface/client). |
| 74 // However, DelegatedFrameHost can register itself as a client before its | 96 // However, DelegatedFrameHost can register itself as a client before its |
| 75 // relationship with the ui::Compositor is known. | 97 // relationship with the ui::Compositor is known. |
| 76 | 98 |
| 77 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it | 99 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it |
| 78 // uses. | 100 // uses. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 105 BeginFrameSource* source); | 127 BeginFrameSource* source); |
| 106 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, | 128 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, |
| 107 BeginFrameSource* source); | 129 BeginFrameSource* source); |
| 108 // Returns true if |child namespace| is or has |search_frame_sink_id| as a | 130 // Returns true if |child namespace| is or has |search_frame_sink_id| as a |
| 109 // child. | 131 // child. |
| 110 bool ChildContains(const FrameSinkId& child_frame_sink_id, | 132 bool ChildContains(const FrameSinkId& child_frame_sink_id, |
| 111 const FrameSinkId& search_frame_sink_id) const; | 133 const FrameSinkId& search_frame_sink_id) const; |
| 112 | 134 |
| 113 void GarbageCollectSurfaces(); | 135 void GarbageCollectSurfaces(); |
| 114 | 136 |
| 137 // Removes reference from a parent surface to a child surface. Used to remove |
| 138 // references without triggered GC. |
| 139 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, |
| 140 const SurfaceId& child_id); |
| 141 |
| 115 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 142 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; |
| 116 SurfaceMap surface_map_; | 143 SurfaceMap surface_map_; |
| 117 base::ObserverList<SurfaceObserver> observer_list_; | 144 base::ObserverList<SurfaceObserver> observer_list_; |
| 118 base::ThreadChecker thread_checker_; | 145 base::ThreadChecker thread_checker_; |
| 119 | 146 |
| 120 // List of surfaces to be destroyed, along with what sequences they're still | 147 // List of surfaces to be destroyed, along with what sequences they're still |
| 121 // waiting on. | 148 // waiting on. |
| 122 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | 149 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; |
| 123 SurfaceDestroyList surfaces_to_destroy_; | 150 SurfaceDestroyList surfaces_to_destroy_; |
| 124 | 151 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 140 bool is_empty() const { return !client && children.empty(); } | 167 bool is_empty() const { return !client && children.empty(); } |
| 141 // The client that's responsible for creating this namespace. Never null. | 168 // The client that's responsible for creating this namespace. Never null. |
| 142 SurfaceFactoryClient* client; | 169 SurfaceFactoryClient* client; |
| 143 // The currently assigned begin frame source for this client. | 170 // The currently assigned begin frame source for this client. |
| 144 BeginFrameSource* source; | 171 BeginFrameSource* source; |
| 145 // This represents a dag of parent -> children mapping. | 172 // This represents a dag of parent -> children mapping. |
| 146 std::vector<FrameSinkId> children; | 173 std::vector<FrameSinkId> children; |
| 147 }; | 174 }; |
| 148 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> | 175 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> |
| 149 frame_sink_source_map_; | 176 frame_sink_source_map_; |
| 177 |
| 178 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>; |
| 179 // Tracks references from the child surface to parent surface. If there are |
| 180 // zero entries in the set for a SurfaceId then nothing is referencing the |
| 181 // surface and it can be garbage collected. |
| 182 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
| 183 child_to_parent_refs_; |
| 184 // Tracks references from the parent surface to child surface. Is the inverse |
| 185 // of |child_to_parent_refs_|. |
| 186 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> |
| 187 parent_to_child_refs_; |
| 188 |
| 150 // Set of which sources are registered to which namespace. Any child | 189 // Set of which sources are registered to which namespace. Any child |
| 151 // that is implicitly using this namespace must be reachable by the | 190 // that is implicitly using this namespace must be reachable by the |
| 152 // parent in the dag. | 191 // parent in the dag. |
| 153 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; | 192 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; |
| 154 | 193 |
| 155 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 194 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
| 156 }; | 195 }; |
| 157 | 196 |
| 158 } // namespace cc | 197 } // namespace cc |
| 159 | 198 |
| 160 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 199 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
| OLD | NEW |