aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-01-12 14:27:39 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-12 19:48:03 +0000
commit1586d85198d17496efa93a6af812e3913882347f (patch)
tree524c24c5019888a5fd9d5e1ce6d3d216e37e5954 /experimental
parent966db9e4ee1e5485fce21a5953b426ad8bf95a9d (diff)
[skotty] Refactor paint opacity
Promote to a PaintNode attribute, drop color composite. TBR= Change-Id: Ia79d5f7e193a472d53ac4ff8beb7234d4dc26cef Reviewed-on: https://skia-review.googlesource.com/94280 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/skotty/Skotty.cpp19
-rw-r--r--experimental/skotty/SkottyProperties.cpp14
-rw-r--r--experimental/skotty/SkottyProperties.h15
-rw-r--r--experimental/sksg/SkSGPaintNode.cpp3
-rw-r--r--experimental/sksg/SkSGPaintNode.h4
5 files changed, 15 insertions, 40 deletions
diff --git a/experimental/skotty/Skotty.cpp b/experimental/skotty/Skotty.cpp
index ce2644ea51..72d12d6ac4 100644
--- a/experimental/skotty/Skotty.cpp
+++ b/experimental/skotty/Skotty.cpp
@@ -298,17 +298,12 @@ sk_sp<sksg::Color> AttachColor(const Json::Value& obj, AttachContext* ctx) {
SkASSERT(obj.isObject());
auto color_node = sksg::Color::Make(SK_ColorBLACK);
- auto composite = sk_make_sp<CompositeColor>(color_node);
- auto color_attached = BindProperty<VectorValue>(obj["c"], ctx, composite,
- [](CompositeColor* node, const VectorValue& c) {
+ auto color_attached = BindProperty<VectorValue>(obj["c"], ctx, color_node,
+ [](sksg::Color* node, const VectorValue& c) {
node->setColor(ValueTraits<VectorValue>::As<SkColor>(c));
});
- auto opacity_attached = BindProperty<ScalarValue>(obj["o"], ctx, composite,
- [](CompositeColor* node, const ScalarValue& o) {
- node->setOpacity(o);
- });
- return (color_attached || opacity_attached) ? color_node : nullptr;
+ return color_attached ? color_node : nullptr;
}
sk_sp<sksg::Gradient> AttachGradient(const Json::Value& obj, AttachContext* ctx) {
@@ -353,12 +348,16 @@ sk_sp<sksg::Gradient> AttachGradient(const Json::Value& obj, AttachContext* ctx)
return gradient_node;
}
-sk_sp<sksg::PaintNode> AttachPaint(const Json::Value& jfill, AttachContext* ctx,
+sk_sp<sksg::PaintNode> AttachPaint(const Json::Value& jpaint, AttachContext* ctx,
sk_sp<sksg::PaintNode> paint_node) {
if (paint_node) {
paint_node->setAntiAlias(true);
- // TODO: refactor opacity
+ BindProperty<ScalarValue>(jpaint["o"], ctx, paint_node,
+ [](sksg::PaintNode* node, const ScalarValue& o) {
+ // BM opacity is [0..100]
+ node->setOpacity(o * 0.01f);
+ });
}
return paint_node;
diff --git a/experimental/skotty/SkottyProperties.cpp b/experimental/skotty/SkottyProperties.cpp
index e962a7d538..6be2eebfa3 100644
--- a/experimental/skotty/SkottyProperties.cpp
+++ b/experimental/skotty/SkottyProperties.cpp
@@ -183,20 +183,6 @@ SkPath ValueTraits<ShapeValue>::As<SkPath>(const ShapeValue& path) {
return path;
}
-CompositeColor::CompositeColor(sk_sp<sksg::Color> wrapped_node)
- : fColorNode(std::move(wrapped_node)) {
- SkASSERT(fColorNode);
-}
-
-void CompositeColor::apply() {
- // 'opacity' is [0..100]
- const auto a = SkScalarRoundToInt(SkTPin<float>(fOpacity * .01f, 0, 1) * SkColorGetA(fColor));
- fColorNode->setColor(SkColorSetARGB(a,
- SkColorGetR(fColor),
- SkColorGetG(fColor),
- SkColorGetB(fColor)));
-}
-
CompositeRRect::CompositeRRect(sk_sp<sksg::RRect> wrapped_node)
: fRRectNode(std::move(wrapped_node)) {}
diff --git a/experimental/skotty/SkottyProperties.h b/experimental/skotty/SkottyProperties.h
index cd22810c2e..177ba35873 100644
--- a/experimental/skotty/SkottyProperties.h
+++ b/experimental/skotty/SkottyProperties.h
@@ -58,21 +58,6 @@ using ShapeValue = SkPath;
p_type f##p_name = p_default; \
public:
-class CompositeColor final : public SkRefCnt {
-public:
- explicit CompositeColor(sk_sp<sksg::Color>);
-
- COMPOSITE_PROPERTY(Color , SkColor , SK_ColorBLACK)
- COMPOSITE_PROPERTY(Opacity, SkScalar, 100 )
-
-private:
- void apply();
-
- sk_sp<sksg::Color> fColorNode;
-
- using INHERITED = SkRefCnt;
-};
-
class CompositeRRect final : public SkRefCnt {
public:
explicit CompositeRRect(sk_sp<sksg::RRect>);
diff --git a/experimental/sksg/SkSGPaintNode.cpp b/experimental/sksg/SkSGPaintNode.cpp
index 146d248b8e..bb5b714030 100644
--- a/experimental/sksg/SkSGPaintNode.cpp
+++ b/experimental/sksg/SkSGPaintNode.cpp
@@ -31,6 +31,9 @@ SkRect PaintNode::onRevalidate(InvalidationController*, const SkMatrix&) {
this->onApplyToPaint(&fPaint);
+ // Compose opacity on top of the subclass value.
+ fPaint.setAlpha(SkScalarRoundToInt(fPaint.getAlpha() * SkTPin<SkScalar>(fOpacity, 0, 1)));
+
return SkRect::MakeEmpty();
}
diff --git a/experimental/sksg/SkSGPaintNode.h b/experimental/sksg/SkSGPaintNode.h
index a2fbada065..1085e27c0f 100644
--- a/experimental/sksg/SkSGPaintNode.h
+++ b/experimental/sksg/SkSGPaintNode.h
@@ -25,6 +25,7 @@ public:
const SkPaint& makePaint();
SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
+ SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
@@ -41,7 +42,8 @@ protected:
private:
SkPaint fPaint;
- SkScalar fStrokeWidth = 1,
+ SkScalar fOpacity = 1,
+ fStrokeWidth = 1,
fStrokeMiter = 4;
bool fAntiAlias = false;
SkPaint::Style fStyle = SkPaint::kFill_Style;