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 | 7 |
8 #include "GrTextUtils.h" | 8 #include "GrTextUtils.h" |
9 | 9 |
10 #include "GrAtlasTextBlob.h" | 10 #include "GrAtlasTextBlob.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #ifdef SK_BUILD_FOR_ANDROID | 33 #ifdef SK_BUILD_FOR_ANDROID |
34 static const int kLargeDFFontLimit = 384; | 34 static const int kLargeDFFontLimit = 384; |
35 #else | 35 #else |
36 static const int kLargeDFFontLimit = 2 * kLargeDFFontSize; | 36 static const int kLargeDFFontLimit = 2 * kLargeDFFontSize; |
37 #endif | 37 #endif |
38 }; | 38 }; |
39 | 39 |
40 void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, | 40 void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, |
41 GrBatchFontCache* fontCache, | 41 GrBatchFontCache* fontCache, |
42 const SkSurfaceProps& props, const SkPaint& skPain
t, | 42 const SkSurfaceProps& props, const SkPaint& skPain
t, |
43 GrColor color, | 43 GrColor color, SkPaint::FakeGamma fakeGamma, |
44 const SkMatrix& viewMatrix, | 44 const SkMatrix& viewMatrix, |
45 const char text[], size_t byteLength, | 45 const char text[], size_t byteLength, |
46 SkScalar x, SkScalar y) { | 46 SkScalar x, SkScalar y) { |
47 SkASSERT(byteLength == 0 || text != nullptr); | 47 SkASSERT(byteLength == 0 || text != nullptr); |
48 | 48 |
49 // nothing to draw | 49 // nothing to draw |
50 if (text == nullptr || byteLength == 0) { | 50 if (text == nullptr || byteLength == 0) { |
51 return; | 51 return; |
52 } | 52 } |
53 | 53 |
54 // Ensure the blob is set for bitmaptext | 54 // Ensure the blob is set for bitmaptext |
55 blob->setHasBitmap(); | 55 blob->setHasBitmap(); |
56 | 56 |
57 GrBatchTextStrike* currStrike = nullptr; | 57 GrBatchTextStrike* currStrike = nullptr; |
58 | 58 |
59 // Get GrFontScaler from cache | 59 // Get GrFontScaler from cache |
60 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::
On, | 60 SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma, |
61 skPaint, &viewMatrix); | 61 skPaint, &viewMatrix); |
62 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); | 62 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); |
63 | 63 |
64 SkFindAndPlaceGlyph::ProcessText( | 64 SkFindAndPlaceGlyph::ProcessText( |
65 skPaint.getTextEncoding(), text, byteLength, | 65 skPaint.getTextEncoding(), text, byteLength, |
66 {x, y}, viewMatrix, skPaint.getTextAlign(), | 66 {x, y}, viewMatrix, skPaint.getTextAlign(), |
67 cache, | 67 cache, |
68 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { | 68 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
69 position += rounding; | 69 position += rounding; |
70 BmpAppendGlyph( | 70 BmpAppendGlyph( |
71 blob, runIndex, fontCache, &currStrike, glyph, | 71 blob, runIndex, fontCache, &currStrike, glyph, |
72 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, | 72 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, |
73 color, fontScaler); | 73 color, fontScaler); |
74 } | 74 } |
75 ); | 75 ); |
76 | 76 |
77 SkGlyphCache::AttachCache(cache); | 77 SkGlyphCache::AttachCache(cache); |
78 } | 78 } |
79 | 79 |
80 void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, | 80 void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, |
81 GrBatchFontCache* fontCache, | 81 GrBatchFontCache* fontCache, |
82 const SkSurfaceProps& props, const SkPaint& skP
aint, | 82 const SkSurfaceProps& props, const SkPaint& skP
aint, |
83 GrColor color, | 83 GrColor color, SkPaint::FakeGamma fakeGamma, |
84 const SkMatrix& viewMatrix, | 84 const SkMatrix& viewMatrix, |
85 const char text[], size_t byteLength, | 85 const char text[], size_t byteLength, |
86 const SkScalar pos[], int scalarsPerPosition, | 86 const SkScalar pos[], int scalarsPerPosition, |
87 const SkPoint& offset) { | 87 const SkPoint& offset) { |
88 SkASSERT(byteLength == 0 || text != nullptr); | 88 SkASSERT(byteLength == 0 || text != nullptr); |
89 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 89 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
90 | 90 |
91 // nothing to draw | 91 // nothing to draw |
92 if (text == nullptr || byteLength == 0) { | 92 if (text == nullptr || byteLength == 0) { |
93 return; | 93 return; |
94 } | 94 } |
95 | 95 |
96 // Ensure the blob is set for bitmaptext | 96 // Ensure the blob is set for bitmaptext |
97 blob->setHasBitmap(); | 97 blob->setHasBitmap(); |
98 | 98 |
99 GrBatchTextStrike* currStrike = nullptr; | 99 GrBatchTextStrike* currStrike = nullptr; |
100 | 100 |
101 // Get GrFontScaler from cache | 101 // Get GrFontScaler from cache |
102 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::
On, | 102 SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma, |
103 skPaint, &viewMatrix); | 103 skPaint, &viewMatrix); |
104 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); | 104 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); |
105 | 105 |
106 SkFindAndPlaceGlyph::ProcessPosText( | 106 SkFindAndPlaceGlyph::ProcessPosText( |
107 skPaint.getTextEncoding(), text, byteLength, | 107 skPaint.getTextEncoding(), text, byteLength, |
108 offset, viewMatrix, pos, scalarsPerPosition, | 108 offset, viewMatrix, pos, scalarsPerPosition, |
109 skPaint.getTextAlign(), cache, | 109 skPaint.getTextAlign(), cache, |
110 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { | 110 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
111 position += rounding; | 111 position += rounding; |
112 BmpAppendGlyph( | 112 BmpAppendGlyph( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil /
scaledTextSize); | 240 blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil /
scaledTextSize); |
241 | 241 |
242 skPaint->setLCDRenderText(false); | 242 skPaint->setLCDRenderText(false); |
243 skPaint->setAutohinted(false); | 243 skPaint->setAutohinted(false); |
244 skPaint->setHinting(SkPaint::kNormal_Hinting); | 244 skPaint->setHinting(SkPaint::kNormal_Hinting); |
245 skPaint->setSubpixelText(true); | 245 skPaint->setSubpixelText(true); |
246 } | 246 } |
247 | 247 |
248 void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, | 248 void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, |
249 GrBatchFontCache* fontCache, const SkSurfaceProps&
props, | 249 GrBatchFontCache* fontCache, const SkSurfaceProps&
props, |
250 const SkPaint& skPaint, GrColor color, | 250 const SkPaint& skPaint, GrColor color, SkPaint::Fak
eGamma fakeGamma, |
251 const SkMatrix& viewMatrix, | 251 const SkMatrix& viewMatrix, |
252 const char text[], size_t byteLength, | 252 const char text[], size_t byteLength, |
253 SkScalar x, SkScalar y) { | 253 SkScalar x, SkScalar y) { |
254 SkASSERT(byteLength == 0 || text != nullptr); | 254 SkASSERT(byteLength == 0 || text != nullptr); |
255 | 255 |
256 // nothing to draw | 256 // nothing to draw |
257 if (text == nullptr || byteLength == 0) { | 257 if (text == nullptr || byteLength == 0) { |
258 return; | 258 return; |
259 } | 259 } |
260 | 260 |
261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true); | 261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true); |
262 SkAutoDescriptor desc; | 262 SkAutoDescriptor desc; |
| 263 // We apply the fake-gamma by altering the distance in the shader, so we ign
ore the |
| 264 // fakeGamma parameter. (It's only used when we fall-back to bitmap text). |
263 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu
llptr); | 265 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu
llptr); |
264 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface
(), | 266 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface
(), |
265 desc.getDesc()); | 267 desc.getDesc()); |
266 | 268 |
267 SkTArray<SkScalar> positions; | 269 SkTArray<SkScalar> positions; |
268 | 270 |
269 const char* textPtr = text; | 271 const char* textPtr = text; |
270 SkScalar stopX = 0; | 272 SkScalar stopX = 0; |
271 SkScalar stopY = 0; | 273 SkScalar stopY = 0; |
272 SkScalar origin = 0; | 274 SkScalar origin = 0; |
(...skipping 30 matching lines...) Expand all Loading... |
303 alignX = SkScalarHalf(alignX); | 305 alignX = SkScalarHalf(alignX); |
304 alignY = SkScalarHalf(alignY); | 306 alignY = SkScalarHalf(alignY); |
305 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { | 307 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { |
306 alignX = 0; | 308 alignX = 0; |
307 alignY = 0; | 309 alignY = 0; |
308 } | 310 } |
309 x -= alignX; | 311 x -= alignX; |
310 y -= alignY; | 312 y -= alignY; |
311 SkPoint offset = SkPoint::Make(x, y); | 313 SkPoint offset = SkPoint::Make(x, y); |
312 | 314 |
313 DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, viewMatrix,
text, byteLength, | 315 DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, fakeGamma, v
iewMatrix, |
314 positions.begin(), 2, offset); | 316 text, byteLength, positions.begin(), 2, offset); |
315 } | 317 } |
316 | 318 |
317 void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, | 319 void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, |
318 GrBatchFontCache* fontCache, const SkSurfaceProp
s& props, | 320 GrBatchFontCache* fontCache, const SkSurfaceProp
s& props, |
319 const SkPaint& origPaint, | 321 const SkPaint& origPaint, |
320 GrColor color, const SkMatrix& viewMatrix, | 322 GrColor color, SkPaint::FakeGamma fakeGamma, |
| 323 const SkMatrix& viewMatrix, |
321 const char text[], size_t byteLength, | 324 const char text[], size_t byteLength, |
322 const SkScalar pos[], int scalarsPerPosition, | 325 const SkScalar pos[], int scalarsPerPosition, |
323 const SkPoint& offset) { | 326 const SkPoint& offset) { |
324 SkASSERT(byteLength == 0 || text != nullptr); | 327 SkASSERT(byteLength == 0 || text != nullptr); |
325 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 328 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
326 | 329 |
327 // nothing to draw | 330 // nothing to draw |
328 if (text == nullptr || byteLength == 0) { | 331 if (text == nullptr || byteLength == 0) { |
329 return; | 332 return; |
330 } | 333 } |
331 | 334 |
332 SkTDArray<char> fallbackTxt; | 335 SkTDArray<char> fallbackTxt; |
333 SkTDArray<SkScalar> fallbackPos; | 336 SkTDArray<SkScalar> fallbackPos; |
334 | 337 |
335 // Setup distance field paint and text ratio | 338 // Setup distance field paint and text ratio |
336 SkScalar textRatio; | 339 SkScalar textRatio; |
337 SkPaint dfPaint(origPaint); | 340 SkPaint dfPaint(origPaint); |
338 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); | 341 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); |
339 blob->setHasDistanceField(); | 342 blob->setHasDistanceField(); |
340 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); | 343 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); |
341 | 344 |
342 GrBatchTextStrike* currStrike = nullptr; | 345 GrBatchTextStrike* currStrike = nullptr; |
343 | 346 |
| 347 // We apply the fake-gamma by altering the distance in the shader, so we ign
ore the |
| 348 // fakeGamma parameter. (It's only used when we fall-back to bitmap text). |
344 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::
Off, | 349 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::
Off, |
345 dfPaint, nullptr); | 350 dfPaint, nullptr); |
346 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true); | 351 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true); |
347 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); | 352 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); |
348 | 353 |
349 const char* stop = text + byteLength; | 354 const char* stop = text + byteLength; |
350 | 355 |
351 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { | 356 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { |
352 while (text < stop) { | 357 while (text < stop) { |
353 const char* lastText = text; | 358 const char* lastText = text; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 413 } |
409 } | 414 } |
410 pos += scalarsPerPosition; | 415 pos += scalarsPerPosition; |
411 } | 416 } |
412 } | 417 } |
413 | 418 |
414 SkGlyphCache::AttachCache(cache); | 419 SkGlyphCache::AttachCache(cache); |
415 if (fallbackTxt.count()) { | 420 if (fallbackTxt.count()) { |
416 blob->initOverride(runIndex); | 421 blob->initOverride(runIndex); |
417 GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props, | 422 GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props, |
418 origPaint, origPaint.getColor(), viewMatrix, | 423 origPaint, origPaint.getColor(), fakeGamma,
viewMatrix, |
419 fallbackTxt.begin(), fallbackTxt.count(), | 424 fallbackTxt.begin(), fallbackTxt.count(), |
420 fallbackPos.begin(), scalarsPerPosition, off
set); | 425 fallbackPos.begin(), scalarsPerPosition, off
set); |
421 } | 426 } |
422 } | 427 } |
423 | 428 |
424 bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont
Cache* cache, | 429 bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont
Cache* cache, |
425 GrBatchTextStrike** strike, const SkGlyph& skGly
ph, | 430 GrBatchTextStrike** strike, const SkGlyph& skGly
ph, |
426 SkScalar sx, SkScalar sy, GrColor color, | 431 SkScalar sx, SkScalar sy, GrColor color, |
427 GrFontScaler* scaler, | 432 GrFontScaler* scaler, |
428 SkScalar textRatio, const SkMatrix& viewMatrix)
{ | 433 SkScalar textRatio, const SkMatrix& viewMatrix)
{ |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) { | 580 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) { |
576 scaler = (GrFontScaler*)auxData; | 581 scaler = (GrFontScaler*)auxData; |
577 } | 582 } |
578 if (nullptr == scaler) { | 583 if (nullptr == scaler) { |
579 scaler = new GrFontScaler(cache); | 584 scaler = new GrFontScaler(cache); |
580 cache->setAuxProc(glyph_cache_aux_proc, scaler); | 585 cache->setAuxProc(glyph_cache_aux_proc, scaler); |
581 } | 586 } |
582 | 587 |
583 return scaler; | 588 return scaler; |
584 } | 589 } |
OLD | NEW |