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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 batch->fFontCache = fontCache; | 1481 batch->fFontCache = fontCache; |
1482 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan
ceField_MaskType; | 1482 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan
ceField_MaskType; |
1483 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); | 1483 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); |
1484 batch->fFilteredColor = filteredColor; | 1484 batch->fFilteredColor = filteredColor; |
1485 batch->fUseBGR = useBGR; | 1485 batch->fUseBGR = useBGR; |
1486 batch->fBatch.fNumGlyphs = glyphCount; | 1486 batch->fBatch.fNumGlyphs = glyphCount; |
1487 batch->fGeoCount = 1; | 1487 batch->fGeoCount = 1; |
1488 return batch; | 1488 return batch; |
1489 } | 1489 } |
1490 | 1490 |
| 1491 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which |
| 1492 // is used to seed the batch with its initial geometry. After seeding, the
client should call |
| 1493 // init() so the Batch can initialize itself |
| 1494 Geometry& geometry() { return fGeoData[0]; } |
| 1495 |
| 1496 void init() { |
| 1497 const Geometry& geo = fGeoData[0]; |
| 1498 fBatch.fColor = geo.fColor; |
| 1499 fBatch.fViewMatrix = geo.fBlob->fViewMatrix; |
| 1500 |
| 1501 // We don't yet position distance field text on the cpu, so we have to m
ap the vertex bounds |
| 1502 // into device space |
| 1503 const Run& run = geo.fBlob->fRuns[geo.fRun]; |
| 1504 if (run.fSubRunInfo[geo.fSubRun].fDrawAsDistanceFields) { |
| 1505 SkRect bounds = run.fVertexBounds; |
| 1506 fBatch.fViewMatrix.mapRect(&bounds); |
| 1507 this->setBounds(bounds); |
| 1508 } else { |
| 1509 this->setBounds(run.fVertexBounds); |
| 1510 } |
| 1511 } |
| 1512 |
1491 const char* name() const override { return "TextBatch"; } | 1513 const char* name() const override { return "TextBatch"; } |
1492 | 1514 |
1493 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 1515 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
1494 if (kColorBitmapMask_MaskType == fMaskType) { | 1516 if (kColorBitmapMask_MaskType == fMaskType) { |
1495 out->setUnknownFourComponents(); | 1517 out->setUnknownFourComponents(); |
1496 } else { | 1518 } else { |
1497 out->setKnownFourComponents(fBatch.fColor); | 1519 out->setKnownFourComponents(fBatch.fColor); |
1498 } | 1520 } |
1499 } | 1521 } |
1500 | 1522 |
1501 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 1523 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
1502 switch (fMaskType) { | 1524 switch (fMaskType) { |
1503 case kGrayscaleDistanceField_MaskType: | 1525 case kGrayscaleDistanceField_MaskType: |
1504 case kGrayscaleCoverageMask_MaskType: | 1526 case kGrayscaleCoverageMask_MaskType: |
1505 out->setUnknownSingleComponent(); | 1527 out->setUnknownSingleComponent(); |
1506 break; | 1528 break; |
1507 case kLCDCoverageMask_MaskType: | 1529 case kLCDCoverageMask_MaskType: |
1508 case kLCDDistanceField_MaskType: | 1530 case kLCDDistanceField_MaskType: |
1509 out->setUnknownOpaqueFourComponents(); | 1531 out->setUnknownOpaqueFourComponents(); |
1510 out->setUsingLCDCoverage(); | 1532 out->setUsingLCDCoverage(); |
1511 break; | 1533 break; |
1512 case kColorBitmapMask_MaskType: | 1534 case kColorBitmapMask_MaskType: |
1513 out->setKnownSingleComponent(0xff); | 1535 out->setKnownSingleComponent(0xff); |
1514 } | 1536 } |
1515 } | 1537 } |
1516 | 1538 |
| 1539 private: |
1517 void initBatchTracker(const GrPipelineOptimizations& opt) override { | 1540 void initBatchTracker(const GrPipelineOptimizations& opt) override { |
1518 // Handle any color overrides | 1541 // Handle any color overrides |
1519 if (!opt.readsColor()) { | 1542 if (!opt.readsColor()) { |
1520 fGeoData[0].fColor = GrColor_ILLEGAL; | 1543 fGeoData[0].fColor = GrColor_ILLEGAL; |
1521 } | 1544 } |
1522 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 1545 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
1523 | 1546 |
1524 // setup batch properties | 1547 // setup batch properties |
1525 fBatch.fColorIgnored = !opt.readsColor(); | 1548 fBatch.fColorIgnored = !opt.readsColor(); |
1526 fBatch.fColor = fGeoData[0].fColor; | 1549 fBatch.fColor = fGeoData[0].fColor; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 | 1778 |
1756 currVertex += byteCount; | 1779 currVertex += byteCount; |
1757 } | 1780 } |
1758 // Make sure to attach the last cache if applicable | 1781 // Make sure to attach the last cache if applicable |
1759 if (cache) { | 1782 if (cache) { |
1760 SkGlyphCache::AttachCache(cache); | 1783 SkGlyphCache::AttachCache(cache); |
1761 } | 1784 } |
1762 this->flush(target, &flushInfo); | 1785 this->flush(target, &flushInfo); |
1763 } | 1786 } |
1764 | 1787 |
1765 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which | |
1766 // is used to seed the batch with its initial geometry. After seeding, the
client should call | |
1767 // init() so the Batch can initialize itself | |
1768 Geometry& geometry() { return fGeoData[0]; } | |
1769 void init() { | |
1770 const Geometry& geo = fGeoData[0]; | |
1771 fBatch.fColor = geo.fColor; | |
1772 fBatch.fViewMatrix = geo.fBlob->fViewMatrix; | |
1773 | |
1774 // We don't yet position distance field text on the cpu, so we have to m
ap the vertex bounds | |
1775 // into device space | |
1776 const Run& run = geo.fBlob->fRuns[geo.fRun]; | |
1777 if (run.fSubRunInfo[geo.fSubRun].fDrawAsDistanceFields) { | |
1778 SkRect bounds = run.fVertexBounds; | |
1779 fBatch.fViewMatrix.mapRect(&bounds); | |
1780 this->setBounds(bounds); | |
1781 } else { | |
1782 this->setBounds(run.fVertexBounds); | |
1783 } | |
1784 } | |
1785 | |
1786 private: | |
1787 TextBatch() {} // initialized in factory functions. | 1788 TextBatch() {} // initialized in factory functions. |
1788 | 1789 |
1789 ~TextBatch() { | 1790 ~TextBatch() { |
1790 for (int i = 0; i < fGeoCount; i++) { | 1791 for (int i = 0; i < fGeoCount; i++) { |
1791 fGeoData[i].fBlob->unref(); | 1792 fGeoData[i].fBlob->unref(); |
1792 } | 1793 } |
1793 } | 1794 } |
1794 | 1795 |
1795 GrMaskFormat maskFormat() const { | 1796 GrMaskFormat maskFormat() const { |
1796 switch (fMaskType) { | 1797 switch (fMaskType) { |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2279 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2280 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2280 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2281 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2281 | 2282 |
2282 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2283 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2283 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2284 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2284 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2285 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2285 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2286 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2286 } | 2287 } |
2287 | 2288 |
2288 #endif | 2289 #endif |
OLD | NEW |