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, 21 kA_ChannelSelectorType, 22 kKeyBits = 3 // Max value is 4, so 3 bits are required at most 23 }; 24 25 SkDisplacementMapEffect(ChannelSelectorType xChannelSelector, 26 ChannelSelectorType yChannelSelector, 27 SkScalar scale, SkImageFilter* displacement, 28 SkImageFilter* color = NULL); 29 30 ~SkDisplacementMapEffect(); 31 32 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect) 33 34 virtual bool onFilterImage(Proxy* proxy, 35 const SkBitmap& src, 36 const SkMatrix& ctm, 37 SkBitmap* dst, 38 SkIPoint* offset) SK_OVERRIDE; 39 #if SK_SUPPORT_GPU 40 virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; } 41 virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 42 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; 43 #endif 44 45 protected: 46 explicit SkDisplacementMapEffect(SkFlattenableReadBuffer& buffer); 47 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 48 49 private: 50 ChannelSelectorType fXChannelSelector; 51 ChannelSelectorType fYChannelSelector; 52 SkScalar fScale; 53 typedef SkImageFilter INHERITED; 54 SkImageFilter* getDisplacementInput() { return getInput(0); } 55 SkImageFilter* getColorInput() { return getInput(1); } 56 }; 57 58 #endif 59