diff options
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | experimental/sksg/SkSGNode.h | 1 | ||||
-rw-r--r-- | experimental/sksg/paint/SkSGStroke.cpp | 38 | ||||
-rw-r--r-- | experimental/sksg/paint/SkSGStroke.h | 51 |
4 files changed, 91 insertions, 0 deletions
@@ -1372,6 +1372,7 @@ if (skia_enable_tools) { "experimental/sksg/geometry/SkSGPath.cpp", "experimental/sksg/geometry/SkSGRect.cpp", "experimental/sksg/paint/SkSGColor.cpp", + "experimental/sksg/paint/SkSGStroke.cpp", ] deps = [ ":skia", diff --git a/experimental/sksg/SkSGNode.h b/experimental/sksg/SkSGNode.h index 08ee784a1e..30ff85d3c7 100644 --- a/experimental/sksg/SkSGNode.h +++ b/experimental/sksg/SkSGNode.h @@ -51,6 +51,7 @@ private: friend class Draw; friend class EffectNode; friend class Group; + friend class Stroke; template <typename Func> void forEachInvalReceiver(Func&&) const; diff --git a/experimental/sksg/paint/SkSGStroke.cpp b/experimental/sksg/paint/SkSGStroke.cpp new file mode 100644 index 0000000000..c30b4a0b37 --- /dev/null +++ b/experimental/sksg/paint/SkSGStroke.cpp @@ -0,0 +1,38 @@ +/* + * 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 new file mode 100644 index 0000000000..ab0c256b58 --- /dev/null +++ b/experimental/sksg/paint/SkSGStroke.h @@ -0,0 +1,51 @@ +/* + * 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 |