Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Primitives express the geometry of the scene, such as quads and references | |
| 6 // to embedded scenes. Primitives are arranged hierarchically as nodes, | |
| 7 // each with an associated transformation matrix. | |
| 8 | |
| 9 [DartPackage="mojo_services"] | |
| 10 module mojo.gfx.composition; | |
| 11 | |
| 12 import "mojo/services/geometry/interfaces/geometry.mojom"; | |
| 13 import "mojo/services/gfx/composition/interfaces/hit_tests.mojom"; | |
| 14 | |
| 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 | |
| 17 // acyclic graph of drawing commands. | |
| 18 // | |
| 19 // The node graph is processed in pre-order traversal. Starting from the | |
| 20 // root, the compositor applies the transformation, clip, recursively | |
| 21 // processes the node's children according to the node's combinator rule, | |
| 22 // then applies the node's own operation. | |
| 23 // | |
| 24 // BLOCKED NODES | |
| 25 // | |
| 26 // 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 | |
| 28 // 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. | |
| 30 // | |
| 31 // When a node cannot be drawn due to an unsatisfied dependency, it is | |
| 32 // said to be "blocked". Blocked nodes prevent rendering of the entire | |
| 33 // subgraph below them. | |
| 34 // | |
| 35 // NODE COMBINATORS | |
| 36 // | |
| 37 // Node combinator rules describe what should happen when a node which is | |
| 38 // otherwise unblocked has one or more blocked children. | |
| 39 // | |
| 40 // With the |MERGE| combinator, the children of a node are all drawn in | |
| 41 // sequence if none of them are blocked, otherwise the node itself is | |
| 42 // blocked. This is the default. | |
| 43 // | |
| 44 // With the |PRUNE| combinator, the children of a node are all drawn in | |
| 45 // sequence while skipping over any of them which are blocked. Blocked | |
| 46 // children will not appear in the output. | |
| 47 // | |
| 48 // 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 | |
| 50 // and all of them are blocked then the node itself is blocked. | |
| 51 // | |
| 52 // 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 | |
| 54 // if not available. | |
| 55 // | |
| 56 // TIPS | |
| 57 // | |
| 58 // 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 | |
| 60 // be redrawn efficiently in many places. | |
| 61 // | |
| 62 // 2. Insert PRUNE or FALLBACK nodes in places where blocking is likely to | |
| 63 // occur, such as when embedding scenes produced by other applications. | |
| 64 // Provide alternate content where possible. | |
| 65 // | |
| 66 struct Node { | |
| 67 // The combinator specifies how child nodes are processed. | |
| 68 enum Combinator { | |
| 69 // All children are drawn in sequence, blocking if any are blocked. | |
| 70 MERGE, | |
| 71 // All children are drawn in sequence, skipping any that are blocked. | |
| 72 PRUNE, | |
| 73 // The first unblocked node is drawn, blocking if there are children | |
| 74 // and all of them are blocked. | |
| 75 FALLBACK, | |
| 76 }; | |
| 77 | |
| 78 // The forward transformation from the node's content space to its | |
| 79 // containing node's content space. If null, an identity transformation | |
| 80 // is assumed. | |
| 81 // | |
| 82 // For example, if you want to translate the content of the node so that | |
| 83 // it is drawn at X = 100 relative to its containing node's origin, simply | |
| 84 // set a transformation matrix with the X translation component equal to 100. | |
| 85 // Take care not to specify the inverse transform by mistake. | |
| 86 mojo.Transform? content_transform; | |
| 87 | |
| 88 // The clip region to apply to this node's content and to its children | |
| 89 // in content space in addition to any clipping performed by the container. | |
| 90 // If null, the node does not apply any clipping of its own. | |
| 91 Clip? content_clip; | |
|
abarth
2016/01/10 04:22:08
Woah there. This should just be a rectangular cli
jeffbrown
2016/01/16 03:28:31
I need to put some thought into whether nodes have
| |
| 92 | |
| 93 // The hit test id to report if anything within the node is hit. | |
| 94 // Use |kHitIdNone| if the node should not be hit tested. | |
| 95 // | |
| 96 // TODO(jeffbrown): This scheme is probably too naive. | |
|
abarth
2016/01/10 04:22:09
Yeah. :)
It should be enough to get going though
| |
| 97 uint32 hit_id = kHitIdNone; | |
| 98 | |
| 99 // The Combinator to apply when processing the children of this node. | |
| 100 Combinator combinator = Combinator.MERGE; | |
| 101 | |
| 102 // 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 | |
| 104 // node; the compositor will close the connection when the scene | |
| 105 // 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; | |
| 110 | |
| 111 // The drawing operation to apply when processing this node. | |
| 112 // If null, no drawing operation occurs at this node. | |
| 113 NodeOp? op; | |
| 114 }; | |
| 115 | |
| 116 // A drawing operation to apply when processing the node. | |
| 117 union NodeOp { | |
| 118 RectNodeOp rect; | |
| 119 ImageNodeOp image; | |
| 120 SceneNodeOp scene; | |
| 121 LayerNodeOp layer; | |
| 122 // TODO(jeffbrown): Color filters. | |
| 123 }; | |
| 124 | |
| 125 // Fills a rectangle with a solid color. | |
| 126 struct RectNodeOp { | |
| 127 // The rectangle to fill in content space. | |
| 128 mojo.Rect content_rect; | |
| 129 | |
| 130 // The rectangle's color. | |
| 131 Color color; | |
| 132 }; | |
| 133 | |
| 134 // Draws an image at the specified location. | |
| 135 // | |
| 136 // The node containing this operation will be blocked if the image resource | |
| 137 // is not ready for use at draw time. | |
| 138 struct ImageNodeOp { | |
| 139 // The rectangle in which to draw the image in content space. | |
| 140 mojo.Rect content_rect; | |
| 141 | |
| 142 // The portion of the image to draw. | |
| 143 // If null, draws the entire image. | |
| 144 mojo.Rect? image_rect; | |
|
abarth
2016/01/10 04:22:09
Sometimes we call this the source_rect
jeffbrown
2016/01/16 03:28:31
Right. I adopted this convention to line up with
| |
| 145 | |
| 146 // The resource id of a valid |MailboxTextureResource| to draw. | |
| 147 // It is an error to specify a resource id that does not refer to an image | |
| 148 // resource; the compositor will close the connection when the scene | |
| 149 // is published. | |
| 150 uint32 image_resource_id; | |
| 151 | |
| 152 // The blending parameters. If null, uses the default values specified | |
| 153 // in the |Blend| structure declaration. | |
| 154 Blend? blend; | |
| 155 }; | |
| 156 | |
| 157 // Draws a scene. | |
| 158 // | |
| 159 // A scene operation embeds another scene at this point in the scene graph. | |
| 160 // It has essentially the same effect as drawing the root node of the | |
| 161 // referenced scene and drawing it as if it were a child of this node. | |
| 162 // | |
| 163 // The node containing this operation will be blocked if the specified | |
| 164 // version of the scene is not ready for use at draw time or if it too | |
| 165 // is blocked. | |
| 166 // | |
| 167 // It is often useful to wrap this node with a |LayerNodeOp| when blending | |
| 168 // the scene with other content. | |
| 169 struct SceneNodeOp { | |
| 170 // 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 | |
| 172 // resource; the compositor will close the connection when the scene | |
| 173 // is published. | |
| 174 // If a cycle is introduced then the node will be considered to be blocked | |
| 175 // at the point where recursion occurs. A subsequent rearrangement of | |
| 176 // scenes which removes the cycle will unblock the node. | |
| 177 uint32 scene_resource_id; | |
| 178 | |
| 179 // The version of the scene that we would like to reference. | |
| 180 // Use |kSceneVersionNone| to request the most recently published | |
| 181 // version of the scene if synchronization is unimportant. | |
| 182 uint32 scene_version = 0; // kSceneVersionNone | |
| 183 }; | |
| 184 | |
| 185 // Draws a layer. | |
| 186 // | |
| 187 // Conceptually, this operation has the effect of drawing the children of | |
| 188 // the node to a temporary buffer of the specified size which is then | |
| 189 // composited in place like an image. This is useful for ensuring | |
| 190 // correct blending of layered content. | |
| 191 struct LayerNodeOp { | |
|
abarth
2016/01/10 04:22:08
Oh, interesting. I thought this was going to be s
jeffbrown
2016/01/16 03:28:31
Technically you can get that behavior simply by em
| |
| 192 // The size of the layer to create. | |
| 193 mojo.Size layer_size; | |
| 194 | |
| 195 // The blending parameters. If null, uses the default values specified | |
| 196 // in the |Blend| structure declaration. | |
| 197 Blend? blend; | |
| 198 }; | |
| 199 | |
| 200 // Specifies a clip region as a rectangle or rounded rectangle. | |
| 201 union Clip { | |
|
abarth
2016/01/10 04:22:09
I'd skip having this union and just have the clips
jeffbrown
2016/01/16 03:28:31
Done.
| |
| 202 mojo.Rect rect; | |
| 203 mojo.RRect rrect; | |
| 204 // TODO(jeffbrown): paths and masks | |
| 205 }; | |
| 206 | |
| 207 // Specifies a color to draw. | |
| 208 // TODO(jeffbrown): This is silly but unambiguous for prototyping. | |
| 209 // Make it less silly. | |
|
abarth
2016/01/10 04:22:08
I'd have used a single uint32 with a defined color
jeffbrown
2016/01/16 03:28:31
Yeah, I'll probably land there. Will leave it for
| |
| 210 struct Color { | |
| 211 uint8 red; | |
| 212 uint8 green; | |
| 213 uint8 blue; | |
| 214 uint8 alpha; | |
| 215 }; | |
| 216 | |
| 217 // Specifies how blending should take place. | |
| 218 struct Blend { | |
| 219 // The opacity for composition in a range from 0 (fully transparent) | |
| 220 // to 255 (fully opaque). | |
| 221 uint8 alpha = 255; | |
| 222 | |
| 223 // TODO(jeffbrown): Blend modes and texture filtering. | |
| 224 }; | |
| OLD | NEW |