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