Generic "directory" viewer slide

This is a generalization of "skottie-dir", based on SkSG and operating
at the Slide API level.

For now it is only instantiated for Json slides, but could be used for
other slide "directories" in the future.

TBR=
NOTRY=true
Change-Id: If12429084bddeb172b234344f23eabcdadedcceb
Reviewed-on: https://skia-review.googlesource.com/108002
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 2a58f2d..92741fe 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -13,6 +13,7 @@
 #include "SampleSlide.h"
 #include "SkottieSlide.h"
 #include "SKPSlide.h"
+#include "SlideDir.h"
 
 #include "GrContext.h"
 #include "SkCanvas.h"
@@ -556,14 +557,23 @@
     for (const auto& json : FLAGS_jsons) {
         fSlides.push_back(sk_make_sp<SkottieSlide2>(json));
 
+        SkTArray<sk_sp<Slide>, true> dirSlides;
+
         SkOSFile::Iter it(json.c_str(), ".json");
         SkString jsonName;
         while (it.next(&jsonName)) {
             if (SkCommandLineFlags::ShouldSkip(FLAGS_match, jsonName.c_str())) {
                 continue;
             }
-            fSlides.push_back(sk_make_sp<SkottieSlide>(jsonName, SkOSPath::Join(json.c_str(),
-                                                                                jsonName.c_str())));
+            auto slide = sk_make_sp<SkottieSlide>(jsonName, SkOSPath::Join(json.c_str(),
+                                                                           jsonName.c_str()));
+            dirSlides.push_back(slide);
+            fSlides.push_back(std::move(slide));
+        }
+
+        if (!dirSlides.empty()) {
+            fSlides.push_back(sk_make_sp<SlideDir>(SkStringPrintf("skottie-dir[%s]", json.c_str()),
+                                                   std::move(dirSlides)));
         }
     }
 }