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

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

Issue 808703006: remove view matrix from context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: one more fix Created 6 years 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
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkXfermodeImageFilter.cpp » ('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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 619
620 SkShader* shader = random->nextBool() ? 620 SkShader* shader = random->nextBool() ?
621 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, 621 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed,
622 stitchTiles ? &tileSize : NULL) : 622 stitchTiles ? &tileSize : NULL) :
623 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu mOctaves, seed, 623 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu mOctaves, seed,
624 stitchTiles ? &tileSize : NULL); 624 stitchTiles ? &tileSize : NULL);
625 625
626 SkPaint paint; 626 SkPaint paint;
627 GrColor paintColor; 627 GrColor paintColor;
628 GrFragmentProcessor* effect; 628 GrFragmentProcessor* effect;
629 SkAssertResult(shader->asFragmentProcessor(context, paint, NULL, &paintColor , &effect)); 629 SkAssertResult(shader->asFragmentProcessor(context, paint,
630 GrProcessorUnitTest::TestMatrix(r andom), NULL,
631 &paintColor, &effect));
630 632
631 SkDELETE(shader); 633 SkDELETE(shader);
632 634
633 return effect; 635 return effect;
634 } 636 }
635 637
636 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) 638 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor)
637 : fType(processor.cast<GrPerlinNoiseEffect>().type()) 639 : fType(processor.cast<GrPerlinNoiseEffect>().type())
638 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) 640 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles())
639 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { 641 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 if (turbulence.stitchTiles()) { 938 if (turbulence.stitchTiles()) {
937 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat a(); 939 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat a();
938 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), 940 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth),
939 SkIntToScalar(stitchData.fHeight)); 941 SkIntToScalar(stitchData.fHeight));
940 } 942 }
941 } 943 }
942 944
943 ///////////////////////////////////////////////////////////////////// 945 /////////////////////////////////////////////////////////////////////
944 946
945 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, 947 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint& paint,
948 const SkMatrix& viewM,
946 const SkMatrix* externalLocalMatri x, 949 const SkMatrix* externalLocalMatri x,
947 GrColor* paintColor, GrFragmentPro cessor** fp) const { 950 GrColor* paintColor, GrFragmentPro cessor** fp) const {
948 SkASSERT(context); 951 SkASSERT(context);
949 952
950 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); 953 *paintColor = SkColor2GrColorJustAlpha(paint.getColor());
951 954
952 SkMatrix localMatrix = this->getLocalMatrix(); 955 SkMatrix localMatrix = this->getLocalMatrix();
953 if (externalLocalMatrix) { 956 if (externalLocalMatrix) {
954 localMatrix.preConcat(*externalLocalMatrix); 957 localMatrix.preConcat(*externalLocalMatrix);
955 } 958 }
956 959
957 SkMatrix matrix = context->getMatrix(); 960 SkMatrix matrix = viewM;
958 matrix.preConcat(localMatrix); 961 matrix.preConcat(localMatrix);
959 962
960 if (0 == fNumOctaves) { 963 if (0 == fNumOctaves) {
961 SkColor clearColor = 0; 964 SkColor clearColor = 0;
962 if (kFractalNoise_Type == fType) { 965 if (kFractalNoise_Type == fType) {
963 clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127); 966 clearColor = SkColorSetARGB(paint.getAlpha() / 2, 127, 127, 127);
964 } 967 }
965 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter( 968 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(
966 clearColor, SkXfermode::kSrc_Mod e)); 969 clearColor, SkXfermode::kSrc_Mod e));
967 *fp = cf->asFragmentProcessor(context); 970 *fp = cf->asFragmentProcessor(context);
968 return true; 971 return true;
969 } 972 }
970 973
971 // Either we don't stitch tiles, either we have a valid tile size 974 // Either we don't stitch tiles, either we have a valid tile size
972 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); 975 SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
973 976
974 SkPerlinNoiseShader::PaintingData* paintingData = 977 SkPerlinNoiseShader::PaintingData* paintingData =
975 SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFr equencyY, matrix)); 978 SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFr equencyY, matrix));
976 SkAutoTUnref<GrTexture> permutationsTexture( 979 SkAutoTUnref<GrTexture> permutationsTexture(
977 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), NULL)); 980 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), NULL));
978 SkAutoTUnref<GrTexture> noiseTexture( 981 SkAutoTUnref<GrTexture> noiseTexture(
979 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), NULL)) ; 982 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), NULL)) ;
980 983
981 SkMatrix m = context->getMatrix(); 984 SkMatrix m = viewM;
982 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); 985 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
983 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); 986 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
984 if ((permutationsTexture) && (noiseTexture)) { 987 if ((permutationsTexture) && (noiseTexture)) {
985 *fp = GrPerlinNoiseEffect::Create(fType, 988 *fp = GrPerlinNoiseEffect::Create(fType,
986 fNumOctaves, 989 fNumOctaves,
987 fStitchTiles, 990 fStitchTiles,
988 paintingData, 991 paintingData,
989 permutationsTexture, noiseTexture, 992 permutationsTexture, noiseTexture,
990 m, paint.getAlpha()); 993 m, paint.getAlpha());
991 } else { 994 } else {
992 SkDELETE(paintingData); 995 SkDELETE(paintingData);
993 *fp = NULL; 996 *fp = NULL;
994 } 997 }
995 return true; 998 return true;
996 } 999 }
997 1000
998 #else 1001 #else
999 1002
1000 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, 1003 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&,
1004 const SkMatrix*, GrColor*,
1001 GrFragmentProcessor**) const { 1005 GrFragmentProcessor**) const {
1002 SkDEBUGFAIL("Should not call in GPU-less build"); 1006 SkDEBUGFAIL("Should not call in GPU-less build");
1003 return false; 1007 return false;
1004 } 1008 }
1005 1009
1006 #endif 1010 #endif
1007 1011
1008 #ifndef SK_IGNORE_TO_STRING 1012 #ifndef SK_IGNORE_TO_STRING
1009 void SkPerlinNoiseShader::toString(SkString* str) const { 1013 void SkPerlinNoiseShader::toString(SkString* str) const {
1010 str->append("SkPerlinNoiseShader: ("); 1014 str->append("SkPerlinNoiseShader: (");
(...skipping 19 matching lines...) Expand all
1030 str->append(" seed: "); 1034 str->append(" seed: ");
1031 str->appendScalar(fSeed); 1035 str->appendScalar(fSeed);
1032 str->append(" stitch tiles: "); 1036 str->append(" stitch tiles: ");
1033 str->append(fStitchTiles ? "true " : "false "); 1037 str->append(fStitchTiles ? "true " : "false ");
1034 1038
1035 this->INHERITED::toString(str); 1039 this->INHERITED::toString(str);
1036 1040
1037 str->append(")"); 1041 str->append(")");
1038 } 1042 }
1039 #endif 1043 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkXfermodeImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698