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 "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 class GrGLConicEffect : public GrGLGeometryProcessor { | 22 class GrGLConicEffect : public GrGLGeometryProcessor { |
23 public: | 23 public: |
24 GrGLConicEffect(const GrGeometryProcessor&, | 24 GrGLConicEffect(const GrGeometryProcessor&, |
25 const GrBatchTracker&); | 25 const GrBatchTracker&); |
26 | 26 |
27 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 27 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
28 | 28 |
29 static inline void GenKey(const GrGeometryProcessor&, | 29 static inline void GenKey(const GrGeometryProcessor&, |
30 const GrBatchTracker&, | 30 const GrBatchTracker&, |
31 const GrGLCaps&, | 31 const GrGLSLCaps&, |
32 GrProcessorKeyBuilder*); | 32 GrProcessorKeyBuilder*); |
33 | 33 |
34 virtual void setData(const GrGLProgramDataManager& pdman, | 34 virtual void setData(const GrGLProgramDataManager& pdman, |
35 const GrPrimitiveProcessor& primProc, | 35 const GrPrimitiveProcessor& primProc, |
36 const GrBatchTracker& bt) override { | 36 const GrBatchTracker& bt) override { |
37 this->setUniformViewMatrix(pdman, primProc.viewMatrix()); | 37 this->setUniformViewMatrix(pdman, primProc.viewMatrix()); |
38 | 38 |
39 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); | 39 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
40 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 40 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
41 GrGLfloat c[4]; | 41 GrGLfloat c[4]; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 "Coverage", | 155 "Coverage", |
156 &coverageScale); | 156 &coverageScale); |
157 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); | 157 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
158 } else { | 158 } else { |
159 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 159 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, | 163 void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, |
164 const GrBatchTracker& bt, | 164 const GrBatchTracker& bt, |
165 const GrGLCaps&, | 165 const GrGLSLCaps&, |
166 GrProcessorKeyBuilder* b) { | 166 GrProcessorKeyBuilder* b) { |
167 const GrConicEffect& ce = gp.cast<GrConicEffect>(); | 167 const GrConicEffect& ce = gp.cast<GrConicEffect>(); |
168 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); | 168 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
169 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 169 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
170 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; | 170 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
171 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; | 171 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
172 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 :
0x0; | 172 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 :
0x0; |
173 key |= ComputePosKey(gp.viewMatrix()) << 5; | 173 key |= ComputePosKey(gp.viewMatrix()) << 5; |
174 b->add32(key); | 174 b->add32(key); |
175 } | 175 } |
176 | 176 |
177 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
178 | 178 |
179 GrConicEffect::~GrConicEffect() {} | 179 GrConicEffect::~GrConicEffect() {} |
180 | 180 |
181 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 181 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
182 const GrGLCaps& caps, | 182 const GrGLSLCaps& caps, |
183 GrProcessorKeyBuilder* b) const { | 183 GrProcessorKeyBuilder* b) const { |
184 GrGLConicEffect::GenKey(*this, bt, caps, b); | 184 GrGLConicEffect::GenKey(*this, bt, caps, b); |
185 } | 185 } |
186 | 186 |
187 GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt
, | 187 GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt
, |
188 const GrGLCaps&) const { | 188 const GrGLSLCaps&) const
{ |
189 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); | 189 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
190 } | 190 } |
191 | 191 |
192 GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t
coverage, | 192 GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t
coverage, |
193 GrPrimitiveEdgeType edgeType, const SkMatrix& local
Matrix) | 193 GrPrimitiveEdgeType edgeType, const SkMatrix& local
Matrix) |
194 : INHERITED(color, viewMatrix, localMatrix) | 194 : INHERITED(color, viewMatrix, localMatrix) |
195 , fCoverageScale(coverage) | 195 , fCoverageScale(coverage) |
196 , fEdgeType(edgeType) { | 196 , fEdgeType(edgeType) { |
197 this->initClassID<GrConicEffect>(); | 197 this->initClassID<GrConicEffect>(); |
198 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 198 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 class GrGLQuadEffect : public GrGLGeometryProcessor { | 257 class GrGLQuadEffect : public GrGLGeometryProcessor { |
258 public: | 258 public: |
259 GrGLQuadEffect(const GrGeometryProcessor&, | 259 GrGLQuadEffect(const GrGeometryProcessor&, |
260 const GrBatchTracker&); | 260 const GrBatchTracker&); |
261 | 261 |
262 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 262 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
263 | 263 |
264 static inline void GenKey(const GrGeometryProcessor&, | 264 static inline void GenKey(const GrGeometryProcessor&, |
265 const GrBatchTracker&, | 265 const GrBatchTracker&, |
266 const GrGLCaps&, | 266 const GrGLSLCaps&, |
267 GrProcessorKeyBuilder*); | 267 GrProcessorKeyBuilder*); |
268 | 268 |
269 virtual void setData(const GrGLProgramDataManager& pdman, | 269 virtual void setData(const GrGLProgramDataManager& pdman, |
270 const GrPrimitiveProcessor& primProc, | 270 const GrPrimitiveProcessor& primProc, |
271 const GrBatchTracker& bt) override { | 271 const GrBatchTracker& bt) override { |
272 this->setUniformViewMatrix(pdman, primProc.viewMatrix()); | 272 this->setUniformViewMatrix(pdman, primProc.viewMatrix()); |
273 | 273 |
274 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); | 274 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
275 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 275 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
276 GrGLfloat c[4]; | 276 GrGLfloat c[4]; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 "Coverage", | 376 "Coverage", |
377 &coverageScale); | 377 &coverageScale); |
378 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); | 378 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
379 } else { | 379 } else { |
380 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 380 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, | 384 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, |
385 const GrBatchTracker& bt, | 385 const GrBatchTracker& bt, |
386 const GrGLCaps&, | 386 const GrGLSLCaps&, |
387 GrProcessorKeyBuilder* b) { | 387 GrProcessorKeyBuilder* b) { |
388 const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); | 388 const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); |
389 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); | 389 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
390 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 390 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
391 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; | 391 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
392 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; | 392 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
393 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 :
0x0; | 393 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 :
0x0; |
394 key |= ComputePosKey(gp.viewMatrix()) << 5; | 394 key |= ComputePosKey(gp.viewMatrix()) << 5; |
395 b->add32(key); | 395 b->add32(key); |
396 } | 396 } |
397 | 397 |
398 ////////////////////////////////////////////////////////////////////////////// | 398 ////////////////////////////////////////////////////////////////////////////// |
399 | 399 |
400 GrQuadEffect::~GrQuadEffect() {} | 400 GrQuadEffect::~GrQuadEffect() {} |
401 | 401 |
402 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, | 402 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
403 const GrGLCaps& caps, | 403 const GrGLSLCaps& caps, |
404 GrProcessorKeyBuilder* b) const { | 404 GrProcessorKeyBuilder* b) const { |
405 GrGLQuadEffect::GenKey(*this, bt, caps, b); | 405 GrGLQuadEffect::GenKey(*this, bt, caps, b); |
406 } | 406 } |
407 | 407 |
408 GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt, | 408 GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt, |
409 const GrGLCaps&) const { | 409 const GrGLSLCaps&) const
{ |
410 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); | 410 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
411 } | 411 } |
412 | 412 |
413 GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co
verage, | 413 GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co
verage, |
414 GrPrimitiveEdgeType edgeType, const SkMatrix& localMa
trix) | 414 GrPrimitiveEdgeType edgeType, const SkMatrix& localMa
trix) |
415 : INHERITED(color, viewMatrix, localMatrix) | 415 : INHERITED(color, viewMatrix, localMatrix) |
416 , fCoverageScale(coverage) | 416 , fCoverageScale(coverage) |
417 , fEdgeType(edgeType) { | 417 , fEdgeType(edgeType) { |
418 this->initClassID<GrQuadEffect>(); | 418 this->initClassID<GrQuadEffect>(); |
419 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 419 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 477 |
478 class GrGLCubicEffect : public GrGLGeometryProcessor { | 478 class GrGLCubicEffect : public GrGLGeometryProcessor { |
479 public: | 479 public: |
480 GrGLCubicEffect(const GrGeometryProcessor&, | 480 GrGLCubicEffect(const GrGeometryProcessor&, |
481 const GrBatchTracker&); | 481 const GrBatchTracker&); |
482 | 482 |
483 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 483 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
484 | 484 |
485 static inline void GenKey(const GrGeometryProcessor&, | 485 static inline void GenKey(const GrGeometryProcessor&, |
486 const GrBatchTracker&, | 486 const GrBatchTracker&, |
487 const GrGLCaps&, | 487 const GrGLSLCaps&, |
488 GrProcessorKeyBuilder*); | 488 GrProcessorKeyBuilder*); |
489 | 489 |
490 virtual void setData(const GrGLProgramDataManager& pdman, | 490 virtual void setData(const GrGLProgramDataManager& pdman, |
491 const GrPrimitiveProcessor& primProc, | 491 const GrPrimitiveProcessor& primProc, |
492 const GrBatchTracker& bt) override { | 492 const GrBatchTracker& bt) override { |
493 this->setUniformViewMatrix(pdman, primProc.viewMatrix()); | 493 this->setUniformViewMatrix(pdman, primProc.viewMatrix()); |
494 | 494 |
495 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); | 495 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
496 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 496 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
497 GrGLfloat c[4]; | 497 GrGLfloat c[4]; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 default: | 621 default: |
622 SkFAIL("Shouldn't get here"); | 622 SkFAIL("Shouldn't get here"); |
623 } | 623 } |
624 | 624 |
625 | 625 |
626 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); | 626 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); |
627 } | 627 } |
628 | 628 |
629 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, | 629 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, |
630 const GrBatchTracker& bt, | 630 const GrBatchTracker& bt, |
631 const GrGLCaps&, | 631 const GrGLSLCaps&, |
632 GrProcessorKeyBuilder* b) { | 632 GrProcessorKeyBuilder* b) { |
633 const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); | 633 const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); |
634 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); | 634 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
635 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 635 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
636 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; | 636 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; |
637 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 :
0x0; | 637 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 :
0x0; |
638 key |= ComputePosKey(gp.viewMatrix()) << 5; | 638 key |= ComputePosKey(gp.viewMatrix()) << 5; |
639 b->add32(key); | 639 b->add32(key); |
640 } | 640 } |
641 | 641 |
642 ////////////////////////////////////////////////////////////////////////////// | 642 ////////////////////////////////////////////////////////////////////////////// |
643 | 643 |
644 GrCubicEffect::~GrCubicEffect() {} | 644 GrCubicEffect::~GrCubicEffect() {} |
645 | 645 |
646 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 646 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
647 const GrGLCaps& caps, | 647 const GrGLSLCaps& caps, |
648 GrProcessorKeyBuilder* b) const { | 648 GrProcessorKeyBuilder* b) const { |
649 GrGLCubicEffect::GenKey(*this, bt, caps, b); | 649 GrGLCubicEffect::GenKey(*this, bt, caps, b); |
650 } | 650 } |
651 | 651 |
652 GrGLPrimitiveProcessor* GrCubicEffect::createGLInstance(const GrBatchTracker& bt
, | 652 GrGLPrimitiveProcessor* GrCubicEffect::createGLInstance(const GrBatchTracker& bt
, |
653 const GrGLCaps&) const { | 653 const GrGLSLCaps&) const
{ |
654 return SkNEW_ARGS(GrGLCubicEffect, (*this, bt)); | 654 return SkNEW_ARGS(GrGLCubicEffect, (*this, bt)); |
655 } | 655 } |
656 | 656 |
657 GrCubicEffect::GrCubicEffect(GrColor color, const SkMatrix& viewMatrix, | 657 GrCubicEffect::GrCubicEffect(GrColor color, const SkMatrix& viewMatrix, |
658 GrPrimitiveEdgeType edgeType) | 658 GrPrimitiveEdgeType edgeType) |
659 : INHERITED(color, viewMatrix), fEdgeType(edgeType) { | 659 : INHERITED(color, viewMatrix), fEdgeType(edgeType) { |
660 this->initClassID<GrCubicEffect>(); | 660 this->initClassID<GrCubicEffect>(); |
661 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 661 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
662 fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs", | 662 fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs", |
663 kVec4f_GrVertexAttribTyp
e)); | 663 kVec4f_GrVertexAttribTyp
e)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 GrGeometryProcessor* gp; | 696 GrGeometryProcessor* gp; |
697 do { | 697 do { |
698 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 698 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
699 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 699 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
700 gp = GrCubicEffect::Create(GrRandomColor(random), | 700 gp = GrCubicEffect::Create(GrRandomColor(random), |
701 GrProcessorUnitTest::TestMatrix(random), edge
Type, caps); | 701 GrProcessorUnitTest::TestMatrix(random), edge
Type, caps); |
702 } while (NULL == gp); | 702 } while (NULL == gp); |
703 return gp; | 703 return gp; |
704 } | 704 } |
705 | 705 |
OLD | NEW |