blob: b37530a42f429e23b3a5a0a4e87977218588c20a [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
Florin Malita418e6582018-07-09 16:20:47 -040039 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)));
Florin Malitae6345d92018-01-03 23:37:54 -050046 }
47
48 ~Merge() override;
49
50protected:
Florin Malita38ea40e2018-01-29 16:31:14 -050051 void onClip(SkCanvas*, bool antiAlias) const override;
Florin Malitae6345d92018-01-03 23:37:54 -050052 void onDraw(SkCanvas*, const SkPaint&) const override;
Florin Malitaeb46bd82019-02-12 09:33:21 -050053 bool onContains(const SkPoint&) const override;
Florin Malitae6345d92018-01-03 23:37:54 -050054
Florin Malitac14f1442018-01-05 11:32:31 -050055 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
Florin Malitae6345d92018-01-03 23:37:54 -050056 SkPath onAsPath() const override;
57
58private:
Florin Malita418e6582018-07-09 16:20:47 -040059 Merge(std::vector<Rec>&& recs);
Florin Malitae6345d92018-01-03 23:37:54 -050060
Florin Malita418e6582018-07-09 16:20:47 -040061 const std::vector<Rec> fRecs;
62 SkPath fMerged;
Florin Malita51012ce2018-01-31 17:06:59 -050063
64 using INHERITED = GeometryNode;
Florin Malitae6345d92018-01-03 23:37:54 -050065};
66
67} // namespace sksg
68
69#endif // SkSGMerge_DEFINED