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