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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 void RemoveObserver(SurfaceDamageObserver* obs) { | 47 void RemoveObserver(SurfaceDamageObserver* obs) { |
48 observer_list_.RemoveObserver(obs); | 48 observer_list_.RemoveObserver(obs); |
49 } | 49 } |
50 | 50 |
51 bool SurfaceModified(SurfaceId surface_id); | 51 bool SurfaceModified(SurfaceId surface_id); |
52 | 52 |
53 // A frame for a surface satisfies a set of sequence numbers in a particular | 53 // A frame for a surface satisfies a set of sequence numbers in a particular |
54 // id namespace. | 54 // id namespace. |
55 void DidSatisfySequences(uint32_t id_namespace, | 55 void DidSatisfySequences(uint32_t client_id, std::vector<uint32_t>* sequence); |
56 std::vector<uint32_t>* sequence); | |
57 | 56 |
58 void RegisterSurfaceIdNamespace(uint32_t id_namespace); | 57 void RegisterSurfaceClientId(uint32_t client_id); |
59 | 58 |
60 // Invalidate a namespace that might still have associated sequences, | 59 // Invalidate a namespace that might still have associated sequences, |
61 // possibly because a renderer process has crashed. | 60 // possibly because a renderer process has crashed. |
62 void InvalidateSurfaceIdNamespace(uint32_t id_namespace); | 61 void InvalidateSurfaceClientId(uint32_t client_id); |
63 | 62 |
64 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered | 63 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered |
65 // and unregistered in any order with respect to each other. | 64 // and unregistered in any order with respect to each other. |
66 // | 65 // |
67 // This happens in practice, e.g. the relationship to between ui::Compositor / | 66 // This happens in practice, e.g. the relationship to between ui::Compositor / |
68 // DelegatedFrameHost is known before ui::Compositor has a surface/client). | 67 // DelegatedFrameHost is known before ui::Compositor has a surface/client). |
69 // However, DelegatedFrameHost can register itself as a client before its | 68 // However, DelegatedFrameHost can register itself as a client before its |
70 // relationship with the ui::Compositor is known. | 69 // relationship with the ui::Compositor is known. |
71 | 70 |
72 // Associates a SurfaceFactoryClient with the surface id namespace it uses. | 71 // Associates a SurfaceFactoryClient with the surface id namespace it uses. |
73 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. | 72 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. |
74 // Caller guarantees the client is alive between register/unregister. | 73 // Caller guarantees the client is alive between register/unregister. |
75 // Reregistering the same namespace when a previous client is active is not | 74 // Reregistering the same namespace when a previous client is active is not |
76 // valid. | 75 // valid. |
77 void RegisterSurfaceFactoryClient(uint32_t id_namespace, | 76 void RegisterSurfaceFactoryClient(uint32_t client_id, |
78 SurfaceFactoryClient* client); | 77 SurfaceFactoryClient* client); |
79 void UnregisterSurfaceFactoryClient(uint32_t id_namespace); | 78 void UnregisterSurfaceFactoryClient(uint32_t client_id); |
80 | 79 |
81 // Associates a |source| with a particular namespace. That namespace and | 80 // Associates a |source| with a particular namespace. That namespace and |
82 // any children of that namespace with valid clients can potentially use | 81 // any children of that namespace with valid clients can potentially use |
83 // that |source|. | 82 // that |source|. |
84 void RegisterBeginFrameSource(BeginFrameSource* source, | 83 void RegisterBeginFrameSource(BeginFrameSource* source, uint32_t client_id); |
85 uint32_t id_namespace); | |
86 void UnregisterBeginFrameSource(BeginFrameSource* source); | 84 void UnregisterBeginFrameSource(BeginFrameSource* source); |
87 | 85 |
88 // Register a relationship between two namespaces. This relationship means | 86 // Register a relationship between two namespaces. This relationship means |
89 // that surfaces from the child namespace will be displayed in the parent. | 87 // that surfaces from the child namespace will be displayed in the parent. |
90 // Children are allowed to use any begin frame source that their parent can | 88 // Children are allowed to use any begin frame source that their parent can |
91 // use. | 89 // use. |
92 void RegisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, | 90 void RegisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, |
93 uint32_t child_namespace); | 91 uint32_t child_namespace); |
94 void UnregisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, | 92 void UnregisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, |
95 uint32_t child_namespace); | 93 uint32_t child_namespace); |
96 | 94 |
97 private: | 95 private: |
98 void RecursivelyAttachBeginFrameSource(uint32_t id_namespace, | 96 void RecursivelyAttachBeginFrameSource(uint32_t client_id, |
99 BeginFrameSource* source); | 97 BeginFrameSource* source); |
100 void RecursivelyDetachBeginFrameSource(uint32_t id_namespace, | 98 void RecursivelyDetachBeginFrameSource(uint32_t client_id, |
101 BeginFrameSource* source); | 99 BeginFrameSource* source); |
102 // Returns true if |child namespace| is or has |search_namespace| as a child. | 100 // Returns true if |child namespace| is or has |search_namespace| as a child. |
103 bool ChildContains(uint32_t child_namespace, uint32_t search_namespace) const; | 101 bool ChildContains(uint32_t child_namespace, uint32_t search_namespace) const; |
104 | 102 |
105 void GarbageCollectSurfaces(); | 103 void GarbageCollectSurfaces(); |
106 | 104 |
107 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 105 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; |
108 SurfaceMap surface_map_; | 106 SurfaceMap surface_map_; |
109 base::ObserverList<SurfaceDamageObserver> observer_list_; | 107 base::ObserverList<SurfaceDamageObserver> observer_list_; |
110 base::ThreadChecker thread_checker_; | 108 base::ThreadChecker thread_checker_; |
111 | 109 |
112 // List of surfaces to be destroyed, along with what sequences they're still | 110 // List of surfaces to be destroyed, along with what sequences they're still |
113 // waiting on. | 111 // waiting on. |
114 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; | 112 using SurfaceDestroyList = std::list<std::unique_ptr<Surface>>; |
115 SurfaceDestroyList surfaces_to_destroy_; | 113 SurfaceDestroyList surfaces_to_destroy_; |
116 | 114 |
117 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 115 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
118 // waited on. | 116 // waited on. |
119 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 117 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
120 | 118 |
121 // Set of valid surface ID namespaces. When a namespace is removed from | 119 // Set of valid surface ID namespaces. When a namespace is removed from |
122 // this set, any remaining sequences with that namespace are considered | 120 // this set, any remaining sequences with that namespace are considered |
123 // satisfied. | 121 // satisfied. |
124 std::unordered_set<uint32_t> valid_surface_id_namespaces_; | 122 std::unordered_set<uint32_t> valid_surface_client_ids_; |
125 | 123 |
126 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient | 124 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient |
127 // pointers guaranteed alive by callers until unregistered. | 125 // pointers guaranteed alive by callers until unregistered. |
128 struct ClientSourceMapping { | 126 struct ClientSourceMapping { |
129 ClientSourceMapping(); | 127 ClientSourceMapping(); |
130 ClientSourceMapping(const ClientSourceMapping& other); | 128 ClientSourceMapping(const ClientSourceMapping& other); |
131 ~ClientSourceMapping(); | 129 ~ClientSourceMapping(); |
132 bool is_empty() const { return !client && children.empty(); } | 130 bool is_empty() const { return !client && children.empty(); } |
133 // The client that's responsible for creating this namespace. Never null. | 131 // The client that's responsible for creating this namespace. Never null. |
134 SurfaceFactoryClient* client; | 132 SurfaceFactoryClient* client; |
135 // The currently assigned begin frame source for this client. | 133 // The currently assigned begin frame source for this client. |
136 BeginFrameSource* source; | 134 BeginFrameSource* source; |
137 // This represents a dag of parent -> children mapping. | 135 // This represents a dag of parent -> children mapping. |
138 std::vector<uint32_t> children; | 136 std::vector<uint32_t> children; |
139 }; | 137 }; |
140 std::unordered_map<uint32_t, ClientSourceMapping> namespace_client_map_; | 138 std::unordered_map<uint32_t, ClientSourceMapping> namespace_client_map_; |
141 // Set of which sources are registered to which namespace. Any child | 139 // Set of which sources are registered to which namespace. Any child |
142 // that is implicitly using this namespace must be reachable by the | 140 // that is implicitly using this namespace must be reachable by the |
143 // parent in the dag. | 141 // parent in the dag. |
144 std::unordered_map<BeginFrameSource*, uint32_t> registered_sources_; | 142 std::unordered_map<BeginFrameSource*, uint32_t> registered_sources_; |
145 | 143 |
146 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 144 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
147 }; | 145 }; |
148 | 146 |
149 } // namespace cc | 147 } // namespace cc |
150 | 148 |
151 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 149 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |