blob: 54924d6475b5bc7a419000dc8cc29db4c697450b [file] [log] [blame]
Florin Malitae6345d92018-01-03 23:37:54 -05001/*
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
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 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
45protected:
Florin Malita38ea40e2018-01-29 16:31:14 -050046 void onClip(SkCanvas*, bool antiAlias) const override;
Florin Malitae6345d92018-01-03 23:37:54 -050047 void onDraw(SkCanvas*, const SkPaint&) const override;
48
Florin Malitac14f1442018-01-05 11:32:31 -050049 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
Florin Malitae6345d92018-01-03 23:37:54 -050050 SkPath onAsPath() const override;
51
52private:
53 Merge(std::vector<sk_sp<GeometryNode>>&& geos, Mode);
54
55 std::vector<sk_sp<GeometryNode>> fGeos;
56 SkPath fMerged;
57 Mode fMode;
Florin Malita51012ce2018-01-31 17:06:59 -050058
59 using INHERITED = GeometryNode;
Florin Malitae6345d92018-01-03 23:37:54 -050060};
61
62} // namespace sksg
63
64#endif // SkSGMerge_DEFINED