[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>
This commit is contained in:
parent
966db9e4ee
commit
1586d85198
@ -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;
|
||||
|
@ -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)) {}
|
||||
|
||||
|
@ -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>);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user