Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | List of all members
skottie::Animation::Builder Class Referencefinal

#include <Skottie.h>

Classes

struct  Stats
 

Public Types

enum  Flags : uint32_t { kDeferImageLoading = 0x01 , kPreferEmbeddedFonts = 0x02 }
 

Public Member Functions

 Builder (uint32_t flags=0)
 
 Builder (const Builder &)
 
 Builder (Builder &&)
 
 ~Builder ()
 
const StatsgetStats () const
 
BuildersetResourceProvider (sk_sp< ResourceProvider >)
 
BuildersetFontManager (sk_sp< SkFontMgr >)
 
BuildersetPropertyObserver (sk_sp< PropertyObserver >)
 
BuildersetLogger (sk_sp< Logger >)
 
BuildersetMarkerObserver (sk_sp< MarkerObserver >)
 
BuildersetPrecompInterceptor (sk_sp< PrecompInterceptor >)
 
BuildersetExpressionManager (sk_sp< ExpressionManager >)
 
BuildersetTextShapingFactory (sk_sp< SkShapers::Factory >)
 
sk_sp< Animationmake (SkStream *)
 
sk_sp< Animationmake (const char *data, size_t length)
 
sk_sp< AnimationmakeFromFile (const char path[])
 
const sk_sp< SlotManager > & getSlotManager () const
 

Detailed Description

Definition at line 95 of file Skottie.h.

Member Enumeration Documentation

◆ Flags

Enumerator
kDeferImageLoading 
kPreferEmbeddedFonts 

Definition at line 97 of file Skottie.h.

97 : uint32_t {
98 kDeferImageLoading = 0x01, // Normally, all static image frames are resolved at
99 // load time via ImageAsset::getFrame(0). With this flag,
100 // frames are only resolved when needed, at seek() time.
101 kPreferEmbeddedFonts = 0x02, // Attempt to use the embedded fonts (glyph paths,
102 // normally used as fallback) over native Skia typefaces.
103 };

Constructor & Destructor Documentation

◆ Builder() [1/3]

skottie::Animation::Builder::Builder ( uint32_t  flags = 0)
explicit

Definition at line 304 of file Skottie.cpp.

304: fFlags(flags) {}
FlutterSemanticsFlag flags

◆ Builder() [2/3]

skottie::Animation::Builder::Builder ( const Builder )
default

◆ Builder() [3/3]

skottie::Animation::Builder::Builder ( Builder &&  )
default

◆ ~Builder()

skottie::Animation::Builder::~Builder ( )
default

Member Function Documentation

◆ getSlotManager()

const sk_sp< SlotManager > & skottie::Animation::Builder::getSlotManager ( ) const
inline

Get handle for SlotManager after animation is built.

Definition at line 182 of file Skottie.h.

182{return fSlotManager;}

◆ getStats()

const Stats & skottie::Animation::Builder::getStats ( ) const
inline

Returns various animation build stats.

Returns
Stats (see above).

Definition at line 123 of file Skottie.h.

123{ return fStats; }

◆ make() [1/2]

sk_sp< Animation > skottie::Animation::Builder::make ( const char *  data,
size_t  length 
)

Definition at line 369 of file Skottie.cpp.

