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