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

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

Issue 2455663003: Add cc::Surface ref counting. (Closed)
Patch Set: Fixes for fsamuel comments. Created 4 years, 1 month 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>
(...skipping 12 matching lines...) Expand all
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
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. If
80 // |should_run_gc| is true and the child surface drops to zero references then
81 // GC will run.
82 void RemoveSurfaceReference(const SurfaceId& parent_id,
83 const SurfaceId& child_id,
84 bool should_run_gc = true);
vmpstr 2016/11/02 20:28:13 No default values, please
kylechar 2016/11/02 21:21:20 Done.
85
86 // Returns the number of surfaces that have references to |surface_id|. When
87 // the count is zero nothing is referencing the surface and it may be garbage
88 // collected.
89 size_t GetSurfaceReferenceCount(const SurfaceId& surface_id) const;
90
91 // Returns the number of surfaces that |surface_id| has references to.
92 size_t GetReferencedSurfaceCount(const SurfaceId& surface_id) const;
93
69 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered 94 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered
70 // and unregistered in any order with respect to each other. 95 // and unregistered in any order with respect to each other.
71 // 96 //
72 // This happens in practice, e.g. the relationship to between ui::Compositor / 97 // This happens in practice, e.g. the relationship to between ui::Compositor /
73 // DelegatedFrameHost is known before ui::Compositor has a surface/client). 98 // DelegatedFrameHost is known before ui::Compositor has a surface/client).
74 // However, DelegatedFrameHost can register itself as a client before its 99 // However, DelegatedFrameHost can register itself as a client before its
75 // relationship with the ui::Compositor is known. 100 // relationship with the ui::Compositor is known.
76 101
77 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it 102 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it
78 // uses. 103 // uses.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bool is_empty() const { return !client && children.empty(); } 165 bool is_empty() const { return !client && children.empty(); }
141 // The client that's responsible for creating this namespace. Never null. 166 // The client that's responsible for creating this namespace. Never null.
142 SurfaceFactoryClient* client; 167 SurfaceFactoryClient* client;
143 // The currently assigned begin frame source for this client. 168 // The currently assigned begin frame source for this client.
144 BeginFrameSource* source; 169 BeginFrameSource* source;
145 // This represents a dag of parent -> children mapping. 170 // This represents a dag of parent -> children mapping.
146 std::vector<FrameSinkId> children; 171 std::vector<FrameSinkId> children;
147 }; 172 };
148 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> 173 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash>
149 frame_sink_source_map_; 174 frame_sink_source_map_;
175
176 using SurfaceIdSet = std::unordered_set<SurfaceId, SurfaceIdHash>;
177 // Tracks references from the child surface to parent surface. If there are
178 // zero entries in the set for a SurfaceId then nothing is referencing the
179 // surface and it can be garbage collected.
180 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
181 child_to_parent_refs_;
182 // Tracks references from the parent surface to child surface. Is the inverse
183 // of |child_to_parent_refs_|.
184 std::unordered_map<SurfaceId, SurfaceIdSet, SurfaceIdHash>
185 parent_to_child_refs_;
186
150 // Set of which sources are registered to which namespace. Any child 187 // Set of which sources are registered to which namespace. Any child
151 // that is implicitly using this namespace must be reachable by the 188 // that is implicitly using this namespace must be reachable by the
152 // parent in the dag. 189 // parent in the dag.
153 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; 190 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_;
154 191
155 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); 192 DISALLOW_COPY_AND_ASSIGN(SurfaceManager);
156 }; 193 };
157 194
158 } // namespace cc 195 } // namespace cc
159 196
160 #endif // CC_SURFACES_SURFACE_MANAGER_H_ 197 #endif // CC_SURFACES_SURFACE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698