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

Side by Side Diff: src/gpu/effects/GrDistanceFieldGeoProc.cpp

Issue 1881513002: Add appendPrecisionModifier method to GrGLSLShaderBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/SkBlurMaskFilter.cpp ('k') | src/gpu/effects/GrTextureDomain.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 "GrDistanceFieldGeoProc.h" 8 #include "GrDistanceFieldGeoProc.h"
9 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
10 #include "GrTexture.h" 10 #include "GrTexture.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); 90 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture();
91 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ; 91 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ;
92 92
93 GrGLSLVertToFrag st(kVec2f_GrSLType); 93 GrGLSLVertToFrag st(kVec2f_GrSLType);
94 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ; 94 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ;
95 vertBuilder->codeAppendf("%s = vec2(%d, %d) * %s;", st.vsOut(), 95 vertBuilder->codeAppendf("%s = vec2(%d, %d) * %s;", st.vsOut(),
96 atlas->width(), atlas->height(), 96 atlas->width(), atlas->height(),
97 dfTexEffect.inTextureCoords()->fName); 97 dfTexEffect.inTextureCoords()->fName);
98 98
99 // Use highp to work around aliasing issues 99 // Use highp to work around aliasing issues
100 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 100 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
101 kHigh_GrSLPreci sion));
102 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 101 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
103 102
104 fragBuilder->codeAppend("\tfloat texColor = "); 103 fragBuilder->codeAppend("\tfloat texColor = ");
105 fragBuilder->appendTextureLookup(args.fSamplers[0], 104 fragBuilder->appendTextureLookup(args.fSamplers[0],
106 "uv", 105 "uv",
107 kVec2f_GrSLType); 106 kVec2f_GrSLType);
108 fragBuilder->codeAppend(".r;\n"); 107 fragBuilder->codeAppend(".r;\n");
109 fragBuilder->codeAppend("\tfloat distance = " 108 fragBuilder->codeAppend("\tfloat distance = "
110 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie ldThreshold ");"); 109 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie ldThreshold ");");
111 #ifdef SK_GAMMA_APPLY_TO_A8 110 #ifdef SK_GAMMA_APPLY_TO_A8
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 dfTexEffect.inPosition()->fName, 327 dfTexEffect.inPosition()->fName,
329 args.fTransformsIn, 328 args.fTransformsIn,
330 args.fTransformsOut); 329 args.fTransformsOut);
331 330
332 const char* textureSizeUniName = nullptr; 331 const char* textureSizeUniName = nullptr;
333 fTextureSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 332 fTextureSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
334 kVec2f_GrSLType, kDefault_G rSLPrecision, 333 kVec2f_GrSLType, kDefault_G rSLPrecision,
335 "TextureSize", &textureSize UniName); 334 "TextureSize", &textureSize UniName);
336 335
337 // Use highp to work around aliasing issues 336 // Use highp to work around aliasing issues
338 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 337 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
339 kHigh_GrSLPreci sion));
340 fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); 338 fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn());
341 339
342 fragBuilder->codeAppend("float texColor = "); 340 fragBuilder->codeAppend("float texColor = ");
343 fragBuilder->appendTextureLookup(args.fSamplers[0], 341 fragBuilder->appendTextureLookup(args.fSamplers[0],
344 "uv", 342 "uv",
345 kVec2f_GrSLType); 343 kVec2f_GrSLType);
346 fragBuilder->codeAppend(".r;"); 344 fragBuilder->codeAppend(".r;");
347 fragBuilder->codeAppend("float distance = " 345 fragBuilder->codeAppend("float distance = "
348 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); 346 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");");
349 347
350 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 348 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
351 kHigh_GrSLPreci sion));
352 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); 349 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
353 fragBuilder->codeAppend("float afwidth;"); 350 fragBuilder->codeAppend("float afwidth;");
354 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) == 351 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) ==
355 kUniformScale_DistanceFieldEffectMask; 352 kUniformScale_DistanceFieldEffectMask;
356 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); 353 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag);
357 if (isUniformScale) { 354 if (isUniformScale) {
358 // For uniform scale, we adjust for the effect of the transformation on the distance 355 // For uniform scale, we adjust for the effect of the transformation on the distance
359 // by using the length of the gradient of the t coordinate in the y direction. 356 // by using the length of the gradient of the t coordinate in the y direction.
360 // We use st coordinates to ensure we're mapping 1:1 from texel spac e to pixel space. 357 // We use st coordinates to ensure we're mapping 1:1 from texel spac e to pixel space.
361 // We use the y gradient because there is a bug in the Mali 400 in t he x direction. 358 // We use the y gradient because there is a bug in the Mali 400 in t he x direction.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 atlas->width(), atlas->height(), 569 atlas->width(), atlas->height(),
573 dfTexEffect.inTextureCoords()->fName); 570 dfTexEffect.inTextureCoords()->fName);
574 571
575 // add frag shader code 572 // add frag shader code
576 573
577 SkAssertResult(fragBuilder->enableFeature( 574 SkAssertResult(fragBuilder->enableFeature(
578 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 575 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
579 576
580 // create LCD offset adjusted by inverse of transform 577 // create LCD offset adjusted by inverse of transform
581 // Use highp to work around aliasing issues 578 // Use highp to work around aliasing issues
582 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 579 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
583 kHigh_GrSLPreci sion));
584 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 580 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
585 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 581 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
586 kHigh_GrSLPreci sion));
587 582
588 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); 583 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width());
589 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { 584 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
590 fragBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DI G, lcdDelta); 585 fragBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DI G, lcdDelta);
591 } else { 586 } else {
592 fragBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG , lcdDelta); 587 fragBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG , lcdDelta);
593 } 588 }
594 if (isUniformScale) { 589 if (isUniformScale) {
595 fragBuilder->codeAppendf("float st_grad_len = abs(dFdy(%s.y));", st. fsIn()); 590 fragBuilder->codeAppendf("float st_grad_len = abs(dFdy(%s.y));", st. fsIn());
596 fragBuilder->codeAppend("vec2 offset = vec2(st_grad_len*delta, 0.0); "); 591 fragBuilder->codeAppend("vec2 offset = vec2(st_grad_len*delta, 0.0); ");
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ; 783 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ;
789 } 784 }
790 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 785 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
791 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), 786 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom),
792 GrTest::TestMatrix(d->fRandom), 787 GrTest::TestMatrix(d->fRandom),
793 d->fTextures[texIdx], params, 788 d->fTextures[texIdx], params,
794 wa, 789 wa,
795 flags, 790 flags,
796 d->fRandom->nextBool()); 791 d->fRandom->nextBool());
797 } 792 }
OLDNEW
« no previous file with comments | « src/effects/SkBlurMaskFilter.cpp ('k') | src/gpu/effects/GrTextureDomain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698