| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPerlinNoiseShader_DEFINED | 8 #ifndef SkPerlinNoiseShader_DEFINED |
| 9 #define SkPerlinNoiseShader_DEFINED | 9 #define SkPerlinNoiseShader_DEFINED |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 * the frequencies so that the noise will be tileable for the given tile si
ze. If tileSize | 55 * the frequencies so that the noise will be tileable for the given tile si
ze. If tileSize |
| 56 * is NULL or an empty size, the frequencies will be used as is without mod
ification. | 56 * is NULL or an empty size, the frequencies will be used as is without mod
ification. |
| 57 */ | 57 */ |
| 58 static SkShader* CreateFractalNoise(SkScalar baseFrequencyX, SkScalar baseFr
equencyY, | 58 static SkShader* CreateFractalNoise(SkScalar baseFrequencyX, SkScalar baseFr
equencyY, |
| 59 int numOctaves, SkScalar seed, | 59 int numOctaves, SkScalar seed, |
| 60 const SkISize* tileSize = NULL); | 60 const SkISize* tileSize = NULL); |
| 61 static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequ
encyY, | 61 static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequ
encyY, |
| 62 int numOctaves, SkScalar seed, | 62 int numOctaves, SkScalar seed, |
| 63 const SkISize* tileSize = NULL); | 63 const SkISize* tileSize = NULL); |
| 64 | 64 |
| 65 virtual bool setContext(const SkBitmap& device, const SkPaint& paint, | 65 virtual SkShader::Context* createContext( |
| 66 const SkMatrix& matrix); | 66 const SkBitmap& device, const SkPaint& paint, |
| 67 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE; | 67 const SkMatrix& matrix, void* storage) const SK_OVERRIDE; |
| 68 virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE; | 68 virtual size_t contextSize() const SK_OVERRIDE; |
| 69 |
| 70 class PerlinNoiseShaderContext : public SkShader::Context { |
| 71 public: |
| 72 PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const SkBitm
ap& device, |
| 73 const SkPaint& paint, const SkMatrix& matrix); |
| 74 virtual ~PerlinNoiseShaderContext() {} |
| 75 |
| 76 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE
; |
| 77 virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRID
E; |
| 78 private: |
| 79 SkPMColor shade(const SkPoint& point, StitchData& stitchData) const; |
| 80 SkScalar calculateTurbulenceValueForPoint( |
| 81 int channel, const PaintingData& paintingData, |
| 82 StitchData& stitchData, const SkPoint& point) const; |
| 83 SkScalar noise2D(int channel, const PaintingData& paintingData, |
| 84 const StitchData& stitchData, const SkPoint& noiseVecto
r) const; |
| 85 |
| 86 SkMatrix fMatrix; |
| 87 |
| 88 typedef SkShader::Context INHERITED; |
| 89 }; |
| 69 | 90 |
| 70 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const S
K_OVERRIDE; | 91 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const S
K_OVERRIDE; |
| 71 | 92 |
| 72 SK_DEVELOPER_TO_STRING() | 93 SK_DEVELOPER_TO_STRING() |
| 73 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) | 94 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) |
| 74 | 95 |
| 75 protected: | 96 protected: |
| 76 SkPerlinNoiseShader(SkReadBuffer&); | 97 SkPerlinNoiseShader(SkReadBuffer&); |
| 77 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 98 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 78 | |
| 79 private: | 99 private: |
| 80 SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, | 100 SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, |
| 81 SkScalar baseFrequencyY, int numOctaves, SkScalar seed, | 101 SkScalar baseFrequencyY, int numOctaves, SkScalar seed, |
| 82 const SkISize* tileSize); | 102 const SkISize* tileSize); |
| 83 virtual ~SkPerlinNoiseShader(); | 103 virtual ~SkPerlinNoiseShader(); |
| 84 | 104 |
| 85 SkScalar noise2D(int channel, const PaintingData& paintingData, | |
| 86 const StitchData& stitchData, const SkPoint& noiseVector) c
onst; | |
| 87 | |
| 88 SkScalar calculateTurbulenceValueForPoint(int channel, const PaintingData& p
aintingData, | |
| 89 StitchData& stitchData, const SkPo
int& point) const; | |
| 90 | |
| 91 SkPMColor shade(const SkPoint& point, StitchData& stitchData) const; | |
| 92 | |
| 93 // TODO (scroggo): Once all SkShaders are created from a factory, and we hav
e removed the | 105 // TODO (scroggo): Once all SkShaders are created from a factory, and we hav
e removed the |
| 94 // constructor that creates SkPerlinNoiseShader from an SkReadBuffer, severa
l fields can | 106 // constructor that creates SkPerlinNoiseShader from an SkReadBuffer, severa
l fields can |
| 95 // be made constant. | 107 // be made constant. |
| 96 /*const*/ SkPerlinNoiseShader::Type fType; | 108 /*const*/ SkPerlinNoiseShader::Type fType; |
| 97 /*const*/ SkScalar fBaseFrequencyX; | 109 /*const*/ SkScalar fBaseFrequencyX; |
| 98 /*const*/ SkScalar fBaseFrequencyY; | 110 /*const*/ SkScalar fBaseFrequencyY; |
| 99 /*const*/ int fNumOctaves; | 111 /*const*/ int fNumOctaves; |
| 100 /*const*/ SkScalar fSeed; | 112 /*const*/ SkScalar fSeed; |
| 101 /*const*/ SkISize fTileSize; | 113 /*const*/ SkISize fTileSize; |
| 102 /*const*/ bool fStitchTiles; | 114 /*const*/ bool fStitchTiles; |
| 103 // TODO (scroggo): Once setContext creates a new object, place this on that
object. | |
| 104 SkMatrix fMatrix; | |
| 105 | 115 |
| 106 PaintingData* fPaintingData; | 116 PaintingData* fPaintingData; |
| 107 | 117 |
| 108 typedef SkShader INHERITED; | 118 typedef SkShader INHERITED; |
| 109 }; | 119 }; |
| 110 | 120 |
| 111 #endif | 121 #endif |
| OLD | NEW |