OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
8 | 8 |
9 #include "GrBatchFontCache.h" | 9 #include "GrBatchFontCache.h" |
10 #include "GrBatchTarget.h" | 10 #include "GrBatchFlushState.h" |
11 #include "GrBatchTest.h" | 11 #include "GrBatchTest.h" |
12 #include "GrBlurUtils.h" | 12 #include "GrBlurUtils.h" |
13 #include "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
14 #include "GrDrawContext.h" | 14 #include "GrDrawContext.h" |
15 #include "GrDrawTarget.h" | 15 #include "GrDrawTarget.h" |
16 #include "GrFontScaler.h" | 16 #include "GrFontScaler.h" |
17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
18 #include "GrStrokeInfo.h" | 18 #include "GrStrokeInfo.h" |
19 #include "GrTextBlobCache.h" | 19 #include "GrTextBlobCache.h" |
20 #include "GrTexturePriv.h" | 20 #include "GrTexturePriv.h" |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 1528 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
1529 } | 1529 } |
1530 | 1530 |
1531 struct FlushInfo { | 1531 struct FlushInfo { |
1532 SkAutoTUnref<const GrVertexBuffer> fVertexBuffer; | 1532 SkAutoTUnref<const GrVertexBuffer> fVertexBuffer; |
1533 SkAutoTUnref<const GrIndexBuffer> fIndexBuffer; | 1533 SkAutoTUnref<const GrIndexBuffer> fIndexBuffer; |
1534 int fGlyphsToFlush; | 1534 int fGlyphsToFlush; |
1535 int fVertexOffset; | 1535 int fVertexOffset; |
1536 }; | 1536 }; |
1537 | 1537 |
1538 void generateGeometry(GrBatchTarget* batchTarget) override { | 1538 void onPrepareDraws(Target* target) override { |
1539 // if we have RGB, then we won't have any SkShaders so no need to use a
localmatrix. | 1539 // if we have RGB, then we won't have any SkShaders so no need to use a
localmatrix. |
1540 // TODO actually only invert if we don't have RGBA | 1540 // TODO actually only invert if we don't have RGBA |
1541 SkMatrix localMatrix; | 1541 SkMatrix localMatrix; |
1542 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 1542 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
1543 SkDebugf("Cannot invert viewmatrix\n"); | 1543 SkDebugf("Cannot invert viewmatrix\n"); |
1544 return; | 1544 return; |
1545 } | 1545 } |
1546 | 1546 |
1547 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); | 1547 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); |
1548 if (!texture) { | 1548 if (!texture) { |
(...skipping 19 matching lines...) Expand all Loading... |
1568 this->usesLocalCoords())); | 1568 this->usesLocalCoords())); |
1569 } | 1569 } |
1570 | 1570 |
1571 FlushInfo flushInfo; | 1571 FlushInfo flushInfo; |
1572 flushInfo.fGlyphsToFlush = 0; | 1572 flushInfo.fGlyphsToFlush = 0; |
1573 size_t vertexStride = gp->getVertexStride(); | 1573 size_t vertexStride = gp->getVertexStride(); |
1574 SkASSERT(vertexStride == (usesDistanceFields ? | 1574 SkASSERT(vertexStride == (usesDistanceFields ? |
1575 get_vertex_stride_df(maskFormat, isLCD) : | 1575 get_vertex_stride_df(maskFormat, isLCD) : |
1576 get_vertex_stride(maskFormat))); | 1576 get_vertex_stride(maskFormat))); |
1577 | 1577 |
1578 batchTarget->initDraw(gp, this->pipeline()); | 1578 target->initDraw(gp, this->pipeline()); |
1579 | 1579 |
1580 int glyphCount = this->numGlyphs(); | 1580 int glyphCount = this->numGlyphs(); |
1581 const GrVertexBuffer* vertexBuffer; | 1581 const GrVertexBuffer* vertexBuffer; |
1582 | 1582 |
1583 void* vertices = batchTarget->makeVertSpace(vertexStride, | 1583 void* vertices = target->makeVertexSpace(vertexStride, |
1584 glyphCount * kVerticesPerGly
ph, | 1584 glyphCount * kVerticesPerGlyph, |
1585 &vertexBuffer, | 1585 &vertexBuffer, |
1586 &flushInfo.fVertexOffset); | 1586 &flushInfo.fVertexOffset); |
1587 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); | 1587 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
1588 flushInfo.fIndexBuffer.reset(batchTarget->resourceProvider()->refQuadInd
exBuffer()); | 1588 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf
fer()); |
1589 if (!vertices || !flushInfo.fVertexBuffer) { | 1589 if (!vertices || !flushInfo.fVertexBuffer) { |
1590 SkDebugf("Could not allocate vertices\n"); | 1590 SkDebugf("Could not allocate vertices\n"); |
1591 return; | 1591 return; |
1592 } | 1592 } |
1593 | 1593 |
1594 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); | 1594 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
1595 | 1595 |
1596 // We cache some values to avoid going to the glyphcache for the same fo
ntScaler twice | 1596 // We cache some values to avoid going to the glyphcache for the same fo
ntScaler twice |
1597 // in a row | 1597 // in a row |
1598 const SkDescriptor* desc = NULL; | 1598 const SkDescriptor* desc = NULL; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 scaler
); | 1682 scaler
); |
1683 } | 1683 } |
1684 glyph = blob->fGlyphs[glyphOffset]; | 1684 glyph = blob->fGlyphs[glyphOffset]; |
1685 SkASSERT(glyph); | 1685 SkASSERT(glyph); |
1686 SkASSERT(id == glyph->fPackedID); | 1686 SkASSERT(id == glyph->fPackedID); |
1687 // We want to be able to assert this but cannot for test
ing purposes. | 1687 // We want to be able to assert this but cannot for test
ing purposes. |
1688 // once skbug:4143 has landed we can revist this assert | 1688 // once skbug:4143 has landed we can revist this assert |
1689 //SkASSERT(glyph->fMaskFormat == this->maskFormat()); | 1689 //SkASSERT(glyph->fMaskFormat == this->maskFormat()); |
1690 | 1690 |
1691 if (!fFontCache->hasGlyph(glyph) && | 1691 if (!fFontCache->hasGlyph(glyph) && |
1692 !strike->addGlyphToAtlas(batchTarget, glyph, scaler,
skGlyph, | 1692 !strike->addGlyphToAtlas(target, glyph, scaler, skGl
yph, maskFormat)) { |
1693 maskFormat)) { | 1693 this->flush(target, &flushInfo); |
1694 this->flush(batchTarget, &flushInfo); | 1694 target->initDraw(gp, this->pipeline()); |
1695 batchTarget->initDraw(gp, this->pipeline()); | |
1696 brokenRun = glyphIdx > 0; | 1695 brokenRun = glyphIdx > 0; |
1697 | 1696 |
1698 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(
batchTarget, | 1697 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(
target, |
1699
glyph, | 1698
glyph, |
1700
scaler, | 1699
scaler, |
1701
skGlyph, | 1700
skGlyph, |
1702
maskFormat); | 1701
maskFormat); |
1703 SkASSERT(success); | 1702 SkASSERT(success); |
1704 } | 1703 } |
1705 fFontCache->addGlyphToBulkAndSetUseToken(&info.fBulkUseT
oken, glyph, | 1704 fFontCache->addGlyphToBulkAndSetUseToken(&info.fBulkUseT
oken, glyph, |
1706 batchTarget->cu
rrentToken()); | 1705 target->current
Token()); |
1707 | 1706 |
1708 // Texture coords are the last vertex attribute so we ge
t a pointer to the | 1707 // Texture coords are the last vertex attribute so we ge
t a pointer to the |
1709 // first one and then map with stride in regenerateTextu
reCoords | 1708 // first one and then map with stride in regenerateTextu
reCoords |
1710 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert
ices); | 1709 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert
ices); |
1711 vertex += info.fVertexStartIndex; | 1710 vertex += info.fVertexStartIndex; |
1712 vertex += vertexStride * glyphIdx * kVerticesPerGlyph; | 1711 vertex += vertexStride * glyphIdx * kVerticesPerGlyph; |
1713 vertex += vertexStride - sizeof(SkIPoint16); | 1712 vertex += vertexStride - sizeof(SkIPoint16); |
1714 | 1713 |
1715 this->regenerateTextureCoords(glyph, vertex, vertexStrid
e); | 1714 this->regenerateTextureCoords(glyph, vertex, vertexStrid
e); |
1716 } | 1715 } |
(...skipping 23 matching lines...) Expand all Loading... |
1740 info.fStrike.reset(SkRef(strike)); | 1739 info.fStrike.reset(SkRef(strike)); |
1741 } | 1740 } |
1742 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : | 1741 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : |
1743 fFontCache->atlasGenerat
ion(maskFormat); | 1742 fFontCache->atlasGenerat
ion(maskFormat); |
1744 } | 1743 } |
1745 } else { | 1744 } else { |
1746 flushInfo.fGlyphsToFlush += glyphCount; | 1745 flushInfo.fGlyphsToFlush += glyphCount; |
1747 | 1746 |
1748 // set use tokens for all of the glyphs in our subrun. This is
only valid if we | 1747 // set use tokens for all of the glyphs in our subrun. This is
only valid if we |
1749 // have a valid atlas generation | 1748 // have a valid atlas generation |
1750 fFontCache->setUseTokenBulk(info.fBulkUseToken, | 1749 fFontCache->setUseTokenBulk(info.fBulkUseToken, target->currentT
oken(), maskFormat); |
1751 batchTarget->currentToken(), | |
1752 maskFormat); | |
1753 } | 1750 } |
1754 | 1751 |
1755 // now copy all vertices | 1752 // now copy all vertices |
1756 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; | 1753 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; |
1757 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou
nt); | 1754 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou
nt); |
1758 | 1755 |
1759 currVertex += byteCount; | 1756 currVertex += byteCount; |
1760 } | 1757 } |
1761 // Make sure to attach the last cache if applicable | 1758 // Make sure to attach the last cache if applicable |
1762 if (cache) { | 1759 if (cache) { |
1763 SkGlyphCache::AttachCache(cache); | 1760 SkGlyphCache::AttachCache(cache); |
1764 } | 1761 } |
1765 this->flush(batchTarget, &flushInfo); | 1762 this->flush(target, &flushInfo); |
1766 } | 1763 } |
1767 | 1764 |
1768 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which | 1765 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which |
1769 // is used to seed the batch with its initial geometry. After seeding, the
client should call | 1766 // is used to seed the batch with its initial geometry. After seeding, the
client should call |
1770 // init() so the Batch can initialize itself | 1767 // init() so the Batch can initialize itself |
1771 Geometry& geometry() { return fGeoData[0]; } | 1768 Geometry& geometry() { return fGeoData[0]; } |
1772 void init() { | 1769 void init() { |
1773 const Geometry& geo = fGeoData[0]; | 1770 const Geometry& geo = fGeoData[0]; |
1774 fBatch.fColor = geo.fColor; | 1771 fBatch.fColor = geo.fColor; |
1775 fBatch.fViewMatrix = geo.fBlob->fViewMatrix; | 1772 fBatch.fViewMatrix = geo.fBlob->fViewMatrix; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 void regeneratePositions(intptr_t vertex, size_t vertexStride, SkScalar tran
sX, | 1865 void regeneratePositions(intptr_t vertex, size_t vertexStride, SkScalar tran
sX, |
1869 SkScalar transY) { | 1866 SkScalar transY) { |
1870 for (int i = 0; i < kVerticesPerGlyph; i++) { | 1867 for (int i = 0; i < kVerticesPerGlyph; i++) { |
1871 SkPoint* point = reinterpret_cast<SkPoint*>(vertex); | 1868 SkPoint* point = reinterpret_cast<SkPoint*>(vertex); |
1872 point->fX += transX; | 1869 point->fX += transX; |
1873 point->fY += transY; | 1870 point->fY += transY; |
1874 vertex += vertexStride; | 1871 vertex += vertexStride; |
1875 } | 1872 } |
1876 } | 1873 } |
1877 | 1874 |
1878 void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) { | 1875 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) { |
1879 GrVertices vertices; | 1876 GrVertices vertices; |
1880 int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads(); | 1877 int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads(); |
1881 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf
fer, | 1878 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf
fer, |
1882 flushInfo->fIndexBuffer, flushInfo->fVertexOffset
, | 1879 flushInfo->fIndexBuffer, flushInfo->fVertexOffset
, |
1883 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->f
GlyphsToFlush, | 1880 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->f
GlyphsToFlush, |
1884 maxGlyphsPerDraw); | 1881 maxGlyphsPerDraw); |
1885 batchTarget->draw(vertices); | 1882 target->draw(vertices); |
1886 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlus
h; | 1883 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlus
h; |
1887 flushInfo->fGlyphsToFlush = 0; | 1884 flushInfo->fGlyphsToFlush = 0; |
1888 } | 1885 } |
1889 | 1886 |
1890 GrColor color() const { return fBatch.fColor; } | 1887 GrColor color() const { return fBatch.fColor; } |
1891 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 1888 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
1892 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 1889 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
1893 int numGlyphs() const { return fBatch.fNumGlyphs; } | 1890 int numGlyphs() const { return fBatch.fNumGlyphs; } |
1894 | 1891 |
1895 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 1892 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2279 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2283 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2280 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2284 | 2281 |
2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2282 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2283 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2284 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2285 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2289 } | 2286 } |
2290 | 2287 |
2291 #endif | 2288 #endif |
OLD | NEW |