| Index: src/gpu/GrAtlasTextContext.cpp
|
| diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
|
| index 33e4f7ed86237dba488e395e25978f81e3e8e6ca..c8688b0adc4ce532ff353dc524e85a07da346a5f 100644
|
| --- a/src/gpu/GrAtlasTextContext.cpp
|
| +++ b/src/gpu/GrAtlasTextContext.cpp
|
| @@ -1474,6 +1474,13 @@ public:
|
| fBatch.fCoverageIgnored = init.fCoverageIgnored;
|
| }
|
|
|
| + struct FlushInfo {
|
| + SkAutoTUnref<const GrVertexBuffer> fVertexBuffer;
|
| + SkAutoTUnref<const GrIndexBuffer> fIndexBuffer;
|
| + int fGlyphsToFlush;
|
| + int fVertexOffset;
|
| + };
|
| +
|
| void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
|
| // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix.
|
| // TODO actually only invert if we don't have RGBA
|
| @@ -1506,6 +1513,8 @@ public:
|
| localMatrix));
|
| }
|
|
|
| + FlushInfo flushInfo;
|
| + flushInfo.fGlyphsToFlush = 0;
|
| size_t vertexStride = gp->getVertexStride();
|
| SkASSERT(vertexStride == (fUseDistanceFields ?
|
| get_vertex_stride_df(fMaskFormat, fUseLCDText) :
|
| @@ -1515,35 +1524,21 @@ public:
|
|
|
| int glyphCount = this->numGlyphs();
|
| int instanceCount = fInstanceCount;
|
| - SkAutoTUnref<const GrIndexBuffer> indexBuffer(
|
| - batchTarget->resourceProvider()->refQuadIndexBuffer());
|
| -
|
| const GrVertexBuffer* vertexBuffer;
|
| - int firstVertex;
|
| +
|
| void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
|
| glyphCount * kVerticesPerGlyph,
|
| &vertexBuffer,
|
| - &firstVertex);
|
| - if (!vertices || !indexBuffer) {
|
| + &flushInfo.fVertexOffset);
|
| + flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
|
| + flushInfo.fIndexBuffer.reset(batchTarget->resourceProvider()->refQuadIndexBuffer());
|
| + if (!vertices || !flushInfo.fVertexBuffer) {
|
| SkDebugf("Could not allocate vertices\n");
|
| return;
|
| }
|
|
|
| unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices);
|
|
|
| - // setup drawinfo
|
| - int maxInstancesPerDraw = indexBuffer->maxQuads();
|
| -
|
| - GrDrawTarget::DrawInfo drawInfo;
|
| - drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
|
| - drawInfo.setStartVertex(0);
|
| - drawInfo.setStartIndex(0);
|
| - drawInfo.setVerticesPerInstance(kVerticesPerGlyph);
|
| - drawInfo.setIndicesPerInstance(kIndicesPerGlyph);
|
| - drawInfo.adjustStartVertex(firstVertex);
|
| - drawInfo.setVertexBuffer(vertexBuffer);
|
| - drawInfo.setIndexBuffer(indexBuffer);
|
| -
|
| // We cache some values to avoid going to the glyphcache for the same fontScaler twice
|
| // in a row
|
| const SkDescriptor* desc = NULL;
|
| @@ -1551,7 +1546,6 @@ public:
|
| GrFontScaler* scaler = NULL;
|
| SkTypeface* typeface = NULL;
|
|
|
| - int instancesToFlush = 0;
|
| for (int i = 0; i < instanceCount; i++) {
|
| Geometry& args = fGeoData[i];
|
| Blob* blob = args.fBlob;
|
| @@ -1635,10 +1629,8 @@ public:
|
|
|
| if (!fFontCache->hasGlyph(glyph) &&
|
| !strike->addGlyphToAtlas(batchTarget, glyph, scaler)) {
|
| - this->flush(batchTarget, &drawInfo, instancesToFlush,
|
| - maxInstancesPerDraw);
|
| + this->flush(batchTarget, &flushInfo);
|
| this->initDraw(batchTarget, gp, pipeline);
|
| - instancesToFlush = 0;
|
| brokenRun = glyphIdx > 0;
|
|
|
| SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(batchTarget,
|
| @@ -1674,7 +1666,7 @@ public:
|
| SkScalar transY = args.fTransY;
|
| this->regeneratePositions(vertex, vertexStride, transX, transY);
|
| }
|
| - instancesToFlush++;
|
| + flushInfo.fGlyphsToFlush++;
|
| }
|
|
|
| // We my have changed the color so update it here
|
| @@ -1687,7 +1679,7 @@ public:
|
| fFontCache->atlasGeneration(fMaskFormat);
|
| }
|
| } else {
|
| - instancesToFlush += glyphCount;
|
| + flushInfo.fGlyphsToFlush += glyphCount;
|
|
|
| // set use tokens for all of the glyphs in our subrun. This is only valid if we
|
| // have a valid atlas generation
|
| @@ -1706,7 +1698,7 @@ public:
|
| if (cache) {
|
| SkGlyphCache::AttachCache(cache);
|
| }
|
| - this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDraw);
|
| + this->flush(batchTarget, &flushInfo);
|
| }
|
|
|
| // The minimum number of Geometry we will try to allocate.
|
| @@ -1833,20 +1825,19 @@ private:
|
| gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
|
| }
|
|
|
| - void flush(GrBatchTarget* batchTarget,
|
| - GrDrawTarget::DrawInfo* drawInfo,
|
| - int instanceCount,
|
| - int maxInstancesPerDraw) {
|
| - while (instanceCount) {
|
| - drawInfo->setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw));
|
| - drawInfo->setVertexCount(drawInfo->instanceCount() * drawInfo->verticesPerInstance());
|
| - drawInfo->setIndexCount(drawInfo->instanceCount() * drawInfo->indicesPerInstance());
|
| -
|
| - batchTarget->draw(*drawInfo);
|
| -
|
| - drawInfo->setStartVertex(drawInfo->startVertex() + drawInfo->vertexCount());
|
| - instanceCount -= drawInfo->instanceCount();
|
| - }
|
| + void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) {
|
| + GrDrawTarget::DrawInfo drawInfo;
|
| + int glyphsToFlush = flushInfo->fGlyphsToFlush;
|
| + int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads();
|
| + drawInfo.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
|
| + flushInfo->fIndexBuffer, flushInfo->fVertexOffset,
|
| + kVerticesPerGlyph, kIndicesPerGlyph, &glyphsToFlush,
|
| + maxGlyphsPerDraw);
|
| + do {
|
| + batchTarget->draw(drawInfo);
|
| + } while (drawInfo.nextInstances(&glyphsToFlush, maxGlyphsPerDraw));
|
| + flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
|
| + flushInfo->fGlyphsToFlush = 0;
|
| }
|
|
|
| GrColor color() const { return fBatch.fColor; }
|
|
|