blob: 9837d0e70162cfcb32fb9707ad5203f9246aeb8d [file] [log] [blame]
Florin Malita5f9102f2018-01-10 13:36:22 -05001/*
2 * Copyright 2018 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 SkSGMaskEffect_DEFINED
9#define SkSGMaskEffect_DEFINED
10
11#include "SkSGEffectNode.h"
12
13namespace sksg {
14
15/**
16 * Concrete Effect node, applying a mask to its descendants.
17 *
18 */
19class MaskEffect final : public EffectNode {
20public:
Florin Malitaa016be92018-03-05 14:01:41 -050021 enum class Mode {
22 kNormal,
23 kInvert
24 };
25
26 static sk_sp<MaskEffect> Make(sk_sp<RenderNode> child, sk_sp<RenderNode> mask,
27 Mode mode = Mode::kNormal) {
Florin Malita5f9102f2018-01-10 13:36:22 -050028 return (child && mask)
Florin Malitaa016be92018-03-05 14:01:41 -050029 ? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask), mode))
Florin Malita5f9102f2018-01-10 13:36:22 -050030 : nullptr;
31 }
32
33 ~MaskEffect() override;
34
35protected:
Florin Malitaa016be92018-03-05 14:01:41 -050036 MaskEffect(sk_sp<RenderNode>, sk_sp<RenderNode> mask, Mode);
Florin Malita5f9102f2018-01-10 13:36:22 -050037
Florin Malitac0132ff2018-08-09 07:40:01 -040038 void onRender(SkCanvas*, const RenderContext*) const override;
Florin Malitaeb46bd82019-02-12 09:33:21 -050039 const RenderNode* onNodeAt(const SkPoint&) const override;
Florin Malita5f9102f2018-01-10 13:36:22 -050040
41 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
42
43private:
Florin Malitaa016be92018-03-05 14:01:41 -050044 const sk_sp<RenderNode> fMaskNode;
45 const Mode fMaskMode;
Florin Malita5f9102f2018-01-10 13:36:22 -050046
47 typedef EffectNode INHERITED;
48};
49
50} // namespace sksg
51
52#endif // SkSGMaskEffect_DEFINED