joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #include "GrAtlasTextContext.h" |
robertphillips | 73c4e64 | 2016-03-02 11:36:59 -0800 | [diff] [blame] | 8 | #include "GrContext.h" |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 9 | #include "GrContextPriv.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 10 | #include "GrTextBlobCache.h" |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 11 | #include "SkDistanceFieldGen.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 12 | #include "SkDraw.h" |
| 13 | #include "SkDrawFilter.h" |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 14 | #include "SkDrawProcs.h" |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 15 | #include "SkFindAndPlaceGlyph.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 16 | #include "SkGr.h" |
Jim Van Verth | c65b65d | 2018-01-16 16:26:35 -0500 | [diff] [blame] | 17 | #include "SkGraphics.h" |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 18 | #include "SkMakeUnique.h" |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 19 | #include "SkMaskFilterBase.h" |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 20 | #include "SkTextMapStateProc.h" |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 21 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 22 | #include "ops/GrMeshDrawOp.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 23 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 24 | // DF sizes and thresholds for usage of the small and medium sizes. For example, above |
| 25 | // kSmallDFFontLimit we will use the medium size. The large size is used up until the size at |
| 26 | // which we switch over to drawing as paths as controlled by Options. |
| 27 | static const int kSmallDFFontSize = 32; |
| 28 | static const int kSmallDFFontLimit = 32; |
Jim Van Verth | 825d4d7 | 2018-01-30 20:37:03 +0000 | [diff] [blame] | 29 | static const int kMediumDFFontSize = 72; |
| 30 | static const int kMediumDFFontLimit = 72; |
| 31 | static const int kLargeDFFontSize = 162; |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 32 | |
| 33 | static const int kDefaultMinDistanceFieldFontSize = 18; |
| 34 | #ifdef SK_BUILD_FOR_ANDROID |
| 35 | static const int kDefaultMaxDistanceFieldFontSize = 384; |
| 36 | #else |
| 37 | static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize; |
| 38 | #endif |
| 39 | |
| 40 | GrAtlasTextContext::GrAtlasTextContext(const Options& options) |
| 41 | : fDistanceAdjustTable(new GrDistanceFieldAdjustTable) { |
| 42 | fMaxDistanceFieldFontSize = options.fMaxDistanceFieldFontSize < 0.f |
| 43 | ? kDefaultMaxDistanceFieldFontSize |
| 44 | : options.fMaxDistanceFieldFontSize; |
| 45 | fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize < 0.f |
| 46 | ? kDefaultMinDistanceFieldFontSize |
| 47 | : options.fMinDistanceFieldFontSize; |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 48 | fDistanceFieldVerticesAlwaysHaveW = options.fDistanceFieldVerticesAlwaysHaveW; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 51 | std::unique_ptr<GrAtlasTextContext> GrAtlasTextContext::Make(const Options& options) { |
| 52 | return std::unique_ptr<GrAtlasTextContext>(new GrAtlasTextContext(options)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 55 | SkColor GrAtlasTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd) { |
| 56 | SkColor canonicalColor = paint.computeLuminanceColor(); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 57 | if (lcd) { |
| 58 | // This is the correct computation, but there are tons of cases where LCD can be overridden. |
| 59 | // For now we just regenerate if any run in a textblob has LCD. |
| 60 | // TODO figure out where all of these overrides are and see if we can incorporate that logic |
| 61 | // at a higher level *OR* use sRGB |
| 62 | SkASSERT(false); |
| 63 | //canonicalColor = SkMaskGamma::CanonicalColor(canonicalColor); |
| 64 | } else { |
| 65 | // A8, though can have mixed BMP text but it shouldn't matter because BMP text won't have |
| 66 | // gamma corrected masks anyways, nor color |
| 67 | U8CPU lum = SkComputeLuminance(SkColorGetR(canonicalColor), |
| 68 | SkColorGetG(canonicalColor), |
| 69 | SkColorGetB(canonicalColor)); |
| 70 | // reduce to our finite number of bits |
| 71 | canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum)); |
| 72 | } |
| 73 | return canonicalColor; |
| 74 | } |
| 75 | |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 76 | SkScalerContextFlags GrAtlasTextContext::ComputeScalerContextFlags( |
| 77 | const GrColorSpaceInfo& colorSpaceInfo) { |
brianosman | 5280dcb | 2016-04-14 06:02:59 -0700 | [diff] [blame] | 78 | // If we're doing gamma-correct rendering, then we can disable the gamma hacks. |
| 79 | // Otherwise, leave them on. In either case, we still want the contrast boost: |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 80 | if (colorSpaceInfo.isGammaCorrect()) { |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 81 | return SkScalerContextFlags::kBoostContrast; |
brianosman | 32f7782 | 2016-04-07 06:25:45 -0700 | [diff] [blame] | 82 | } else { |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 83 | return SkScalerContextFlags::kFakeGammaAndBoostContrast; |
brianosman | 32f7782 | 2016-04-07 06:25:45 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 87 | // TODO if this function ever shows up in profiling, then we can compute this value when the |
| 88 | // textblob is being built and cache it. However, for the time being textblobs mostly only have 1 |
| 89 | // run so this is not a big deal to compute here. |
| 90 | bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { |
halcanary | 3377975 | 2015-10-27 14:01:05 -0700 | [diff] [blame] | 91 | SkTextBlobRunIterator it(blob); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 92 | for (; !it.done(); it.next()) { |
| 93 | if (it.isLCD()) { |
| 94 | return true; |
| 95 | } |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 100 | void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* target, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 101 | const GrClip& clip, const SkPaint& skPaint, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 102 | const SkMatrix& viewMatrix, const SkSurfaceProps& props, |
| 103 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 104 | SkDrawFilter* drawFilter, const SkIRect& clipBounds) { |
joshualitt | 9b8e79e | 2015-04-24 09:57:12 -0700 | [diff] [blame] | 105 | // If we have been abandoned, then don't draw |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 106 | if (context->abandoned()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 110 | sk_sp<GrAtlasTextBlob> cacheBlob; |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 111 | SkMaskFilterBase::BlurRec blurRec; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 112 | GrAtlasTextBlob::Key key; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 113 | // It might be worth caching these things, but its not clear at this time |
| 114 | // TODO for animated mask filters, this will fill up our cache. We need a safeguard here |
| 115 | const SkMaskFilter* mf = skPaint.getMaskFilter(); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 116 | bool canCache = !(skPaint.getPathEffect() || |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 117 | (mf && !as_MFB(mf)->asABlur(&blurRec)) || |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 118 | drawFilter); |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 119 | SkScalerContextFlags scalerContextFlags = ComputeScalerContextFlags(target->colorSpaceInfo()); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 120 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 121 | auto glyphCache = context->contextPriv().getGlyphCache(); |
| 122 | auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 123 | GrTextBlobCache* textBlobCache = context->contextPriv().getTextBlobCache(); |
| 124 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 125 | if (canCache) { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 126 | bool hasLCD = HasLCD(blob); |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 127 | |
| 128 | // We canonicalize all non-lcd draws to use kUnknown_SkPixelGeometry |
joshualitt | 2c89bc1 | 2016-02-11 05:42:30 -0800 | [diff] [blame] | 129 | SkPixelGeometry pixelGeometry = hasLCD ? props.pixelGeometry() : |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 130 | kUnknown_SkPixelGeometry; |
| 131 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 132 | // TODO we want to figure out a way to be able to use the canonical color on LCD text, |
| 133 | // see the note on ComputeCanonicalColor above. We pick a dummy value for LCD text to |
| 134 | // ensure we always match the same key |
| 135 | GrColor canonicalColor = hasLCD ? SK_ColorTRANSPARENT : |
| 136 | ComputeCanonicalColor(skPaint, hasLCD); |
| 137 | |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 138 | key.fPixelGeometry = pixelGeometry; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 139 | key.fUniqueID = blob->uniqueID(); |
| 140 | key.fStyle = skPaint.getStyle(); |
| 141 | key.fHasBlur = SkToBool(mf); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 142 | key.fCanonicalColor = canonicalColor; |
brianosman | 8d7ffce | 2016-04-21 08:29:06 -0700 | [diff] [blame] | 143 | key.fScalerContextFlags = scalerContextFlags; |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 144 | cacheBlob = textBlobCache->find(key); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 147 | GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 148 | if (cacheBlob) { |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 149 | if (cacheBlob->mustRegenerate(paint, blurRec, viewMatrix, x, y)) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 150 | // We have to remake the blob because changes may invalidate our masks. |
| 151 | // TODO we could probably get away reuse most of the time if the pointer is unique, |
| 152 | // but we'd have to clear the subrun information |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 153 | textBlobCache->remove(cacheBlob.get()); |
| 154 | cacheBlob = textBlobCache->makeCachedBlob(blob, key, blurRec, skPaint); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 155 | this->regenerateTextBlob(cacheBlob.get(), glyphCache, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 156 | *context->caps()->shaderCaps(), paint, scalerContextFlags, |
| 157 | viewMatrix, props, blob, x, y, drawFilter); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 158 | } else { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 159 | textBlobCache->makeMRU(cacheBlob.get()); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 160 | |
| 161 | if (CACHE_SANITY_CHECK) { |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 162 | int glyphCount = 0; |
| 163 | int runCount = 0; |
| 164 | GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 165 | sk_sp<GrAtlasTextBlob> sanityBlob(textBlobCache->makeBlob(glyphCount, runCount)); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 166 | sanityBlob->setupKey(key, blurRec, skPaint); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 167 | this->regenerateTextBlob(sanityBlob.get(), glyphCache, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 168 | *context->caps()->shaderCaps(), paint, scalerContextFlags, |
| 169 | viewMatrix, props, blob, x, y, drawFilter); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 170 | GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob); |
| 171 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 172 | } |
| 173 | } else { |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 174 | if (canCache) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 175 | cacheBlob = textBlobCache->makeCachedBlob(blob, key, blurRec, skPaint); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 176 | } else { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 177 | cacheBlob = textBlobCache->makeBlob(blob); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 178 | } |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 179 | this->regenerateTextBlob(cacheBlob.get(), glyphCache, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 180 | *context->caps()->shaderCaps(), paint, scalerContextFlags, |
| 181 | viewMatrix, props, blob, x, y, drawFilter); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 184 | cacheBlob->flush(restrictedAtlasManager, target, props, fDistanceAdjustTable.get(), paint, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 185 | clip, viewMatrix, clipBounds, x, y); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 188 | void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 189 | GrGlyphCache* glyphCache, |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 190 | const GrShaderCaps& shaderCaps, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 191 | const GrTextUtils::Paint& paint, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 192 | SkScalerContextFlags scalerContextFlags, |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 193 | const SkMatrix& viewMatrix, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 194 | const SkSurfaceProps& props, const SkTextBlob* blob, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 195 | SkScalar x, SkScalar y, |
| 196 | SkDrawFilter* drawFilter) const { |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 197 | cacheBlob->initReusableBlob(paint.luminanceColor(), viewMatrix, x, y); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 198 | |
| 199 | // Regenerate textblob |
halcanary | 3377975 | 2015-10-27 14:01:05 -0700 | [diff] [blame] | 200 | SkTextBlobRunIterator it(blob); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 201 | GrTextUtils::RunPaint runPaint(&paint, drawFilter, props); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 202 | for (int run = 0; !it.done(); it.next(), run++) { |
| 203 | int glyphCount = it.glyphCount(); |
| 204 | size_t textLen = glyphCount * sizeof(uint16_t); |
| 205 | const SkPoint& offset = it.offset(); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 206 | cacheBlob->push_back_run(run); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 207 | if (!runPaint.modifyForRun([it](SkPaint* p) { it.applyFontToPaint(p); })) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 208 | continue; |
| 209 | } |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 210 | cacheBlob->setRunPaintFlags(run, runPaint.skPaint().getFlags()); |
| 211 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 212 | if (this->canDrawAsDistanceFields(runPaint, viewMatrix, props, shaderCaps)) { |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 213 | switch (it.positioning()) { |
| 214 | case SkTextBlob::kDefault_Positioning: { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 215 | this->drawDFText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 216 | viewMatrix, (const char*)it.glyphs(), textLen, x + offset.x(), |
| 217 | y + offset.y()); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | case SkTextBlob::kHorizontal_Positioning: { |
joshualitt | 5425a9a | 2015-12-11 11:05:43 -0800 | [diff] [blame] | 221 | SkPoint dfOffset = SkPoint::Make(x, y + offset.y()); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 222 | this->drawDFPosText(cacheBlob, run, glyphCache, props, runPaint, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 223 | scalerContextFlags, viewMatrix, (const char*)it.glyphs(), |
| 224 | textLen, it.pos(), 1, dfOffset); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 225 | break; |
| 226 | } |
| 227 | case SkTextBlob::kFull_Positioning: { |
joshualitt | 5425a9a | 2015-12-11 11:05:43 -0800 | [diff] [blame] | 228 | SkPoint dfOffset = SkPoint::Make(x, y); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 229 | this->drawDFPosText(cacheBlob, run, glyphCache, props, runPaint, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 230 | scalerContextFlags, viewMatrix, (const char*)it.glyphs(), |
| 231 | textLen, it.pos(), 2, dfOffset); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | } |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 235 | } else { |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 236 | switch (it.positioning()) { |
| 237 | case SkTextBlob::kDefault_Positioning: |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 238 | DrawBmpText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 239 | viewMatrix, (const char*)it.glyphs(), textLen, x + offset.x(), |
| 240 | y + offset.y()); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 241 | break; |
| 242 | case SkTextBlob::kHorizontal_Positioning: |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 243 | DrawBmpPosText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 244 | viewMatrix, (const char*)it.glyphs(), textLen, it.pos(), 1, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 245 | SkPoint::Make(x, y + offset.y())); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 246 | break; |
| 247 | case SkTextBlob::kFull_Positioning: |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 248 | DrawBmpPosText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 249 | viewMatrix, (const char*)it.glyphs(), textLen, it.pos(), 2, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 250 | SkPoint::Make(x, y)); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 251 | break; |
| 252 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 253 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 257 | inline sk_sp<GrAtlasTextBlob> |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 258 | GrAtlasTextContext::makeDrawTextBlob(GrTextBlobCache* blobCache, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 259 | GrGlyphCache* glyphCache, |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 260 | const GrShaderCaps& shaderCaps, |
| 261 | const GrTextUtils::Paint& paint, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 262 | SkScalerContextFlags scalerContextFlags, |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 263 | const SkMatrix& viewMatrix, |
| 264 | const SkSurfaceProps& props, |
| 265 | const char text[], size_t byteLength, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 266 | SkScalar x, SkScalar y) const { |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 267 | int glyphCount = paint.skPaint().countText(text, byteLength); |
Brian Salomon | b3f6ac4 | 2017-07-31 08:00:25 -0400 | [diff] [blame] | 268 | if (!glyphCount) { |
| 269 | return nullptr; |
| 270 | } |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 271 | sk_sp<GrAtlasTextBlob> blob = blobCache->makeBlob(glyphCount, 1); |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 272 | blob->initThrowawayBlob(viewMatrix, x, y); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 273 | blob->setRunPaintFlags(0, paint.skPaint().getFlags()); |
joshualitt | a6bf4c5 | 2016-01-19 06:59:29 -0800 | [diff] [blame] | 274 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 275 | if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 276 | this->drawDFText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 277 | text, byteLength, x, y); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 278 | } else { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 279 | DrawBmpText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix, text, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 280 | byteLength, x, y); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 281 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 282 | return blob; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 285 | inline sk_sp<GrAtlasTextBlob> |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 286 | GrAtlasTextContext::makeDrawPosTextBlob(GrTextBlobCache* blobCache, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 287 | GrGlyphCache* glyphCache, |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 288 | const GrShaderCaps& shaderCaps, |
| 289 | const GrTextUtils::Paint& paint, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 290 | SkScalerContextFlags scalerContextFlags, |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 291 | const SkMatrix& viewMatrix, |
| 292 | const SkSurfaceProps& props, |
| 293 | const char text[], size_t byteLength, |
| 294 | const SkScalar pos[], int scalarsPerPosition, const |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 295 | SkPoint& offset) const { |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 296 | int glyphCount = paint.skPaint().countText(text, byteLength); |
Brian Salomon | b3f6ac4 | 2017-07-31 08:00:25 -0400 | [diff] [blame] | 297 | if (!glyphCount) { |
| 298 | return nullptr; |
| 299 | } |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 300 | |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 301 | sk_sp<GrAtlasTextBlob> blob = blobCache->makeBlob(glyphCount, 1); |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 302 | blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y()); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 303 | blob->setRunPaintFlags(0, paint.skPaint().getFlags()); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 304 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 305 | if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 306 | this->drawDFPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 307 | text, byteLength, pos, scalarsPerPosition, offset); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 308 | } else { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 309 | DrawBmpPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix, |
| 310 | text, byteLength, pos, scalarsPerPosition, offset); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 311 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 312 | return blob; |
| 313 | } |
| 314 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 315 | void GrAtlasTextContext::drawText(GrContext* context, GrTextUtils::Target* target, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 316 | const GrClip& clip, const SkPaint& skPaint, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 317 | const SkMatrix& viewMatrix, const SkSurfaceProps& props, |
| 318 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 319 | const SkIRect& regionClipBounds) { |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 320 | if (context->abandoned()) { |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 321 | return; |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 322 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 323 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 324 | auto glyphCache = context->contextPriv().getGlyphCache(); |
| 325 | auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 326 | auto textBlobCache = context->contextPriv().getTextBlobCache(); |
| 327 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 328 | GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 329 | sk_sp<GrAtlasTextBlob> blob( |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 330 | this->makeDrawTextBlob(textBlobCache, glyphCache, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 331 | *context->caps()->shaderCaps(), paint, |
| 332 | ComputeScalerContextFlags(target->colorSpaceInfo()), |
| 333 | viewMatrix, props, text, byteLength, x, y)); |
| 334 | if (blob) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 335 | blob->flush(restrictedAtlasManager, target, props, fDistanceAdjustTable.get(), paint, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 336 | clip, viewMatrix, regionClipBounds, x, y); |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 337 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 340 | void GrAtlasTextContext::drawPosText(GrContext* context, GrTextUtils::Target* target, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 341 | const GrClip& clip, const SkPaint& skPaint, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 342 | const SkMatrix& viewMatrix, const SkSurfaceProps& props, |
| 343 | const char text[], size_t byteLength, const SkScalar pos[], |
| 344 | int scalarsPerPosition, const SkPoint& offset, |
| 345 | const SkIRect& regionClipBounds) { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 346 | GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 347 | if (context->abandoned()) { |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 348 | return; |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 349 | } |
| 350 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 351 | auto glyphCache = context->contextPriv().getGlyphCache(); |
| 352 | auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 353 | auto textBlobCache = context->contextPriv().getTextBlobCache(); |
| 354 | |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 355 | sk_sp<GrAtlasTextBlob> blob(this->makeDrawPosTextBlob( |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 356 | textBlobCache, glyphCache, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 357 | *context->caps()->shaderCaps(), paint, |
| 358 | ComputeScalerContextFlags(target->colorSpaceInfo()), viewMatrix, props, text, |
| 359 | byteLength, pos, scalarsPerPosition, offset)); |
| 360 | if (blob) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 361 | blob->flush(restrictedAtlasManager, target, props, fDistanceAdjustTable.get(), paint, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 362 | clip, viewMatrix, regionClipBounds, offset.fX, offset.fY); |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 363 | } |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 366 | void GrAtlasTextContext::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 367 | GrGlyphCache* glyphCache, const SkSurfaceProps& props, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 368 | const GrTextUtils::Paint& paint, |
| 369 | SkScalerContextFlags scalerContextFlags, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 370 | const SkMatrix& viewMatrix, const char text[], |
| 371 | size_t byteLength, SkScalar x, SkScalar y) { |
| 372 | SkASSERT(byteLength == 0 || text != nullptr); |
| 373 | |
| 374 | // nothing to draw |
| 375 | if (text == nullptr || byteLength == 0) { |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | // Ensure the blob is set for bitmaptext |
| 380 | blob->setHasBitmap(); |
| 381 | |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 382 | if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 383 | DrawBmpTextAsPaths(blob, runIndex, glyphCache, props, paint, scalerContextFlags, viewMatrix, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 384 | text, byteLength, x, y); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 385 | return; |
| 386 | } |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 387 | |
| 388 | sk_sp<GrTextStrike> currStrike; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 389 | SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); |
| 390 | SkFindAndPlaceGlyph::ProcessText(paint.skPaint().getTextEncoding(), text, byteLength, {x, y}, |
| 391 | viewMatrix, paint.skPaint().getTextAlign(), cache, |
| 392 | [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
| 393 | position += rounding; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 394 | BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, |
Jim Van Verth | c65b65d | 2018-01-16 16:26:35 -0500 | [diff] [blame] | 395 | glyph, SkScalarFloorToScalar(position.fX), |
| 396 | SkScalarFloorToScalar(position.fY), |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 397 | paint.filteredPremulColor(), cache, |
| 398 | SK_Scalar1); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 399 | }); |
| 400 | |
| 401 | SkGlyphCache::AttachCache(cache); |
| 402 | } |
| 403 | |
| 404 | void GrAtlasTextContext::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 405 | GrGlyphCache* glyphCache, const SkSurfaceProps& props, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 406 | const GrTextUtils::Paint& paint, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 407 | SkScalerContextFlags scalerContextFlags, |
| 408 | const SkMatrix& viewMatrix, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 409 | const char text[], size_t byteLength, const SkScalar pos[], |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 410 | int scalarsPerPosition, const SkPoint& offset) { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 411 | SkASSERT(byteLength == 0 || text != nullptr); |
| 412 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 413 | |
| 414 | // nothing to draw |
| 415 | if (text == nullptr || byteLength == 0) { |
| 416 | return; |
| 417 | } |
| 418 | |
| 419 | // Ensure the blob is set for bitmaptext |
| 420 | blob->setHasBitmap(); |
| 421 | |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 422 | if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 423 | DrawBmpPosTextAsPaths(blob, runIndex, glyphCache, props, paint, scalerContextFlags, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 424 | viewMatrix, text, byteLength, pos, scalarsPerPosition, offset); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 428 | sk_sp<GrTextStrike> currStrike; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 429 | SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 430 | SkFindAndPlaceGlyph::ProcessPosText( |
| 431 | paint.skPaint().getTextEncoding(), text, byteLength, offset, viewMatrix, pos, |
| 432 | scalarsPerPosition, paint.skPaint().getTextAlign(), cache, |
| 433 | [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
| 434 | position += rounding; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 435 | BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, |
Jim Van Verth | c65b65d | 2018-01-16 16:26:35 -0500 | [diff] [blame] | 436 | SkScalarFloorToScalar(position.fX), |
| 437 | SkScalarFloorToScalar(position.fY), |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 438 | paint.filteredPremulColor(), cache, SK_Scalar1); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 439 | }); |
| 440 | |
| 441 | SkGlyphCache::AttachCache(cache); |
| 442 | } |
| 443 | |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 444 | void GrAtlasTextContext::DrawBmpTextAsPaths(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 445 | GrGlyphCache* glyphCache, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 446 | const SkSurfaceProps& props, |
| 447 | const GrTextUtils::Paint& origPaint, |
| 448 | SkScalerContextFlags scalerContextFlags, |
| 449 | const SkMatrix& viewMatrix, const char text[], |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 450 | size_t byteLength, SkScalar x, SkScalar y) { |
| 451 | // nothing to draw |
| 452 | if (text == nullptr || byteLength == 0) { |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 457 | SkPaint pathPaint(origPaint); |
| 458 | pathPaint.setStyle(SkPaint::kFill_Style); |
| 459 | pathPaint.setPathEffect(nullptr); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 460 | |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 461 | GrTextUtils::PathTextIter iter(text, byteLength, pathPaint, true); |
Jim Van Verth | 080a928 | 2018-03-02 10:41:43 -0500 | [diff] [blame^] | 462 | FallbackTextHelper fallbackTextHelper(viewMatrix, pathPaint, glyphCache, iter.getPathScale()); |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 463 | |
| 464 | const SkGlyph* iterGlyph; |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 465 | const SkPath* iterPath; |
| 466 | SkScalar xpos = 0; |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 467 | const char* lastText = text; |
| 468 | while (iter.next(&iterGlyph, &iterPath, &xpos)) { |
| 469 | if (iterGlyph) { |
| 470 | SkPoint pos = SkPoint::Make(xpos + x, y); |
| 471 | fallbackTextHelper.appendText(*iterGlyph, iter.getText() - lastText, lastText, pos); |
| 472 | } else if (iterPath) { |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 473 | blob->appendPathGlyph(runIndex, *iterPath, xpos + x, y, iter.getPathScale(), false); |
| 474 | } |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 475 | lastText = iter.getText(); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 476 | } |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 477 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 478 | fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | void GrAtlasTextContext::DrawBmpPosTextAsPaths(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 482 | GrGlyphCache* glyphCache, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 483 | const SkSurfaceProps& props, |
| 484 | const GrTextUtils::Paint& origPaint, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 485 | SkScalerContextFlags scalerContextFlags, |
| 486 | const SkMatrix& viewMatrix, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 487 | const char text[], size_t byteLength, |
| 488 | const SkScalar pos[], int scalarsPerPosition, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 489 | const SkPoint& offset) { |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 490 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 491 | |
| 492 | // nothing to draw |
| 493 | if (text == nullptr || byteLength == 0) { |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | // setup our std paint, in hopes of getting hits in the cache |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 498 | SkPaint pathPaint(origPaint); |
| 499 | SkScalar matrixScale = pathPaint.setupForAsPaths(); |
Jim Van Verth | 080a928 | 2018-03-02 10:41:43 -0500 | [diff] [blame^] | 500 | FallbackTextHelper fallbackTextHelper(viewMatrix, origPaint, glyphCache, matrixScale); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 501 | |
| 502 | // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 503 | pathPaint.setStyle(SkPaint::kFill_Style); |
| 504 | pathPaint.setPathEffect(nullptr); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 505 | |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 506 | SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(pathPaint.getTextEncoding(), |
| 507 | pathPaint.isDevKernText(), |
| 508 | true); |
| 509 | SkAutoGlyphCache autoCache(pathPaint, &props, nullptr); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 510 | SkGlyphCache* cache = autoCache.getCache(); |
| 511 | |
| 512 | const char* stop = text + byteLength; |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 513 | const char* lastText = text; |
| 514 | SkTextAlignProc alignProc(pathPaint.getTextAlign()); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 515 | SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
| 516 | |
| 517 | while (text < stop) { |
| 518 | const SkGlyph& glyph = glyphCacheProc(cache, &text); |
| 519 | if (glyph.fWidth) { |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 520 | SkPoint tmsLoc; |
| 521 | tmsProc(pos, &tmsLoc); |
| 522 | SkPoint loc; |
| 523 | alignProc(tmsLoc, glyph, &loc); |
| 524 | if (SkMask::kARGB32_Format == glyph.fMaskFormat) { |
| 525 | fallbackTextHelper.appendText(glyph, text - lastText, lastText, loc); |
| 526 | } else { |
| 527 | const SkPath* path = cache->findPath(glyph); |
| 528 | if (path) { |
| 529 | blob->appendPathGlyph(runIndex, *path, loc.fX, loc.fY, matrixScale, false); |
| 530 | } |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 531 | } |
| 532 | } |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 533 | lastText = text; |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 534 | pos += scalarsPerPosition; |
| 535 | } |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 536 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 537 | fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 538 | } |
| 539 | |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 540 | void GrAtlasTextContext::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 541 | GrGlyphCache* grGlyphCache, |
| 542 | sk_sp<GrTextStrike>* strike, |
Jim Van Verth | c65b65d | 2018-01-16 16:26:35 -0500 | [diff] [blame] | 543 | const SkGlyph& skGlyph, SkScalar sx, SkScalar sy, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 544 | GrColor color, SkGlyphCache* skGlyphCache, |
Jim Van Verth | c65b65d | 2018-01-16 16:26:35 -0500 | [diff] [blame] | 545 | SkScalar textRatio) { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 546 | if (!*strike) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 547 | *strike = grGlyphCache->getStrike(skGlyphCache); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), |
| 551 | skGlyph.getSubXFixed(), |
| 552 | skGlyph.getSubYFixed(), |
| 553 | GrGlyph::kCoverage_MaskStyle); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 554 | GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 555 | if (!glyph) { |
| 556 | return; |
| 557 | } |
| 558 | |
Jim Van Verth | c65b65d | 2018-01-16 16:26:35 -0500 | [diff] [blame] | 559 | SkASSERT(skGlyph.fWidth == glyph->width()); |
| 560 | SkASSERT(skGlyph.fHeight == glyph->height()); |
| 561 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 562 | SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft); |
| 563 | SkScalar dy = SkIntToScalar(glyph->fBounds.fTop); |
| 564 | SkScalar width = SkIntToScalar(glyph->fBounds.width()); |
| 565 | SkScalar height = SkIntToScalar(glyph->fBounds.height()); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 566 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 567 | dx *= textRatio; |
| 568 | dy *= textRatio; |
| 569 | width *= textRatio; |
| 570 | height *= textRatio; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 571 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 572 | SkRect glyphRect = SkRect::MakeXYWH(sx + dx, sy + dy, width, height); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 573 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 574 | blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, skGlyphCache, skGlyph, sx, sy, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 575 | textRatio, true); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 576 | } |
| 577 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 578 | bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 579 | const SkSurfaceProps& props, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 580 | const GrShaderCaps& caps) const { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 581 | if (!viewMatrix.hasPerspective()) { |
| 582 | SkScalar maxScale = viewMatrix.getMaxScale(); |
| 583 | SkScalar scaledTextSize = maxScale * skPaint.getTextSize(); |
| 584 | // Hinted text looks far better at small resolutions |
| 585 | // Scaling up beyond 2x yields undesireable artifacts |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 586 | if (scaledTextSize < fMinDistanceFieldFontSize || |
| 587 | scaledTextSize > fMaxDistanceFieldFontSize) { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 588 | return false; |
| 589 | } |
| 590 | |
| 591 | bool useDFT = props.isUseDeviceIndependentFonts(); |
| 592 | #if SK_FORCE_DISTANCE_FIELD_TEXT |
| 593 | useDFT = true; |
| 594 | #endif |
| 595 | |
| 596 | if (!useDFT && scaledTextSize < kLargeDFFontSize) { |
| 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 601 | // mask filters modify alpha, which doesn't translate well to distance |
| 602 | if (skPaint.getMaskFilter() || !caps.shaderDerivativeSupport()) { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 603 | return false; |
| 604 | } |
| 605 | |
| 606 | // TODO: add some stroking support |
| 607 | if (skPaint.getStyle() != SkPaint::kFill_Style) { |
| 608 | return false; |
| 609 | } |
| 610 | |
| 611 | return true; |
| 612 | } |
| 613 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 614 | void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 615 | SkPaint* skPaint, |
| 616 | SkScalar* textRatio, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 617 | const SkMatrix& viewMatrix) const { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 618 | SkScalar textSize = skPaint->getTextSize(); |
| 619 | SkScalar scaledTextSize = textSize; |
| 620 | |
| 621 | if (viewMatrix.hasPerspective()) { |
| 622 | // for perspective, we simply force to the medium size |
| 623 | // TODO: compute a size based on approximate screen area |
| 624 | scaledTextSize = kMediumDFFontLimit; |
| 625 | } else { |
| 626 | SkScalar maxScale = viewMatrix.getMaxScale(); |
| 627 | // if we have non-unity scale, we need to choose our base text size |
| 628 | // based on the SkPaint's text size multiplied by the max scale factor |
| 629 | // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? |
| 630 | if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { |
| 631 | scaledTextSize *= maxScale; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | // We have three sizes of distance field text, and within each size 'bucket' there is a floor |
| 636 | // and ceiling. A scale outside of this range would require regenerating the distance fields |
| 637 | SkScalar dfMaskScaleFloor; |
| 638 | SkScalar dfMaskScaleCeil; |
| 639 | if (scaledTextSize <= kSmallDFFontLimit) { |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 640 | dfMaskScaleFloor = fMinDistanceFieldFontSize; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 641 | dfMaskScaleCeil = kSmallDFFontLimit; |
| 642 | *textRatio = textSize / kSmallDFFontSize; |
| 643 | skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 644 | } else if (scaledTextSize <= kMediumDFFontLimit) { |
| 645 | dfMaskScaleFloor = kSmallDFFontLimit; |
| 646 | dfMaskScaleCeil = kMediumDFFontLimit; |
| 647 | *textRatio = textSize / kMediumDFFontSize; |
| 648 | skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 649 | } else { |
| 650 | dfMaskScaleFloor = kMediumDFFontLimit; |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 651 | dfMaskScaleCeil = fMaxDistanceFieldFontSize; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 652 | *textRatio = textSize / kLargeDFFontSize; |
| 653 | skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 654 | } |
| 655 | |
| 656 | // Because there can be multiple runs in the blob, we want the overall maxMinScale, and |
| 657 | // minMaxScale to make regeneration decisions. Specifically, we want the maximum minimum scale |
| 658 | // we can tolerate before we'd drop to a lower mip size, and the minimum maximum scale we can |
| 659 | // tolerate before we'd have to move to a large mip size. When we actually test these values |
| 660 | // we look at the delta in scale between the new viewmatrix and the old viewmatrix, and test |
| 661 | // against these values to decide if we can reuse or not(ie, will a given scale change our mip |
| 662 | // level) |
| 663 | SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil); |
| 664 | blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize); |
| 665 | |
| 666 | skPaint->setAntiAlias(true); |
| 667 | skPaint->setLCDRenderText(false); |
| 668 | skPaint->setAutohinted(false); |
| 669 | skPaint->setHinting(SkPaint::kNormal_Hinting); |
| 670 | skPaint->setSubpixelText(true); |
| 671 | } |
| 672 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 673 | void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 674 | GrGlyphCache* glyphCache, const SkSurfaceProps& props, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 675 | const GrTextUtils::Paint& paint, |
| 676 | SkScalerContextFlags scalerContextFlags, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 677 | const SkMatrix& viewMatrix, const char text[], |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 678 | size_t byteLength, SkScalar x, SkScalar y) const { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 679 | SkASSERT(byteLength == 0 || text != nullptr); |
| 680 | |
| 681 | // nothing to draw |
| 682 | if (text == nullptr || byteLength == 0) { |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | const SkPaint& skPaint = paint.skPaint(); |
| 687 | SkPaint::GlyphCacheProc glyphCacheProc = |
| 688 | SkPaint::GetGlyphCacheProc(skPaint.getTextEncoding(), skPaint.isDevKernText(), true); |
| 689 | SkAutoDescriptor desc; |
| 690 | SkScalerContextEffects effects; |
| 691 | // We apply the fake-gamma by altering the distance in the shader, so we ignore the |
| 692 | // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). |
Herb Derby | 980a48d | 2018-01-23 13:39:21 -0500 | [diff] [blame] | 693 | SkScalerContext::CreateDescriptorAndEffectsUsingPaint( |
| 694 | skPaint, &props, SkScalerContextFlags::kNone, nullptr, &desc, &effects); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 695 | SkGlyphCache* origPaintCache = |
| 696 | SkGlyphCache::DetachCache(skPaint.getTypeface(), effects, desc.getDesc()); |
| 697 | |
| 698 | SkTArray<SkScalar> positions; |
| 699 | |
| 700 | const char* textPtr = text; |
| 701 | SkScalar stopX = 0; |
| 702 | SkScalar stopY = 0; |
| 703 | SkScalar origin = 0; |
| 704 | switch (skPaint.getTextAlign()) { |
| 705 | case SkPaint::kRight_Align: origin = SK_Scalar1; break; |
| 706 | case SkPaint::kCenter_Align: origin = SK_ScalarHalf; break; |
| 707 | case SkPaint::kLeft_Align: origin = 0; break; |
| 708 | } |
| 709 | |
| 710 | SkAutoKern autokern; |
| 711 | const char* stop = text + byteLength; |
| 712 | while (textPtr < stop) { |
| 713 | // don't need x, y here, since all subpixel variants will have the |
| 714 | // same advance |
| 715 | const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr); |
| 716 | |
| 717 | SkScalar width = SkFloatToScalar(glyph.fAdvanceX) + autokern.adjust(glyph); |
| 718 | positions.push_back(stopX + origin * width); |
| 719 | |
| 720 | SkScalar height = SkFloatToScalar(glyph.fAdvanceY); |
| 721 | positions.push_back(stopY + origin * height); |
| 722 | |
| 723 | stopX += width; |
| 724 | stopY += height; |
| 725 | } |
| 726 | SkASSERT(textPtr == stop); |
| 727 | |
| 728 | SkGlyphCache::AttachCache(origPaintCache); |
| 729 | |
| 730 | // now adjust starting point depending on alignment |
| 731 | SkScalar alignX = stopX; |
| 732 | SkScalar alignY = stopY; |
| 733 | if (skPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 734 | alignX = SkScalarHalf(alignX); |
| 735 | alignY = SkScalarHalf(alignY); |
| 736 | } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { |
| 737 | alignX = 0; |
| 738 | alignY = 0; |
| 739 | } |
| 740 | x -= alignX; |
| 741 | y -= alignY; |
| 742 | SkPoint offset = SkPoint::Make(x, y); |
| 743 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 744 | this->drawDFPosText(blob, runIndex, glyphCache, props, paint, scalerContextFlags, viewMatrix, |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 745 | text, byteLength, positions.begin(), 2, offset); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 746 | } |
| 747 | |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 748 | void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 749 | GrGlyphCache* glyphCache, const SkSurfaceProps& props, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 750 | const GrTextUtils::Paint& paint, |
| 751 | SkScalerContextFlags scalerContextFlags, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 752 | const SkMatrix& viewMatrix, const char text[], |
| 753 | size_t byteLength, const SkScalar pos[], |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 754 | int scalarsPerPosition, const SkPoint& offset) const { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 755 | SkASSERT(byteLength == 0 || text != nullptr); |
| 756 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 757 | |
| 758 | // nothing to draw |
| 759 | if (text == nullptr || byteLength == 0) { |
| 760 | return; |
| 761 | } |
| 762 | |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 763 | bool hasWCoord = viewMatrix.hasPerspective() || fDistanceFieldVerticesAlwaysHaveW; |
| 764 | |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 765 | // Setup distance field paint and text ratio |
| 766 | SkScalar textRatio; |
| 767 | SkPaint dfPaint(paint); |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 768 | this->initDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 769 | blob->setHasDistanceField(); |
| 770 | blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(), |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 771 | paint.skPaint().isAntiAlias(), hasWCoord); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 772 | |
Jim Van Verth | 080a928 | 2018-03-02 10:41:43 -0500 | [diff] [blame^] | 773 | FallbackTextHelper fallbackTextHelper(viewMatrix, paint, glyphCache, textRatio); |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 774 | |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 775 | sk_sp<GrTextStrike> currStrike; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 776 | |
| 777 | // We apply the fake-gamma by altering the distance in the shader, so we ignore the |
| 778 | // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). |
| 779 | SkGlyphCache* cache = |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 780 | blob->setupCache(runIndex, props, SkScalerContextFlags::kNone, dfPaint, nullptr); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 781 | SkPaint::GlyphCacheProc glyphCacheProc = |
| 782 | SkPaint::GetGlyphCacheProc(dfPaint.getTextEncoding(), dfPaint.isDevKernText(), true); |
| 783 | |
| 784 | const char* stop = text + byteLength; |
| 785 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 786 | SkPaint::Align align = dfPaint.getTextAlign(); |
| 787 | SkScalar alignMul = SkPaint::kCenter_Align == align ? SK_ScalarHalf : |
| 788 | (SkPaint::kRight_Align == align ? SK_Scalar1 : 0); |
| 789 | while (text < stop) { |
| 790 | const char* lastText = text; |
| 791 | // the last 2 parameters are ignored |
| 792 | const SkGlyph& glyph = glyphCacheProc(cache, &text); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 793 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 794 | if (glyph.fWidth) { |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 795 | SkPoint glyphPos(offset); |
| 796 | glyphPos.fX += pos[0] - SkFloatToScalar(glyph.fAdvanceX) * alignMul * textRatio; |
| 797 | glyphPos.fY += (2 == scalarsPerPosition ? pos[1] : 0) - |
| 798 | SkFloatToScalar(glyph.fAdvanceY) * alignMul * textRatio; |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 799 | |
| 800 | if (glyph.fMaskFormat != SkMask::kARGB32_Format) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 801 | DfAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, glyphPos.fX, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 802 | glyphPos.fY, paint.filteredPremulColor(), cache, textRatio); |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 803 | } else { |
| 804 | // can't append color glyph to SDF batch, send to fallback |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 805 | fallbackTextHelper.appendText(glyph, SkToInt(text - lastText), lastText, glyphPos); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 806 | } |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 807 | } |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 808 | pos += scalarsPerPosition; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | SkGlyphCache::AttachCache(cache); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 812 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 813 | fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, paint, scalerContextFlags); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 814 | } |
| 815 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 816 | // TODO: merge with BmpAppendGlyph |
| 817 | void GrAtlasTextContext::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 818 | GrGlyphCache* grGlyphCache, sk_sp<GrTextStrike>* strike, |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 819 | const SkGlyph& skGlyph, SkScalar sx, SkScalar sy, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 820 | GrColor color, SkGlyphCache* skGlyphCache, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 821 | SkScalar textRatio) { |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 822 | if (!*strike) { |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 823 | *strike = grGlyphCache->getStrike(skGlyphCache); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), |
| 827 | skGlyph.getSubXFixed(), |
| 828 | skGlyph.getSubYFixed(), |
| 829 | GrGlyph::kDistance_MaskStyle); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 830 | GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 831 | if (!glyph) { |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 832 | return; |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); |
| 836 | SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); |
| 837 | SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2 * SK_DistanceFieldInset); |
| 838 | SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2 * SK_DistanceFieldInset); |
| 839 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 840 | dx *= textRatio; |
| 841 | dy *= textRatio; |
| 842 | width *= textRatio; |
| 843 | height *= textRatio; |
| 844 | SkRect glyphRect = SkRect::MakeXYWH(sx + dx, sy + dy, width, height); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 845 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 846 | blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, skGlyphCache, skGlyph, sx, sy, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 847 | textRatio, false); |
Brian Salomon | 52db940 | 2017-11-07 14:58:55 -0500 | [diff] [blame] | 848 | } |
| 849 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 850 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 851 | |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 852 | void GrAtlasTextContext::FallbackTextHelper::appendText(const SkGlyph& glyph, int count, |
| 853 | const char* text, SkPoint glyphPos) { |
| 854 | SkScalar maxDim = SkTMax(glyph.fWidth, glyph.fHeight)*fTextRatio; |
| 855 | if (!fUseScaledFallback) { |
| 856 | SkScalar scaledGlyphSize = maxDim * fMaxScale; |
| 857 | if (!fViewMatrix.hasPerspective() && scaledGlyphSize > fMaxTextSize) { |
| 858 | fUseScaledFallback = true; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | fFallbackTxt.append(count, text); |
| 863 | if (fUseScaledFallback) { |
Jim Van Verth | 080a928 | 2018-03-02 10:41:43 -0500 | [diff] [blame^] | 864 | // If there's a glyph in the font that's particularly large, it's possible |
| 865 | // that fScaledFallbackTextSize may end up minimizing too much. We'd rather skip |
| 866 | // that glyph than make the others pixelated, so we set a minimum size of half the |
| 867 | // maximum text size to avoid this case. |
| 868 | SkScalar glyphTextSize = SkTMax(SkScalarFloorToScalar(fMaxTextSize*fTextSize / maxDim), |
| 869 | 0.5f*fMaxTextSize); |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 870 | fScaledFallbackTextSize = SkTMin(glyphTextSize, fScaledFallbackTextSize); |
| 871 | } |
| 872 | *fFallbackPos.append() = glyphPos; |
| 873 | } |
| 874 | |
| 875 | void GrAtlasTextContext::FallbackTextHelper::drawText(GrAtlasTextBlob* blob, int runIndex, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 876 | GrGlyphCache* glyphCache, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 877 | const SkSurfaceProps& props, |
| 878 | const GrTextUtils::Paint& paint, |
| 879 | SkScalerContextFlags scalerContextFlags) { |
| 880 | if (fFallbackTxt.count()) { |
| 881 | blob->initOverride(runIndex); |
| 882 | blob->setHasBitmap(); |
| 883 | SkGlyphCache* cache = nullptr; |
| 884 | const SkPaint& skPaint = paint.skPaint(); |
| 885 | SkPaint::GlyphCacheProc glyphCacheProc = |
| 886 | SkPaint::GetGlyphCacheProc(skPaint.getTextEncoding(), |
| 887 | skPaint.isDevKernText(), true); |
| 888 | SkColor textColor = paint.filteredPremulColor(); |
| 889 | SkScalar textRatio = SK_Scalar1; |
| 890 | fViewMatrix.mapPoints(fFallbackPos.begin(), fFallbackPos.count()); |
| 891 | if (fUseScaledFallback) { |
| 892 | // Set up paint and matrix to scale glyphs |
| 893 | SkPaint scaledPaint(skPaint); |
| 894 | scaledPaint.setTextSize(fScaledFallbackTextSize); |
| 895 | // remove maxScale from viewMatrix and move it into textRatio |
| 896 | // this keeps the base glyph size consistent regardless of matrix scale |
| 897 | SkMatrix modMatrix(fViewMatrix); |
| 898 | SkScalar invScale = SkScalarInvert(fMaxScale); |
| 899 | modMatrix.preScale(invScale, invScale); |
| 900 | textRatio = fTextSize * fMaxScale / fScaledFallbackTextSize; |
| 901 | cache = blob->setupCache(runIndex, props, scalerContextFlags, scaledPaint, |
| 902 | &modMatrix); |
| 903 | } else { |
| 904 | cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, |
| 905 | &fViewMatrix); |
| 906 | } |
| 907 | |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 908 | sk_sp<GrTextStrike> currStrike; |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 909 | const char* text = fFallbackTxt.begin(); |
| 910 | const char* stop = text + fFallbackTxt.count(); |
| 911 | SkPoint* glyphPos = fFallbackPos.begin(); |
| 912 | while (text < stop) { |
| 913 | const SkGlyph& glyph = glyphCacheProc(cache, &text); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 914 | GrAtlasTextContext::BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, |
Jim Van Verth | c401bb9 | 2018-02-15 14:05:24 -0500 | [diff] [blame] | 915 | glyphPos->fX, glyphPos->fY, textColor, |
| 916 | cache, textRatio); |
| 917 | glyphPos++; |
| 918 | } |
| 919 | |
| 920 | SkGlyphCache::AttachCache(cache); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 925 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 926 | #if GR_TEST_UTILS |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 927 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 928 | #include "GrRenderTargetContext.h" |
| 929 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 930 | GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) { |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 931 | static uint32_t gContextID = SK_InvalidGenID; |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 932 | static std::unique_ptr<GrAtlasTextContext> gTextContext; |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 933 | static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 934 | |
| 935 | if (context->uniqueID() != gContextID) { |
| 936 | gContextID = context->uniqueID(); |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 937 | gTextContext = GrAtlasTextContext::Make(GrAtlasTextContext::Options()); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 940 | // Setup dummy SkPaint / GrPaint / GrRenderTargetContext |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 941 | sk_sp<GrRenderTargetContext> rtc(context->makeDeferredRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 942 | SkBackingFit::kApprox, 1024, 1024, kRGBA_8888_GrPixelConfig, nullptr)); |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 943 | |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 944 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 945 | |
| 946 | // Because we the GrTextUtils::Paint requires an SkPaint for font info, we ignore the GrPaint |
| 947 | // param. |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 948 | SkPaint skPaint; |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 949 | skPaint.setColor(random->nextU()); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 950 | skPaint.setLCDRenderText(random->nextBool()); |
| 951 | skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool()); |
| 952 | skPaint.setSubpixelText(random->nextBool()); |
Brian Salomon | 4cbb6e6 | 2017-10-25 15:12:19 -0400 | [diff] [blame] | 953 | GrTextUtils::Paint utilsPaint(&skPaint, &rtc->colorSpaceInfo()); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 954 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 955 | const char* text = "The quick brown fox jumps over the lazy dog."; |
| 956 | int textLen = (int)strlen(text); |
| 957 | |
joshualitt | b8d8649 | 2016-02-24 09:23:03 -0800 | [diff] [blame] | 958 | // create some random x/y offsets, including negative offsets |
| 959 | static const int kMaxTrans = 1024; |
| 960 | int xPos = (random->nextU() % 2) * 2 - 1; |
| 961 | int yPos = (random->nextU() % 2) * 2 - 1; |
| 962 | int xInt = (random->nextU() % kMaxTrans) * xPos; |
| 963 | int yInt = (random->nextU() % kMaxTrans) * yPos; |
| 964 | SkScalar x = SkIntToScalar(xInt); |
| 965 | SkScalar y = SkIntToScalar(yInt); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 966 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 967 | auto glyphCache = context->contextPriv().getGlyphCache(); |
| 968 | auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 969 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 970 | // right now we don't handle textblobs, nor do we handle drawPosText. Since we only intend to |
| 971 | // test the text op with this unit test, that is okay. |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 972 | sk_sp<GrAtlasTextBlob> blob(gTextContext->makeDrawTextBlob( |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 973 | context->contextPriv().getTextBlobCache(), glyphCache, |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 974 | *context->caps()->shaderCaps(), utilsPaint, |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 975 | GrAtlasTextContext::kTextBlobOpScalerContextFlags, viewMatrix, gSurfaceProps, text, |
| 976 | static_cast<size_t>(textLen), x, y)); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 977 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 978 | return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, gSurfaceProps, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 979 | gTextContext->dfAdjustTable(), restrictedAtlasManager, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 980 | rtc->textTarget()); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | #endif |