michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkDisplacementMapEffect_DEFINED michael@0: #define SkDisplacementMapEffect_DEFINED michael@0: michael@0: #include "SkImageFilter.h" michael@0: #include "SkBitmap.h" michael@0: michael@0: class SK_API SkDisplacementMapEffect : public SkImageFilter { michael@0: public: michael@0: enum ChannelSelectorType { michael@0: kUnknown_ChannelSelectorType, michael@0: kR_ChannelSelectorType, michael@0: kG_ChannelSelectorType, michael@0: kB_ChannelSelectorType, michael@0: kA_ChannelSelectorType michael@0: }; michael@0: michael@0: ~SkDisplacementMapEffect(); michael@0: michael@0: static SkDisplacementMapEffect* Create(ChannelSelectorType xChannelSelector, michael@0: ChannelSelectorType yChannelSelector, michael@0: SkScalar scale, SkImageFilter* displacement, michael@0: SkImageFilter* color = NULL, michael@0: const CropRect* cropRect = NULL) { michael@0: return SkNEW_ARGS(SkDisplacementMapEffect, (xChannelSelector, yChannelSelector, scale, michael@0: displacement, color, cropRect)); michael@0: } michael@0: michael@0: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect) michael@0: michael@0: virtual bool onFilterImage(Proxy* proxy, michael@0: const SkBitmap& src, michael@0: const Context& ctx, michael@0: SkBitmap* dst, michael@0: SkIPoint* offset) const SK_OVERRIDE; michael@0: virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE; michael@0: michael@0: virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&, michael@0: SkIRect* dst) const SK_OVERRIDE; michael@0: michael@0: #if SK_SUPPORT_GPU michael@0: virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; } michael@0: virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, michael@0: SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE; michael@0: #endif michael@0: michael@0: protected: michael@0: explicit SkDisplacementMapEffect(SkReadBuffer& buffer); michael@0: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; michael@0: michael@0: #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS michael@0: public: michael@0: #endif michael@0: SkDisplacementMapEffect(ChannelSelectorType xChannelSelector, michael@0: ChannelSelectorType yChannelSelector, michael@0: SkScalar scale, SkImageFilter* displacement, michael@0: SkImageFilter* color = NULL, michael@0: const CropRect* cropRect = NULL); michael@0: michael@0: private: michael@0: ChannelSelectorType fXChannelSelector; michael@0: ChannelSelectorType fYChannelSelector; michael@0: SkScalar fScale; michael@0: typedef SkImageFilter INHERITED; michael@0: const SkImageFilter* getDisplacementInput() const { return getInput(0); } michael@0: const SkImageFilter* getColorInput() const { return getInput(1); } michael@0: }; michael@0: michael@0: #endif