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 "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 GrDrawTarget::DrawInfo drawInfo; | 1497 GrDrawTarget::DrawInfo drawInfo; |
1498 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | 1498 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
1499 drawInfo.setStartVertex(0); | 1499 drawInfo.setStartVertex(0); |
1500 drawInfo.setStartIndex(0); | 1500 drawInfo.setStartIndex(0); |
1501 drawInfo.setVerticesPerInstance(kVerticesPerGlyph); | 1501 drawInfo.setVerticesPerInstance(kVerticesPerGlyph); |
1502 drawInfo.setIndicesPerInstance(kIndicesPerGlyph); | 1502 drawInfo.setIndicesPerInstance(kIndicesPerGlyph); |
1503 drawInfo.adjustStartVertex(firstVertex); | 1503 drawInfo.adjustStartVertex(firstVertex); |
1504 drawInfo.setVertexBuffer(vertexBuffer); | 1504 drawInfo.setVertexBuffer(vertexBuffer); |
1505 drawInfo.setIndexBuffer(quadIndexBuffer); | 1505 drawInfo.setIndexBuffer(quadIndexBuffer); |
1506 | 1506 |
| 1507 // We cache some values to avoid going to the glyphcache for the same fo
ntScaler twice |
| 1508 // in a row |
| 1509 const SkDescriptor* desc = NULL; |
| 1510 SkGlyphCache* cache = NULL; |
| 1511 GrFontScaler* scaler = NULL; |
| 1512 GrBatchTextStrike* strike = NULL; |
| 1513 SkTypeface* typeface = NULL; |
| 1514 |
1507 int instancesToFlush = 0; | 1515 int instancesToFlush = 0; |
1508 for (int i = 0; i < instanceCount; i++) { | 1516 for (int i = 0; i < instanceCount; i++) { |
1509 Geometry& args = fGeoData[i]; | 1517 Geometry& args = fGeoData[i]; |
1510 Blob* blob = args.fBlob; | 1518 Blob* blob = args.fBlob; |
1511 Run& run = blob->fRuns[args.fRun]; | 1519 Run& run = blob->fRuns[args.fRun]; |
1512 TextInfo& info = run.fSubRunInfo[args.fSubRun]; | 1520 TextInfo& info = run.fSubRunInfo[args.fSubRun]; |
1513 | 1521 |
1514 uint64_t currentAtlasGen = fFontCache->atlasGeneration(fMaskFormat); | 1522 uint64_t currentAtlasGen = fFontCache->atlasGeneration(fMaskFormat); |
1515 bool regenerateTextureCoords = info.fAtlasGeneration != currentAtlas
Gen; | 1523 bool regenerateTextureCoords = info.fAtlasGeneration != currentAtlas
Gen; |
1516 bool regenerateColors; | 1524 bool regenerateColors; |
1517 if (fUseDistanceFields) { | 1525 if (fUseDistanceFields) { |
1518 regenerateColors = !fUseLCDText && run.fColor != args.fColor; | 1526 regenerateColors = !fUseLCDText && run.fColor != args.fColor; |
1519 } else { | 1527 } else { |
1520 regenerateColors = kA8_GrMaskFormat == fMaskFormat && run.fColor
!= args.fColor; | 1528 regenerateColors = kA8_GrMaskFormat == fMaskFormat && run.fColor
!= args.fColor; |
1521 } | 1529 } |
1522 bool regeneratePositions = args.fTransX != 0.f || args.fTransY != 0.
f; | 1530 bool regeneratePositions = args.fTransX != 0.f || args.fTransY != 0.
f; |
1523 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 1531 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
1524 | 1532 |
1525 // We regenerate both texture coords and colors in the blob itself,
and update the | 1533 // We regenerate both texture coords and colors in the blob itself,
and update the |
1526 // atlas generation. If we don't end up purging any unused plots, w
e can avoid | 1534 // atlas generation. If we don't end up purging any unused plots, w
e can avoid |
1527 // regenerating the coords. We could take a finer grained approach
to updating texture | 1535 // regenerating the coords. We could take a finer grained approach
to updating texture |
1528 // coords but its not clear if the extra bookkeeping would offset an
y gains. | 1536 // coords but its not clear if the extra bookkeeping would offset an
y gains. |
1529 // To avoid looping over the glyphs twice, we do one loop and condit
ionally update color | 1537 // To avoid looping over the glyphs twice, we do one loop and condit
ionally update color |
1530 // or coords as needed. One final note, if we have to break a run f
or an atlas eviction | 1538 // or coords as needed. One final note, if we have to break a run f
or an atlas eviction |
1531 // then we can't really trust the atlas has all of the correct data.
Atlas evictions | 1539 // then we can't really trust the atlas has all of the correct data.
Atlas evictions |
1532 // should be pretty rare, so we just always regenerate in those case
s | 1540 // should be pretty rare, so we just always regenerate in those case
s |
1533 if (regenerateTextureCoords || regenerateColors || regeneratePositio
ns) { | 1541 if (regenerateTextureCoords || regenerateColors || regeneratePositio
ns) { |
1534 // first regenerate texture coordinates / colors if need be | 1542 // first regenerate texture coordinates / colors if need be |
1535 const SkDescriptor* desc = NULL; | |
1536 SkGlyphCache* cache = NULL; | |
1537 GrFontScaler* scaler = NULL; | |
1538 GrBatchTextStrike* strike = NULL; | |
1539 bool brokenRun = false; | 1543 bool brokenRun = false; |
1540 if (regenerateTextureCoords) { | 1544 if (regenerateTextureCoords) { |
1541 info.fBulkUseToken.reset(); | 1545 info.fBulkUseToken.reset(); |
1542 desc = info.fOverrideDescriptor ? info.fOverrideDescriptor->
getDesc() : | 1546 |
1543 run.fDescriptor.getDesc(); | 1547 // We can reuse if we have a valid strike and our descriptor
s / typeface are the |
1544 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); | 1548 // same |
1545 scaler = GrTextContext::GetGrFontScaler(cache); | 1549 const SkDescriptor* newDesc = info.fOverrideDescriptor ? |
1546 strike = fFontCache->getStrike(scaler); | 1550 info.fOverrideDescriptor->getD
esc() : |
| 1551 run.fDescriptor.getDesc(); |
| 1552 if (!cache || !SkTypeface::Equal(typeface, run.fTypeface) || |
| 1553 !(desc->equals(*newDesc))) { |
| 1554 if (cache) { |
| 1555 SkGlyphCache::AttachCache(cache); |
| 1556 } |
| 1557 desc = newDesc; |
| 1558 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); |
| 1559 scaler = GrTextContext::GetGrFontScaler(cache); |
| 1560 strike = fFontCache->getStrike(scaler); |
| 1561 typeface = run.fTypeface; |
| 1562 } |
1547 } | 1563 } |
1548 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { | 1564 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
1549 GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.
fGlyphStartIndex]; | 1565 GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.
fGlyphStartIndex]; |
1550 | 1566 |
1551 if (regenerateTextureCoords) { | 1567 if (regenerateTextureCoords) { |
1552 // Upload the glyph only if needed | 1568 // Upload the glyph only if needed |
1553 GrGlyph* glyph = strike->getGlyph(glyphID, scaler); | 1569 GrGlyph* glyph = strike->getGlyph(glyphID, scaler); |
1554 SkASSERT(glyph); | 1570 SkASSERT(glyph); |
1555 | 1571 |
1556 if (!fFontCache->hasGlyph(glyph) && | 1572 if (!fFontCache->hasGlyph(glyph) && |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 SkScalar transX = args.fTransX; | 1608 SkScalar transX = args.fTransX; |
1593 SkScalar transY = args.fTransY; | 1609 SkScalar transY = args.fTransY; |
1594 this->regeneratePositions(vertex, vertexStride, transX,
transY); | 1610 this->regeneratePositions(vertex, vertexStride, transX,
transY); |
1595 } | 1611 } |
1596 instancesToFlush++; | 1612 instancesToFlush++; |
1597 } | 1613 } |
1598 | 1614 |
1599 // We my have changed the color so update it here | 1615 // We my have changed the color so update it here |
1600 run.fColor = args.fColor; | 1616 run.fColor = args.fColor; |
1601 if (regenerateTextureCoords) { | 1617 if (regenerateTextureCoords) { |
1602 SkGlyphCache::AttachCache(cache); | |
1603 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : | 1618 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : |
1604 fFontCache->atlasGenerat
ion(fMaskFormat); | 1619 fFontCache->atlasGenerat
ion(fMaskFormat); |
1605 } | 1620 } |
1606 } else { | 1621 } else { |
1607 instancesToFlush += glyphCount; | 1622 instancesToFlush += glyphCount; |
1608 | 1623 |
1609 // set use tokens for all of the glyphs in our subrun. This is
only valid if we | 1624 // set use tokens for all of the glyphs in our subrun. This is
only valid if we |
1610 // have a valid atlas generation | 1625 // have a valid atlas generation |
1611 fFontCache->setUseTokenBulk(info.fBulkUseToken, | 1626 fFontCache->setUseTokenBulk(info.fBulkUseToken, |
1612 batchTarget->currentToken(), | 1627 batchTarget->currentToken(), |
1613 fMaskFormat); | 1628 fMaskFormat); |
1614 } | 1629 } |
1615 | 1630 |
1616 // now copy all vertices | 1631 // now copy all vertices |
1617 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; | 1632 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; |
1618 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou
nt); | 1633 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou
nt); |
1619 | 1634 |
1620 currVertex += byteCount; | 1635 currVertex += byteCount; |
1621 } | 1636 } |
1622 | 1637 // Make sure to attach the last cache if applicable |
| 1638 if (cache) { |
| 1639 SkGlyphCache::AttachCache(cache); |
| 1640 } |
1623 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra
w); | 1641 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra
w); |
1624 } | 1642 } |
1625 | 1643 |
1626 // The minimum number of Geometry we will try to allocate. | 1644 // The minimum number of Geometry we will try to allocate. |
1627 static const int kMinAllocated = 32; | 1645 static const int kMinAllocated = 32; |
1628 | 1646 |
1629 // Total number of Geometry this Batch owns | 1647 // Total number of Geometry this Batch owns |
1630 int instanceCount() const { return fInstanceCount; } | 1648 int instanceCount() const { return fInstanceCount; } |
1631 SkAutoSTMalloc<kMinAllocated, Geometry>* geoData() { return &fGeoData; } | 1649 SkAutoSTMalloc<kMinAllocated, Geometry>* geoData() { return &fGeoData; } |
1632 | 1650 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2072 pipelineBuilder.setFromPaint(grPaint, rt, clip); | 2090 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
2073 | 2091 |
2074 GrColor color = grPaint.getColor(); | 2092 GrColor color = grPaint.getColor(); |
2075 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 2093 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
2076 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk
Paint); | 2094 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk
Paint); |
2077 } | 2095 } |
2078 | 2096 |
2079 // Now flush big glyphs | 2097 // Now flush big glyphs |
2080 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); | 2098 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); |
2081 } | 2099 } |
OLD | NEW |