[skotty,sksg] Initial RRect support
Bug: skia:
Change-Id: I51bf6619e8d857d5d14fcd6651c144bd3c59453f
Reviewed-on: https://skia-review.googlesource.com/90027
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/experimental/skotty/Skotty.cpp b/experimental/skotty/Skotty.cpp
index 7a8e9e3..b94cad2 100644
--- a/experimental/skotty/Skotty.cpp
+++ b/experimental/skotty/Skotty.cpp
@@ -21,6 +21,7 @@
#include "SkSGInvalidationController.h"
#include "SkSGGroup.h"
#include "SkSGPath.h"
+#include "SkSGRect.h"
#include "SkSGTransform.h"
#include "SkStream.h"
#include "SkTArray.h"
@@ -79,7 +80,7 @@
sk_sp<sksg::RenderNode> AttachTransform(const Json::Value& t, AttachContext* ctx,
sk_sp<sksg::RenderNode> wrapped_node) {
- if (!t.isObject())
+ if (!t.isObject() || !wrapped_node)
return wrapped_node;
auto xform = sk_make_sp<CompositeTransform>(wrapped_node);
@@ -143,6 +144,26 @@
return path_attached ? path_node : nullptr;
}
+sk_sp<sksg::GeometryNode> AttachRRectGeometry(const Json::Value& jrect, AttachContext* ctx) {
+ SkASSERT(jrect.isObject());
+
+ auto rect_node = sksg::RRect::Make();
+ auto composite = sk_make_sp<CompositeRRect>(rect_node);
+
+ auto p_attached = AttachProperty<VectorValue, SkPoint>(jrect["p"], ctx, composite,
+ [](const sk_sp<CompositeRRect>& node, const SkPoint& pos) { node->setPosition(pos); });
+ auto s_attached = AttachProperty<VectorValue, SkSize>(jrect["s"], ctx, composite,
+ [](const sk_sp<CompositeRRect>& node, const SkSize& sz) { node->setSize(sz); });
+ auto r_attached = AttachProperty<ScalarValue, SkScalar>(jrect["r"], ctx, composite,
+ [](const sk_sp<CompositeRRect>& node, SkScalar radius) { node->setRadius(radius); });
+
+ if (!p_attached && !s_attached && !r_attached) {
+ return nullptr;
+ }
+
+ return rect_node;
+}
+
sk_sp<sksg::Color> AttachColorPaint(const Json::Value& obj, AttachContext* ctx) {
SkASSERT(obj.isObject());
@@ -205,6 +226,7 @@
using GeometryAttacherT = sk_sp<sksg::GeometryNode> (*)(const Json::Value&, AttachContext*);
static constexpr GeometryAttacherT gGeometryAttachers[] = {
AttachPathGeometry,
+ AttachRRectGeometry,
};
using PaintAttacherT = sk_sp<sksg::PaintNode> (*)(const Json::Value&, AttachContext*);
@@ -241,6 +263,7 @@
static constexpr ShapeInfo gShapeInfo[] = {
{ "fl", ShapeType::kPaint , 0 }, // fill -> AttachFillPaint
{ "gr", ShapeType::kGroup , 0 }, // group -> AttachShapeGroup
+ { "rc", ShapeType::kGeometry , 1 }, // shape -> AttachRRectGeometry
{ "sh", ShapeType::kGeometry , 0 }, // shape -> AttachPathGeometry
{ "st", ShapeType::kPaint , 1 }, // stroke -> AttachStrokePaint
{ "tr", ShapeType::kTransform, 0 }, // transform -> AttachTransform