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 // Primitives express the geometry of the scene, such as quads and references | 5 // Primitives express the geometry of the scene, such as quads and references |
6 // to embedded scenes. Primitives are arranged hierarchically as nodes, | 6 // to embedded scenes. Primitives are arranged hierarchically as nodes, |
7 // each with an associated transformation matrix. | 7 // each with an associated transformation matrix. |
8 | 8 |
9 [DartPackage="mojo_services"] | 9 [DartPackage="mojo_services"] |
10 module mojo.gfx.composition; | 10 module mojo.gfx.composition; |
11 | 11 |
12 import "mojo/services/geometry/interfaces/geometry.mojom"; | 12 import "mojo/services/geometry/interfaces/geometry.mojom"; |
13 import "mojo/services/gfx/composition/interfaces/hit_tests.mojom"; | 13 import "mojo/services/gfx/composition/interfaces/hit_tests.mojom"; |
14 | 14 |
15 // Nodes express the geometry and content of the scene, such as images and | 15 // Nodes express the geometry and content of the scene, such as images and |
16 // references to embedded scenes. Nodes are arranged to form a directed | 16 // references to embedded scenes. Nodes are arranged to form a directed |
17 // acyclic graph of drawing commands. | 17 // acyclic graph of drawing commands. |
18 // | 18 // |
19 // The node graph is processed in pre-order traversal. Starting from the | 19 // RENDERING |
| 20 // |
| 21 // The node graph is renderer in pre-order traversal. Starting from the |
20 // root, the compositor applies the transformation, clip, applies the | 22 // root, the compositor applies the transformation, clip, applies the |
21 // node's operation (if any), then recursively processes the node's children | 23 // node's operation (if any), then recursively processes the node's children |
22 // according to the node's combinator rule. | 24 // according to the node's combinator rule. |
23 // | 25 // |
24 // BLOCKED NODES | 26 // BLOCKED NODES |
25 // | 27 // |
26 // Due to the asynchronous nature of the system, it may happen that some | 28 // Due to the asynchronous nature of the system, it may happen that some |
27 // nodes cannot be processed immediately at drawing time because they require | 29 // nodes cannot be processed immediately at drawing time because they require |
28 // access to certain resources which are not available, such as a specific | 30 // access to certain resources which are not available, such as a specific |
29 // version of a scene which has yet to be produced by some other application. | 31 // version of a scene which has yet to be produced by some other application. |
(...skipping 16 matching lines...) Expand all Loading... |
46 // children will not appear in the output. | 48 // children will not appear in the output. |
47 // | 49 // |
48 // With the |FALLBACK| combinator, the first unblocked child of a node is | 50 // With the |FALLBACK| combinator, the first unblocked child of a node is |
49 // drawn and the remaining nodes are ignored. If the node has children | 51 // drawn and the remaining nodes are ignored. If the node has children |
50 // and all of them are blocked then the node itself is blocked. | 52 // and all of them are blocked then the node itself is blocked. |
51 // | 53 // |
52 // Combinators make it possible to express complex rules such as substituting | 54 // Combinators make it possible to express complex rules such as substituting |
53 // missing content for an earlier version of that content or for a placeholder | 55 // missing content for an earlier version of that content or for a placeholder |
54 // if not available. | 56 // if not available. |
55 // | 57 // |
| 58 // INSTANCING |
| 59 // |
| 60 // The compositor allows nodes to be referenced and reused multiple times |
| 61 // within a scene (this is known as instancing). Instancing makes it easier |
| 62 // to take advantage of combinators for interleaving placeholder content |
| 63 // when certain nodes are blocked from rendering (see above). It also allows |
| 64 // common elements to be reused if desired. |
| 65 // |
| 66 // Likewise, the compositor allows scenes to be multiply referenced so that |
| 67 // the same content can be presented simultaneously in several places. |
| 68 // |
| 69 // CYCLES |
| 70 // |
| 71 // The compositor forbids cycles among nodes within scenes and will |
| 72 // reject scene updates which introduce node cycles by closing the client's |
| 73 // connection. |
| 74 // |
| 75 // Likewise, the compositor forbids cycles across scenes and will respond |
| 76 // to them by considering any scene within a cycle to be blocked from |
| 77 // rendering. |
| 78 // |
| 79 // For example, if there are scenes A, B, and C linked such that rendering |
| 80 // would traverse a path A -> B -> C -> B, the compositor will consider both |
| 81 // scenes B and C to be blocked and will apply A's combinator rules as required |
| 82 // to resolve the problem at the point where it would have entered the cycle. |
| 83 // This may cause A itself to be blocked if there are no applicable |PRUNE| |
| 84 // or |FALLBACK| predicated alternatives. |
| 85 // |
| 86 // This policy protects clients from cross-scene cycles which may have been |
| 87 // introduced downstream in the graph without their knowledge or which may |
| 88 // occur transiently, so long as they are not within the cycle themselves. |
| 89 // It also ensures that cycles are resolved deterministically regardless of |
| 90 // where they are encountered during traversal; all scenes within the cycle |
| 91 // are suppressed. |
| 92 // |
56 // TIPS | 93 // TIPS |
57 // | 94 // |
58 // 1. Reuse nodes when possible to reduce the size of the graph. Consider | 95 // 1. Reuse nodes when possible to reduce the size of the graph. Consider |
59 // using LayerNodeOps to flatten common elements to a texture which can | 96 // using LayerNodeOps to flatten common elements to a texture which can |
60 // be redrawn efficiently in many places. | 97 // be redrawn efficiently in many places. |
61 // | 98 // |
62 // 2. Insert PRUNE or FALLBACK nodes in places where blocking is likely to | 99 // 2. Insert |PRUNE| or |FALLBACK| nodes in places where blocking is likely to |
63 // occur, such as when embedding scenes produced by other applications. | 100 // occur, such as when embedding scenes produced by other applications. |
64 // Provide alternate content where possible. | 101 // Provide alternate content where possible to avoid stalling the |
| 102 // rendering pipeline at these points. |
65 // | 103 // |
66 struct Node { | 104 struct Node { |
67 // The combinator specifies how child nodes are processed. | 105 // The combinator specifies how child nodes are processed. |
68 enum Combinator { | 106 enum Combinator { |
69 // All children are drawn in sequence, blocking if any are blocked. | 107 // All children are drawn in sequence, blocking if any are blocked. |
70 MERGE, | 108 MERGE, |
71 // All children are drawn in sequence, skipping any that are blocked. | 109 // All children are drawn in sequence, skipping any that are blocked. |
72 PRUNE, | 110 PRUNE, |
73 // The first unblocked node is drawn, blocking if there are children | 111 // The first unblocked node is drawn, blocking if there are children |
74 // and all of them are blocked. | 112 // and all of them are blocked. |
(...skipping 19 matching lines...) Expand all Loading... |
94 // Use |kHitIdNone| if the node should not be hit tested. | 132 // Use |kHitIdNone| if the node should not be hit tested. |
95 // | 133 // |
96 // TODO(jeffbrown): This scheme is probably too naive. | 134 // TODO(jeffbrown): This scheme is probably too naive. |
97 uint32 hit_id = kHitIdNone; | 135 uint32 hit_id = kHitIdNone; |
98 | 136 |
99 // The Combinator to apply when processing the children of this node. | 137 // The Combinator to apply when processing the children of this node. |
100 Combinator combinator = Combinator.MERGE; | 138 Combinator combinator = Combinator.MERGE; |
101 | 139 |
102 // The ids of the children of this node. | 140 // The ids of the children of this node. |
103 // It is an error to specify a node id that does not refer to a valid | 141 // It is an error to specify a node id that does not refer to a valid |
104 // node; the compositor will close the connection when the scene | 142 // node or which creates a cycle in the graph; the compositor will close |
105 // is published. | 143 // the connection when the scene is published. |
106 // If a cycle is introduced then the node will be considered to be blocked | |
107 // at the point where recursion occurs. A subsequent rearrangement of | |
108 // scenes which removes the cycle will unblock the node. | |
109 array<uint32>? child_node_ids; | 144 array<uint32>? child_node_ids; |
110 | 145 |
111 // The drawing operation to apply when processing this node. | 146 // The drawing operation to apply when processing this node. |
112 // If null, no drawing operation occurs at this node. | 147 // If null, no drawing operation occurs at this node. |
113 NodeOp? op; | 148 NodeOp? op; |
114 }; | 149 }; |
115 | 150 |
116 // A drawing operation to apply when processing the node. | 151 // A drawing operation to apply when processing the node. |
117 union NodeOp { | 152 union NodeOp { |
118 RectNodeOp rect; | 153 RectNodeOp rect; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // version of the scene is not ready for use at draw time or if it too | 199 // version of the scene is not ready for use at draw time or if it too |
165 // is blocked. | 200 // is blocked. |
166 // | 201 // |
167 // It is often useful to wrap this node with a |LayerNodeOp| when blending | 202 // It is often useful to wrap this node with a |LayerNodeOp| when blending |
168 // the scene with other content. | 203 // the scene with other content. |
169 struct SceneNodeOp { | 204 struct SceneNodeOp { |
170 // The resource id of a valid |SceneResource| to link into the scene. | 205 // The resource id of a valid |SceneResource| to link into the scene. |
171 // It is an error to specify a resource id that does not refer to a scene | 206 // It is an error to specify a resource id that does not refer to a scene |
172 // resource; the compositor will close the connection when the scene | 207 // resource; the compositor will close the connection when the scene |
173 // is published. | 208 // is published. |
174 // If a cycle is introduced then the node will be considered to be blocked | 209 // If a cycle is introduced then the scene will be substituted with |
175 // at the point where recursion occurs. A subsequent rearrangement of | 210 // placeholder content by the compositor. |
176 // scenes which removes the cycle will unblock the node. | |
177 uint32 scene_resource_id; | 211 uint32 scene_resource_id; |
178 | 212 |
179 // The version of the scene that we would like to reference. | 213 // The version of the scene that we would like to reference. |
180 // Use |kSceneVersionNone| to request the most recently published | 214 // Use |kSceneVersionNone| to request the most recently published |
181 // version of the scene if synchronization is unimportant. | 215 // version of the scene if synchronization is unimportant. |
182 uint32 scene_version = 0; // kSceneVersionNone | 216 uint32 scene_version = 0; // kSceneVersionNone |
183 }; | 217 }; |
184 | 218 |
185 // Draws a layer. | 219 // Draws a layer. |
186 // | 220 // |
(...skipping 21 matching lines...) Expand all Loading... |
208 }; | 242 }; |
209 | 243 |
210 // Specifies how blending should take place. | 244 // Specifies how blending should take place. |
211 struct Blend { | 245 struct Blend { |
212 // The opacity for composition in a range from 0 (fully transparent) | 246 // The opacity for composition in a range from 0 (fully transparent) |
213 // to 255 (fully opaque). | 247 // to 255 (fully opaque). |
214 uint8 alpha = 255; | 248 uint8 alpha = 255; |
215 | 249 |
216 // TODO(jeffbrown): Blend modes and texture filtering. | 250 // TODO(jeffbrown): Blend modes and texture filtering. |
217 }; | 251 }; |
OLD | NEW |