aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-12-29 11:52:44 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-29 17:12:11 +0000
commitfa8d49adfa8d592219e9ac999c54e87969aa817d (patch)
treef464556de9280e5ae43f57b0aec07417612c9711 /experimental
parentd1e268cfa1c4d2d56ea04f09576220f3841cc0a1 (diff)
[sksg] Refactor stroke logic
Instead of a specialized node, hoist attributes to base class. TBR= Change-Id: I4fa5a24dfc899307a8603577738972ebd32f57f5 Reviewed-on: https://skia-review.googlesource.com/89903 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/sksg/SkSGPaintNode.cpp10
-rw-r--r--experimental/sksg/SkSGPaintNode.h19
-rw-r--r--experimental/sksg/paint/SkSGColor.cpp6
-rw-r--r--experimental/sksg/paint/SkSGColor.h2
-rw-r--r--experimental/sksg/paint/SkSGStroke.cpp38
-rw-r--r--experimental/sksg/paint/SkSGStroke.h51
6 files changed, 28 insertions, 98 deletions
diff --git a/experimental/sksg/SkSGPaintNode.cpp b/experimental/sksg/SkSGPaintNode.cpp
index cd0bc81df5..2b7a31fbad 100644
--- a/experimental/sksg/SkSGPaintNode.cpp
+++ b/experimental/sksg/SkSGPaintNode.cpp
@@ -20,7 +20,15 @@ const SkPaint& PaintNode::makePaint() {
void PaintNode::onRevalidate(InvalidationController*, const SkMatrix&) {
SkASSERT(this->isInvalidated());
- fPaint = this->onMakePaint();
+ fPaint.reset();
+ fPaint.setAntiAlias(fAntiAlias);
+ fPaint.setStyle(fStyle);
+ fPaint.setStrokeWidth(fStrokeWidth);
+ fPaint.setStrokeMiter(fStrokeMiter);
+ fPaint.setStrokeJoin(fStrokeJoin);
+ fPaint.setStrokeCap(fStrokeCap);
+
+ this->onApplyToPaint(&fPaint);
}
} // namespace sksg
diff --git a/experimental/sksg/SkSGPaintNode.h b/experimental/sksg/SkSGPaintNode.h
index d0a7787bc8..534ad551ae 100644
--- a/experimental/sksg/SkSGPaintNode.h
+++ b/experimental/sksg/SkSGPaintNode.h
@@ -22,18 +22,31 @@ namespace sksg {
*/
class PaintNode : public Node {
public:
-
const SkPaint& makePaint();
+ SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
+ SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
+ SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
+ SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
+ SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
+ SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
+
protected:
PaintNode();
- virtual SkPaint onMakePaint() const = 0;
+ virtual void onApplyToPaint(SkPaint*) const = 0;
void onRevalidate(InvalidationController*, const SkMatrix&) override;
private:
- SkPaint fPaint;
+ SkPaint fPaint;
+
+ SkScalar fStrokeWidth = 1,
+ fStrokeMiter = 4;
+ bool fAntiAlias = false;
+ SkPaint::Style fStyle = SkPaint::kFill_Style;
+ SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
+ SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
typedef Node INHERITED;
};
diff --git a/experimental/sksg/paint/SkSGColor.cpp b/experimental/sksg/paint/SkSGColor.cpp
index 826bc4bc7c..d5d4d1ce62 100644
--- a/experimental/sksg/paint/SkSGColor.cpp
+++ b/experimental/sksg/paint/SkSGColor.cpp
@@ -11,10 +11,8 @@ namespace sksg {
Color::Color(SkColor c) : fColor(c) {}
-SkPaint Color::onMakePaint() const {
- SkPaint paint;
- paint.setColor(fColor);
- return paint;
+void Color::onApplyToPaint(SkPaint* paint) const {
+ paint->setColor(fColor);
}
} // namespace sksg
diff --git a/experimental/sksg/paint/SkSGColor.h b/experimental/sksg/paint/SkSGColor.h
index a4e0862892..a19921cfd3 100644
--- a/experimental/sksg/paint/SkSGColor.h
+++ b/experimental/sksg/paint/SkSGColor.h
@@ -24,7 +24,7 @@ public:
SG_ATTRIBUTE(Color, SkColor, fColor)
protected:
- SkPaint onMakePaint() const override;
+ void onApplyToPaint(SkPaint*) const override;
private:
explicit Color(SkColor);
diff --git a/experimental/sksg/paint/SkSGStroke.cpp b/experimental/sksg/paint/SkSGStroke.cpp
deleted file mode 100644
index c30b4a0b37..0000000000
--- a/experimental/sksg/paint/SkSGStroke.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSGStroke.h"
-
-namespace sksg {
-
-Stroke::Stroke(sk_sp<PaintNode> paint)
- : fPaint(std::move(paint)) {
- fPaint->addInvalReceiver(this);
-}
-
-Stroke::~Stroke() {
- fPaint->removeInvalReceiver(this);
-}
-
-void Stroke::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
- fPaint->revalidate(ic, ctm);
- INHERITED::onRevalidate(ic, ctm);
-}
-
-SkPaint Stroke::onMakePaint() const {
- SkPaint paint = fPaint->makePaint();
-
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(fStrokeWidth);
- paint.setStrokeMiter(fStrokeMiter);
- paint.setStrokeJoin(fStrokeJoin);
- paint.setStrokeCap(fStrokeCap);
-
- return paint;
-}
-
-} // namespace sksg
diff --git a/experimental/sksg/paint/SkSGStroke.h b/experimental/sksg/paint/SkSGStroke.h
deleted file mode 100644
index ab0c256b58..0000000000
--- a/experimental/sksg/paint/SkSGStroke.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkSGStroke_DEFINED
-#define SkSGStroke_DEFINED
-
-#include "SkSGPaintNode.h"
-
-#include "SkScalar.h"
-
-namespace sksg {
-
-/**
- * Concrete Paint node wrapper, applying a stroke effect to an existing paint.
- */
-class Stroke final : public PaintNode {
-public:
- static sk_sp<Stroke> Make(sk_sp<PaintNode> paint) {
- return paint ? sk_sp<Stroke>(new Stroke(std::move(paint))) : nullptr;
- }
-
- SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
- SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
- SG_ATTRIBUTE(StrokeJoin , SkPaint::Join, fStrokeJoin )
- SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
-
-protected:
- void onRevalidate(InvalidationController*, const SkMatrix&) override;
-
- SkPaint onMakePaint() const override;
-
-private:
- explicit Stroke(sk_sp<PaintNode>);
- ~Stroke() override;
-
- sk_sp<PaintNode> fPaint;
- SkScalar fStrokeWidth = 1,
- fStrokeMiter = 4;
- SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
- SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
-
- typedef PaintNode INHERITED;
-};
-
-} // namespace sksg
-
-#endif // SkSGStroke_DEFINED