2018-01-10 18:36:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSGMaskEffect_DEFINED
|
|
|
|
#define SkSGMaskEffect_DEFINED
|
|
|
|
|
|
|
|
#include "SkSGEffectNode.h"
|
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete Effect node, applying a mask to its descendants.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class MaskEffect final : public EffectNode {
|
|
|
|
public:
|
2018-03-05 19:01:41 +00:00
|
|
|
enum class Mode {
|
|
|
|
kNormal,
|
|
|
|
kInvert
|
|
|
|
};
|
|
|
|
|
|
|
|
static sk_sp<MaskEffect> Make(sk_sp<RenderNode> child, sk_sp<RenderNode> mask,
|
|
|
|
Mode mode = Mode::kNormal) {
|
2018-01-10 18:36:22 +00:00
|
|
|
return (child && mask)
|
2018-03-05 19:01:41 +00:00
|
|
|
? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask), mode))
|
2018-01-10 18:36:22 +00:00
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
~MaskEffect() override;
|
|
|
|
|
|
|
|
protected:
|
2018-03-05 19:01:41 +00:00
|
|
|
MaskEffect(sk_sp<RenderNode>, sk_sp<RenderNode> mask, Mode);
|
2018-01-10 18:36:22 +00:00
|
|
|
|
2018-08-09 11:40:01 +00:00
|
|
|
void onRender(SkCanvas*, const RenderContext*) const override;
|
2019-02-12 14:33:21 +00:00
|
|
|
const RenderNode* onNodeAt(const SkPoint&) const override;
|
2018-01-10 18:36:22 +00:00
|
|
|
|
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
|
|
|
|
|
|
|
private:
|
2018-03-05 19:01:41 +00:00
|
|
|
const sk_sp<RenderNode> fMaskNode;
|
|
|
|
const Mode fMaskMode;
|
2018-01-10 18:36:22 +00:00
|
|
|
|
|
|
|
typedef EffectNode INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sksg
|
|
|
|
|
|
|
|
#endif // SkSGMaskEffect_DEFINED
|