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" |
11 #include "GrBatchFontCache.h" | 11 #include "GrBatchFontCache.h" |
12 #include "GrBlurUtils.h" | 12 #include "GrBlurUtils.h" |
13 #include "GrCaps.h" | 13 #include "GrCaps.h" |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrDrawContext.h" | 15 #include "GrDrawContext.h" |
16 #include "GrTextContext.h" | |
17 | 16 |
18 #include "SkDistanceFieldGen.h" | 17 #include "SkDistanceFieldGen.h" |
19 #include "SkDrawProcs.h" | 18 #include "SkDrawProcs.h" |
20 #include "SkFindAndPlaceGlyph.h" | 19 #include "SkFindAndPlaceGlyph.h" |
21 #include "SkGlyphCache.h" | 20 #include "SkGlyphCache.h" |
22 #include "SkPaint.h" | 21 #include "SkPaint.h" |
23 #include "SkRect.h" | 22 #include "SkRect.h" |
24 #include "SkTextMapStateProc.h" | 23 #include "SkTextMapStateProc.h" |
25 #include "SkTextToPathIter.h" | 24 #include "SkTextToPathIter.h" |
26 | 25 |
(...skipping 25 matching lines...) Expand all Loading... |
52 return; | 51 return; |
53 } | 52 } |
54 | 53 |
55 // Ensure the blob is set for bitmaptext | 54 // Ensure the blob is set for bitmaptext |
56 blob->setHasBitmap(); | 55 blob->setHasBitmap(); |
57 | 56 |
58 GrBatchTextStrike* currStrike = nullptr; | 57 GrBatchTextStrike* currStrike = nullptr; |
59 | 58 |
60 // Get GrFontScaler from cache | 59 // Get GrFontScaler from cache |
61 SkGlyphCache* cache = blob->setupCache(runIndex, props, skPaint, &viewMatrix
, false); | 60 SkGlyphCache* cache = blob->setupCache(runIndex, props, skPaint, &viewMatrix
, false); |
62 GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache); | 61 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); |
63 | 62 |
64 SkFindAndPlaceGlyph::ProcessText( | 63 SkFindAndPlaceGlyph::ProcessText( |
65 skPaint.getTextEncoding(), text, byteLength, | 64 skPaint.getTextEncoding(), text, byteLength, |
66 {x, y}, viewMatrix, skPaint.getTextAlign(), | 65 {x, y}, viewMatrix, skPaint.getTextAlign(), |
67 cache, | 66 cache, |
68 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { | 67 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
69 position += rounding; | 68 position += rounding; |
70 BmpAppendGlyph( | 69 BmpAppendGlyph( |
71 blob, runIndex, fontCache, &currStrike, glyph, | 70 blob, runIndex, fontCache, &currStrike, glyph, |
72 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, | 71 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, |
(...skipping 20 matching lines...) Expand all Loading... |
93 return; | 92 return; |
94 } | 93 } |
95 | 94 |
96 // Ensure the blob is set for bitmaptext | 95 // Ensure the blob is set for bitmaptext |
97 blob->setHasBitmap(); | 96 blob->setHasBitmap(); |
98 | 97 |
99 GrBatchTextStrike* currStrike = nullptr; | 98 GrBatchTextStrike* currStrike = nullptr; |
100 | 99 |
101 // Get GrFontScaler from cache | 100 // Get GrFontScaler from cache |
102 SkGlyphCache* cache = blob->setupCache(runIndex, props, skPaint, &viewMatrix
, false); | 101 SkGlyphCache* cache = blob->setupCache(runIndex, props, skPaint, &viewMatrix
, false); |
103 GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache); | 102 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); |
104 | 103 |
105 SkFindAndPlaceGlyph::ProcessPosText( | 104 SkFindAndPlaceGlyph::ProcessPosText( |
106 skPaint.getTextEncoding(), text, byteLength, | 105 skPaint.getTextEncoding(), text, byteLength, |
107 offset, viewMatrix, pos, scalarsPerPosition, | 106 offset, viewMatrix, pos, scalarsPerPosition, |
108 skPaint.getTextAlign(), cache, | 107 skPaint.getTextAlign(), cache, |
109 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { | 108 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
110 position += rounding; | 109 position += rounding; |
111 BmpAppendGlyph( | 110 BmpAppendGlyph( |
112 blob, runIndex, fontCache, &currStrike, glyph, | 111 blob, runIndex, fontCache, &currStrike, glyph, |
113 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, | 112 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY)
, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 SkScalar textRatio; | 334 SkScalar textRatio; |
336 SkPaint dfPaint(origPaint); | 335 SkPaint dfPaint(origPaint); |
337 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); | 336 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); |
338 blob->setHasDistanceField(); | 337 blob->setHasDistanceField(); |
339 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); | 338 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); |
340 | 339 |
341 GrBatchTextStrike* currStrike = nullptr; | 340 GrBatchTextStrike* currStrike = nullptr; |
342 | 341 |
343 SkGlyphCache* cache = blob->setupCache(runIndex, props, dfPaint, nullptr, tr
ue); | 342 SkGlyphCache* cache = blob->setupCache(runIndex, props, dfPaint, nullptr, tr
ue); |
344 SkDrawCacheProc glyphCacheProc = dfPaint.getDrawCacheProc(); | 343 SkDrawCacheProc glyphCacheProc = dfPaint.getDrawCacheProc(); |
345 GrFontScaler* fontScaler = GrTextContext::GetGrFontScaler(cache); | 344 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); |
346 | 345 |
347 const char* stop = text + byteLength; | 346 const char* stop = text + byteLength; |
348 | 347 |
349 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { | 348 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { |
350 while (text < stop) { | 349 while (text < stop) { |
351 const char* lastText = text; | 350 const char* lastText = text; |
352 // the last 2 parameters are ignored | 351 // the last 2 parameters are ignored |
353 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 352 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
354 | 353 |
355 if (glyph.fWidth) { | 354 if (glyph.fWidth) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 528 |
530 matrix[SkMatrix::kMTransX] = loc.fX; | 529 matrix[SkMatrix::kMTransX] = loc.fX; |
531 matrix[SkMatrix::kMTransY] = loc.fY; | 530 matrix[SkMatrix::kMTransY] = loc.fY; |
532 GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, *path, pa
int, | 531 GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, *path, pa
int, |
533 viewMatrix, &matrix, clipBou
nds, false); | 532 viewMatrix, &matrix, clipBou
nds, false); |
534 } | 533 } |
535 } | 534 } |
536 pos += scalarsPerPosition; | 535 pos += scalarsPerPosition; |
537 } | 536 } |
538 } | 537 } |
| 538 |
| 539 bool GrTextUtils::ShouldDisableLCD(const SkPaint& paint) { |
| 540 return !SkXfermode::AsMode(paint.getXfermode(), nullptr) || |
| 541 paint.getMaskFilter() || |
| 542 paint.getRasterizer() || |
| 543 paint.getPathEffect() || |
| 544 paint.isFakeBoldText() || |
| 545 paint.getStyle() != SkPaint::kFill_Style; |
| 546 } |
| 547 |
| 548 uint32_t GrTextUtils::FilterTextFlags(const SkSurfaceProps& surfaceProps, const
SkPaint& paint) { |
| 549 uint32_t flags = paint.getFlags(); |
| 550 |
| 551 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
| 552 return flags; |
| 553 } |
| 554 |
| 555 if (kUnknown_SkPixelGeometry == surfaceProps.pixelGeometry() || ShouldDisabl
eLCD(paint)) { |
| 556 flags &= ~SkPaint::kLCDRenderText_Flag; |
| 557 flags |= SkPaint::kGenA8FromLCD_Flag; |
| 558 } |
| 559 |
| 560 return flags; |
| 561 } |
| 562 |
| 563 static void glyph_cache_aux_proc(void* data) { |
| 564 GrFontScaler* scaler = (GrFontScaler*)data; |
| 565 SkSafeUnref(scaler); |
| 566 } |
| 567 |
| 568 GrFontScaler* GrTextUtils::GetGrFontScaler(SkGlyphCache* cache) { |
| 569 void* auxData; |
| 570 GrFontScaler* scaler = nullptr; |
| 571 |
| 572 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) { |
| 573 scaler = (GrFontScaler*)auxData; |
| 574 } |
| 575 if (nullptr == scaler) { |
| 576 scaler = new GrFontScaler(cache); |
| 577 cache->setAuxProc(glyph_cache_aux_proc, scaler); |
| 578 } |
| 579 |
| 580 return scaler; |
| 581 } |
OLD | NEW |