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

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

Issue 1884873006: Rename lots of things from 'sRGB' to 'GammaCorrect', where appropriate (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
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 dfTexEffect.inPosition()->fName, 75 dfTexEffect.inPosition()->fName,
76 args.fTransformsIn, 76 args.fTransformsIn,
77 args.fTransformsOut); 77 args.fTransformsOut);
78 78
79 // add varyings 79 // add varyings
80 GrGLSLVertToFrag recipScale(kFloat_GrSLType); 80 GrGLSLVertToFrag recipScale(kFloat_GrSLType);
81 GrGLSLVertToFrag uv(kVec2f_GrSLType); 81 GrGLSLVertToFrag uv(kVec2f_GrSLType);
82 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) == 82 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) ==
83 kUniformScale_DistanceFieldEffectMask; 83 kUniformScale_DistanceFieldEffectMask;
84 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); 84 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag);
85 bool srgbOutput = SkToBool(dfTexEffect.getFlags() & kSRGB_DistanceFieldE ffectFlag); 85 bool isGammaCorrect =
86 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF lag);
86 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); 87 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
87 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo ords()->fName); 88 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo ords()->fName);
88 89
89 // compute numbers to be hardcoded to convert texture coordinates from f loat to int 90 // compute numbers to be hardcoded to convert texture coordinates from f loat to int
90 SkASSERT(dfTexEffect.numTextures() == 1); 91 SkASSERT(dfTexEffect.numTextures() == 1);
91 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); 92 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture();
92 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ; 93 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ;
93 94
94 GrGLSLVertToFrag st(kVec2f_GrSLType); 95 GrGLSLVertToFrag st(kVec2f_GrSLType);
95 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ; 96 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,"); 152 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,");
152 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);"); 153 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);");
153 154
154 // this gives us a smooth step across approximately one fragment 155 // this gives us a smooth step across approximately one fragment
155 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);"); 156 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);");
156 } 157 }
157 158
158 // The smoothstep falloff compensates for the non-linear sRGB response c urve. If we are 159 // The smoothstep falloff compensates for the non-linear sRGB response c urve. If we are
159 // doing gamma-correct rendering (to an sRGB or F16 buffer), then we act ually want distance 160 // doing gamma-correct rendering (to an sRGB or F16 buffer), then we act ually want distance
160 // mapped linearly to coverage, so use a linear step: 161 // mapped linearly to coverage, so use a linear step:
161 if (srgbOutput) { 162 if (isGammaCorrect) {
162 fragBuilder->codeAppend( 163 fragBuilder->codeAppend(
163 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1. 0);"); 164 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1. 0);");
164 } else { 165 } else {
165 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d istance);"); 166 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d istance);");
166 } 167 }
167 168
168 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 169 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
169 } 170 }
170 171
171 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override { 172 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 uniformHandler, 557 uniformHandler,
557 gpArgs->fPositionVar, 558 gpArgs->fPositionVar,
558 dfTexEffect.inPosition()->fName, 559 dfTexEffect.inPosition()->fName,
559 args.fTransformsIn, 560 args.fTransformsIn,
560 args.fTransformsOut); 561 args.fTransformsOut);
561 562
562 // set up varyings 563 // set up varyings
563 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) == 564 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi eldEffectMask) ==
564 kUniformScale_DistanceFieldEffectMask; 565 kUniformScale_DistanceFieldEffectMask;
565 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); 566 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag);
566 bool srgbOutput = SkToBool(dfTexEffect.getFlags() & kSRGB_DistanceFieldE ffectFlag); 567 bool isGammaCorrect =
568 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF lag);
567 GrGLSLVertToFrag recipScale(kFloat_GrSLType); 569 GrGLSLVertToFrag recipScale(kFloat_GrSLType);
568 GrGLSLVertToFrag uv(kVec2f_GrSLType); 570 GrGLSLVertToFrag uv(kVec2f_GrSLType);
569 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); 571 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
570 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo ords()->fName); 572 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo ords()->fName);
571 573
572 // compute numbers to be hardcoded to convert texture coordinates from f loat to int 574 // compute numbers to be hardcoded to convert texture coordinates from f loat to int
573 SkASSERT(dfTexEffect.numTextures() == 1); 575 SkASSERT(dfTexEffect.numTextures() == 1);
574 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); 576 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture();
575 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ; 577 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ;
576 578
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,"); 676 fragBuilder->codeAppend("vec2 grad = vec2(dist_grad.x*Jdx.x + dist_g rad.y*Jdy.x,");
675 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);"); 677 fragBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_g rad.y*Jdy.y);");
676 678
677 // this gives us a smooth step across approximately one fragment 679 // this gives us a smooth step across approximately one fragment
678 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);"); 680 fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*leng th(grad);");
679 } 681 }
680 682
681 // The smoothstep falloff compensates for the non-linear sRGB response c urve. If we are 683 // The smoothstep falloff compensates for the non-linear sRGB response c urve. If we are
682 // doing gamma-correct rendering (to an sRGB or F16 buffer), then we act ually want distance 684 // doing gamma-correct rendering (to an sRGB or F16 buffer), then we act ually want distance
683 // mapped linearly to coverage, so use a linear step: 685 // mapped linearly to coverage, so use a linear step:
684 if (srgbOutput) { 686 if (isGammaCorrect) {
685 fragBuilder->codeAppend("vec4 val = " 687 fragBuilder->codeAppend("vec4 val = "
686 "vec4(clamp(distance + vec3(afwidth) / vec3(2.0 * afwidth), 0.0, 1.0), 1.0f);"); 688 "vec4(clamp(distance + vec3(afwidth) / vec3(2.0 * afwidth), 0.0, 1.0), 1.0f);");
687 } else { 689 } else {
688 fragBuilder->codeAppend( 690 fragBuilder->codeAppend(
689 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), dista nce), 1.0);"); 691 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), dista nce), 1.0);");
690 } 692 }
691 693
692 // set alpha to be max of rgb coverage 694 // set alpha to be max of rgb coverage
693 fragBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);"); 695 fragBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);");
694 696
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ; 805 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0 ;
804 } 806 }
805 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 807 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
806 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), 808 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom),
807 GrTest::TestMatrix(d->fRandom), 809 GrTest::TestMatrix(d->fRandom),
808 d->fTextures[texIdx], params, 810 d->fTextures[texIdx], params,
809 wa, 811 wa,
810 flags, 812 flags,
811 d->fRandom->nextBool()); 813 d->fRandom->nextBool());
812 } 814 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698