aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-01-02 10:40:00 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-02 15:56:30 +0000
commit2e1d7e234241328154a93b6ddb19f573abc29c15 (patch)
tree7bc90b46f1ddcda47a11ec014b809873fcafe235 /experimental
parentb950b5975bbbf22fec9b41b576d4d43ddfd6a208 (diff)
[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>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/skotty/Skotty.cpp25
-rw-r--r--experimental/skotty/SkottyProperties.cpp32
-rw-r--r--experimental/skotty/SkottyProperties.h17
-rw-r--r--experimental/sksg/geometry/SkSGRect.cpp10
-rw-r--r--experimental/sksg/geometry/SkSGRect.h24
5 files changed, 106 insertions, 2 deletions
diff --git a/experimental/skotty/Skotty.cpp b/experimental/skotty/Skotty.cpp
index 7a8e9e35c4..b94cad243b 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 @@ bool AttachProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp<No
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 @@ sk_sp<sksg::GeometryNode> AttachPathGeometry(const Json::Value& jpath, AttachCon
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 @@ sk_sp<sksg::PaintNode> AttachStrokePaint(const Json::Value& jstroke, AttachConte
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 @@ const ShapeInfo* FindShapeInfo(const Json::Value& shape) {
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
diff --git a/experimental/skotty/SkottyProperties.cpp b/experimental/skotty/SkottyProperties.cpp
index 1a3a14593c..7ee4008975 100644
--- a/experimental/skotty/SkottyProperties.cpp
+++ b/experimental/skotty/SkottyProperties.cpp
@@ -10,6 +10,7 @@
#include "SkColor.h"
#include "SkottyPriv.h"
#include "SkPath.h"
+#include "SkSGRect.h"
#include "SkSGTransform.h"
namespace skotty {
@@ -121,6 +122,24 @@ SkPoint VectorValue::as<SkPoint>() const {
}
template <>
+SkSize VectorValue::as<SkSize>() const {
+ const auto pt = this->as<SkPoint>();
+ return SkSize::Make(pt.x(), pt.y());
+}
+
+template <>
+std::vector<SkScalar> VectorValue::as<std::vector<SkScalar>>() const {
+ std::vector<SkScalar> vec;
+ vec.reserve(fVals.count());
+
+ for (const auto& val : fVals) {
+ vec.push_back(val);
+ }
+
+ return vec;
+}
+
+template <>
SkPath ShapeValue::as<SkPath>() const {
SkPath path;
@@ -146,6 +165,19 @@ SkPath ShapeValue::as<SkPath>() const {
return path;
}
+CompositeRRect::CompositeRRect(sk_sp<sksg::RRect> wrapped_node)
+ : fRRectNode(std::move(wrapped_node)) {}
+
+void CompositeRRect::apply() {
+ // BM "position" == "center position"
+ auto rr = SkRRect::MakeRectXY(SkRect::MakeXYWH(fPosition.x() - fSize.width() / 2,
+ fPosition.y() - fSize.height() / 2,
+ fSize.width(), fSize.height()),
+ fRadius,
+ fRadius);
+ fRRectNode->setRRect(rr);
+}
+
CompositeTransform::CompositeTransform(sk_sp<sksg::RenderNode> wrapped_node)
: fTransformNode(sksg::Transform::Make(std::move(wrapped_node), SkMatrix::I())) {}
diff --git a/experimental/skotty/SkottyProperties.h b/experimental/skotty/SkottyProperties.h
index 0273aea2f4..e1504747b4 100644
--- a/experimental/skotty/SkottyProperties.h
+++ b/experimental/skotty/SkottyProperties.h
@@ -20,6 +20,7 @@
class SkPath;
namespace sksg {
+class RRect;
class RenderNode;
class Transform;
}
@@ -100,6 +101,22 @@ struct ShapeValue {
p_type f##p_name = p_default; \
public:
+class CompositeRRect final : public SkRefCnt {
+public:
+ explicit CompositeRRect(sk_sp<sksg::RRect>);
+
+ COMPOSITE_PROPERTY(Position, SkPoint , SkPoint::Make(0, 0))
+ COMPOSITE_PROPERTY(Size , SkSize , SkSize::Make(0, 0))
+ COMPOSITE_PROPERTY(Radius , SkScalar, 0)
+
+private:
+ void apply();
+
+ sk_sp<sksg::RRect> fRRectNode;
+
+ using INHERITED = SkRefCnt;
+};
+
class CompositeTransform final : public SkRefCnt {
public:
explicit CompositeTransform(sk_sp<sksg::RenderNode>);
diff --git a/experimental/sksg/geometry/SkSGRect.cpp b/experimental/sksg/geometry/SkSGRect.cpp
index 69bd94681b..53e6fba400 100644
--- a/experimental/sksg/geometry/SkSGRect.cpp
+++ b/experimental/sksg/geometry/SkSGRect.cpp
@@ -22,4 +22,14 @@ SkRect Rect::onComputeBounds() const {
return fRect;
}
+RRect::RRect(const SkRRect& rr) : fRRect(rr) {}
+
+void RRect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
+ canvas->drawRRect(fRRect, paint);
+}
+
+SkRect RRect::onComputeBounds() const {
+ return fRRect.getBounds();
+}
+
} // namespace sksg
diff --git a/experimental/sksg/geometry/SkSGRect.h b/experimental/sksg/geometry/SkSGRect.h
index a0e5ec62e8..cc912f0ad0 100644
--- a/experimental/sksg/geometry/SkSGRect.h
+++ b/experimental/sksg/geometry/SkSGRect.h
@@ -11,6 +11,7 @@
#include "SkSGGeometryNode.h"
#include "SkRect.h"
+#include "SkRRect.h"
class SkCanvas;
class SkPaint;
@@ -20,7 +21,7 @@ namespace sksg {
/**
* Concrete Geometry node, wrapping an SkRect.
*/
-class Rect : public GeometryNode {
+class Rect final : public GeometryNode {
public:
static sk_sp<Rect> Make() { return sk_sp<Rect>(new Rect(SkRect::MakeEmpty())); }
static sk_sp<Rect> Make(const SkRect& r) { return sk_sp<Rect>(new Rect(r)); }
@@ -41,6 +42,27 @@ private:
SkRect fRect;
};
+/**
+ * Concrete Geometry node, wrapping an SkRRect.
+ */
+class RRect final : public GeometryNode {
+public:
+ static sk_sp<RRect> Make() { return sk_sp<RRect>(new RRect(SkRRect())); }
+ static sk_sp<RRect> Make(const SkRRect& rr) { return sk_sp<RRect>(new RRect(rr)); }
+
+ SG_ATTRIBUTE(RRect, SkRRect, fRRect)
+
+protected:
+ void onDraw(SkCanvas*, const SkPaint&) const override;
+
+ SkRect onComputeBounds() const override;
+
+private:
+ explicit RRect(const SkRRect&);
+
+ SkRRect fRRect;
+};
+
} // namespace sksg
#endif // SkSGRect_DEFINED