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