OLD | NEW |
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" | |
15 #include "gl/GrGLTexture.h" | |
16 #include "gl/GrGLGeometryProcessor.h" | 14 #include "gl/GrGLGeometryProcessor.h" |
| 15 #include "glsl/GrGLSLFragmentProcessor.h" |
17 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 16 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
18 #include "glsl/GrGLSLProgramBuilder.h" | 17 #include "glsl/GrGLSLProgramBuilder.h" |
19 #include "glsl/GrGLSLProgramDataManager.h" | 18 #include "glsl/GrGLSLProgramDataManager.h" |
20 #include "glsl/GrGLSLVertexShaderBuilder.h" | 19 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 20 #include "glsl/GrGLSLUtil.h" |
21 | 21 |
22 // Assuming a radius of a little less than the diagonal of the fragment | 22 // Assuming a radius of a little less than the diagonal of the fragment |
23 #define SK_DistanceFieldAAFactor "0.65" | 23 #define SK_DistanceFieldAAFactor "0.65" |
24 | 24 |
25 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { | 25 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { |
26 public: | 26 public: |
27 GrGLDistanceFieldA8TextGeoProc() | 27 GrGLDistanceFieldA8TextGeoProc() |
28 : fViewMatrix(SkMatrix::InvalidMatrix()) | 28 : fViewMatrix(SkMatrix::InvalidMatrix()) |
29 , fColor(GrColor_ILLEGAL) | 29 , fColor(GrColor_ILLEGAL) |
30 #ifdef SK_GAMMA_APPLY_TO_A8 | 30 #ifdef SK_GAMMA_APPLY_TO_A8 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 if (distanceAdjust != fDistanceAdjust) { | 153 if (distanceAdjust != fDistanceAdjust) { |
154 pdman.set1f(fDistanceAdjustUni, distanceAdjust); | 154 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
155 fDistanceAdjust = distanceAdjust; | 155 fDistanceAdjust = distanceAdjust; |
156 } | 156 } |
157 #endif | 157 #endif |
158 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); | 158 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); |
159 | 159 |
160 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g
p.viewMatrix())) { | 160 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g
p.viewMatrix())) { |
161 fViewMatrix = dfa8gp.viewMatrix(); | 161 fViewMatrix = dfa8gp.viewMatrix(); |
162 float viewMatrix[3 * 3]; | 162 float viewMatrix[3 * 3]; |
163 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 163 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
164 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 164 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
165 } | 165 } |
166 | 166 |
167 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { | 167 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { |
168 float c[4]; | 168 float c[4]; |
169 GrColorToRGBAFloat(dfa8gp.color(), c); | 169 GrColorToRGBAFloat(dfa8gp.color(), c); |
170 pdman.set4fv(fColorUniform, 1, c); | 170 pdman.set4fv(fColorUniform, 1, c); |
171 fColor = dfa8gp.color(); | 171 fColor = dfa8gp.color(); |
172 } | 172 } |
173 } | 173 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 pdman.set2f(fTextureSizeUni, | 383 pdman.set2f(fTextureSizeUni, |
384 SkIntToScalar(fTextureSize.width()), | 384 SkIntToScalar(fTextureSize.width()), |
385 SkIntToScalar(fTextureSize.height())); | 385 SkIntToScalar(fTextureSize.height())); |
386 } | 386 } |
387 | 387 |
388 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); | 388 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); |
389 | 389 |
390 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.
viewMatrix())) { | 390 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.
viewMatrix())) { |
391 fViewMatrix = dfpgp.viewMatrix(); | 391 fViewMatrix = dfpgp.viewMatrix(); |
392 float viewMatrix[3 * 3]; | 392 float viewMatrix[3 * 3]; |
393 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 393 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
394 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 394 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
395 } | 395 } |
396 | 396 |
397 if (dfpgp.color() != fColor) { | 397 if (dfpgp.color() != fColor) { |
398 float c[4]; | 398 float c[4]; |
399 GrColorToRGBAFloat(dfpgp.color(), c); | 399 GrColorToRGBAFloat(dfpgp.color(), c); |
400 pdman.set4fv(fColorUniform, 1, c); | 400 pdman.set4fv(fColorUniform, 1, c); |
401 fColor = dfpgp.color(); | 401 fColor = dfpgp.color(); |
402 } | 402 } |
403 } | 403 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 pdman.set3f(fDistanceAdjustUni, | 652 pdman.set3f(fDistanceAdjustUni, |
653 wa.fR, | 653 wa.fR, |
654 wa.fG, | 654 wa.fG, |
655 wa.fB); | 655 wa.fB); |
656 fDistanceAdjust = wa; | 656 fDistanceAdjust = wa; |
657 } | 657 } |
658 | 658 |
659 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.
viewMatrix())) { | 659 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.
viewMatrix())) { |
660 fViewMatrix = dflcd.viewMatrix(); | 660 fViewMatrix = dflcd.viewMatrix(); |
661 float viewMatrix[3 * 3]; | 661 float viewMatrix[3 * 3]; |
662 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 662 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
663 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 663 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
664 } | 664 } |
665 | 665 |
666 if (dflcd.color() != fColor) { | 666 if (dflcd.color() != fColor) { |
667 float c[4]; | 667 float c[4]; |
668 GrColorToRGBAFloat(dflcd.color(), c); | 668 GrColorToRGBAFloat(dflcd.color(), c); |
669 pdman.set4fv(fColorUniform, 1, c); | 669 pdman.set4fv(fColorUniform, 1, c); |
670 fColor = dflcd.color(); | 670 fColor = dflcd.color(); |
671 } | 671 } |
672 } | 672 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 753 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
754 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 754 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
755 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 755 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
756 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 756 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
757 GrTest::TestMatrix(d->fRandom), | 757 GrTest::TestMatrix(d->fRandom), |
758 d->fTextures[texIdx], params, | 758 d->fTextures[texIdx], params, |
759 wa, | 759 wa, |
760 flags, | 760 flags, |
761 d->fRandom->nextBool()); | 761 d->fRandom->nextBool()); |
762 } | 762 } |
OLD | NEW |