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/macros.h" | 16 #include "base/macros.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "cc/surfaces/frame_sink_id.h" |
19 #include "cc/surfaces/surface_damage_observer.h" | 20 #include "cc/surfaces/surface_damage_observer.h" |
20 #include "cc/surfaces/surface_id.h" | 21 #include "cc/surfaces/surface_id.h" |
21 #include "cc/surfaces/surface_sequence.h" | 22 #include "cc/surfaces/surface_sequence.h" |
22 #include "cc/surfaces/surfaces_export.h" | 23 #include "cc/surfaces/surfaces_export.h" |
23 | 24 |
| 25 namespace gfx { |
| 26 class Size; |
| 27 } // namespace gfx |
| 28 |
24 namespace cc { | 29 namespace cc { |
25 class BeginFrameSource; | 30 class BeginFrameSource; |
26 class CompositorFrame; | 31 class CompositorFrame; |
27 class Surface; | 32 class Surface; |
28 class SurfaceFactoryClient; | 33 class SurfaceFactoryClient; |
29 | 34 |
30 class CC_SURFACES_EXPORT SurfaceManager { | 35 class CC_SURFACES_EXPORT SurfaceManager { |
31 public: | 36 public: |
32 SurfaceManager(); | 37 class Delegate { |
| 38 public: |
| 39 virtual ~Delegate() = default; |
| 40 virtual void OnSurfaceCreated(const gfx::Size& size, |
| 41 float device_scale_factor, |
| 42 const SurfaceId& surface_id) = 0; |
| 43 }; |
| 44 |
| 45 explicit SurfaceManager(Delegate* delegate); |
33 ~SurfaceManager(); | 46 ~SurfaceManager(); |
34 | 47 |
35 void RegisterSurface(Surface* surface); | 48 void RegisterSurface(Surface* surface); |
36 void DeregisterSurface(const SurfaceId& surface_id); | 49 void DeregisterSurface(const SurfaceId& surface_id); |
37 | 50 |
38 // Destroy the Surface once a set of sequence numbers has been satisfied. | 51 // Destroy the Surface once a set of sequence numbers has been satisfied. |
39 void Destroy(std::unique_ptr<Surface> surface); | 52 void Destroy(std::unique_ptr<Surface> surface); |
40 | 53 |
41 Surface* GetSurfaceForId(const SurfaceId& surface_id); | 54 Surface* GetSurfaceForId(const SurfaceId& surface_id); |
42 | 55 |
43 void AddObserver(SurfaceDamageObserver* obs) { | 56 void AddObserver(SurfaceDamageObserver* obs) { |
44 observer_list_.AddObserver(obs); | 57 observer_list_.AddObserver(obs); |
45 } | 58 } |
46 | 59 |
47 void RemoveObserver(SurfaceDamageObserver* obs) { | 60 void RemoveObserver(SurfaceDamageObserver* obs) { |
48 observer_list_.RemoveObserver(obs); | 61 observer_list_.RemoveObserver(obs); |
49 } | 62 } |
50 | 63 |
51 bool SurfaceModified(const SurfaceId& surface_id); | 64 bool SurfaceModified(const SurfaceId& surface_id); |
52 | 65 |
| 66 void DidCreateNewSurface(const gfx::Size& size, |
| 67 float device_scale_factor, |
| 68 const SurfaceId& surface_id); |
| 69 |
53 // A frame for a surface satisfies a set of sequence numbers in a particular | 70 // A frame for a surface satisfies a set of sequence numbers in a particular |
54 // id namespace. | 71 // id namespace. |
55 void DidSatisfySequences(uint32_t client_id, std::vector<uint32_t>* sequence); | 72 void DidSatisfySequences(const FrameSinkId& frame_sink_id, |
| 73 std::vector<uint32_t>* sequence); |
56 | 74 |
57 void RegisterSurfaceClientId(uint32_t client_id); | 75 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); |
58 | 76 |
59 // Invalidate a namespace that might still have associated sequences, | 77 // Invalidate a frame_sink_id that might still have associated sequences, |
60 // possibly because a renderer process has crashed. | 78 // possibly because a renderer process has crashed. |
61 void InvalidateSurfaceClientId(uint32_t client_id); | 79 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id); |
62 | 80 |
63 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered | 81 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered |
64 // and unregistered in any order with respect to each other. | 82 // and unregistered in any order with respect to each other. |
65 // | 83 // |
66 // This happens in practice, e.g. the relationship to between ui::Compositor / | 84 // This happens in practice, e.g. the relationship to between ui::Compositor / |
67 // DelegatedFrameHost is known before ui::Compositor has a surface/client). | 85 // DelegatedFrameHost is known before ui::Compositor has a surface/client). |
68 // However, DelegatedFrameHost can register itself as a client before its | 86 // However, DelegatedFrameHost can register itself as a client before its |
69 // relationship with the ui::Compositor is known. | 87 // relationship with the ui::Compositor is known. |
70 | 88 |
71 // Associates a SurfaceFactoryClient with the surface id namespace it uses. | 89 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it |
| 90 // uses. |
72 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. | 91 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. |
73 // Caller guarantees the client is alive between register/unregister. | 92 // Caller guarantees the client is alive between register/unregister. |
74 // Reregistering the same namespace when a previous client is active is not | 93 // Reregistering the same namespace when a previous client is active is not |
75 // valid. | 94 // valid. |
76 void RegisterSurfaceFactoryClient(uint32_t client_id, | 95 void RegisterSurfaceFactoryClient(const FrameSinkId& frame_sink_id, |
77 SurfaceFactoryClient* client); | 96 SurfaceFactoryClient* client); |
78 void UnregisterSurfaceFactoryClient(uint32_t client_id); | 97 void UnregisterSurfaceFactoryClient(const FrameSinkId& frame_sink_id); |
79 | 98 |
80 // Associates a |source| with a particular namespace. That namespace and | 99 // Associates a |source| with a particular namespace. That namespace and |
81 // any children of that namespace with valid clients can potentially use | 100 // any children of that namespace with valid clients can potentially use |
82 // that |source|. | 101 // that |source|. |
83 void RegisterBeginFrameSource(BeginFrameSource* source, uint32_t client_id); | 102 void RegisterBeginFrameSource(BeginFrameSource* source, |
| 103 const FrameSinkId& frame_sink_id); |
84 void UnregisterBeginFrameSource(BeginFrameSource* source); | 104 void UnregisterBeginFrameSource(BeginFrameSource* source); |
85 | 105 |
86 // Register a relationship between two namespaces. This relationship means | 106 // Register a relationship between two namespaces. This relationship means |
87 // that surfaces from the child namespace will be displayed in the parent. | 107 // that surfaces from the child namespace will be displayed in the parent. |
88 // Children are allowed to use any begin frame source that their parent can | 108 // Children are allowed to use any begin frame source that their parent can |
89 // use. | 109 // use. |
90 void RegisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, | 110 void RegisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, |
91 uint32_t child_namespace); | 111 const FrameSinkId& child_frame_sink_id); |
92 void UnregisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, | 112 void UnregisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, |
93 uint32_t child_namespace); | 113 const FrameSinkId& child_frame_sink_id); |
94 | 114 |
95 private: | 115 private: |
96 void RecursivelyAttachBeginFrameSource(uint32_t client_id, | 116 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, |
97 BeginFrameSource* source); | 117 BeginFrameSource* source); |
98 void RecursivelyDetachBeginFrameSource(uint32_t client_id, | 118 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, |
99 BeginFrameSource* source); | 119 BeginFrameSource* source); |
100 // Returns true if |child namespace| is or has |search_namespace| as a child. | 120 // Returns true if |child namespace| is or has |search_frame_sink_id| as a |
101 bool ChildContains(uint32_t child_namespace, uint32_t search_namespace) const; | 121 // child. |
| 122 bool ChildContains(const FrameSinkId& child_frame_sink_id, |
| 123 const FrameSinkId& search_frame_sink_id) const; |
102 | 124 |
103 void GarbageCollectSurfaces(); | 125 void GarbageCollectSurfaces(); |
104 | 126 |
| 127 Delegate* const delegate_; |
| 128 |
105 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 129 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; |
106 SurfaceMap surface_map_; | 130 SurfaceMap surface_map_; |
107 base::ObserverList<SurfaceDamageObserver> observer_list_; | 131 base::ObserverList<SurfaceDamageObserver> observer_list_; |
108 base::ThreadChecker thread_checker_; | 132 base::ThreadChecker thread_checker_; |
109 | 133 |
110 // List of surfaces to be destroyed, along with what sequences they're still | 134 // List of surfaces to be destroyed, along with what sequences they're still |
111 // waiting on. | 135 // waiting on. |
112 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | 136 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; |
113 SurfaceDestroyList surfaces_to_destroy_; | 137 SurfaceDestroyList surfaces_to_destroy_; |
114 | 138 |
115 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 139 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
116 // waited on. | 140 // waited on. |
117 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 141 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
118 | 142 |
119 // Set of valid surface ID namespaces. When a namespace is removed from | 143 // Set of valid surface ID namespaces. When a namespace is removed from |
120 // this set, any remaining sequences with that namespace are considered | 144 // this set, any remaining sequences with that namespace are considered |
121 // satisfied. | 145 // satisfied. |
122 std::unordered_set<uint32_t> valid_surface_client_ids_; | 146 std::unordered_set<FrameSinkId, FrameSinkIdHash> valid_frame_sink_ids_; |
123 | 147 |
124 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient | 148 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient |
125 // pointers guaranteed alive by callers until unregistered. | 149 // pointers guaranteed alive by callers until unregistered. |
126 struct ClientSourceMapping { | 150 struct ClientSourceMapping { |
127 ClientSourceMapping(); | 151 ClientSourceMapping(); |
128 ClientSourceMapping(const ClientSourceMapping& other); | 152 ClientSourceMapping(const ClientSourceMapping& other); |
129 ~ClientSourceMapping(); | 153 ~ClientSourceMapping(); |
130 bool is_empty() const { return !client && children.empty(); } | 154 bool is_empty() const { return !client && children.empty(); } |
131 // The client that's responsible for creating this namespace. Never null. | 155 // The client that's responsible for creating this namespace. Never null. |
132 SurfaceFactoryClient* client; | 156 SurfaceFactoryClient* client; |
133 // The currently assigned begin frame source for this client. | 157 // The currently assigned begin frame source for this client. |
134 BeginFrameSource* source; | 158 BeginFrameSource* source; |
135 // This represents a dag of parent -> children mapping. | 159 // This represents a dag of parent -> children mapping. |
136 std::vector<uint32_t> children; | 160 std::vector<FrameSinkId> children; |
137 }; | 161 }; |
138 std::unordered_map<uint32_t, ClientSourceMapping> namespace_client_map_; | 162 std::unordered_map<FrameSinkId, ClientSourceMapping, FrameSinkIdHash> |
| 163 namespace_client_map_; |
139 // Set of which sources are registered to which namespace. Any child | 164 // Set of which sources are registered to which namespace. Any child |
140 // that is implicitly using this namespace must be reachable by the | 165 // that is implicitly using this namespace must be reachable by the |
141 // parent in the dag. | 166 // parent in the dag. |
142 std::unordered_map<BeginFrameSource*, uint32_t> registered_sources_; | 167 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; |
143 | 168 |
144 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 169 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
145 }; | 170 }; |
146 | 171 |
147 } // namespace cc | 172 } // namespace cc |
148 | 173 |
149 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 174 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |