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 "include/core/SkBlurTypes.h"
12#include "include/core/SkCoverageMode.h"
13#include "include/core/SkFlattenable.h"
14#include "include/core/SkScalar.h"
15
16class SkMatrix;
17struct SkRect;
18
19/** \class SkMaskFilter
20
21 SkMaskFilter is the base class for object that perform transformations on
22 the mask before drawing it. An example subclass is Blur.
23*/
24class SK_API SkMaskFilter : public SkFlattenable {
25public:
26 /** Create a blur maskfilter.
27 * @param style The SkBlurStyle to use
28 * @param sigma Standard deviation of the Gaussian blur to apply. Must be > 0.
29 * @param respectCTM if true the blur's sigma is modified by the CTM.
30 * @return The new blur maskfilter
31 */
32 static sk_sp<SkMaskFilter> MakeBlur(SkBlurStyle style, SkScalar sigma,
33 bool respectCTM = true);
34
35 /**
36 * Construct a maskfilter whose effect is to first apply the inner filter and then apply
37 * the outer filter to the result of the inner's. Returns nullptr on failure.
38 */
39 static sk_sp<SkMaskFilter> MakeCompose(sk_sp<SkMaskFilter> outer, sk_sp<SkMaskFilter> inner);
40
41 /**
42 * Compose two maskfilters together using a coverage mode. Returns nullptr on failure.
43 */
44 static sk_sp<SkMaskFilter> MakeCombine(sk_sp<SkMaskFilter> filterA, sk_sp<SkMaskFilter> filterB,
45 SkCoverageMode mode);
46
47 static SkFlattenable::Type GetFlattenableType() {
48 return kSkMaskFilter_Type;
49 }
50
51 SkFlattenable::Type getFlattenableType() const override {
52 return kSkMaskFilter_Type;
53 }
54
55 static sk_sp<SkMaskFilter> Deserialize(const void* data, size_t size,
56 const SkDeserialProcs* procs = nullptr) {
57 return sk_sp<SkMaskFilter>(static_cast<SkMaskFilter*>(
58 SkFlattenable::Deserialize(
59 kSkMaskFilter_Type, data, size, procs).release()));
60 }
61
62private:
63 static void RegisterFlattenables();
64 friend class SkFlattenable;
65};
66
67#endif
68