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 "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
9 | 9 |
10 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
11 #include "glsl/GrGLSLGeometryProcessor.h" | 11 #include "glsl/GrGLSLGeometryProcessor.h" |
12 #include "glsl/GrGLSLProgramDataManager.h" | 12 #include "glsl/GrGLSLProgramDataManager.h" |
13 #include "glsl/GrGLSLUniformHandler.h" | 13 #include "glsl/GrGLSLUniformHandler.h" |
14 #include "glsl/GrGLSLUtil.h" | 14 #include "glsl/GrGLSLUtil.h" |
15 #include "glsl/GrGLSLVarying.h" | 15 #include "glsl/GrGLSLVarying.h" |
16 #include "glsl/GrGLSLVertexShaderBuilder.h" | 16 #include "glsl/GrGLSLVertexShaderBuilder.h" |
17 | 17 |
18 class GrGLConicEffect : public GrGLSLGeometryProcessor { | 18 class GrGLConicEffect : public GrGLSLGeometryProcessor { |
19 public: | 19 public: |
20 GrGLConicEffect(const GrGeometryProcessor&); | 20 GrGLConicEffect(const GrGeometryProcessor&); |
21 | 21 |
22 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 22 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
23 | 23 |
24 static inline void GenKey(const GrGeometryProcessor&, | 24 static inline void GenKey(const GrGeometryProcessor&, |
25 const GrGLSLCaps&, | 25 const GrGLSLCaps&, |
26 GrProcessorKeyBuilder*); | 26 GrProcessorKeyBuilder*); |
27 | 27 |
28 void setData(const GrGLSLProgramDataManager& pdman, | 28 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& primProc, |
29 const GrPrimitiveProcessor& primProc) override { | 29 FPCoordTransformIter&& transformIter) override { |
30 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); | 30 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); |
31 | 31 |
32 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { | 32 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { |
33 fViewMatrix = ce.viewMatrix(); | 33 fViewMatrix = ce.viewMatrix(); |
34 float viewMatrix[3 * 3]; | 34 float viewMatrix[3 * 3]; |
35 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 35 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
36 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 36 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
37 } | 37 } |
38 | 38 |
39 if (ce.color() != fColor) { | 39 if (ce.color() != fColor) { |
40 float c[4]; | 40 float c[4]; |
41 GrColorToRGBAFloat(ce.color(), c); | 41 GrColorToRGBAFloat(ce.color(), c); |
42 pdman.set4fv(fColorUniform, 1, c); | 42 pdman.set4fv(fColorUniform, 1, c); |
43 fColor = ce.color(); | 43 fColor = ce.color(); |
44 } | 44 } |
45 | 45 |
46 if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale)
{ | 46 if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale)
{ |
47 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverag
eScale())); | 47 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverag
eScale())); |
48 fCoverageScale = ce.coverageScale(); | 48 fCoverageScale = ce.coverageScale(); |
49 } | 49 } |
50 } | 50 this->setTransformDataHelper(ce.localMatrix(), pdman, &transformIter); |
51 | |
52 void setTransformData(const GrPrimitiveProcessor& primProc, | |
53 const GrGLSLProgramDataManager& pdman, | |
54 int index, | |
55 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | |
56 this->setTransformDataHelper(primProc.cast<GrConicEffect>().localMatrix(
), pdman, index, | |
57 transforms); | |
58 } | 51 } |
59 | 52 |
60 private: | 53 private: |
61 SkMatrix fViewMatrix; | 54 SkMatrix fViewMatrix; |
62 GrColor fColor; | 55 GrColor fColor; |
63 uint8_t fCoverageScale; | 56 uint8_t fCoverageScale; |
64 GrPrimitiveEdgeType fEdgeType; | 57 GrPrimitiveEdgeType fEdgeType; |
65 UniformHandle fColorUniform; | 58 UniformHandle fColorUniform; |
66 UniformHandle fCoverageScaleUniform; | 59 UniformHandle fCoverageScaleUniform; |
67 UniformHandle fViewMatrixUniform; | 60 UniformHandle fViewMatrixUniform; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 gp.viewMatrix(), | 95 gp.viewMatrix(), |
103 &fViewMatrixUniform); | 96 &fViewMatrixUniform); |
104 | 97 |
105 // emit transforms with position | 98 // emit transforms with position |
106 this->emitTransforms(vertBuilder, | 99 this->emitTransforms(vertBuilder, |
107 varyingHandler, | 100 varyingHandler, |
108 uniformHandler, | 101 uniformHandler, |
109 gpArgs->fPositionVar, | 102 gpArgs->fPositionVar, |
110 gp.inPosition()->fName, | 103 gp.inPosition()->fName, |
111 gp.localMatrix(), | 104 gp.localMatrix(), |
112 args.fTransformsIn, | 105 args.fFPCoordTransformHandler); |
113 args.fTransformsOut); | |
114 | 106 |
115 // TODO: this precision check should actually be a check on the number of bi
ts | 107 // TODO: this precision check should actually be a check on the number of bi
ts |
116 // high and medium provide and the selection of the lowest level that suffic
es. | 108 // high and medium provide and the selection of the lowest level that suffic
es. |
117 // Additionally we should assert that the upstream code only lets us get her
e if | 109 // Additionally we should assert that the upstream code only lets us get her
e if |
118 // either high or medium provides the required number of bits. | 110 // either high or medium provides the required number of bits. |
119 GrSLPrecision precision = kHigh_GrSLPrecision; | 111 GrSLPrecision precision = kHigh_GrSLPrecision; |
120 const GrShaderCaps::PrecisionInfo& highP = args.fGLSLCaps->getFloatShaderPre
cisionInfo( | 112 const GrShaderCaps::PrecisionInfo& highP = args.fGLSLCaps->getFloatShaderPre
cisionInfo( |
121 kFragment_GrShaderT
ype, | 113 kFragment_GrShaderT
ype, |
122 kHigh_GrSLPrecision
); | 114 kHigh_GrSLPrecision
); |
123 if (!highP.supported()) { | 115 if (!highP.supported()) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 class GrGLQuadEffect : public GrGLSLGeometryProcessor { | 284 class GrGLQuadEffect : public GrGLSLGeometryProcessor { |
293 public: | 285 public: |
294 GrGLQuadEffect(const GrGeometryProcessor&); | 286 GrGLQuadEffect(const GrGeometryProcessor&); |
295 | 287 |
296 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 288 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
297 | 289 |
298 static inline void GenKey(const GrGeometryProcessor&, | 290 static inline void GenKey(const GrGeometryProcessor&, |
299 const GrGLSLCaps&, | 291 const GrGLSLCaps&, |
300 GrProcessorKeyBuilder*); | 292 GrProcessorKeyBuilder*); |
301 | 293 |
302 void setData(const GrGLSLProgramDataManager& pdman, | 294 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& primProc, |
303 const GrPrimitiveProcessor& primProc) override { | 295 FPCoordTransformIter&& transformIter) override { |
304 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); | 296 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); |
305 | 297 |
306 if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMa
trix())) { | 298 if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMa
trix())) { |
307 fViewMatrix = qe.viewMatrix(); | 299 fViewMatrix = qe.viewMatrix(); |
308 float viewMatrix[3 * 3]; | 300 float viewMatrix[3 * 3]; |
309 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 301 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
310 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 302 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
311 } | 303 } |
312 | 304 |
313 if (qe.color() != fColor) { | 305 if (qe.color() != fColor) { |
314 float c[4]; | 306 float c[4]; |
315 GrColorToRGBAFloat(qe.color(), c); | 307 GrColorToRGBAFloat(qe.color(), c); |
316 pdman.set4fv(fColorUniform, 1, c); | 308 pdman.set4fv(fColorUniform, 1, c); |
317 fColor = qe.color(); | 309 fColor = qe.color(); |
318 } | 310 } |
319 | 311 |
320 if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale)
{ | 312 if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale)
{ |
321 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverag
eScale())); | 313 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverag
eScale())); |
322 fCoverageScale = qe.coverageScale(); | 314 fCoverageScale = qe.coverageScale(); |
323 } | 315 } |
324 } | 316 this->setTransformDataHelper(qe.localMatrix(), pdman, &transformIter); |
325 | |
326 void setTransformData(const GrPrimitiveProcessor& primProc, | |
327 const GrGLSLProgramDataManager& pdman, | |
328 int index, | |
329 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | |
330 this->setTransformDataHelper(primProc.cast<GrQuadEffect>().localMatrix()
, pdman, index, | |
331 transforms); | |
332 } | 317 } |
333 | 318 |
334 private: | 319 private: |
335 SkMatrix fViewMatrix; | 320 SkMatrix fViewMatrix; |
336 GrColor fColor; | 321 GrColor fColor; |
337 uint8_t fCoverageScale; | 322 uint8_t fCoverageScale; |
338 GrPrimitiveEdgeType fEdgeType; | 323 GrPrimitiveEdgeType fEdgeType; |
339 UniformHandle fColorUniform; | 324 UniformHandle fColorUniform; |
340 UniformHandle fCoverageScaleUniform; | 325 UniformHandle fCoverageScaleUniform; |
341 UniformHandle fViewMatrixUniform; | 326 UniformHandle fViewMatrixUniform; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 gp.viewMatrix(), | 361 gp.viewMatrix(), |
377 &fViewMatrixUniform); | 362 &fViewMatrixUniform); |
378 | 363 |
379 // emit transforms with position | 364 // emit transforms with position |
380 this->emitTransforms(vertBuilder, | 365 this->emitTransforms(vertBuilder, |
381 varyingHandler, | 366 varyingHandler, |
382 uniformHandler, | 367 uniformHandler, |
383 gpArgs->fPositionVar, | 368 gpArgs->fPositionVar, |
384 gp.inPosition()->fName, | 369 gp.inPosition()->fName, |
385 gp.localMatrix(), | 370 gp.localMatrix(), |
386 args.fTransformsIn, | 371 args.fFPCoordTransformHandler); |
387 args.fTransformsOut); | |
388 | 372 |
389 fragBuilder->codeAppendf("float edgeAlpha;"); | 373 fragBuilder->codeAppendf("float edgeAlpha;"); |
390 | 374 |
391 switch (fEdgeType) { | 375 switch (fEdgeType) { |
392 case kHairlineAA_GrProcessorEdgeType: { | 376 case kHairlineAA_GrProcessorEdgeType: { |
393 SkAssertResult(fragBuilder->enableFeature( | 377 SkAssertResult(fragBuilder->enableFeature( |
394 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | 378 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); |
395 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); | 379 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
396 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); | 380 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
397 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," | 381 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 class GrGLCubicEffect : public GrGLSLGeometryProcessor { | 493 class GrGLCubicEffect : public GrGLSLGeometryProcessor { |
510 public: | 494 public: |
511 GrGLCubicEffect(const GrGeometryProcessor&); | 495 GrGLCubicEffect(const GrGeometryProcessor&); |
512 | 496 |
513 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 497 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
514 | 498 |
515 static inline void GenKey(const GrGeometryProcessor&, | 499 static inline void GenKey(const GrGeometryProcessor&, |
516 const GrGLSLCaps&, | 500 const GrGLSLCaps&, |
517 GrProcessorKeyBuilder*); | 501 GrProcessorKeyBuilder*); |
518 | 502 |
519 void setData(const GrGLSLProgramDataManager& pdman, | 503 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& primProc, |
520 const GrPrimitiveProcessor& primProc) override { | 504 FPCoordTransformIter&& transformIter) override { |
521 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); | 505 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); |
522 | 506 |
523 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { | 507 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { |
524 fViewMatrix = ce.viewMatrix(); | 508 fViewMatrix = ce.viewMatrix(); |
525 float viewMatrix[3 * 3]; | 509 float viewMatrix[3 * 3]; |
526 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 510 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
527 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 511 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
528 } | 512 } |
529 | 513 |
530 if (ce.color() != fColor) { | 514 if (ce.color() != fColor) { |
531 float c[4]; | 515 float c[4]; |
532 GrColorToRGBAFloat(ce.color(), c); | 516 GrColorToRGBAFloat(ce.color(), c); |
533 pdman.set4fv(fColorUniform, 1, c); | 517 pdman.set4fv(fColorUniform, 1, c); |
534 fColor = ce.color(); | 518 fColor = ce.color(); |
535 } | 519 } |
| 520 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
536 } | 521 } |
537 | 522 |
538 private: | 523 private: |
539 SkMatrix fViewMatrix; | 524 SkMatrix fViewMatrix; |
540 GrColor fColor; | 525 GrColor fColor; |
541 GrPrimitiveEdgeType fEdgeType; | 526 GrPrimitiveEdgeType fEdgeType; |
542 UniformHandle fColorUniform; | 527 UniformHandle fColorUniform; |
543 UniformHandle fViewMatrixUniform; | 528 UniformHandle fViewMatrixUniform; |
544 | 529 |
545 typedef GrGLSLGeometryProcessor INHERITED; | 530 typedef GrGLSLGeometryProcessor INHERITED; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 gp.inPosition()->fName, | 562 gp.inPosition()->fName, |
578 gp.viewMatrix(), | 563 gp.viewMatrix(), |
579 &fViewMatrixUniform); | 564 &fViewMatrixUniform); |
580 | 565 |
581 // emit transforms with position | 566 // emit transforms with position |
582 this->emitTransforms(vertBuilder, | 567 this->emitTransforms(vertBuilder, |
583 varyingHandler, | 568 varyingHandler, |
584 uniformHandler, | 569 uniformHandler, |
585 gpArgs->fPositionVar, | 570 gpArgs->fPositionVar, |
586 gp.inPosition()->fName, | 571 gp.inPosition()->fName, |
587 args.fTransformsIn, | 572 args.fFPCoordTransformHandler); |
588 args.fTransformsOut); | |
589 | 573 |
590 | 574 |
591 GrGLSLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecisi
on); | 575 GrGLSLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecisi
on); |
592 GrGLSLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); | 576 GrGLSLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); |
593 GrGLSLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); | 577 GrGLSLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); |
594 GrGLSLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 578 GrGLSLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
595 GrGLSLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 579 GrGLSLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
596 GrGLSLShaderVar gF("gF", kVec2f_GrSLType, 0, kHigh_GrSLPrecision); | 580 GrGLSLShaderVar gF("gF", kVec2f_GrSLType, 0, kHigh_GrSLPrecision); |
597 GrGLSLShaderVar gFM("gFM", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 581 GrGLSLShaderVar gFM("gFM", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
598 GrGLSLShaderVar func("func", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 582 GrGLSLShaderVar func("func", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 sk_sp<GrGeometryProcessor> gp; | 703 sk_sp<GrGeometryProcessor> gp; |
720 do { | 704 do { |
721 GrPrimitiveEdgeType edgeType = | 705 GrPrimitiveEdgeType edgeType = |
722 static_cast<GrPrimitiveEdgeType>( | 706 static_cast<GrPrimitiveEdgeType>( |
723 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 707 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
724 gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), | 708 gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), |
725 GrTest::TestMatrix(d->fRandom), edgeType, *d->f
Caps); | 709 GrTest::TestMatrix(d->fRandom), edgeType, *d->f
Caps); |
726 } while (nullptr == gp); | 710 } while (nullptr == gp); |
727 return gp; | 711 return gp; |
728 } | 712 } |
OLD | NEW |