| 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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
| 9 | 9 |
| 10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } | 427 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
| 428 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 428 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 429 bool usesLocalCoords() const { return fUsesLocalCoords; } | 429 bool usesLocalCoords() const { return fUsesLocalCoords; } |
| 430 | 430 |
| 431 inline Mode getMode() const { return fMode; } | 431 inline Mode getMode() const { return fMode; } |
| 432 | 432 |
| 433 class GLProcessor : public GrGLGeometryProcessor { | 433 class GLProcessor : public GrGLGeometryProcessor { |
| 434 public: | 434 public: |
| 435 GLProcessor(const GrGeometryProcessor&, | 435 GLProcessor(const GrGeometryProcessor&, |
| 436 const GrBatchTracker&) | 436 const GrBatchTracker&) |
| 437 : fColor(GrColor_ILLEGAL) {} | 437 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) {} |
| 438 | 438 |
| 439 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 439 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 440 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>()
; | 440 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>()
; |
| 441 GrGLGPBuilder* pb = args.fPB; | 441 GrGLGPBuilder* pb = args.fPB; |
| 442 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 442 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 443 | 443 |
| 444 // emit attributes | 444 // emit attributes |
| 445 vsBuilder->emitAttributes(ee); | 445 vsBuilder->emitAttributes(ee); |
| 446 | 446 |
| 447 GrGLVertToFrag offsets0(kVec2f_GrSLType); | 447 GrGLVertToFrag offsets0(kVec2f_GrSLType); |
| 448 args.fPB->addVarying("EllipseOffsets0", &offsets0); | 448 args.fPB->addVarying("EllipseOffsets0", &offsets0); |
| 449 vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), | 449 vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
| 450 ee.inEllipseOffsets0()->fName); | 450 ee.inEllipseOffsets0()->fName); |
| 451 | 451 |
| 452 GrGLVertToFrag offsets1(kVec2f_GrSLType); | 452 GrGLVertToFrag offsets1(kVec2f_GrSLType); |
| 453 args.fPB->addVarying("EllipseOffsets1", &offsets1); | 453 args.fPB->addVarying("EllipseOffsets1", &offsets1); |
| 454 vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), | 454 vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
| 455 ee.inEllipseOffsets1()->fName); | 455 ee.inEllipseOffsets1()->fName); |
| 456 | 456 |
| 457 // setup pass through color | 457 // setup pass through color |
| 458 if (!ee.colorIgnored()) { | 458 if (!ee.colorIgnored()) { |
| 459 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 459 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 460 } | 460 } |
| 461 | 461 |
| 462 // Setup position | 462 // Setup position |
| 463 this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatri
x()); | 463 this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatri
x(), |
| 464 &fViewMatrixUniform); |
| 464 | 465 |
| 465 // emit transforms | 466 // emit transforms |
| 466 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, | 467 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, |
| 467 args.fTransformsIn, args.fTransformsOut); | 468 args.fTransformsIn, args.fTransformsOut); |
| 468 | 469 |
| 469 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 470 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
| 470 SkAssertResult(fsBuilder->enableFeature( | 471 SkAssertResult(fsBuilder->enableFeature( |
| 471 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)
); | 472 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)
); |
| 472 // for outer curve | 473 // for outer curve |
| 473 fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn()
); | 474 fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn()
); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 uint16_t key = ellipseEffect.getMode(); | 516 uint16_t key = ellipseEffect.getMode(); |
| 516 key |= ellipseEffect.colorIgnored() << 9; | 517 key |= ellipseEffect.colorIgnored() << 9; |
| 517 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10; | 518 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10; |
| 518 b->add32(key); | 519 b->add32(key); |
| 519 } | 520 } |
| 520 | 521 |
| 521 virtual void setData(const GrGLProgramDataManager& pdman, | 522 virtual void setData(const GrGLProgramDataManager& pdman, |
| 522 const GrPrimitiveProcessor& gp, | 523 const GrPrimitiveProcessor& gp, |
| 523 const GrBatchTracker& bt) override { | 524 const GrBatchTracker& bt) override { |
| 524 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); | 525 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); |
| 525 this->setUniformViewMatrix(pdman, dee.viewMatrix()); | 526 |
| 527 if (!dee.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dee.
viewMatrix())) { |
| 528 fViewMatrix = dee.viewMatrix(); |
| 529 GrGLfloat viewMatrix[3 * 3]; |
| 530 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 531 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 532 } |
| 526 | 533 |
| 527 if (dee.color() != fColor) { | 534 if (dee.color() != fColor) { |
| 528 GrGLfloat c[4]; | 535 GrGLfloat c[4]; |
| 529 GrColorToRGBAFloat(dee.color(), c); | 536 GrColorToRGBAFloat(dee.color(), c); |
| 530 pdman.set4fv(fColorUniform, 1, c); | 537 pdman.set4fv(fColorUniform, 1, c); |
| 531 fColor = dee.color(); | 538 fColor = dee.color(); |
| 532 } | 539 } |
| 533 } | 540 } |
| 534 | 541 |
| 535 private: | 542 private: |
| 543 SkMatrix fViewMatrix; |
| 536 GrColor fColor; | 544 GrColor fColor; |
| 537 UniformHandle fColorUniform; | 545 UniformHandle fColorUniform; |
| 546 UniformHandle fViewMatrixUniform; |
| 538 | 547 |
| 539 typedef GrGLGeometryProcessor INHERITED; | 548 typedef GrGLGeometryProcessor INHERITED; |
| 540 }; | 549 }; |
| 541 | 550 |
| 542 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 551 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 543 const GrGLSLCaps& caps, | 552 const GrGLSLCaps& caps, |
| 544 GrProcessorKeyBuilder* b) const override { | 553 GrProcessorKeyBuilder* b) const override { |
| 545 GLProcessor::GenKey(*this, bt, caps, b); | 554 GLProcessor::GenKey(*this, bt, caps, b); |
| 546 } | 555 } |
| 547 | 556 |
| (...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2020 } | 2029 } |
| 2021 | 2030 |
| 2022 BATCH_TEST_DEFINE(RRectBatch) { | 2031 BATCH_TEST_DEFINE(RRectBatch) { |
| 2023 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2032 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
| 2024 GrColor color = GrRandomColor(random); | 2033 GrColor color = GrRandomColor(random); |
| 2025 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2034 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
| 2026 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2035 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
| 2027 } | 2036 } |
| 2028 | 2037 |
| 2029 #endif | 2038 #endif |
| OLD | NEW |