60const MaskInfo* GetMaskInfo(
char mode) {
61 static constexpr MaskInfo k_add_info =
63 static constexpr MaskInfo k_int_info =
65 static constexpr MaskInfo k_sub_info =
67 static constexpr MaskInfo k_dif_info =
71 case 'a':
return &k_add_info;
72 case 'f':
return &k_dif_info;
73 case 'i':
return &k_int_info;
74 case 's':
return &k_sub_info;
81class MaskAdapter final :
public AnimatablePropertyContainer {
87 fMaskPaint->setAntiAlias(
true);
88 if (!this->requires_isolation()) {
90 fMaskPaint->setBlendMode(bm);
93 this->bind(abuilder, jmask[
"o"], fOpacity);
95 if (this->bind(abuilder, jmask[
"f"], fFeather)) {
102 bool hasEffect()
const {
103 return !this->isStatic()
105 || fFeather !=
SkV2{0,0};
114 if (this->requires_isolation()) {
122 void onSync()
override {
123 fMaskPaint->setOpacity(fOpacity * 0.01f);
126 static constexpr SkScalar kFeatherToSigma = 0.38f;
127 fMaskFilter->setSigma({fFeather.x * kFeatherToSigma,
128 fFeather.y * kFeatherToSigma});
132 bool requires_isolation()
const {
157 const AnimationBuilder* abuilder,
159 if (!jmask)
return childNode;
168 bool has_effect =
false;
174 if (!jmode || jmode->
size() != 1) {
185 const auto* mask_info = GetMaskInfo(
mode);
191 auto mask_path = abuilder->attachPath((*
m)[
"pt"]);
197 auto mask_blend_mode = mask_info->fBlendMode;
198 auto mask_merge_mode = mask_info->fMergeMode;
199 auto mask_inverted = ParseDefault<bool>((*
m)[
"inv"],
false);
201 if (mask_stack.
empty()) {
207 mask_inverted = mask_inverted != mask_info->fInvertGeometry;
213 auto mask_adapter = sk_make_sp<MaskAdapter>(*
m, *abuilder, mask_blend_mode);
214 abuilder->attachDiscardableAdapter(mask_adapter);
216 has_effect |= mask_adapter->hasEffect();
218 mask_stack.
push_back({ std::move(mask_path),
219 std::move(mask_adapter),
224 if (mask_stack.
empty())
231 if (mask_stack.
size() == 1) {
233 clip_node = std::move(mask_stack.
front().mask_path);
236 std::vector<sksg::Merge::Rec> merge_recs;
239 for (
auto& mask : mask_stack) {
240 merge_recs.push_back({std::move(mask.mask_path), mask.merge_mode });
250 if (mask_stack.size() == 1) {
252 const auto rec = mask_stack.front();
253 maskNode = rec.mask_adapter->makeMask(std::move(rec.mask_path));
255 std::vector<sk_sp<sksg::RenderNode>> masks;
256 masks.reserve(
SkToSizeT(mask_stack.size()));
257 for (
auto& rec : mask_stack) {
258 masks.push_back(rec.mask_adapter->makeMask(std::move(rec.mask_path)));
267class LayerController final :
public Animator {
271 size_t tanim_count,
float in,
float out)
272 : fLayerAnimators(
std::move(layer_animators))
273 , fLayerNode(
std::move(layer))
274 , fTransformAnimatorsCount(tanim_count)
279 StateChanged onSeek(
float t)
override {
281 const auto active = (t >= fIn && t < fOut) || (t > fOut && t <= fIn);
283 bool changed =
false;
285 changed |= (fLayerNode->
isVisible() != active);
292 const auto dispatch_count = active ? fLayerAnimators.size()
293 : fTransformAnimatorsCount;
294 for (
size_t i = 0;
i < dispatch_count; ++
i) {
295 changed |= fLayerAnimators[
i]->seek(t);
304 const size_t fTransformAnimatorsCount;
309class MotionBlurController final :
public Animator {
312 : fMotionBlurEffect(
std::move(mbe)) {}
318 StateChanged onSeek(
float t)
override {
319 fMotionBlurEffect->setT(t);
340 if (this->
isCamera() || ParseDefault<int>(jlayer[
"ddd"], 0)) {
341 fFlags |= Flags::kIs3D;
348 static constexpr int kCameraLayerType = 13;
350 return fType == kCameraLayerType;
356 const auto transform_chain_type = this->is3D() ? TransformType::k3D
357 : TransformType::k2D;
358 fLayerTransform = this->getTransform(abuilder, cbuilder, transform_chain_type);
360 return fLayerTransform;
365 TransformType ttype) {
366 const auto cache_valid_mask = (1ul << ttype);
367 if (!(fFlags & cache_valid_mask)) {
369 fFlags |= cache_valid_mask;
373 fTransformCache[ttype] = this->doAttachTransform(abuilder, cbuilder, ttype);
374 fLayerScope = ascope.release();
375 fTransformAnimatorCount = fLayerScope.size();
378 return fTransformCache[ttype];
382 CompositionBuilder* cbuilder,
383 TransformType ttype) {
384 if (
auto* parent_builder = cbuilder->layerBuilder(fParentIndex)) {
386 return parent_builder->getTransform(abuilder, cbuilder, ttype);
391 if (ttype == TransformType::k3D && !this->
isCamera()) {
392 return cbuilder->getCameraTransform();
399 CompositionBuilder* cbuilder,
400 TransformType ttype) {
406 auto parent_transform = this->getParentTransform(abuilder, cbuilder, ttype);
414 return abuilder.attachCamera(fJlayer,
421 ? abuilder.attachMatrix3D(*jtransform, std::move(parent_transform), fAutoOrient)
422 : abuilder.attachMatrix2D(*jtransform, std::move(parent_transform), fAutoOrient);
425bool LayerBuilder::hasMotionBlur(
const CompositionBuilder* cbuilder)
const {
426 return cbuilder->fMotionBlurSamples > 1
427 && cbuilder->fMotionBlurAngle > 0
438 AnimationBuilder::LayerInfo*)
const;
447 kTransformEffects = 0x01,
451 static constexpr struct {
454 } gLayerBuildInfo[] = {
455 { &AnimationBuilder::attachPrecompLayer, kTransformEffects },
456 { &AnimationBuilder::attachSolidLayer , kTransformEffects },
457 { &AnimationBuilder::attachFootageLayer, kTransformEffects },
458 { &AnimationBuilder::attachNullLayer , 0 },
459 { &AnimationBuilder::attachShapeLayer , 0 },
460 { &AnimationBuilder::attachTextLayer , 0 },
461 { &AnimationBuilder::attachAudioLayer , kForceSeek },
464 { &AnimationBuilder::attachFootageLayer, kTransformEffects },
468 { &AnimationBuilder::attachNullLayer , 0 },
472 if (fType < 0 ||
static_cast<size_t>(fType) >=
std::size(gLayerBuildInfo)) {
476 const auto& build_info = gLayerBuildInfo[fType];
485 if (build_info.fBuilder) {
486 layer = (abuilder.*(build_info.fBuilder))(fJlayer, &fInfo);
491 if (::skottie::Parse<float>(fJlayer[
"w"], &
w) && ::skottie::Parse<float>(fJlayer[
"h"], &
h)) {
494#ifdef SK_LEGACY_SKOTTIE_CLIPPING
502 layer = AttachMask(fJlayer[
"masksProperties"], &abuilder, std::move(layer));
506 const auto transform_effects = (build_info.fFlags & kTransformEffects);
509 if (fLayerTransform && !transform_effects) {
520 if (fLayerTransform && transform_effects) {
533 layer = abuilder.
attachOpacity(*jtransform, std::move(layer));
537 fContentTree = layer;
538 if (ParseDefault<bool>(fJlayer[
"hd"],
false)) {
542 const auto has_animators = !abuilder.fCurrentAnimatorScope->empty();
543 const auto force_seek_count = build_info.fFlags & kForceSeek
544 ? abuilder.fCurrentAnimatorScope->size()
545 : fTransformAnimatorCount;
554 if (layer && has_animators && this->hasMotionBlur(cbuilder)) {
557 cbuilder->fMotionBlurSamples,
558 cbuilder->fMotionBlurAngle,
559 cbuilder->fMotionBlurPhase);
560 controller = sk_make_sp<MotionBlurController>(motion_blur);
561 layer = std::move(motion_blur);
564 abuilder.fCurrentAnimatorScope->push_back(std::move(controller));
566 if (ParseDefault<bool>(fJlayer[
"td"],
false)) {
572 const auto matte_mode = prev_layer
573 ? ParseDefault<size_t>(fJlayer[
"tt"], 0)
575 if (matte_mode > 0) {
583 if (matte_mode <=
std::size(gMatteModes)) {
586 prev_layer->fContentTree,
587 gMatteModes[matte_mode - 1]);
590 "Unknown track matte mode: %zu\n", matte_mode);
596 return abuilder.attachBlendMode(fJlayer, std::move(layer));
sksg::Merge::Mode fMergeMode
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
constexpr SkColor SK_ColorBLACK
constexpr size_t SkToSizeT(S x)
const char * begin() const
sk_sp< sksg::RenderNode > attachOpacity(const skjson::ObjectValue &, sk_sp< sksg::RenderNode >) const
void log(Logger::Level, const skjson::Value *, const char fmt[],...) const SK_PRINTF_LIKE(4
sk_sp< sksg::RenderNode > attachEffects(const skjson::ArrayValue &, sk_sp< sksg::RenderNode >) const
sk_sp< sksg::RenderNode > attachStyles(const skjson::ArrayValue &, sk_sp< sksg::RenderNode >) const
LayerBuilder(const skjson::ObjectValue &jlayer, const SkSize &comp_size)
sk_sp< sksg::RenderNode > buildRenderTree(const AnimationBuilder &, CompositionBuilder *, const LayerBuilder *prev_layer)
sk_sp< sksg::Transform > buildTransform(const AnimationBuilder &, CompositionBuilder *)
static sk_sp< MotionBlurEffect > Make(sk_sp< Animator > animator, sk_sp< sksg::RenderNode > child, size_t samples_per_frame, float shutter_angle, float shutter_phase)
static sk_sp< BlurImageFilter > Make()
static sk_sp< ClipEffect > Make(sk_sp< RenderNode > child, sk_sp< GeometryNode > clip, bool aa=false, bool force_clip=false)
static sk_sp< Draw > Make(sk_sp< GeometryNode > geo, sk_sp< PaintNode > paint)
static sk_sp< Group > Make()
static sk_sp< RenderNode > Make(sk_sp< RenderNode > child, sk_sp< ImageFilter > filter)
static sk_sp< LayerEffect > Make(sk_sp< RenderNode > child, SkBlendMode mode=SkBlendMode::kSrcOver)
static sk_sp< MaskEffect > Make(sk_sp< RenderNode > child, sk_sp< RenderNode > mask, Mode mode=Mode::kAlphaNormal)
static sk_sp< Merge > Make(std::vector< Rec > &&recs)
static sk_sp< Rect > Make()
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
SK_API sk_sp< SkShader > Color(SkColor)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By default
std::vector< sk_sp< Animator > > AnimatorScope
T ParseDefault(const skjson::Value &v, const T &defaultValue)
static constexpr SkRect MakeWH(float w, float h)