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

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

Issue 385713005: Allow GrGLEffects to produce variable length keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: rebase Created 6 years, 5 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
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkTableColorFilter.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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 #include "GrTBackendEffectFactory.h" 492 #include "GrTBackendEffectFactory.h"
493 493
494 class GrGLPerlinNoise : public GrGLEffect { 494 class GrGLPerlinNoise : public GrGLEffect {
495 public: 495 public:
496 GrGLPerlinNoise(const GrBackendEffectFactory& factory, 496 GrGLPerlinNoise(const GrBackendEffectFactory& factory,
497 const GrDrawEffect& drawEffect); 497 const GrDrawEffect& drawEffect);
498 virtual ~GrGLPerlinNoise() {} 498 virtual ~GrGLPerlinNoise() {}
499 499
500 virtual void emitCode(GrGLShaderBuilder*, 500 virtual void emitCode(GrGLShaderBuilder*,
501 const GrDrawEffect&, 501 const GrDrawEffect&,
502 EffectKey, 502 const GrEffectKey&,
503 const char* outputColor, 503 const char* outputColor,
504 const char* inputColor, 504 const char* inputColor,
505 const TransformedCoordsArray&, 505 const TransformedCoordsArray&,
506 const TextureSamplerArray&) SK_OVERRIDE; 506 const TextureSamplerArray&) SK_OVERRIDE;
507 507
508 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 508 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
509 509
510 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); 510 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder* b);
511 511
512 private: 512 private:
513 513
514 GrGLUniformManager::UniformHandle fStitchDataUni; 514 GrGLUniformManager::UniformHandle fStitchDataUni;
515 SkPerlinNoiseShader::Type fType; 515 SkPerlinNoiseShader::Type fType;
516 bool fStitchTiles; 516 bool fStitchTiles;
517 int fNumOctaves; 517 int fNumOctaves;
518 GrGLUniformManager::UniformHandle fBaseFrequencyUni; 518 GrGLUniformManager::UniformHandle fBaseFrequencyUni;
519 GrGLUniformManager::UniformHandle fAlphaUni; 519 GrGLUniformManager::UniformHandle fAlphaUni;
520 520
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 640
641 GrGLPerlinNoise::GrGLPerlinNoise(const GrBackendEffectFactory& factory, const Gr DrawEffect& drawEffect) 641 GrGLPerlinNoise::GrGLPerlinNoise(const GrBackendEffectFactory& factory, const Gr DrawEffect& drawEffect)
642 : INHERITED (factory) 642 : INHERITED (factory)
643 , fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type()) 643 , fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type())
644 , fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles()) 644 , fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles())
645 , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) { 645 , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) {
646 } 646 }
647 647
648 void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder, 648 void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder,
649 const GrDrawEffect&, 649 const GrDrawEffect&,
650 EffectKey key, 650 const GrEffectKey& key,
651 const char* outputColor, 651 const char* outputColor,
652 const char* inputColor, 652 const char* inputColor,
653 const TransformedCoordsArray& coords, 653 const TransformedCoordsArray& coords,
654 const TextureSamplerArray& samplers) { 654 const TextureSamplerArray& samplers) {
655 sk_ignore_unused_variable(inputColor); 655 sk_ignore_unused_variable(inputColor);
656 656
657 SkString vCoords = builder->ensureFSCoords2D(coords, 0); 657 SkString vCoords = builder->ensureFSCoords2D(coords, 0);
658 658
659 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity, 659 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity,
660 kVec2f_GrSLType, "baseFrequency"); 660 kVec2f_GrSLType, "baseFrequency");
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 builder->fsCodeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni); 893 builder->fsCodeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni);
894 894
895 // Clamp values 895 // Clamp values
896 builder->fsCodeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu tColor); 896 builder->fsCodeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu tColor);
897 897
898 // Pre-multiply the result 898 // Pre-multiply the result
899 builder->fsCodeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", 899 builder->fsCodeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n",
900 outputColor, outputColor, outputColor, outputColor); 900 outputColor, outputColor, outputColor, outputColor);
901 } 901 }
902 902
903 GrGLEffect::EffectKey GrGLPerlinNoise::GenKey(const GrDrawEffect& drawEffect, co nst GrGLCaps&) { 903 void GrGLPerlinNoise::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, Gr EffectKeyBuilder* b) {
904 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE ffect>(); 904 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE ffect>();
905 905
906 EffectKey key = turbulence.numOctaves(); 906 uint32_t key = turbulence.numOctaves();
907 907
908 key = key << 3; // Make room for next 3 bits 908 key = key << 3; // Make room for next 3 bits
909 909
910 switch (turbulence.type()) { 910 switch (turbulence.type()) {
911 case SkPerlinNoiseShader::kFractalNoise_Type: 911 case SkPerlinNoiseShader::kFractalNoise_Type:
912 key |= 0x1; 912 key |= 0x1;
913 break; 913 break;
914 case SkPerlinNoiseShader::kTurbulence_Type: 914 case SkPerlinNoiseShader::kTurbulence_Type:
915 key |= 0x2; 915 key |= 0x2;
916 break; 916 break;
917 default: 917 default:
918 // leave key at 0 918 // leave key at 0
919 break; 919 break;
920 } 920 }
921 921
922 if (turbulence.stitchTiles()) { 922 if (turbulence.stitchTiles()) {
923 key |= 0x4; // Flip the 3rd bit if tile stitching is on 923 key |= 0x4; // Flip the 3rd bit if tile stitching is on
924 } 924 }
925 925
926 return key; 926 b->add32(key);
927 } 927 }
928 928
929 void GrGLPerlinNoise::setData(const GrGLUniformManager& uman, const GrDrawEffect & drawEffect) { 929 void GrGLPerlinNoise::setData(const GrGLUniformManager& uman, const GrDrawEffect & drawEffect) {
930 INHERITED::setData(uman, drawEffect); 930 INHERITED::setData(uman, drawEffect);
931 931
932 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE ffect>(); 932 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE ffect>();
933 933
934 const SkVector& baseFrequency = turbulence.baseFrequency(); 934 const SkVector& baseFrequency = turbulence.baseFrequency();
935 uman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); 935 uman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
936 uman.set1f(fAlphaUni, SkScalarDiv(SkIntToScalar(turbulence.alpha()), SkIntTo Scalar(255))); 936 uman.set1f(fAlphaUni, SkScalarDiv(SkIntToScalar(turbulence.alpha()), SkIntTo Scalar(255)));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 str->append(" seed: "); 1043 str->append(" seed: ");
1044 str->appendScalar(fSeed); 1044 str->appendScalar(fSeed);
1045 str->append(" stitch tiles: "); 1045 str->append(" stitch tiles: ");
1046 str->append(fStitchTiles ? "true " : "false "); 1046 str->append(fStitchTiles ? "true " : "false ");
1047 1047
1048 this->INHERITED::toString(str); 1048 this->INHERITED::toString(str);
1049 1049
1050 str->append(")"); 1050 str->append(")");
1051 } 1051 }
1052 #endif 1052 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkTableColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698