[sksg] Initial stroke wrapper support
TBR= Change-Id: I33e2fe076334de34c4427e7bfe6b6aaa724130b2 Reviewed-on: https://skia-review.googlesource.com/89641 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
7a4d067d88
commit
f91d57b585
1
BUILD.gn
1
BUILD.gn
@ -1372,6 +1372,7 @@ if (skia_enable_tools) {
|
|||||||
"experimental/sksg/geometry/SkSGPath.cpp",
|
"experimental/sksg/geometry/SkSGPath.cpp",
|
||||||
"experimental/sksg/geometry/SkSGRect.cpp",
|
"experimental/sksg/geometry/SkSGRect.cpp",
|
||||||
"experimental/sksg/paint/SkSGColor.cpp",
|
"experimental/sksg/paint/SkSGColor.cpp",
|
||||||
|
"experimental/sksg/paint/SkSGStroke.cpp",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":skia",
|
":skia",
|
||||||
|
@ -51,6 +51,7 @@ private:
|
|||||||
friend class Draw;
|
friend class Draw;
|
||||||
friend class EffectNode;
|
friend class EffectNode;
|
||||||
friend class Group;
|
friend class Group;
|
||||||
|
friend class Stroke;
|
||||||
|
|
||||||
template <typename Func>
|
template <typename Func>
|
||||||
void forEachInvalReceiver(Func&&) const;
|
void forEachInvalReceiver(Func&&) const;
|
||||||
|
38
experimental/sksg/paint/SkSGStroke.cpp
Normal file
38
experimental/sksg/paint/SkSGStroke.cpp
Normal file
@ -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
|
51
experimental/sksg/paint/SkSGStroke.h
Normal file
51
experimental/sksg/paint/SkSGStroke.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user