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

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

Issue 1713693002: Use unorm shorts for texture coordinates when rendering text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix tabbing Created 4 years, 10 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/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/gl/GrGLVertexArray.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 this->emitTransforms(vertBuilder, 71 this->emitTransforms(vertBuilder,
72 varyingHandler, 72 varyingHandler,
73 uniformHandler, 73 uniformHandler,
74 gpArgs->fPositionVar, 74 gpArgs->fPositionVar,
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 st(kVec2f_GrSLType); 81 GrGLSLVertToFrag uv(kVec2f_GrSLType);
82 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag); 82 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan ceFieldEffectFlag);
83 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ; 83 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
84 vertBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCo ords()->fName); 84 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo ords()->fName);
85 85
86 // compute numbers to be hardcoded to convert texture coordinates from i nt to float 86 // compute numbers to be hardcoded to convert texture coordinates from i nt to float
87 SkASSERT(dfTexEffect.numTextures() == 1); 87 SkASSERT(dfTexEffect.numTextures() == 1);
88 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); 88 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture();
89 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ; 89 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ;
90 SkScalar recipWidth = 1.0f / atlas->width();
91 SkScalar recipHeight = 1.0f / atlas->height();
92 90
93 GrGLSLVertToFrag uv(kVec2f_GrSLType); 91 GrGLSLVertToFrag st(kVec2f_GrSLType);
94 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); 92 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ;
95 vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), 93 vertBuilder->codeAppendf("%s = vec2(%d, %d) * %s;", st.vsOut(),
96 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, 94 atlas->width(), atlas->height(),
97 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight,
98 dfTexEffect.inTextureCoords()->fName); 95 dfTexEffect.inTextureCoords()->fName);
99 96
100 // Use highp to work around aliasing issues 97 // Use highp to work around aliasing issues
101 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 98 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
102 kHigh_GrSLPreci sion)); 99 kHigh_GrSLPreci sion));
103 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 100 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
104 101
105 fragBuilder->codeAppend("\tfloat texColor = "); 102 fragBuilder->codeAppend("\tfloat texColor = ");
106 fragBuilder->appendTextureLookup(args.fSamplers[0], 103 fragBuilder->appendTextureLookup(args.fSamplers[0],
107 "uv", 104 "uv",
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 #endif 214 #endif
218 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) 215 , fFlags(flags & kNonLCD_DistanceFieldEffectMask)
219 , fInColor(nullptr) 216 , fInColor(nullptr)
220 , fUsesLocalCoords(usesLocalCoords) { 217 , fUsesLocalCoords(usesLocalCoords) {
221 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); 218 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
222 this->initClassID<GrDistanceFieldA8TextGeoProc>(); 219 this->initClassID<GrDistanceFieldA8TextGeoProc>();
223 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, 220 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType,
224 kHigh_GrSLPrecision)); 221 kHigh_GrSLPrecision));
225 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri bType)); 222 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri bType));
226 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 223 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
227 kVec2s_GrVertexAttribT ype)); 224 kVec2us_GrVertexAttribTy pe,
225 kHigh_GrSLPrecision));
228 this->addTextureAccess(&fTextureAccess); 226 this->addTextureAccess(&fTextureAccess);
229 } 227 }
230 228
231 void GrDistanceFieldA8TextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, 229 void GrDistanceFieldA8TextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps,
232 GrProcessorKeyBuilder* b) const { 230 GrProcessorKeyBuilder* b) const {
233 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); 231 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b);
234 } 232 }
235 233
236 GrGLSLPrimitiveProcessor* GrDistanceFieldA8TextGeoProc::createGLSLInstance(const GrGLSLCaps&) const { 234 GrGLSLPrimitiveProcessor* GrDistanceFieldA8TextGeoProc::createGLSLInstance(const GrGLSLCaps&) const {
237 return new GrGLDistanceFieldA8TextGeoProc(); 235 return new GrGLDistanceFieldA8TextGeoProc();
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 varyingHandler, 513 varyingHandler,
516 uniformHandler, 514 uniformHandler,
517 gpArgs->fPositionVar, 515 gpArgs->fPositionVar,
518 dfTexEffect.inPosition()->fName, 516 dfTexEffect.inPosition()->fName,
519 args.fTransformsIn, 517 args.fTransformsIn,
520 args.fTransformsOut); 518 args.fTransformsOut);
521 519
522 // set up varyings 520 // set up varyings
523 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di stanceFieldEffectMask); 521 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di stanceFieldEffectMask);
524 GrGLSLVertToFrag recipScale(kFloat_GrSLType); 522 GrGLSLVertToFrag recipScale(kFloat_GrSLType);
525 GrGLSLVertToFrag st(kVec2f_GrSLType); 523 GrGLSLVertToFrag uv(kVec2f_GrSLType);
526 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ; 524 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
527 vertBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCo ords()->fName); 525 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo ords()->fName);
528 526
529 // compute numbers to be hardcoded to convert texture coordinates from i nt to float 527 // compute numbers to be hardcoded to convert texture coordinates from i nt to float
530 SkASSERT(dfTexEffect.numTextures() == 1); 528 SkASSERT(dfTexEffect.numTextures() == 1);
531 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); 529 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture();
532 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ; 530 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height())) ;
533 SkScalar recipWidth = 1.0f / atlas->width();
534 SkScalar recipHeight = 1.0f / atlas->height();
535 531
536 GrGLSLVertToFrag uv(kVec2f_GrSLType); 532 GrGLSLVertToFrag st(kVec2f_GrSLType);
537 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); 533 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision) ;
538 vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), 534 vertBuilder->codeAppendf("%s = vec2(%d, %d) * %s;", st.vsOut(),
539 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, 535 atlas->width(), atlas->height(),
540 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight,
541 dfTexEffect.inTextureCoords()->fName); 536 dfTexEffect.inTextureCoords()->fName);
542 537
543 // add frag shader code 538 // add frag shader code
544 539
545 SkAssertResult(fragBuilder->enableFeature( 540 SkAssertResult(fragBuilder->enableFeature(
546 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 541 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
547 542
548 // create LCD offset adjusted by inverse of transform 543 // create LCD offset adjusted by inverse of transform
549 // Use highp to work around aliasing issues 544 // Use highp to work around aliasing issues
550 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, 545 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 , fTextureAccess(texture, params) 696 , fTextureAccess(texture, params)
702 , fDistanceAdjust(distanceAdjust) 697 , fDistanceAdjust(distanceAdjust)
703 , fFlags(flags & kLCD_DistanceFieldEffectMask) 698 , fFlags(flags & kLCD_DistanceFieldEffectMask)
704 , fUsesLocalCoords(usesLocalCoords) { 699 , fUsesLocalCoords(usesLocalCoords) {
705 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); 700 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag));
706 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); 701 this->initClassID<GrDistanceFieldLCDTextGeoProc>();
707 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, 702 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType,
708 kHigh_GrSLPrecision)); 703 kHigh_GrSLPrecision));
709 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri bType)); 704 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri bType));
710 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 705 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
711 kVec2s_GrVertexAttribTyp e)); 706 kVec2us_GrVertexAttribTy pe,
707 kHigh_GrSLPrecision));
712 this->addTextureAccess(&fTextureAccess); 708 this->addTextureAccess(&fTextureAccess);
713 } 709 }
714 710
715 void GrDistanceFieldLCDTextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, 711 void GrDistanceFieldLCDTextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps,
716 GrProcessorKeyBuilder* b ) const { 712 GrProcessorKeyBuilder* b ) const {
717 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); 713 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b);
718 } 714 }
719 715
720 GrGLSLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLSLInstance(cons t GrGLSLCaps&) const { 716 GrGLSLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLSLInstance(cons t GrGLSLCaps&) const {
721 return new GrGLDistanceFieldLCDTextGeoProc(); 717 return new GrGLDistanceFieldLCDTextGeoProc();
(...skipping 21 matching lines...) Expand all
743 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 739 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
744 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 740 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
745 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 741 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
746 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), 742 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom),
747 GrTest::TestMatrix(d->fRandom), 743 GrTest::TestMatrix(d->fRandom),
748 d->fTextures[texIdx], params, 744 d->fTextures[texIdx], params,
749 wa, 745 wa,
750 flags, 746 flags,
751 d->fRandom->nextBool()); 747 d->fRandom->nextBool());
752 } 748 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/gl/GrGLVertexArray.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698