2018-01-04 04:37:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSGMerge_DEFINED
|
|
|
|
#define SkSGMerge_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "modules/sksg/include/SkSGGeometryNode.h"
|
2018-01-04 04:37:54 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2018-01-04 04:37:54 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
class SkPaint;
|
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete Geometry node, combining other geometries based on Mode.
|
|
|
|
*/
|
|
|
|
class Merge final : public GeometryNode {
|
|
|
|
public:
|
|
|
|
enum class Mode {
|
|
|
|
// Append path mode.
|
|
|
|
kMerge,
|
|
|
|
|
|
|
|
// SkPathOp ops.
|
|
|
|
kUnion,
|
|
|
|
kIntersect,
|
|
|
|
kDifference,
|
|
|
|
kReverseDifference,
|
|
|
|
kXOR,
|
|
|
|
};
|
|
|
|
|
2018-07-09 20:20:47 +00:00
|
|
|
struct Rec {
|
|
|
|
sk_sp<GeometryNode> fGeo;
|
|
|
|
Mode fMode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static sk_sp<Merge> Make(std::vector<Rec>&& recs) {
|
|
|
|
return sk_sp<Merge>(new Merge(std::move(recs)));
|
2018-01-04 04:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Merge() override;
|
|
|
|
|
|
|
|
protected:
|
2018-01-29 21:31:14 +00:00
|
|
|
void onClip(SkCanvas*, bool antiAlias) const override;
|
2018-01-04 04:37:54 +00:00
|
|
|
void onDraw(SkCanvas*, const SkPaint&) const override;
|
2019-02-12 14:33:21 +00:00
|
|
|
bool onContains(const SkPoint&) const override;
|
2018-01-04 04:37:54 +00:00
|
|
|
|
2018-01-05 16:32:31 +00:00
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
2018-01-04 04:37:54 +00:00
|
|
|
SkPath onAsPath() const override;
|
|
|
|
|
|
|
|
private:
|
2018-07-09 20:20:47 +00:00
|
|
|
Merge(std::vector<Rec>&& recs);
|
2018-01-04 04:37:54 +00:00
|
|
|
|
2018-07-09 20:20:47 +00:00
|
|
|
const std::vector<Rec> fRecs;
|
|
|
|
SkPath fMerged;
|
2018-01-31 22:06:59 +00:00
|
|
|
|
|
|
|
using INHERITED = GeometryNode;
|
2018-01-04 04:37:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sksg
|
|
|
|
|
|
|
|
#endif // SkSGMerge_DEFINED
|