1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkSGTrimEffect_DEFINED 9 #define SkSGTrimEffect_DEFINED 10 11 #include "SkSGGeometryNode.h" 12 13 #include "SkPath.h" 14 #include "SkTrimPathEffect.h" 15 16 class SkCanvas; 17 class SkPaint; 18 19 namespace sksg { 20 21 /** 22 * Concrete Geometry node, applying a trim effect to its child. 23 */ 24 class TrimEffect final : public GeometryNode { 25 public: Make(sk_sp<GeometryNode> child)26 static sk_sp<TrimEffect> Make(sk_sp<GeometryNode> child) { 27 return child ? sk_sp<TrimEffect>(new TrimEffect(std::move(child))) : nullptr; 28 } 29 30 ~TrimEffect() override; 31 32 SG_ATTRIBUTE(Start , SkScalar , fStart ) 33 SG_ATTRIBUTE(Stop , SkScalar , fStop ) 34 SG_ATTRIBUTE(Mode , SkTrimPathEffect::Mode, fMode ) 35 36 protected: 37 void onClip(SkCanvas*, bool antiAlias) const override; 38 void onDraw(SkCanvas*, const SkPaint&) const override; 39 40 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 41 SkPath onAsPath() const override; 42 43 private: 44 explicit TrimEffect(sk_sp<GeometryNode>); 45 46 const sk_sp<GeometryNode> fChild; 47 48 SkPath fTrimmedPath; 49 SkScalar fStart = 0, 50 fStop = 1; 51 SkTrimPathEffect::Mode fMode = SkTrimPathEffect::Mode::kNormal; 52 53 using INHERITED = GeometryNode; 54 }; 55 56 } // namespace sksg 57 58 #endif // SkSGTrimEffect_DEFINED 59