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 const RenderNode* onNodeAt(const SkPoint&) const override; 40 41 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 42 43 private: 44 const sk_sp<RenderNode> fMaskNode; 45 const Mode fMaskMode; 46 47 typedef EffectNode INHERITED; 48 }; 49 50 } // namespace sksg 51 52 #endif // SkSGMaskEffect_DEFINED 53