blob: d82a40ab9fe2eeb39e150035a5c7a77924997bf6 [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,
21 kA_ChannelSelectorType,
22 kKeyBits = 3 // Max value is 4, so 3 bits are required at most
23 };
24
commit-bot@chromium.org7b320702013-07-10 21:22:18 +000025 SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
26 ChannelSelectorType yChannelSelector,
27 SkScalar scale, SkImageFilter* displacement,
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +000028 SkImageFilter* color = NULL,
29 const CropRect* cropRect = NULL);
sugoi@google.com781cc762013-01-15 15:40:19 +000030
31 ~SkDisplacementMapEffect();
32
33 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
34
35 virtual bool onFilterImage(Proxy* proxy,
36 const SkBitmap& src,
37 const SkMatrix& ctm,
38 SkBitmap* dst,
39 SkIPoint* offset) SK_OVERRIDE;
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +000040 virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE;
41
sugoi@google.com781cc762013-01-15 15:40:19 +000042#if SK_SUPPORT_GPU
43 virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; }
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000044 virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
45 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
sugoi@google.com781cc762013-01-15 15:40:19 +000046#endif
47
48protected:
49 explicit SkDisplacementMapEffect(SkFlattenableReadBuffer& buffer);
50 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
51
52private:
53 ChannelSelectorType fXChannelSelector;
54 ChannelSelectorType fYChannelSelector;
55 SkScalar fScale;
56 typedef SkImageFilter INHERITED;
57 SkImageFilter* getDisplacementInput() { return getInput(0); }
58 SkImageFilter* getColorInput() { return getInput(1); }
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +000059 const SkImageFilter* getDisplacementInput() const { return getInput(0); }
60 const SkImageFilter* getColorInput() const { return getInput(1); }
sugoi@google.com781cc762013-01-15 15:40:19 +000061};
62
63#endif