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" |
| 8 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 9 | #include "GrBatch.h" |
| 10 | #include "GrBatchFontCache.h" |
| 11 | #include "GrBatchTarget.h" |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 12 | #include "GrBatchTest.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 13 | #include "GrBlurUtils.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 14 | #include "GrDefaultGeoProcFactory.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 15 | #include "GrDrawContext.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 16 | #include "GrFontScaler.h" |
| 17 | #include "GrIndexBuffer.h" |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 18 | #include "GrResourceProvider.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 19 | #include "GrStrokeInfo.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 20 | #include "GrTextBlobCache.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 21 | #include "GrTexturePriv.h" |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame] | 22 | #include "GrVertexBuffer.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 23 | |
| 24 | #include "SkAutoKern.h" |
| 25 | #include "SkColorPriv.h" |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 26 | #include "SkColorFilter.h" |
| 27 | #include "SkDistanceFieldGen.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 28 | #include "SkDraw.h" |
| 29 | #include "SkDrawFilter.h" |
| 30 | #include "SkDrawProcs.h" |
| 31 | #include "SkGlyphCache.h" |
| 32 | #include "SkGpuDevice.h" |
| 33 | #include "SkGr.h" |
| 34 | #include "SkPath.h" |
| 35 | #include "SkRTConf.h" |
| 36 | #include "SkStrokeRec.h" |
| 37 | #include "SkTextBlob.h" |
| 38 | #include "SkTextMapStateProc.h" |
| 39 | |
| 40 | #include "effects/GrBitmapTextGeoProc.h" |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 41 | #include "effects/GrDistanceFieldGeoProc.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 42 | |
| 43 | namespace { |
| 44 | static const size_t kLCDTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
| 45 | |
| 46 | // position + local coord |
| 47 | static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
| 48 | |
| 49 | static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16); |
| 50 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 51 | static const int kMinDFFontSize = 18; |
| 52 | static const int kSmallDFFontSize = 32; |
| 53 | static const int kSmallDFFontLimit = 32; |
| 54 | static const int kMediumDFFontSize = 72; |
| 55 | static const int kMediumDFFontLimit = 72; |
| 56 | static const int kLargeDFFontSize = 162; |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 57 | static const int kLargeDFFontLimit = 2 * kLargeDFFontSize; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 58 | |
| 59 | SkDEBUGCODE(static const int kExpectedDistanceAdjustTableSize = 8;) |
| 60 | static const int kDistanceAdjustLumShift = 5; |
| 61 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 62 | static const int kVerticesPerGlyph = 4; |
| 63 | static const int kIndicesPerGlyph = 6; |
| 64 | |
| 65 | static size_t get_vertex_stride(GrMaskFormat maskFormat) { |
| 66 | switch (maskFormat) { |
| 67 | case kA8_GrMaskFormat: |
| 68 | return kGrayTextVASize; |
| 69 | case kARGB_GrMaskFormat: |
| 70 | return kColorTextVASize; |
| 71 | default: |
| 72 | return kLCDTextVASize; |
| 73 | } |
| 74 | } |
| 75 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 76 | static size_t get_vertex_stride_df(GrMaskFormat maskFormat, bool useLCDText) { |
| 77 | SkASSERT(maskFormat == kA8_GrMaskFormat); |
| 78 | if (useLCDText) { |
| 79 | return kLCDTextVASize; |
| 80 | } else { |
| 81 | return kGrayTextVASize; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
| 86 | unsigned r = SkColorGetR(c); |
| 87 | unsigned g = SkColorGetG(c); |
| 88 | unsigned b = SkColorGetB(c); |
| 89 | return GrColorPackRGBA(r, g, b, 0xff); |
| 90 | } |
| 91 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | // TODO |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 95 | // Distance field text in textblobs |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 96 | |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 97 | GrAtlasTextContext::GrAtlasTextContext(GrContext* context, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 98 | const SkDeviceProperties& properties, |
| 99 | bool enableDistanceFields) |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 100 | : INHERITED(context, properties) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 101 | , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))) { |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 102 | // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest |
| 103 | // vertexStride |
| 104 | SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize, |
| 105 | vertex_attribute_changed); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 106 | fCurrStrike = NULL; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 107 | fCache = context->getTextBlobCache(); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 108 | |
| 109 | #if SK_FORCE_DISTANCE_FIELD_TEXT |
| 110 | fEnableDFRendering = true; |
| 111 | #else |
| 112 | fEnableDFRendering = enableDistanceFields; |
| 113 | #endif |
| 114 | } |
| 115 | |
| 116 | void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gamma) { |
| 117 | |
| 118 | // This is used for an approximation of the mask gamma hack, used by raster and bitmap |
| 119 | // text. The mask gamma hack is based off of guessing what the blend color is going to |
| 120 | // be, and adjusting the mask so that when run through the linear blend will |
| 121 | // produce the value closest to the desired result. However, in practice this means |
| 122 | // that the 'adjusted' mask is just increasing or decreasing the coverage of |
| 123 | // the mask depending on what it is thought it will blit against. For black (on |
| 124 | // assumed white) this means that coverages are decreased (on a curve). For white (on |
| 125 | // assumed black) this means that coverages are increased (on a a curve). At |
| 126 | // middle (perceptual) gray (which could be blit against anything) the coverages |
| 127 | // remain the same. |
| 128 | // |
| 129 | // The idea here is that instead of determining the initial (real) coverage and |
| 130 | // then adjusting that coverage, we determine an adjusted coverage directly by |
| 131 | // essentially manipulating the geometry (in this case, the distance to the glyph |
| 132 | // edge). So for black (on assumed white) this thins a bit; for white (on |
| 133 | // assumed black) this fake bolds the geometry a bit. |
| 134 | // |
| 135 | // The distance adjustment is calculated by determining the actual coverage value which |
| 136 | // when fed into in the mask gamma table gives us an 'adjusted coverage' value of 0.5. This |
| 137 | // actual coverage value (assuming it's between 0 and 1) corresponds to a distance from the |
| 138 | // actual edge. So by subtracting this distance adjustment and computing without the |
| 139 | // the coverage adjustment we should get 0.5 coverage at the same point. |
| 140 | // |
| 141 | // This has several implications: |
| 142 | // For non-gray lcd smoothed text, each subpixel essentially is using a |
| 143 | // slightly different geometry. |
| 144 | // |
| 145 | // For black (on assumed white) this may not cover some pixels which were |
| 146 | // previously covered; however those pixels would have been only slightly |
| 147 | // covered and that slight coverage would have been decreased anyway. Also, some pixels |
| 148 | // which were previously fully covered may no longer be fully covered. |
| 149 | // |
| 150 | // For white (on assumed black) this may cover some pixels which weren't |
| 151 | // previously covered at all. |
| 152 | |
| 153 | int width, height; |
| 154 | size_t size; |
| 155 | |
| 156 | #ifdef SK_GAMMA_CONTRAST |
| 157 | SkScalar contrast = SK_GAMMA_CONTRAST; |
| 158 | #else |
| 159 | SkScalar contrast = 0.5f; |
| 160 | #endif |
| 161 | SkScalar paintGamma = gamma; |
| 162 | SkScalar deviceGamma = gamma; |
| 163 | |
| 164 | size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, |
| 165 | &width, &height); |
| 166 | |
| 167 | SkASSERT(kExpectedDistanceAdjustTableSize == height); |
| 168 | fTable = SkNEW_ARRAY(SkScalar, height); |
| 169 | |
| 170 | SkAutoTArray<uint8_t> data((int)size); |
| 171 | SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get()); |
| 172 | |
| 173 | // find the inverse points where we cross 0.5 |
| 174 | // binsearch might be better, but we only need to do this once on creation |
| 175 | for (int row = 0; row < height; ++row) { |
| 176 | uint8_t* rowPtr = data.get() + row*width; |
| 177 | for (int col = 0; col < width - 1; ++col) { |
| 178 | if (rowPtr[col] <= 127 && rowPtr[col + 1] >= 128) { |
| 179 | // compute point where a mask value will give us a result of 0.5 |
| 180 | float interp = (127.5f - rowPtr[col]) / (rowPtr[col + 1] - rowPtr[col]); |
| 181 | float borderAlpha = (col + interp) / 255.f; |
| 182 | |
| 183 | // compute t value for that alpha |
| 184 | // this is an approximate inverse for smoothstep() |
| 185 | float t = borderAlpha*(borderAlpha*(4.0f*borderAlpha - 6.0f) + 5.0f) / 3.0f; |
| 186 | |
| 187 | // compute distance which gives us that t value |
| 188 | const float kDistanceFieldAAFactor = 0.65f; // should match SK_DistanceFieldAAFactor |
| 189 | float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor; |
| 190 | |
| 191 | fTable[row] = d; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 196 | } |
| 197 | |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 198 | GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 199 | const SkDeviceProperties& props, |
| 200 | bool enableDistanceFields) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 201 | return SkNEW_ARGS(GrAtlasTextContext, (context, props, enableDistanceFields)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 202 | } |
| 203 | |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 204 | bool GrAtlasTextContext::canDraw(const GrRenderTarget*, |
| 205 | const GrClip&, |
| 206 | const GrPaint&, |
| 207 | const SkPaint& skPaint, |
| 208 | const SkMatrix& viewMatrix) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 209 | return this->canDrawAsDistanceFields(skPaint, viewMatrix) || |
| 210 | !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 211 | } |
| 212 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 213 | GrColor GrAtlasTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd) { |
| 214 | GrColor canonicalColor = paint.computeLuminanceColor(); |
| 215 | if (lcd) { |
| 216 | // This is the correct computation, but there are tons of cases where LCD can be overridden. |
| 217 | // For now we just regenerate if any run in a textblob has LCD. |
| 218 | // TODO figure out where all of these overrides are and see if we can incorporate that logic |
| 219 | // at a higher level *OR* use sRGB |
| 220 | SkASSERT(false); |
| 221 | //canonicalColor = SkMaskGamma::CanonicalColor(canonicalColor); |
| 222 | } else { |
| 223 | // A8, though can have mixed BMP text but it shouldn't matter because BMP text won't have |
| 224 | // gamma corrected masks anyways, nor color |
| 225 | U8CPU lum = SkComputeLuminance(SkColorGetR(canonicalColor), |
| 226 | SkColorGetG(canonicalColor), |
| 227 | SkColorGetB(canonicalColor)); |
| 228 | // reduce to our finite number of bits |
| 229 | canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum)); |
| 230 | } |
| 231 | return canonicalColor; |
| 232 | } |
| 233 | |
| 234 | // TODO if this function ever shows up in profiling, then we can compute this value when the |
| 235 | // textblob is being built and cache it. However, for the time being textblobs mostly only have 1 |
| 236 | // run so this is not a big deal to compute here. |
| 237 | bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { |
| 238 | SkTextBlob::RunIterator it(blob); |
| 239 | for (; !it.done(); it.next()) { |
| 240 | if (it.isLCD()) { |
| 241 | return true; |
| 242 | } |
| 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 247 | bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY, |
| 248 | const BitmapTextBlob& blob, const SkPaint& paint, |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 249 | const SkMaskFilter::BlurRec& blurRec, |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 250 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 251 | // If we have LCD text then our canonical color will be set to transparent, in this case we have |
| 252 | // to regenerate the blob on any color change |
| 253 | if (blob.fKey.fCanonicalColor == SK_ColorTRANSPARENT && blob.fPaintColor != paint.getColor()) { |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 254 | return true; |
| 255 | } |
| 256 | |
| 257 | if (blob.fViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) { |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | if (blob.fViewMatrix.hasPerspective() && !blob.fViewMatrix.cheapEqualTo(viewMatrix)) { |
| 262 | return true; |
| 263 | } |
| 264 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 265 | // We only cache one masked version |
| 266 | if (blob.fKey.fHasBlur && |
| 267 | (blob.fBlurRec.fSigma != blurRec.fSigma || |
| 268 | blob.fBlurRec.fStyle != blurRec.fStyle || |
| 269 | blob.fBlurRec.fQuality != blurRec.fQuality)) { |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | // Similarly, we only cache one version for each style |
| 274 | if (blob.fKey.fStyle != SkPaint::kFill_Style && |
| 275 | (blob.fStrokeInfo.fFrameWidth != paint.getStrokeWidth() || |
| 276 | blob.fStrokeInfo.fMiterLimit != paint.getStrokeMiter() || |
| 277 | blob.fStrokeInfo.fJoin != paint.getStrokeJoin())) { |
| 278 | return true; |
| 279 | } |
| 280 | |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 281 | // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls |
| 282 | // for mixed blobs if this becomes an issue. |
| 283 | if (blob.hasBitmap() && blob.hasDistanceField()) { |
joshualitt | 473ffa1 | 2015-04-22 18:23:15 -0700 | [diff] [blame] | 284 | // Identical viewmatrices and we can reuse in all cases |
| 285 | if (blob.fViewMatrix.cheapEqualTo(viewMatrix) && x == blob.fX && y == blob.fY) { |
| 286 | return false; |
| 287 | } |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 288 | return true; |
| 289 | } |
| 290 | |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 291 | if (blob.hasBitmap()) { |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 292 | if (blob.fViewMatrix.getScaleX() != viewMatrix.getScaleX() || |
| 293 | blob.fViewMatrix.getScaleY() != viewMatrix.getScaleY() || |
| 294 | blob.fViewMatrix.getSkewX() != viewMatrix.getSkewX() || |
| 295 | blob.fViewMatrix.getSkewY() != viewMatrix.getSkewY()) { |
| 296 | return true; |
| 297 | } |
| 298 | |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 299 | // We can update the positions in the cachedtextblobs without regenerating the whole blob, |
| 300 | // but only for integer translations. |
| 301 | // This cool bit of math will determine the necessary translation to apply to the already |
| 302 | // generated vertex coordinates to move them to the correct position |
| 303 | SkScalar transX = viewMatrix.getTranslateX() + |
| 304 | viewMatrix.getScaleX() * (x - blob.fX) + |
| 305 | viewMatrix.getSkewX() * (y - blob.fY) - |
| 306 | blob.fViewMatrix.getTranslateX(); |
| 307 | SkScalar transY = viewMatrix.getTranslateY() + |
| 308 | viewMatrix.getSkewY() * (x - blob.fX) + |
| 309 | viewMatrix.getScaleY() * (y - blob.fY) - |
| 310 | blob.fViewMatrix.getTranslateY(); |
joshualitt | f0c000d | 2015-04-27 09:36:55 -0700 | [diff] [blame] | 311 | if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY) ) { |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 312 | return true; |
| 313 | } |
| 314 | |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 315 | (*outTransX) = transX; |
| 316 | (*outTransY) = transY; |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 317 | } else if (blob.hasDistanceField()) { |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 318 | // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different |
| 319 | // distance field being generated, so we have to regenerate in those cases |
| 320 | SkScalar newMaxScale = viewMatrix.getMaxScale(); |
| 321 | SkScalar oldMaxScale = blob.fViewMatrix.getMaxScale(); |
| 322 | SkScalar scaleAdjust = newMaxScale / oldMaxScale; |
| 323 | if (scaleAdjust < blob.fMaxMinScale || scaleAdjust > blob.fMinMaxScale) { |
| 324 | return true; |
| 325 | } |
| 326 | |
| 327 | (*outTransX) = x - blob.fX; |
| 328 | (*outTransY) = y - blob.fY; |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 329 | } |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 330 | // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case |
| 331 | // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate |
| 332 | // the blob anyways at flush time, so no need to regenerate explicitly |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 333 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 334 | return false; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 338 | inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, |
| 339 | const SkPaint& skPaint, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 340 | const SkMatrix* viewMatrix, |
| 341 | bool noGamma) { |
| 342 | skPaint.getScalerContextDescriptor(&run->fDescriptor, &fDeviceProperties, viewMatrix, noGamma); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 343 | run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); |
| 344 | return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc()); |
| 345 | } |
| 346 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 347 | void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 348 | const GrClip& clip, const SkPaint& skPaint, |
| 349 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
| 350 | SkScalar x, SkScalar y, |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 351 | SkDrawFilter* drawFilter, const SkIRect& clipBounds) { |
joshualitt | 9b8e79e | 2015-04-24 09:57:12 -0700 | [diff] [blame] | 352 | // If we have been abandoned, then don't draw |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 353 | if (fContext->abandoned()) { |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | GrDrawContext* drawContext = fContext->drawContext(); |
| 358 | if (!drawContext) { |
joshualitt | 9b8e79e | 2015-04-24 09:57:12 -0700 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 362 | SkAutoTUnref<BitmapTextBlob> cacheBlob; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 363 | SkMaskFilter::BlurRec blurRec; |
| 364 | BitmapTextBlob::Key key; |
| 365 | // It might be worth caching these things, but its not clear at this time |
| 366 | // TODO for animated mask filters, this will fill up our cache. We need a safeguard here |
| 367 | const SkMaskFilter* mf = skPaint.getMaskFilter(); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 368 | bool canCache = !(skPaint.getPathEffect() || |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 369 | (mf && !mf->asABlur(&blurRec)) || |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 370 | drawFilter); |
| 371 | |
| 372 | if (canCache) { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 373 | bool hasLCD = HasLCD(blob); |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 374 | |
| 375 | // We canonicalize all non-lcd draws to use kUnknown_SkPixelGeometry |
| 376 | SkPixelGeometry pixelGeometry = hasLCD ? fDeviceProperties.pixelGeometry() : |
| 377 | kUnknown_SkPixelGeometry; |
| 378 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 379 | // TODO we want to figure out a way to be able to use the canonical color on LCD text, |
| 380 | // see the note on ComputeCanonicalColor above. We pick a dummy value for LCD text to |
| 381 | // ensure we always match the same key |
| 382 | GrColor canonicalColor = hasLCD ? SK_ColorTRANSPARENT : |
| 383 | ComputeCanonicalColor(skPaint, hasLCD); |
| 384 | |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 385 | key.fPixelGeometry = pixelGeometry; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 386 | key.fUniqueID = blob->uniqueID(); |
| 387 | key.fStyle = skPaint.getStyle(); |
| 388 | key.fHasBlur = SkToBool(mf); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 389 | key.fCanonicalColor = canonicalColor; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 390 | cacheBlob.reset(SkSafeRef(fCache->find(key))); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 391 | } |
| 392 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 393 | SkIRect clipRect; |
| 394 | clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 395 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 396 | SkScalar transX = 0.f; |
| 397 | SkScalar transY = 0.f; |
| 398 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 399 | // Though for the time being runs in the textblob can override the paint, they only touch font |
| 400 | // info. |
| 401 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 402 | if (!SkPaint2GrPaint(fContext, rt, skPaint, viewMatrix, true, &grPaint)) { |
| 403 | return; |
| 404 | } |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 405 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 406 | if (cacheBlob) { |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 407 | if (MustRegenerateBlob(&transX, &transY, *cacheBlob, skPaint, blurRec, viewMatrix, x, y)) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 408 | // We have to remake the blob because changes may invalidate our masks. |
| 409 | // TODO we could probably get away reuse most of the time if the pointer is unique, |
| 410 | // but we'd have to clear the subrun information |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 411 | fCache->remove(cacheBlob); |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 412 | cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint, |
| 413 | kGrayTextVASize))); |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 414 | this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 415 | blob, x, y, drawFilter, clipRect, rt, clip, grPaint); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 416 | } else { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 417 | // If we can reuse the blob, then make sure we update the blob's viewmatrix, and x/y |
| 418 | // offsets |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 419 | cacheBlob->fViewMatrix = viewMatrix; |
| 420 | cacheBlob->fX = x; |
| 421 | cacheBlob->fY = y; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 422 | fCache->makeMRU(cacheBlob); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 423 | } |
| 424 | } else { |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 425 | if (canCache) { |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 426 | cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint, |
| 427 | kGrayTextVASize))); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 428 | } else { |
| 429 | cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); |
| 430 | } |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 431 | this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 432 | blob, x, y, drawFilter, clipRect, rt, clip, grPaint); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 433 | } |
| 434 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 435 | cacheBlob->fPaintColor = skPaint.getColor(); |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 436 | this->flush(drawContext, blob, cacheBlob, rt, skPaint, grPaint, drawFilter, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 437 | clip, viewMatrix, clipBounds, x, y, transX, transY); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 438 | } |
| 439 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 440 | inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, |
| 441 | const SkMatrix& viewMatrix) { |
| 442 | // TODO: support perspective (need getMaxScale replacement) |
| 443 | if (viewMatrix.hasPerspective()) { |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | SkScalar maxScale = viewMatrix.getMaxScale(); |
| 448 | SkScalar scaledTextSize = maxScale*skPaint.getTextSize(); |
| 449 | // Hinted text looks far better at small resolutions |
| 450 | // Scaling up beyond 2x yields undesireable artifacts |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 451 | if (scaledTextSize < kMinDFFontSize || scaledTextSize > kLargeDFFontLimit) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | |
| 455 | if (!fEnableDFRendering && !skPaint.isDistanceFieldTextTEMP() && |
| 456 | scaledTextSize < kLargeDFFontSize) { |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | // rasterizers and mask filters modify alpha, which doesn't |
| 461 | // translate well to distance |
| 462 | if (skPaint.getRasterizer() || skPaint.getMaskFilter() || |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 463 | !fContext->shaderDerivativeSupport()) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 464 | return false; |
| 465 | } |
| 466 | |
| 467 | // TODO: add some stroking support |
| 468 | if (skPaint.getStyle() != SkPaint::kFill_Style) { |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | return true; |
| 473 | } |
| 474 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 475 | void GrAtlasTextContext::regenerateTextBlob(BitmapTextBlob* cacheBlob, |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 476 | const SkPaint& skPaint, GrColor color, |
| 477 | const SkMatrix& viewMatrix, |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 478 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 479 | SkDrawFilter* drawFilter, const SkIRect& clipRect, |
| 480 | GrRenderTarget* rt, const GrClip& clip, |
| 481 | const GrPaint& paint) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 482 | cacheBlob->fViewMatrix = viewMatrix; |
| 483 | cacheBlob->fX = x; |
| 484 | cacheBlob->fY = y; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 485 | |
| 486 | // Regenerate textblob |
| 487 | SkPaint runPaint = skPaint; |
| 488 | SkTextBlob::RunIterator it(blob); |
| 489 | for (int run = 0; !it.done(); it.next(), run++) { |
| 490 | int glyphCount = it.glyphCount(); |
| 491 | size_t textLen = glyphCount * sizeof(uint16_t); |
| 492 | const SkPoint& offset = it.offset(); |
| 493 | // applyFontToPaint() always overwrites the exact same attributes, |
| 494 | // so it is safe to not re-seed the paint for this reason. |
| 495 | it.applyFontToPaint(&runPaint); |
| 496 | |
| 497 | if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) { |
| 498 | // A false return from filter() means we should abort the current draw. |
| 499 | runPaint = skPaint; |
| 500 | continue; |
| 501 | } |
| 502 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 503 | runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 504 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 505 | // setup vertex / glyphIndex for the new run |
| 506 | if (run > 0) { |
| 507 | PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back(); |
| 508 | PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back(); |
| 509 | |
| 510 | newRun.fVertexStartIndex = lastRun.fVertexEndIndex; |
| 511 | newRun.fVertexEndIndex = lastRun.fVertexEndIndex; |
| 512 | |
| 513 | newRun.fGlyphStartIndex = lastRun.fGlyphEndIndex; |
| 514 | newRun.fGlyphEndIndex = lastRun.fGlyphEndIndex; |
| 515 | } |
| 516 | |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 517 | if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { |
| 518 | cacheBlob->setHasDistanceField(); |
| 519 | SkPaint dfPaint = runPaint; |
| 520 | SkScalar textRatio; |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 521 | this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMatrix); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 522 | Run& runIdx = cacheBlob->fRuns[run]; |
| 523 | PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); |
| 524 | subRun.fUseLCDText = runPaint.isLCDRenderText(); |
| 525 | subRun.fDrawAsDistanceFields = true; |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 526 | |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 527 | SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], dfPaint, NULL, true); |
| 528 | |
| 529 | SkTDArray<char> fallbackTxt; |
| 530 | SkTDArray<SkScalar> fallbackPos; |
| 531 | SkPoint dfOffset; |
| 532 | int scalarsPerPosition = 2; |
| 533 | switch (it.positioning()) { |
| 534 | case SkTextBlob::kDefault_Positioning: { |
| 535 | this->internalDrawDFText(cacheBlob, run, cache, dfPaint, color, viewMatrix, |
| 536 | (const char *)it.glyphs(), textLen, |
| 537 | x + offset.x(), y + offset.y(), clipRect, textRatio, |
| 538 | &fallbackTxt, &fallbackPos, &dfOffset, runPaint); |
| 539 | break; |
| 540 | } |
| 541 | case SkTextBlob::kHorizontal_Positioning: { |
| 542 | scalarsPerPosition = 1; |
| 543 | dfOffset = SkPoint::Make(x, y + offset.y()); |
| 544 | this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix, |
| 545 | (const char*)it.glyphs(), textLen, it.pos(), |
| 546 | scalarsPerPosition, dfOffset, clipRect, textRatio, |
| 547 | &fallbackTxt, &fallbackPos); |
| 548 | break; |
| 549 | } |
| 550 | case SkTextBlob::kFull_Positioning: { |
| 551 | dfOffset = SkPoint::Make(x, y); |
| 552 | this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix, |
| 553 | (const char*)it.glyphs(), textLen, it.pos(), |
| 554 | scalarsPerPosition, dfOffset, clipRect, textRatio, |
| 555 | &fallbackTxt, &fallbackPos); |
| 556 | break; |
| 557 | } |
| 558 | } |
| 559 | if (fallbackTxt.count()) { |
| 560 | this->fallbackDrawPosText(cacheBlob, run, rt, clip, paint, runPaint, viewMatrix, |
| 561 | fallbackTxt, fallbackPos, scalarsPerPosition, dfOffset, |
| 562 | clipRect); |
| 563 | } |
| 564 | |
| 565 | SkGlyphCache::AttachCache(cache); |
| 566 | } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { |
| 567 | cacheBlob->fRuns[run].fDrawAsPaths = true; |
| 568 | } else { |
| 569 | cacheBlob->setHasBitmap(); |
| 570 | SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPaint, &viewMatrix, |
| 571 | false); |
| 572 | switch (it.positioning()) { |
| 573 | case SkTextBlob::kDefault_Positioning: |
| 574 | this->internalDrawBMPText(cacheBlob, run, cache, runPaint, color, viewMatrix, |
| 575 | (const char *)it.glyphs(), textLen, |
| 576 | x + offset.x(), y + offset.y(), clipRect); |
| 577 | break; |
| 578 | case SkTextBlob::kHorizontal_Positioning: |
| 579 | this->internalDrawBMPPosText(cacheBlob, run, cache, runPaint, color, viewMatrix, |
| 580 | (const char*)it.glyphs(), textLen, it.pos(), 1, |
| 581 | SkPoint::Make(x, y + offset.y()), clipRect); |
| 582 | break; |
| 583 | case SkTextBlob::kFull_Positioning: |
| 584 | this->internalDrawBMPPosText(cacheBlob, run, cache, runPaint, color, viewMatrix, |
| 585 | (const char*)it.glyphs(), textLen, it.pos(), 2, |
| 586 | SkPoint::Make(x, y), clipRect); |
| 587 | break; |
| 588 | } |
| 589 | SkGlyphCache::AttachCache(cache); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | if (drawFilter) { |
| 593 | // A draw filter may change the paint arbitrarily, so we must re-seed in this case. |
| 594 | runPaint = skPaint; |
| 595 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 599 | inline void GrAtlasTextContext::initDistanceFieldPaint(BitmapTextBlob* blob, |
| 600 | SkPaint* skPaint, |
| 601 | SkScalar* textRatio, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 602 | const SkMatrix& viewMatrix) { |
| 603 | // getMaxScale doesn't support perspective, so neither do we at the moment |
| 604 | SkASSERT(!viewMatrix.hasPerspective()); |
| 605 | SkScalar maxScale = viewMatrix.getMaxScale(); |
| 606 | SkScalar textSize = skPaint->getTextSize(); |
| 607 | SkScalar scaledTextSize = textSize; |
| 608 | // if we have non-unity scale, we need to choose our base text size |
| 609 | // based on the SkPaint's text size multiplied by the max scale factor |
| 610 | // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? |
| 611 | if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { |
| 612 | scaledTextSize *= maxScale; |
| 613 | } |
| 614 | |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 615 | // We have three sizes of distance field text, and within each size 'bucket' there is a floor |
| 616 | // and ceiling. A scale outside of this range would require regenerating the distance fields |
| 617 | SkScalar dfMaskScaleFloor; |
| 618 | SkScalar dfMaskScaleCeil; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 619 | if (scaledTextSize <= kSmallDFFontLimit) { |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 620 | dfMaskScaleFloor = kMinDFFontSize; |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 621 | dfMaskScaleCeil = kSmallDFFontLimit; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 622 | *textRatio = textSize / kSmallDFFontSize; |
| 623 | skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 624 | } else if (scaledTextSize <= kMediumDFFontLimit) { |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 625 | dfMaskScaleFloor = kSmallDFFontLimit; |
| 626 | dfMaskScaleCeil = kMediumDFFontLimit; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 627 | *textRatio = textSize / kMediumDFFontSize; |
| 628 | skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 629 | } else { |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 630 | dfMaskScaleFloor = kMediumDFFontLimit; |
| 631 | dfMaskScaleCeil = kLargeDFFontLimit; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 632 | *textRatio = textSize / kLargeDFFontSize; |
| 633 | skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 634 | } |
| 635 | |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 636 | // Because there can be multiple runs in the blob, we want the overall maxMinScale, and |
| 637 | // minMaxScale to make regeneration decisions. Specifically, we want the maximum minimum scale |
| 638 | // we can tolerate before we'd drop to a lower mip size, and the minimum maximum scale we can |
| 639 | // tolerate before we'd have to move to a large mip size. When we actually test these values |
| 640 | // we look at the delta in scale between the new viewmatrix and the old viewmatrix, and test |
| 641 | // against these values to decide if we can reuse or not(ie, will a given scale change our mip |
| 642 | // level) |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 643 | SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil); |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 644 | blob->fMaxMinScale = SkMaxScalar(dfMaskScaleFloor / scaledTextSize, blob->fMaxMinScale); |
| 645 | blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMinMaxScale); |
| 646 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 647 | skPaint->setLCDRenderText(false); |
| 648 | skPaint->setAutohinted(false); |
| 649 | skPaint->setHinting(SkPaint::kNormal_Hinting); |
| 650 | skPaint->setSubpixelText(true); |
| 651 | } |
| 652 | |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 653 | inline void GrAtlasTextContext::fallbackDrawPosText(BitmapTextBlob* blob, |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 654 | int runIndex, |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 655 | GrRenderTarget* rt, const GrClip& clip, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 656 | const GrPaint& paint, |
| 657 | const SkPaint& skPaint, |
| 658 | const SkMatrix& viewMatrix, |
| 659 | const SkTDArray<char>& fallbackTxt, |
| 660 | const SkTDArray<SkScalar>& fallbackPos, |
| 661 | int scalarsPerPosition, |
| 662 | const SkPoint& offset, |
| 663 | const SkIRect& clipRect) { |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 664 | SkASSERT(fallbackTxt.count()); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 665 | blob->setHasBitmap(); |
| 666 | Run& run = blob->fRuns[runIndex]; |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 667 | // Push back a new subrun to fill and set the override descriptor |
| 668 | run.push_back(); |
| 669 | run.fOverrideDescriptor.reset(SkNEW(SkAutoDescriptor)); |
| 670 | skPaint.getScalerContextDescriptor(run.fOverrideDescriptor, |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 671 | &fDeviceProperties, &viewMatrix, false); |
| 672 | SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 673 | run.fOverrideDescriptor->getDesc()); |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 674 | this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, paint.getColor(), viewMatrix, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 675 | fallbackTxt.begin(), fallbackTxt.count(), |
| 676 | fallbackPos.begin(), scalarsPerPosition, offset, clipRect); |
| 677 | SkGlyphCache::AttachCache(cache); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | inline GrAtlasTextContext::BitmapTextBlob* |
| 681 | GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint, |
| 682 | const SkMatrix& viewMatrix, SkGlyphCache** cache, |
| 683 | SkPaint* dfPaint, SkScalar* textRatio) { |
| 684 | BitmapTextBlob* blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
| 685 | |
| 686 | *dfPaint = origPaint; |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 687 | this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 688 | blob->fViewMatrix = viewMatrix; |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 689 | Run& run = blob->fRuns[0]; |
| 690 | PerSubRunInfo& subRun = run.fSubRunInfo.back(); |
| 691 | subRun.fUseLCDText = origPaint.isLCDRenderText(); |
| 692 | subRun.fDrawAsDistanceFields = true; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 693 | |
| 694 | *cache = this->setupCache(&blob->fRuns[0], *dfPaint, NULL, true); |
| 695 | return blob; |
| 696 | } |
| 697 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 698 | inline GrAtlasTextContext::BitmapTextBlob* |
| 699 | GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, |
| 700 | const GrPaint& paint, const SkPaint& skPaint, |
| 701 | const SkMatrix& viewMatrix, |
| 702 | const char text[], size_t byteLength, |
| 703 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 704 | int glyphCount = skPaint.countText(text, byteLength); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 705 | SkIRect clipRect; |
| 706 | clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 707 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 708 | BitmapTextBlob* blob; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 709 | if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
| 710 | SkPaint dfPaint; |
| 711 | SkScalar textRatio; |
| 712 | SkGlyphCache* cache; |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 713 | blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPaint, &textRatio); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 714 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 715 | SkTDArray<char> fallbackTxt; |
| 716 | SkTDArray<SkScalar> fallbackPos; |
| 717 | SkPoint offset; |
| 718 | this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), viewMatrix, text, |
| 719 | byteLength, x, y, clipRect, textRatio, &fallbackTxt, &fallbackPos, |
| 720 | &offset, skPaint); |
| 721 | SkGlyphCache::AttachCache(cache); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 722 | if (fallbackTxt.count()) { |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 723 | this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMatrix, fallbackTxt, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 724 | fallbackPos, 2, offset, clipRect); |
| 725 | } |
| 726 | } else { |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 727 | blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 728 | blob->fViewMatrix = viewMatrix; |
| 729 | |
| 730 | SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix, false); |
| 731 | this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text, |
| 732 | byteLength, x, y, clipRect); |
| 733 | SkGlyphCache::AttachCache(cache); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 734 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 735 | return blob; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 736 | } |
| 737 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 738 | inline GrAtlasTextContext::BitmapTextBlob* |
| 739 | GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip, |
| 740 | const GrPaint& paint, const SkPaint& skPaint, |
| 741 | const SkMatrix& viewMatrix, |
| 742 | const char text[], size_t byteLength, |
| 743 | const SkScalar pos[], int scalarsPerPosition, |
| 744 | const SkPoint& offset, const SkIRect& regionClipBounds) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 745 | int glyphCount = skPaint.countText(text, byteLength); |
| 746 | |
| 747 | SkIRect clipRect; |
| 748 | clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 749 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 750 | BitmapTextBlob* blob; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 751 | if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
| 752 | SkPaint dfPaint; |
| 753 | SkScalar textRatio; |
| 754 | SkGlyphCache* cache; |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 755 | blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPaint, &textRatio); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 756 | |
| 757 | SkTDArray<char> fallbackTxt; |
| 758 | SkTDArray<SkScalar> fallbackPos; |
| 759 | this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), viewMatrix, text, |
| 760 | byteLength, pos, scalarsPerPosition, offset, clipRect, |
| 761 | textRatio, &fallbackTxt, &fallbackPos); |
| 762 | SkGlyphCache::AttachCache(cache); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 763 | if (fallbackTxt.count()) { |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 764 | this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMatrix, fallbackTxt, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 765 | fallbackPos, scalarsPerPosition, offset, clipRect); |
| 766 | } |
| 767 | } else { |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 768 | blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 769 | blob->fViewMatrix = viewMatrix; |
| 770 | SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix, false); |
| 771 | this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text, |
| 772 | byteLength, pos, scalarsPerPosition, offset, clipRect); |
| 773 | SkGlyphCache::AttachCache(cache); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 774 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 775 | return blob; |
| 776 | } |
| 777 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 778 | void GrAtlasTextContext::onDrawText(GrDrawContext* drawContext, GrRenderTarget* rt, |
| 779 | const GrClip& clip, |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 780 | const GrPaint& paint, const SkPaint& skPaint, |
| 781 | const SkMatrix& viewMatrix, |
| 782 | const char text[], size_t byteLength, |
| 783 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 784 | if (drawContext) { |
| 785 | SkAutoTUnref<BitmapTextBlob> blob( |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 786 | this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, |
| 787 | text, byteLength, x, y, regionClipBounds)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 788 | this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBounds); |
| 789 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 790 | } |
| 791 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 792 | void GrAtlasTextContext::onDrawPosText(GrDrawContext* drawContext, GrRenderTarget* rt, |
| 793 | const GrClip& clip, |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 794 | const GrPaint& paint, const SkPaint& skPaint, |
| 795 | const SkMatrix& viewMatrix, |
| 796 | const char text[], size_t byteLength, |
| 797 | const SkScalar pos[], int scalarsPerPosition, |
| 798 | const SkPoint& offset, const SkIRect& regionClipBounds) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 799 | if (drawContext) { |
| 800 | SkAutoTUnref<BitmapTextBlob> blob( |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 801 | this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, |
| 802 | text, byteLength, |
| 803 | pos, scalarsPerPosition, |
| 804 | offset, regionClipBounds)); |
| 805 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 806 | this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBounds); |
| 807 | } |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex, |
| 811 | SkGlyphCache* cache, const SkPaint& skPaint, |
| 812 | GrColor color, |
| 813 | const SkMatrix& viewMatrix, |
| 814 | const char text[], size_t byteLength, |
| 815 | SkScalar x, SkScalar y, const SkIRect& clipRect) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 816 | SkASSERT(byteLength == 0 || text != NULL); |
| 817 | |
| 818 | // nothing to draw |
| 819 | if (text == NULL || byteLength == 0) { |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | fCurrStrike = NULL; |
| 824 | SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| 825 | |
| 826 | // Get GrFontScaler from cache |
| 827 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 828 | |
| 829 | // transform our starting point |
| 830 | { |
| 831 | SkPoint loc; |
| 832 | viewMatrix.mapXY(x, y, &loc); |
| 833 | x = loc.fX; |
| 834 | y = loc.fY; |
| 835 | } |
| 836 | |
| 837 | // need to measure first |
| 838 | if (skPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 839 | SkVector stopVector; |
| 840 | MeasureText(cache, glyphCacheProc, text, byteLength, &stopVector); |
| 841 | |
| 842 | SkScalar stopX = stopVector.fX; |
| 843 | SkScalar stopY = stopVector.fY; |
| 844 | |
| 845 | if (skPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 846 | stopX = SkScalarHalf(stopX); |
| 847 | stopY = SkScalarHalf(stopY); |
| 848 | } |
| 849 | x -= stopX; |
| 850 | y -= stopY; |
| 851 | } |
| 852 | |
| 853 | const char* stop = text + byteLength; |
| 854 | |
| 855 | SkAutoKern autokern; |
| 856 | |
| 857 | SkFixed fxMask = ~0; |
| 858 | SkFixed fyMask = ~0; |
| 859 | SkScalar halfSampleX, halfSampleY; |
| 860 | if (cache->isSubpixel()) { |
| 861 | halfSampleX = halfSampleY = SkFixedToScalar(SkGlyph::kSubpixelRound); |
| 862 | SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix); |
| 863 | if (kX_SkAxisAlignment == baseline) { |
| 864 | fyMask = 0; |
| 865 | halfSampleY = SK_ScalarHalf; |
| 866 | } else if (kY_SkAxisAlignment == baseline) { |
| 867 | fxMask = 0; |
| 868 | halfSampleX = SK_ScalarHalf; |
| 869 | } |
| 870 | } else { |
| 871 | halfSampleX = halfSampleY = SK_ScalarHalf; |
| 872 | } |
| 873 | |
| 874 | Sk48Dot16 fx = SkScalarTo48Dot16(x + halfSampleX); |
| 875 | Sk48Dot16 fy = SkScalarTo48Dot16(y + halfSampleY); |
| 876 | |
| 877 | while (text < stop) { |
| 878 | const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); |
| 879 | |
| 880 | fx += autokern.adjust(glyph); |
| 881 | |
| 882 | if (glyph.fWidth) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 883 | this->bmpAppendGlyph(blob, |
| 884 | runIndex, |
| 885 | GrGlyph::Pack(glyph.getGlyphID(), |
| 886 | glyph.getSubXFixed(), |
| 887 | glyph.getSubYFixed(), |
| 888 | GrGlyph::kCoverage_MaskStyle), |
| 889 | Sk48Dot16FloorToInt(fx), |
| 890 | Sk48Dot16FloorToInt(fy), |
| 891 | color, |
| 892 | fontScaler, |
| 893 | clipRect); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | fx += glyph.fAdvanceX; |
| 897 | fy += glyph.fAdvanceY; |
| 898 | } |
| 899 | } |
| 900 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 901 | void GrAtlasTextContext::internalDrawBMPPosText(BitmapTextBlob* blob, int runIndex, |
| 902 | SkGlyphCache* cache, const SkPaint& skPaint, |
| 903 | GrColor color, |
| 904 | const SkMatrix& viewMatrix, |
| 905 | const char text[], size_t byteLength, |
| 906 | const SkScalar pos[], int scalarsPerPosition, |
| 907 | const SkPoint& offset, const SkIRect& clipRect) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 908 | SkASSERT(byteLength == 0 || text != NULL); |
| 909 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 910 | |
| 911 | // nothing to draw |
| 912 | if (text == NULL || byteLength == 0) { |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | fCurrStrike = NULL; |
| 917 | SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| 918 | |
| 919 | // Get GrFontScaler from cache |
| 920 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 921 | |
| 922 | const char* stop = text + byteLength; |
| 923 | SkTextAlignProc alignProc(skPaint.getTextAlign()); |
| 924 | SkTextMapStateProc tmsProc(viewMatrix, offset, scalarsPerPosition); |
| 925 | |
| 926 | if (cache->isSubpixel()) { |
| 927 | // maybe we should skip the rounding if linearText is set |
| 928 | SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix); |
| 929 | |
| 930 | SkFixed fxMask = ~0; |
| 931 | SkFixed fyMask = ~0; |
| 932 | SkScalar halfSampleX = SkFixedToScalar(SkGlyph::kSubpixelRound); |
| 933 | SkScalar halfSampleY = SkFixedToScalar(SkGlyph::kSubpixelRound); |
| 934 | if (kX_SkAxisAlignment == baseline) { |
| 935 | fyMask = 0; |
| 936 | halfSampleY = SK_ScalarHalf; |
| 937 | } else if (kY_SkAxisAlignment == baseline) { |
| 938 | fxMask = 0; |
| 939 | halfSampleX = SK_ScalarHalf; |
| 940 | } |
| 941 | |
| 942 | if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
| 943 | while (text < stop) { |
| 944 | SkPoint tmsLoc; |
| 945 | tmsProc(pos, &tmsLoc); |
| 946 | Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + halfSampleX); |
| 947 | Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + halfSampleY); |
| 948 | |
| 949 | const SkGlyph& glyph = glyphCacheProc(cache, &text, |
| 950 | fx & fxMask, fy & fyMask); |
| 951 | |
| 952 | if (glyph.fWidth) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 953 | this->bmpAppendGlyph(blob, |
| 954 | runIndex, |
| 955 | GrGlyph::Pack(glyph.getGlyphID(), |
| 956 | glyph.getSubXFixed(), |
| 957 | glyph.getSubYFixed(), |
| 958 | GrGlyph::kCoverage_MaskStyle), |
| 959 | Sk48Dot16FloorToInt(fx), |
| 960 | Sk48Dot16FloorToInt(fy), |
| 961 | color, |
| 962 | fontScaler, |
| 963 | clipRect); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 964 | } |
| 965 | pos += scalarsPerPosition; |
| 966 | } |
| 967 | } else { |
| 968 | while (text < stop) { |
| 969 | const char* currentText = text; |
| 970 | const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0); |
| 971 | |
| 972 | if (metricGlyph.fWidth) { |
| 973 | SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;) |
| 974 | SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;) |
| 975 | SkPoint tmsLoc; |
| 976 | tmsProc(pos, &tmsLoc); |
| 977 | SkPoint alignLoc; |
| 978 | alignProc(tmsLoc, metricGlyph, &alignLoc); |
| 979 | |
| 980 | Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + halfSampleX); |
| 981 | Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + halfSampleY); |
| 982 | |
| 983 | // have to call again, now that we've been "aligned" |
| 984 | const SkGlyph& glyph = glyphCacheProc(cache, ¤tText, |
| 985 | fx & fxMask, fy & fyMask); |
| 986 | // the assumption is that the metrics haven't changed |
| 987 | SkASSERT(prevAdvX == glyph.fAdvanceX); |
| 988 | SkASSERT(prevAdvY == glyph.fAdvanceY); |
| 989 | SkASSERT(glyph.fWidth); |
| 990 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 991 | this->bmpAppendGlyph(blob, |
| 992 | runIndex, |
| 993 | GrGlyph::Pack(glyph.getGlyphID(), |
| 994 | glyph.getSubXFixed(), |
| 995 | glyph.getSubYFixed(), |
| 996 | GrGlyph::kCoverage_MaskStyle), |
| 997 | Sk48Dot16FloorToInt(fx), |
| 998 | Sk48Dot16FloorToInt(fy), |
| 999 | color, |
| 1000 | fontScaler, |
| 1001 | clipRect); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1002 | } |
| 1003 | pos += scalarsPerPosition; |
| 1004 | } |
| 1005 | } |
| 1006 | } else { // not subpixel |
| 1007 | |
| 1008 | if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
| 1009 | while (text < stop) { |
| 1010 | // the last 2 parameters are ignored |
| 1011 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1012 | |
| 1013 | if (glyph.fWidth) { |
| 1014 | SkPoint tmsLoc; |
| 1015 | tmsProc(pos, &tmsLoc); |
| 1016 | |
| 1017 | Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf); //halfSampleX; |
| 1018 | Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1019 | this->bmpAppendGlyph(blob, |
| 1020 | runIndex, |
| 1021 | GrGlyph::Pack(glyph.getGlyphID(), |
| 1022 | glyph.getSubXFixed(), |
| 1023 | glyph.getSubYFixed(), |
| 1024 | GrGlyph::kCoverage_MaskStyle), |
| 1025 | Sk48Dot16FloorToInt(fx), |
| 1026 | Sk48Dot16FloorToInt(fy), |
| 1027 | color, |
| 1028 | fontScaler, |
| 1029 | clipRect); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1030 | } |
| 1031 | pos += scalarsPerPosition; |
| 1032 | } |
| 1033 | } else { |
| 1034 | while (text < stop) { |
| 1035 | // the last 2 parameters are ignored |
| 1036 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1037 | |
| 1038 | if (glyph.fWidth) { |
| 1039 | SkPoint tmsLoc; |
| 1040 | tmsProc(pos, &tmsLoc); |
| 1041 | |
| 1042 | SkPoint alignLoc; |
| 1043 | alignProc(tmsLoc, glyph, &alignLoc); |
| 1044 | |
| 1045 | Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf); //halfSampleX; |
| 1046 | Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf); //halfSampleY; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1047 | this->bmpAppendGlyph(blob, |
| 1048 | runIndex, |
| 1049 | GrGlyph::Pack(glyph.getGlyphID(), |
| 1050 | glyph.getSubXFixed(), |
| 1051 | glyph.getSubYFixed(), |
| 1052 | GrGlyph::kCoverage_MaskStyle), |
| 1053 | Sk48Dot16FloorToInt(fx), |
| 1054 | Sk48Dot16FloorToInt(fy), |
| 1055 | color, |
| 1056 | fontScaler, |
| 1057 | clipRect); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1058 | } |
| 1059 | pos += scalarsPerPosition; |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1065 | |
| 1066 | void GrAtlasTextContext::internalDrawDFText(BitmapTextBlob* blob, int runIndex, |
| 1067 | SkGlyphCache* cache, const SkPaint& skPaint, |
| 1068 | GrColor color, |
| 1069 | const SkMatrix& viewMatrix, |
| 1070 | const char text[], size_t byteLength, |
| 1071 | SkScalar x, SkScalar y, const SkIRect& clipRect, |
| 1072 | SkScalar textRatio, |
| 1073 | SkTDArray<char>* fallbackTxt, |
| 1074 | SkTDArray<SkScalar>* fallbackPos, |
| 1075 | SkPoint* offset, |
| 1076 | const SkPaint& origPaint) { |
| 1077 | SkASSERT(byteLength == 0 || text != NULL); |
| 1078 | |
| 1079 | // nothing to draw |
| 1080 | if (text == NULL || byteLength == 0) { |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | SkDrawCacheProc glyphCacheProc = origPaint.getDrawCacheProc(); |
| 1085 | SkAutoDescriptor desc; |
| 1086 | origPaint.getScalerContextDescriptor(&desc, &fDeviceProperties, NULL, true); |
| 1087 | SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(origPaint.getTypeface(), |
| 1088 | desc.getDesc()); |
| 1089 | |
| 1090 | SkTArray<SkScalar> positions; |
| 1091 | |
| 1092 | const char* textPtr = text; |
| 1093 | SkFixed stopX = 0; |
| 1094 | SkFixed stopY = 0; |
| 1095 | SkFixed origin = 0; |
| 1096 | switch (origPaint.getTextAlign()) { |
| 1097 | case SkPaint::kRight_Align: origin = SK_Fixed1; break; |
| 1098 | case SkPaint::kCenter_Align: origin = SK_FixedHalf; break; |
| 1099 | case SkPaint::kLeft_Align: origin = 0; break; |
| 1100 | } |
| 1101 | |
| 1102 | SkAutoKern autokern; |
| 1103 | const char* stop = text + byteLength; |
| 1104 | while (textPtr < stop) { |
| 1105 | // don't need x, y here, since all subpixel variants will have the |
| 1106 | // same advance |
| 1107 | const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr, 0, 0); |
| 1108 | |
| 1109 | SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph); |
| 1110 | positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width))); |
| 1111 | |
| 1112 | SkFixed height = glyph.fAdvanceY; |
| 1113 | positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height))); |
| 1114 | |
| 1115 | stopX += width; |
| 1116 | stopY += height; |
| 1117 | } |
| 1118 | SkASSERT(textPtr == stop); |
| 1119 | |
| 1120 | // now adjust starting point depending on alignment |
| 1121 | SkScalar alignX = SkFixedToScalar(stopX); |
| 1122 | SkScalar alignY = SkFixedToScalar(stopY); |
| 1123 | if (origPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 1124 | alignX = SkScalarHalf(alignX); |
| 1125 | alignY = SkScalarHalf(alignY); |
| 1126 | } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) { |
| 1127 | alignX = 0; |
| 1128 | alignY = 0; |
| 1129 | } |
| 1130 | x -= alignX; |
| 1131 | y -= alignY; |
| 1132 | *offset = SkPoint::Make(x, y); |
| 1133 | |
| 1134 | this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatrix, text, byteLength, |
| 1135 | positions.begin(), 2, *offset, clipRect, textRatio, fallbackTxt, |
| 1136 | fallbackPos); |
| 1137 | SkGlyphCache::AttachCache(origPaintCache); |
| 1138 | } |
| 1139 | |
| 1140 | void GrAtlasTextContext::internalDrawDFPosText(BitmapTextBlob* blob, int runIndex, |
| 1141 | SkGlyphCache* cache, const SkPaint& skPaint, |
| 1142 | GrColor color, |
| 1143 | const SkMatrix& viewMatrix, |
| 1144 | const char text[], size_t byteLength, |
| 1145 | const SkScalar pos[], int scalarsPerPosition, |
| 1146 | const SkPoint& offset, const SkIRect& clipRect, |
| 1147 | SkScalar textRatio, |
| 1148 | SkTDArray<char>* fallbackTxt, |
| 1149 | SkTDArray<SkScalar>* fallbackPos) { |
| 1150 | |
| 1151 | SkASSERT(byteLength == 0 || text != NULL); |
| 1152 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 1153 | |
| 1154 | // nothing to draw |
| 1155 | if (text == NULL || byteLength == 0) { |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | fCurrStrike = NULL; |
| 1160 | |
| 1161 | SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| 1162 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 1163 | |
| 1164 | const char* stop = text + byteLength; |
| 1165 | |
| 1166 | if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
| 1167 | while (text < stop) { |
| 1168 | const char* lastText = text; |
| 1169 | // the last 2 parameters are ignored |
| 1170 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1171 | |
| 1172 | if (glyph.fWidth) { |
| 1173 | SkScalar x = offset.x() + pos[0]; |
| 1174 | SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0); |
| 1175 | |
| 1176 | if (!this->dfAppendGlyph(blob, |
| 1177 | runIndex, |
| 1178 | GrGlyph::Pack(glyph.getGlyphID(), |
| 1179 | glyph.getSubXFixed(), |
| 1180 | glyph.getSubYFixed(), |
| 1181 | GrGlyph::kDistance_MaskStyle), |
| 1182 | x, y, color, fontScaler, clipRect, |
| 1183 | textRatio, viewMatrix)) { |
| 1184 | // couldn't append, send to fallback |
| 1185 | fallbackTxt->append(SkToInt(text-lastText), lastText); |
| 1186 | *fallbackPos->append() = pos[0]; |
| 1187 | if (2 == scalarsPerPosition) { |
| 1188 | *fallbackPos->append() = pos[1]; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | pos += scalarsPerPosition; |
| 1193 | } |
| 1194 | } else { |
| 1195 | SkScalar alignMul = SkPaint::kCenter_Align == skPaint.getTextAlign() ? SK_ScalarHalf |
| 1196 | : SK_Scalar1; |
| 1197 | while (text < stop) { |
| 1198 | const char* lastText = text; |
| 1199 | // the last 2 parameters are ignored |
| 1200 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1201 | |
| 1202 | if (glyph.fWidth) { |
| 1203 | SkScalar x = offset.x() + pos[0]; |
| 1204 | SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0); |
| 1205 | |
| 1206 | SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio; |
| 1207 | SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio; |
| 1208 | |
| 1209 | if (!this->dfAppendGlyph(blob, |
| 1210 | runIndex, |
| 1211 | GrGlyph::Pack(glyph.getGlyphID(), |
| 1212 | glyph.getSubXFixed(), |
| 1213 | glyph.getSubYFixed(), |
| 1214 | GrGlyph::kDistance_MaskStyle), |
| 1215 | x - advanceX, y - advanceY, color, |
| 1216 | fontScaler, |
| 1217 | clipRect, |
| 1218 | textRatio, |
| 1219 | viewMatrix)) { |
| 1220 | // couldn't append, send to fallback |
| 1221 | fallbackTxt->append(SkToInt(text-lastText), lastText); |
| 1222 | *fallbackPos->append() = pos[0]; |
| 1223 | if (2 == scalarsPerPosition) { |
| 1224 | *fallbackPos->append() = pos[1]; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | pos += scalarsPerPosition; |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | void GrAtlasTextContext::bmpAppendGlyph(BitmapTextBlob* blob, int runIndex, |
| 1234 | GrGlyph::PackedID packed, |
| 1235 | int vx, int vy, GrColor color, GrFontScaler* scaler, |
| 1236 | const SkIRect& clipRect) { |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1237 | Run& run = blob->fRuns[runIndex]; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1238 | if (!fCurrStrike) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1239 | fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1240 | run.fStrike.reset(SkRef(fCurrStrike)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1244 | if (!glyph) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1245 | return; |
| 1246 | } |
| 1247 | |
| 1248 | int x = vx + glyph->fBounds.fLeft; |
| 1249 | int y = vy + glyph->fBounds.fTop; |
| 1250 | |
| 1251 | // keep them as ints until we've done the clip-test |
| 1252 | int width = glyph->fBounds.width(); |
| 1253 | int height = glyph->fBounds.height(); |
| 1254 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1255 | #if 0 |
| 1256 | // Not checking the clip bounds might introduce a performance regression. However, its not |
| 1257 | // clear if this is still true today with the larger tiles we use in Chrome. For repositionable |
| 1258 | // blobs, we want to make sure we have all of the glyphs, so clipping them out is not ideal. |
| 1259 | // We could store the cliprect in the key, but then we'd lose the ability to do integer scrolls |
| 1260 | // TODO verify this |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1261 | // check if we clipped out |
| 1262 | if (clipRect.quickReject(x, y, x + width, y + height)) { |
| 1263 | return; |
| 1264 | } |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1265 | #endif |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1266 | |
| 1267 | // If the glyph is too large we fall back to paths |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1268 | if (glyph->fTooLargeForAtlas) { |
joshualitt | 19e4c02 | 2015-05-13 11:23:03 -0700 | [diff] [blame] | 1269 | this->appendGlyphPath(blob, glyph, scaler, SkIntToScalar(vx), SkIntToScalar(vy)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1270 | return; |
| 1271 | } |
| 1272 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1273 | GrMaskFormat format = glyph->fMaskFormat; |
| 1274 | |
| 1275 | PerSubRunInfo* subRun = &run.fSubRunInfo.back(); |
| 1276 | if (run.fInitialized && subRun->fMaskFormat != format) { |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 1277 | subRun = &run.fSubRunInfo.push_back(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | run.fInitialized = true; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1281 | |
| 1282 | size_t vertexStride = get_vertex_stride(format); |
| 1283 | |
| 1284 | SkRect r; |
| 1285 | r.fLeft = SkIntToScalar(x); |
| 1286 | r.fTop = SkIntToScalar(y); |
| 1287 | r.fRight = r.fLeft + SkIntToScalar(width); |
| 1288 | r.fBottom = r.fTop + SkIntToScalar(height); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1289 | subRun->fMaskFormat = format; |
| 1290 | this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMaskFormat == format, |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1291 | glyph); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1292 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1293 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1294 | bool GrAtlasTextContext::dfAppendGlyph(BitmapTextBlob* blob, int runIndex, |
| 1295 | GrGlyph::PackedID packed, |
| 1296 | SkScalar sx, SkScalar sy, GrColor color, |
| 1297 | GrFontScaler* scaler, |
| 1298 | const SkIRect& clipRect, |
| 1299 | SkScalar textRatio, const SkMatrix& viewMatrix) { |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1300 | Run& run = blob->fRuns[runIndex]; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1301 | if (!fCurrStrike) { |
| 1302 | fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1303 | run.fStrike.reset(SkRef(fCurrStrike)); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1307 | if (!glyph) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | // fallback to color glyph support |
| 1312 | if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
| 1313 | return false; |
| 1314 | } |
| 1315 | |
| 1316 | SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); |
| 1317 | SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); |
| 1318 | SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2 * SK_DistanceFieldInset); |
| 1319 | SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2 * SK_DistanceFieldInset); |
| 1320 | |
| 1321 | SkScalar scale = textRatio; |
| 1322 | dx *= scale; |
| 1323 | dy *= scale; |
| 1324 | width *= scale; |
| 1325 | height *= scale; |
| 1326 | sx += dx; |
| 1327 | sy += dy; |
| 1328 | SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); |
| 1329 | |
| 1330 | #if 0 |
| 1331 | // check if we clipped out |
| 1332 | SkRect dstRect; |
| 1333 | viewMatrix.mapRect(&dstRect, glyphRect); |
| 1334 | if (clipRect.quickReject(SkScalarTruncToInt(dstRect.left()), |
| 1335 | SkScalarTruncToInt(dstRect.top()), |
| 1336 | SkScalarTruncToInt(dstRect.right()), |
| 1337 | SkScalarTruncToInt(dstRect.bottom()))) { |
| 1338 | return true; |
| 1339 | } |
| 1340 | #endif |
| 1341 | |
| 1342 | // TODO combine with the above |
| 1343 | // If the glyph is too large we fall back to paths |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1344 | if (glyph->fTooLargeForAtlas) { |
joshualitt | 19e4c02 | 2015-05-13 11:23:03 -0700 | [diff] [blame] | 1345 | this->appendGlyphPath(blob, glyph, scaler, sx - dx, sy - dy); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1346 | return true; |
| 1347 | } |
| 1348 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1349 | PerSubRunInfo* subRun = &run.fSubRunInfo.back(); |
| 1350 | SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat); |
| 1351 | subRun->fMaskFormat = kA8_GrMaskFormat; |
| 1352 | |
| 1353 | size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCDText); |
| 1354 | |
| 1355 | bool useColorVerts = !subRun->fUseLCDText; |
| 1356 | this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride, useColorVerts, |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1357 | glyph); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1358 | return true; |
| 1359 | } |
| 1360 | |
| 1361 | inline void GrAtlasTextContext::appendGlyphPath(BitmapTextBlob* blob, GrGlyph* glyph, |
joshualitt | 19e4c02 | 2015-05-13 11:23:03 -0700 | [diff] [blame] | 1362 | GrFontScaler* scaler, SkScalar x, SkScalar y) { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1363 | if (NULL == glyph->fPath) { |
| 1364 | SkPath* path = SkNEW(SkPath); |
| 1365 | if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
| 1366 | // flag the glyph as being dead? |
| 1367 | SkDELETE(path); |
| 1368 | return; |
| 1369 | } |
| 1370 | glyph->fPath = path; |
| 1371 | } |
| 1372 | SkASSERT(glyph->fPath); |
| 1373 | blob->fBigGlyphs.push_back(BitmapTextBlob::BigGlyph(*glyph->fPath, x, y)); |
| 1374 | } |
| 1375 | |
| 1376 | inline void GrAtlasTextContext::appendGlyphCommon(BitmapTextBlob* blob, Run* run, |
| 1377 | Run::SubRunInfo* subRun, |
| 1378 | const SkRect& positions, GrColor color, |
| 1379 | size_t vertexStride, bool useVertexColor, |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1380 | GrGlyph* glyph) { |
| 1381 | blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1382 | run->fVertexBounds.joinNonEmptyArg(positions); |
| 1383 | run->fColor = color; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1384 | |
| 1385 | intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVertexEndIndex); |
| 1386 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1387 | if (useVertexColor) { |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1388 | // V0 |
| 1389 | SkPoint* position = reinterpret_cast<SkPoint*>(vertex); |
| 1390 | position->set(positions.fLeft, positions.fTop); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1391 | SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 1392 | *colorPtr = color; |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1393 | vertex += vertexStride; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1394 | |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1395 | // V1 |
| 1396 | position = reinterpret_cast<SkPoint*>(vertex); |
| 1397 | position->set(positions.fLeft, positions.fBottom); |
| 1398 | colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1399 | *colorPtr = color; |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1400 | vertex += vertexStride; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1401 | |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1402 | // V2 |
| 1403 | position = reinterpret_cast<SkPoint*>(vertex); |
| 1404 | position->set(positions.fRight, positions.fBottom); |
| 1405 | colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1406 | *colorPtr = color; |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1407 | vertex += vertexStride; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1408 | |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1409 | // V3 |
| 1410 | position = reinterpret_cast<SkPoint*>(vertex); |
| 1411 | position->set(positions.fRight, positions.fTop); |
| 1412 | colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1413 | *colorPtr = color; |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 1414 | } else { |
| 1415 | // V0 |
| 1416 | SkPoint* position = reinterpret_cast<SkPoint*>(vertex); |
| 1417 | position->set(positions.fLeft, positions.fTop); |
| 1418 | vertex += vertexStride; |
| 1419 | |
| 1420 | // V1 |
| 1421 | position = reinterpret_cast<SkPoint*>(vertex); |
| 1422 | position->set(positions.fLeft, positions.fBottom); |
| 1423 | vertex += vertexStride; |
| 1424 | |
| 1425 | // V2 |
| 1426 | position = reinterpret_cast<SkPoint*>(vertex); |
| 1427 | position->set(positions.fRight, positions.fBottom); |
| 1428 | vertex += vertexStride; |
| 1429 | |
| 1430 | // V3 |
| 1431 | position = reinterpret_cast<SkPoint*>(vertex); |
| 1432 | position->set(positions.fRight, positions.fTop); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | subRun->fGlyphEndIndex++; |
| 1436 | subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
| 1437 | } |
| 1438 | |
| 1439 | class BitmapTextBatch : public GrBatch { |
| 1440 | public: |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1441 | typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 1442 | typedef GrAtlasTextContext::BitmapTextBlob Blob; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1443 | typedef Blob::Run Run; |
| 1444 | typedef Run::SubRunInfo TextInfo; |
| 1445 | struct Geometry { |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1446 | Blob* fBlob; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1447 | int fRun; |
| 1448 | int fSubRun; |
| 1449 | GrColor fColor; |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1450 | SkScalar fTransX; |
| 1451 | SkScalar fTransY; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1452 | }; |
| 1453 | |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1454 | static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount, |
| 1455 | GrBatchFontCache* fontCache) { |
| 1456 | return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1459 | static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount, |
| 1460 | GrBatchFontCache* fontCache, |
| 1461 | DistanceAdjustTable* distanceAdjustTable, |
| 1462 | SkColor filteredColor, bool useLCDText, |
| 1463 | bool useBGR, float gamma) { |
| 1464 | return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache, distanceAdjustTable, |
| 1465 | filteredColor, useLCDText, useBGR, gamma)); |
| 1466 | } |
| 1467 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1468 | const char* name() const override { return "BitmapTextBatch"; } |
| 1469 | |
| 1470 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 1471 | if (kARGB_GrMaskFormat == fMaskFormat) { |
| 1472 | out->setUnknownFourComponents(); |
| 1473 | } else { |
| 1474 | out->setKnownFourComponents(fBatch.fColor); |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1479 | if (!fUseDistanceFields) { |
| 1480 | // Bitmap Text |
| 1481 | if (kARGB_GrMaskFormat != fMaskFormat) { |
| 1482 | if (GrPixelConfigIsAlphaOnly(fPixelConfig)) { |
| 1483 | out->setUnknownSingleComponent(); |
| 1484 | } else if (GrPixelConfigIsOpaque(fPixelConfig)) { |
| 1485 | out->setUnknownOpaqueFourComponents(); |
| 1486 | out->setUsingLCDCoverage(); |
| 1487 | } else { |
| 1488 | out->setUnknownFourComponents(); |
| 1489 | out->setUsingLCDCoverage(); |
| 1490 | } |
| 1491 | } else { |
| 1492 | out->setKnownSingleComponent(0xff); |
| 1493 | } |
| 1494 | } else { |
| 1495 | // Distance fields |
| 1496 | if (!fUseLCDText) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1497 | out->setUnknownSingleComponent(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1498 | } else { |
| 1499 | out->setUnknownFourComponents(); |
| 1500 | out->setUsingLCDCoverage(); |
| 1501 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void initBatchTracker(const GrPipelineInfo& init) override { |
| 1506 | // Handle any color overrides |
| 1507 | if (init.fColorIgnored) { |
| 1508 | fBatch.fColor = GrColor_ILLEGAL; |
| 1509 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 1510 | fBatch.fColor = init.fOverrideColor; |
| 1511 | } |
| 1512 | |
| 1513 | // setup batch properties |
| 1514 | fBatch.fColorIgnored = init.fColorIgnored; |
| 1515 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 1516 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 1517 | } |
| 1518 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1519 | struct FlushInfo { |
| 1520 | SkAutoTUnref<const GrVertexBuffer> fVertexBuffer; |
| 1521 | SkAutoTUnref<const GrIndexBuffer> fIndexBuffer; |
| 1522 | int fGlyphsToFlush; |
| 1523 | int fVertexOffset; |
| 1524 | }; |
| 1525 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1526 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
| 1527 | // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix. |
| 1528 | // TODO actually only invert if we don't have RGBA |
| 1529 | SkMatrix localMatrix; |
| 1530 | if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { |
| 1531 | SkDebugf("Cannot invert viewmatrix\n"); |
| 1532 | return; |
| 1533 | } |
| 1534 | |
joshualitt | 62db8ba | 2015-04-09 08:22:37 -0700 | [diff] [blame] | 1535 | GrTexture* texture = fFontCache->getTexture(fMaskFormat); |
| 1536 | if (!texture) { |
| 1537 | SkDebugf("Could not allocate backing texture for atlas\n"); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1541 | SkAutoTUnref<const GrGeometryProcessor> gp; |
| 1542 | if (fUseDistanceFields) { |
| 1543 | gp.reset(this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this->color(), |
| 1544 | texture)); |
| 1545 | } else { |
| 1546 | GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1547 | gp.reset(GrBitmapTextGeoProc::Create(this->color(), |
| 1548 | texture, |
| 1549 | params, |
| 1550 | fMaskFormat, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 1551 | localMatrix, |
| 1552 | this->usesLocalCoords())); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1553 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1554 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1555 | FlushInfo flushInfo; |
| 1556 | flushInfo.fGlyphsToFlush = 0; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1557 | size_t vertexStride = gp->getVertexStride(); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1558 | SkASSERT(vertexStride == (fUseDistanceFields ? |
| 1559 | get_vertex_stride_df(fMaskFormat, fUseLCDText) : |
| 1560 | get_vertex_stride(fMaskFormat))); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1561 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 1562 | batchTarget->initDraw(gp, pipeline); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1563 | |
| 1564 | int glyphCount = this->numGlyphs(); |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1565 | int instanceCount = fInstanceCount; |
bsalomon | 8415abe | 2015-05-04 11:41:41 -0700 | [diff] [blame] | 1566 | const GrVertexBuffer* vertexBuffer; |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1567 | |
robertphillips | e40d397 | 2015-05-07 09:51:43 -0700 | [diff] [blame] | 1568 | void* vertices = batchTarget->makeVertSpace(vertexStride, |
| 1569 | glyphCount * kVerticesPerGlyph, |
| 1570 | &vertexBuffer, |
| 1571 | &flushInfo.fVertexOffset); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1572 | flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
| 1573 | flushInfo.fIndexBuffer.reset(batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 1574 | if (!vertices || !flushInfo.fVertexBuffer) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1575 | SkDebugf("Could not allocate vertices\n"); |
| 1576 | return; |
| 1577 | } |
| 1578 | |
| 1579 | unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
| 1580 | |
joshualitt | 25ba7ea | 2015-04-21 07:49:49 -0700 | [diff] [blame] | 1581 | // We cache some values to avoid going to the glyphcache for the same fontScaler twice |
| 1582 | // in a row |
| 1583 | const SkDescriptor* desc = NULL; |
| 1584 | SkGlyphCache* cache = NULL; |
| 1585 | GrFontScaler* scaler = NULL; |
joshualitt | 25ba7ea | 2015-04-21 07:49:49 -0700 | [diff] [blame] | 1586 | SkTypeface* typeface = NULL; |
| 1587 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1588 | for (int i = 0; i < instanceCount; i++) { |
| 1589 | Geometry& args = fGeoData[i]; |
| 1590 | Blob* blob = args.fBlob; |
| 1591 | Run& run = blob->fRuns[args.fRun]; |
| 1592 | TextInfo& info = run.fSubRunInfo[args.fSubRun]; |
| 1593 | |
| 1594 | uint64_t currentAtlasGen = fFontCache->atlasGeneration(fMaskFormat); |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 1595 | bool regenerateTextureCoords = info.fAtlasGeneration != currentAtlasGen || |
| 1596 | run.fStrike->isAbandoned(); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1597 | bool regenerateColors; |
| 1598 | if (fUseDistanceFields) { |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 1599 | regenerateColors = !fUseLCDText && run.fColor != args.fColor; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1600 | } else { |
| 1601 | regenerateColors = kA8_GrMaskFormat == fMaskFormat && run.fColor != args.fColor; |
| 1602 | } |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1603 | bool regeneratePositions = args.fTransX != 0.f || args.fTransY != 0.f; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1604 | int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
| 1605 | |
| 1606 | // We regenerate both texture coords and colors in the blob itself, and update the |
| 1607 | // atlas generation. If we don't end up purging any unused plots, we can avoid |
| 1608 | // regenerating the coords. We could take a finer grained approach to updating texture |
| 1609 | // coords but its not clear if the extra bookkeeping would offset any gains. |
| 1610 | // To avoid looping over the glyphs twice, we do one loop and conditionally update color |
| 1611 | // or coords as needed. One final note, if we have to break a run for an atlas eviction |
| 1612 | // then we can't really trust the atlas has all of the correct data. Atlas evictions |
| 1613 | // should be pretty rare, so we just always regenerate in those cases |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1614 | if (regenerateTextureCoords || regenerateColors || regeneratePositions) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1615 | // first regenerate texture coordinates / colors if need be |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1616 | bool brokenRun = false; |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1617 | |
| 1618 | // Because the GrBatchFontCache may evict the strike a blob depends on using for |
| 1619 | // generating its texture coords, we have to track whether or not the strike has |
| 1620 | // been abandoned. If it hasn't been abandoned, then we can use the GrGlyph*s as is |
| 1621 | // otherwise we have to get the new strike, and use that to get the correct glyphs. |
| 1622 | // Because we do not have the packed ids, and thus can't look up our glyphs in the |
| 1623 | // new strike, we instead keep our ref to the old strike and use the packed ids from |
| 1624 | // it. These ids will still be valid as long as we hold the ref. When we are done |
| 1625 | // updating our cache of the GrGlyph*s, we drop our ref on the old strike |
| 1626 | bool regenerateGlyphs = false; |
| 1627 | GrBatchTextStrike* strike = NULL; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1628 | if (regenerateTextureCoords) { |
joshualitt | b4c507e | 2015-04-08 08:07:59 -0700 | [diff] [blame] | 1629 | info.fBulkUseToken.reset(); |
joshualitt | 25ba7ea | 2015-04-21 07:49:49 -0700 | [diff] [blame] | 1630 | |
| 1631 | // We can reuse if we have a valid strike and our descriptors / typeface are the |
| 1632 | // same |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 1633 | const SkDescriptor* newDesc = run.fOverrideDescriptor ? |
| 1634 | run.fOverrideDescriptor->getDesc() : |
joshualitt | 25ba7ea | 2015-04-21 07:49:49 -0700 | [diff] [blame] | 1635 | run.fDescriptor.getDesc(); |
| 1636 | if (!cache || !SkTypeface::Equal(typeface, run.fTypeface) || |
| 1637 | !(desc->equals(*newDesc))) { |
| 1638 | if (cache) { |
| 1639 | SkGlyphCache::AttachCache(cache); |
| 1640 | } |
| 1641 | desc = newDesc; |
| 1642 | cache = SkGlyphCache::DetachCache(run.fTypeface, desc); |
| 1643 | scaler = GrTextContext::GetGrFontScaler(cache); |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1644 | strike = run.fStrike; |
joshualitt | 25ba7ea | 2015-04-21 07:49:49 -0700 | [diff] [blame] | 1645 | typeface = run.fTypeface; |
| 1646 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1647 | |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1648 | if (run.fStrike->isAbandoned()) { |
| 1649 | regenerateGlyphs = true; |
| 1650 | strike = fFontCache->getStrike(scaler); |
| 1651 | } else { |
| 1652 | strike = run.fStrike; |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1657 | if (regenerateTextureCoords) { |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1658 | size_t glyphOffset = glyphIdx + info.fGlyphStartIndex; |
| 1659 | GrGlyph* glyph; |
| 1660 | if (regenerateGlyphs) { |
| 1661 | // Get the id from the old glyph, and use the new strike to lookup |
| 1662 | // the glyph. |
| 1663 | glyph = blob->fGlyphs[glyphOffset]; |
| 1664 | blob->fGlyphs[glyphOffset] = strike->getGlyph(glyph->fPackedID, |
| 1665 | scaler); |
| 1666 | } |
| 1667 | glyph = blob->fGlyphs[glyphOffset]; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1668 | SkASSERT(glyph); |
| 1669 | |
| 1670 | if (!fFontCache->hasGlyph(glyph) && |
| 1671 | !strike->addGlyphToAtlas(batchTarget, glyph, scaler)) { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1672 | this->flush(batchTarget, &flushInfo); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 1673 | batchTarget->initDraw(gp, pipeline); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1674 | brokenRun = glyphIdx > 0; |
| 1675 | |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1676 | SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(batchTarget, |
| 1677 | glyph, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1678 | scaler); |
| 1679 | SkASSERT(success); |
| 1680 | } |
joshualitt | b4c507e | 2015-04-08 08:07:59 -0700 | [diff] [blame] | 1681 | fFontCache->addGlyphToBulkAndSetUseToken(&info.fBulkUseToken, glyph, |
| 1682 | batchTarget->currentToken()); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1683 | |
| 1684 | // Texture coords are the last vertex attribute so we get a pointer to the |
| 1685 | // first one and then map with stride in regenerateTextureCoords |
| 1686 | intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices); |
| 1687 | vertex += info.fVertexStartIndex; |
| 1688 | vertex += vertexStride * glyphIdx * kVerticesPerGlyph; |
| 1689 | vertex += vertexStride - sizeof(SkIPoint16); |
| 1690 | |
| 1691 | this->regenerateTextureCoords(glyph, vertex, vertexStride); |
| 1692 | } |
| 1693 | |
| 1694 | if (regenerateColors) { |
| 1695 | intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices); |
| 1696 | vertex += info.fVertexStartIndex; |
| 1697 | vertex += vertexStride * glyphIdx * kVerticesPerGlyph + sizeof(SkPoint); |
| 1698 | this->regenerateColors(vertex, vertexStride, args.fColor); |
| 1699 | } |
| 1700 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1701 | if (regeneratePositions) { |
| 1702 | intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices); |
| 1703 | vertex += info.fVertexStartIndex; |
| 1704 | vertex += vertexStride * glyphIdx * kVerticesPerGlyph; |
| 1705 | SkScalar transX = args.fTransX; |
| 1706 | SkScalar transY = args.fTransY; |
| 1707 | this->regeneratePositions(vertex, vertexStride, transX, transY); |
| 1708 | } |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1709 | flushInfo.fGlyphsToFlush++; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1712 | // We my have changed the color so update it here |
| 1713 | run.fColor = args.fColor; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1714 | if (regenerateTextureCoords) { |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 1715 | if (regenerateGlyphs) { |
| 1716 | run.fStrike.reset(SkRef(strike)); |
| 1717 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1718 | info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAtlasGeneration : |
| 1719 | fFontCache->atlasGeneration(fMaskFormat); |
| 1720 | } |
| 1721 | } else { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1722 | flushInfo.fGlyphsToFlush += glyphCount; |
joshualitt | b4c507e | 2015-04-08 08:07:59 -0700 | [diff] [blame] | 1723 | |
| 1724 | // set use tokens for all of the glyphs in our subrun. This is only valid if we |
| 1725 | // have a valid atlas generation |
| 1726 | fFontCache->setUseTokenBulk(info.fBulkUseToken, |
| 1727 | batchTarget->currentToken(), |
| 1728 | fMaskFormat); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | // now copy all vertices |
| 1732 | size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; |
| 1733 | memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCount); |
| 1734 | |
| 1735 | currVertex += byteCount; |
| 1736 | } |
joshualitt | 25ba7ea | 2015-04-21 07:49:49 -0700 | [diff] [blame] | 1737 | // Make sure to attach the last cache if applicable |
| 1738 | if (cache) { |
| 1739 | SkGlyphCache::AttachCache(cache); |
| 1740 | } |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1741 | this->flush(batchTarget, &flushInfo); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1744 | // The minimum number of Geometry we will try to allocate. |
| 1745 | static const int kMinAllocated = 32; |
| 1746 | |
| 1747 | // Total number of Geometry this Batch owns |
| 1748 | int instanceCount() const { return fInstanceCount; } |
| 1749 | SkAutoSTMalloc<kMinAllocated, Geometry>* geoData() { return &fGeoData; } |
| 1750 | |
| 1751 | // to avoid even the initial copy of the struct, we have a getter for the first item which |
| 1752 | // is used to seed the batch with its initial geometry. After seeding, the client should call |
| 1753 | // init() so the Batch can initialize itself |
| 1754 | Geometry& geometry() { return fGeoData[0]; } |
| 1755 | void init() { |
joshualitt | 444987f | 2015-05-06 06:46:01 -0700 | [diff] [blame] | 1756 | const Geometry& geo = fGeoData[0]; |
| 1757 | fBatch.fColor = geo.fColor; |
| 1758 | fBatch.fViewMatrix = geo.fBlob->fViewMatrix; |
| 1759 | |
| 1760 | // We don't yet position distance field text on the cpu, so we have to map the vertex bounds |
| 1761 | // into device space |
| 1762 | const Run& run = geo.fBlob->fRuns[geo.fRun]; |
| 1763 | if (run.fSubRunInfo[geo.fSubRun].fDrawAsDistanceFields) { |
| 1764 | SkRect bounds = run.fVertexBounds; |
| 1765 | fBatch.fViewMatrix.mapRect(&bounds); |
| 1766 | this->setBounds(bounds); |
| 1767 | } else { |
| 1768 | this->setBounds(run.fVertexBounds); |
| 1769 | } |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1770 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1771 | |
| 1772 | private: |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1773 | BitmapTextBatch(GrMaskFormat maskFormat, int glyphCount, GrBatchFontCache* fontCache) |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1774 | : fMaskFormat(maskFormat) |
| 1775 | , fPixelConfig(fontCache->getPixelConfig(maskFormat)) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1776 | , fFontCache(fontCache) |
| 1777 | , fUseDistanceFields(false) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1778 | this->initClassID<BitmapTextBatch>(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1779 | fBatch.fNumGlyphs = glyphCount; |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1780 | fInstanceCount = 1; |
| 1781 | fAllocatedCount = kMinAllocated; |
| 1782 | } |
| 1783 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1784 | BitmapTextBatch(GrMaskFormat maskFormat, int glyphCount, GrBatchFontCache* fontCache, |
| 1785 | DistanceAdjustTable* distanceAdjustTable, SkColor filteredColor, |
| 1786 | bool useLCDText, bool useBGR, float gamma) |
| 1787 | : fMaskFormat(maskFormat) |
| 1788 | , fPixelConfig(fontCache->getPixelConfig(maskFormat)) |
| 1789 | , fFontCache(fontCache) |
| 1790 | , fDistanceAdjustTable(SkRef(distanceAdjustTable)) |
| 1791 | , fFilteredColor(filteredColor) |
| 1792 | , fUseDistanceFields(true) |
| 1793 | , fUseLCDText(useLCDText) |
| 1794 | , fUseBGR(useBGR) |
| 1795 | , fGamma(gamma) { |
| 1796 | this->initClassID<BitmapTextBatch>(); |
| 1797 | fBatch.fNumGlyphs = glyphCount; |
| 1798 | fInstanceCount = 1; |
| 1799 | fAllocatedCount = kMinAllocated; |
| 1800 | SkASSERT(fMaskFormat == kA8_GrMaskFormat); |
| 1801 | } |
| 1802 | |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1803 | ~BitmapTextBatch() { |
| 1804 | for (int i = 0; i < fInstanceCount; i++) { |
| 1805 | fGeoData[i].fBlob->unref(); |
| 1806 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexStride) { |
| 1810 | int width = glyph->fBounds.width(); |
| 1811 | int height = glyph->fBounds.height(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1812 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1813 | int u0, v0, u1, v1; |
| 1814 | if (fUseDistanceFields) { |
| 1815 | u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset; |
| 1816 | v0 = glyph->fAtlasLocation.fY + SK_DistanceFieldInset; |
| 1817 | u1 = u0 + width - 2 * SK_DistanceFieldInset; |
| 1818 | v1 = v0 + height - 2 * SK_DistanceFieldInset; |
| 1819 | } else { |
| 1820 | u0 = glyph->fAtlasLocation.fX; |
| 1821 | v0 = glyph->fAtlasLocation.fY; |
| 1822 | u1 = u0 + width; |
| 1823 | v1 = v0 + height; |
| 1824 | } |
| 1825 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1826 | SkIPoint16* textureCoords; |
| 1827 | // V0 |
| 1828 | textureCoords = reinterpret_cast<SkIPoint16*>(vertex); |
| 1829 | textureCoords->set(u0, v0); |
| 1830 | vertex += vertexStride; |
| 1831 | |
| 1832 | // V1 |
| 1833 | textureCoords = reinterpret_cast<SkIPoint16*>(vertex); |
| 1834 | textureCoords->set(u0, v1); |
| 1835 | vertex += vertexStride; |
| 1836 | |
| 1837 | // V2 |
| 1838 | textureCoords = reinterpret_cast<SkIPoint16*>(vertex); |
| 1839 | textureCoords->set(u1, v1); |
| 1840 | vertex += vertexStride; |
| 1841 | |
| 1842 | // V3 |
| 1843 | textureCoords = reinterpret_cast<SkIPoint16*>(vertex); |
| 1844 | textureCoords->set(u1, v0); |
| 1845 | } |
| 1846 | |
| 1847 | void regenerateColors(intptr_t vertex, size_t vertexStride, GrColor color) { |
| 1848 | for (int i = 0; i < kVerticesPerGlyph; i++) { |
| 1849 | SkColor* vcolor = reinterpret_cast<SkColor*>(vertex); |
| 1850 | *vcolor = color; |
| 1851 | vertex += vertexStride; |
| 1852 | } |
| 1853 | } |
| 1854 | |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 1855 | void regeneratePositions(intptr_t vertex, size_t vertexStride, SkScalar transX, |
| 1856 | SkScalar transY) { |
| 1857 | for (int i = 0; i < kVerticesPerGlyph; i++) { |
| 1858 | SkPoint* point = reinterpret_cast<SkPoint*>(vertex); |
| 1859 | point->fX += transX; |
| 1860 | point->fY += transY; |
| 1861 | vertex += vertexStride; |
| 1862 | } |
| 1863 | } |
| 1864 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1865 | void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) { |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1866 | GrVertices vertices; |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1867 | int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads(); |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1868 | vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1869 | flushInfo->fIndexBuffer, flushInfo->fVertexOffset, |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1870 | kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsToFlush, |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1871 | maxGlyphsPerDraw); |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1872 | batchTarget->draw(vertices); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1873 | flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
| 1874 | flushInfo->fGlyphsToFlush = 0; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | GrColor color() const { return fBatch.fColor; } |
| 1878 | const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 1879 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 1880 | int numGlyphs() const { return fBatch.fNumGlyphs; } |
| 1881 | |
| 1882 | bool onCombineIfPossible(GrBatch* t) override { |
| 1883 | BitmapTextBatch* that = t->cast<BitmapTextBatch>(); |
| 1884 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1885 | if (fUseDistanceFields != that->fUseDistanceFields) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1886 | return false; |
| 1887 | } |
| 1888 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1889 | if (!fUseDistanceFields) { |
| 1890 | // Bitmap Text |
| 1891 | if (fMaskFormat != that->fMaskFormat) { |
| 1892 | return false; |
| 1893 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1894 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1895 | // TODO we can often batch across LCD text if we have dual source blending and don't |
| 1896 | // have to use the blend constant |
| 1897 | if (fMaskFormat != kA8_GrMaskFormat && this->color() != that->color()) { |
| 1898 | return false; |
| 1899 | } |
| 1900 | |
| 1901 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 1902 | return false; |
| 1903 | } |
| 1904 | } else { |
| 1905 | // Distance Fields |
| 1906 | SkASSERT(this->fMaskFormat == that->fMaskFormat && |
| 1907 | this->fMaskFormat == kA8_GrMaskFormat); |
| 1908 | |
| 1909 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 1910 | return false; |
| 1911 | } |
| 1912 | |
| 1913 | if (fFilteredColor != that->fFilteredColor) { |
| 1914 | return false; |
| 1915 | } |
| 1916 | |
| 1917 | if (fUseLCDText != that->fUseLCDText) { |
| 1918 | return false; |
| 1919 | } |
| 1920 | |
| 1921 | if (fUseBGR != that->fUseBGR) { |
| 1922 | return false; |
| 1923 | } |
| 1924 | |
| 1925 | if (fGamma != that->fGamma) { |
| 1926 | return false; |
| 1927 | } |
| 1928 | |
| 1929 | // TODO see note above |
| 1930 | if (fUseLCDText && this->color() != that->color()) { |
| 1931 | return false; |
| 1932 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | fBatch.fNumGlyphs += that->numGlyphs(); |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 1936 | |
| 1937 | // copy that->geoData(). We do this manually for performance reasons |
| 1938 | SkAutoSTMalloc<kMinAllocated, Geometry>* otherGeoData = that->geoData(); |
| 1939 | int otherInstanceCount = that->instanceCount(); |
| 1940 | int allocSize = otherInstanceCount + fInstanceCount; |
| 1941 | if (allocSize > fAllocatedCount) { |
| 1942 | while (allocSize > fAllocatedCount) { |
| 1943 | fAllocatedCount = fAllocatedCount << 1; |
| 1944 | } |
| 1945 | fGeoData.realloc(fAllocatedCount); |
| 1946 | } |
| 1947 | |
| 1948 | memcpy(&fGeoData[fInstanceCount], otherGeoData->get(), |
| 1949 | otherInstanceCount * sizeof(Geometry)); |
| 1950 | int total = fInstanceCount + otherInstanceCount; |
| 1951 | for (int i = fInstanceCount; i < total; i++) { |
| 1952 | fGeoData[i].fBlob->ref(); |
| 1953 | } |
| 1954 | fInstanceCount = total; |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1955 | |
| 1956 | this->joinBounds(that->bounds()); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1957 | return true; |
| 1958 | } |
| 1959 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1960 | // TODO just use class params |
| 1961 | // TODO trying to figure out why lcd is so whack |
| 1962 | GrGeometryProcessor* setupDfProcessor(const SkMatrix& viewMatrix, SkColor filteredColor, |
| 1963 | GrColor color, GrTexture* texture) { |
| 1964 | GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode); |
| 1965 | |
| 1966 | // set up any flags |
| 1967 | uint32_t flags = 0; |
| 1968 | flags |= viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 1969 | flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
| 1970 | flags |= fUseLCDText && viewMatrix.rectStaysRect() ? |
| 1971 | kRectToRect_DistanceFieldEffectFlag : 0; |
| 1972 | flags |= fUseLCDText && fUseBGR ? kBGR_DistanceFieldEffectFlag : 0; |
| 1973 | |
| 1974 | // see if we need to create a new effect |
| 1975 | if (fUseLCDText) { |
| 1976 | GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); |
| 1977 | |
| 1978 | float redCorrection = |
| 1979 | (*fDistanceAdjustTable)[GrColorUnpackR(colorNoPreMul) >> kDistanceAdjustLumShift]; |
| 1980 | float greenCorrection = |
| 1981 | (*fDistanceAdjustTable)[GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift]; |
| 1982 | float blueCorrection = |
| 1983 | (*fDistanceAdjustTable)[GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift]; |
| 1984 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = |
| 1985 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(redCorrection, |
| 1986 | greenCorrection, |
| 1987 | blueCorrection); |
| 1988 | |
| 1989 | return GrDistanceFieldLCDTextGeoProc::Create(color, |
| 1990 | viewMatrix, |
| 1991 | texture, |
| 1992 | params, |
| 1993 | widthAdjust, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 1994 | flags, |
| 1995 | this->usesLocalCoords()); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1996 | } else { |
| 1997 | flags |= kColorAttr_DistanceFieldEffectFlag; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 1998 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 1999 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(fGamma, filteredColor); |
| 2000 | float correction = (*fDistanceAdjustTable)[lum >> kDistanceAdjustLumShift]; |
| 2001 | return GrDistanceFieldA8TextGeoProc::Create(color, |
| 2002 | viewMatrix, |
| 2003 | texture, |
| 2004 | params, |
| 2005 | correction, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 2006 | flags, |
| 2007 | this->usesLocalCoords()); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 2008 | #else |
| 2009 | return GrDistanceFieldA8TextGeoProc::Create(color, |
| 2010 | viewMatrix, |
| 2011 | texture, |
| 2012 | params, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 2013 | flags, |
| 2014 | this->usesLocalCoords()); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 2015 | #endif |
| 2016 | } |
| 2017 | |
| 2018 | } |
| 2019 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2020 | struct BatchTracker { |
| 2021 | GrColor fColor; |
| 2022 | SkMatrix fViewMatrix; |
| 2023 | bool fUsesLocalCoords; |
| 2024 | bool fColorIgnored; |
| 2025 | bool fCoverageIgnored; |
| 2026 | int fNumGlyphs; |
| 2027 | }; |
| 2028 | |
| 2029 | BatchTracker fBatch; |
joshualitt | ad802c6 | 2015-04-15 05:31:57 -0700 | [diff] [blame] | 2030 | SkAutoSTMalloc<kMinAllocated, Geometry> fGeoData; |
| 2031 | int fInstanceCount; |
| 2032 | int fAllocatedCount; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2033 | GrMaskFormat fMaskFormat; |
| 2034 | GrPixelConfig fPixelConfig; |
| 2035 | GrBatchFontCache* fFontCache; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 2036 | |
| 2037 | // Distance field properties |
| 2038 | SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; |
| 2039 | SkColor fFilteredColor; |
| 2040 | bool fUseDistanceFields; |
| 2041 | bool fUseLCDText; |
| 2042 | bool fUseBGR; |
| 2043 | float fGamma; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2044 | }; |
| 2045 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 2046 | void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* drawContext, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2047 | GrRenderTarget* rt, const SkTextBlob::RunIterator& it, |
| 2048 | const GrClip& clip, const SkPaint& skPaint, |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2049 | SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, |
| 2050 | const SkIRect& clipBounds, SkScalar x, SkScalar y) { |
| 2051 | SkPaint runPaint = skPaint; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2052 | |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2053 | size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 2054 | const SkPoint& offset = it.offset(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2055 | |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2056 | it.applyFontToPaint(&runPaint); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2057 | |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2058 | if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) { |
| 2059 | return; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 2062 | runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint)); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2063 | |
| 2064 | switch (it.positioning()) { |
| 2065 | case SkTextBlob::kDefault_Positioning: |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2066 | this->drawTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, |
| 2067 | (const char *)it.glyphs(), |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2068 | textLen, x + offset.x(), y + offset.y(), clipBounds); |
| 2069 | break; |
| 2070 | case SkTextBlob::kHorizontal_Positioning: |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2071 | this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, |
| 2072 | (const char*)it.glyphs(), |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2073 | textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), |
| 2074 | clipBounds); |
| 2075 | break; |
| 2076 | case SkTextBlob::kFull_Positioning: |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2077 | this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, |
| 2078 | (const char*)it.glyphs(), |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2079 | textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds); |
| 2080 | break; |
| 2081 | } |
| 2082 | } |
| 2083 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2084 | |
| 2085 | inline BitmapTextBatch* |
| 2086 | GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo& info, |
| 2087 | int glyphCount, int run, int subRun, |
| 2088 | GrColor color, SkScalar transX, SkScalar transY, |
| 2089 | const SkPaint& skPaint) { |
| 2090 | GrMaskFormat format = info.fMaskFormat; |
| 2091 | GrColor subRunColor; |
| 2092 | if (kARGB_GrMaskFormat == format) { |
| 2093 | uint8_t paintAlpha = skPaint.getAlpha(); |
| 2094 | subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha); |
| 2095 | } else { |
| 2096 | subRunColor = color; |
| 2097 | } |
| 2098 | |
| 2099 | BitmapTextBatch* batch; |
| 2100 | if (info.fDrawAsDistanceFields) { |
| 2101 | SkColor filteredColor; |
| 2102 | SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 2103 | if (colorFilter) { |
| 2104 | filteredColor = colorFilter->filterColor(skPaint.getColor()); |
| 2105 | } else { |
| 2106 | filteredColor = skPaint.getColor(); |
| 2107 | } |
| 2108 | bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); |
| 2109 | float gamma = fDeviceProperties.gamma(); |
| 2110 | batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFontCache(), |
| 2111 | fDistanceAdjustTable, filteredColor, |
| 2112 | info.fUseLCDText, useBGR, |
| 2113 | gamma); |
| 2114 | } else { |
| 2115 | batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFontCache()); |
| 2116 | } |
| 2117 | BitmapTextBatch::Geometry& geometry = batch->geometry(); |
| 2118 | geometry.fBlob = SkRef(cacheBlob); |
| 2119 | geometry.fRun = run; |
| 2120 | geometry.fSubRun = subRun; |
| 2121 | geometry.fColor = subRunColor; |
| 2122 | geometry.fTransX = transX; |
| 2123 | geometry.fTransY = transY; |
| 2124 | batch->init(); |
| 2125 | |
| 2126 | return batch; |
| 2127 | } |
| 2128 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2129 | inline void GrAtlasTextContext::flushRun(GrDrawContext* drawContext, |
| 2130 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2131 | BitmapTextBlob* cacheBlob, int run, GrColor color, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2132 | SkScalar transX, SkScalar transY, |
| 2133 | const SkPaint& skPaint) { |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2134 | for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); subRun++) { |
| 2135 | const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; |
| 2136 | int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
| 2137 | if (0 == glyphCount) { |
| 2138 | continue; |
| 2139 | } |
| 2140 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2141 | SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, glyphCount, run, |
| 2142 | subRun, color, transX, transY, |
| 2143 | skPaint)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2144 | drawContext->drawText(pipelineBuilder, batch); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2148 | inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, |
| 2149 | GrDrawContext* drawContext, GrRenderTarget* rt, |
| 2150 | const GrClip& clip, const SkPaint& skPaint, |
joshualitt | 1107e90 | 2015-05-11 14:52:11 -0700 | [diff] [blame] | 2151 | SkScalar transX, SkScalar transY, |
| 2152 | const SkIRect& clipBounds) { |
joshualitt | fc07256 | 2015-05-13 12:15:06 -0700 | [diff] [blame] | 2153 | if (!cacheBlob->fBigGlyphs.count()) { |
| 2154 | return; |
| 2155 | } |
| 2156 | |
| 2157 | SkMatrix pathMatrix; |
| 2158 | if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) { |
| 2159 | SkDebugf("could not invert viewmatrix\n"); |
| 2160 | return; |
| 2161 | } |
| 2162 | |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2163 | for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 2164 | BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
joshualitt | 19e4c02 | 2015-05-13 11:23:03 -0700 | [diff] [blame] | 2165 | bigGlyph.fVx += transX; |
| 2166 | bigGlyph.fVy += transY; |
joshualitt | fc07256 | 2015-05-13 12:15:06 -0700 | [diff] [blame] | 2167 | SkMatrix translate = cacheBlob->fViewMatrix; |
| 2168 | translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy); |
| 2169 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2170 | GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, bigGlyph.fPath, |
| 2171 | skPaint, translate, &pathMatrix, clipBounds, false); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 2172 | } |
| 2173 | } |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2174 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 2175 | void GrAtlasTextContext::flush(GrDrawContext* drawContext, |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2176 | const SkTextBlob* blob, |
| 2177 | BitmapTextBlob* cacheBlob, |
| 2178 | GrRenderTarget* rt, |
| 2179 | const SkPaint& skPaint, |
| 2180 | const GrPaint& grPaint, |
| 2181 | SkDrawFilter* drawFilter, |
| 2182 | const GrClip& clip, |
| 2183 | const SkMatrix& viewMatrix, |
| 2184 | const SkIRect& clipBounds, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 2185 | SkScalar x, SkScalar y, |
| 2186 | SkScalar transX, SkScalar transY) { |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2187 | // We loop through the runs of the blob, flushing each. If any run is too large, then we flush |
| 2188 | // it as paths |
| 2189 | GrPipelineBuilder pipelineBuilder; |
| 2190 | pipelineBuilder.setFromPaint(grPaint, rt, clip); |
| 2191 | |
| 2192 | GrColor color = grPaint.getColor(); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2193 | |
| 2194 | SkTextBlob::RunIterator it(blob); |
| 2195 | for (int run = 0; !it.done(); it.next(), run++) { |
| 2196 | if (cacheBlob->fRuns[run].fDrawAsPaths) { |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 2197 | this->flushRunAsPaths(drawContext, rt, it, clip, skPaint, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2198 | drawFilter, viewMatrix, clipBounds, x, y); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2199 | continue; |
| 2200 | } |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 2201 | cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2202 | this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, |
| 2203 | transX, transY, skPaint); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | // Now flush big glyphs |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2207 | this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, transX, transY, clipBounds); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2210 | void GrAtlasTextContext::flush(GrDrawContext* drawContext, |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2211 | BitmapTextBlob* cacheBlob, |
| 2212 | GrRenderTarget* rt, |
| 2213 | const SkPaint& skPaint, |
| 2214 | const GrPaint& grPaint, |
joshualitt | 1107e90 | 2015-05-11 14:52:11 -0700 | [diff] [blame] | 2215 | const GrClip& clip, |
| 2216 | const SkIRect& clipBounds) { |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2217 | GrPipelineBuilder pipelineBuilder; |
| 2218 | pipelineBuilder.setFromPaint(grPaint, rt, clip); |
| 2219 | |
| 2220 | GrColor color = grPaint.getColor(); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2221 | for (int run = 0; run < cacheBlob->fRunCount; run++) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 2222 | this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | // Now flush big glyphs |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2226 | this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, 0, 0, clipBounds); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 2227 | } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2228 | |
| 2229 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2230 | |
| 2231 | #ifdef GR_TEST_UTILS |
| 2232 | |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 2233 | BATCH_TEST_DEFINE(TextBlobBatch) { |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2234 | static uint32_t gContextID = SK_InvalidGenID; |
| 2235 | static GrAtlasTextContext* gTextContext = NULL; |
| 2236 | static SkDeviceProperties gDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType); |
| 2237 | |
| 2238 | if (context->uniqueID() != gContextID) { |
| 2239 | gContextID = context->uniqueID(); |
| 2240 | SkDELETE(gTextContext); |
| 2241 | // We don't yet test the fall back to paths in the GrTextContext base class. This is mostly |
| 2242 | // because we don't really want to have a gpu device here. |
| 2243 | // We enable distance fields by twiddling a knob on the paint |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 2244 | gTextContext = GrAtlasTextContext::Create(context, gDeviceProperties, false); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | // create dummy render target |
| 2248 | GrSurfaceDesc desc; |
| 2249 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 2250 | desc.fWidth = 1024; |
| 2251 | desc.fHeight = 1024; |
| 2252 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
joshualitt | 1573206 | 2015-05-13 12:15:14 -0700 | [diff] [blame] | 2253 | desc.fSampleCnt = 0; |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2254 | SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, true, NULL, 0)); |
| 2255 | SkASSERT(texture); |
| 2256 | SkASSERT(NULL != texture->asRenderTarget()); |
| 2257 | GrRenderTarget* rt = texture->asRenderTarget(); |
| 2258 | |
| 2259 | // Setup dummy SkPaint / GrPaint |
| 2260 | GrColor color = GrRandomColor(random); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 2261 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 2262 | SkPaint skPaint; |
| 2263 | skPaint.setDistanceFieldTextTEMP(random->nextBool()); |
| 2264 | skPaint.setColor(color); |
| 2265 | skPaint.setLCDRenderText(random->nextBool()); |
| 2266 | skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool()); |
| 2267 | skPaint.setSubpixelText(random->nextBool()); |
| 2268 | |
| 2269 | GrPaint grPaint; |
| 2270 | if (!SkPaint2GrPaint(context, rt, skPaint, viewMatrix, true, &grPaint)) { |
| 2271 | SkFAIL("couldn't convert paint\n"); |
| 2272 | } |
| 2273 | |
| 2274 | const char* text = "The quick brown fox jumps over the lazy dog."; |
| 2275 | int textLen = (int)strlen(text); |
| 2276 | |
| 2277 | // Setup clip |
| 2278 | GrClip clip; |
| 2279 | SkIRect noClip = SkIRect::MakeLargest(); |
| 2280 | |
| 2281 | // right now we don't handle textblobs, nor do we handle drawPosText. Since we only |
| 2282 | // intend to test the batch with this unit test, that is okay. |
| 2283 | SkAutoTUnref<GrAtlasTextContext::BitmapTextBlob> blob( |
| 2284 | gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMatrix, text, |
| 2285 | static_cast<size_t>(textLen), 0, 0, noClip)); |
| 2286 | |
| 2287 | SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 2288 | SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 2289 | const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]; |
| 2290 | return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, transY, skPaint); |
| 2291 | } |
| 2292 | |
| 2293 | #endif |