joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [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 | |
| 8 | #include "GrTextUtils.h" |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 9 | #include "GrAtlasGlyphCache.h" |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 10 | #include "GrAtlasTextBlob.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 11 | #include "GrBlurUtils.h" |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 12 | #include "GrCaps.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 13 | #include "GrContext.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 14 | #include "GrRenderTargetContext.h" |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 15 | #include "GrSurfaceContextPriv.h" |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 16 | #include "SkDistanceFieldGen.h" |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 17 | #include "SkDrawFilter.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 18 | #include "SkDrawProcs.h" |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 19 | #include "SkFindAndPlaceGlyph.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 20 | #include "SkGlyphCache.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 21 | #include "SkGr.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 22 | #include "SkPaint.h" |
| 23 | #include "SkRect.h" |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 24 | #include "SkTextBlobRunIterator.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 25 | #include "SkTextMapStateProc.h" |
| 26 | #include "SkTextToPathIter.h" |
| 27 | |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 28 | namespace { |
| 29 | static const int kMinDFFontSize = 18; |
| 30 | static const int kSmallDFFontSize = 32; |
| 31 | static const int kSmallDFFontLimit = 32; |
| 32 | static const int kMediumDFFontSize = 72; |
| 33 | static const int kMediumDFFontLimit = 72; |
| 34 | static const int kLargeDFFontSize = 162; |
| 35 | #ifdef SK_BUILD_FOR_ANDROID |
| 36 | static const int kLargeDFFontLimit = 384; |
| 37 | #else |
| 38 | static const int kLargeDFFontLimit = 2 * kLargeDFFontSize; |
| 39 | #endif |
| 40 | }; |
| 41 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 42 | bool GrTextUtils::Paint::toGrPaint(GrMaskFormat maskFormat, GrRenderTargetContext* rtc, |
| 43 | const SkMatrix& viewMatrix, GrPaint* grPaint) const { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 44 | // TODO: this is the last use of GrSurfaceContextPriv |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 45 | GrContext* context = rtc->surfPriv().getContext(); |
| 46 | if (kARGB_GrMaskFormat == maskFormat) { |
| 47 | return SkPaintToGrPaintWithPrimitiveColor(context, rtc, this->skPaint(), grPaint); |
| 48 | } else { |
| 49 | return SkPaintToGrPaint(context, rtc, this->skPaint(), viewMatrix, grPaint); |
| 50 | } |
| 51 | } |
| 52 | |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 53 | void GrTextUtils::Paint::initFilteredColor() { |
| 54 | // This mirrors the logic in skpaint_to_grpaint_impl for handling paint colors |
| 55 | if (fDstColorSpace) { |
| 56 | GrColor4f filteredColor = SkColorToUnpremulGrColor4f(fPaint->getColor(), fDstColorSpace, |
| 57 | fColorXformFromSRGB); |
| 58 | if (fPaint->getColorFilter()) { |
| 59 | filteredColor = GrColor4f::FromSkColor4f( |
| 60 | fPaint->getColorFilter()->filterColor4f(filteredColor.toSkColor4f())); |
| 61 | } |
| 62 | fFilteredPremulColor = filteredColor.premul().toGrColor(); |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 63 | } else { |
| 64 | SkColor filteredSkColor = fPaint->getColor(); |
| 65 | if (fPaint->getColorFilter()) { |
| 66 | filteredSkColor = fPaint->getColorFilter()->filterColor(filteredSkColor); |
| 67 | } |
| 68 | fFilteredPremulColor = SkColorToPremulGrColor(filteredSkColor); |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 72 | bool GrTextUtils::RunPaint::modifyForRun(const SkTextBlobRunIterator& run) { |
| 73 | if (!fModifiedPaint.isValid()) { |
| 74 | fModifiedPaint.init(fOriginalPaint->skPaint()); |
| 75 | fPaint = fModifiedPaint.get(); |
| 76 | } else if (fFilter) { |
| 77 | // We have to reset before applying the run because the filter could have arbitrary |
| 78 | // changed the paint. |
| 79 | *fModifiedPaint.get() = fOriginalPaint->skPaint(); |
| 80 | } |
| 81 | run.applyFontToPaint(fModifiedPaint.get()); |
| 82 | |
| 83 | if (fFilter) { |
| 84 | if (!fFilter->filter(fModifiedPaint.get(), SkDrawFilter::kText_Type)) { |
| 85 | // A false return from filter() means we should abort the current draw. |
| 86 | return false; |
| 87 | } |
| 88 | // The draw filter could have changed either the paint color or color filter. |
| 89 | this->initFilteredColor(); |
| 90 | } |
| 91 | fModifiedPaint.get()->setFlags(FilterTextFlags(fProps, *fModifiedPaint.get())); |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* fontCache, |
| 96 | const SkSurfaceProps& props, const GrTextUtils::Paint& paint, |
| 97 | uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
| 98 | const char text[], size_t byteLength, SkScalar x, SkScalar y) { |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 99 | SkASSERT(byteLength == 0 || text != nullptr); |
| 100 | |
| 101 | // nothing to draw |
| 102 | if (text == nullptr || byteLength == 0) { |
| 103 | return; |
| 104 | } |
| 105 | |
joshualitt | a6bf4c5 | 2016-01-19 06:59:29 -0800 | [diff] [blame] | 106 | // Ensure the blob is set for bitmaptext |
| 107 | blob->setHasBitmap(); |
| 108 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 109 | GrAtlasTextStrike* currStrike = nullptr; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 110 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 111 | SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 112 | SkFindAndPlaceGlyph::ProcessText( |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 113 | paint.skPaint().getTextEncoding(), text, byteLength, |
| 114 | {x, y}, viewMatrix, paint.skPaint().getTextAlign(), |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 115 | cache, |
| 116 | [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 117 | position += rounding; |
| 118 | BmpAppendGlyph( |
| 119 | blob, runIndex, fontCache, &currStrike, glyph, |
| 120 | SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY), |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 121 | paint.filteredPremulColor(), cache); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 122 | } |
| 123 | ); |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 124 | |
| 125 | SkGlyphCache::AttachCache(cache); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 128 | void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* fontCache, |
| 129 | const SkSurfaceProps& props, const GrTextUtils::Paint& paint, |
| 130 | uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
| 131 | const char text[], size_t byteLength, const SkScalar pos[], |
| 132 | int scalarsPerPosition, const SkPoint& offset) { |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 133 | SkASSERT(byteLength == 0 || text != nullptr); |
| 134 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 135 | |
| 136 | // nothing to draw |
| 137 | if (text == nullptr || byteLength == 0) { |
| 138 | return; |
| 139 | } |
| 140 | |
joshualitt | a6bf4c5 | 2016-01-19 06:59:29 -0800 | [diff] [blame] | 141 | // Ensure the blob is set for bitmaptext |
| 142 | blob->setHasBitmap(); |
| 143 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 144 | GrAtlasTextStrike* currStrike = nullptr; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 145 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 146 | SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 147 | |
| 148 | SkFindAndPlaceGlyph::ProcessPosText( |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 149 | paint.skPaint().getTextEncoding(), text, byteLength, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 150 | offset, viewMatrix, pos, scalarsPerPosition, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 151 | paint.skPaint().getTextAlign(), cache, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 152 | [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
| 153 | position += rounding; |
| 154 | BmpAppendGlyph( |
| 155 | blob, runIndex, fontCache, &currStrike, glyph, |
| 156 | SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY), |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 157 | paint.filteredPremulColor(), cache); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 158 | } |
| 159 | ); |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 160 | |
| 161 | SkGlyphCache::AttachCache(cache); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void GrTextUtils::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 165 | GrAtlasGlyphCache* fontCache, |
| 166 | GrAtlasTextStrike** strike, const SkGlyph& skGlyph, |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 167 | int vx, int vy, GrColor color, SkGlyphCache* cache) { |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 168 | if (!*strike) { |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 169 | *strike = fontCache->getStrike(cache); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), |
| 173 | skGlyph.getSubXFixed(), |
| 174 | skGlyph.getSubYFixed(), |
| 175 | GrGlyph::kCoverage_MaskStyle); |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 176 | GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, cache); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 177 | if (!glyph) { |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | int x = vx + glyph->fBounds.fLeft; |
| 182 | int y = vy + glyph->fBounds.fTop; |
| 183 | |
| 184 | // keep them as ints until we've done the clip-test |
| 185 | int width = glyph->fBounds.width(); |
| 186 | int height = glyph->fBounds.height(); |
| 187 | |
| 188 | SkRect r; |
| 189 | r.fLeft = SkIntToScalar(x); |
| 190 | r.fTop = SkIntToScalar(y); |
| 191 | r.fRight = r.fLeft + SkIntToScalar(width); |
| 192 | r.fBottom = r.fTop + SkIntToScalar(height); |
| 193 | |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 194 | blob->appendGlyph(runIndex, r, color, *strike, glyph, cache, skGlyph, |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 195 | SkIntToScalar(vx), SkIntToScalar(vy), 1.0f, true); |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 196 | } |
| 197 | |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 198 | bool GrTextUtils::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 199 | const SkSurfaceProps& props, const GrShaderCaps& caps) { |
Jim Van Verth | 3921ba2 | 2017-06-27 15:07:31 -0400 | [diff] [blame] | 200 | if (!viewMatrix.hasPerspective()) { |
| 201 | SkScalar maxScale = viewMatrix.getMaxScale(); |
| 202 | SkScalar scaledTextSize = maxScale * skPaint.getTextSize(); |
| 203 | // Hinted text looks far better at small resolutions |
| 204 | // Scaling up beyond 2x yields undesireable artifacts |
| 205 | if (scaledTextSize < kMinDFFontSize || |
| 206 | scaledTextSize > kLargeDFFontLimit) { |
| 207 | return false; |
| 208 | } |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 209 | |
Jim Van Verth | 3921ba2 | 2017-06-27 15:07:31 -0400 | [diff] [blame] | 210 | bool useDFT = props.isUseDeviceIndependentFonts(); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 211 | #if SK_FORCE_DISTANCE_FIELD_TEXT |
Jim Van Verth | 3921ba2 | 2017-06-27 15:07:31 -0400 | [diff] [blame] | 212 | useDFT = true; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 213 | #endif |
| 214 | |
Jim Van Verth | 3921ba2 | 2017-06-27 15:07:31 -0400 | [diff] [blame] | 215 | if (!useDFT && scaledTextSize < kLargeDFFontSize) { |
| 216 | return false; |
| 217 | } |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // rasterizers and mask filters modify alpha, which doesn't |
| 221 | // translate well to distance |
| 222 | if (skPaint.getRasterizer() || skPaint.getMaskFilter() || !caps.shaderDerivativeSupport()) { |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | // TODO: add some stroking support |
| 227 | if (skPaint.getStyle() != SkPaint::kFill_Style) { |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | void GrTextUtils::InitDistanceFieldPaint(GrAtlasTextBlob* blob, |
| 235 | SkPaint* skPaint, |
| 236 | SkScalar* textRatio, |
| 237 | const SkMatrix& viewMatrix) { |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 238 | SkScalar textSize = skPaint->getTextSize(); |
| 239 | SkScalar scaledTextSize = textSize; |
Jim Van Verth | 3921ba2 | 2017-06-27 15:07:31 -0400 | [diff] [blame] | 240 | |
| 241 | if (viewMatrix.hasPerspective()) { |
| 242 | // for perspective, we simply force to the medium size |
| 243 | // TODO: compute a size based on approximate screen area |
| 244 | scaledTextSize = kMediumDFFontLimit; |
| 245 | } else { |
| 246 | SkScalar maxScale = viewMatrix.getMaxScale(); |
| 247 | // if we have non-unity scale, we need to choose our base text size |
| 248 | // based on the SkPaint's text size multiplied by the max scale factor |
| 249 | // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? |
| 250 | if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { |
| 251 | scaledTextSize *= maxScale; |
| 252 | } |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | // We have three sizes of distance field text, and within each size 'bucket' there is a floor |
| 256 | // and ceiling. A scale outside of this range would require regenerating the distance fields |
| 257 | SkScalar dfMaskScaleFloor; |
| 258 | SkScalar dfMaskScaleCeil; |
| 259 | if (scaledTextSize <= kSmallDFFontLimit) { |
| 260 | dfMaskScaleFloor = kMinDFFontSize; |
| 261 | dfMaskScaleCeil = kSmallDFFontLimit; |
| 262 | *textRatio = textSize / kSmallDFFontSize; |
| 263 | skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 264 | } else if (scaledTextSize <= kMediumDFFontLimit) { |
| 265 | dfMaskScaleFloor = kSmallDFFontLimit; |
| 266 | dfMaskScaleCeil = kMediumDFFontLimit; |
| 267 | *textRatio = textSize / kMediumDFFontSize; |
| 268 | skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 269 | } else { |
| 270 | dfMaskScaleFloor = kMediumDFFontLimit; |
| 271 | dfMaskScaleCeil = kLargeDFFontLimit; |
| 272 | *textRatio = textSize / kLargeDFFontSize; |
| 273 | skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 274 | } |
| 275 | |
| 276 | // Because there can be multiple runs in the blob, we want the overall maxMinScale, and |
| 277 | // minMaxScale to make regeneration decisions. Specifically, we want the maximum minimum scale |
| 278 | // we can tolerate before we'd drop to a lower mip size, and the minimum maximum scale we can |
| 279 | // tolerate before we'd have to move to a large mip size. When we actually test these values |
| 280 | // we look at the delta in scale between the new viewmatrix and the old viewmatrix, and test |
| 281 | // against these values to decide if we can reuse or not(ie, will a given scale change our mip |
| 282 | // level) |
| 283 | SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 284 | blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 285 | |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 286 | skPaint->setAntiAlias(true); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 287 | skPaint->setLCDRenderText(false); |
| 288 | skPaint->setAutohinted(false); |
| 289 | skPaint->setHinting(SkPaint::kNormal_Hinting); |
| 290 | skPaint->setSubpixelText(true); |
| 291 | } |
| 292 | |
| 293 | void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 294 | GrAtlasGlyphCache* fontCache, const SkSurfaceProps& props, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 295 | const GrTextUtils::Paint& paint, uint32_t scalerContextFlags, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 296 | const SkMatrix& viewMatrix, |
| 297 | const char text[], size_t byteLength, |
| 298 | SkScalar x, SkScalar y) { |
| 299 | SkASSERT(byteLength == 0 || text != nullptr); |
| 300 | |
| 301 | // nothing to draw |
| 302 | if (text == nullptr || byteLength == 0) { |
| 303 | return; |
| 304 | } |
| 305 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 306 | const SkPaint& skPaint = paint.skPaint(); |
robertphillips | e34f17d | 2016-07-19 07:59:22 -0700 | [diff] [blame] | 307 | SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(skPaint.getTextEncoding(), |
| 308 | skPaint.isDevKernText(), |
| 309 | true); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 310 | SkAutoDescriptor desc; |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 311 | SkScalerContextEffects effects; |
brianosman | 32f7782 | 2016-04-07 06:25:45 -0700 | [diff] [blame] | 312 | // We apply the fake-gamma by altering the distance in the shader, so we ignore the |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 313 | // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 314 | skPaint.getScalerContextDescriptor(&effects, &desc, props, SkPaint::kNone_ScalerContextFlags, |
| 315 | nullptr); |
| 316 | SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface(), effects, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 317 | desc.getDesc()); |
| 318 | |
| 319 | SkTArray<SkScalar> positions; |
| 320 | |
| 321 | const char* textPtr = text; |
benjaminwagner | 6b3eacb | 2016-03-24 19:07:58 -0700 | [diff] [blame] | 322 | SkScalar stopX = 0; |
| 323 | SkScalar stopY = 0; |
| 324 | SkScalar origin = 0; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 325 | switch (skPaint.getTextAlign()) { |
benjaminwagner | 6b3eacb | 2016-03-24 19:07:58 -0700 | [diff] [blame] | 326 | case SkPaint::kRight_Align: origin = SK_Scalar1; break; |
| 327 | case SkPaint::kCenter_Align: origin = SK_ScalarHalf; break; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 328 | case SkPaint::kLeft_Align: origin = 0; break; |
| 329 | } |
| 330 | |
| 331 | SkAutoKern autokern; |
| 332 | const char* stop = text + byteLength; |
| 333 | while (textPtr < stop) { |
| 334 | // don't need x, y here, since all subpixel variants will have the |
| 335 | // same advance |
benjaminwagner | d936f63 | 2016-02-23 10:44:31 -0800 | [diff] [blame] | 336 | const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 337 | |
benjaminwagner | 6b3eacb | 2016-03-24 19:07:58 -0700 | [diff] [blame] | 338 | SkScalar width = SkFloatToScalar(glyph.fAdvanceX) + autokern.adjust(glyph); |
| 339 | positions.push_back(stopX + origin * width); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 340 | |
benjaminwagner | 6b3eacb | 2016-03-24 19:07:58 -0700 | [diff] [blame] | 341 | SkScalar height = SkFloatToScalar(glyph.fAdvanceY); |
| 342 | positions.push_back(stopY + origin * height); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 343 | |
| 344 | stopX += width; |
| 345 | stopY += height; |
| 346 | } |
| 347 | SkASSERT(textPtr == stop); |
| 348 | |
| 349 | SkGlyphCache::AttachCache(origPaintCache); |
| 350 | |
| 351 | // now adjust starting point depending on alignment |
benjaminwagner | 6b3eacb | 2016-03-24 19:07:58 -0700 | [diff] [blame] | 352 | SkScalar alignX = stopX; |
| 353 | SkScalar alignY = stopY; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 354 | if (skPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 355 | alignX = SkScalarHalf(alignX); |
| 356 | alignY = SkScalarHalf(alignY); |
| 357 | } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { |
| 358 | alignX = 0; |
| 359 | alignY = 0; |
| 360 | } |
| 361 | x -= alignX; |
| 362 | y -= alignY; |
| 363 | SkPoint offset = SkPoint::Make(x, y); |
| 364 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 365 | DrawDFPosText(blob, runIndex, fontCache, props, paint, scalerContextFlags, viewMatrix, text, |
| 366 | byteLength, positions.begin(), 2, offset); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 369 | void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* fontCache, |
| 370 | const SkSurfaceProps& props, const GrTextUtils::Paint& paint, |
| 371 | uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
| 372 | const char text[], size_t byteLength, const SkScalar pos[], |
| 373 | int scalarsPerPosition, const SkPoint& offset) { |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 374 | SkASSERT(byteLength == 0 || text != nullptr); |
| 375 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 376 | |
| 377 | // nothing to draw |
| 378 | if (text == nullptr || byteLength == 0) { |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | SkTDArray<char> fallbackTxt; |
| 383 | SkTDArray<SkScalar> fallbackPos; |
| 384 | |
| 385 | // Setup distance field paint and text ratio |
| 386 | SkScalar textRatio; |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 387 | SkPaint dfPaint(paint); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 388 | GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); |
| 389 | blob->setHasDistanceField(); |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 390 | blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(), |
| 391 | paint.skPaint().isAntiAlias()); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 392 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 393 | GrAtlasTextStrike* currStrike = nullptr; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 394 | |
brianosman | 32f7782 | 2016-04-07 06:25:45 -0700 | [diff] [blame] | 395 | // We apply the fake-gamma by altering the distance in the shader, so we ignore the |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 396 | // passed-in scaler context flags. (It's only used when we fall-back to bitmap text). |
| 397 | SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::kNone_ScalerContextFlags, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 398 | dfPaint, nullptr); |
robertphillips | e34f17d | 2016-07-19 07:59:22 -0700 | [diff] [blame] | 399 | SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(dfPaint.getTextEncoding(), |
| 400 | dfPaint.isDevKernText(), |
| 401 | true); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 402 | |
| 403 | const char* stop = text + byteLength; |
| 404 | |
| 405 | if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { |
| 406 | while (text < stop) { |
| 407 | const char* lastText = text; |
| 408 | // the last 2 parameters are ignored |
benjaminwagner | d936f63 | 2016-02-23 10:44:31 -0800 | [diff] [blame] | 409 | const SkGlyph& glyph = glyphCacheProc(cache, &text); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 410 | |
| 411 | if (glyph.fWidth) { |
| 412 | SkScalar x = offset.x() + pos[0]; |
| 413 | SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0); |
| 414 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 415 | if (!DfAppendGlyph(blob, runIndex, fontCache, &currStrike, glyph, x, y, |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 416 | paint.filteredPremulColor(), cache, textRatio, viewMatrix)) { |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 417 | // couldn't append, send to fallback |
| 418 | fallbackTxt.append(SkToInt(text-lastText), lastText); |
| 419 | *fallbackPos.append() = pos[0]; |
| 420 | if (2 == scalarsPerPosition) { |
| 421 | *fallbackPos.append() = pos[1]; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | pos += scalarsPerPosition; |
| 426 | } |
| 427 | } else { |
| 428 | SkScalar alignMul = SkPaint::kCenter_Align == dfPaint.getTextAlign() ? SK_ScalarHalf |
| 429 | : SK_Scalar1; |
| 430 | while (text < stop) { |
| 431 | const char* lastText = text; |
| 432 | // the last 2 parameters are ignored |
benjaminwagner | d936f63 | 2016-02-23 10:44:31 -0800 | [diff] [blame] | 433 | const SkGlyph& glyph = glyphCacheProc(cache, &text); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 434 | |
| 435 | if (glyph.fWidth) { |
| 436 | SkScalar x = offset.x() + pos[0]; |
| 437 | SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0); |
| 438 | |
benjaminwagner | 6b3eacb | 2016-03-24 19:07:58 -0700 | [diff] [blame] | 439 | SkScalar advanceX = SkFloatToScalar(glyph.fAdvanceX) * alignMul * textRatio; |
| 440 | SkScalar advanceY = SkFloatToScalar(glyph.fAdvanceY) * alignMul * textRatio; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 441 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 442 | if (!DfAppendGlyph(blob, runIndex, fontCache, &currStrike, glyph, x - advanceX, |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 443 | y - advanceY, paint.filteredPremulColor(), cache, textRatio, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 444 | viewMatrix)) { |
| 445 | // couldn't append, send to fallback |
| 446 | fallbackTxt.append(SkToInt(text-lastText), lastText); |
| 447 | *fallbackPos.append() = pos[0]; |
| 448 | if (2 == scalarsPerPosition) { |
| 449 | *fallbackPos.append() = pos[1]; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | pos += scalarsPerPosition; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | SkGlyphCache::AttachCache(cache); |
| 458 | if (fallbackTxt.count()) { |
| 459 | blob->initOverride(runIndex); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 460 | GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props, paint, scalerContextFlags, |
| 461 | viewMatrix, fallbackTxt.begin(), fallbackTxt.count(), |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 462 | fallbackPos.begin(), scalarsPerPosition, offset); |
| 463 | } |
| 464 | } |
| 465 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 466 | bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* cache, |
| 467 | GrAtlasTextStrike** strike, const SkGlyph& skGlyph, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 468 | SkScalar sx, SkScalar sy, GrColor color, |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 469 | SkGlyphCache* glyphCache, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 470 | SkScalar textRatio, const SkMatrix& viewMatrix) { |
| 471 | if (!*strike) { |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 472 | *strike = cache->getStrike(glyphCache); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), |
| 476 | skGlyph.getSubXFixed(), |
| 477 | skGlyph.getSubYFixed(), |
| 478 | GrGlyph::kDistance_MaskStyle); |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 479 | GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, glyphCache); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 480 | if (!glyph) { |
| 481 | return true; |
| 482 | } |
| 483 | |
| 484 | // fallback to color glyph support |
| 485 | if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
| 486 | return false; |
| 487 | } |
| 488 | |
| 489 | SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); |
| 490 | SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); |
| 491 | SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2 * SK_DistanceFieldInset); |
| 492 | SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2 * SK_DistanceFieldInset); |
| 493 | |
| 494 | SkScalar scale = textRatio; |
| 495 | dx *= scale; |
| 496 | dy *= scale; |
| 497 | width *= scale; |
| 498 | height *= scale; |
| 499 | sx += dx; |
| 500 | sy += dy; |
| 501 | SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); |
| 502 | |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 503 | blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, glyphCache, skGlyph, |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 504 | sx - dx, sy - dy, scale, false); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 505 | return true; |
| 506 | } |
| 507 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 508 | void GrTextUtils::DrawTextAsPath(GrContext* context, GrRenderTargetContext* rtc, const GrClip& clip, |
| 509 | const SkPaint& paint, const SkMatrix& viewMatrix, |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 510 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 511 | const SkIRect& clipBounds) { |
Jim Van Verth | 1380bb4 | 2017-07-31 14:28:47 -0400 | [diff] [blame] | 512 | if (!paint.countText(text, byteLength)) { |
| 513 | return; |
| 514 | } |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 515 | SkTextToPathIter iter(text, byteLength, paint, true); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 516 | |
| 517 | SkMatrix matrix; |
| 518 | matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
| 519 | matrix.postTranslate(x, y); |
| 520 | |
| 521 | const SkPath* iterPath; |
| 522 | SkScalar xpos, prevXPos = 0; |
| 523 | |
| 524 | while (iter.next(&iterPath, &xpos)) { |
| 525 | matrix.postTranslate(xpos - prevXPos, 0); |
| 526 | if (iterPath) { |
| 527 | const SkPaint& pnt = iter.getPaint(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 528 | GrBlurUtils::drawPathWithMaskFilter(context, rtc, clip, *iterPath, |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 529 | pnt, viewMatrix, &matrix, clipBounds, false); |
| 530 | } |
| 531 | prevXPos = xpos; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | void GrTextUtils::DrawPosTextAsPath(GrContext* context, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 536 | GrRenderTargetContext* rtc, |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 537 | const SkSurfaceProps& props, |
| 538 | const GrClip& clip, |
| 539 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 540 | const char text[], size_t byteLength, |
| 541 | const SkScalar pos[], int scalarsPerPosition, |
| 542 | const SkPoint& offset, const SkIRect& clipBounds) { |
Jim Van Verth | 1380bb4 | 2017-07-31 14:28:47 -0400 | [diff] [blame] | 543 | if (!origPaint.countText(text, byteLength)) { |
| 544 | return; |
| 545 | } |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 546 | // setup our std paint, in hopes of getting hits in the cache |
| 547 | SkPaint paint(origPaint); |
| 548 | SkScalar matrixScale = paint.setupForAsPaths(); |
| 549 | |
| 550 | SkMatrix matrix; |
| 551 | matrix.setScale(matrixScale, matrixScale); |
| 552 | |
| 553 | // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. |
| 554 | paint.setStyle(SkPaint::kFill_Style); |
| 555 | paint.setPathEffect(nullptr); |
| 556 | |
robertphillips | e34f17d | 2016-07-19 07:59:22 -0700 | [diff] [blame] | 557 | SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(), |
| 558 | paint.isDevKernText(), |
| 559 | true); |
benjaminwagner | d936f63 | 2016-02-23 10:44:31 -0800 | [diff] [blame] | 560 | SkAutoGlyphCache autoCache(paint, &props, nullptr); |
| 561 | SkGlyphCache* cache = autoCache.getCache(); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 562 | |
| 563 | const char* stop = text + byteLength; |
| 564 | SkTextAlignProc alignProc(paint.getTextAlign()); |
| 565 | SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
| 566 | |
| 567 | // Now restore the original settings, so we "draw" with whatever style/stroking. |
| 568 | paint.setStyle(origPaint.getStyle()); |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 569 | paint.setPathEffect(origPaint.refPathEffect()); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 570 | |
| 571 | while (text < stop) { |
benjaminwagner | d936f63 | 2016-02-23 10:44:31 -0800 | [diff] [blame] | 572 | const SkGlyph& glyph = glyphCacheProc(cache, &text); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 573 | if (glyph.fWidth) { |
| 574 | const SkPath* path = cache->findPath(glyph); |
| 575 | if (path) { |
| 576 | SkPoint tmsLoc; |
| 577 | tmsProc(pos, &tmsLoc); |
| 578 | SkPoint loc; |
| 579 | alignProc(tmsLoc, glyph, &loc); |
| 580 | |
| 581 | matrix[SkMatrix::kMTransX] = loc.fX; |
| 582 | matrix[SkMatrix::kMTransY] = loc.fY; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 583 | GrBlurUtils::drawPathWithMaskFilter(context, rtc, clip, *path, paint, |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 584 | viewMatrix, &matrix, clipBounds, false); |
| 585 | } |
| 586 | } |
| 587 | pos += scalarsPerPosition; |
| 588 | } |
| 589 | } |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 590 | |
| 591 | bool GrTextUtils::ShouldDisableLCD(const SkPaint& paint) { |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 592 | return paint.getMaskFilter() || |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 593 | paint.getRasterizer() || |
| 594 | paint.getPathEffect() || |
| 595 | paint.isFakeBoldText() || |
| 596 | paint.getStyle() != SkPaint::kFill_Style; |
| 597 | } |
| 598 | |
| 599 | uint32_t GrTextUtils::FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint) { |
| 600 | uint32_t flags = paint.getFlags(); |
| 601 | |
| 602 | if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
| 603 | return flags; |
| 604 | } |
| 605 | |
| 606 | if (kUnknown_SkPixelGeometry == surfaceProps.pixelGeometry() || ShouldDisableLCD(paint)) { |
| 607 | flags &= ~SkPaint::kLCDRenderText_Flag; |
| 608 | flags |= SkPaint::kGenA8FromLCD_Flag; |
| 609 | } |
| 610 | |
| 611 | return flags; |
| 612 | } |