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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "modules/sksg/include/SkSGEffectNode.h"
|
2018-01-10 18:36:22 +00:00
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete Effect node, applying a mask to its descendants.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class MaskEffect final : public EffectNode {
|
|
|
|
public:
|
2019-10-16 12:51:09 +00:00
|
|
|
enum class Mode : uint32_t {
|
|
|
|
kAlphaNormal,
|
|
|
|
kAlphaInvert,
|
|
|
|
kLumaNormal,
|
|
|
|
kLumaInvert,
|
2018-03-05 19:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static sk_sp<MaskEffect> Make(sk_sp<RenderNode> child, sk_sp<RenderNode> mask,
|
2019-10-16 12:51:09 +00:00
|
|
|
Mode mode = Mode::kAlphaNormal) {
|
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
|