Mozart: Improve internal scene graph representation.

This patch changes the internal scene graph representation into an
immutable data structure which allows for multiple versions to be
maintained simultaneously as well as for the node structure to be
preserved during snapshot operations.

Previously the node structure was traversed once during snapshot
with the intent that all relevant information would be recorded
info an immutable |RenderFrame| object for rasterization and for
hit testing.  However it proved prohibitively expensive to copy
the necessary node structure information into the |RenderFrame|
for hit testing.  So this change does away with all of that.

The compositor now keeps three levels of structural information
to be generated and traversed as required.

1. |SceneDef| which holds a table of immutable |NodeDef| objects
   describing the currently presented state of the scene graph
   and pending updates which have yet to be applied.

2. |SceneContent| which is generated from a |SceneDef| when the
   scene graph is presented.  It consists of an immutable index
   of |NodeDef| objects for a particular version of the scene
   graph as it existed at the time of presentation.  This index
   contains sufficient linkage information to ensure that the
   scene does not contain any internal cross-node cycles and
   that all references resources and nodes are reachable.

3. |Snapshot| which is generated from a collection of |SceneContent|
   objects when the frame is snapshotted.  When producing the
   snapshot, all scene references are resolved and combinator
   rules are evaluated to produce a final description of a single
   frame of graphical content to be rasterized.  The |Snapshot|
   can also be traversed later for hit testing purposes since
   it retains a record of the disposition of each node (whether
   they were blocked).

Altogether, these new representations resolve numerous issues with
the old model such as how we can retain multiple versions of a
scene for as long as required or how we can traverse particular
versions or snapshots of the scene graph to execute queries such
as hit testing.

There are still many optimizations we could apply to the structure
but it's already looking much better overall and there is
significantly less wasted effort during snapshotting when blocked
nodes are discovered.

This also puts us in a nice position to start dealing with
synchronization issues such as applications which publish scenes
referencing textures which have yet to be produced: while walking
the tree we can make a decision of whether to wait or to fallback
on previously published content which may be already be ready with
per-scene granularity.  (To do later.)

(Hit testing itself will be implemented in a later patch.)

BUG=
R=abarth@google.com

Review URL: https://codereview.chromium.org/1749063002 .
diff --git a/mojo/services/gfx/composition/interfaces/nodes.mojom b/mojo/services/gfx/composition/interfaces/nodes.mojom
index 588a8eb..602ec44 100644
--- a/mojo/services/gfx/composition/interfaces/nodes.mojom
+++ b/mojo/services/gfx/composition/interfaces/nodes.mojom
@@ -16,7 +16,9 @@
 // references to embedded scenes.  Nodes are arranged to form a directed
 // acyclic graph of drawing commands.
 //
-// The node graph is processed in pre-order traversal.  Starting from the
+// RENDERING
+//
+// The node graph is renderer in pre-order traversal.  Starting from the
 // root, the compositor applies the transformation, clip, applies the
 // node's operation (if any), then recursively processes the node's children
 // according to the node's combinator rule.
@@ -53,15 +55,51 @@
 // missing content for an earlier version of that content or for a placeholder
 // if not available.
 //
+// INSTANCING
+//
+// The compositor allows nodes to be referenced and reused multiple times
+// within a scene (this is known as instancing).  Instancing makes it easier
+// to take advantage of combinators for interleaving placeholder content
+// when certain nodes are blocked from rendering (see above).  It also allows
+// common elements to be reused if desired.
+//
+// Likewise, the compositor allows scenes to be multiply referenced so that
+// the same content can be presented simultaneously in several places.
+//
+// CYCLES
+//
+// The compositor forbids cycles among nodes within scenes and will
+// reject scene updates which introduce node cycles by closing the client's
+// connection.
+//
+// Likewise, the compositor forbids cycles across scenes and will respond
+// to them by considering any scene within a cycle to be blocked from
+// rendering.
+//
+// For example, if there are scenes A, B, and C linked such that rendering
+// would traverse a path A -> B -> C -> B, the compositor will consider both
+// scenes B and C to be blocked and will apply A's combinator rules as required
+// to resolve the problem at the point where it would have entered the cycle.
+// This may cause A itself to be blocked if there are no applicable |PRUNE|
+// or |FALLBACK| predicated alternatives.
+//
+// This policy protects clients from cross-scene cycles which may have been
+// introduced downstream in the graph without their knowledge or which may
+// occur transiently, so long as they are not within the cycle themselves.
+// It also ensures that cycles are resolved deterministically regardless of
+// where they are encountered during traversal; all scenes within the cycle
+// are suppressed.
+//
 // TIPS
 //
 // 1. Reuse nodes when possible to reduce the size of the graph.  Consider
 //    using LayerNodeOps to flatten common elements to a texture which can
 //    be redrawn efficiently in many places.
 //
-// 2. Insert PRUNE or FALLBACK nodes in places where blocking is likely to
+// 2. Insert |PRUNE| or |FALLBACK| nodes in places where blocking is likely to
 //    occur, such as when embedding scenes produced by other applications.
-//    Provide alternate content where possible.
+//    Provide alternate content where possible to avoid stalling the
+//    rendering pipeline at these points.
 //
 struct Node {
   // The combinator specifies how child nodes are processed.
@@ -101,11 +139,8 @@
 
   // The ids of the children of this node.
   // It is an error to specify a node id that does not refer to a valid
-  // node; the compositor will close the connection when the scene
-  // is published.
-  // If a cycle is introduced then the node will be considered to be blocked
-  // at the point where recursion occurs.  A subsequent rearrangement of
-  // scenes which removes the cycle will unblock the node.
+  // node or which creates a cycle in the graph; the compositor will close
+  // the connection when the scene is published.
   array<uint32>? child_node_ids;
 
   // The drawing operation to apply when processing this node.
@@ -171,9 +206,8 @@
   // It is an error to specify a resource id that does not refer to a scene
   // resource; the compositor will close the connection when the scene
   // is published.
-  // If a cycle is introduced then the node will be considered to be blocked
-  // at the point where recursion occurs.  A subsequent rearrangement of
-  // scenes which removes the cycle will unblock the node.
+  // If a cycle is introduced then the scene will be substituted with
+  // placeholder content by the compositor.
   uint32 scene_resource_id;
 
   // The version of the scene that we would like to reference.