Home | History | Annotate | Download | only in include
      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 SkSGClipEffect_DEFINED
      9 #define SkSGClipEffect_DEFINED
     10 
     11 #include "SkSGEffectNode.h"
     12 
     13 namespace sksg {
     14 
     15 class GeometryNode;
     16 
     17 /**
     18  * Concrete Effect node, applying a clip to its descendants.
     19  *
     20  */
     21 class ClipEffect final : public EffectNode {
     22 public:
     23     static sk_sp<ClipEffect> Make(sk_sp<RenderNode> child, sk_sp<GeometryNode> clip,
     24                                   bool aa = false) {
     25         return (child && clip)
     26             ? sk_sp<ClipEffect>(new ClipEffect(std::move(child), std::move(clip), aa))
     27             : nullptr;
     28     }
     29 
     30     ~ClipEffect() override;
     31 
     32 protected:
     33     ClipEffect(sk_sp<RenderNode>, sk_sp<GeometryNode>, bool aa);
     34 
     35     void onRender(SkCanvas*, const RenderContext*) const override;
     36     const RenderNode* onNodeAt(const SkPoint&)     const override;
     37 
     38     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
     39 
     40 private:
     41     const sk_sp<GeometryNode> fClipNode;
     42     const bool                fAntiAlias;
     43 
     44     bool                      fNoop = false;
     45 
     46     typedef EffectNode INHERITED;
     47 };
     48 
     49 } // namespace sksg
     50 
     51 #endif // SkSGClipEffect_DEFINED
     52