skia2/modules/sksg/include/SkSGDashEffect.h
Florin Malita ed38d201de [skottie] Stroke dash support
AE supports dashing all strokes.  Dashes are specified as an arbitrary
number of intervals (alternating dash/gap) plus a start offset.

All values can be animated independently (but of course!).

  - implement a SkSG dash effect (based on SkDashPathEffect)
  - expand the shape builder logic to allow local geometry adjustments
    (kind of a bummer that dashing is a stroke/paint property as opposed
    to a geometry effect in AE)

Change-Id: Ic9ff35f2f9a552a3c26f9e1596ce58ad81f7ced5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274550
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2020-03-02 16:56:22 +00:00

58 lines
1.5 KiB
C++

/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkSGDashEffect_DEFINED
#define SkSGDashEffect_DEFINED
#include "include/core/SkPath.h"
#include "modules/sksg/include/SkSGGeometryNode.h"
#include <vector>
namespace sksg {
/**
* Apply a dash effect to the child geometry.
*
* Follows the same semantics as SkDashPathEffect, with one minor tweak: when the number of
* intervals is odd, they are repeated once more to attain an even sequence (same as SVG
* stroke-dasharray: https://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty).
*/
class DashEffect final : public GeometryNode {
public:
static sk_sp<DashEffect> Make(sk_sp<GeometryNode> child) {
return child ? sk_sp<DashEffect>(new DashEffect(std::move(child))) : nullptr;
}
~DashEffect() override;
SG_ATTRIBUTE(Intervals, std::vector<float>, fIntervals)
SG_ATTRIBUTE(Phase, float , fPhase )
protected:
void onClip(SkCanvas*, bool antiAlias) const override;
void onDraw(SkCanvas*, const SkPaint&) const override;
bool onContains(const SkPoint&) const override;
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
SkPath onAsPath() const override;
private:
explicit DashEffect(sk_sp<GeometryNode>);
const sk_sp<GeometryNode> fChild;
SkPath fDashedPath; // cache
std::vector<float> fIntervals;
float fPhase;
};
} // namespace sksg
#endif // SkSGDashEffect_DEFINED