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 SkSGPath_DEFINED 9 #define SkSGPath_DEFINED 10 11 #include "include/core/SkPath.h" 12 #include "include/core/SkRect.h" 13 #include "include/core/SkRefCnt.h" 14 #include "modules/sksg/include/SkSGGeometryNode.h" 15 #include "modules/sksg/include/SkSGNode.h" 16 17 class SkCanvas; 18 class SkMatrix; 19 class SkPaint; 20 enum class SkPathFillType; 21 struct SkPoint; 22 23 namespace sksg { 24 class InvalidationController; 25 26 /** 27 * Concrete Geometry node, wrapping an SkPath. 28 */ 29 class Path : public GeometryNode { 30 public: Make()31 static sk_sp<Path> Make() { return sk_sp<Path>(new Path(SkPath())); } Make(const SkPath & r)32 static sk_sp<Path> Make(const SkPath& r) { return sk_sp<Path>(new Path(r)); } 33 SG_ATTRIBUTE(Path,SkPath,fPath)34 SG_ATTRIBUTE(Path, SkPath, fPath) 35 36 // Temporarily inlined for SkPathFillType staging 37 // SG_MAPPED_ATTRIBUTE(FillType, SkPathFillType, fPath) 38 39 SkPathFillType getFillType() const { 40 return fPath.getFillType(); 41 } 42 setFillType(SkPathFillType fillType)43 void setFillType(SkPathFillType fillType) { 44 if (fillType != fPath.getFillType()) { 45 fPath.setFillType(fillType); 46 this->invalidate(); 47 } 48 } 49 50 protected: 51 void onClip(SkCanvas*, bool antiAlias) const override; 52 void onDraw(SkCanvas*, const SkPaint&) const override; 53 bool onContains(const SkPoint&) const override; 54 55 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 56 SkPath onAsPath() const override; 57 58 private: 59 explicit Path(const SkPath&); 60 61 SkPath fPath; 62 63 using INHERITED = GeometryNode; 64 }; 65 66 } // namespace sksg 67 68 #endif // SkSGPath_DEFINED 69