OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_SURFACES_FRAMESINK_MANAGER_H_ |
| 6 #define CC_SURFACES_FRAMESINK_MANAGER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <list> |
| 11 #include <memory> |
| 12 #include <unordered_map> |
| 13 #include <unordered_set> |
| 14 #include <vector> |
| 15 |
| 16 #include "base/logging.h" |
| 17 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/threading/thread_checker.h" |
| 20 #include "cc/surfaces/frame_sink_id.h" |
| 21 #include "cc/surfaces/surface_factory_client.h" |
| 22 #include "cc/surfaces/surfaces_export.h" |
| 23 |
| 24 #if DCHECK_IS_ON() |
| 25 #include <iosfwd> |
| 26 #include <string> |
| 27 #endif |
| 28 |
| 29 namespace cc { |
| 30 class BeginFrameSource; |
| 31 class SurfaceFactoryClient; |
| 32 |
| 33 class CC_SURFACES_EXPORT FrameSinkManager { |
| 34 public: |
| 35 FrameSinkManager(); |
| 36 ~FrameSinkManager(); |
| 37 |
| 38 void RegisterFrameSinkId(const FrameSinkId& frame_sink_id); |
| 39 |
| 40 // Invalidate a frame_sink_id that might still have associated sequences, |
| 41 // possibly because a renderer process has crashed. |
| 42 void InvalidateFrameSinkId(const FrameSinkId& frame_sink_id); |
| 43 |
| 44 // SurfaceFactoryClient, hierarchy, and BeginFrameSource can be registered |
| 45 // and unregistered in any order with respect to each other. |
| 46 // |
| 47 // This happens in practice, e.g. the relationship to between ui::Compositor / |
| 48 // DelegatedFrameHost is known before ui::Compositor has a surface/client). |
| 49 // However, DelegatedFrameHost can register itself as a client before its |
| 50 // relationship with the ui::Compositor is known. |
| 51 |
| 52 // Associates a SurfaceFactoryClient with the surface id frame_sink_id it |
| 53 // uses. |
| 54 // SurfaceFactoryClient and surface namespaces/allocators have a 1:1 mapping. |
| 55 // Caller guarantees the client is alive between register/unregister. |
| 56 // Reregistering the same namespace when a previous client is active is not |
| 57 // valid. |
| 58 void RegisterSurfaceFactoryClient(const FrameSinkId& frame_sink_id, |
| 59 SurfaceFactoryClient* client); |
| 60 void UnregisterSurfaceFactoryClient(const FrameSinkId& frame_sink_id); |
| 61 |
| 62 // Associates a |source| with a particular namespace. That namespace and |
| 63 // any children of that namespace with valid clients can potentially use |
| 64 // that |source|. |
| 65 void RegisterBeginFrameSource(BeginFrameSource* source, |
| 66 const FrameSinkId& frame_sink_id); |
| 67 void UnregisterBeginFrameSource(BeginFrameSource* source); |
| 68 |
| 69 // Register a relationship between two namespaces. This relationship means |
| 70 // that surfaces from the child namespace will be displayed in the parent. |
| 71 // Children are allowed to use any begin frame source that their parent can |
| 72 // use. |
| 73 void RegisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, |
| 74 const FrameSinkId& child_frame_sink_id); |
| 75 void UnregisterFrameSinkHierarchy(const FrameSinkId& parent_frame_sink_id, |
| 76 const FrameSinkId& child_frame_sink_id); |
| 77 |
| 78 private: |
| 79 void RecursivelyAttachBeginFrameSource(const FrameSinkId& frame_sink_id, |
| 80 BeginFrameSource* source); |
| 81 void RecursivelyDetachBeginFrameSource(const FrameSinkId& frame_sink_id, |
| 82 BeginFrameSource* source); |
| 83 |
| 84 // Returns true if |child namespace| is or has |search_frame_sink_id| as a |
| 85 // child. |
| 86 bool ChildContains(const FrameSinkId& child_frame_sink_id, |
| 87 const FrameSinkId& search_frame_sink_id) const; |
| 88 |
| 89 // Set of valid surface ID namespaces. When a namespace is removed from |
| 90 // this set, any remaining sequences with that namespace are considered |
| 91 // satisfied. |
| 92 std::unordered_set<FrameSinkId, FrameSinkIdHash> valid_frame_sink_ids_; |
| 93 |
| 94 // Begin frame source routing. Both BeginFrameSource and SurfaceFactoryClient |
| 95 // pointers guaranteed alive by callers until unregistered. |
| 96 struct FrameSinkSourceMapping { |
| 97 FrameSinkSourceMapping(); |
| 98 FrameSinkSourceMapping(const FrameSinkSourceMapping& other); |
| 99 ~FrameSinkSourceMapping(); |
| 100 bool is_empty() const { return !client && children.empty(); } |
| 101 // The client that's responsible for creating this namespace. Never null. |
| 102 SurfaceFactoryClient* client; |
| 103 // The currently assigned begin frame source for this client. |
| 104 BeginFrameSource* source; |
| 105 // This represents a dag of parent -> children mapping. |
| 106 std::vector<FrameSinkId> children; |
| 107 }; |
| 108 std::unordered_map<FrameSinkId, FrameSinkSourceMapping, FrameSinkIdHash> |
| 109 frame_sink_source_map_; |
| 110 |
| 111 // Set of which sources are registered to which namespace. Any child |
| 112 // that is implicitly using this namespace must be reachable by the |
| 113 // parent in the dag. |
| 114 std::unordered_map<BeginFrameSource*, FrameSinkId> registered_sources_; |
| 115 |
| 116 base::ThreadChecker thread_checker_; |
| 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(FrameSinkManager); |
| 119 }; |
| 120 |
| 121 } // namespace cc |
| 122 |
| 123 #endif // CC_SURFACES_FRAMESINK_MANAGER_H_ |
OLD | NEW |