49#if !defined(SK_DISABLE_LEGACY_SHAPER_FACTORY)
62 fRoot = std::move(
root);
72 const char fmt[], ...)
const {
80 const auto len = vsnprintf(buff,
sizeof(buff),
fmt, va);
84 SkDebugf(
"!! Could not format log message !!\n");
89 static constexpr char kEllipsesStr[] =
"...";
90 strcpy(buff +
sizeof(buff) -
sizeof(kEllipsesStr), kEllipsesStr);
95 fLogger->log(lvl, buff, jsonstr.
c_str());
104 this->
bind(abuilder, jobject[
"o"], fOpacity);
108 void onSync()
override {
109 this->
node()->setOpacity(fOpacity * 0.01f);
114 using INHERITED = DiscardableAdapterBase<OpacityAdapter, sksg::OpacityEffect>;
124 if (adapter->isStatic()) {
128 if (adapter->isStatic()) {
129 if (!dispatched && adapter->node()->getOpacity() >= 1) {
134 fCurrentAnimatorScope->push_back(adapter);
137 return adapter->node();
148 : fResourceProvider(
std::move(rp))
149 , fFontMgr(
std::move(fontmgr))
150 , fPropertyObserver(
std::move(pobserver))
152 , fMarkerObserver(
std::move(mobserver))
153 , fPrecompInterceptor(
std::move(pi))
154 , fExpressionManager(
std::move(expressionmgr))
155 , fShapingFactory(
std::move(shapingFactory))
159 , fCompSize(comp_size)
161 , fFrameRate(framerate)
163 , fHasNontrivialBlending(
false) {}
166 this->dispatchMarkers(jroot[
"markers"]);
171 this->parseAssets(jroot[
"assets"]);
172 this->
parseFonts(jroot[
"fonts"], jroot[
"chars"]);
173 fSlotsRoot = jroot[
"slots"];
177 auto animators = ascope.
release();
181 fRevalidator->setRoot(
root);
182 fRevalidator->revalidate();
184 return { std::move(
root), std::move(animators), std::move(fSlotManager)};
194 fAssets.
set(ParseDefault<SkString>((*asset)[
"id"],
SkString()), { asset,
false });
200 if (!fMarkerObserver || !jmarkers) {
205 const auto frameRatio = 1 / (fFrameRate * fDuration);
215 fMarkerObserver->onMarker(
229 bool dispatched =
false;
230 if (fPropertyObserver) {
231 const char * node_name = fPropertyObserverContext;
232 fPropertyObserver->onColorProperty(node_name,
235 return std::make_unique<ColorPropertyHandle>(c, fRevalidator);
243 bool dispatched =
false;
245 if (fPropertyObserver) {
246 fPropertyObserver->onOpacityProperty(fPropertyObserverContext,
249 return std::make_unique<OpacityPropertyHandle>(o, fRevalidator);
258 bool dispatched =
false;
262 fSlotManager->trackTextValue(
SkString(slotID->begin()), t);
267 if (fPropertyObserver) {
268 fPropertyObserver->onTextProperty(fPropertyObserverContext,
271 return std::make_unique<TextPropertyHandle>(t, fRevalidator);
279 bool dispatched =
false;
281 if (fPropertyObserver) {
282 fPropertyObserver->onTransformProperty(fPropertyObserverContext,
285 return std::make_unique<TransformPropertyHandle>(t, fRevalidator);
293 return fExpressionManager;
296void AnimationBuilder::AutoPropertyTracker::updateContext(
PropertyObserver* observer,
299 fBuilder->fPropertyObserverContext =
name ?
name->begin() : fPrevContext;
310 fResourceProvider = std::move(rp);
315 fFontMgr = std::move(fmgr);
320 fPropertyObserver = std::move(pobserver);
325 fLogger = std::move(
logger);
330 fMarkerObserver = std::move(mobserver);
335 fPrecompInterceptor = std::move(pi);
340 fExpressionManager = std::move(em);
345 fShapingFactory = std::move(factory);
350 if (!
stream->hasLength()) {
366 return this->
make(
static_cast<const char*
>(
data->data()),
data->size());
374 sk_sp<SkData> load(
const char[],
const char[])
const override {
return nullptr; }
376 auto resolvedProvider = fResourceProvider
377 ? fResourceProvider : sk_make_sp<NullResourceProvider>();
382 const auto t0 = std::chrono::steady_clock::now();
394 const auto t1 = std::chrono::steady_clock::now();
395 fStats.fJsonParseTimeMS = std::chrono::duration<float, std::milli>{t1-t0}.count();
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),
409 "Invalid animation params (version: %s, size: [%f %f], frame rate: %f, "
410 "in-point: %f, out-point: %f)\n",
417#if defined(SK_DISABLE_LEGACY_SHAPER_FACTORY)
424 std::move(fPropertyObserver),
426 std::move(fMarkerObserver),
427 std::move(fPrecompInterceptor),
428 std::move(fExpressionManager),
431 auto ainfo =
builder.parse(json);
433 fSlotManager = ainfo.fSlotManager;
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();
439 if (!ainfo.fSceneRoot && fLogger) {
444 if (
builder.hasNontrivialBlending()) {
445 flags |= Animation::Flags::kRequiresTopLevelIsolation;
449 std::move(ainfo.fAnimators),
462 return data ? this->
make(
static_cast<const char*
>(
data->data()),
data->size())
470 : fSceneRoot(
std::move(scene_root))
471 , fAnimators(
std::move(animators))
483 this->
render(canvas, dstR, 0);
499 if (!(renderFlags & RenderFlag::kDisableTopLevelClipping)) {
503 if ((fFlags & Flags::kRequiresTopLevelIsolation) &&
504 !(renderFlags & RenderFlag::kSkipTopLevelIsolation)) {
510 fSceneRoot->
render(canvas);
520 const auto kLastValidFrame = std::nextafterf(fOutPoint, fInPoint),
521 comp_time = SkTPin<float>(fInPoint + t, fInPoint, kLastValidFrame);
523 for (
const auto& anim : fAnimators) {
524 anim->seek(comp_time);
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool SkIsFinite(T x, Pack... values)
static constexpr float sk_ieee_float_divide(float numer, float denom)
sk_sp< T > sk_make_sp(Args &&... args)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
constexpr int SkToInt(S x)
int saveLayer(const SkRect *bounds, const SkPaint *paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void concat(const SkMatrix &matrix)
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
static sk_sp< SkData > MakeFromFileName(const char path[])
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
@ kCenter_ScaleToFit
scales and aligns to center
static const SkMatrix & I()
const char * c_str() const
SkString toString() const
Builder & setExpressionManager(sk_sp< ExpressionManager >)
Builder & setPropertyObserver(sk_sp< PropertyObserver >)
Builder(uint32_t flags=0)
Builder & setResourceProvider(sk_sp< ResourceProvider >)
Builder & setFontManager(sk_sp< SkFontMgr >)
Builder & setPrecompInterceptor(sk_sp< PrecompInterceptor >)
Builder & setMarkerObserver(sk_sp< MarkerObserver >)
Builder & setLogger(sk_sp< Logger >)
sk_sp< Animation > make(SkStream *)
Builder & setTextShapingFactory(sk_sp< SkShapers::Factory >)
sk_sp< Animation > makeFromFile(const char path[])
static sk_sp< Animation > MakeFromFile(const char path[])
void seekFrame(double t, sksg::InvalidationController *ic=nullptr)
const SkSize & size() const
void seekFrameTime(double t, sksg::InvalidationController *=nullptr)
const SkString & version() const
static sk_sp< Animation > Make(const char *data, size_t length)
void render(SkCanvas *canvas, const SkRect *dst=nullptr) const
bool bind(const AnimationBuilder &, const skjson::ObjectValue *, T *)
bool dispatchOpacityProperty(const sk_sp< sksg::OpacityEffect > &) const
sk_sp< sksg::RenderNode > attachOpacity(const skjson::ObjectValue &, sk_sp< sksg::RenderNode >) const
void parseFonts(const skjson::ObjectValue *jfonts, const skjson::ArrayValue *jchars)
bool dispatchTransformProperty(const sk_sp< TransformAdapter2D > &) const
bool dispatchColorProperty(const sk_sp< sksg::Color > &) const
sk_sp< ExpressionManager > expression_manager() const
friend class CompositionBuilder
void log(Logger::Level, const skjson::Value *, const char fmt[],...) const SK_PRINTF_LIKE(4
AnimationInfo parse(const skjson::ObjectValue &)
bool dispatchTextProperty(const sk_sp< TextAdapter > &, const skjson::ObjectValue *jtext) const
AnimationBuilder(sk_sp< ResourceProvider >, sk_sp< SkFontMgr >, sk_sp< PropertyObserver >, sk_sp< Logger >, sk_sp< MarkerObserver >, sk_sp< PrecompInterceptor >, sk_sp< ExpressionManager >, sk_sp< SkShapers::Factory >, Animation::Builder::Stats *, const SkSize &comp_size, float duration, float framerate, uint32_t flags)
const sk_sp< sksg::OpacityEffect > & node() const
static sk_sp< OpacityAdapter > Make(Args &&... args)
OpacityAdapter(const skjson::ObjectValue &jobject, sk_sp< sksg::RenderNode > child, const AnimationBuilder &abuilder)
void setRoot(sk_sp< sksg::RenderNode >)
const SkRect & revalidate(InvalidationController *, const SkMatrix &)
void render(SkCanvas *, const RenderContext *=nullptr) const
FlutterSemanticsFlag flags
static float max(float r, float g, float b)
SK_API sk_sp< SkShader > Color(SkColor)
SKSHAPER_API sk_sp< Factory > Factory()
sk_sp< Factory > BestAvailable()
DlVertices::Builder Builder
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
DEF_SWITCHES_START aot vmservice shared library name
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
T ParseDefault(const skjson::Value &v, const T &defaultValue)
static double time(int loops, Benchmark *bench, Target *target)
static SkString fmt(SkColor4f c)
static constexpr SkRect MakeSize(const SkSize &size)
static constexpr SkSize Make(SkScalar w, SkScalar h)
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)