/src/skia/modules/sksg/include/SkSGMaskEffect.h
Line | Count | Source |
1 | | /* |
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 "modules/sksg/include/SkSGEffectNode.h" |
12 | | |
13 | | namespace sksg { |
14 | | |
15 | | /** |
16 | | * Concrete Effect node, applying a mask to its descendants. |
17 | | * |
18 | | */ |
19 | | class MaskEffect final : public EffectNode { |
20 | | public: |
21 | | enum class Mode : uint32_t { |
22 | | kAlphaNormal, |
23 | | kAlphaInvert, |
24 | | kLumaNormal, |
25 | | kLumaInvert, |
26 | | }; |
27 | | |
28 | | static sk_sp<MaskEffect> Make(sk_sp<RenderNode> child, sk_sp<RenderNode> mask, |
29 | 29.4k | Mode mode = Mode::kAlphaNormal) { |
30 | 29.4k | return (child && mask) |
31 | 18.8k | ? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask), mode)) |
32 | 10.6k | : nullptr; |
33 | 29.4k | } |
34 | | |
35 | | ~MaskEffect() override; |
36 | | |
37 | | protected: |
38 | | MaskEffect(sk_sp<RenderNode>, sk_sp<RenderNode> mask, Mode); |
39 | | |
40 | | void onRender(SkCanvas*, const RenderContext*) const override; |
41 | | const RenderNode* onNodeAt(const SkPoint&) const override; |
42 | | |
43 | | SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; |
44 | | |
45 | | private: |
46 | | const sk_sp<RenderNode> fMaskNode; |
47 | | const Mode fMaskMode; |
48 | | |
49 | | using INHERITED = EffectNode; |
50 | | }; |
51 | | |
52 | | } // namespace sksg |
53 | | |
54 | | #endif // SkSGMaskEffect_DEFINED |