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