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 | |
118 size_t vertexStride = gp->getVertexStride(); | 115 size_t vertexStride = gp->getVertexStride(); |
119 SkASSERT(canTweakAlphaForCoverage ? | 116 SkASSERT(canTweakAlphaForCoverage ? |
120 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 117 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
121 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 118 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
122 int instanceCount = fGeoData.count(); | 119 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); | |
130 | 120 |
| 121 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( |
| 122 batchTarget->resourceProvider())); |
| 123 InstancedHelper helper; |
| 124 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve
rtexStride, |
| 125 indexBuffer, kVertsPerAAFillRect, kIndicesP
erAAFillRect, |
| 126 instanceCount); |
131 if (!vertices || !indexBuffer) { | 127 if (!vertices || !indexBuffer) { |
132 SkDebugf("Could not allocate vertices\n"); | 128 SkDebugf("Could not allocate vertices\n"); |
133 return; | 129 return; |
134 } | 130 } |
135 | 131 |
136 for (int i = 0; i < instanceCount; i++) { | 132 for (int i = 0; i < instanceCount; i++) { |
137 const Geometry& args = fGeoData[i]; | 133 const Geometry& args = fGeoData[i]; |
138 this->generateAAFillRectGeometry(vertices, | 134 this->generateAAFillRectGeometry(vertices, |
139 i * kVertsPerAAFillRect * vertexStr
ide, | 135 i * kVertsPerAAFillRect * vertexStr
ide, |
140 vertexStride, | 136 vertexStride, |
141 args.fColor, | 137 args.fColor, |
142 args.fViewMatrix, | 138 args.fViewMatrix, |
143 args.fRect, | 139 args.fRect, |
144 args.fDevRect, | 140 args.fDevRect, |
145 canTweakAlphaForCoverage); | 141 canTweakAlphaForCoverage); |
146 } | 142 } |
147 | 143 |
148 GrDrawTarget::DrawInfo drawInfo; | 144 helper.issueDraws(batchTarget); |
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 } | |
170 } | 145 } |
171 | 146 |
172 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 147 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
173 | 148 |
174 private: | 149 private: |
175 AAFillRectBatch(const Geometry& geometry) { | 150 AAFillRectBatch(const Geometry& geometry) { |
176 this->initClassID<AAFillRectBatch>(); | 151 this->initClassID<AAFillRectBatch>(); |
177 fGeoData.push_back(geometry); | 152 fGeoData.push_back(geometry); |
178 | 153 |
179 this->setBounds(geometry.fDevRect); | 154 this->setBounds(geometry.fDevRect); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 453 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
479 SkDebugf("Cannot invert\n"); | 454 SkDebugf("Cannot invert\n"); |
480 return; | 455 return; |
481 } | 456 } |
482 | 457 |
483 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 458 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
484 localMatr
ix)); | 459 localMatr
ix)); |
485 | 460 |
486 batchTarget->initDraw(gp, pipeline); | 461 batchTarget->initDraw(gp, pipeline); |
487 | 462 |
488 const SkAutoTUnref<const GrIndexBuffer> indexBuffer( | |
489 GetIndexBuffer(batchTarget->resourceProvider(), this->miterStroke())
); | |
490 | |
491 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | 463 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
492 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 464 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
493 // everywhere we can remove this nastiness | 465 // everywhere we can remove this nastiness |
494 GrPipelineInfo init; | 466 GrPipelineInfo init; |
495 init.fColorIgnored = fBatch.fColorIgnored; | 467 init.fColorIgnored = fBatch.fColorIgnored; |
496 init.fOverrideColor = GrColor_ILLEGAL; | 468 init.fOverrideColor = GrColor_ILLEGAL; |
497 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 469 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
498 init.fUsesLocalCoords = this->usesLocalCoords(); | 470 init.fUsesLocalCoords = this->usesLocalCoords(); |
499 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 471 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
500 | 472 |
501 size_t vertexStride = gp->getVertexStride(); | 473 size_t vertexStride = gp->getVertexStride(); |
502 | 474 |
503 SkASSERT(canTweakAlphaForCoverage ? | 475 SkASSERT(canTweakAlphaForCoverage ? |
504 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 476 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
505 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 477 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
506 int innerVertexNum = 4; | 478 int innerVertexNum = 4; |
507 int outerVertexNum = this->miterStroke() ? 4 : 8; | 479 int outerVertexNum = this->miterStroke() ? 4 : 8; |
508 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; | 480 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; |
| 481 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn
dexCnt; |
| 482 int instanceCount = fGeoData.count(); |
509 | 483 |
510 int instanceCount = fGeoData.count(); | 484 const SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
511 int vertexCount = totalVertexNum * instanceCount; | 485 GetIndexBuffer(batchTarget->resourceProvider(), this->miterStroke())
); |
512 | 486 InstancedHelper helper; |
513 const GrVertexBuffer* vertexBuffer; | 487 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve
rtexStride, |
514 int firstVertex; | 488 indexBuffer, verticesPerInstance, indicesP
erInstance, |
515 | 489 instanceCount); |
516 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | |
517 vertexCount, | |
518 &vertexBuffer, | |
519 &firstVertex); | |
520 | |
521 if (!vertices || !indexBuffer) { | 490 if (!vertices || !indexBuffer) { |
522 SkDebugf("Could not allocate vertices\n"); | 491 SkDebugf("Could not allocate vertices\n"); |
523 return; | 492 return; |
524 } | 493 } |
525 | 494 |
526 for (int i = 0; i < instanceCount; i++) { | 495 for (int i = 0; i < instanceCount; i++) { |
527 const Geometry& args = fGeoData[i]; | 496 const Geometry& args = fGeoData[i]; |
528 this->generateAAStrokeRectGeometry(vertices, | 497 this->generateAAStrokeRectGeometry(vertices, |
529 i * totalVertexNum * vertexStride
, | 498 i * verticesPerInstance * vertexS
tride, |
530 vertexStride, | 499 vertexStride, |
531 outerVertexNum, | 500 outerVertexNum, |
532 innerVertexNum, | 501 innerVertexNum, |
533 args.fColor, | 502 args.fColor, |
534 args.fDevOutside, | 503 args.fDevOutside, |
535 args.fDevOutsideAssist, | 504 args.fDevOutsideAssist, |
536 args.fDevInside, | 505 args.fDevInside, |
537 args.fMiterStroke, | 506 args.fMiterStroke, |
538 canTweakAlphaForCoverage); | 507 canTweakAlphaForCoverage); |
539 } | 508 } |
540 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn
dexCnt; | 509 helper.issueDraws(batchTarget); |
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 } | |
564 } | 510 } |
565 | 511 |
566 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 512 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
567 | 513 |
568 private: | 514 private: |
569 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) { | 515 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) { |
570 this->initClassID<AAStrokeRectBatch>(); | 516 this->initClassID<AAStrokeRectBatch>(); |
571 fBatch.fViewMatrix = viewMatrix; | 517 fBatch.fViewMatrix = viewMatrix; |
572 fGeoData.push_back(geometry); | 518 fGeoData.push_back(geometry); |
573 | 519 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 geo.fColor = GrRandomColor(random); | 856 geo.fColor = GrRandomColor(random); |
911 geo.fDevOutside = outside; | 857 geo.fDevOutside = outside; |
912 geo.fDevOutsideAssist = outsideAssist; | 858 geo.fDevOutsideAssist = outsideAssist; |
913 geo.fDevInside = inside; | 859 geo.fDevInside = inside; |
914 geo.fMiterStroke = miterStroke; | 860 geo.fMiterStroke = miterStroke; |
915 | 861 |
916 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); | 862 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); |
917 } | 863 } |
918 | 864 |
919 #endif | 865 #endif |
OLD | NEW |