|
17 | 17 | #include "SkPoint.h"
|
18 | 18 | #include "SkSGClipEffect.h"
|
19 | 19 | #include "SkSGColor.h"
|
| 20 | +#include "SkSGColorFilter.h" |
20 | 21 | #include "SkSGDraw.h"
|
21 | 22 | #include "SkSGGeometryTransform.h"
|
22 | 23 | #include "SkSGGradient.h"
|
@@ -258,9 +259,10 @@ sk_sp<sksg::GeometryNode> AttachPolystarGeometry(const skjson::ObjectValue& jsta
|
258 | 259 | return std::move(path_node);
|
259 | 260 | }
|
260 | 261 |
|
261 |
| -sk_sp<sksg::Color> AttachColor(const skjson::ObjectValue& jcolor, AttachContext* ctx) { |
| 262 | +sk_sp<sksg::Color> AttachColor(const skjson::ObjectValue& jcolor, AttachContext* ctx, |
| 263 | + const char prop_name[]) { |
262 | 264 | auto color_node = sksg::Color::Make(SK_ColorBLACK);
|
263 |
| - BindProperty<VectorValue>(jcolor["c"], &ctx->fAnimators, |
| 265 | + BindProperty<VectorValue>(jcolor[prop_name], &ctx->fAnimators, |
264 | 266 | [color_node](const VectorValue& c) {
|
265 | 267 | color_node->setColor(ValueTraits<VectorValue>::As<SkColor>(c));
|
266 | 268 | });
|
@@ -357,15 +359,15 @@ sk_sp<sksg::PaintNode> AttachStroke(const skjson::ObjectValue& jstroke, AttachCo
|
357 | 359 | }
|
358 | 360 |
|
359 | 361 | sk_sp<sksg::PaintNode> AttachColorFill(const skjson::ObjectValue& jfill, AttachContext* ctx) {
|
360 |
| - return AttachPaint(jfill, ctx, AttachColor(jfill, ctx)); |
| 362 | + return AttachPaint(jfill, ctx, AttachColor(jfill, ctx, "c")); |
361 | 363 | }
|
362 | 364 |
|
363 | 365 | sk_sp<sksg::PaintNode> AttachGradientFill(const skjson::ObjectValue& jfill, AttachContext* ctx) {
|
364 | 366 | return AttachPaint(jfill, ctx, AttachGradient(jfill, ctx));
|
365 | 367 | }
|
366 | 368 |
|
367 | 369 | sk_sp<sksg::PaintNode> AttachColorStroke(const skjson::ObjectValue& jstroke, AttachContext* ctx) {
|
368 |
| - return AttachStroke(jstroke, ctx, AttachPaint(jstroke, ctx, AttachColor(jstroke, ctx))); |
| 370 | + return AttachStroke(jstroke, ctx, AttachPaint(jstroke, ctx, AttachColor(jstroke, ctx, "c"))); |
369 | 371 | }
|
370 | 372 |
|
371 | 373 | sk_sp<sksg::PaintNode> AttachGradientStroke(const skjson::ObjectValue& jstroke,
|
@@ -1106,14 +1108,55 @@ sk_sp<sksg::RenderNode> AttachMask(const skjson::ArrayValue* jmask,
|
1106 | 1108 | return sksg::MaskEffect::Make(std::move(childNode), std::move(mask_group));
|
1107 | 1109 | }
|
1108 | 1110 |
|
| 1111 | + |
| 1112 | +sk_sp<sksg::RenderNode> AttachFillLayerEffect(const skjson::ArrayValue* jeffect_props, |
| 1113 | + AttachContext* ctx, |
| 1114 | + sk_sp<sksg::RenderNode> layer) { |
| 1115 | + if (!jeffect_props) return layer; |
| 1116 | + |
| 1117 | + sk_sp<sksg::Color> color_node; |
| 1118 | + |
| 1119 | + for (const skjson::ObjectValue* jprop : *jeffect_props) { |
| 1120 | + if (!jprop) continue; |
| 1121 | + |
| 1122 | + switch (const auto ty = ParseDefault<int>((*jprop)["ty"], -1)) { |
| 1123 | + case 2: // color |
| 1124 | + color_node = AttachColor(*jprop, ctx, "v"); |
| 1125 | + break; |
| 1126 | + default: |
| 1127 | + LOG("?? Ignoring unsupported fill effect poperty type: %d\n", ty); |
| 1128 | + break; |
| 1129 | + } |
| 1130 | + } |
| 1131 | + |
| 1132 | + return color_node |
| 1133 | + ? sksg::ColorModeFilter::Make(std::move(layer), std::move(color_node), SkBlendMode::kSrcIn) |
| 1134 | + : nullptr; |
| 1135 | +} |
| 1136 | + |
| 1137 | +sk_sp<sksg::RenderNode> AttachLayerEffects(const skjson::ArrayValue& jeffects, |
| 1138 | + AttachContext* ctx, |
| 1139 | + sk_sp<sksg::RenderNode> layer) { |
| 1140 | + for (const skjson::ObjectValue* jeffect : jeffects) { |
| 1141 | + if (!jeffect) continue; |
| 1142 | + |
| 1143 | + switch (const auto ty = ParseDefault<int>((*jeffect)["ty"], -1)) { |
| 1144 | + case 21: // Fill |
| 1145 | + layer = AttachFillLayerEffect((*jeffect)["ef"], ctx, std::move(layer)); |
| 1146 | + break; |
| 1147 | + default: |
| 1148 | + LOG("?? Unsupported layer effect type: %d\n", ty); |
| 1149 | + break; |
| 1150 | + } |
| 1151 | + } |
| 1152 | + |
| 1153 | + return layer; |
| 1154 | +} |
| 1155 | + |
1109 | 1156 | sk_sp<sksg::RenderNode> AttachLayer(const skjson::ObjectValue* jlayer,
|
1110 | 1157 | AttachLayerContext* layerCtx) {
|
1111 | 1158 | if (!jlayer) return nullptr;
|
1112 | 1159 |
|
1113 |
| - if (!(*jlayer)["ef"].is<skjson::NullValue>()) { |
1114 |
| - LOG("?? Unsupported layer effect.\n"); |
1115 |
| - } |
1116 |
| - |
1117 | 1160 | using LayerAttacher = sk_sp<sksg::RenderNode> (*)(const skjson::ObjectValue&, AttachContext*);
|
1118 | 1161 | static constexpr LayerAttacher gLayerAttachers[] = {
|
1119 | 1162 | AttachCompLayer, // 'ty': 0
|
@@ -1157,6 +1200,11 @@ sk_sp<sksg::RenderNode> AttachLayer(const skjson::ObjectValue* jlayer,
|
1157 | 1200 | layer = AttachOpacity(*jtransform, &local_ctx, std::move(layer));
|
1158 | 1201 | }
|
1159 | 1202 |
|
| 1203 | + // Optional layer effects. |
| 1204 | + if (const skjson::ArrayValue* jeffects = (*jlayer)["ef"]) { |
| 1205 | + layer = AttachLayerEffects(*jeffects, &local_ctx, std::move(layer)); |
| 1206 | + } |
| 1207 | + |
1160 | 1208 | class LayerController final : public sksg::GroupAnimator {
|
1161 | 1209 | public:
|
1162 | 1210 | LayerController(sksg::AnimatorList&& layer_animators,
|
|
0 commit comments