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 "modules/sksg/include/SkSGGeometryNode.h" 12 13 #include "include/core/SkPath.h" 14 #include "include/effects/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 bool onContains(const SkPoint&) const override; 40 41 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 42 SkPath onAsPath() const override; 43 44 private: 45 explicit TrimEffect(sk_sp<GeometryNode>); 46 47 const sk_sp<GeometryNode> fChild; 48 49 SkPath fTrimmedPath; 50 SkScalar fStart = 0, 51 fStop = 1; 52 SkTrimPathEffect::Mode fMode = SkTrimPathEffect::Mode::kNormal; 53 54 using INHERITED = GeometryNode; 55 }; 56 57 } // namespace sksg 58 59 #endif // SkSGTrimEffect_DEFINED 60