blob: f93f2c445481991bcd208570298d8da0123a9004 [file] [log] [blame]
sugoi@google.com781cc762013-01-15 15:40:19 +00001/*
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"
sugoi@google.com781cc762013-01-15 15:40:19 +000012
13class SK_API SkDisplacementMapEffect : public SkImageFilter {
14public:
15 enum ChannelSelectorType {
16 kUnknown_ChannelSelectorType,
17 kR_ChannelSelectorType,
18 kG_ChannelSelectorType,
19 kB_ChannelSelectorType,
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000020 kA_ChannelSelectorType
sugoi@google.com781cc762013-01-15 15:40:19 +000021 };
22
robertphillipsbfe11fc2016-04-15 07:17:36 -070023 ~SkDisplacementMapEffect() override;
sugoi@google.com781cc762013-01-15 15:40:19 +000024
robertphillipsbfe11fc2016-04-15 07:17:36 -070025 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);
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000031
sugoi@google.com781cc762013-01-15 15:40:19 +000032 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
33
senorblancoe5e79842016-03-21 14:51:59 -070034 SkRect computeFastBounds(const SkRect& src) const override;
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +000035
senorblancoe5e79842016-03-21 14:51:59 -070036 virtual SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&,
37 MapDirection) const override;
38 SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000039
robertphillipsf3f5bad2014-12-19 13:49:15 -080040 SK_TO_STRING_OVERRIDE()
41
robertphillipsbfe11fc2016-04-15 07:17:36 -070042#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
43 static SkImageFilter* Create(ChannelSelectorType xChannelSelector,
44 ChannelSelectorType yChannelSelector,
45 SkScalar scale, SkImageFilter* displacement,
46 SkImageFilter* color = nullptr,
47 const CropRect* cropRect = nullptr) {
48 return Make(xChannelSelector, yChannelSelector, scale,
49 sk_ref_sp<SkImageFilter>(displacement),
50 sk_ref_sp<SkImageFilter>(color),
51 cropRect).release();
52 }
53#endif
54
sugoi@google.com781cc762013-01-15 15:40:19 +000055protected:
robertphillipse6277de2016-04-11 07:23:34 -070056 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
57 SkIPoint* offset) const override;
58
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000059 SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
60 ChannelSelectorType yChannelSelector,
robertphillipsbfe11fc2016-04-15 07:17:36 -070061 SkScalar scale, sk_sp<SkImageFilter> inputs[2],
senorblanco24e06d52015-03-18 12:11:33 -070062 const CropRect* cropRect);
mtklein36352bf2015-03-25 18:17:31 -070063 void flatten(SkWriteBuffer&) const override;
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000064
sugoi@google.com781cc762013-01-15 15:40:19 +000065private:
66 ChannelSelectorType fXChannelSelector;
67 ChannelSelectorType fYChannelSelector;
68 SkScalar fScale;
69 typedef SkImageFilter INHERITED;
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +000070 const SkImageFilter* getDisplacementInput() const { return getInput(0); }
71 const SkImageFilter* getColorInput() const { return getInput(1); }
sugoi@google.com781cc762013-01-15 15:40:19 +000072};
73
74#endif