Home | History | Annotate | Download | only in effects
      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 
     30     void onRender(SkCanvas*) const override;
     31 
     32     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
     33 
     34 private:
     35     float fOpacity;
     36 
     37     typedef EffectNode INHERITED;
     38 };
     39 
     40 } // namespace sksg
     41 
     42 #endif // SkSGOpacityEffect_DEFINED
     43