| 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 #include "SkDither.h" | 8 #include "SkDither.h" |
| 9 #include "SkPerlinNoiseShader.h" | 9 #include "SkPerlinNoiseShader.h" |
| 10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return noiseValue; | 44 return noiseValue; |
| 45 } | 45 } |
| 46 | 46 |
| 47 inline SkScalar smoothCurve(SkScalar t) { | 47 inline SkScalar smoothCurve(SkScalar t) { |
| 48 static const SkScalar SK_Scalar3 = 3.0f; | 48 static const SkScalar SK_Scalar3 = 3.0f; |
| 49 | 49 |
| 50 // returns t * t * (3 - 2 * t) | 50 // returns t * t * (3 - 2 * t) |
| 51 return SkScalarMul(SkScalarSquare(t), SK_Scalar3 - 2 * t); | 51 return SkScalarMul(SkScalarSquare(t), SK_Scalar3 - 2 * t); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool perlin_noise_type_is_valid(SkPerlinNoiseShader::Type type) { |
| 55 return (SkPerlinNoiseShader::kFractalNoise_Type == type) || |
| 56 (SkPerlinNoiseShader::kTurbulence_Type == type); |
| 57 } |
| 58 |
| 54 } // end namespace | 59 } // end namespace |
| 55 | 60 |
| 56 struct SkPerlinNoiseShader::StitchData { | 61 struct SkPerlinNoiseShader::StitchData { |
| 57 StitchData() | 62 StitchData() |
| 58 : fWidth(0) | 63 : fWidth(0) |
| 59 , fWrapX(0) | 64 , fWrapX(0) |
| 60 , fHeight(0) | 65 , fHeight(0) |
| 61 , fWrapY(0) | 66 , fWrapY(0) |
| 62 {} | 67 {} |
| 63 | 68 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 , fBaseFrequencyX(baseFrequencyX) | 281 , fBaseFrequencyX(baseFrequencyX) |
| 277 , fBaseFrequencyY(baseFrequencyY) | 282 , fBaseFrequencyY(baseFrequencyY) |
| 278 , fNumOctaves(numOctaves > 255 ? 255 : numOctaves/*[0,255] octaves allowed*/) | 283 , fNumOctaves(numOctaves > 255 ? 255 : numOctaves/*[0,255] octaves allowed*/) |
| 279 , fSeed(seed) | 284 , fSeed(seed) |
| 280 , fTileSize(NULL == tileSize ? SkISize::Make(0, 0) : *tileSize) | 285 , fTileSize(NULL == tileSize ? SkISize::Make(0, 0) : *tileSize) |
| 281 , fStitchTiles(!fTileSize.isEmpty()) | 286 , fStitchTiles(!fTileSize.isEmpty()) |
| 282 { | 287 { |
| 283 SkASSERT(numOctaves >= 0 && numOctaves < 256); | 288 SkASSERT(numOctaves >= 0 && numOctaves < 256); |
| 284 } | 289 } |
| 285 | 290 |
| 291 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 292 SkPerlinNoiseShader::SkPerlinNoiseShader(SkReadBuffer& buffer) : INHERITED(buffe
r) { |
| 293 fType = (SkPerlinNoiseShader::Type) buffer.readInt(); |
| 294 fBaseFrequencyX = buffer.readScalar(); |
| 295 fBaseFrequencyY = buffer.readScalar(); |
| 296 fNumOctaves = buffer.readInt(); |
| 297 fSeed = buffer.readScalar(); |
| 298 fStitchTiles = buffer.readBool(); |
| 299 fTileSize.fWidth = buffer.readInt(); |
| 300 fTileSize.fHeight = buffer.readInt(); |
| 301 buffer.validate(perlin_noise_type_is_valid(fType) && |
| 302 (fNumOctaves >= 0) && (fNumOctaves <= 255) && |
| 303 (fStitchTiles != fTileSize.isEmpty())); |
| 304 } |
| 305 #endif |
| 306 |
| 286 SkPerlinNoiseShader::~SkPerlinNoiseShader() { | 307 SkPerlinNoiseShader::~SkPerlinNoiseShader() { |
| 287 } | 308 } |
| 288 | 309 |
| 289 SkFlattenable* SkPerlinNoiseShader::CreateProc(SkReadBuffer& buffer) { | 310 SkFlattenable* SkPerlinNoiseShader::CreateProc(SkReadBuffer& buffer) { |
| 290 Type type = (Type)buffer.readInt(); | 311 Type type = (Type)buffer.readInt(); |
| 291 SkScalar freqX = buffer.readScalar(); | 312 SkScalar freqX = buffer.readScalar(); |
| 292 SkScalar freqY = buffer.readScalar(); | 313 SkScalar freqY = buffer.readScalar(); |
| 293 int octaves = buffer.readInt(); | 314 int octaves = buffer.readInt(); |
| 294 SkScalar seed = buffer.readScalar(); | 315 SkScalar seed = buffer.readScalar(); |
| 295 SkISize tileSize; | 316 SkISize tileSize; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 SkIntToScalar(stitchData.fHeight)); | 957 SkIntToScalar(stitchData.fHeight)); |
| 937 } | 958 } |
| 938 } | 959 } |
| 939 | 960 |
| 940 ///////////////////////////////////////////////////////////////////// | 961 ///////////////////////////////////////////////////////////////////// |
| 941 | 962 |
| 942 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint&
paint, | 963 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint&
paint, |
| 943 const SkMatrix* externalLocalMatri
x, | 964 const SkMatrix* externalLocalMatri
x, |
| 944 GrColor* paintColor, GrFragmentPro
cessor** fp) const { | 965 GrColor* paintColor, GrFragmentPro
cessor** fp) const { |
| 945 SkASSERT(context); | 966 SkASSERT(context); |
| 946 | 967 |
| 947 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); | 968 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 948 | 969 |
| 949 SkMatrix localMatrix = this->getLocalMatrix(); | 970 SkMatrix localMatrix = this->getLocalMatrix(); |
| 950 if (externalLocalMatrix) { | 971 if (externalLocalMatrix) { |
| 951 localMatrix.preConcat(*externalLocalMatrix); | 972 localMatrix.preConcat(*externalLocalMatrix); |
| 952 } | 973 } |
| 953 | 974 |
| 954 SkMatrix matrix = context->getMatrix(); | 975 SkMatrix matrix = context->getMatrix(); |
| 955 matrix.preConcat(localMatrix); | 976 matrix.preConcat(localMatrix); |
| 956 | 977 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 str->append(" seed: "); | 1048 str->append(" seed: "); |
| 1028 str->appendScalar(fSeed); | 1049 str->appendScalar(fSeed); |
| 1029 str->append(" stitch tiles: "); | 1050 str->append(" stitch tiles: "); |
| 1030 str->append(fStitchTiles ? "true " : "false "); | 1051 str->append(fStitchTiles ? "true " : "false "); |
| 1031 | 1052 |
| 1032 this->INHERITED::toString(str); | 1053 this->INHERITED::toString(str); |
| 1033 | 1054 |
| 1034 str->append(")"); | 1055 str->append(")"); |
| 1035 } | 1056 } |
| 1036 #endif | 1057 #endif |
| OLD | NEW |