Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: services/gfx/compositor/graph/snapshot.h

Issue 1749063002: Mozart: Improve internal scene graph representation. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-0
Patch Set: avoid unnecessary hashtable lookups Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/gfx/compositor/graph/scene_label.cc ('k') | services/gfx/compositor/graph/snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 9 #include <memory>
10 #include <unordered_map>
10 #include <unordered_set> 11 #include <unordered_set>
11 12
12 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
13 #include "mojo/services/geometry/interfaces/geometry.mojom.h" 15 #include "mojo/services/geometry/interfaces/geometry.mojom.h"
14 #include "mojo/services/gfx/composition/interfaces/scheduling.mojom.h" 16 #include "mojo/services/gfx/composition/interfaces/scheduling.mojom.h"
15 17
16 namespace compositor { 18 namespace compositor {
17 19
20 class NodeDef;
18 class SceneDef; 21 class SceneDef;
22 class SceneContent;
23 class SceneNodeDef;
19 class RenderFrame; 24 class RenderFrame;
20 25
21 // Describes a single frame snapshot of the scene graph, sufficient for 26 // Describes a single frame snapshot of the scene graph, sufficient for
22 // 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
23 // blocked scene nodes are evaluated to produce a final description of 28 // blocked scene nodes are evaluated to produce a final description of
24 // the frame along with its dependencies. 29 // the frame along with its dependencies.
25 // 30 //
26 // 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
27 // originally used to produce it. The snapshot must be invalidated whenever 32 // originally used to produce it. The snapshot must be invalidated whenever
28 // any of these scenes change. Note that the snapshot will contain a list 33 // any of these scenes change. Note that the snapshot will contain a list
29 // of dependencies even in the case where a frame could not be produced, 34 // of dependencies even in the case where a frame could not be produced,
30 // in which case the dependencies express the set of scenes which, if updated, 35 // in which case the dependencies express the set of scenes which, if updated,
31 // might allow composition to be unblocked and make progress on a subsequent 36 // might allow composition to be unblocked and make progress on a subsequent
32 // frame. 37 // frame.
33 // 38 //
34 // Snapshot objects are not thread-safe since they have direct references to 39 // Snapshot objects are not thread-safe since they have direct references to
35 // the scene graph definition. However, the snapshot's frame is thread-safe 40 // the scene graph definition. However, the snapshot's frame is thread-safe
36 // and is intended to be shared by other components. 41 // and is intended to be sent to the backend rasterizer.
37 class Snapshot { 42 class Snapshot {
38 public: 43 public:
44 // Describes the result of a snapshot operation.
45 enum class Disposition {
46 kSuccess, // The snapshot was successful.
47 kBlocked, // The node was blocked from rendering.
48 kCycle, // The node was blocked due to a cycle, must unwind fully.
49 };
50
39 ~Snapshot(); 51 ~Snapshot();
40 52
41 // Returns true if the snapshot is valid. 53 // Returns true if the snapshot is valid.
42 bool valid() const { return valid_; } 54 bool valid() const { return valid_; }
43 55
44 // Gets the frame produced from this snapshot, or null if none. 56 // Gets the frame produced from this snapshot, or null if none.
45 // 57 //
46 // This is always null if |valid()| is false but it may be null even 58 // This is always null if |valid()| is false but it may be null even
47 // when |valid()| is true if composition was blocked and unable to produce 59 // when |valid()| is true if composition was blocked and unable to produce
48 // a frame during the snapshot operation. 60 // a frame during the snapshot operation.
49 const std::shared_ptr<RenderFrame>& frame() const { return frame_; } 61 const std::shared_ptr<RenderFrame>& frame() const { return frame_; }
50 62
51 // Unconditionally marks the snapshot as invalid. 63 // Unconditionally marks the snapshot as invalid.
52 // 64 //
53 // Returns true if the snapshot became invalid as a result of this operation, 65 // Returns true if the snapshot became invalid as a result of this operation,
54 // or false if it was already invalid. 66 // or false if it was already invalid.
55 bool Invalidate(); 67 bool Invalidate();
56 68
57 // Invalidates the snapshot if it has a dependency on the specified scene. 69 // Invalidates the snapshot if it has a dependency on the specified scene.
58 // When this occurs, the entire list of dependencies is flushed (we no longer 70 // When this occurs, the entire list of dependencies is flushed (we no longer
59 // need them) in case the scene in question or its contents are about to 71 // need them) in case the scene in question or its contents are about to
60 // be destroyed. 72 // be destroyed.
61 // 73 //
62 // Returns true if the snapshot became invalid as a result of this operation, 74 // Returns true if the snapshot became invalid as a result of this operation,
63 // or false if it was already invalid. 75 // or false if it was already invalid.
64 bool InvalidateScene(SceneDef* scene_def); 76 bool InvalidateScene(const SceneDef* scene_def);
77
78 // Returns true if the specified node was blocked from rendering.
79 // Only meaningful while the snapshot is valid.
80 bool IsBlocked(const NodeDef* node) const;
81
82 // Gets the scene content which was resolved by following a scene node link.
83 // Only meaningful while the snapshot is valid.
84 const SceneContent* GetResolvedSceneContent(
85 const SceneNodeDef* scene_node) const;
65 86
66 private: 87 private:
67 friend class SnapshotBuilder; 88 friend class SnapshotBuilder;
68 89
69 Snapshot(); 90 Snapshot();
70 91
71 std::unordered_set<SceneDef*> dependencies_; 92 void ClearContent();
93
94 // Just the set of dependent scene tokens. Used for invalidation.
95 std::unordered_set<uint32_t> dependencies_;
96
97 // The root scene in the graph.
98 // This reference together with |resolved_scenes| retains all of the
99 // nodes used by the snapshot so that we can use bare pointers for nodes
100 // and avoid excess reference counting overhead in other data structures.
101 scoped_refptr<const SceneContent> root_scene_content_;
102
103 // Map of scenes which were resolved from scene nodes.
104 std::unordered_map<const SceneNodeDef*, scoped_refptr<const SceneContent>>
105 resolved_scene_contents_;
106
107 // Node states, true if snapshotted successfully, false if blocked.
108 std::unordered_map<const NodeDef*, Disposition> node_dispositions_;
109
110 // A frame ready to be rendered.
72 std::shared_ptr<RenderFrame> frame_; 111 std::shared_ptr<RenderFrame> frame_;
112
113 // True if the snapshot is still valid.
73 bool valid_ = true; 114 bool valid_ = true;
74 115
75 DISALLOW_COPY_AND_ASSIGN(Snapshot); 116 DISALLOW_COPY_AND_ASSIGN(Snapshot);
76 }; 117 };
77 118
78 // Builder for snapshots. 119 // Builds a table of all of the state which will be required for rendering
120 // a scene graph.
79 class SnapshotBuilder { 121 class SnapshotBuilder {
80 public: 122 public:
81 // Creates a snapshot builder.
82 //
83 // |block_log|, if not null, the snapshotter will append information to
84 // this stream describing the parts of the scene graph for which
85 // composition was blocked.
86 explicit SnapshotBuilder(std::ostream* block_log); 123 explicit SnapshotBuilder(std::ostream* block_log);
87 ~SnapshotBuilder(); 124 ~SnapshotBuilder();
88 125
89 // If not null, the snapshotter will append information to this stream 126 // If not null, the snapshotter will append information to this stream
90 // describing the parts of the scene graph for which composition was blocked. 127 // describing the parts of the scene graph for which composition was blocked.
91 std::ostream* block_log() { return block_log_; } 128 std::ostream* block_log() { return block_log_; }
92 129
93 // Adds a scene dependency to the snapshot. 130 // Snapshots the requested node.
94 void AddSceneDependency(SceneDef* scene); 131 Snapshot::Disposition SnapshotNode(const NodeDef* node,
132 const SceneContent* content);
133
134 // Snapshots the requested scene.
135 Snapshot::Disposition SnapshotScene(const SceneDef* scene,
136 uint32_t version,
137 const SceneNodeDef* referrer_node,
138 const SceneContent* referrer_content);
95 139
96 // Builds a snapshot rooted at the specified scene. 140 // Builds a snapshot rooted at the specified scene.
97 std::unique_ptr<Snapshot> Build( 141 std::unique_ptr<Snapshot> Build(
98 SceneDef* root_scene, 142 const SceneDef* root_scene,
99 const mojo::Rect& viewport, 143 const mojo::Rect& viewport,
100 const mojo::gfx::composition::FrameInfo& frame_info); 144 const mojo::gfx::composition::FrameInfo& frame_info);
101 145
102 private: 146 private:
147 // Snapshots the root scene of a renderer.
148 // This is just like |SnapshotScene| but the errors are reported a little
149 // differently since there is no referrer node.
150 Snapshot::Disposition SnapshotRenderer(const SceneDef* scene);
151
152 // Snapshots the root node of a scene and detects cycles.
153 // This is just like |SnapshotNode| but performs cycle detection which
154 // isn't otherwise needed.
155 Snapshot::Disposition SnapshotRootAndDetectCycles(
156 const NodeDef* node,
157 const SceneContent* content);
158
103 std::ostream* const block_log_; 159 std::ostream* const block_log_;
104 std::unique_ptr<Snapshot> snapshot_; 160 std::unique_ptr<Snapshot> snapshot_;
161 const SceneContent* cycle_ = nullptr; // point where a cycle was detected
105 162
106 DISALLOW_COPY_AND_ASSIGN(SnapshotBuilder); 163 DISALLOW_COPY_AND_ASSIGN(SnapshotBuilder);
107 }; 164 };
108 165
109 } // namespace compositor 166 } // namespace compositor
110 167
111 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_ 168 #endif // SERVICES_GFX_COMPOSITOR_GRAPH_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « services/gfx/compositor/graph/scene_label.cc ('k') | services/gfx/compositor/graph/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698