blob: c4fd0120e5ad9d86947a26321c978962b40e8e98 [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
38 void onRender(SkCanvas*) const override;
39
40 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
41
42private:
Florin Malitaa016be92018-03-05 14:01:41 -050043 const sk_sp<RenderNode> fMaskNode;
44 const Mode fMaskMode;
Florin Malita5f9102f2018-01-10 13:36:22 -050045
46 typedef EffectNode INHERITED;
47};
48
49} // namespace sksg
50
51#endif // SkSGMaskEffect_DEFINED