blob: 9513a54f15c92e07c2df048cb48b0f82babfb890 [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"
12#include "SkBitmap.h"
13
14class SK_API SkDisplacementMapEffect : public SkImageFilter {
15public:
16 enum ChannelSelectorType {
17 kUnknown_ChannelSelectorType,
18 kR_ChannelSelectorType,
19 kG_ChannelSelectorType,
20 kB_ChannelSelectorType,
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000021 kA_ChannelSelectorType
sugoi@google.com781cc762013-01-15 15:40:19 +000022 };
23
sugoi@google.com781cc762013-01-15 15:40:19 +000024 ~SkDisplacementMapEffect();
25
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000026 static SkDisplacementMapEffect* Create(ChannelSelectorType xChannelSelector,
27 ChannelSelectorType yChannelSelector,
28 SkScalar scale, SkImageFilter* displacement,
29 SkImageFilter* color = NULL,
senorblanco24e06d52015-03-18 12:11:33 -070030 const CropRect* cropRect = NULL);
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
34 virtual bool onFilterImage(Proxy* proxy,
35 const SkBitmap& src,
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +000036 const Context& ctx,
sugoi@google.com781cc762013-01-15 15:40:19 +000037 SkBitmap* dst,
mtklein36352bf2015-03-25 18:17:31 -070038 SkIPoint* offset) const override;
39 void computeFastBounds(const SkRect& src, SkRect* dst) const override;
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +000040
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000041 virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
mtklein36352bf2015-03-25 18:17:31 -070042 SkIRect* dst) const override;
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000043
sugoi@google.com781cc762013-01-15 15:40:19 +000044#if SK_SUPPORT_GPU
mtklein36352bf2015-03-25 18:17:31 -070045 bool canFilterImageGPU() const override { return true; }
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +000046 virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
mtklein36352bf2015-03-25 18:17:31 -070047 SkBitmap* result, SkIPoint* offset) const override;
sugoi@google.com781cc762013-01-15 15:40:19 +000048#endif
49
robertphillipsf3f5bad2014-12-19 13:49:15 -080050 SK_TO_STRING_OVERRIDE()
51
sugoi@google.com781cc762013-01-15 15:40:19 +000052protected:
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000053 SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
54 ChannelSelectorType yChannelSelector,
senorblanco9ea3d572014-07-08 09:16:22 -070055 SkScalar scale, SkImageFilter* inputs[2],
senorblanco24e06d52015-03-18 12:11:33 -070056 const CropRect* cropRect);
mtklein36352bf2015-03-25 18:17:31 -070057 void flatten(SkWriteBuffer&) const override;
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000058
sugoi@google.com781cc762013-01-15 15:40:19 +000059private:
60 ChannelSelectorType fXChannelSelector;
61 ChannelSelectorType fYChannelSelector;
62 SkScalar fScale;
63 typedef SkImageFilter INHERITED;
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +000064 const SkImageFilter* getDisplacementInput() const { return getInput(0); }
65 const SkImageFilter* getColorInput() const { return getInput(1); }
sugoi@google.com781cc762013-01-15 15:40:19 +000066};
67
68#endif