Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 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 SkSGOpacityEffect_DEFINED |
| 9 | #define SkSGOpacityEffect_DEFINED |
| 10 | |
| 11 | #include "SkSGEffectNode.h" |
| 12 | |
| 13 | namespace sksg { |
| 14 | |
| 15 | /** |
| 16 | * Concrete Effect node, applying opacity to its descendants. |
| 17 | * |
| 18 | */ |
| 19 | class OpacityEffect final : public EffectNode { |
| 20 | public: |
| 21 | static sk_sp<OpacityEffect> Make(sk_sp<RenderNode> child, float opacity = 1) { |
| 22 | return child ? sk_sp<OpacityEffect>(new OpacityEffect(std::move(child), opacity)) : nullptr; |
| 23 | } |
| 24 | |
| 25 | SG_ATTRIBUTE(Opacity, float, fOpacity) |
| 26 | |
| 27 | protected: |
| 28 | OpacityEffect(sk_sp<RenderNode>, float); |
| 29 | |
Florin Malita | c0132ff | 2018-08-09 07:40:01 -0400 | [diff] [blame] | 30 | void onRender(SkCanvas*, const RenderContext*) const override; |
Florin Malita | eb46bd8 | 2019-02-12 09:33:21 -0500 | [diff] [blame] | 31 | const RenderNode* onNodeAt(const SkPoint&) const override; |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 32 | |
| 33 | SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; |
| 34 | |
| 35 | private: |
| 36 | float fOpacity; |
| 37 | |
| 38 | typedef EffectNode INHERITED; |
| 39 | }; |
| 40 | |
| 41 | } // namespace sksg |
| 42 | |
| 43 | #endif // SkSGOpacityEffect_DEFINED |