Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPerlinNoiseShader.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 SkPerlinNoiseShader_DEFINED
9 #define SkPerlinNoiseShader_DEFINED
10 
11 #include "SkShader.h"
12 
25 class SK_API SkPerlinNoiseShader : public SkShader {
26 public:
27  struct StitchData;
28  struct PaintingData;
29 
38  enum Type {
39  kFractalNoise_Type,
40  kTurbulence_Type,
41  kFirstType = kFractalNoise_Type,
42  kLastType = kTurbulence_Type
43  };
58  static sk_sp<SkShader> MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
59  int numOctaves, SkScalar seed,
60  const SkISize* tileSize = nullptr);
61  static sk_sp<SkShader> MakeTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
62  int numOctaves, SkScalar seed,
63  const SkISize* tileSize = nullptr);
64 
65 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
66  static SkShader* CreateFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
67  int numOctaves, SkScalar seed,
68  const SkISize* tileSize = NULL) {
69  return MakeFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, tileSize).release();
70  }
71  static SkShader* CreateTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
72  int numOctaves, SkScalar seed,
73  const SkISize* tileSize = NULL) {
74  return MakeTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, tileSize).release();
75  }
76  static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
77  int numOctaves, SkScalar seed,
78  const SkISize* tileSize = NULL) {
79  return CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, tileSize);
80  }
81 #endif
82 
84  public:
86  virtual ~PerlinNoiseShaderContext();
87 
88  void shadeSpan(int x, int y, SkPMColor[], int count) override;
89 
90  private:
91  SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
92  SkScalar calculateTurbulenceValueForPoint(
93  int channel,
94  StitchData& stitchData, const SkPoint& point) const;
95  SkScalar noise2D(int channel,
96  const StitchData& stitchData, const SkPoint& noiseVector) const;
97 
98  SkMatrix fMatrix;
99  PaintingData* fPaintingData;
100 
101  typedef SkShader::Context INHERITED;
102  };
103 
104 #if SK_SUPPORT_GPU
106 #endif
107 
108  SK_TO_STRING_OVERRIDE()
109  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
110 
111 protected:
112  void flatten(SkWriteBuffer&) const override;
113  Context* onCreateContext(const ContextRec&, void* storage) const override;
114  size_t onContextSize(const ContextRec&) const override;
115 
116 private:
117  SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX,
118  SkScalar baseFrequencyY, int numOctaves, SkScalar seed,
119  const SkISize* tileSize);
120  virtual ~SkPerlinNoiseShader();
121 
122  const SkPerlinNoiseShader::Type fType;
123  const SkScalar fBaseFrequencyX;
124  const SkScalar fBaseFrequencyY;
125  const int fNumOctaves;
126  const SkScalar fSeed;
127  const SkISize fTileSize;
128  const bool fStitchTiles;
129 
130  typedef SkShader INHERITED;
131 };
132 
133 #endif
SkPerlinNoiseShader creates an image using the Perlin turbulence function.
Definition: SkPerlinNoiseShader.h:25
Definition: SkShader.h:327
Shaders specify the source color(s) for what is being drawn.
Definition: SkShader.h:38
Definition: SkPerlinNoiseShader.h:83
Definition: SkPoint.h:156
virtual sk_sp< GrFragmentProcessor > asFragmentProcessor(const AsFPArgs &) const
Returns a GrFragmentProcessor that implements the shader for the GPU backend.
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
Definition: SkRefCnt.h:135
uint32_t SkPMColor
32 bit ARGB color value, premultiplied.
Definition: SkColor.h:147
Definition: SkShader.h:123
Definition: SkWriteBuffer.h:26
ContextRec acts as a parameter bundle for creating Contexts.
Definition: SkShader.h:104