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 <unordered_map> | 11 #include <unordered_map> |
12 #include <unordered_set> | 12 #include <unordered_set> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "cc/surfaces/surface_damage_observer.h" | 18 #include "cc/surfaces/surface_damage_observer.h" |
19 #include "cc/surfaces/surface_id.h" | 19 #include "cc/surfaces/surface_id.h" |
20 #include "cc/surfaces/surface_sequence.h" | 20 #include "cc/surfaces/surface_sequence.h" |
21 #include "cc/surfaces/surfaces_export.h" | 21 #include "cc/surfaces/surfaces_export.h" |
22 | 22 |
23 namespace cc { | 23 namespace cc { |
24 class BeginFrameSource; | |
24 class CompositorFrame; | 25 class CompositorFrame; |
25 class Surface; | 26 class Surface; |
27 class SurfaceFactoryClient; | |
26 | 28 |
27 class CC_SURFACES_EXPORT SurfaceManager { | 29 class CC_SURFACES_EXPORT SurfaceManager { |
28 public: | 30 public: |
29 SurfaceManager(); | 31 SurfaceManager(); |
30 ~SurfaceManager(); | 32 ~SurfaceManager(); |
31 | 33 |
32 void RegisterSurface(Surface* surface); | 34 void RegisterSurface(Surface* surface); |
33 void DeregisterSurface(SurfaceId surface_id); | 35 void DeregisterSurface(SurfaceId surface_id); |
34 | 36 |
35 // Destroy the Surface once a set of sequence numbers has been satisfied. | 37 // Destroy the Surface once a set of sequence numbers has been satisfied. |
(...skipping 15 matching lines...) Expand all Loading... | |
51 // id namespace. | 53 // id namespace. |
52 void DidSatisfySequences(uint32_t id_namespace, | 54 void DidSatisfySequences(uint32_t id_namespace, |
53 std::vector<uint32_t>* sequence); | 55 std::vector<uint32_t>* sequence); |
54 | 56 |
55 void RegisterSurfaceIdNamespace(uint32_t id_namespace); | 57 void RegisterSurfaceIdNamespace(uint32_t id_namespace); |
56 | 58 |
57 // Invalidate a namespace that might still have associated sequences, | 59 // Invalidate a namespace that might still have associated sequences, |
58 // possibly because a renderer process has crashed. | 60 // possibly because a renderer process has crashed. |
59 void InvalidateSurfaceIdNamespace(uint32_t id_namespace); | 61 void InvalidateSurfaceIdNamespace(uint32_t id_namespace); |
60 | 62 |
63 // SurfaceFactoryClient and namespace hierarchy may be registered in | |
64 // either order. (The relationship to between ui::Compositor / | |
65 // DelegatedFrameHost is known before ui::Compositor has a surface/client). | |
66 // However, DelegatedFrameHost can register itself as a client before | |
67 // its relationship with the ui::Compositor is known.) | |
68 // | |
69 // SurfaceFactoryClient registration for a namespace should outlive | |
70 // the BeginFrameSource registration. | |
71 // | |
72 // Associates a SurfaceFactoryClient with the surface id namespace it uses. | |
73 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. | |
74 // A nullptr client implies unregistering the client from the namespace. | |
75 // Caller guarantees the client is alive between register/unregister. | |
76 // Reregistering the same namespace when a previous client is active is not | |
77 // valid. | |
78 void RegisterSurfaceFactoryClient(uint32_t id_namespace, | |
brianderson
2016/02/18 23:01:07
Is it possible to fold this into RegisterSurfaceId
enne (OOO)
2016/02/19 21:26:57
Sadly, no. SurfaceIdNamespace is about the alloca
| |
79 SurfaceFactoryClient* client); | |
80 | |
81 void RegisterBeginFrameSource(BeginFrameSource* source, | |
82 uint32_t id_namespace); | |
83 void UnregisterBeginFrameSource(BeginFrameSource* source); | |
84 | |
85 // TODO(enne): Call this in the right spots. | |
86 // Children should always register/unregister with their parents. | |
87 // Unregistration of child namespaces should happen before | |
88 // unregistering surface factory clients. | |
89 void RegisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, | |
90 uint32_t child_namespace); | |
91 void UnregisterSurfaceNamespaceHierarchy(uint32_t parent_namespace, | |
92 uint32_t child_namespace); | |
93 | |
61 private: | 94 private: |
95 void RecursivelyAttachBeginFrameSource(uint32_t id_namespace, | |
96 BeginFrameSource* source); | |
97 void RecursivelyDetachBeginFrameSource(uint32_t id_namespace, | |
98 BeginFrameSource* source); | |
99 | |
62 void GarbageCollectSurfaces(); | 100 void GarbageCollectSurfaces(); |
63 | 101 |
64 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; | 102 using SurfaceMap = std::unordered_map<SurfaceId, Surface*, SurfaceIdHash>; |
65 SurfaceMap surface_map_; | 103 SurfaceMap surface_map_; |
66 base::ObserverList<SurfaceDamageObserver> observer_list_; | 104 base::ObserverList<SurfaceDamageObserver> observer_list_; |
67 base::ThreadChecker thread_checker_; | 105 base::ThreadChecker thread_checker_; |
68 | 106 |
69 // List of surfaces to be destroyed, along with what sequences they're still | 107 // List of surfaces to be destroyed, along with what sequences they're still |
70 // waiting on. | 108 // waiting on. |
71 using SurfaceDestroyList = std::list<Surface*>; | 109 using SurfaceDestroyList = std::list<Surface*>; |
72 SurfaceDestroyList surfaces_to_destroy_; | 110 SurfaceDestroyList surfaces_to_destroy_; |
73 | 111 |
74 // Set of SurfaceSequences that have been satisfied by a frame but not yet | 112 // Set of SurfaceSequences that have been satisfied by a frame but not yet |
75 // waited on. | 113 // waited on. |
76 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; | 114 std::unordered_set<SurfaceSequence, SurfaceSequenceHash> satisfied_sequences_; |
77 | 115 |
78 // Set of valid surface ID namespaces. When a namespace is removed from | 116 // Set of valid surface ID namespaces. When a namespace is removed from |
79 // this set, any remaining sequences with that namespace are considered | 117 // this set, any remaining sequences with that namespace are considered |
80 // satisfied. | 118 // satisfied. |
81 std::unordered_set<uint32_t> valid_surface_id_namespaces_; | 119 std::unordered_set<uint32_t> valid_surface_id_namespaces_; |
82 | 120 |
121 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient | |
122 // pointers guaranteed alive by callers until unregistered. | |
123 struct ClientSourceMapping { | |
124 ClientSourceMapping(); | |
125 ~ClientSourceMapping(); | |
126 bool is_empty() const { return !client && !children.size(); } | |
127 // The client that's responsible for creating this namespace. Never null. | |
128 SurfaceFactoryClient* client; | |
129 // The currently assigned begin frame source for this client. | |
130 BeginFrameSource* source; | |
131 // This represents a dag of parent -> children mapping. | |
132 std::vector<uint32_t> children; | |
133 }; | |
134 std::unordered_map<uint32_t, ClientSourceMapping> namespace_client_map_; | |
135 // Set of which sources are registered to which namespace. Any child | |
136 // that is implicitly using this namespace must be reachable by the | |
137 // parent in the dag. | |
138 std::unordered_map<BeginFrameSource*, uint32_t> registered_sources_; | |
139 | |
83 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); | 140 DISALLOW_COPY_AND_ASSIGN(SurfaceManager); |
84 }; | 141 }; |
85 | 142 |
86 } // namespace cc | 143 } // namespace cc |
87 | 144 |
88 #endif // CC_SURFACES_SURFACE_MANAGER_H_ | 145 #endif // CC_SURFACES_SURFACE_MANAGER_H_ |
OLD | NEW |