• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 {
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) {
28         return (child && mask)
29             ? sk_sp<MaskEffect>(new MaskEffect(std::move(child), std::move(mask), mode))
30             : nullptr;
31     }
32 
33     ~MaskEffect() override;
34 
35 protected:
36     MaskEffect(sk_sp<RenderNode>, sk_sp<RenderNode> mask, Mode);
37 
38     void onRender(SkCanvas*, const RenderContext*) const override;
39 
40     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
41 
42 private:
43     const sk_sp<RenderNode> fMaskNode;
44     const Mode              fMaskMode;
45 
46     typedef EffectNode INHERITED;
47 };
48 
49 } // namespace sksg
50 
51 #endif // SkSGMaskEffect_DEFINED
52