| 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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 719     SkScalar baseFrequencyY = random->nextRangeScalar(0.01f, | 719     SkScalar baseFrequencyY = random->nextRangeScalar(0.01f, | 
| 720                                                       0.99f); | 720                                                       0.99f); | 
| 721 | 721 | 
| 722     SkShader* shader = random->nextBool() ? | 722     SkShader* shader = random->nextBool() ? | 
| 723         SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, 
      numOctaves, seed, | 723         SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, 
      numOctaves, seed, | 
| 724                                                 stitchTiles ? &tileSize : NULL) 
      : | 724                                                 stitchTiles ? &tileSize : NULL) 
      : | 
| 725         SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
      mOctaves, seed, | 725         SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
      mOctaves, seed, | 
| 726                                              stitchTiles ? &tileSize : NULL); | 726                                              stitchTiles ? &tileSize : NULL); | 
| 727 | 727 | 
| 728     SkPaint paint; | 728     SkPaint paint; | 
| 729     GrEffectRef* effect = shader->asNewEffect(context, paint, NULL); | 729     GrColor grColor; | 
|  | 730     GrEffectRef* effect; | 
|  | 731     shader->asNewEffect(context, paint, NULL, &grColor, &effect); | 
| 730 | 732 | 
| 731     SkDELETE(shader); | 733     SkDELETE(shader); | 
| 732 | 734 | 
| 733     return effect; | 735     return effect; | 
| 734 } | 736 } | 
| 735 | 737 | 
| 736 ///////////////////////////////////////////////////////////////////// | 738 ///////////////////////////////////////////////////////////////////// | 
| 737 | 739 | 
| 738 void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder, | 740 void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder, | 
| 739                                 const GrDrawEffect&, | 741                                 const GrDrawEffect&, | 
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1271 | 1273 | 
| 1272 void GrGLSimplexNoise::setData(const GrGLUniformManager& uman, const GrDrawEffec
      t& drawEffect) { | 1274 void GrGLSimplexNoise::setData(const GrGLUniformManager& uman, const GrDrawEffec
      t& drawEffect) { | 
| 1273     INHERITED::setData(uman, drawEffect); | 1275     INHERITED::setData(uman, drawEffect); | 
| 1274 | 1276 | 
| 1275     const GrSimplexNoiseEffect& turbulence = drawEffect.castEffect<GrSimplexNois
      eEffect>(); | 1277     const GrSimplexNoiseEffect& turbulence = drawEffect.castEffect<GrSimplexNois
      eEffect>(); | 
| 1276     uman.set1f(fSeedUni, turbulence.seed()); | 1278     uman.set1f(fSeedUni, turbulence.seed()); | 
| 1277 } | 1279 } | 
| 1278 | 1280 | 
| 1279 ///////////////////////////////////////////////////////////////////// | 1281 ///////////////////////////////////////////////////////////////////// | 
| 1280 | 1282 | 
| 1281 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint&
       paint, | 1283 bool SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint, | 
| 1282                                               const SkMatrix* externalLocalMatri
      x) const { | 1284                                       const SkMatrix* externalLocalMatrix, GrCol
      or* grColor, | 
|  | 1285                                       GrEffectRef** grEffect) const { | 
| 1283     SkASSERT(NULL != context); | 1286     SkASSERT(NULL != context); | 
| 1284 | 1287 | 
|  | 1288     *grColor = SkColor2GrColorJustAlpha(paint.getColor()); | 
|  | 1289 | 
| 1285     SkMatrix localMatrix = this->getLocalMatrix(); | 1290     SkMatrix localMatrix = this->getLocalMatrix(); | 
| 1286     if (externalLocalMatrix) { | 1291     if (externalLocalMatrix) { | 
| 1287         localMatrix.preConcat(*externalLocalMatrix); | 1292         localMatrix.preConcat(*externalLocalMatrix); | 
| 1288     } | 1293     } | 
| 1289 | 1294 | 
| 1290     if (0 == fNumOctaves) { | 1295     if (0 == fNumOctaves) { | 
| 1291         SkColor clearColor = 0; | 1296         SkColor clearColor = 0; | 
| 1292         if (kFractalNoise_Type == fType) { | 1297         if (kFractalNoise_Type == fType) { | 
| 1293             clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127); | 1298             clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127); | 
| 1294         } | 1299         } | 
| 1295         SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter( | 1300         SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter( | 
| 1296                                                 clearColor, SkXfermode::kSrc_Mod
      e)); | 1301                                                 clearColor, SkXfermode::kSrc_Mod
      e)); | 
| 1297         return cf->asNewEffect(context); | 1302         *grEffect = cf->asNewEffect(context); | 
|  | 1303         return true; | 
| 1298     } | 1304     } | 
| 1299 | 1305 | 
| 1300     // Either we don't stitch tiles, either we have a valid tile size | 1306     // Either we don't stitch tiles, either we have a valid tile size | 
| 1301     SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); | 1307     SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); | 
| 1302 | 1308 | 
| 1303 #ifdef SK_USE_SIMPLEX_NOISE | 1309 #ifdef SK_USE_SIMPLEX_NOISE | 
| 1304     // Simplex noise is currently disabled but can be enabled by defining SK_USE
      _SIMPLEX_NOISE | 1310     // Simplex noise is currently disabled but can be enabled by defining SK_USE
      _SIMPLEX_NOISE | 
