| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ | 5 #ifndef SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ | 6 #define SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "mojo/services/geometry/interfaces/geometry.mojom.h" | 14 #include "mojo/services/geometry/interfaces/geometry.mojom.h" |
| 15 #include "mojo/services/gfx/composition/interfaces/hit_tests.mojom.h" | 15 #include "mojo/services/gfx/composition/interfaces/hit_tests.mojom.h" |
| 16 #include "mojo/services/gfx/composition/interfaces/scheduling.mojom.h" | 16 #include "mojo/services/gfx/composition/interfaces/scheduling.mojom.h" |
| 17 | 17 |
| 18 namespace compositor { | 18 namespace compositor { |
| 19 | 19 |
| 20 class NodeDef; | 20 class Node; |
| 21 class SceneDef; | 21 class SceneDef; |
| 22 class SceneContent; | 22 class SceneContent; |
| 23 class SceneNodeDef; | 23 class SceneNode; |
| 24 class RenderFrame; | 24 class RenderFrame; |
| 25 | 25 |
| 26 // Describes a single frame snapshot of the scene graph, sufficient for | 26 // Describes a single frame snapshot of the scene graph, sufficient for |
| 27 // rendering and hit testing. When the snapshot is made, all predicated and | 27 // rendering and hit testing. When the snapshot is made, all predicated and |
| 28 // blocked scene nodes are evaluated to produce a final description of | 28 // blocked scene nodes are evaluated to produce a final description of |
| 29 // the content of the frame along with its dependencies. | 29 // the content of the frame along with its dependencies. |
| 30 // | 30 // |
| 31 // The snapshot holds a list of dependencies for the scenes whose state was | 31 // The snapshot holds a list of dependencies for the scenes whose state was |
| 32 // originally used to produce it so that the snapshot can be invalidated | 32 // originally used to produce it so that the snapshot can be invalidated |
| 33 // whenever one of these scenes changes. Note that the snapshot will contain | 33 // whenever one of these scenes changes. Note that the snapshot will contain |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const mojo::Rect& viewport, | 69 const mojo::Rect& viewport, |
| 70 const mojo::gfx::composition::FrameInfo& frame_info) const; | 70 const mojo::gfx::composition::FrameInfo& frame_info) const; |
| 71 | 71 |
| 72 // Performs a hit test at the specified point, populating the result. | 72 // Performs a hit test at the specified point, populating the result. |
| 73 // Only valid if |!is_blocked()|. | 73 // Only valid if |!is_blocked()|. |
| 74 void HitTest(const mojo::PointF& point, | 74 void HitTest(const mojo::PointF& point, |
| 75 mojo::gfx::composition::HitTestResult* result) const; | 75 mojo::gfx::composition::HitTestResult* result) const; |
| 76 | 76 |
| 77 // Returns true if the specified node was blocked from rendering. | 77 // Returns true if the specified node was blocked from rendering. |
| 78 // Only valid if |!is_blocked()|. | 78 // Only valid if |!is_blocked()|. |
| 79 bool IsNodeBlocked(const NodeDef* node) const; | 79 bool IsNodeBlocked(const Node* node) const; |
| 80 | 80 |
| 81 // Gets the scene content which was resolved by following a scene node link. | 81 // Gets the scene content which was resolved by following a scene node link. |
| 82 // Only valid if |!is_blocked()|. | 82 // Only valid if |!is_blocked()|. |
| 83 const SceneContent* GetResolvedSceneContent( | 83 const SceneContent* GetResolvedSceneContent( |
| 84 const SceneNodeDef* scene_node) const; | 84 const SceneNode* scene_node) const; |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 friend class base::RefCounted<Snapshot>; | 87 friend class base::RefCounted<Snapshot>; |
| 88 friend class SnapshotBuilder; | 88 friend class SnapshotBuilder; |
| 89 | 89 |
| 90 Snapshot(); | 90 Snapshot(); |
| 91 ~Snapshot(); | 91 ~Snapshot(); |
| 92 | 92 |
| 93 // Disposition of the snapshot as a whole. | 93 // Disposition of the snapshot as a whole. |
| 94 Disposition disposition_; | 94 Disposition disposition_; |
| 95 | 95 |
| 96 // Just the set of dependent scene tokens. Used for invalidation. | 96 // Just the set of dependent scene tokens. Used for invalidation. |
| 97 std::unordered_set<uint32_t> dependencies_; | 97 std::unordered_set<uint32_t> dependencies_; |
| 98 | 98 |
| 99 // The root scene in the graph. | 99 // The root scene in the graph. |
| 100 // This reference together with |resolved_scenes| retains all of the | 100 // This reference together with |resolved_scenes| retains all of the |
| 101 // nodes used by the snapshot so that we can use bare pointers for nodes | 101 // nodes used by the snapshot so that we can use bare pointers for nodes |
| 102 // and avoid excess reference counting overhead in other data structures. | 102 // and avoid excess reference counting overhead in other data structures. |
| 103 scoped_refptr<const SceneContent> root_scene_content_; | 103 scoped_refptr<const SceneContent> root_scene_content_; |
| 104 | 104 |
| 105 // Map of scenes which were resolved from scene nodes. | 105 // Map of scenes which were resolved from scene nodes. |
| 106 std::unordered_map<const SceneNodeDef*, scoped_refptr<const SceneContent>> | 106 std::unordered_map<const SceneNode*, scoped_refptr<const SceneContent>> |
| 107 resolved_scene_contents_; | 107 resolved_scene_contents_; |
| 108 | 108 |
| 109 // Node states, true if snapshotted successfully, false if blocked. | 109 // Node states, true if snapshotted successfully, false if blocked. |
| 110 std::unordered_map<const NodeDef*, Disposition> node_dispositions_; | 110 std::unordered_map<const Node*, Disposition> node_dispositions_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 112 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 // Builds a table of all of the state which will be required for rendering | 115 // Builds a table of all of the state which will be required for rendering |
| 116 // a scene graph. | 116 // a scene graph. |
| 117 class SnapshotBuilder { | 117 class SnapshotBuilder { |
| 118 public: | 118 public: |
| 119 explicit SnapshotBuilder(std::ostream* block_log); | 119 explicit SnapshotBuilder(std::ostream* block_log); |
| 120 ~SnapshotBuilder(); | 120 ~SnapshotBuilder(); |
| 121 | 121 |
| 122 // If not null, the snapshotter will append information to this stream | 122 // If not null, the snapshotter will append information to this stream |
| 123 // describing the parts of the scene graph for which composition was blocked. | 123 // describing the parts of the scene graph for which composition was blocked. |
| 124 std::ostream* block_log() { return block_log_; } | 124 std::ostream* block_log() { return block_log_; } |
| 125 | 125 |
| 126 // Snapshots the requested node. | 126 // Snapshots the requested node. |
| 127 Snapshot::Disposition SnapshotNode(const NodeDef* node, | 127 Snapshot::Disposition SnapshotNode(const Node* node, |
| 128 const SceneContent* content); | 128 const SceneContent* content); |
| 129 | 129 |
| 130 // Snapshots the requested scene. | 130 // Snapshots the requested scene. |
| 131 Snapshot::Disposition SnapshotScene(const SceneDef* scene, | 131 Snapshot::Disposition SnapshotScene(const SceneDef* scene, |
| 132 uint32_t version, | 132 uint32_t version, |
| 133 const SceneNodeDef* referrer_node, | 133 const SceneNode* referrer_node, |
| 134 const SceneContent* referrer_content); | 134 const SceneContent* referrer_content); |
| 135 | 135 |
| 136 // Builds a snapshot rooted at the specified scene. | 136 // Builds a snapshot rooted at the specified scene. |
| 137 scoped_refptr<const Snapshot> Build(const SceneDef* root_scene); | 137 scoped_refptr<const Snapshot> Build(const SceneDef* root_scene); |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 // Snapshots the root scene of a renderer. | 140 // Snapshots the root scene of a renderer. |
| 141 // This is just like |SnapshotScene| but the errors are reported a little | 141 // This is just like |SnapshotScene| but the errors are reported a little |
| 142 // differently since there is no referrer node. | 142 // differently since there is no referrer node. |
| 143 Snapshot::Disposition SnapshotRenderer(const SceneDef* scene); | 143 Snapshot::Disposition SnapshotRenderer(const SceneDef* scene); |
| 144 | 144 |
| 145 // Snapshots the root node of a scene and detects cycles. | 145 // Snapshots the root node of a scene and detects cycles. |
| 146 // This is just like |SnapshotNode| but performs cycle detection which | 146 // This is just like |SnapshotNode| but performs cycle detection which |
| 147 // isn't otherwise needed. | 147 // isn't otherwise needed. |
| 148 Snapshot::Disposition SnapshotRootAndDetectCycles( | 148 Snapshot::Disposition SnapshotRootAndDetectCycles( |
| 149 const NodeDef* node, | 149 const Node* node, |
| 150 const SceneContent* content); | 150 const SceneContent* content); |
| 151 | 151 |
| 152 std::ostream* const block_log_; | 152 std::ostream* const block_log_; |
| 153 scoped_refptr<Snapshot> snapshot_; | 153 scoped_refptr<Snapshot> snapshot_; |
| 154 const SceneContent* cycle_ = nullptr; // point where a cycle was detected | 154 const SceneContent* cycle_ = nullptr; // point where a cycle was detected |
| 155 | 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(SnapshotBuilder); | 156 DISALLOW_COPY_AND_ASSIGN(SnapshotBuilder); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 } // namespace compositor | 159 } // namespace compositor |
| 160 | 160 |
| 161 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ | 161 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ |
| OLD | NEW |