xref: /aosp_15_r20/external/skia/modules/sksg/include/SkSGOpacityEffect.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 "include/core/SkRect.h"
12 #include "include/core/SkRefCnt.h"
13 #include "modules/sksg/include/SkSGEffectNode.h"
14 #include "modules/sksg/include/SkSGNode.h"
15 #include "modules/sksg/include/SkSGRenderNode.h"
16 
17 #include <utility>
18 
19 class SkCanvas;
20 class SkMatrix;
21 struct SkPoint;
22 
23 namespace sksg {
24 class InvalidationController;
25 
26 /**
27  * Concrete Effect node, applying opacity to its descendants.
28  *
29  */
30 class OpacityEffect final : public EffectNode {
31 public:
32     static sk_sp<OpacityEffect> Make(sk_sp<RenderNode> child, float opacity = 1) {
33         return child ? sk_sp<OpacityEffect>(new OpacityEffect(std::move(child), opacity)) : nullptr;
34     }
35 
36     SG_ATTRIBUTE(Opacity, float, fOpacity)
37 
38 protected:
39     OpacityEffect(sk_sp<RenderNode>, float);
40 
41     void onRender(SkCanvas*, const RenderContext*) const override;
42     const RenderNode* onNodeAt(const SkPoint&)     const override;
43 
44     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
45 
46 private:
47     float fOpacity;
48 
49     using INHERITED = EffectNode;
50 };
51 
52 } // namespace sksg
53 
54 #endif // SkSGOpacityEffect_DEFINED
55