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 SkBlurMaskFilter_DEFINED
9#define SkBlurMaskFilter_DEFINED
10
11// we include this since our callers will need to at least be able to ref/unref
12#include "SkMaskFilter.h"
13#include "SkScalar.h"
14#include "SkBlurTypes.h"
15
16class SK_API SkBlurMaskFilter {
17public:
18    /**
19     *  If radius > 0, return the corresponding sigma, else return 0. Use this to convert from the
20     *  (legacy) idea of specify the blur "radius" to the standard notion of specifying its sigma.
21     */
22    static SkScalar ConvertRadiusToSigma(SkScalar radius);
23
24    enum BlurFlags {
25        kNone_BlurFlag              = 0x00,
26        /** The blur layer's radius is not affected by transforms */
27        kIgnoreTransform_BlurFlag   = 0x01,
28        /** Use a smother, higher qulity blur algorithm */
29        kHighQuality_BlurFlag       = 0x02,
30        /** mask for all blur flags */
31        kAll_BlurFlag               = 0x03
32    };
33
34    /** Create a blur maskfilter.
35     *  @param style     The SkBlurStyle to use
36     *  @param sigma     Standard deviation of the Gaussian blur to apply. Must be > 0.
37     *  @param occluder  The rect for which no pixels need be drawn (b.c. it will be overdrawn
38     *                   with some opaque object. This is just a hint which backends are free to
39     *                   ignore.
40     *  @param flags     Flags to use - defaults to none
41     *  @return The new blur maskfilter
42     */
43    static sk_sp<SkMaskFilter> Make(SkBlurStyle style, SkScalar sigma,
44                                    const SkRect& occluder, uint32_t flags = kNone_BlurFlag);
45
46    static sk_sp<SkMaskFilter> Make(SkBlurStyle style, SkScalar sigma,
47                                    uint32_t flags = kNone_BlurFlag) {
48        return Make(style, sigma, SkRect::MakeEmpty(), flags);
49    }
50
51#ifdef SK_SUPPORT_LEGACY_EMBOSSMASKFILTER
52    /** Create an emboss maskfilter
53        @param blurSigma    standard deviation of the Gaussian blur to apply
54                            before applying lighting (e.g. 3)
55        @param direction    array of 3 scalars [x, y, z] specifying the direction of the light source
56        @param ambient      0...1 amount of ambient light
57        @param specular     coefficient for specular highlights (e.g. 8)
58        @return the emboss maskfilter
59    */
60    static sk_sp<SkMaskFilter> MakeEmboss(SkScalar blurSigma, const SkScalar direction[3],
61                                          SkScalar ambient, SkScalar specular);
62#endif
63
64    static const int kMaxDivisions = 6;
65
66    // This method computes all the parameters for drawing a partially occluded nine-patched
67    // blurred rrect mask:
68    //   rrectToDraw - the integerized rrect to draw in the mask
69    //   widthHeight - how large to make the mask (rrectToDraw will be centered in this coord sys)
70    //   rectXs, rectYs - the x & y coordinates of the covering geometry lattice
71    //   texXs, texYs - the texture coordinate at each point in rectXs & rectYs
72    //   numXs, numYs - number of coordinates in the x & y directions
73    //   skipMask - bit mask that contains a 1-bit whenever one of the cells is occluded
74    // It returns true if 'devRRect' is nine-patchable
75    static bool ComputeBlurredRRectParams(const SkRRect& srcRRect, const SkRRect& devRRect,
76                                          const SkRect& occluder,
77                                          SkScalar sigma, SkScalar xformedSigma,
78                                          SkRRect* rrectToDraw,
79                                          SkISize* widthHeight,
80                                          SkScalar rectXs[kMaxDivisions],
81                                          SkScalar rectYs[kMaxDivisions],
82                                          SkScalar texXs[kMaxDivisions],
83                                          SkScalar texYs[kMaxDivisions],
84                                          int* numXs, int* numYs, uint32_t* skipMask);
85
86    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
87
88private:
89    SkBlurMaskFilter(); // can't be instantiated
90};
91
92#endif
93