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         kLast_ChannelSelectorType = kA_ChannelSelectorType
23     };
24 
25     ~SkDisplacementMapEffect() override;
26 
27     static sk_sp<SkImageFilter> Make(ChannelSelectorType xChannelSelector,
28                                      ChannelSelectorType yChannelSelector,
29                                      SkScalar scale,
30                                      sk_sp<SkImageFilter> displacement,
31                                      sk_sp<SkImageFilter> color,
32                                      const CropRect* cropRect = nullptr);
33 
34     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
35 
36     SkRect computeFastBounds(const SkRect& src) const override;
37 
38     virtual SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&,
39                                    MapDirection) const override;
40     sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
41     SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
42 
43     SK_TO_STRING_OVERRIDE()
44 
45 protected:
46     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
47                                         SkIPoint* offset) const override;
48 
49     SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
50                             ChannelSelectorType yChannelSelector,
51                             SkScalar scale, sk_sp<SkImageFilter> inputs[2],
52                             const CropRect* cropRect);
53     void flatten(SkWriteBuffer&) const override;
54 
55 private:
56     ChannelSelectorType fXChannelSelector;
57     ChannelSelectorType fYChannelSelector;
58     SkScalar fScale;
59     typedef SkImageFilter INHERITED;
60     const SkImageFilter* getDisplacementInput() const { return getInput(0); }
61     const SkImageFilter* getColorInput() const { return getInput(1); }
62 };
63 
64 #endif
65