| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
| 9 #include "GrBatch.h" | 9 #include "GrBatch.h" |
| 10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | 104 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 105 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 105 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 106 // everywhere we can remove this nastiness | 106 // everywhere we can remove this nastiness |
| 107 GrPipelineInfo init; | 107 GrPipelineInfo init; |
| 108 init.fColorIgnored = fBatch.fColorIgnored; | 108 init.fColorIgnored = fBatch.fColorIgnored; |
| 109 init.fOverrideColor = GrColor_ILLEGAL; | 109 init.fOverrideColor = GrColor_ILLEGAL; |
| 110 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 110 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 111 init.fUsesLocalCoords = this->usesLocalCoords(); | 111 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 112 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 112 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 113 | 113 |
| 114 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( | |
| 115 batchTarget->resourceProvider())); | |
| 116 | |
| 117 size_t vertexStride = gp->getVertexStride(); | 114 size_t vertexStride = gp->getVertexStride(); |
| 118 SkASSERT(canTweakAlphaForCoverage ? | 115 SkASSERT(canTweakAlphaForCoverage ? |
| 119 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 116 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 120 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 117 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 121 int instanceCount = fGeoData.count(); | 118 int instanceCount = fGeoData.count(); |
| 122 int vertexCount = kVertsPerAAFillRect * instanceCount; | |
| 123 const GrVertexBuffer* vertexBuffer; | |
| 124 int firstVertex; | |
| 125 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | |
| 126 vertexCount, | |
| 127 &vertexBuffer, | |
| 128 &firstVertex); | |
| 129 | 119 |
| 120 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( |
| 121 batchTarget->resourceProvider())); |
| 122 InstancedHelper helper; |
| 123 void* vertices = helper.init(batchTarget, vertexStride, indexBuffer, kVe
rtsPerAAFillRect, |
| 124 kIndicesPerAAFillRect, instanceCount); |
| 130 if (!vertices || !indexBuffer) { | 125 if (!vertices || !indexBuffer) { |
| 131 SkDebugf("Could not allocate vertices\n"); | 126 SkDebugf("Could not allocate vertices\n"); |
| 132 return; | 127 return; |
| 133 } | 128 } |
| 134 | 129 |
| 135 for (int i = 0; i < instanceCount; i++) { | 130 for (int i = 0; i < instanceCount; i++) { |
| 136 const Geometry& args = fGeoData[i]; | 131 const Geometry& args = fGeoData[i]; |
| 137 this->generateAAFillRectGeometry(vertices, | 132 this->generateAAFillRectGeometry(vertices, |
| 138 i * kVertsPerAAFillRect * vertexStr
ide, | 133 i * kVertsPerAAFillRect * vertexStr
ide, |
| 139 vertexStride, | 134 vertexStride, |
| 140 args.fColor, | 135 args.fColor, |
| 141 args.fViewMatrix, | 136 args.fViewMatrix, |
| 142 args.fRect, | 137 args.fRect, |
| 143 args.fDevRect, | 138 args.fDevRect, |
| 144 canTweakAlphaForCoverage); | 139 canTweakAlphaForCoverage); |
| 145 } | 140 } |
| 146 | 141 |
| 147 GrDrawTarget::DrawInfo drawInfo; | 142 helper.issueDraws(batchTarget); |
| 148 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
| 149 drawInfo.setStartVertex(0); | |
| 150 drawInfo.setStartIndex(0); | |
| 151 drawInfo.setVerticesPerInstance(kVertsPerAAFillRect); | |
| 152 drawInfo.setIndicesPerInstance(kIndicesPerAAFillRect); | |
| 153 drawInfo.adjustStartVertex(firstVertex); | |
| 154 drawInfo.setVertexBuffer(vertexBuffer); | |
| 155 drawInfo.setIndexBuffer(indexBuffer); | |
| 156 | |
| 157 int maxInstancesPerDraw = kNumAAFillRectsInIndexBuffer; | |
| 158 | |
| 159 while (instanceCount) { | |
| 160 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
| 161 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
| 162 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
| 163 | |
| 164 batchTarget->draw(drawInfo); | |
| 165 | |
| 166 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
| 167 instanceCount -= drawInfo.instanceCount(); | |
| 168 } | |
| 169 } | 143 } |
| 170 | 144 |
| 171 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 145 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 172 | 146 |
| 173 private: | 147 private: |
| 174 AAFillRectBatch(const Geometry& geometry) { | 148 AAFillRectBatch(const Geometry& geometry) { |
| 175 this->initClassID<AAFillRectBatch>(); | 149 this->initClassID<AAFillRectBatch>(); |
| 176 fGeoData.push_back(geometry); | 150 fGeoData.push_back(geometry); |
| 177 | 151 |
| 178 this->setBounds(geometry.fDevRect); | 152 this->setBounds(geometry.fDevRect); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 451 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 478 SkDebugf("Cannot invert\n"); | 452 SkDebugf("Cannot invert\n"); |
| 479 return; | 453 return; |
| 480 } | 454 } |
| 481 | 455 |
| 482 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 456 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 483 localMatr
ix)); | 457 localMatr
ix)); |
| 484 | 458 |
| 485 batchTarget->initDraw(gp, pipeline); | 459 batchTarget->initDraw(gp, pipeline); |
| 486 | 460 |
| 487 const SkAutoTUnref<const GrIndexBuffer> indexBuffer( | |
| 488 GetIndexBuffer(batchTarget->resourceProvider(), this->miterStroke())
); | |
| 489 | |
| 490 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | 461 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 491 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 462 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 492 // everywhere we can remove this nastiness | 463 // everywhere we can remove this nastiness |
| 493 GrPipelineInfo init; | 464 GrPipelineInfo init; |
| 494 init.fColorIgnored = fBatch.fColorIgnored; | 465 init.fColorIgnored = fBatch.fColorIgnored; |
| 495 init.fOverrideColor = GrColor_ILLEGAL; | 466 init.fOverrideColor = GrColor_ILLEGAL; |
| 496 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 467 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 497 init.fUsesLocalCoords = this->usesLocalCoords(); | 468 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 498 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 469 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 499 | 470 |
| 500 size_t vertexStride = gp->getVertexStride(); | 471 size_t vertexStride = gp->getVertexStride(); |
| 501 | 472 |
| 502 SkASSERT(canTweakAlphaForCoverage ? | 473 SkASSERT(canTweakAlphaForCoverage ? |
| 503 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 474 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 504 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 475 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 505 int innerVertexNum = 4; | 476 int innerVertexNum = 4; |
| 506 int outerVertexNum = this->miterStroke() ? 4 : 8; | 477 int outerVertexNum = this->miterStroke() ? 4 : 8; |
| 507 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; | 478 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; |
| 508 | 479 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn
dexCnt; |
| 509 int instanceCount = fGeoData.count(); | 480 int instanceCount = fGeoData.count(); |
| 510 int vertexCount = totalVertexNum * instanceCount; | 481 |
| 511 | 482 const SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 512 const GrVertexBuffer* vertexBuffer; | 483 GetIndexBuffer(batchTarget->resourceProvider(), this->miterStroke())
); |
| 513 int firstVertex; | 484 InstancedHelper helper; |
| 514 | 485 void* vertices = helper.init(batchTarget, vertexStride, indexBuffer, ver
ticesPerInstance, |
| 515 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 486 indicesPerInstance, instanceCount); |
| 516 vertexCount, | 487 if (!vertices || !indexBuffer) { |
| 517 &vertexBuffer, | |
| 518 &firstVertex); | |
| 519 | |
| 520 if (!vertices) { | |
| 521 SkDebugf("Could not allocate vertices\n"); | 488 SkDebugf("Could not allocate vertices\n"); |
| 522 return; | 489 return; |
| 523 } | 490 } |
| 524 | 491 |
| 525 for (int i = 0; i < instanceCount; i++) { | 492 for (int i = 0; i < instanceCount; i++) { |
| 526 const Geometry& args = fGeoData[i]; | 493 const Geometry& args = fGeoData[i]; |
| 527 this->generateAAStrokeRectGeometry(vertices, | 494 this->generateAAStrokeRectGeometry(vertices, |
| 528 i * totalVertexNum * vertexStride
, | 495 i * verticesPerInstance * vertexS
tride, |
| 529 vertexStride, | 496 vertexStride, |
| 530 outerVertexNum, | 497 outerVertexNum, |
| 531 innerVertexNum, | 498 innerVertexNum, |
| 532 args.fColor, | 499 args.fColor, |
| 533 args.fDevOutside, | 500 args.fDevOutside, |
| 534 args.fDevOutsideAssist, | 501 args.fDevOutsideAssist, |
| 535 args.fDevInside, | 502 args.fDevInside, |
| 536 args.fMiterStroke, | 503 args.fMiterStroke, |
| 537 canTweakAlphaForCoverage); | 504 canTweakAlphaForCoverage); |
| 538 } | 505 } |
| 539 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn
dexCnt; | 506 helper.issueDraws(batchTarget); |
| 540 GrDrawTarget::DrawInfo drawInfo; | |
| 541 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
| 542 drawInfo.setStartVertex(0); | |
| 543 drawInfo.setStartIndex(0); | |
| 544 drawInfo.setVerticesPerInstance(totalVertexNum); | |
| 545 drawInfo.setIndicesPerInstance(indicesPerInstance); | |
| 546 drawInfo.adjustStartVertex(firstVertex); | |
| 547 drawInfo.setVertexBuffer(vertexBuffer); | |
| 548 drawInfo.setIndexBuffer(indexBuffer); | |
| 549 | |
| 550 int maxInstancesPerDraw = this->miterStroke() ? kNumMiterRectsInIndexBuf
fer : | |
| 551 kNumBevelRectsInIndexBuf
fer; | |
| 552 | |
| 553 while (instanceCount) { | |
| 554 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
| 555 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
| 556 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
| 557 | |
| 558 batchTarget->draw(drawInfo); | |
| 559 | |
| 560 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
| 561 instanceCount -= drawInfo.instanceCount(); | |
| 562 } | |
| 563 } | 507 } |
| 564 | 508 |
| 565 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 509 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 566 | 510 |
| 567 private: | 511 private: |
| 568 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) { | 512 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) { |
| 569 this->initClassID<AAStrokeRectBatch>(); | 513 this->initClassID<AAStrokeRectBatch>(); |
| 570 fBatch.fViewMatrix = viewMatrix; | 514 fBatch.fViewMatrix = viewMatrix; |
| 571 fGeoData.push_back(geometry); | 515 fGeoData.push_back(geometry); |
| 572 | 516 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 geo.fColor = GrRandomColor(random); | 853 geo.fColor = GrRandomColor(random); |
| 910 geo.fDevOutside = outside; | 854 geo.fDevOutside = outside; |
| 911 geo.fDevOutsideAssist = outsideAssist; | 855 geo.fDevOutsideAssist = outsideAssist; |
| 912 geo.fDevInside = inside; | 856 geo.fDevInside = inside; |
| 913 geo.fMiterStroke = miterStroke; | 857 geo.fMiterStroke = miterStroke; |
| 914 | 858 |
| 915 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); | 859 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); |
| 916 } | 860 } |
| 917 | 861 |
| 918 #endif | 862 #endif |
| OLD | NEW |