Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 318923005: SkShader::asNewEffect Refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Style corrections Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, &grColor, &effect, NULL);
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
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, GrColor* grColor,
1282 const SkMatrix* externalLocalMatri x) const { 1284 GrEffectRef** grEffect, const SkMatrix* ex ternalLocalMatrix)
1285 const {
jvanverth1 2014/06/05 17:36:31 indent 'const {', and grColor never gets set by th
dandov 2014/06/06 21:50:43 Done.
1283 SkASSERT(NULL != context); 1286 SkASSERT(NULL != context);
1284 1287
1285 SkMatrix localMatrix = this->getLocalMatrix(); 1288 SkMatrix localMatrix = this->getLocalMatrix();
1286 if (externalLocalMatrix) { 1289 if (externalLocalMatrix) {
1287 localMatrix.preConcat(*externalLocalMatrix); 1290 localMatrix.preConcat(*externalLocalMatrix);
1288 } 1291 }
1289 1292
1290 if (0 == fNumOctaves) { 1293 if (0 == fNumOctaves) {
1291 SkColor clearColor = 0; 1294 SkColor clearColor = 0;
1292 if (kFractalNoise_Type == fType) { 1295 if (kFractalNoise_Type == fType) {
1293 clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127); 1296 clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127);
1294 } 1297 }
1295 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter( 1298 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(
1296 clearColor, SkXfermode::kSrc_Mod e)); 1299 clearColor, SkXfermode::kSrc_Mod e));
1297 return cf->asNewEffect(context); 1300 *grEffect = cf->asNewEffect(context);
1301 return true;
1298 } 1302 }
1299 1303
1300 // Either we don't stitch tiles, either we have a valid tile size 1304 // Either we don't stitch tiles, either we have a valid tile size
1301 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); 1305 SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
1302 1306
1303 #ifdef SK_USE_SIMPLEX_NOISE 1307 #ifdef SK_USE_SIMPLEX_NOISE
1304 // Simplex noise is currently disabled but can be enabled by defining SK_USE _SIMPLEX_NOISE 1308 // Simplex noise is currently disabled but can be enabled by defining SK_USE _SIMPLEX_NOISE
1305 sk_ignore_unused_variable(context); 1309 sk_ignore_unused_variable(context);
1306 GrEffectRef* effect = 1310 *grEffect =
1307 GrSimplexNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, 1311 GrSimplexNoiseEffect::Create(fType, fPaintingData->fBaseFrequency,
1308 fNumOctaves, fStitchTiles, fSeed, 1312 fNumOctaves, fStitchTiles, fSeed,
1309 this->getLocalMatrix(), paint.getAlpha()); 1313 this->getLocalMatrix(), paint.getAlpha());
1310 #else 1314 #else
1311 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture( 1315 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture(
1312 context, fPaintingData->getPermutationsBitmap(), NULL); 1316 context, fPaintingData->getPermutationsBitmap(), NULL);
1313 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture( 1317 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture(
1314 context, fPaintingData->getNoiseBitmap(), NULL); 1318 context, fPaintingData->getNoiseBitmap(), NULL);
1315 1319
1316 GrEffectRef* effect = (NULL != permutationsTexture) && (NULL != noiseTexture ) ? 1320 *grEffect = (NULL != permutationsTexture) && (NULL != noiseTexture) ?
1317 GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, 1321 GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency,
1318 fNumOctaves, fStitchTiles, 1322 fNumOctaves, fStitchTiles,
1319 fPaintingData->fStitchDataInit, 1323 fPaintingData->fStitchDataInit,
1320 permutationsTexture, noiseTexture, 1324 permutationsTexture, noiseTexture,
1321 localMatrix, paint.getAlpha()) : 1325 localMatrix, paint.getAlpha()) :
1322 NULL; 1326 NULL;
1323 1327
1324 // Unlock immediately, this is not great, but we don't have a way of 1328 // 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 1329 // knowing when else to unlock it currently. TODO: Remove this when
1326 // unref becomes the unlock replacement for all types of textures. 1330 // unref becomes the unlock replacement for all types of textures.
1327 if (NULL != permutationsTexture) { 1331 if (NULL != permutationsTexture) {
1328 GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture); 1332 GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture);
1329 } 1333 }
1330 if (NULL != noiseTexture) { 1334 if (NULL != noiseTexture) {
1331 GrUnlockAndUnrefCachedBitmapTexture(noiseTexture); 1335 GrUnlockAndUnrefCachedBitmapTexture(noiseTexture);
1332 } 1336 }
1333 #endif 1337 #endif
1334 1338
1335 return effect; 1339 return true;
1336 } 1340 }
1337 1341
1338 #else 1342 #else
1339 1343
1340 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const { 1344 bool SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint, GrColor* grColor,
1345 GrEffectRef** grEffect, const SkMatrix* lo calMatrix) const {
1341 SkDEBUGFAIL("Should not call in GPU-less build"); 1346 SkDEBUGFAIL("Should not call in GPU-less build");
1342 return NULL; 1347 *grEffect = NULL;
1348 return false;
1343 } 1349 }
1344 1350
1345 #endif 1351 #endif
1346 1352
1347 #ifndef SK_IGNORE_TO_STRING 1353 #ifndef SK_IGNORE_TO_STRING
1348 void SkPerlinNoiseShader::toString(SkString* str) const { 1354 void SkPerlinNoiseShader::toString(SkString* str) const {
1349 str->append("SkPerlinNoiseShader: ("); 1355 str->append("SkPerlinNoiseShader: (");
1350 1356
1351 str->append("type: "); 1357 str->append("type: ");
1352 switch (fType) { 1358 switch (fType) {
(...skipping 16 matching lines...) Expand all
1369 str->append(" seed: "); 1375 str->append(" seed: ");
1370 str->appendScalar(fSeed); 1376 str->appendScalar(fSeed);
1371 str->append(" stitch tiles: "); 1377 str->append(" stitch tiles: ");
1372 str->append(fStitchTiles ? "true " : "false "); 1378 str->append(fStitchTiles ? "true " : "false ");
1373 1379
1374 this->INHERITED::toString(str); 1380 this->INHERITED::toString(str);
1375 1381
1376 str->append(")"); 1382 str->append(")");
1377 } 1383 }
1378 #endif 1384 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698