Initial scene graph (SkSG)

Sketching a thin (as in close-to-skia-semantics) scene graph API, focused on
external animation, inval tracking and minimal repaint.

Only a few concrete classes/features so far:

* Rect/Color/Transform/Group
* basic inval tracking
* a trivial animated sample with inval visualization

Pretty much everything (especially naming) is volatile, so treat accordingly.

The interesting bits to review are likely in Node.{h,cpp} for inval and
SampleSGInval.cpp for usage.

Initial class hierarchy:

  * Node: invalidation/ancestors tracking
  |
   -- * RenderNode: onRender(SkCanvas)
  |   |
  |    -- * Draw (concrete): rendering a [geometry, paint] tuple
  |   |
  |    -- * Group (concrete): grouping multiple RenderNodes
  |   |
  |    -- * EffectNode: single-descendant effect wrapper
  |       |
  |        -- * Transform (concrete): transform effect
  |
   -- * PaintNode: onMakePaint()
  |   |
  |    -- * Color (concrete): SkColor paint wrapper
  |
   -- * GeometryNode: onComputeBounds(), onDraw(SkCanvas, SkPaint)
      |
       -- * Rect (concrete): SkRect wrapper

TBR=

Change-Id: Iacf9b773c181a7582ecd31ee968562f179d1aa1b
Reviewed-on: https://skia-review.googlesource.com/85502
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/experimental/sksg/SkSGGroup.cpp b/experimental/sksg/SkSGGroup.cpp
new file mode 100644
index 0000000..b8e28f7
--- /dev/null
+++ b/experimental/sksg/SkSGGroup.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkSGGroup.h"
+
+namespace sksg {
+
+Group::Group() {}
+
+Group::~Group() {
+    for (const auto& child : fChildren) {
+        child->removeInvalReceiver(this);
+    }
+}
+
+void Group::addChild(sk_sp<RenderNode> node) {
+    // should we allow duplicates?
+    for (const auto& child : fChildren) {
+        if (child == node) {
+            return;
+        }
+    }
+
+    node->addInvalReceiver(this);
+    fChildren.push_back(std::move(node));
+}
+
+void Group::removeChild(const sk_sp<RenderNode>& node) {
+    int origCount = fChildren.count();
+    for (int i = 0; i < origCount; ++i) {
+        if (fChildren[i] == node) {
+            fChildren.removeShuffle(i);
+            node->removeInvalReceiver(this);
+            break;
+        }
+    }
+    SkASSERT(fChildren.count() == origCount - 1);
+}
+
+void Group::onRender(SkCanvas* canvas) const {
+    for (const auto& child : fChildren) {
+        child->render(canvas);
+    }
+}
+
+void Group::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
+    for (const auto& child : fChildren) {
+        child->revalidate(ic, ctm);
+    }
+}
+
+} // namespace sksg