[Skottie] Add raw data factory

... and funnel all existing factories through the new one.

Change-Id: I01ffb95abf178eacc0ad430e730d680800a509c7
Reviewed-on: https://skia-review.googlesource.com/145428
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skottie/include/Skottie.h b/modules/skottie/include/Skottie.h
index 428a3a6..34a94dd 100644
--- a/modules/skottie/include/Skottie.h
+++ b/modules/skottie/include/Skottie.h
@@ -44,6 +44,8 @@
                fAnimatorCount;
     };
 
+    static sk_sp<Animation> Make(const char* data, size_t length,
+                                 const ResourceProvider* = nullptr, Stats* = nullptr);
     static sk_sp<Animation> Make(SkStream*, const ResourceProvider* = nullptr, Stats* = nullptr);
     static sk_sp<Animation> MakeFromFile(const char path[], const ResourceProvider* = nullptr,
                                          Stats* = nullptr);
diff --git a/modules/skottie/src/Skottie.cpp b/modules/skottie/src/Skottie.cpp
index 9934141..7e09c36 100644
--- a/modules/skottie/src/Skottie.cpp
+++ b/modules/skottie/src/Skottie.cpp
@@ -1252,27 +1252,32 @@
 } // namespace
 
 sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider* provider, Stats* stats) {
-    Stats stats_storage;
-    if (!stats)
-        stats = &stats_storage;
-    memset(stats, 0, sizeof(struct Stats));
-
     if (!stream->hasLength()) {
         // TODO: handle explicit buffering?
         LOG("!! cannot parse streaming content\n");
         return nullptr;
     }
 
-    stats->fJsonSize = stream->getLength();
-    const auto t0 = SkTime::GetMSecs();
-
     auto data = SkData::MakeFromStream(stream, stream->getLength());
     if (!data) {
         SkDebugf("!! Failed to read the input stream.\n");
         return nullptr;
     }
 
-    const skjson::DOM dom(static_cast<const char*>(data->data()), data->size());
+    return Make(static_cast<const char*>(data->data()), data->size(), provider, stats);
+}
+
+sk_sp<Animation> Animation::Make(const char* data, size_t data_len,
+                                 const ResourceProvider* provider, Stats* stats) {
+    Stats stats_storage;
+    if (!stats)
+        stats = &stats_storage;
+    memset(stats, 0, sizeof(struct Stats));
+
+    stats->fJsonSize = data_len;
+    const auto t0 = SkTime::GetMSecs();
+
+    const skjson::DOM dom(data, data_len);
     if (!dom.root().is<skjson::ObjectValue>()) {
         // TODO: more error info.
         SkDebugf("!! Failed to parse JSON input.\n");
@@ -1323,8 +1328,8 @@
         const SkString fDir;
     };
 
-    const auto jsonStream =  SkStream::MakeFromFile(path);
-    if (!jsonStream)
+    const auto data =  SkData::MakeFromFileName(path);
+    if (!data)
         return nullptr;
 
     std::unique_ptr<ResourceProvider> defaultProvider;
@@ -1332,7 +1337,8 @@
         defaultProvider = skstd::make_unique<DirectoryResourceProvider>(SkOSPath::Dirname(path));
     }
 
-    return Make(jsonStream.get(), res ? res : defaultProvider.get(), stats);
+    return Make(static_cast<const char*>(data->data()), data->size(),
+                res ? res : defaultProvider.get(), stats);
 }
 
 Animation::Animation(const ResourceProvider& resources,