Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2006 The Android Open Source Project
      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 SkMaskFilter_DEFINED
      9 #define SkMaskFilter_DEFINED
     10 
     11 #include "SkBlurTypes.h"
     12 #include "SkCoverageMode.h"
     13 #include "SkFlattenable.h"
     14 #include "SkScalar.h"
     15 
     16 class SkMatrix;
     17 struct SkRect;
     18 class SkString;
     19 
     20 /** \class SkMaskFilter
     21 
     22     SkMaskFilter is the base class for object that perform transformations on
     23     the mask before drawing it. An example subclass is Blur.
     24 */
     25 class SK_API SkMaskFilter : public SkFlattenable {
     26 public:
     27     /** Create a blur maskfilter.
     28      *  @param style      The SkBlurStyle to use
     29      *  @param sigma      Standard deviation of the Gaussian blur to apply. Must be > 0.
     30      *  @param respectCTM if true the blur's sigma is modified by the CTM.
     31      *  @return The new blur maskfilter
     32      */
     33     static sk_sp<SkMaskFilter> MakeBlur(SkBlurStyle style, SkScalar sigma,
     34                                         bool respectCTM = true);
     35 
     36     /**
     37      *  Construct a maskfilter whose effect is to first apply the inner filter and then apply
     38      *  the outer filter to the result of the inner's. Returns nullptr on failure.
     39      */
     40     static sk_sp<SkMaskFilter> MakeCompose(sk_sp<SkMaskFilter> outer, sk_sp<SkMaskFilter> inner);
     41 
     42     /**
     43      *  Compose two maskfilters together using a coverage mode. Returns nullptr on failure.
     44      */
     45     static sk_sp<SkMaskFilter> MakeCombine(sk_sp<SkMaskFilter> filterA, sk_sp<SkMaskFilter> filterB,
     46                                            SkCoverageMode mode);
     47 
     48     /**
     49      *  Construct a maskfilter with an additional transform.
     50      *
     51      *  Note: unlike shader local matrices, this transform composes next to the CTM.
     52      *
     53      *    TotalMatrix = CTM x MaskFilterMatrix x (optional/downstream) ShaderLocalMatrix
     54      */
     55     sk_sp<SkMaskFilter> makeWithMatrix(const SkMatrix&) const;
     56 
     57     static SkFlattenable::Type GetFlattenableType() {
     58         return kSkMaskFilter_Type;
     59     }
     60 
     61     SkFlattenable::Type getFlattenableType() const override {
     62         return kSkMaskFilter_Type;
     63     }
     64 
     65     static sk_sp<SkMaskFilter> Deserialize(const void* data, size_t size,
     66                                           const SkDeserialProcs* procs = nullptr) {
     67         return sk_sp<SkMaskFilter>(static_cast<SkMaskFilter*>(
     68                                   SkFlattenable::Deserialize(
     69                                   kSkMaskFilter_Type, data, size, procs).release()));
     70     }
     71 
     72 private:
     73     static void RegisterFlattenables();
     74     friend class SkFlattenable;
     75 };
     76 
     77 #endif
     78