| 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 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 position = reinterpret_cast<SkPoint*>(vertex); | 1424 position = reinterpret_cast<SkPoint*>(vertex); |
| 1425 position->set(positions.fRight, positions.fTop); | 1425 position->set(positions.fRight, positions.fTop); |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 subRun->fGlyphEndIndex++; | 1428 subRun->fGlyphEndIndex++; |
| 1429 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; | 1429 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 class TextBatch : public GrVertexBatch { | 1432 class TextBatch : public GrVertexBatch { |
| 1433 public: | 1433 public: |
| 1434 DEFINE_BATCH_CLASS_ID |
| 1435 |
| 1434 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; | 1436 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; |
| 1435 typedef GrAtlasTextBlob Blob; | 1437 typedef GrAtlasTextBlob Blob; |
| 1436 typedef Blob::Run Run; | 1438 typedef Blob::Run Run; |
| 1437 typedef Run::SubRunInfo TextInfo; | 1439 typedef Run::SubRunInfo TextInfo; |
| 1438 struct Geometry { | 1440 struct Geometry { |
| 1439 Blob* fBlob; | 1441 Blob* fBlob; |
| 1440 int fRun; | 1442 int fRun; |
| 1441 int fSubRun; | 1443 int fSubRun; |
| 1442 GrColor fColor; | 1444 GrColor fColor; |
| 1443 SkScalar fTransX; | 1445 SkScalar fTransX; |
| 1444 SkScalar fTransY; | 1446 SkScalar fTransY; |
| 1445 }; | 1447 }; |
| 1446 | 1448 |
| 1447 static TextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCount, | 1449 static TextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCount, |
| 1448 GrBatchFontCache* fontCache) { | 1450 GrBatchFontCache* fontCache) { |
| 1449 TextBatch* batch = new TextBatch; | 1451 TextBatch* batch = new TextBatch; |
| 1450 | 1452 |
| 1451 batch->initClassID<TextBatch>(); | |
| 1452 batch->fFontCache = fontCache; | 1453 batch->fFontCache = fontCache; |
| 1453 switch (maskFormat) { | 1454 switch (maskFormat) { |
| 1454 case kA8_GrMaskFormat: | 1455 case kA8_GrMaskFormat: |
| 1455 batch->fMaskType = kGrayscaleCoverageMask_MaskType; | 1456 batch->fMaskType = kGrayscaleCoverageMask_MaskType; |
| 1456 break; | 1457 break; |
| 1457 case kA565_GrMaskFormat: | 1458 case kA565_GrMaskFormat: |
| 1458 batch->fMaskType = kLCDCoverageMask_MaskType; | 1459 batch->fMaskType = kLCDCoverageMask_MaskType; |
| 1459 break; | 1460 break; |
| 1460 case kARGB_GrMaskFormat: | 1461 case kARGB_GrMaskFormat: |
| 1461 batch->fMaskType = kColorBitmapMask_MaskType; | 1462 batch->fMaskType = kColorBitmapMask_MaskType; |
| 1462 break; | 1463 break; |
| 1463 } | 1464 } |
| 1464 batch->fBatch.fNumGlyphs = glyphCount; | 1465 batch->fBatch.fNumGlyphs = glyphCount; |
| 1465 batch->fGeoCount = 1; | 1466 batch->fGeoCount = 1; |
| 1466 batch->fFilteredColor = 0; | 1467 batch->fFilteredColor = 0; |
| 1467 batch->fFontCache = fontCache; | 1468 batch->fFontCache = fontCache; |
| 1468 batch->fUseBGR = false; | 1469 batch->fUseBGR = false; |
| 1469 return batch; | 1470 return batch; |
| 1470 } | 1471 } |
| 1471 | 1472 |
| 1472 static TextBatch* CreateDistanceField(int glyphCount, GrBatchFontCache* font
Cache, | 1473 static TextBatch* CreateDistanceField(int glyphCount, GrBatchFontCache* font
Cache, |
| 1473 const DistanceAdjustTable* distanceAdj
ustTable, | 1474 const DistanceAdjustTable* distanceAdj
ustTable, |
| 1474 SkColor filteredColor, bool isLCD, | 1475 SkColor filteredColor, bool isLCD, |
| 1475 bool useBGR) { | 1476 bool useBGR) { |
| 1476 TextBatch* batch = new TextBatch; | 1477 TextBatch* batch = new TextBatch; |
| 1477 batch->initClassID<TextBatch>(); | 1478 |
| 1478 batch->fFontCache = fontCache; | 1479 batch->fFontCache = fontCache; |
| 1479 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan
ceField_MaskType; | 1480 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan
ceField_MaskType; |
| 1480 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); | 1481 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); |
| 1481 batch->fFilteredColor = filteredColor; | 1482 batch->fFilteredColor = filteredColor; |
| 1482 batch->fUseBGR = useBGR; | 1483 batch->fUseBGR = useBGR; |
| 1483 batch->fBatch.fNumGlyphs = glyphCount; | 1484 batch->fBatch.fNumGlyphs = glyphCount; |
| 1484 batch->fGeoCount = 1; | 1485 batch->fGeoCount = 1; |
| 1485 return batch; | 1486 return batch; |
| 1486 } | 1487 } |
| 1487 | 1488 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 | 1777 |
| 1777 currVertex += byteCount; | 1778 currVertex += byteCount; |
| 1778 } | 1779 } |
| 1779 // Make sure to attach the last cache if applicable | 1780 // Make sure to attach the last cache if applicable |
| 1780 if (cache) { | 1781 if (cache) { |
| 1781 SkGlyphCache::AttachCache(cache); | 1782 SkGlyphCache::AttachCache(cache); |
| 1782 } | 1783 } |
| 1783 this->flush(target, &flushInfo); | 1784 this->flush(target, &flushInfo); |
| 1784 } | 1785 } |
| 1785 | 1786 |
| 1786 TextBatch() {} // initialized in factory functions. | 1787 TextBatch() : INHERITED(ClassID()) {} // initialized in factory functions. |
| 1787 | 1788 |
| 1788 ~TextBatch() { | 1789 ~TextBatch() { |
| 1789 for (int i = 0; i < fGeoCount; i++) { | 1790 for (int i = 0; i < fGeoCount; i++) { |
| 1790 fGeoData[i].fBlob->unref(); | 1791 fGeoData[i].fBlob->unref(); |
| 1791 } | 1792 } |
| 1792 } | 1793 } |
| 1793 | 1794 |
| 1794 GrMaskFormat maskFormat() const { | 1795 GrMaskFormat maskFormat() const { |
| 1795 switch (fMaskType) { | 1796 switch (fMaskType) { |
| 1796 case kLCDCoverageMask_MaskType: | 1797 case kLCDCoverageMask_MaskType: |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 kGrayscaleDistanceField_MaskType, | 2038 kGrayscaleDistanceField_MaskType, |
| 2038 kLCDDistanceField_MaskType, | 2039 kLCDDistanceField_MaskType, |
| 2039 } fMaskType; | 2040 } fMaskType; |
| 2040 bool fUseBGR; // fold this into the enum? | 2041 bool fUseBGR; // fold this into the enum? |
| 2041 | 2042 |
| 2042 GrBatchFontCache* fFontCache; | 2043 GrBatchFontCache* fFontCache; |
| 2043 | 2044 |
| 2044 // Distance field properties | 2045 // Distance field properties |
| 2045 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable; | 2046 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable; |
| 2046 SkColor fFilteredColor; | 2047 SkColor fFilteredColor; |
| 2048 |
| 2049 typedef GrVertexBatch INHERITED; |
| 2047 }; | 2050 }; |
| 2048 | 2051 |
| 2049 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt, | 2052 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt, |
| 2050 const SkTextBlob::RunIterator& it, | 2053 const SkTextBlob::RunIterator& it, |
| 2051 const GrClip& clip, const SkPaint& skPa
int, | 2054 const GrClip& clip, const SkPaint& skPa
int, |
| 2052 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, | 2055 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, |
| 2053 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { | 2056 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { |
| 2054 SkPaint runPaint = skPaint; | 2057 SkPaint runPaint = skPaint; |
| 2055 | 2058 |
| 2056 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 2059 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2279 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
| 2280 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2283 static_cast<size_t>(textLen), 0, 0,
noClip)); |
| 2281 | 2284 |
| 2282 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 2283 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 2284 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
| 2285 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
| 2286 } | 2289 } |
| 2287 | 2290 |
| 2288 #endif | 2291 #endif |
| OLD | NEW |