sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 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 | #include "SkBitmap.h" |
| 13 | |
| 14 | class SK_API SkDisplacementMapEffect : public SkImageFilter { |
| 15 | public: |
| 16 | enum ChannelSelectorType { |
| 17 | kUnknown_ChannelSelectorType, |
| 18 | kR_ChannelSelectorType, |
| 19 | kG_ChannelSelectorType, |
| 20 | kB_ChannelSelectorType, |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 21 | kA_ChannelSelectorType |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 24 | ~SkDisplacementMapEffect(); |
| 25 | |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 26 | static SkDisplacementMapEffect* Create(ChannelSelectorType xChannelSelector, |
| 27 | ChannelSelectorType yChannelSelector, |
| 28 | SkScalar scale, SkImageFilter* displacement, |
| 29 | SkImageFilter* color = NULL, |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 30 | const CropRect* cropRect = NULL); |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 31 | |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 32 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect) |
| 33 | |
| 34 | virtual bool onFilterImage(Proxy* proxy, |
| 35 | const SkBitmap& src, |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 36 | const Context& ctx, |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 37 | SkBitmap* dst, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 38 | SkIPoint* offset) const override; |
| 39 | void computeFastBounds(const SkRect& src, SkRect* dst) const override; |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 40 | |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 41 | virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 42 | SkIRect* dst) const override; |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 43 | |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 44 | #if SK_SUPPORT_GPU |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 45 | bool canFilterImageGPU() const override { return true; } |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 46 | virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 47 | SkBitmap* result, SkIPoint* offset) const override; |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 48 | #endif |
| 49 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 50 | SK_TO_STRING_OVERRIDE() |
| 51 | |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 52 | protected: |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 53 | SkDisplacementMapEffect(ChannelSelectorType xChannelSelector, |
| 54 | ChannelSelectorType yChannelSelector, |
senorblanco | 9ea3d57 | 2014-07-08 09:16:22 -0700 | [diff] [blame] | 55 | SkScalar scale, SkImageFilter* inputs[2], |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 56 | const CropRect* cropRect); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 57 | void flatten(SkWriteBuffer&) const override; |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 58 | |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 59 | private: |
| 60 | ChannelSelectorType fXChannelSelector; |
| 61 | ChannelSelectorType fYChannelSelector; |
| 62 | SkScalar fScale; |
| 63 | typedef SkImageFilter INHERITED; |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 64 | const SkImageFilter* getDisplacementInput() const { return getInput(0); } |
| 65 | const SkImageFilter* getColorInput() const { return getInput(1); } |
sugoi@google.com | 781cc76 | 2013-01-15 15:40:19 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #endif |