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

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

Issue 278963002: add localmatrix parameter to shader's asNewEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/effects/gradients/SkLinearGradient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 SkScalar baseFrequencyY = random->nextRangeScalar(0.01f, 716 SkScalar baseFrequencyY = random->nextRangeScalar(0.01f,
717 0.99f); 717 0.99f);
718 718
719 SkShader* shader = random->nextBool() ? 719 SkShader* shader = random->nextBool() ?
720 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, 720 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed,
721 stitchTiles ? &tileSize : NULL) : 721 stitchTiles ? &tileSize : NULL) :
722 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu mOctaves, seed, 722 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu mOctaves, seed,
723 stitchTiles ? &tileSize : NULL); 723 stitchTiles ? &tileSize : NULL);
724 724
725 SkPaint paint; 725 SkPaint paint;
726 GrEffectRef* effect = shader->asNewEffect(context, paint); 726 GrEffectRef* effect = shader->asNewEffect(context, paint, NULL);
727 727
728 SkDELETE(shader); 728 SkDELETE(shader);
729 729
730 return effect; 730 return effect;
731 } 731 }
732 732
733 ///////////////////////////////////////////////////////////////////// 733 /////////////////////////////////////////////////////////////////////
734 734
735 void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder, 735 void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
736 const GrDrawEffect&, 736 const GrDrawEffect&,
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 1268
1269 void GrGLSimplexNoise::setData(const GrGLUniformManager& uman, const GrDrawEffec t& drawEffect) { 1269 void GrGLSimplexNoise::setData(const GrGLUniformManager& uman, const GrDrawEffec t& drawEffect) {
1270 INHERITED::setData(uman, drawEffect); 1270 INHERITED::setData(uman, drawEffect);
1271 1271
1272 const GrSimplexNoiseEffect& turbulence = drawEffect.castEffect<GrSimplexNois eEffect>(); 1272 const GrSimplexNoiseEffect& turbulence = drawEffect.castEffect<GrSimplexNois eEffect>();
1273 uman.set1f(fSeedUni, turbulence.seed()); 1273 uman.set1f(fSeedUni, turbulence.seed());
1274 } 1274 }
1275 1275
1276 ///////////////////////////////////////////////////////////////////// 1276 /////////////////////////////////////////////////////////////////////
1277 1277
1278 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint) const { 1278 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint,
1279 const SkMatrix* externalLocalMatri x) const {
1279 SkASSERT(NULL != context); 1280 SkASSERT(NULL != context);
1280 1281
1282 SkMatrix localMatrix = this->getLocalMatrix();
1283 if (externalLocalMatrix) {
1284 localMatrix.preConcat(*externalLocalMatrix);
1285 }
1286
1281 if (0 == fNumOctaves) { 1287 if (0 == fNumOctaves) {
1282 SkColor clearColor = 0; 1288 SkColor clearColor = 0;
1283 if (kFractalNoise_Type == fType) { 1289 if (kFractalNoise_Type == fType) {
1284 clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127); 1290 clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127);
1285 } 1291 }
1286 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter( 1292 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(
1287 clearColor, SkXfermode::kSrc_Mod e)); 1293 clearColor, SkXfermode::kSrc_Mod e));
1288 return cf->asNewEffect(context); 1294 return cf->asNewEffect(context);
1289 } 1295 }
1290 1296
(...skipping 11 matching lines...) Expand all
1302 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture( 1308 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture(
1303 context, fPaintingData->getPermutationsBitmap(), NULL); 1309 context, fPaintingData->getPermutationsBitmap(), NULL);
1304 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture( 1310 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture(
1305 context, fPaintingData->getNoiseBitmap(), NULL); 1311 context, fPaintingData->getNoiseBitmap(), NULL);
1306 1312
1307 GrEffectRef* effect = (NULL != permutationsTexture) && (NULL != noiseTexture ) ? 1313 GrEffectRef* effect = (NULL != permutationsTexture) && (NULL != noiseTexture ) ?
1308 GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, 1314 GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency,
1309 fNumOctaves, fStitchTiles, 1315 fNumOctaves, fStitchTiles,
1310 fPaintingData->fStitchDataInit, 1316 fPaintingData->fStitchDataInit,
1311 permutationsTexture, noiseTexture, 1317 permutationsTexture, noiseTexture,
1312 this->getLocalMatrix(), paint.getAlpha()) : 1318 localMatrix, paint.getAlpha()) :
1313 NULL; 1319 NULL;
1314 1320
1315 // Unlock immediately, this is not great, but we don't have a way of 1321 // Unlock immediately, this is not great, but we don't have a way of
1316 // knowing when else to unlock it currently. TODO: Remove this when 1322 // knowing when else to unlock it currently. TODO: Remove this when
1317 // unref becomes the unlock replacement for all types of textures. 1323 // unref becomes the unlock replacement for all types of textures.
1318 if (NULL != permutationsTexture) { 1324 if (NULL != permutationsTexture) {
1319 GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture); 1325 GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture);
1320 } 1326 }
1321 if (NULL != noiseTexture) { 1327 if (NULL != noiseTexture) {
1322 GrUnlockAndUnrefCachedBitmapTexture(noiseTexture); 1328 GrUnlockAndUnrefCachedBitmapTexture(noiseTexture);
1323 } 1329 }
1324 #endif 1330 #endif
1325 1331
1326 return effect; 1332 return effect;
1327 } 1333 }
1328 1334
1329 #else 1335 #else
1330 1336
1331 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext*, const SkPaint&) const { 1337 GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const {
1332 SkDEBUGFAIL("Should not call in GPU-less build"); 1338 SkDEBUGFAIL("Should not call in GPU-less build");
1333 return NULL; 1339 return NULL;
1334 } 1340 }
1335 1341
1336 #endif 1342 #endif
1337 1343
1338 #ifndef SK_IGNORE_TO_STRING 1344 #ifndef SK_IGNORE_TO_STRING
1339 void SkPerlinNoiseShader::toString(SkString* str) const { 1345 void SkPerlinNoiseShader::toString(SkString* str) const {
1340 str->append("SkPerlinNoiseShader: ("); 1346 str->append("SkPerlinNoiseShader: (");
1341 1347
(...skipping 18 matching lines...) Expand all
1360 str->append(" seed: "); 1366 str->append(" seed: ");
1361 str->appendScalar(fSeed); 1367 str->appendScalar(fSeed);
1362 str->append(" stitch tiles: "); 1368 str->append(" stitch tiles: ");
1363 str->append(fStitchTiles ? "true " : "false "); 1369 str->append(fStitchTiles ? "true " : "false ");
1364 1370
1365 this->INHERITED::toString(str); 1371 this->INHERITED::toString(str);
1366 1372
1367 str->append(")"); 1373 str->append(")");
1368 } 1374 }
1369 #endif 1375 #endif
OLDNEW
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/effects/gradients/SkLinearGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698