369 {
370 TRACE_EVENT0("skottie", TRACE_FUNC);
371
372 // Sanitize factory args.
373 class NullResourceProvider final : public ResourceProvider {
374 sk_sp<SkData> load(const char[], const char[]) const override { return nullptr; }
375 };
376 auto resolvedProvider = fResourceProvider
377 ? fResourceProvider : sk_make_sp<NullResourceProvider>();
378
379 fStats = Stats{};
380
381 fStats.fJsonSize = data_len;
382 const auto t0 = std::chrono::steady_clock::now();
383
384 const skjson::DOM dom(data, data_len);
385 if (!dom.root().is<skjson::ObjectValue>()) {
386 // TODO: more error info.
387 if (fLogger) {
388 fLogger->log(Logger::Level::kError, "Failed to parse JSON input.\n");
389 }
390 return nullptr;
391 }
392 const auto& json = dom.root().as<skjson::ObjectValue>();
393
394 const auto t1 = std::chrono::steady_clock::now();
395 fStats.fJsonParseTimeMS = std::chrono::duration<float, std::milli>{t1-t0}.count();
396
397 const auto version = ParseDefault<SkString>(json["v"], SkString());
398 const auto size = SkSize::Make(ParseDefault<float>(json["w"], 0.0f),
399 ParseDefault<float>(json["h"], 0.0f));
400 const auto fps = ParseDefault<float>(json["fr"], -1.0f),
401 inPoint = ParseDefault<float>(json["ip"], 0.0f),
402 outPoint = std::max(ParseDefault<float>(json["op"], SK_ScalarMax), inPoint),
404
405 if (size.isEmpty() || version.isEmpty() || fps <= 0 ||
407 if (fLogger) {
408 const auto msg = SkStringPrintf(
409 "Invalid animation params (version: %s, size: [%f %f], frame rate: %f, "
410 "in-point: %f, out-point: %f)\n",
412 fLogger->log(Logger::Level::kError, msg.c_str());
413 }
414 return nullptr;
415 }
416
417#if defined(SK_DISABLE_LEGACY_SHAPER_FACTORY)
418 auto factory = fShapingFactory ? fShapingFactory : ::SkShapers::Primitive::Factory();
419#else
420 auto factory = fShapingFactory ? fShapingFactory : ::SkShapers::BestAvailable();
421#endif
422 SkASSERT(resolvedProvider);
423 internal::AnimationBuilder builder(std::move(resolvedProvider), fFontMgr,
424 std::move(fPropertyObserver),
425 std::move(fLogger),
426 std::move(fMarkerObserver),
427 std::move(fPrecompInterceptor),
428 std::move(fExpressionManager),
429 std::move(factory),
430 &fStats, size, duration, fps, fFlags);
431 auto ainfo = builder.parse(json);
432
433 fSlotManager = ainfo.fSlotManager;
434
435 const auto t2 = std::chrono::steady_clock::now();
436 fStats.fSceneParseTimeMS = std::chrono::duration<float, std::milli>{t2-t1}.count();
437 fStats.fTotalLoadTimeMS = std::chrono::duration<float, std::milli>{t2-t0}.count();
438
439 if (!ainfo.fSceneRoot && fLogger) {
440 fLogger->log(Logger::Level::kError, "Could not parse animation.\n");
441 }
442
443 uint32_t flags = 0;
444 if (builder.hasNontrivialBlending()) {
445 flags |= Animation::Flags::kRequiresTopLevelIsolation;
446 }
447
448 return sk_sp<Animation>(new Animation(std::move(ainfo.fSceneRoot),
449 std::move(ainfo.fAnimators),
450 std::move(version),
451 size,
452 inPoint,
453 outPoint,
454 duration,
455 fps,
456 flags));
457}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool SkIsFinite(T x, Pack... values)
static constexpr float sk_ieee_float_divide(float numer, float denom)
#define SK_ScalarMax
Definition: SkScalar.h:24
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
SI T load(const P *ptr)
Definition: Transform_inl.h:98
bool isEmpty() const
Definition: SkString.h:130
const char * c_str() const
Definition: SkString.h:133
double inPoint() const
Definition: Skottie.h:278
const SkSize & size() const
Definition: Skottie.h:286
double fps() const
Definition: Skottie.h:273
const SkString & version() const
Definition: Skottie.h:285
double outPoint() const
Definition: Skottie.h:283
double duration() const
Definition: Skottie.h:268
static float max(float r, float g, float b)
Definition: hsl.cpp:49
SKSHAPER_API sk_sp< Factory > Factory()
sk_sp< Factory > BestAvailable()
Definition: dom.py:1
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56
bool isEmpty() const
Definition: SkSize.h:71
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ make() [2/2]

sk_sp< Animation > skottie::Animation::Builder::make ( SkStream stream)

Animation factories.

Definition at line 349 of file Skottie.cpp.

349 {
350 if (!stream->hasLength()) {
351 // TODO: handle explicit buffering?
352 if (fLogger) {
353 fLogger->log(Logger::Level::kError, "Cannot parse streaming content.\n");
354 }
355 return nullptr;
356 }
357
358 auto data = SkData::MakeFromStream(stream, stream->getLength());
359 if (!data) {
360 if (fLogger) {
361 fLogger->log(Logger::Level::kError, "Failed to read the input stream.\n");
362 }
363 return nullptr;
364 }
365
366 return this->make(static_cast<const char*>(data->data()), data->size());
367}
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition: SkData.cpp:208
sk_sp< Animation > make(SkStream *)
Definition: Skottie.cpp:349

◆ makeFromFile()

sk_sp< Animation > skottie::Animation::Builder::makeFromFile ( const char  path[])

Definition at line 459 of file Skottie.cpp.

459 {
460 const auto data = SkData::MakeFromFileName(path);
461
462 return data ? this->make(static_cast<const char*>(data->data()), data->size())
463 : nullptr;
464}
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition: SkData.cpp:148
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ setExpressionManager()

Animation::Builder & skottie::Animation::Builder::setExpressionManager ( sk_sp< ExpressionManager em)

Registers an ExpressionManager to evaluate AE expressions. If unspecified, expressions in the animation JSON will be ignored.

Definition at line 339 of file Skottie.cpp.

339 {
340 fExpressionManager = std::move(em);
341 return *this;
342}

◆ setFontManager()

Animation::Builder & skottie::Animation::Builder::setFontManager ( sk_sp< SkFontMgr fmgr)

Specify a font manager for loading animation fonts.

Definition at line 314 of file Skottie.cpp.

314 {
315 fFontMgr = std::move(fmgr);
316 return *this;
317}

◆ setLogger()

Animation::Builder & skottie::Animation::Builder::setLogger ( sk_sp< Logger logger)

Register a Logger with this builder.

Definition at line 324 of file Skottie.cpp.

324 {
325 fLogger = std::move(logger);
326 return *this;
327}

◆ setMarkerObserver()

Animation::Builder & skottie::Animation::Builder::setMarkerObserver ( sk_sp< MarkerObserver mobserver)

Register a MarkerObserver with this builder.

Definition at line 329 of file Skottie.cpp.

329 {
330 fMarkerObserver = std::move(mobserver);
331 return *this;
332}

◆ setPrecompInterceptor()

Animation::Builder & skottie::Animation::Builder::setPrecompInterceptor ( sk_sp< PrecompInterceptor pi)

Register a precomp layer interceptor. This allows substituting precomp layers with custom/externally managed content.

Definition at line 334 of file Skottie.cpp.

334 {
335 fPrecompInterceptor = std::move(pi);
336 return *this;
337}

◆ setPropertyObserver()

Animation::Builder & skottie::Animation::Builder::setPropertyObserver ( sk_sp< PropertyObserver pobserver)

Specify a PropertyObserver to receive callbacks during parsing.

See SkottieProperty.h for more details.

Definition at line 319 of file Skottie.cpp.

319 {
320 fPropertyObserver = std::move(pobserver);
321 return *this;
322}

◆ setResourceProvider()

Animation::Builder & skottie::Animation::Builder::setResourceProvider ( sk_sp< ResourceProvider rp)

Specify a loader for external resources (images, etc.).

Definition at line 309 of file Skottie.cpp.

309 {
310 fResourceProvider = std::move(rp);
311 return *this;
312}

◆ setTextShapingFactory()

Animation::Builder & skottie::Animation::Builder::setTextShapingFactory ( sk_sp< SkShapers::Factory factory)

Registers a factory to be used when shaping text. If unspecified, text will be shaped with primitive shaping. See //modules/skshaper/utils/FactoryHelpers.h

Definition at line 344 of file Skottie.cpp.

344 {
345 fShapingFactory = std::move(factory);
346 return *this;
347}

The documentation for this class was generated from the following files: