| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 * Create alias for CreateTurbulunce until all Skia users changed | 65 * Create alias for CreateTurbulunce until all Skia users changed |
| 66 * its code to use the new naming | 66 * its code to use the new naming |
| 67 */ | 67 */ |
| 68 static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequ
encyY, | 68 static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequ
encyY, |
| 69 int numOctaves, SkScalar seed, | 69 int numOctaves, SkScalar seed, |
| 70 const SkISize* tileSize = NULL) { | 70 const SkISize* tileSize = NULL) { |
| 71 return CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, ti
leSize); | 71 return CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, ti
leSize); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 virtual bool setContext(const SkBitmap& device, const SkPaint& paint, | 75 virtual SkShader::Context* createContext( |
| 76 const SkMatrix& matrix); | 76 const SkBitmap& device, const SkPaint& paint, |
| 77 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE; | 77 const SkMatrix& matrix, void* storage) const SK_OVERRIDE; |
| 78 virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE; | 78 virtual size_t contextSize() const SK_OVERRIDE; |
| 79 |
| 80 class PerlinNoiseShaderContext : public SkShader::Context { |
| 81 public: |
| 82 PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const SkBitm
ap& device, |
| 83 const SkPaint& paint, const SkMatrix& matrix); |
| 84 virtual ~PerlinNoiseShaderContext() {} |
| 85 |
| 86 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE
; |
| 87 virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRID
E; |
| 88 |
| 89 private: |
| 90 SkPMColor shade(const SkPoint& point, StitchData& stitchData) const; |
| 91 SkScalar calculateTurbulenceValueForPoint( |
| 92 int channel, const PaintingData& paintingData, |
| 93 StitchData& stitchData, const SkPoint& point) const; |
| 94 SkScalar noise2D(int channel, const PaintingData& paintingData, |
| 95 const StitchData& stitchData, const SkPoint& noiseVecto
r) const; |
| 96 |
| 97 SkMatrix fMatrix; |
| 98 |
| 99 typedef SkShader::Context INHERITED; |
| 100 }; |
| 79 | 101 |
| 80 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const S
K_OVERRIDE; | 102 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const S
K_OVERRIDE; |
| 81 | 103 |
| 82 SK_TO_STRING_OVERRIDE() | 104 SK_TO_STRING_OVERRIDE() |
| 83 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) | 105 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) |
| 84 | 106 |
| 85 protected: | 107 protected: |
| 86 SkPerlinNoiseShader(SkReadBuffer&); | 108 SkPerlinNoiseShader(SkReadBuffer&); |
| 87 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 109 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 88 | 110 |
| 89 private: | 111 private: |
| 90 SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, | 112 SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, |
| 91 SkScalar baseFrequencyY, int numOctaves, SkScalar seed, | 113 SkScalar baseFrequencyY, int numOctaves, SkScalar seed, |
| 92 const SkISize* tileSize); | 114 const SkISize* tileSize); |
| 93 virtual ~SkPerlinNoiseShader(); | 115 virtual ~SkPerlinNoiseShader(); |
| 94 | 116 |
| 95 SkScalar noise2D(int channel, const PaintingData& paintingData, | |
| 96 const StitchData& stitchData, const SkPoint& noiseVector) c
onst; | |
| 97 | |
| 98 SkScalar calculateTurbulenceValueForPoint(int channel, const PaintingData& p
aintingData, | |
| 99 StitchData& stitchData, const SkPo
int& point) const; | |
| 100 | |
| 101 SkPMColor shade(const SkPoint& point, StitchData& stitchData) const; | |
| 102 | |
| 103 // TODO (scroggo): Once all SkShaders are created from a factory, and we hav
e removed the | 117 // TODO (scroggo): Once all SkShaders are created from a factory, and we hav
e removed the |
| 104 // constructor that creates SkPerlinNoiseShader from an SkReadBuffer, severa
l fields can | 118 // constructor that creates SkPerlinNoiseShader from an SkReadBuffer, severa
l fields can |
| 105 // be made constant. | 119 // be made constant. |
| 106 /*const*/ SkPerlinNoiseShader::Type fType; | 120 /*const*/ SkPerlinNoiseShader::Type fType; |
| 107 /*const*/ SkScalar fBaseFrequencyX; | 121 /*const*/ SkScalar fBaseFrequencyX; |
| 108 /*const*/ SkScalar fBaseFrequencyY; | 122 /*const*/ SkScalar fBaseFrequencyY; |
| 109 /*const*/ int fNumOctaves; | 123 /*const*/ int fNumOctaves; |
| 110 /*const*/ SkScalar fSeed; | 124 /*const*/ SkScalar fSeed; |
| 111 /*const*/ SkISize fTileSize; | 125 /*const*/ SkISize fTileSize; |
| 112 /*const*/ bool fStitchTiles; | 126 /*const*/ bool fStitchTiles; |
| 113 // TODO (scroggo): Once setContext creates a new object, place this on that
object. | |
| 114 SkMatrix fMatrix; | |
| 115 | 127 |
| 116 PaintingData* fPaintingData; | 128 PaintingData* fPaintingData; |
| 117 | 129 |
| 118 typedef SkShader INHERITED; | 130 typedef SkShader INHERITED; |
| 119 }; | 131 }; |
| 120 | 132 |
| 121 #endif | 133 #endif |
| OLD | NEW |