Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 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 | static sk_sp<Merge> Make(std::vector<sk_sp<GeometryNode>>&& geos, Mode mode) { |
| 40 | return sk_sp<Merge>(new Merge(std::move(geos), mode)); |
| 41 | } |
| 42 | |
| 43 | ~Merge() override; |
| 44 | |
| 45 | protected: |
Florin Malita | 38ea40e | 2018-01-29 16:31:14 -0500 | [diff] [blame] | 46 | void onClip(SkCanvas*, bool antiAlias) const override; |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 47 | void onDraw(SkCanvas*, const SkPaint&) const override; |
| 48 | |
Florin Malita | c14f144 | 2018-01-05 11:32:31 -0500 | [diff] [blame] | 49 | SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 50 | SkPath onAsPath() const override; |
| 51 | |
| 52 | private: |
| 53 | Merge(std::vector<sk_sp<GeometryNode>>&& geos, Mode); |
| 54 | |
| 55 | std::vector<sk_sp<GeometryNode>> fGeos; |
| 56 | SkPath fMerged; |
| 57 | Mode fMode; |
Florin Malita | 51012ce | 2018-01-31 17:06:59 -0500 | [diff] [blame] | 58 | |
| 59 | using INHERITED = GeometryNode; |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace sksg |
| 63 | |
| 64 | #endif // SkSGMerge_DEFINED |