@@ -357,6 +357,71 @@ std::vector<sk_sp<sksg::GeometryNode>> AttachRoundGeometryEffect(
357
357
return rounded;
358
358
}
359
359
360
+ std::vector<sk_sp<sksg::RenderNode>> AttachRepeaterDrawEffect (
361
+ const skjson::ObjectValue& jrepeater,
362
+ const AnimationBuilder* abuilder,
363
+ AnimatorScope* ascope,
364
+ std::vector<sk_sp<sksg::RenderNode>>&& draws) {
365
+
366
+ std::vector<sk_sp<sksg::RenderNode>> repeater_draws;
367
+
368
+ if (const skjson::ObjectValue* jtransform = jrepeater[" tr" ]) {
369
+ sk_sp<sksg::RenderNode> repeater_node;
370
+ if (draws.size () > 1 ) {
371
+ repeater_node = sksg::Group::Make (std::move (draws));
372
+ } else {
373
+ repeater_node = std::move (draws[0 ]);
374
+ }
375
+
376
+ const auto repeater_composite = (ParseDefault (jrepeater[" m" ], 1 ) == 1 )
377
+ ? RepeaterAdapter::Composite::kAbove
378
+ : RepeaterAdapter::Composite::kBelow ;
379
+
380
+ auto adapter = sk_make_sp<RepeaterAdapter>(std::move (repeater_node),
381
+ repeater_composite);
382
+
383
+ abuilder->bindProperty <ScalarValue>(jrepeater[" c" ], ascope,
384
+ [adapter](const ScalarValue& c) {
385
+ adapter->setCount (c);
386
+ });
387
+ abuilder->bindProperty <ScalarValue>(jrepeater[" o" ], ascope,
388
+ [adapter](const ScalarValue& o) {
389
+ adapter->setOffset (o);
390
+ });
391
+ abuilder->bindProperty <VectorValue>((*jtransform)[" a" ], ascope,
392
+ [adapter](const VectorValue& a) {
393
+ adapter->setAnchorPoint (ValueTraits<VectorValue>::As<SkPoint>(a));
394
+ });
395
+ abuilder->bindProperty <VectorValue>((*jtransform)[" p" ], ascope,
396
+ [adapter](const VectorValue& p) {
397
+ adapter->setPosition (ValueTraits<VectorValue>::As<SkPoint>(p));
398
+ });
399
+ abuilder->bindProperty <VectorValue>((*jtransform)[" s" ], ascope,
400
+ [adapter](const VectorValue& s) {
401
+ adapter->setScale (ValueTraits<VectorValue>::As<SkVector>(s));
402
+ });
403
+ abuilder->bindProperty <ScalarValue>((*jtransform)[" r" ], ascope,
404
+ [adapter](const ScalarValue& r) {
405
+ adapter->setRotation (r);
406
+ });
407
+ abuilder->bindProperty <ScalarValue>((*jtransform)[" so" ], ascope,
408
+ [adapter](const ScalarValue& so) {
409
+ adapter->setStartOpacity (so);
410
+ });
411
+ abuilder->bindProperty <ScalarValue>((*jtransform)[" eo" ], ascope,
412
+ [adapter](const ScalarValue& eo) {
413
+ adapter->setEndOpacity (eo);
414
+ });
415
+
416
+ repeater_draws.reserve (1 );
417
+ repeater_draws.push_back (adapter->root ());
418
+ } else {
419
+ repeater_draws = std::move (draws);
420
+ }
421
+
422
+ return repeater_draws;
423
+ }
424
+
360
425
using GeometryAttacherT = sk_sp<sksg::GeometryNode> (*)(const skjson::ObjectValue&,
361
426
const AnimationBuilder*, AnimatorScope*);
362
427
static constexpr GeometryAttacherT gGeometryAttachers [] = {
@@ -385,12 +450,22 @@ static constexpr GeometryEffectAttacherT gGeometryEffectAttachers[] = {
385
450
AttachRoundGeometryEffect,
386
451
};
387
452
453
+ using DrawEffectAttacherT =
454
+ std::vector<sk_sp<sksg::RenderNode>> (*)(const skjson::ObjectValue&,
455
+ const AnimationBuilder*, AnimatorScope*,
456
+ std::vector<sk_sp<sksg::RenderNode>>&&);
457
+
458
+ static constexpr DrawEffectAttacherT gDrawEffectAttachers [] = {
459
+ AttachRepeaterDrawEffect,
460
+ };
461
+
388
462
enum class ShapeType {
389
463
kGeometry ,
390
464
kGeometryEffect ,
391
465
kPaint ,
392
466
kGroup ,
393
467
kTransform ,
468
+ kDrawEffect ,
394
469
};
395
470
396
471
struct ShapeInfo {
@@ -409,6 +484,7 @@ const ShapeInfo* FindShapeInfo(const skjson::ObjectValue& jshape) {
409
484
{ " mm" , ShapeType::kGeometryEffect , 0 }, // merge -> AttachMergeGeometryEffect
410
485
{ " rc" , ShapeType::kGeometry , 1 }, // rrect -> AttachRRectGeometry
411
486
{ " rd" , ShapeType::kGeometryEffect , 2 }, // round -> AttachRoundGeometryEffect
487
+ { " rp" , ShapeType::kDrawEffect , 0 }, // repeater -> AttachRepeaterDrawEffect
412
488
{ " sh" , ShapeType::kGeometry , 0 }, // shape -> AttachPathGeometry
413
489
{ " sr" , ShapeType::kGeometry , 3 }, // polystar -> AttachPolyStarGeometry
414
490
{ " st" , ShapeType::kPaint , 1 }, // stroke -> AttachColorStroke
@@ -574,6 +650,16 @@ sk_sp<sksg::RenderNode> AnimationBuilder::attachShape(const skjson::ArrayValue*
574
650
draws.push_back (sksg::Draw::Make (std::move (geo), std::move (paint)));
575
651
ctx->fCommittedAnimators = ctx->fScope ->size ();
576
652
} break ;
653
+ case ShapeType::kDrawEffect : {
654
+ SkASSERT (rec->fInfo .fAttacherIndex < SK_ARRAY_COUNT (gDrawEffectAttachers ));
655
+ if (!draws.empty ()) {
656
+ draws = gDrawEffectAttachers [rec->fInfo .fAttacherIndex ](rec->fJson ,
657
+ this ,
658
+ ctx->fScope ,
659
+ std::move (draws));
660
+ ctx->fCommittedAnimators = ctx->fScope ->size ();
661
+ }
662
+ } break ;
577
663
default :
578
664
break ;
579
665
}
0 commit comments