| 1305     sk_ignore_unused_variable(context); | 1311     sk_ignore_unused_variable(context); | 
| 1306     GrEffectRef* effect = | 1312     *grEffect = | 
| 1307         GrSimplexNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, | 1313         GrSimplexNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, | 
| 1308                                      fNumOctaves, fStitchTiles, fSeed, | 1314                                      fNumOctaves, fStitchTiles, fSeed, | 
| 1309                                      this->getLocalMatrix(), paint.getAlpha()); | 1315                                      this->getLocalMatrix(), paint.getAlpha()); | 
| 1310 #else | 1316 #else | 
| 1311     GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture( | 1317     GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture( | 
| 1312         context, fPaintingData->getPermutationsBitmap(), NULL); | 1318         context, fPaintingData->getPermutationsBitmap(), NULL); | 
| 1313     GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture( | 1319     GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture( | 
| 1314         context, fPaintingData->getNoiseBitmap(), NULL); | 1320         context, fPaintingData->getNoiseBitmap(), NULL); | 
| 1315 | 1321 | 
| 1316     GrEffectRef* effect = (NULL != permutationsTexture) && (NULL != noiseTexture
      ) ? | 1322     *grEffect = (NULL != permutationsTexture) && (NULL != noiseTexture) ? | 
| 1317         GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, | 1323         GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, | 
| 1318                                     fNumOctaves, fStitchTiles, | 1324                                     fNumOctaves, fStitchTiles, | 
| 1319                                     fPaintingData->fStitchDataInit, | 1325                                     fPaintingData->fStitchDataInit, | 
| 1320                                     permutationsTexture, noiseTexture, | 1326                                     permutationsTexture, noiseTexture, | 
| 1321                                     localMatrix, paint.getAlpha()) : | 1327                                     localMatrix, paint.getAlpha()) : | 
| 1322         NULL; | 1328         NULL; | 
| 1323 | 1329 | 
| 1324     // Unlock immediately, this is not great, but we don't have a way of | 1330     // Unlock immediately, this is not great, but we don't have a way of | 
| 1325     // knowing when else to unlock it currently. TODO: Remove this when | 1331     // knowing when else to unlock it currently. TODO: Remove this when | 
| 1326     // unref becomes the unlock replacement for all types of textures. | 1332     // unref becomes the unlock replacement for all types of textures. | 
| 1327     if (NULL != permutationsTexture) { | 1333     if (NULL != permutationsTexture) { | 
| 1328         GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture); | 1334         GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture); | 
| 1329     } | 1335     } | 
| 1330     if (NULL != noiseTexture) { | 1336     if (NULL != noiseTexture) { | 
| 1331         GrUnlockAndUnrefCachedBitmapTexture(noiseTexture); | 1337         GrUnlockAndUnrefCachedBitmapTexture(noiseTexture); | 
| 1332     } | 1338     } | 
| 1333 #endif | 1339 #endif | 
| 1334 | 1340 | 
| 1335     return effect; | 1341     return true; | 
| 1336 } | 1342 } | 
| 1337 | 1343 | 
| 1338 #else | 1344 #else | 
| 1339 | 1345 | 
| 1340 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext*, const SkPaint&, const 
      SkMatrix*) const { | 1346 bool SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint, | 
|  | 1347                                       const SkMatrix* externalLocalMatrix, GrCol
      or* grColor, | 
|  | 1348                                       GrEffectRef** grEffect) const { | 
| 1341     SkDEBUGFAIL("Should not call in GPU-less build"); | 1349     SkDEBUGFAIL("Should not call in GPU-less build"); | 
| 1342     return NULL; | 1350     return false; | 
| 1343 } | 1351 } | 
| 1344 | 1352 | 
| 1345 #endif | 1353 #endif | 
| 1346 | 1354 | 
| 1347 #ifndef SK_IGNORE_TO_STRING | 1355 #ifndef SK_IGNORE_TO_STRING | 
| 1348 void SkPerlinNoiseShader::toString(SkString* str) const { | 1356 void SkPerlinNoiseShader::toString(SkString* str) const { | 
| 1349     str->append("SkPerlinNoiseShader: ("); | 1357     str->append("SkPerlinNoiseShader: ("); | 
| 1350 | 1358 | 
| 1351     str->append("type: "); | 1359     str->append("type: "); | 
| 1352     switch (fType) { | 1360     switch (fType) { | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 1369     str->append(" seed: "); | 1377     str->append(" seed: "); | 
| 1370     str->appendScalar(fSeed); | 1378     str->appendScalar(fSeed); | 
| 1371     str->append(" stitch tiles: "); | 1379     str->append(" stitch tiles: "); | 
| 1372     str->append(fStitchTiles ? "true " : "false "); | 1380     str->append(fStitchTiles ? "true " : "false "); | 
| 1373 | 1381 | 
| 1374     this->INHERITED::toString(str); | 1382     this->INHERITED::toString(str); | 
| 1375 | 1383 | 
| 1376     str->append(")"); | 1384     str->append(")"); | 
| 1377 } | 1385 } | 
| 1378 #endif | 1386 #endif | 
| OLD | NEW | 
|---|