Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: cc/surfaces/surface_manager.h

Issue 2625203004: Add debug method to print surface references. (Closed)
Patch Set: Cleanup. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <sstream>
danakj 2017/01/17 23:21:57 do u need more than iosfwd? and should these be in
kylechar 2017/01/18 15:06:18 iosfwd has a forward def for stringstream, so it s
13 #include <string>
12 #include <unordered_map> 14 #include <unordered_map>
13 #include <unordered_set> 15 #include <unordered_set>
14 #include <vector> 16 #include <vector>
15 17
16 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
17 #include "base/macros.h" 19 #include "base/macros.h"
18 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
19 #include "base/observer_list.h" 21 #include "base/observer_list.h"
20 #include "base/threading/thread_checker.h" 22 #include "base/threading/thread_checker.h"
21 #include "cc/surfaces/frame_sink_id.h" 23 #include "cc/surfaces/frame_sink_id.h"
(...skipping 14 matching lines...) Expand all
36 : public NON_EXPORTED_BASE(SurfaceReferenceManager) { 38 : public NON_EXPORTED_BASE(SurfaceReferenceManager) {
37 public: 39 public:
38 enum class LifetimeType { 40 enum class LifetimeType {
39 REFERENCES, 41 REFERENCES,
40 SEQUENCES, 42 SEQUENCES,
41 }; 43 };
42 44
43 explicit SurfaceManager(LifetimeType lifetime_type = LifetimeType::SEQUENCES); 45 explicit SurfaceManager(LifetimeType lifetime_type = LifetimeType::SEQUENCES);
44 ~SurfaceManager() override; 46 ~SurfaceManager() override;
45 47
48 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
danakj 2017/01/17 23:21:57 #if DCHECK_IS_ON() is the way to spell this
kylechar 2017/01/18 15:06:18 Huh, that's handy.
49 // Returns a string representation of all reachable surface references.
50 std::string PrintSurfaceReferences();
danakj 2017/01/17 23:21:57 This doesnt print, SurfaceReferencesToString ?
kylechar 2017/01/18 15:06:18 Done.
51 #endif
52
46 void RegisterSurface(Surface* surface); 53 void RegisterSurface(Surface* surface);
47 void DeregisterSurface(const SurfaceId& surface_id); 54 void DeregisterSurface(const SurfaceId& surface_id);
48 55
49 // Destroy the Surface once a set of sequence numbers has been satisfied. 56 // Destroy the Surface once a set of sequence numbers has been satisfied.
50 void Destroy(std::unique_ptr<Surface> surface); 57 void Destroy(std::unique_ptr<Surface> surface);
51 58
52 Surface* GetSurfaceForId(const SurfaceId& surface_id); 59 Surface* GetSurfaceForId(const SurfaceId& surface_id);
53 60
54 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); } 61 void AddObserver(SurfaceObserver* obs) { observer_list_.AddObserver(obs); }
55 62
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void RemoveSurfaceReference(const SurfaceId& parent_id, 126 void RemoveSurfaceReference(const SurfaceId& parent_id,
120 const SurfaceId& child_id) override; 127 const SurfaceId& child_id) override;
121 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const override; 128 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const override;
122 size_t GetReferencedSurfaceCount(const SurfaceId& surface_id) const override; 129 size_t GetReferencedSurfaceCount(const SurfaceId& surface_id) const override;
123 130
124 scoped_refptr<SurfaceReferenceFactory> reference_factory() { 131 scoped_refptr<SurfaceReferenceFactory> reference_factory() {
125 return reference_factory_; 132 return reference_factory_;
126 } 133 }
127 134
128 private: 135 private:
136 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>;
137
129 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, 138 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id,
130 BeginFrameSource* source); 139 BeginFrameSource* source);
131 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, 140 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id,
132 BeginFrameSource* source); 141 BeginFrameSource* source);
133 // Returns true if |child namespace| is or has |search_frame_sink_id| as a 142 // Returns true if |child namespace| is or has |search_frame_sink_id| as a
134 // child. 143 // child.
135 bool ChildContains(const FrameSinkId& child_frame_sink_id, 144 bool ChildContains(const FrameSinkId& child_frame_sink_id,
136 const FrameSinkId& search_frame_sink_id) const; 145 const FrameSinkId& search_frame_sink_id) const;
137 146
138 // Garbage collects all destroyed surfaces not reachable from the root. Used 147 // Garbage collects all destroyed surfaces not reachable from the root. Used
139 // when |use_references_| is true. 148 // when |use_references_| is true.
140 void GarbageCollectSurfacesFromRoot(); 149 void GarbageCollectSurfacesFromRoot();
141 void GarbageCollectSurfaces(); 150 void GarbageCollectSurfaces();
142 151
143 // Removes reference from a parent surface to a child surface. Used to remove 152 // Removes reference from a parent surface to a child surface. Used to remove
144 // references without triggered GC. 153 // references without triggered GC.
145 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, 154 void RemoveSurfaceReferenceImpl(const SurfaceId& parent_id,
146 const SurfaceId& child_id); 155 const SurfaceId& child_id);
147 156
157 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
158 // Recursively prints surface references starting at |surface_id| to |str|.
159 void PrintSurfaceReferencesImpl(const SurfaceId& surface_id,
160 std::string indent,
161 std::stringstream* str);
162 #endif
163
148 // Use reference or sequence based lifetime management. 164 // Use reference or sequence based lifetime management.
149 LifetimeType lifetime_type_; 165 LifetimeType lifetime_type_;
150 166
151 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; 167 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>;
152 SurfaceMap surface_map_; 168 SurfaceMap surface_map_;
153 base::ObserverList<SurfaceObserver> observer_list_; 169 base::ObserverList<SurfaceObserver> observer_list_;
154 base::ThreadChecker thread_checker_; 170 base::ThreadChecker thread_checker_;
155 171
156 // List of surfaces to be destroyed, along with what sequences they're still 172 // List of surfaces to be destroyed, along with what sequences they're still
157 // waiting on. 173 // waiting on.
(...skipping 19 matching lines...) Expand all
177 // The client that's responsible for creating this namespace. Never null. 193 // The client that's responsible for creating this namespace. Never null.
178 SurfaceFactoryClient* client; 194 SurfaceFactoryClient* client;
179 // The currently assigned begin frame source for this client. 195 // The currently assigned begin frame source for this client.
180 BeginFrameSource* source; 196 BeginFrameSource* source;
181 // This represents a dag of parent -> children mapping. 197 // This represents a dag of parent -> children mapping.
182 std::vector<FrameSinkId> children; 198 std::vector<FrameSinkId> children;
183 }; 199 };
184 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> 200 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash>
185 frame_sink_source_map_; 201 frame_sink_source_map_;
186 202
187 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>;
188 // Tracks references from the child surface to parent surface. If there are 203 // 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 204 // zero entries in the set for a SurfaceId then nothing is referencing the
190 // surface and it can be garbage collected. 205 // surface and it can be garbage collected.
191 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> 206 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
192 child_to_parent_refs_; 207 child_to_parent_refs_;
193 // Tracks references from the parent surface to child surface. Is the inverse 208 // Tracks references from the parent surface to child surface. Is the inverse
194 // of |child_to_parent_refs_|. 209 // of |child_to_parent_refs_|.
195 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash> 210 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
196 parent_to_child_refs_; 211 parent_to_child_refs_;
197 212
(...skipping 11 matching lines...) Expand all
209 scoped_refptr<SurfaceReferenceFactory> reference_factory_; 224 scoped_refptr<SurfaceReferenceFactory> reference_factory_;
210 225
211 base::WeakPtrFactory<SurfaceManager> weak_factory_; 226 base::WeakPtrFactory<SurfaceManager> weak_factory_;
212 227
213 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); 228 DISALLOW_COPY_AND_ASSIGN(SurfaceManager);
214 }; 229 };
215 230
216 } // namespace cc 231 } // namespace cc
217 232
218 #endif // CC_SURFACES_SURFACE_MANAGER_H_ 233 #endif // CC_SURFACES_SURFACE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698