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 15 class SkCanvas; 16 class SkPaint; 17 18 namespace sksg { 19 20 /** 21 * Concrete Geometry node, applying a trim effect to its child. 22 */ 23 class TrimEffect final : public GeometryNode { 24 public: Make(sk_sp<GeometryNode> child)25 static sk_sp<TrimEffect> Make(sk_sp<GeometryNode> child) { 26 return child ? sk_sp<TrimEffect>(new TrimEffect(std::move(child))) : nullptr; 27 } 28 29 ~TrimEffect() override; 30 31 SG_ATTRIBUTE(Start , SkScalar, fStart ) 32 SG_ATTRIBUTE(End , SkScalar, fEnd ) 33 SG_ATTRIBUTE(Offset, SkScalar, fOffset) 34 35 protected: 36 void onClip(SkCanvas*, bool antiAlias) const override; 37 void onDraw(SkCanvas*, const SkPaint&) const override; 38 39 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 40 SkPath onAsPath() const override; 41 42 private: 43 explicit TrimEffect(sk_sp<GeometryNode>); 44 45 const sk_sp<GeometryNode> fChild; 46 47 SkScalar fStart = 0, // starting t 48 fEnd = 1, // ending t 49 fOffset = 0; // t offset 50 51 using INHERITED = GeometryNode; 52 }; 53 54 } // namespace sksg 55 56 #endif // SkSGTrimEffect_DEFINED 57