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 SkEmbossMaskFilter_DEFINED
9 #define SkEmbossMaskFilter_DEFINED
10 
11 #include "SkMaskFilter.h"
12 
13 /** \class SkEmbossMaskFilter
14 
15     This mask filter creates a 3D emboss look, by specifying a light and blur amount.
16 */
17 class SK_API SkEmbossMaskFilter : public SkMaskFilter {
18 public:
19     struct Light {
20         SkScalar    fDirection[3];  // x,y,z
21         uint16_t    fPad;
22         uint8_t     fAmbient;
23         uint8_t     fSpecular;      // exponent, 4.4 right now
24     };
25 
26     static sk_sp<SkMaskFilter> Make(SkScalar blurSigma, const Light& light);
27 
28 #ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR
Create(SkScalar blurSigma,const Light & light)29     static SkMaskFilter* Create(SkScalar blurSigma, const Light& light) {
30         return Make(blurSigma, light).release();
31     }
32 #endif
33 
34     // overrides from SkMaskFilter
35     //  This method is not exported to java.
36     SkMask::Format getFormat() const override;
37     //  This method is not exported to java.
38     bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
39                     SkIPoint* margin) const override;
40 
41     SK_TO_STRING_OVERRIDE()
42     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmbossMaskFilter)
43 
44 protected:
45     SkEmbossMaskFilter(SkScalar blurSigma, const Light& light);
46     void flatten(SkWriteBuffer&) const override;
47 
48 private:
49     Light       fLight;
50     SkScalar    fBlurSigma;
51 
52     typedef SkMaskFilter INHERITED;
53 };
54 
55 #endif
56