[skrive] Initial artboard plumbing

"Artboards" are top-level Rive containers (similar to AE compositions),
holding the scene graphics and related animations.

Artboard properties:

  - name
  - width/height (size)
  - translation (position)
  - origin (anchor point for transforms?)
  - (background) color
  - clip contents flag

Plumb artboard parsing + background rendering, and hook into viewer.

TBR=
Change-Id: Ib188245ce41a76197cf9e0937689adf8243826d6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295244
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
diff --git a/tools/viewer/SkRiveSlide.cpp b/tools/viewer/SkRiveSlide.cpp
new file mode 100644
index 0000000..5be5d81
--- /dev/null
+++ b/tools/viewer/SkRiveSlide.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "tools/viewer/SkRiveSlide.h"
+
+#include "include/core/SkCanvas.h"
+#include "include/core/SkStream.h"
+
+#if defined(SK_ENABLE_SKRIVE)
+
+SkRiveSlide::SkRiveSlide(const SkString& name, const SkString& path)
+    : fPath(path) {
+    fName = name;
+}
+
+SkRiveSlide::~SkRiveSlide() = default;
+
+void SkRiveSlide::load(SkScalar w, SkScalar h) {
+    fWinSize    = {w , h};
+    fRive       = skrive::SkRive::Builder().make(SkFILEStream::Make(fPath.c_str()));
+    fRiveBounds = SkRect::MakeEmpty();
+
+    if (fRive) {
+        SkDebugf("Loaded Rive animation: %zu artboards\n", fRive->artboards().size());
+        for (const auto& ab : fRive->artboards()) {
+            const auto& pos  = ab->getTranslation();
+            const auto& size = ab->getSize();
+
+            fRiveBounds.join(SkRect::MakeXYWH(pos.x, pos.y, size.x, size.y));
+        }
+    } else {
+        SkDebugf("Failed to load Rive animation: %s\n", fPath.c_str());
+    }
+}
+
+void SkRiveSlide::unload() {
+    fRive.reset();
+}
+
+void SkRiveSlide::resize(SkScalar w, SkScalar h) {
+    fWinSize = {w , h};
+}
+
+SkISize SkRiveSlide::getDimensions() const {
+    // We always scale to fill the window.
+    return fWinSize.toCeil();
+}
+
+void SkRiveSlide::draw(SkCanvas* canvas) {
+    if (!fRive) {
+        return;
+    }
+
+    // Scale the Rive artboards to fill our window.
+    SkAutoCanvasRestore acr(canvas, true);
+    canvas->concat(SkMatrix::MakeRectToRect(fRiveBounds,
+                                            SkRect::MakeSize(fWinSize),
+                                            SkMatrix::kCenter_ScaleToFit ));
+
+    for (const auto& ab : fRive->artboards()) {
+        ab->revalidate(nullptr, SkMatrix::I());
+        ab->render(canvas);
+    }
+}
+
+#endif // defined(SK_ENABLE_SKRIVE)