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