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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 unsigned g = SkColorGetG(c); | 92 unsigned g = SkColorGetG(c); |
93 unsigned b = SkColorGetB(c); | 93 unsigned b = SkColorGetB(c); |
94 return GrColorPackRGBA(r, g, b, 0xff); | 94 return GrColorPackRGBA(r, g, b, 0xff); |
95 } | 95 } |
96 | 96 |
97 }; | 97 }; |
98 | 98 |
99 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, | 99 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, |
100 GrDrawContext* drawContext, | 100 GrDrawContext* drawContext, |
101 const SkSurfaceProps& surfaceProps) | 101 const SkSurfaceProps& surfaceProps) |
102 : INHERITED(context, drawContext, surfaceProps) | 102 : INHERITED(context, drawContext, surfaceProps), fDistanceAdjustTable(new Di
stanceAdjustTable) { |
103 , fDistanceAdjustTable(SkNEW(DistanceAdjustTable)) { | |
104 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest | 103 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest |
105 // vertexStride | 104 // vertexStride |
106 static_assert(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCD
TextVASize, | 105 static_assert(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCD
TextVASize, |
107 "vertex_attribute_changed"); | 106 "vertex_attribute_changed"); |
108 fCurrStrike = NULL; | 107 fCurrStrike = NULL; |
109 fCache = context->getTextBlobCache(); | 108 fCache = context->getTextBlobCache(); |
110 } | 109 } |
111 | 110 |
112 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable() { | 111 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable() { |
113 | 112 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 #else | 153 #else |
155 SkScalar contrast = 0.5f; | 154 SkScalar contrast = 0.5f; |
156 #endif | 155 #endif |
157 SkScalar paintGamma = SK_GAMMA_EXPONENT; | 156 SkScalar paintGamma = SK_GAMMA_EXPONENT; |
158 SkScalar deviceGamma = SK_GAMMA_EXPONENT; | 157 SkScalar deviceGamma = SK_GAMMA_EXPONENT; |
159 | 158 |
160 size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, | 159 size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, |
161 &width, &height); | 160 &width, &height); |
162 | 161 |
163 SkASSERT(kExpectedDistanceAdjustTableSize == height); | 162 SkASSERT(kExpectedDistanceAdjustTableSize == height); |
164 fTable = SkNEW_ARRAY(SkScalar, height); | 163 fTable = new SkScalar[height]; |
165 | 164 |
166 SkAutoTArray<uint8_t> data((int)size); | 165 SkAutoTArray<uint8_t> data((int)size); |
167 SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get
()); | 166 SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get
()); |
168 | 167 |
169 // find the inverse points where we cross 0.5 | 168 // find the inverse points where we cross 0.5 |
170 // binsearch might be better, but we only need to do this once on creation | 169 // binsearch might be better, but we only need to do this once on creation |
171 for (int row = 0; row < height; ++row) { | 170 for (int row = 0; row < height; ++row) { |
172 uint8_t* rowPtr = data.get() + row*width; | 171 uint8_t* rowPtr = data.get() + row*width; |
173 for (int col = 0; col < width - 1; ++col) { | 172 for (int col = 0; col < width - 1; ++col) { |
174 if (rowPtr[col] <= 127 && rowPtr[col + 1] >= 128) { | 173 if (rowPtr[col] <= 127 && rowPtr[col + 1] >= 128) { |
(...skipping 12 matching lines...) Expand all Loading... |
187 fTable[row] = d; | 186 fTable[row] = d; |
188 break; | 187 break; |
189 } | 188 } |
190 } | 189 } |
191 } | 190 } |
192 } | 191 } |
193 | 192 |
194 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, | 193 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, |
195 GrDrawContext* drawContext, | 194 GrDrawContext* drawContext, |
196 const SkSurfaceProps& surfaceProp
s) { | 195 const SkSurfaceProps& surfaceProp
s) { |
197 return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, surfaceProps)); | 196 return new GrAtlasTextContext(context, drawContext, surfaceProps); |
198 } | 197 } |
199 | 198 |
200 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, | 199 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, |
201 const GrClip&, | 200 const GrClip&, |
202 const GrPaint&, | 201 const GrPaint&, |
203 const SkPaint& skPaint, | 202 const SkPaint& skPaint, |
204 const SkMatrix& viewMatrix) { | 203 const SkMatrix& viewMatrix) { |
205 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || | 204 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || |
206 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); | 205 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); |
207 } | 206 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 const SkTDArray<char>& fallb
ackTxt, | 672 const SkTDArray<char>& fallb
ackTxt, |
674 const SkTDArray<SkScalar>& f
allbackPos, | 673 const SkTDArray<SkScalar>& f
allbackPos, |
675 int scalarsPerPosition, | 674 int scalarsPerPosition, |
676 const SkPoint& offset, | 675 const SkPoint& offset, |
677 const SkIRect& clipRect) { | 676 const SkIRect& clipRect) { |
678 SkASSERT(fallbackTxt.count()); | 677 SkASSERT(fallbackTxt.count()); |
679 blob->setHasBitmap(); | 678 blob->setHasBitmap(); |
680 Run& run = blob->fRuns[runIndex]; | 679 Run& run = blob->fRuns[runIndex]; |
681 // Push back a new subrun to fill and set the override descriptor | 680 // Push back a new subrun to fill and set the override descriptor |
682 run.push_back(); | 681 run.push_back(); |
683 run.fOverrideDescriptor.reset(SkNEW(SkAutoDescriptor)); | 682 run.fOverrideDescriptor.reset(new SkAutoDescriptor); |
684 skPaint.getScalerContextDescriptor(run.fOverrideDescriptor, | 683 skPaint.getScalerContextDescriptor(run.fOverrideDescriptor, |
685 fSurfaceProps, &viewMatrix, false); | 684 fSurfaceProps, &viewMatrix, false); |
686 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, | 685 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, |
687 run.fOverrideDescriptor->get
Desc()); | 686 run.fOverrideDescriptor->get
Desc()); |
688 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatr
ix, | 687 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatr
ix, |
689 fallbackTxt.begin(), fallbackTxt.count(), | 688 fallbackTxt.begin(), fallbackTxt.count(), |
690 fallbackPos.begin(), scalarsPerPosition, offset
, clipRect); | 689 fallbackPos.begin(), scalarsPerPosition, offset
, clipRect); |
691 SkGlyphCache::AttachCache(cache); | 690 SkGlyphCache::AttachCache(cache); |
692 } | 691 } |
693 | 692 |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph*
glyph, | 1363 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph*
glyph, |
1365 GrFontScaler* scaler, const SkGl
yph& skGlyph, | 1364 GrFontScaler* scaler, const SkGl
yph& skGlyph, |
1366 SkScalar x, SkScalar y, SkScalar
scale, | 1365 SkScalar x, SkScalar y, SkScalar
scale, |
1367 bool applyVM) { | 1366 bool applyVM) { |
1368 if (NULL == glyph->fPath) { | 1367 if (NULL == glyph->fPath) { |
1369 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph); | 1368 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph); |
1370 if (!glyphPath) { | 1369 if (!glyphPath) { |
1371 return; | 1370 return; |
1372 } | 1371 } |
1373 | 1372 |
1374 glyph->fPath = SkNEW_ARGS(SkPath, (*glyphPath)); | 1373 glyph->fPath = new SkPath(*glyphPath); |
1375 } | 1374 } |
1376 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, sc
ale, applyVM)); | 1375 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, sc
ale, applyVM)); |
1377 } | 1376 } |
1378 | 1377 |
1379 inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru
n, | 1378 inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru
n, |
1380 Run::SubRunInfo* subRun, | 1379 Run::SubRunInfo* subRun, |
1381 const SkRect& positions, GrCol
or color, | 1380 const SkRect& positions, GrCol
or color, |
1382 size_t vertexStride, bool useV
ertexColor, | 1381 size_t vertexStride, bool useV
ertexColor, |
1383 GrGlyph* glyph) { | 1382 GrGlyph* glyph) { |
1384 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; | 1383 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 Blob* fBlob; | 1448 Blob* fBlob; |
1450 int fRun; | 1449 int fRun; |
1451 int fSubRun; | 1450 int fSubRun; |
1452 GrColor fColor; | 1451 GrColor fColor; |
1453 SkScalar fTransX; | 1452 SkScalar fTransX; |
1454 SkScalar fTransY; | 1453 SkScalar fTransY; |
1455 }; | 1454 }; |
1456 | 1455 |
1457 static TextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCount, | 1456 static TextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCount, |
1458 GrBatchFontCache* fontCache) { | 1457 GrBatchFontCache* fontCache) { |
1459 TextBatch* batch = SkNEW(TextBatch); | 1458 TextBatch* batch = new TextBatch; |
1460 | 1459 |
1461 batch->initClassID<TextBatch>(); | 1460 batch->initClassID<TextBatch>(); |
1462 batch->fFontCache = fontCache; | 1461 batch->fFontCache = fontCache; |
1463 switch (maskFormat) { | 1462 switch (maskFormat) { |
1464 case kA8_GrMaskFormat: | 1463 case kA8_GrMaskFormat: |
1465 batch->fMaskType = kGrayscaleCoverageMask_MaskType; | 1464 batch->fMaskType = kGrayscaleCoverageMask_MaskType; |
1466 break; | 1465 break; |
1467 case kA565_GrMaskFormat: | 1466 case kA565_GrMaskFormat: |
1468 batch->fMaskType = kLCDCoverageMask_MaskType; | 1467 batch->fMaskType = kLCDCoverageMask_MaskType; |
1469 break; | 1468 break; |
1470 case kARGB_GrMaskFormat: | 1469 case kARGB_GrMaskFormat: |
1471 batch->fMaskType = kColorBitmapMask_MaskType; | 1470 batch->fMaskType = kColorBitmapMask_MaskType; |
1472 break; | 1471 break; |
1473 } | 1472 } |
1474 batch->fBatch.fNumGlyphs = glyphCount; | 1473 batch->fBatch.fNumGlyphs = glyphCount; |
1475 batch->fGeoCount = 1; | 1474 batch->fGeoCount = 1; |
1476 batch->fFilteredColor = 0; | 1475 batch->fFilteredColor = 0; |
1477 batch->fFontCache = fontCache; | 1476 batch->fFontCache = fontCache; |
1478 batch->fUseBGR = false; | 1477 batch->fUseBGR = false; |
1479 return batch; | 1478 return batch; |
1480 } | 1479 } |
1481 | 1480 |
1482 static TextBatch* CreateDistanceField(int glyphCount, GrBatchFontCache* font
Cache, | 1481 static TextBatch* CreateDistanceField(int glyphCount, GrBatchFontCache* font
Cache, |
1483 DistanceAdjustTable* distanceAdjustTab
le, | 1482 DistanceAdjustTable* distanceAdjustTab
le, |
1484 SkColor filteredColor, bool isLCD, | 1483 SkColor filteredColor, bool isLCD, |
1485 bool useBGR) { | 1484 bool useBGR) { |
1486 TextBatch* batch = SkNEW(TextBatch); | 1485 TextBatch* batch = new TextBatch; |
1487 batch->initClassID<TextBatch>(); | 1486 batch->initClassID<TextBatch>(); |
1488 batch->fFontCache = fontCache; | 1487 batch->fFontCache = fontCache; |
1489 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan
ceField_MaskType; | 1488 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan
ceField_MaskType; |
1490 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); | 1489 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); |
1491 batch->fFilteredColor = filteredColor; | 1490 batch->fFilteredColor = filteredColor; |
1492 batch->fUseBGR = useBGR; | 1491 batch->fUseBGR = useBGR; |
1493 batch->fBatch.fNumGlyphs = glyphCount; | 1492 batch->fBatch.fNumGlyphs = glyphCount; |
1494 batch->fGeoCount = 1; | 1493 batch->fGeoCount = 1; |
1495 return batch; | 1494 return batch; |
1496 } | 1495 } |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2230 | 2229 |
2231 #ifdef GR_TEST_UTILS | 2230 #ifdef GR_TEST_UTILS |
2232 | 2231 |
2233 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { | 2232 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { |
2234 static uint32_t gContextID = SK_InvalidGenID; | 2233 static uint32_t gContextID = SK_InvalidGenID; |
2235 static GrAtlasTextContext* gTextContext = NULL; | 2234 static GrAtlasTextContext* gTextContext = NULL; |
2236 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); | 2235 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); |
2237 | 2236 |
2238 if (context->uniqueID() != gContextID) { | 2237 if (context->uniqueID() != gContextID) { |
2239 gContextID = context->uniqueID(); | 2238 gContextID = context->uniqueID(); |
2240 SkDELETE(gTextContext); | 2239 delete gTextContext; |
2241 | 2240 |
2242 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly | 2241 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly |
2243 // because we don't really want to have a gpu device here. | 2242 // because we don't really want to have a gpu device here. |
2244 // We enable distance fields by twiddling a knob on the paint | 2243 // We enable distance fields by twiddling a knob on the paint |
2245 GrDrawContext* drawContext = context->drawContext(&gSurfaceProps); | 2244 GrDrawContext* drawContext = context->drawContext(&gSurfaceProps); |
2246 | 2245 |
2247 gTextContext = GrAtlasTextContext::Create(context, drawContext, gSurface
Props); | 2246 gTextContext = GrAtlasTextContext::Create(context, drawContext, gSurface
Props); |
2248 } | 2247 } |
2249 | 2248 |
2250 // create dummy render target | 2249 // create dummy render target |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2286 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2285 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2287 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2286 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2288 | 2287 |
2289 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2288 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2290 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2289 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2291 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2290 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2292 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2291 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2293 } | 2292 } |
2294 | 2293 |
2295 #endif | 2294 #endif |
OLD | NEW |