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 SkSGMerge_DEFINED 9 #define SkSGMerge_DEFINED 10 11 #include "SkSGGeometryNode.h" 12 13 #include "SkPath.h" 14 15 #include <vector> 16 17 class SkCanvas; 18 class SkPaint; 19 20 namespace sksg { 21 22 /** 23 * Concrete Geometry node, combining other geometries based on Mode. 24 */ 25 class Merge final : public GeometryNode { 26 public: 27 enum class Mode { 28 // Append path mode. 29 kMerge, 30 31 // SkPathOp ops. 32 kUnion, 33 kIntersect, 34 kDifference, 35 kReverseDifference, 36 kXOR, 37 }; 38 39 struct Rec { 40 sk_sp<GeometryNode> fGeo; 41 Mode fMode; 42 }; 43 Make(std::vector<Rec> && recs)44 static sk_sp<Merge> Make(std::vector<Rec>&& recs) { 45 return sk_sp<Merge>(new Merge(std::move(recs))); 46 } 47 48 ~Merge() override; 49 50 protected: 51 void onClip(SkCanvas*, bool antiAlias) const override; 52 void onDraw(SkCanvas*, const SkPaint&) const override; 53 54 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 55 SkPath onAsPath() const override; 56 57 private: 58 Merge(std::vector<Rec>&& recs); 59 60 const std::vector<Rec> fRecs; 61 SkPath fMerged; 62 63 using INHERITED = GeometryNode; 64 }; 65 66 } // namespace sksg 67 68 #endif // SkSGMerge_DEFINED 69