Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkDisplacementMapEffect.h
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 
13 class SK_API SkDisplacementMapEffect : public SkImageFilter {
14 public:
15  enum ChannelSelectorType {
16  kUnknown_ChannelSelectorType,
17  kR_ChannelSelectorType,
18  kG_ChannelSelectorType,
19  kB_ChannelSelectorType,
20  kA_ChannelSelectorType
21  };
22 
23  ~SkDisplacementMapEffect() override;
24 
25  static sk_sp<SkImageFilter> Make(ChannelSelectorType xChannelSelector,
26  ChannelSelectorType yChannelSelector,
27  SkScalar scale,
28  sk_sp<SkImageFilter> displacement,
30  const CropRect* cropRect = nullptr);
31 
32  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
33 
34  SkRect computeFastBounds(const SkRect& src) const override;
35 
36  virtual SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&,
37  MapDirection) const override;
38  SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
39 
40  SK_TO_STRING_OVERRIDE()
41 
42 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
43  static SkImageFilter* Create(ChannelSelectorType xChannelSelector,
44  ChannelSelectorType yChannelSelector,
45  SkScalar scale, SkImageFilter* displacement,
46  SkImageFilter* color = nullptr,
47  const CropRect* cropRect = nullptr) {
48  return Make(xChannelSelector, yChannelSelector, scale,
49  sk_ref_sp<SkImageFilter>(displacement),
50  sk_ref_sp<SkImageFilter>(color),
51  cropRect).release();
52  }
53 #endif
54 
55 protected:
56  sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
57  SkIPoint* offset) const override;
58 
59  SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
60  ChannelSelectorType yChannelSelector,
61  SkScalar scale, sk_sp<SkImageFilter> inputs[2],
62  const CropRect* cropRect);
63  void flatten(SkWriteBuffer&) const override;
64 
65 private:
66  ChannelSelectorType fXChannelSelector;
67  ChannelSelectorType fYChannelSelector;
68  SkScalar fScale;
69  typedef SkImageFilter INHERITED;
70  const SkImageFilter* getDisplacementInput() const { return getInput(0); }
71  const SkImageFilter* getColorInput() const { return getInput(1); }
72 };
73 
74 #endif
T *SK_WARN_UNUSED_RESULT release()
Return the bare pointer, and set the internal object pointer to nullptr.
Definition: SkRefCnt.h:363
Definition: SkImageFilter.h:55
void flatten(SkWriteBuffer &) const override
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
virtual sk_sp< SkSpecialImage > onFilterImage(SkSpecialImage *src, const Context &, SkIPoint *offset) const =0
This is the virtual which should be overridden by the derived class to perform image filtering...
Definition: SkRefCnt.h:135
Base class for image filters.
Definition: SkImageFilter.h:35
SkImageFilter * getInput(int i) const
Returns the input filter at a given index, or NULL if no input is connected.
Definition: SkImageFilter.h:176
Definition: SkWriteBuffer.h:26
Definition: SkRect.h:390
virtual SkIRect onFilterNodeBounds(const SkIRect &, const SkMatrix &, MapDirection) const
Performs a forwards or reverse mapping of the given rect to accommodate this filter's margin requirem...
virtual SkIRect onFilterBounds(const SkIRect &, const SkMatrix &, MapDirection) const
This function recurses into its inputs with the given rect (first argument), calls filterBounds() wit...
Definition: SkImageFilter.h:37
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
Definition: SkDisplacementMapEffect.h:13