Skip to content

Commit 6e487e6

Browse files
fmalitaSkia Commit-Bot
authored and
Skia Commit-Bot
committed
[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 <[email protected]> Commit-Queue: Florin Malita <[email protected]>
1 parent 95df57b commit 6e487e6

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

modules/skottie/include/Skottie.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class SK_API Animation : public SkRefCnt {
4444
fAnimatorCount;
4545
};
4646

47+
static sk_sp<Animation> Make(const char* data, size_t length,
48+
const ResourceProvider* = nullptr, Stats* = nullptr);
4749
static sk_sp<Animation> Make(SkStream*, const ResourceProvider* = nullptr, Stats* = nullptr);
4850
static sk_sp<Animation> MakeFromFile(const char path[], const ResourceProvider* = nullptr,
4951
Stats* = nullptr);

modules/skottie/src/Skottie.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,27 +1252,32 @@ sk_sp<sksg::RenderNode> AttachComposition(const skjson::ObjectValue& comp, Attac
12521252
} // namespace
12531253

12541254
sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider* provider, Stats* stats) {
1255-
Stats stats_storage;
1256-
if (!stats)
1257-
stats = &stats_storage;
1258-
memset(stats, 0, sizeof(struct Stats));
1259-
12601255
if (!stream->hasLength()) {
12611256
// TODO: handle explicit buffering?
12621257
LOG("!! cannot parse streaming content\n");
12631258
return nullptr;
12641259
}
12651260

1266-
stats->fJsonSize = stream->getLength();
1267-
const auto t0 = SkTime::GetMSecs();
1268-
12691261
auto data = SkData::MakeFromStream(stream, stream->getLength());
12701262
if (!data) {
12711263
SkDebugf("!! Failed to read the input stream.\n");
12721264
return nullptr;
12731265
}
12741266

1275-
const skjson::DOM dom(static_cast<const char*>(data->data()), data->size());
1267+
return Make(static_cast<const char*>(data->data()), data->size(), provider, stats);
1268+
}
1269+
1270+
sk_sp<Animation> Animation::Make(const char* data, size_t data_len,
1271+
const ResourceProvider* provider, Stats* stats) {
1272+
Stats stats_storage;
1273+
if (!stats)
1274+
stats = &stats_storage;
1275+
memset(stats, 0, sizeof(struct Stats));
1276+
1277+
stats->fJsonSize = data_len;
1278+
const auto t0 = SkTime::GetMSecs();
1279+
1280+
const skjson::DOM dom(data, data_len);
12761281
if (!dom.root().is<skjson::ObjectValue>()) {
12771282
// TODO: more error info.
12781283
SkDebugf("!! Failed to parse JSON input.\n");
@@ -1323,16 +1328,17 @@ sk_sp<Animation> Animation::MakeFromFile(const char path[], const ResourceProvid
13231328
const SkString fDir;
13241329
};
13251330

1326-
const auto jsonStream = SkStream::MakeFromFile(path);
1327-
if (!jsonStream)
1331+
const auto data = SkData::MakeFromFileName(path);
1332+
if (!data)
13281333
return nullptr;
13291334

13301335
std::unique_ptr<ResourceProvider> defaultProvider;
13311336
if (!res) {
13321337
defaultProvider = skstd::make_unique<DirectoryResourceProvider>(SkOSPath::Dirname(path));
13331338
}
13341339

1335-
return Make(jsonStream.get(), res ? res : defaultProvider.get(), stats);
1340+
return Make(static_cast<const char*>(data->data()), data->size(),
1341+
res ? res : defaultProvider.get(), stats);
13361342
}
13371343

13381344
Animation::Animation(const ResourceProvider& resources,

0 commit comments

Comments
 (0)