| 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 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 clearColor, SkXfermode::kSrc_Mod
e)); | 989 clearColor, SkXfermode::kSrc_Mod
e)); |
| 990 *fp = cf->asFragmentProcessor(context); | 990 *fp = cf->asFragmentProcessor(context); |
| 991 return true; | 991 return true; |
| 992 } | 992 } |
| 993 | 993 |
| 994 // Either we don't stitch tiles, either we have a valid tile size | 994 // Either we don't stitch tiles, either we have a valid tile size |
| 995 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); | 995 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); |
| 996 | 996 |
| 997 SkPerlinNoiseShader::PaintingData* paintingData = | 997 SkPerlinNoiseShader::PaintingData* paintingData = |
| 998 SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFr
equencyY, matrix)); | 998 SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFr
equencyY, matrix)); |
| 999 SkAutoTUnref<GrTexture> permutationsTexture( | 999 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture( |
| 1000 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
NULL)); | 1000 context, paintingData->getPermutationsBitmap(), NULL); |
| 1001 SkAutoTUnref<GrTexture> noiseTexture( | 1001 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture( |
| 1002 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), NULL))
; | 1002 context, paintingData->getNoiseBitmap(), NULL); |
| 1003 | 1003 |
| 1004 SkMatrix m = context->getMatrix(); | 1004 SkMatrix m = context->getMatrix(); |
| 1005 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); | 1005 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
| 1006 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); | 1006 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
| 1007 if ((permutationsTexture) && (noiseTexture)) { | 1007 if ((permutationsTexture) && (noiseTexture)) { |
| 1008 *fp = GrPerlinNoiseEffect::Create(fType, | 1008 *fp = GrPerlinNoiseEffect::Create(fType, |
| 1009 fNumOctaves, | 1009 fNumOctaves, |
| 1010 fStitchTiles, | 1010 fStitchTiles, |
| 1011 paintingData, | 1011 paintingData, |
| 1012 permutationsTexture, noiseTexture, | 1012 permutationsTexture, noiseTexture, |
| 1013 m, paint.getAlpha()); | 1013 m, paint.getAlpha()); |
| 1014 } else { | 1014 } else { |
| 1015 SkDELETE(paintingData); | 1015 SkDELETE(paintingData); |
| 1016 *fp = NULL; | 1016 *fp = NULL; |
| 1017 } | 1017 } |
| 1018 |
| 1019 // Unlock immediately, this is not great, but we don't have a way of |
| 1020 // knowing when else to unlock it currently. TODO: Remove this when |
| 1021 // unref becomes the unlock replacement for all types of textures. |
| 1022 if (permutationsTexture) { |
| 1023 GrUnlockAndUnrefCachedBitmapTexture(permutationsTexture); |
| 1024 } |
| 1025 if (noiseTexture) { |
| 1026 GrUnlockAndUnrefCachedBitmapTexture(noiseTexture); |
| 1027 } |
| 1028 |
| 1018 return true; | 1029 return true; |
| 1019 } | 1030 } |
| 1020 | 1031 |
| 1021 #else | 1032 #else |
| 1022 | 1033 |
| 1023 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const
SkMatrix*, GrColor*, | 1034 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const
SkMatrix*, GrColor*, |
| 1024 GrFragmentProcessor**) const { | 1035 GrFragmentProcessor**) const { |
| 1025 SkDEBUGFAIL("Should not call in GPU-less build"); | 1036 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 1026 return false; | 1037 return false; |
| 1027 } | 1038 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1053 str->append(" seed: "); | 1064 str->append(" seed: "); |
| 1054 str->appendScalar(fSeed); | 1065 str->appendScalar(fSeed); |
| 1055 str->append(" stitch tiles: "); | 1066 str->append(" stitch tiles: "); |
| 1056 str->append(fStitchTiles ? "true " : "false "); | 1067 str->append(fStitchTiles ? "true " : "false "); |
| 1057 | 1068 |
| 1058 this->INHERITED::toString(str); | 1069 this->INHERITED::toString(str); |
| 1059 | 1070 |
| 1060 str->append(")"); | 1071 str->append(")"); |
| 1061 } | 1072 } |
| 1062 #endif | 1073 #endif |
| OLD | NEW |