1 /*
2  * Copyright 2013 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 SkDisplacementMapEffect_DEFINED
9 #define SkDisplacementMapEffect_DEFINED
10 
11 #include "SkImageFilter.h"
12 
13 class SK_API SkDisplacementMapEffect : public SkImageFilter {
14 public:
15     enum ChannelSelectorType {
16         kUnknown_ChannelSelectorType,
17         kR_ChannelSelectorType,
18         kG_ChannelSelectorType,
19         kB_ChannelSelectorType,
20         kA_ChannelSelectorType
21     };
22 
23     ~SkDisplacementMapEffect() override;
24 
25     static sk_sp<SkImageFilter> Make(ChannelSelectorType xChannelSelector,
26                                      ChannelSelectorType yChannelSelector,
27                                      SkScalar scale,
28                                      sk_sp<SkImageFilter> displacement,
29                                      sk_sp<SkImageFilter> color,
30                                      const CropRect* cropRect = nullptr);
31 
32     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
33 
34     SkRect computeFastBounds(const SkRect& src) const override;
35 
36     virtual SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&,
37                                    MapDirection) const override;
38     SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
39 
40     SK_TO_STRING_OVERRIDE()
41 
42 protected:
43     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
44                                         SkIPoint* offset) const override;
45 
46     SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
47                             ChannelSelectorType yChannelSelector,
48                             SkScalar scale, sk_sp<SkImageFilter> inputs[2],
49                             const CropRect* cropRect);
50     void flatten(SkWriteBuffer&) const override;
51 
52 private:
53     ChannelSelectorType fXChannelSelector;
54     ChannelSelectorType fYChannelSelector;
55     SkScalar fScale;
56     typedef SkImageFilter INHERITED;
getDisplacementInput()57     const SkImageFilter* getDisplacementInput() const { return getInput(0); }
getColorInput()58     const SkImageFilter* getColorInput() const { return getInput(1); }
59 };
60 
61 #endif
62