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 "modules/sksg/include/SkSGGeometryNode.h"
12
13#include "include/core/SkPath.h"
14
15#include <vector>
16
17class SkCanvas;
18class SkPaint;
19
20namespace sksg {
21
22/**
23 * Concrete Geometry node, combining other geometries based on Mode.
24 */
25class Merge final : public GeometryNode {
26public:
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
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
50protected:
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
58private:
59 Merge(std::vector<Rec>&& recs);
60
61 const std::vector<Rec> fRecs;
62 SkPath fMerged;
63
64 using INHERITED = GeometryNode;
65};
66
67} // namespace sksg
68
69#endif // SkSGMerge_DEFINED
70