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

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

Issue 1889453002: Tweak distance field path renderer behavior in gamma-correct mode (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebased, plumbed gamma-correctness via DrawPathArgs, fixed typos from most recent change 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/gpu/batches/GrAADistanceFieldPathRenderer.cpp ('k') | no next file » | 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 fragBuilder->codeAppend(".r;"); 355 fragBuilder->codeAppend(".r;");
356 fragBuilder->codeAppend("float distance = " 356 fragBuilder->codeAppend("float distance = "
357 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); 357 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");");
358 358
359 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision); 359 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
360 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); 360 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
361 fragBuilder->codeAppend("float afwidth;"); 361 fragBuilder->codeAppend("float afwidth;");
362 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) == 362 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) ==
363 kUniformScale_DistanceFieldEffectMask; 363 kUniformScale_DistanceFieldEffectMask;
364 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); 364 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag);
365 bool isGammaCorrect =
366 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF lag);
365 if (isUniformScale) { 367 if (isUniformScale) {
366 // For uniform scale, we adjust for the effect of the transformation on the distance 368 // For uniform scale, we adjust for the effect of the transformation on the distance
367 // by using the length of the gradient of the t coordinate in the y direction. 369 // by using the length of the gradient of the t coordinate in the y direction.
368 // We use st coordinates to ensure we're mapping 1:1 from texel spac e to pixel space. 370 // We use st coordinates to ensure we're mapping 1:1 from texel spac e to pixel space.
369 // We use the y gradient because there is a bug in the Mali 400 in t he x direction. 371 // We use the y gradient because there is a bug in the Mali 400 in t he x direction.
370 372
371 // this gives us a smooth step across approximately one fragment 373 // this gives us a smooth step across approximately one fragment
372 fragBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "* dFdy(st.y));"); 374 fragBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "* dFdy(st.y));");
373 375
374 } else if (isSimilarity) { 376 } else if (isSimilarity) {
(...skipping 20 matching lines...) Expand all
395 fragBuilder->codeAppend("}"); 397 fragBuilder->codeAppend("}");
396 398
397 fragBuilder->codeAppend("vec2 Jdx = dFdx(st);"); 399 fragBuilder->codeAppend("vec2 Jdx = dFdx(st);");
398 fragBuilder->codeAppend("vec2 Jdy = dFdy(st);"); 400 fragBuilder->codeAppend("vec2 Jdy = dFdy(st);");
399 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,"); 401 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,");
400 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);"); 402 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);");
401 403
402 // this gives us a smooth step across approximately one fragment 404 // this gives us a smooth step across approximately one fragment
403 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);"); 405 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);");
404 } 406 }
405 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, dista nce);"); 407 // The smoothstep falloff compensates for the non-linear sRGB response c urve. If we are
408 // doing gamma-correct rendering (to an sRGB or F16 buffer), then we act ually want distance
409 // mapped linearly to coverage, so use a linear step:
410 if (isGammaCorrect) {
411 fragBuilder->codeAppend(
412 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1. 0);");
413 } else {
414 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d istance);");
415 }
406 416
407 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 417 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
408 } 418 }
409 419
410 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override { 420 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override {
411 SkASSERT(fTextureSizeUni.isValid()); 421 SkASSERT(fTextureSizeUni.isValid());
412 422
413 GrTexture* texture = proc.texture(0); 423 GrTexture* texture = proc.texture(0);
414 if (texture->width() != fTextureSize.width() || 424 if (texture->width() != fTextureSize.width() ||
415 texture->height() != fTextureSize.height()) { 425 texture->height() != fTextureSize.height()) {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ; 815 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ;
806 } 816 }
807 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 817 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
808 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), 818 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom),
809 GrTest::TestMatrix(d->fRandom), 819 GrTest::TestMatrix(d->fRandom),
810 d->fTextures[texIdx], params, 820 d->fTextures[texIdx], params,
811 wa, 821 wa,
812 flags, 822 flags,
813 d->fRandom->nextBool()); 823 d->fRandom->nextBool());
814 } 824 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAADistanceFieldPathRenderer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698