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

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

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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/GrDisableColorXP.cpp ('k') | src/gpu/effects/GrMatrixConvolutionEffect.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"
11 11
12 #include "SkDistanceFieldGen.h" 12 #include "SkDistanceFieldGen.h"
13 13
14 #include "gl/GrGLFragmentProcessor.h" 14 #include "gl/GrGLFragmentProcessor.h"
15 #include "gl/GrGLTexture.h" 15 #include "gl/GrGLTexture.h"
16 #include "gl/GrGLGeometryProcessor.h" 16 #include "gl/GrGLGeometryProcessor.h"
17 #include "gl/builders/GrGLProgramBuilder.h" 17 #include "gl/builders/GrGLProgramBuilder.h"
18 #include "glsl/GrGLSLProgramDataManager.h"
18 19
19 // Assuming a radius of a little less than the diagonal of the fragment 20 // Assuming a radius of a little less than the diagonal of the fragment
20 #define SK_DistanceFieldAAFactor "0.65" 21 #define SK_DistanceFieldAAFactor "0.65"
21 22
22 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { 23 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor {
23 public: 24 public:
24 GrGLDistanceFieldA8TextGeoProc() 25 GrGLDistanceFieldA8TextGeoProc()
25 : fViewMatrix(SkMatrix::InvalidMatrix()) 26 : fViewMatrix(SkMatrix::InvalidMatrix())
26 , fColor(GrColor_ILLEGAL) 27 , fColor(GrColor_ILLEGAL)
27 #ifdef SK_GAMMA_APPLY_TO_A8 28 #ifdef SK_GAMMA_APPLY_TO_A8
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);"); 137 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);");
137 138
138 // this gives us a smooth step across approximately one fragment 139 // this gives us a smooth step across approximately one fragment
139 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); 140 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);");
140 } 141 }
141 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); 142 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);");
142 143
143 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 144 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
144 } 145 }
145 146
146 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor & proc) override { 147 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override {
147 #ifdef SK_GAMMA_APPLY_TO_A8 148 #ifdef SK_GAMMA_APPLY_TO_A8
148 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi eldA8TextGeoProc>(); 149 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi eldA8TextGeoProc>();
149 float distanceAdjust = dfTexEffect.getDistanceAdjust(); 150 float distanceAdjust = dfTexEffect.getDistanceAdjust();
150 if (distanceAdjust != fDistanceAdjust) { 151 if (distanceAdjust != fDistanceAdjust) {
151 pdman.set1f(fDistanceAdjustUni, distanceAdjust); 152 pdman.set1f(fDistanceAdjustUni, distanceAdjust);
152 fDistanceAdjust = distanceAdjust; 153 fDistanceAdjust = distanceAdjust;
153 } 154 }
154 #endif 155 #endif
155 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8 TextGeoProc>(); 156 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8 TextGeoProc>();
156 157
157 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g p.viewMatrix())) { 158 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g p.viewMatrix())) {
158 fViewMatrix = dfa8gp.viewMatrix(); 159 fViewMatrix = dfa8gp.viewMatrix();
159 GrGLfloat viewMatrix[3 * 3]; 160 float viewMatrix[3 * 3];
160 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); 161 GrGLGetMatrix<3>(viewMatrix, fViewMatrix);
161 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); 162 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
162 } 163 }
163 164
164 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { 165 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) {
165 GrGLfloat c[4]; 166 float c[4];
166 GrColorToRGBAFloat(dfa8gp.color(), c); 167 GrColorToRGBAFloat(dfa8gp.color(), c);
167 pdman.set4fv(fColorUniform, 1, c); 168 pdman.set4fv(fColorUniform, 1, c);
168 fColor = dfa8gp.color(); 169 fColor = dfa8gp.color();
169 } 170 }
170 } 171 }
171 172
172 static inline void GenKey(const GrGeometryProcessor& gp, 173 static inline void GenKey(const GrGeometryProcessor& gp,
173 const GrGLSLCaps&, 174 const GrGLSLCaps&,
174 GrProcessorKeyBuilder* b) { 175 GrProcessorKeyBuilder* b) {
175 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel dA8TextGeoProc>(); 176 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel dA8TextGeoProc>();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);"); 364 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);");
364 365
365 // this gives us a smooth step across approximately one fragment 366 // this gives us a smooth step across approximately one fragment
366 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); 367 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);");
367 } 368 }
368 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); 369 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);");
369 370
370 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); 371 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
371 } 372 }
372 373
373 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor & proc) override { 374 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess or& proc) override {
374 SkASSERT(fTextureSizeUni.isValid()); 375 SkASSERT(fTextureSizeUni.isValid());
375 376
376 GrTexture* texture = proc.texture(0); 377 GrTexture* texture = proc.texture(0);
377 if (texture->width() != fTextureSize.width() || 378 if (texture->width() != fTextureSize.width() ||
378 texture->height() != fTextureSize.height()) { 379 texture->height() != fTextureSize.height()) {
379 fTextureSize = SkISize::Make(texture->width(), texture->height()); 380 fTextureSize = SkISize::Make(texture->width(), texture->height());
380 pdman.set2f(fTextureSizeUni, 381 pdman.set2f(fTextureSizeUni,
381 SkIntToScalar(fTextureSize.width()), 382 SkIntToScalar(fTextureSize.width()),
382 SkIntToScalar(fTextureSize.height())); 383 SkIntToScalar(fTextureSize.height()));
383 } 384 }
384 385
385 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG eoProc>(); 386 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG eoProc>();
386 387
387 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp. viewMatrix())) { 388 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp. viewMatrix())) {
388 fViewMatrix = dfpgp.viewMatrix(); 389 fViewMatrix = dfpgp.viewMatrix();
389 GrGLfloat viewMatrix[3 * 3]; 390 float viewMatrix[3 * 3];
390 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); 391 GrGLGetMatrix<3>(viewMatrix, fViewMatrix);
391 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); 392 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
392 } 393 }
393 394
394 if (dfpgp.color() != fColor) { 395 if (dfpgp.color() != fColor) {
395 GrGLfloat c[4]; 396 float c[4];
396 GrColorToRGBAFloat(dfpgp.color(), c); 397 GrColorToRGBAFloat(dfpgp.color(), c);
397 pdman.set4fv(fColorUniform, 1, c); 398 pdman.set4fv(fColorUniform, 1, c);
398 fColor = dfpgp.color(); 399 fColor = dfpgp.color();
399 } 400 }
400 } 401 }
401 402
402 static inline void GenKey(const GrGeometryProcessor& gp, 403 static inline void GenKey(const GrGeometryProcessor& gp,
403 const GrGLSLCaps&, 404 const GrGLSLCaps&,
404 GrProcessorKeyBuilder* b) { 405 GrProcessorKeyBuilder* b) {
405 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP athGeoProc>(); 406 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP athGeoProc>();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 633 }
633 634
634 fsBuilder->codeAppend( 635 fsBuilder->codeAppend(
635 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);"); 636 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);");
636 // set alpha to be max of rgb coverage 637 // set alpha to be max of rgb coverage
637 fsBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);"); 638 fsBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);");
638 639
639 fsBuilder->codeAppendf("%s = val;", args.fOutputCoverage); 640 fsBuilder->codeAppendf("%s = val;", args.fOutputCoverage);
640 } 641 }
641 642
642 void setData(const GrGLProgramDataManager& pdman, 643 void setData(const GrGLSLProgramDataManager& pdman,
643 const GrPrimitiveProcessor& processor) override { 644 const GrPrimitiveProcessor& processor) override {
644 SkASSERT(fDistanceAdjustUni.isValid()); 645 SkASSERT(fDistanceAdjustUni.isValid());
645 646
646 const GrDistanceFieldLCDTextGeoProc& dflcd = processor.cast<GrDistanceFi eldLCDTextGeoProc>(); 647 const GrDistanceFieldLCDTextGeoProc& dflcd = processor.cast<GrDistanceFi eldLCDTextGeoProc>();
647 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dflcd.getDistanceAdju st(); 648 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dflcd.getDistanceAdju st();
648 if (wa != fDistanceAdjust) { 649 if (wa != fDistanceAdjust) {
649 pdman.set3f(fDistanceAdjustUni, 650 pdman.set3f(fDistanceAdjustUni,
650 wa.fR, 651 wa.fR,
651 wa.fG, 652 wa.fG,
652 wa.fB); 653 wa.fB);
653 fDistanceAdjust = wa; 654 fDistanceAdjust = wa;
654 } 655 }
655 656
656 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd. viewMatrix())) { 657 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd. viewMatrix())) {
657 fViewMatrix = dflcd.viewMatrix(); 658 fViewMatrix = dflcd.viewMatrix();
658 GrGLfloat viewMatrix[3 * 3]; 659 float viewMatrix[3 * 3];
659 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); 660 GrGLGetMatrix<3>(viewMatrix, fViewMatrix);
660 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); 661 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
661 } 662 }
662 663
663 if (dflcd.color() != fColor) { 664 if (dflcd.color() != fColor) {
664 GrGLfloat c[4]; 665 float c[4];
665 GrColorToRGBAFloat(dflcd.color(), c); 666 GrColorToRGBAFloat(dflcd.color(), c);
666 pdman.set4fv(fColorUniform, 1, c); 667 pdman.set4fv(fColorUniform, 1, c);
667 fColor = dflcd.color(); 668 fColor = dflcd.color();
668 } 669 }
669 } 670 }
670 671
671 static inline void GenKey(const GrGeometryProcessor& gp, 672 static inline void GenKey(const GrGeometryProcessor& gp,
672 const GrGLSLCaps&, 673 const GrGLSLCaps&,
673 GrProcessorKeyBuilder* b) { 674 GrProcessorKeyBuilder* b) {
674 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie ldLCDTextGeoProc>(); 675 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie ldLCDTextGeoProc>();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 751 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
751 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 752 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
752 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 753 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
753 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), 754 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom),
754 GrTest::TestMatrix(d->fRandom), 755 GrTest::TestMatrix(d->fRandom),
755 d->fTextures[texIdx], params, 756 d->fTextures[texIdx], params,
756 wa, 757 wa,
757 flags, 758 flags,
758 d->fRandom->nextBool()); 759 d->fRandom->nextBool());
759 } 760 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDisableColorXP.cpp ('k') | src/gpu/effects/GrMatrixConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698