blob: c158ec1f2c0e80c945dca4e0b514ce9050289433 [file] [log] [blame]
joshualitt1d89e8d2015-04-01 12:40:54 -07001/*
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
robertphillipsccb1b572015-05-27 11:02:55 -07009#include "GrBlurUtils.h"
robertphillipsea461502015-05-26 11:38:03 -070010#include "GrDrawContext.h"
robertphillips2334fb62015-06-17 05:43:33 -070011#include "GrDrawTarget.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070012#include "GrFontScaler.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070013#include "GrStrokeInfo.h"
joshualittb7133be2015-04-08 09:08:31 -070014#include "GrTextBlobCache.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070015#include "GrTexturePriv.h"
bsalomon72e3ae42015-04-28 08:08:46 -070016#include "GrVertexBuffer.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070017
18#include "SkAutoKern.h"
19#include "SkColorPriv.h"
joshualitt9bd2daf2015-04-17 09:30:06 -070020#include "SkColorFilter.h"
21#include "SkDistanceFieldGen.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070022#include "SkDraw.h"
23#include "SkDrawFilter.h"
24#include "SkDrawProcs.h"
herb9be5ff62015-11-11 11:30:11 -080025#include "SkFindAndPlaceGlyph.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070026#include "SkGlyphCache.h"
27#include "SkGpuDevice.h"
bsalomonf1b7a1d2015-09-28 06:26:28 -070028#include "SkGrPriv.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070029#include "SkPath.h"
30#include "SkRTConf.h"
31#include "SkStrokeRec.h"
32#include "SkTextBlob.h"
33#include "SkTextMapStateProc.h"
34
joshualitta751c972015-11-20 13:37:32 -080035#include "batches/GrAtlasTextBatch.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070036
37namespace {
joshualitt9bd2daf2015-04-17 09:30:06 -070038static const int kMinDFFontSize = 18;
39static const int kSmallDFFontSize = 32;
40static const int kSmallDFFontLimit = 32;
41static const int kMediumDFFontSize = 72;
42static const int kMediumDFFontLimit = 72;
43static const int kLargeDFFontSize = 162;
jvanverth97c595f2015-06-19 11:06:28 -070044#ifdef SK_BUILD_FOR_ANDROID
45static const int kLargeDFFontLimit = 384;
46#else
joshualitta7c63892015-04-21 13:24:37 -070047static const int kLargeDFFontLimit = 2 * kLargeDFFontSize;
jvanverth97c595f2015-06-19 11:06:28 -070048#endif
joshualitt9bd2daf2015-04-17 09:30:06 -070049
50SkDEBUGCODE(static const int kExpectedDistanceAdjustTableSize = 8;)
joshualitt1d89e8d2015-04-01 12:40:54 -070051};
52
robertphillipsf6703fa2015-09-01 05:36:47 -070053GrAtlasTextContext::GrAtlasTextContext(GrContext* context, const SkSurfaceProps& surfaceProps)
54 : INHERITED(context, surfaceProps)
55 , fDistanceAdjustTable(new DistanceAdjustTable) {
joshualittb7133be2015-04-08 09:08:31 -070056 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
57 // vertexStride
joshualitta751c972015-11-20 13:37:32 -080058 static_assert(GrAtlasTextBatch::kGrayTextVASize >= GrAtlasTextBatch::kColorTextVASize &&
59 GrAtlasTextBatch::kGrayTextVASize >= GrAtlasTextBatch::kLCDTextVASize,
bungeman99fe8222015-08-20 07:57:51 -070060 "vertex_attribute_changed");
halcanary96fcdcc2015-08-27 07:41:13 -070061 fCurrStrike = nullptr;
joshualittb7133be2015-04-08 09:08:31 -070062 fCache = context->getTextBlobCache();
joshualitt9bd2daf2015-04-17 09:30:06 -070063}
64
robertphillips9fc82752015-06-19 04:46:45 -070065void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable() {
joshualitt9bd2daf2015-04-17 09:30:06 -070066
67 // This is used for an approximation of the mask gamma hack, used by raster and bitmap
68 // text. The mask gamma hack is based off of guessing what the blend color is going to
69 // be, and adjusting the mask so that when run through the linear blend will
70 // produce the value closest to the desired result. However, in practice this means
71 // that the 'adjusted' mask is just increasing or decreasing the coverage of
72 // the mask depending on what it is thought it will blit against. For black (on
73 // assumed white) this means that coverages are decreased (on a curve). For white (on
74 // assumed black) this means that coverages are increased (on a a curve). At
75 // middle (perceptual) gray (which could be blit against anything) the coverages
76 // remain the same.
77 //
78 // The idea here is that instead of determining the initial (real) coverage and
79 // then adjusting that coverage, we determine an adjusted coverage directly by
80 // essentially manipulating the geometry (in this case, the distance to the glyph
81 // edge). So for black (on assumed white) this thins a bit; for white (on
82 // assumed black) this fake bolds the geometry a bit.
83 //
84 // The distance adjustment is calculated by determining the actual coverage value which
85 // when fed into in the mask gamma table gives us an 'adjusted coverage' value of 0.5. This
86 // actual coverage value (assuming it's between 0 and 1) corresponds to a distance from the
87 // actual edge. So by subtracting this distance adjustment and computing without the
88 // the coverage adjustment we should get 0.5 coverage at the same point.
89 //
90 // This has several implications:
91 // For non-gray lcd smoothed text, each subpixel essentially is using a
92 // slightly different geometry.
93 //
94 // For black (on assumed white) this may not cover some pixels which were
95 // previously covered; however those pixels would have been only slightly
96 // covered and that slight coverage would have been decreased anyway. Also, some pixels
97 // which were previously fully covered may no longer be fully covered.
98 //
99 // For white (on assumed black) this may cover some pixels which weren't
100 // previously covered at all.
101
102 int width, height;
103 size_t size;
104
105#ifdef SK_GAMMA_CONTRAST
106 SkScalar contrast = SK_GAMMA_CONTRAST;
107#else
108 SkScalar contrast = 0.5f;
109#endif
robertphillips9fc82752015-06-19 04:46:45 -0700110 SkScalar paintGamma = SK_GAMMA_EXPONENT;
111 SkScalar deviceGamma = SK_GAMMA_EXPONENT;
joshualitt9bd2daf2015-04-17 09:30:06 -0700112
113 size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma,
114 &width, &height);
115
116 SkASSERT(kExpectedDistanceAdjustTableSize == height);
halcanary385fe4d2015-08-26 13:07:48 -0700117 fTable = new SkScalar[height];
joshualitt9bd2daf2015-04-17 09:30:06 -0700118
119 SkAutoTArray<uint8_t> data((int)size);
120 SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get());
121
122 // find the inverse points where we cross 0.5
123 // binsearch might be better, but we only need to do this once on creation
124 for (int row = 0; row < height; ++row) {
125 uint8_t* rowPtr = data.get() + row*width;
126 for (int col = 0; col < width - 1; ++col) {
127 if (rowPtr[col] <= 127 && rowPtr[col + 1] >= 128) {
128 // compute point where a mask value will give us a result of 0.5
129 float interp = (127.5f - rowPtr[col]) / (rowPtr[col + 1] - rowPtr[col]);
130 float borderAlpha = (col + interp) / 255.f;
131
132 // compute t value for that alpha
133 // this is an approximate inverse for smoothstep()
134 float t = borderAlpha*(borderAlpha*(4.0f*borderAlpha - 6.0f) + 5.0f) / 3.0f;
135
136 // compute distance which gives us that t value
137 const float kDistanceFieldAAFactor = 0.65f; // should match SK_DistanceFieldAAFactor
138 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor;
139
140 fTable[row] = d;
141 break;
142 }
143 }
144 }
joshualitt1d89e8d2015-04-01 12:40:54 -0700145}
146
joshualittdbd35932015-04-02 09:19:04 -0700147GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context,
robertphillipsfcf78292015-06-19 11:49:52 -0700148 const SkSurfaceProps& surfaceProps) {
robertphillipsf6703fa2015-09-01 05:36:47 -0700149 return new GrAtlasTextContext(context, surfaceProps);
joshualitt1d89e8d2015-04-01 12:40:54 -0700150}
151
joshualittdbd35932015-04-02 09:19:04 -0700152bool GrAtlasTextContext::canDraw(const GrRenderTarget*,
153 const GrClip&,
154 const GrPaint&,
155 const SkPaint& skPaint,
156 const SkMatrix& viewMatrix) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700157 return this->canDrawAsDistanceFields(skPaint, viewMatrix) ||
158 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix);
joshualitt1d89e8d2015-04-01 12:40:54 -0700159}
160
joshualitt9e36c1a2015-04-14 12:17:27 -0700161GrColor GrAtlasTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd) {
162 GrColor canonicalColor = paint.computeLuminanceColor();
163 if (lcd) {
164 // This is the correct computation, but there are tons of cases where LCD can be overridden.
165 // For now we just regenerate if any run in a textblob has LCD.
166 // TODO figure out where all of these overrides are and see if we can incorporate that logic
167 // at a higher level *OR* use sRGB
168 SkASSERT(false);
169 //canonicalColor = SkMaskGamma::CanonicalColor(canonicalColor);
170 } else {
171 // A8, though can have mixed BMP text but it shouldn't matter because BMP text won't have
172 // gamma corrected masks anyways, nor color
173 U8CPU lum = SkComputeLuminance(SkColorGetR(canonicalColor),
174 SkColorGetG(canonicalColor),
175 SkColorGetB(canonicalColor));
176 // reduce to our finite number of bits
177 canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum));
178 }
179 return canonicalColor;
180}
181
182// TODO if this function ever shows up in profiling, then we can compute this value when the
183// textblob is being built and cache it. However, for the time being textblobs mostly only have 1
184// run so this is not a big deal to compute here.
185bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) {
halcanary33779752015-10-27 14:01:05 -0700186 SkTextBlobRunIterator it(blob);
joshualitt9e36c1a2015-04-14 12:17:27 -0700187 for (; !it.done(); it.next()) {
188 if (it.isLCD()) {
189 return true;
190 }
191 }
192 return false;
193}
194
joshualitt2a0e9f32015-04-13 06:12:21 -0700195bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY,
joshualitt374b2f72015-07-21 08:05:03 -0700196 const GrAtlasTextBlob& blob, const SkPaint& paint,
jvanverth0628a522015-08-18 07:44:22 -0700197 GrColor color, const SkMaskFilter::BlurRec& blurRec,
joshualittdbd35932015-04-02 09:19:04 -0700198 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
joshualitt9e36c1a2015-04-14 12:17:27 -0700199 // If we have LCD text then our canonical color will be set to transparent, in this case we have
200 // to regenerate the blob on any color change
jvanverth0628a522015-08-18 07:44:22 -0700201 // We use the grPaint to get any color filter effects
202 if (blob.fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
203 blob.fPaintColor != color) {
joshualitt2a0e9f32015-04-13 06:12:21 -0700204 return true;
205 }
206
207 if (blob.fViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
208 return true;
209 }
210
211 if (blob.fViewMatrix.hasPerspective() && !blob.fViewMatrix.cheapEqualTo(viewMatrix)) {
212 return true;
213 }
214
joshualitt53b5f442015-04-13 06:33:59 -0700215 // We only cache one masked version
216 if (blob.fKey.fHasBlur &&
217 (blob.fBlurRec.fSigma != blurRec.fSigma ||
218 blob.fBlurRec.fStyle != blurRec.fStyle ||
219 blob.fBlurRec.fQuality != blurRec.fQuality)) {
220 return true;
221 }
222
223 // Similarly, we only cache one version for each style
224 if (blob.fKey.fStyle != SkPaint::kFill_Style &&
225 (blob.fStrokeInfo.fFrameWidth != paint.getStrokeWidth() ||
226 blob.fStrokeInfo.fMiterLimit != paint.getStrokeMiter() ||
227 blob.fStrokeInfo.fJoin != paint.getStrokeJoin())) {
228 return true;
229 }
230
joshualittfcfb9fc2015-04-21 07:35:10 -0700231 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
232 // for mixed blobs if this becomes an issue.
233 if (blob.hasBitmap() && blob.hasDistanceField()) {
joshualitt473ffa12015-04-22 18:23:15 -0700234 // Identical viewmatrices and we can reuse in all cases
235 if (blob.fViewMatrix.cheapEqualTo(viewMatrix) && x == blob.fX && y == blob.fY) {
236 return false;
237 }
joshualitt2a0e9f32015-04-13 06:12:21 -0700238 return true;
239 }
240
joshualittfcfb9fc2015-04-21 07:35:10 -0700241 if (blob.hasBitmap()) {
joshualitt64c99cc2015-04-21 09:43:03 -0700242 if (blob.fViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
243 blob.fViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
244 blob.fViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
245 blob.fViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
246 return true;
247 }
248
joshualittfcfb9fc2015-04-21 07:35:10 -0700249 // We can update the positions in the cachedtextblobs without regenerating the whole blob,
250 // but only for integer translations.
251 // This cool bit of math will determine the necessary translation to apply to the already
252 // generated vertex coordinates to move them to the correct position
253 SkScalar transX = viewMatrix.getTranslateX() +
254 viewMatrix.getScaleX() * (x - blob.fX) +
255 viewMatrix.getSkewX() * (y - blob.fY) -
256 blob.fViewMatrix.getTranslateX();
257 SkScalar transY = viewMatrix.getTranslateY() +
258 viewMatrix.getSkewY() * (x - blob.fX) +
259 viewMatrix.getScaleY() * (y - blob.fY) -
260 blob.fViewMatrix.getTranslateY();
joshualittf0c000d2015-04-27 09:36:55 -0700261 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY) ) {
joshualittfcfb9fc2015-04-21 07:35:10 -0700262 return true;
263 }
264
joshualittfcfb9fc2015-04-21 07:35:10 -0700265 (*outTransX) = transX;
266 (*outTransY) = transY;
joshualitta7c63892015-04-21 13:24:37 -0700267 } else if (blob.hasDistanceField()) {
joshualitt64c99cc2015-04-21 09:43:03 -0700268 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
269 // distance field being generated, so we have to regenerate in those cases
270 SkScalar newMaxScale = viewMatrix.getMaxScale();
271 SkScalar oldMaxScale = blob.fViewMatrix.getMaxScale();
272 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
273 if (scaleAdjust < blob.fMaxMinScale || scaleAdjust > blob.fMinMaxScale) {
274 return true;
275 }
276
277 (*outTransX) = x - blob.fX;
278 (*outTransY) = y - blob.fY;
joshualittfcfb9fc2015-04-21 07:35:10 -0700279 }
joshualitt374b2f72015-07-21 08:05:03 -0700280
joshualitta7c63892015-04-21 13:24:37 -0700281 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
282 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
283 // the blob anyways at flush time, so no need to regenerate explicitly
joshualitt2a0e9f32015-04-13 06:12:21 -0700284 return false;
joshualitt1d89e8d2015-04-01 12:40:54 -0700285}
286
287
joshualitt374b2f72015-07-21 08:05:03 -0700288inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run,
joshualittdbd35932015-04-02 09:19:04 -0700289 const SkPaint& skPaint,
joshualitt9bd2daf2015-04-17 09:30:06 -0700290 const SkMatrix* viewMatrix,
291 bool noGamma) {
robertphillipsfcf78292015-06-19 11:49:52 -0700292 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMatrix, noGamma);
joshualitt1d89e8d2015-04-01 12:40:54 -0700293 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
294 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc());
295}
296
robertphillipsf6703fa2015-09-01 05:36:47 -0700297void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc, GrRenderTarget* rt,
robertphillipsccb1b572015-05-27 11:02:55 -0700298 const GrClip& clip, const SkPaint& skPaint,
299 const SkMatrix& viewMatrix, const SkTextBlob* blob,
300 SkScalar x, SkScalar y,
joshualittdbd35932015-04-02 09:19:04 -0700301 SkDrawFilter* drawFilter, const SkIRect& clipBounds) {
joshualitt9b8e79e2015-04-24 09:57:12 -0700302 // If we have been abandoned, then don't draw
robertphillipsea461502015-05-26 11:38:03 -0700303 if (fContext->abandoned()) {
304 return;
305 }
306
joshualitt374b2f72015-07-21 08:05:03 -0700307 SkAutoTUnref<GrAtlasTextBlob> cacheBlob;
joshualitt53b5f442015-04-13 06:33:59 -0700308 SkMaskFilter::BlurRec blurRec;
joshualitt374b2f72015-07-21 08:05:03 -0700309 GrAtlasTextBlob::Key key;
joshualitt53b5f442015-04-13 06:33:59 -0700310 // It might be worth caching these things, but its not clear at this time
311 // TODO for animated mask filters, this will fill up our cache. We need a safeguard here
312 const SkMaskFilter* mf = skPaint.getMaskFilter();
joshualitt2a0e9f32015-04-13 06:12:21 -0700313 bool canCache = !(skPaint.getPathEffect() ||
joshualitt53b5f442015-04-13 06:33:59 -0700314 (mf && !mf->asABlur(&blurRec)) ||
joshualitt2a0e9f32015-04-13 06:12:21 -0700315 drawFilter);
316
317 if (canCache) {
joshualitt9e36c1a2015-04-14 12:17:27 -0700318 bool hasLCD = HasLCD(blob);
joshualitte4cee1f2015-05-11 13:04:28 -0700319
320 // We canonicalize all non-lcd draws to use kUnknown_SkPixelGeometry
robertphillipsfcf78292015-06-19 11:49:52 -0700321 SkPixelGeometry pixelGeometry = hasLCD ? fSurfaceProps.pixelGeometry() :
joshualitte4cee1f2015-05-11 13:04:28 -0700322 kUnknown_SkPixelGeometry;
323
joshualitt9e36c1a2015-04-14 12:17:27 -0700324 // TODO we want to figure out a way to be able to use the canonical color on LCD text,
325 // see the note on ComputeCanonicalColor above. We pick a dummy value for LCD text to
326 // ensure we always match the same key
327 GrColor canonicalColor = hasLCD ? SK_ColorTRANSPARENT :
328 ComputeCanonicalColor(skPaint, hasLCD);
329
joshualitte4cee1f2015-05-11 13:04:28 -0700330 key.fPixelGeometry = pixelGeometry;
joshualitt53b5f442015-04-13 06:33:59 -0700331 key.fUniqueID = blob->uniqueID();
332 key.fStyle = skPaint.getStyle();
333 key.fHasBlur = SkToBool(mf);
joshualitt9e36c1a2015-04-14 12:17:27 -0700334 key.fCanonicalColor = canonicalColor;
joshualitt53b5f442015-04-13 06:33:59 -0700335 cacheBlob.reset(SkSafeRef(fCache->find(key)));
joshualitt2a0e9f32015-04-13 06:12:21 -0700336 }
337
joshualitt1d89e8d2015-04-01 12:40:54 -0700338 SkIRect clipRect;
339 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect);
340
joshualitt2a0e9f32015-04-13 06:12:21 -0700341 SkScalar transX = 0.f;
342 SkScalar transY = 0.f;
343
joshualitt9e36c1a2015-04-14 12:17:27 -0700344 // Though for the time being runs in the textblob can override the paint, they only touch font
345 // info.
346 GrPaint grPaint;
bsalomonf1b7a1d2015-09-28 06:26:28 -0700347 if (!SkPaintToGrPaint(fContext, skPaint, viewMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700348 return;
349 }
joshualitt9e36c1a2015-04-14 12:17:27 -0700350
joshualittb7133be2015-04-08 09:08:31 -0700351 if (cacheBlob) {
jvanverth0628a522015-08-18 07:44:22 -0700352 if (MustRegenerateBlob(&transX, &transY, *cacheBlob, skPaint, grPaint.getColor(), blurRec,
353 viewMatrix, x, y)) {
joshualitt1d89e8d2015-04-01 12:40:54 -0700354 // We have to remake the blob because changes may invalidate our masks.
355 // TODO we could probably get away reuse most of the time if the pointer is unique,
356 // but we'd have to clear the subrun information
joshualittb7133be2015-04-08 09:08:31 -0700357 fCache->remove(cacheBlob);
joshualitt53b5f442015-04-13 06:33:59 -0700358 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint,
joshualitta751c972015-11-20 13:37:32 -0800359 GrAtlasTextBatch::kGrayTextVASize)));
robertphillips9c240a12015-05-28 07:45:59 -0700360 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix,
jvanverth0628a522015-08-18 07:44:22 -0700361 blob, x, y, drawFilter, clipRect, rt, clip);
joshualittb7133be2015-04-08 09:08:31 -0700362 } else {
joshualitt9e36c1a2015-04-14 12:17:27 -0700363 // If we can reuse the blob, then make sure we update the blob's viewmatrix, and x/y
joshualitt7e7b5c52015-07-21 12:56:56 -0700364 // offsets. Note, we offset the vertex bounds right before flushing
joshualitt2a0e9f32015-04-13 06:12:21 -0700365 cacheBlob->fViewMatrix = viewMatrix;
366 cacheBlob->fX = x;
367 cacheBlob->fY = y;
joshualittb7133be2015-04-08 09:08:31 -0700368 fCache->makeMRU(cacheBlob);
joshualitt259fbf12015-07-21 11:39:34 -0700369#ifdef CACHE_SANITY_CHECK
370 {
371 int glyphCount = 0;
372 int runCount = 0;
373 GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob);
374 SkAutoTUnref<GrAtlasTextBlob> sanityBlob(fCache->createBlob(glyphCount, runCount,
375 kGrayTextVASize));
376 GrTextBlobCache::SetupCacheBlobKey(sanityBlob, key, blurRec, skPaint);
377 this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor(), viewMatrix,
jvanverth0628a522015-08-18 07:44:22 -0700378 blob, x, y, drawFilter, clipRect, rt, clip);
joshualitt259fbf12015-07-21 11:39:34 -0700379 GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob);
380 }
381
382#endif
joshualitt1d89e8d2015-04-01 12:40:54 -0700383 }
384 } else {
joshualitt2a0e9f32015-04-13 06:12:21 -0700385 if (canCache) {
joshualitt53b5f442015-04-13 06:33:59 -0700386 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint,
joshualitta751c972015-11-20 13:37:32 -0800387 GrAtlasTextBatch::kGrayTextVASize)));
joshualitt2a0e9f32015-04-13 06:12:21 -0700388 } else {
joshualitta751c972015-11-20 13:37:32 -0800389 cacheBlob.reset(fCache->createBlob(blob, GrAtlasTextBatch::kGrayTextVASize));
joshualitt2a0e9f32015-04-13 06:12:21 -0700390 }
robertphillips9c240a12015-05-28 07:45:59 -0700391 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix,
jvanverth0628a522015-08-18 07:44:22 -0700392 blob, x, y, drawFilter, clipRect, rt, clip);
joshualitt1d89e8d2015-04-01 12:40:54 -0700393 }
394
robertphillipsf6703fa2015-09-01 05:36:47 -0700395 this->flush(blob, cacheBlob, dc, rt, skPaint, grPaint, drawFilter,
joshualitt2a0e9f32015-04-13 06:12:21 -0700396 clip, viewMatrix, clipBounds, x, y, transX, transY);
joshualitt1d89e8d2015-04-01 12:40:54 -0700397}
398
joshualitt9bd2daf2015-04-17 09:30:06 -0700399inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint,
400 const SkMatrix& viewMatrix) {
401 // TODO: support perspective (need getMaxScale replacement)
402 if (viewMatrix.hasPerspective()) {
403 return false;
404 }
405
406 SkScalar maxScale = viewMatrix.getMaxScale();
407 SkScalar scaledTextSize = maxScale*skPaint.getTextSize();
408 // Hinted text looks far better at small resolutions
409 // Scaling up beyond 2x yields undesireable artifacts
jvanverth34d72882015-06-22 08:08:09 -0700410 if (scaledTextSize < kMinDFFontSize || scaledTextSize > kLargeDFFontLimit) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700411 return false;
412 }
413
bsalomonafcd7cd2015-08-31 12:39:41 -0700414 bool useDFT = fSurfaceProps.isUseDeviceIndependentFonts();
robertphillipsbcd7ab52015-06-18 05:27:18 -0700415#if SK_FORCE_DISTANCE_FIELD_TEXT
416 useDFT = true;
417#endif
418
jvanverth4854d132015-06-22 06:46:56 -0700419 if (!useDFT && scaledTextSize < kLargeDFFontSize) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700420 return false;
421 }
422
423 // rasterizers and mask filters modify alpha, which doesn't
424 // translate well to distance
425 if (skPaint.getRasterizer() || skPaint.getMaskFilter() ||
bsalomon76228632015-05-29 08:02:10 -0700426 !fContext->caps()->shaderCaps()->shaderDerivativeSupport()) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700427 return false;
428 }
429
430 // TODO: add some stroking support
431 if (skPaint.getStyle() != SkPaint::kFill_Style) {
432 return false;
433 }
434
435 return true;
436}
437
joshualitt374b2f72015-07-21 08:05:03 -0700438void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
joshualitt9e36c1a2015-04-14 12:17:27 -0700439 const SkPaint& skPaint, GrColor color,
440 const SkMatrix& viewMatrix,
joshualittdbd35932015-04-02 09:19:04 -0700441 const SkTextBlob* blob, SkScalar x, SkScalar y,
joshualittfcfb9fc2015-04-21 07:35:10 -0700442 SkDrawFilter* drawFilter, const SkIRect& clipRect,
jvanverth0628a522015-08-18 07:44:22 -0700443 GrRenderTarget* rt, const GrClip& clip) {
herbe59124e2015-11-18 10:54:39 -0800444 // The color here is the GrPaint color, and it is used to determine whether we
jvanverth0628a522015-08-18 07:44:22 -0700445 // have to regenerate LCD text blobs.
446 // We use this color vs the SkPaint color because it has the colorfilter applied.
447 cacheBlob->fPaintColor = color;
joshualitt1d89e8d2015-04-01 12:40:54 -0700448 cacheBlob->fViewMatrix = viewMatrix;
449 cacheBlob->fX = x;
450 cacheBlob->fY = y;
joshualitt1d89e8d2015-04-01 12:40:54 -0700451
452 // Regenerate textblob
453 SkPaint runPaint = skPaint;
halcanary33779752015-10-27 14:01:05 -0700454 SkTextBlobRunIterator it(blob);
joshualitt1d89e8d2015-04-01 12:40:54 -0700455 for (int run = 0; !it.done(); it.next(), run++) {
456 int glyphCount = it.glyphCount();
457 size_t textLen = glyphCount * sizeof(uint16_t);
458 const SkPoint& offset = it.offset();
459 // applyFontToPaint() always overwrites the exact same attributes,
460 // so it is safe to not re-seed the paint for this reason.
461 it.applyFontToPaint(&runPaint);
462
463 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
464 // A false return from filter() means we should abort the current draw.
465 runPaint = skPaint;
466 continue;
467 }
468
robertphillipsfcf78292015-06-19 11:49:52 -0700469 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
joshualitt1d89e8d2015-04-01 12:40:54 -0700470
joshualitt1d89e8d2015-04-01 12:40:54 -0700471 // setup vertex / glyphIndex for the new run
472 if (run > 0) {
473 PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back();
474 PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back();
475
476 newRun.fVertexStartIndex = lastRun.fVertexEndIndex;
477 newRun.fVertexEndIndex = lastRun.fVertexEndIndex;
478
479 newRun.fGlyphStartIndex = lastRun.fGlyphEndIndex;
480 newRun.fGlyphEndIndex = lastRun.fGlyphEndIndex;
481 }
482
joshualittfcfb9fc2015-04-21 07:35:10 -0700483 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) {
484 cacheBlob->setHasDistanceField();
485 SkPaint dfPaint = runPaint;
486 SkScalar textRatio;
joshualitt64c99cc2015-04-21 09:43:03 -0700487 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMatrix);
joshualittfcfb9fc2015-04-21 07:35:10 -0700488 Run& runIdx = cacheBlob->fRuns[run];
489 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back();
490 subRun.fUseLCDText = runPaint.isLCDRenderText();
491 subRun.fDrawAsDistanceFields = true;
joshualitt9a27e632015-04-06 10:53:36 -0700492
joshualittfcfb9fc2015-04-21 07:35:10 -0700493 SkTDArray<char> fallbackTxt;
494 SkTDArray<SkScalar> fallbackPos;
495 SkPoint dfOffset;
496 int scalarsPerPosition = 2;
497 switch (it.positioning()) {
498 case SkTextBlob::kDefault_Positioning: {
jvanverth157e6482015-09-09 08:05:12 -0700499 this->internalDrawDFText(cacheBlob, run, dfPaint, color, viewMatrix,
joshualittfcfb9fc2015-04-21 07:35:10 -0700500 (const char *)it.glyphs(), textLen,
501 x + offset.x(), y + offset.y(), clipRect, textRatio,
502 &fallbackTxt, &fallbackPos, &dfOffset, runPaint);
503 break;
504 }
505 case SkTextBlob::kHorizontal_Positioning: {
506 scalarsPerPosition = 1;
507 dfOffset = SkPoint::Make(x, y + offset.y());
jvanverth157e6482015-09-09 08:05:12 -0700508 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix,
joshualittfcfb9fc2015-04-21 07:35:10 -0700509 (const char*)it.glyphs(), textLen, it.pos(),
510 scalarsPerPosition, dfOffset, clipRect, textRatio,
511 &fallbackTxt, &fallbackPos);
512 break;
513 }
514 case SkTextBlob::kFull_Positioning: {
515 dfOffset = SkPoint::Make(x, y);
jvanverth157e6482015-09-09 08:05:12 -0700516 this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix,
joshualittfcfb9fc2015-04-21 07:35:10 -0700517 (const char*)it.glyphs(), textLen, it.pos(),
518 scalarsPerPosition, dfOffset, clipRect, textRatio,
519 &fallbackTxt, &fallbackPos);
520 break;
521 }
522 }
523 if (fallbackTxt.count()) {
jvanverth0628a522015-08-18 07:44:22 -0700524 this->fallbackDrawPosText(cacheBlob, run, rt, clip, color, runPaint, viewMatrix,
joshualittfcfb9fc2015-04-21 07:35:10 -0700525 fallbackTxt, fallbackPos, scalarsPerPosition, dfOffset,
526 clipRect);
527 }
joshualittfcfb9fc2015-04-21 07:35:10 -0700528 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) {
529 cacheBlob->fRuns[run].fDrawAsPaths = true;
530 } else {
531 cacheBlob->setHasBitmap();
532 SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], runPaint, &viewMatrix,
533 false);
534 switch (it.positioning()) {
535 case SkTextBlob::kDefault_Positioning:
536 this->internalDrawBMPText(cacheBlob, run, cache, runPaint, color, viewMatrix,
537 (const char *)it.glyphs(), textLen,
538 x + offset.x(), y + offset.y(), clipRect);
539 break;
540 case SkTextBlob::kHorizontal_Positioning:
541 this->internalDrawBMPPosText(cacheBlob, run, cache, runPaint, color, viewMatrix,
542 (const char*)it.glyphs(), textLen, it.pos(), 1,
543 SkPoint::Make(x, y + offset.y()), clipRect);
544 break;
545 case SkTextBlob::kFull_Positioning:
546 this->internalDrawBMPPosText(cacheBlob, run, cache, runPaint, color, viewMatrix,
547 (const char*)it.glyphs(), textLen, it.pos(), 2,
548 SkPoint::Make(x, y), clipRect);
549 break;
550 }
551 SkGlyphCache::AttachCache(cache);
joshualitt1d89e8d2015-04-01 12:40:54 -0700552 }
553
554 if (drawFilter) {
555 // A draw filter may change the paint arbitrarily, so we must re-seed in this case.
556 runPaint = skPaint;
557 }
joshualitt1d89e8d2015-04-01 12:40:54 -0700558 }
559}
560
joshualitt374b2f72015-07-21 08:05:03 -0700561inline void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
joshualitt64c99cc2015-04-21 09:43:03 -0700562 SkPaint* skPaint,
563 SkScalar* textRatio,
joshualitt9bd2daf2015-04-17 09:30:06 -0700564 const SkMatrix& viewMatrix) {
565 // getMaxScale doesn't support perspective, so neither do we at the moment
566 SkASSERT(!viewMatrix.hasPerspective());
567 SkScalar maxScale = viewMatrix.getMaxScale();
568 SkScalar textSize = skPaint->getTextSize();
569 SkScalar scaledTextSize = textSize;
570 // if we have non-unity scale, we need to choose our base text size
571 // based on the SkPaint's text size multiplied by the max scale factor
572 // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)?
573 if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) {
574 scaledTextSize *= maxScale;
575 }
576
joshualitt64c99cc2015-04-21 09:43:03 -0700577 // We have three sizes of distance field text, and within each size 'bucket' there is a floor
578 // and ceiling. A scale outside of this range would require regenerating the distance fields
579 SkScalar dfMaskScaleFloor;
580 SkScalar dfMaskScaleCeil;
joshualitt9bd2daf2015-04-17 09:30:06 -0700581 if (scaledTextSize <= kSmallDFFontLimit) {
joshualitt64c99cc2015-04-21 09:43:03 -0700582 dfMaskScaleFloor = kMinDFFontSize;
joshualitta7c63892015-04-21 13:24:37 -0700583 dfMaskScaleCeil = kSmallDFFontLimit;
joshualitt9bd2daf2015-04-17 09:30:06 -0700584 *textRatio = textSize / kSmallDFFontSize;
585 skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize));
586 } else if (scaledTextSize <= kMediumDFFontLimit) {
joshualitta7c63892015-04-21 13:24:37 -0700587 dfMaskScaleFloor = kSmallDFFontLimit;
588 dfMaskScaleCeil = kMediumDFFontLimit;
joshualitt9bd2daf2015-04-17 09:30:06 -0700589 *textRatio = textSize / kMediumDFFontSize;
590 skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize));
591 } else {
joshualitta7c63892015-04-21 13:24:37 -0700592 dfMaskScaleFloor = kMediumDFFontLimit;
593 dfMaskScaleCeil = kLargeDFFontLimit;
joshualitt9bd2daf2015-04-17 09:30:06 -0700594 *textRatio = textSize / kLargeDFFontSize;
595 skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize));
596 }
597
joshualitt64c99cc2015-04-21 09:43:03 -0700598 // Because there can be multiple runs in the blob, we want the overall maxMinScale, and
599 // minMaxScale to make regeneration decisions. Specifically, we want the maximum minimum scale
600 // we can tolerate before we'd drop to a lower mip size, and the minimum maximum scale we can
601 // tolerate before we'd have to move to a large mip size. When we actually test these values
602 // we look at the delta in scale between the new viewmatrix and the old viewmatrix, and test
603 // against these values to decide if we can reuse or not(ie, will a given scale change our mip
604 // level)
joshualitta7c63892015-04-21 13:24:37 -0700605 SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil);
joshualitt64c99cc2015-04-21 09:43:03 -0700606 blob->fMaxMinScale = SkMaxScalar(dfMaskScaleFloor / scaledTextSize, blob->fMaxMinScale);
607 blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMinMaxScale);
608
joshualitt9bd2daf2015-04-17 09:30:06 -0700609 skPaint->setLCDRenderText(false);
610 skPaint->setAutohinted(false);
611 skPaint->setHinting(SkPaint::kNormal_Hinting);
612 skPaint->setSubpixelText(true);
613}
614
joshualitt374b2f72015-07-21 08:05:03 -0700615inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob,
joshualittfcfb9fc2015-04-21 07:35:10 -0700616 int runIndex,
joshualittfec19e12015-04-17 10:32:32 -0700617 GrRenderTarget* rt, const GrClip& clip,
jvanverth0628a522015-08-18 07:44:22 -0700618 GrColor color,
joshualitt9bd2daf2015-04-17 09:30:06 -0700619 const SkPaint& skPaint,
620 const SkMatrix& viewMatrix,
621 const SkTDArray<char>& fallbackTxt,
622 const SkTDArray<SkScalar>& fallbackPos,
623 int scalarsPerPosition,
624 const SkPoint& offset,
625 const SkIRect& clipRect) {
joshualittfec19e12015-04-17 10:32:32 -0700626 SkASSERT(fallbackTxt.count());
joshualittfcfb9fc2015-04-21 07:35:10 -0700627 blob->setHasBitmap();
628 Run& run = blob->fRuns[runIndex];
joshualitt97202d22015-04-22 13:47:02 -0700629 // Push back a new subrun to fill and set the override descriptor
630 run.push_back();
halcanary385fe4d2015-08-26 13:07:48 -0700631 run.fOverrideDescriptor.reset(new SkAutoDescriptor);
joshualitt97202d22015-04-22 13:47:02 -0700632 skPaint.getScalerContextDescriptor(run.fOverrideDescriptor,
robertphillipsfcf78292015-06-19 11:49:52 -0700633 fSurfaceProps, &viewMatrix, false);
joshualittfec19e12015-04-17 10:32:32 -0700634 SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface,
joshualitt97202d22015-04-22 13:47:02 -0700635 run.fOverrideDescriptor->getDesc());
jvanverth0628a522015-08-18 07:44:22 -0700636 this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatrix,
joshualitt9bd2daf2015-04-17 09:30:06 -0700637 fallbackTxt.begin(), fallbackTxt.count(),
638 fallbackPos.begin(), scalarsPerPosition, offset, clipRect);
639 SkGlyphCache::AttachCache(cache);
joshualitt9bd2daf2015-04-17 09:30:06 -0700640}
641
joshualitt374b2f72015-07-21 08:05:03 -0700642inline GrAtlasTextBlob*
herbe59124e2015-11-18 10:54:39 -0800643GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint,
644 const SkMatrix& viewMatrix, SkPaint* dfPaint,
jvanverth157e6482015-09-09 08:05:12 -0700645 SkScalar* textRatio) {
joshualitta751c972015-11-20 13:37:32 -0800646 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBatch::kGrayTextVASize);
joshualitt9bd2daf2015-04-17 09:30:06 -0700647
648 *dfPaint = origPaint;
joshualitt64c99cc2015-04-21 09:43:03 -0700649 this->initDistanceFieldPaint(blob, dfPaint, textRatio, viewMatrix);
joshualitt9bd2daf2015-04-17 09:30:06 -0700650 blob->fViewMatrix = viewMatrix;
joshualittfcfb9fc2015-04-21 07:35:10 -0700651 Run& run = blob->fRuns[0];
652 PerSubRunInfo& subRun = run.fSubRunInfo.back();
653 subRun.fUseLCDText = origPaint.isLCDRenderText();
654 subRun.fDrawAsDistanceFields = true;
joshualitt9bd2daf2015-04-17 09:30:06 -0700655
joshualitt9bd2daf2015-04-17 09:30:06 -0700656 return blob;
657}
658
joshualitt374b2f72015-07-21 08:05:03 -0700659inline GrAtlasTextBlob*
joshualitt79dfb2b2015-05-11 08:58:08 -0700660GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip,
661 const GrPaint& paint, const SkPaint& skPaint,
662 const SkMatrix& viewMatrix,
663 const char text[], size_t byteLength,
664 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
joshualitt1d89e8d2015-04-01 12:40:54 -0700665 int glyphCount = skPaint.countText(text, byteLength);
joshualitt1d89e8d2015-04-01 12:40:54 -0700666 SkIRect clipRect;
667 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect);
668
joshualitt374b2f72015-07-21 08:05:03 -0700669 GrAtlasTextBlob* blob;
joshualitt9bd2daf2015-04-17 09:30:06 -0700670 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) {
671 SkPaint dfPaint;
672 SkScalar textRatio;
jvanverth157e6482015-09-09 08:05:12 -0700673 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &textRatio);
joshualitt1d89e8d2015-04-01 12:40:54 -0700674
joshualitt9bd2daf2015-04-17 09:30:06 -0700675 SkTDArray<char> fallbackTxt;
676 SkTDArray<SkScalar> fallbackPos;
677 SkPoint offset;
jvanverth157e6482015-09-09 08:05:12 -0700678 this->internalDrawDFText(blob, 0, dfPaint, paint.getColor(), viewMatrix, text,
joshualitt9bd2daf2015-04-17 09:30:06 -0700679 byteLength, x, y, clipRect, textRatio, &fallbackTxt, &fallbackPos,
680 &offset, skPaint);
joshualitt9bd2daf2015-04-17 09:30:06 -0700681 if (fallbackTxt.count()) {
herbe59124e2015-11-18 10:54:39 -0800682 this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPaint, viewMatrix,
jvanverth0628a522015-08-18 07:44:22 -0700683 fallbackTxt, fallbackPos, 2, offset, clipRect);
joshualitt9bd2daf2015-04-17 09:30:06 -0700684 }
685 } else {
joshualitta751c972015-11-20 13:37:32 -0800686 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBatch::kGrayTextVASize);
joshualitt9bd2daf2015-04-17 09:30:06 -0700687 blob->fViewMatrix = viewMatrix;
688
689 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix, false);
690 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
691 byteLength, x, y, clipRect);
692 SkGlyphCache::AttachCache(cache);
joshualitt9bd2daf2015-04-17 09:30:06 -0700693 }
joshualitt79dfb2b2015-05-11 08:58:08 -0700694 return blob;
joshualitt1d89e8d2015-04-01 12:40:54 -0700695}
696
joshualitt374b2f72015-07-21 08:05:03 -0700697inline GrAtlasTextBlob*
joshualitt79dfb2b2015-05-11 08:58:08 -0700698GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip,
699 const GrPaint& paint, const SkPaint& skPaint,
700 const SkMatrix& viewMatrix,
701 const char text[], size_t byteLength,
702 const SkScalar pos[], int scalarsPerPosition,
703 const SkPoint& offset, const SkIRect& regionClipBounds) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700704 int glyphCount = skPaint.countText(text, byteLength);
705
706 SkIRect clipRect;
707 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect);
708
joshualitt374b2f72015-07-21 08:05:03 -0700709 GrAtlasTextBlob* blob;
joshualitt9bd2daf2015-04-17 09:30:06 -0700710 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) {
711 SkPaint dfPaint;
712 SkScalar textRatio;
jvanverth157e6482015-09-09 08:05:12 -0700713 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &textRatio);
joshualitt9bd2daf2015-04-17 09:30:06 -0700714
715 SkTDArray<char> fallbackTxt;
716 SkTDArray<SkScalar> fallbackPos;
jvanverth157e6482015-09-09 08:05:12 -0700717 this->internalDrawDFPosText(blob, 0, dfPaint, paint.getColor(), viewMatrix, text,
joshualitt9bd2daf2015-04-17 09:30:06 -0700718 byteLength, pos, scalarsPerPosition, offset, clipRect,
719 textRatio, &fallbackTxt, &fallbackPos);
joshualitt9bd2daf2015-04-17 09:30:06 -0700720 if (fallbackTxt.count()) {
herbe59124e2015-11-18 10:54:39 -0800721 this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPaint, viewMatrix,
722 fallbackTxt, fallbackPos, scalarsPerPosition, offset,
jvanverth0628a522015-08-18 07:44:22 -0700723 clipRect);
joshualitt9bd2daf2015-04-17 09:30:06 -0700724 }
725 } else {
joshualitta751c972015-11-20 13:37:32 -0800726 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBatch::kGrayTextVASize);
joshualitt9bd2daf2015-04-17 09:30:06 -0700727 blob->fViewMatrix = viewMatrix;
728 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMatrix, false);
729 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
730 byteLength, pos, scalarsPerPosition, offset, clipRect);
731 SkGlyphCache::AttachCache(cache);
joshualitt9bd2daf2015-04-17 09:30:06 -0700732 }
joshualitt79dfb2b2015-05-11 08:58:08 -0700733 return blob;
734}
735
robertphillipsf6703fa2015-09-01 05:36:47 -0700736void GrAtlasTextContext::onDrawText(GrDrawContext* dc, GrRenderTarget* rt,
herbe59124e2015-11-18 10:54:39 -0800737 const GrClip& clip,
joshualitt79dfb2b2015-05-11 08:58:08 -0700738 const GrPaint& paint, const SkPaint& skPaint,
739 const SkMatrix& viewMatrix,
740 const char text[], size_t byteLength,
741 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
joshualitt374b2f72015-07-21 08:05:03 -0700742 SkAutoTUnref<GrAtlasTextBlob> blob(
robertphillips2334fb62015-06-17 05:43:33 -0700743 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix,
744 text, byteLength, x, y, regionClipBounds));
robertphillipsf6703fa2015-09-01 05:36:47 -0700745 this->flush(blob, dc, rt, skPaint, paint, clip, regionClipBounds);
joshualitt79dfb2b2015-05-11 08:58:08 -0700746}
747
robertphillipsf6703fa2015-09-01 05:36:47 -0700748void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc, GrRenderTarget* rt,
robertphillipsccb1b572015-05-27 11:02:55 -0700749 const GrClip& clip,
joshualitt79dfb2b2015-05-11 08:58:08 -0700750 const GrPaint& paint, const SkPaint& skPaint,
751 const SkMatrix& viewMatrix,
752 const char text[], size_t byteLength,
753 const SkScalar pos[], int scalarsPerPosition,
754 const SkPoint& offset, const SkIRect& regionClipBounds) {
joshualitt374b2f72015-07-21 08:05:03 -0700755 SkAutoTUnref<GrAtlasTextBlob> blob(
robertphillips2334fb62015-06-17 05:43:33 -0700756 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix,
757 text, byteLength,
758 pos, scalarsPerPosition,
759 offset, regionClipBounds));
joshualitt79dfb2b2015-05-11 08:58:08 -0700760
robertphillipsf6703fa2015-09-01 05:36:47 -0700761 this->flush(blob, dc, rt, skPaint, paint, clip, regionClipBounds);
joshualitt9bd2daf2015-04-17 09:30:06 -0700762}
763
joshualitt374b2f72015-07-21 08:05:03 -0700764void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex,
joshualitt9bd2daf2015-04-17 09:30:06 -0700765 SkGlyphCache* cache, const SkPaint& skPaint,
766 GrColor color,
767 const SkMatrix& viewMatrix,
768 const char text[], size_t byteLength,
769 SkScalar x, SkScalar y, const SkIRect& clipRect) {
halcanary96fcdcc2015-08-27 07:41:13 -0700770 SkASSERT(byteLength == 0 || text != nullptr);
joshualitt1d89e8d2015-04-01 12:40:54 -0700771
772 // nothing to draw
halcanary96fcdcc2015-08-27 07:41:13 -0700773 if (text == nullptr || byteLength == 0) {
joshualitt1d89e8d2015-04-01 12:40:54 -0700774 return;
775 }
776
halcanary96fcdcc2015-08-27 07:41:13 -0700777 fCurrStrike = nullptr;
joshualitt1d89e8d2015-04-01 12:40:54 -0700778
779 // Get GrFontScaler from cache
780 GrFontScaler* fontScaler = GetGrFontScaler(cache);
781
herbe59124e2015-11-18 10:54:39 -0800782 SkFindAndPlaceGlyph::ProcessText(
herb4c11b3f2015-11-20 13:53:12 -0800783 skPaint.getTextEncoding(), text, byteLength,
784 {x, y}, viewMatrix, skPaint.getTextAlign(),
785 cache,
herbe59124e2015-11-18 10:54:39 -0800786 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
787 position += rounding;
788 this->bmpAppendGlyph(
789 blob, runIndex, glyph,
790 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
791 color, fontScaler, clipRect);
joshualitt1d89e8d2015-04-01 12:40:54 -0700792 }
herbe59124e2015-11-18 10:54:39 -0800793 );
joshualitt1d89e8d2015-04-01 12:40:54 -0700794}
795
joshualitt374b2f72015-07-21 08:05:03 -0700796void GrAtlasTextContext::internalDrawBMPPosText(GrAtlasTextBlob* blob, int runIndex,
joshualitt9bd2daf2015-04-17 09:30:06 -0700797 SkGlyphCache* cache, const SkPaint& skPaint,
798 GrColor color,
799 const SkMatrix& viewMatrix,
800 const char text[], size_t byteLength,
801 const SkScalar pos[], int scalarsPerPosition,
802 const SkPoint& offset, const SkIRect& clipRect) {
halcanary96fcdcc2015-08-27 07:41:13 -0700803 SkASSERT(byteLength == 0 || text != nullptr);
joshualitt1d89e8d2015-04-01 12:40:54 -0700804 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
805
806 // nothing to draw
halcanary96fcdcc2015-08-27 07:41:13 -0700807 if (text == nullptr || byteLength == 0) {
joshualitt1d89e8d2015-04-01 12:40:54 -0700808 return;
809 }
810
halcanary96fcdcc2015-08-27 07:41:13 -0700811 fCurrStrike = nullptr;
joshualitt1d89e8d2015-04-01 12:40:54 -0700812
813 // Get GrFontScaler from cache
814 GrFontScaler* fontScaler = GetGrFontScaler(cache);
815
herb9be5ff62015-11-11 11:30:11 -0800816 SkFindAndPlaceGlyph::ProcessPosText(
herb4c11b3f2015-11-20 13:53:12 -0800817 skPaint.getTextEncoding(), text, byteLength,
818 offset, viewMatrix, pos, scalarsPerPosition,
819 skPaint.getTextAlign(), cache,
herb9be5ff62015-11-11 11:30:11 -0800820 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
821 position += rounding;
822 this->bmpAppendGlyph(
823 blob, runIndex, glyph,
824 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
825 color, fontScaler, clipRect);
joshualitt1d89e8d2015-04-01 12:40:54 -0700826 }
herb9be5ff62015-11-11 11:30:11 -0800827 );
joshualitt1d89e8d2015-04-01 12:40:54 -0700828}
829
joshualitt374b2f72015-07-21 08:05:03 -0700830void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex,
jvanverth157e6482015-09-09 08:05:12 -0700831 const SkPaint& skPaint, GrColor color,
joshualitt9bd2daf2015-04-17 09:30:06 -0700832 const SkMatrix& viewMatrix,
833 const char text[], size_t byteLength,
834 SkScalar x, SkScalar y, const SkIRect& clipRect,
835 SkScalar textRatio,
836 SkTDArray<char>* fallbackTxt,
837 SkTDArray<SkScalar>* fallbackPos,
838 SkPoint* offset,
839 const SkPaint& origPaint) {
halcanary96fcdcc2015-08-27 07:41:13 -0700840 SkASSERT(byteLength == 0 || text != nullptr);
joshualitt9bd2daf2015-04-17 09:30:06 -0700841
842 // nothing to draw
halcanary96fcdcc2015-08-27 07:41:13 -0700843 if (text == nullptr || byteLength == 0) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700844 return;
845 }
846
847 SkDrawCacheProc glyphCacheProc = origPaint.getDrawCacheProc();
848 SkAutoDescriptor desc;
halcanary96fcdcc2015-08-27 07:41:13 -0700849 origPaint.getScalerContextDescriptor(&desc, fSurfaceProps, nullptr, true);
herbe59124e2015-11-18 10:54:39 -0800850 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(origPaint.getTypeface(),
joshualitt9bd2daf2015-04-17 09:30:06 -0700851 desc.getDesc());
852
853 SkTArray<SkScalar> positions;
854
855 const char* textPtr = text;
856 SkFixed stopX = 0;
857 SkFixed stopY = 0;
858 SkFixed origin = 0;
859 switch (origPaint.getTextAlign()) {
860 case SkPaint::kRight_Align: origin = SK_Fixed1; break;
861 case SkPaint::kCenter_Align: origin = SK_FixedHalf; break;
862 case SkPaint::kLeft_Align: origin = 0; break;
863 }
864
865 SkAutoKern autokern;
866 const char* stop = text + byteLength;
867 while (textPtr < stop) {
868 // don't need x, y here, since all subpixel variants will have the
869 // same advance
870 const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr, 0, 0);
871
872 SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph);
873 positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width)));
874
875 SkFixed height = glyph.fAdvanceY;
876 positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height)));
877
878 stopX += width;
879 stopY += height;
880 }
881 SkASSERT(textPtr == stop);
882
jvanverth157e6482015-09-09 08:05:12 -0700883 SkGlyphCache::AttachCache(origPaintCache);
884
joshualitt9bd2daf2015-04-17 09:30:06 -0700885 // now adjust starting point depending on alignment
886 SkScalar alignX = SkFixedToScalar(stopX);
887 SkScalar alignY = SkFixedToScalar(stopY);
888 if (origPaint.getTextAlign() == SkPaint::kCenter_Align) {
889 alignX = SkScalarHalf(alignX);
890 alignY = SkScalarHalf(alignY);
891 } else if (origPaint.getTextAlign() == SkPaint::kLeft_Align) {
892 alignX = 0;
893 alignY = 0;
894 }
895 x -= alignX;
896 y -= alignY;
897 *offset = SkPoint::Make(x, y);
898
jvanverth157e6482015-09-09 08:05:12 -0700899 this->internalDrawDFPosText(blob, runIndex, skPaint, color, viewMatrix, text, byteLength,
joshualitt9bd2daf2015-04-17 09:30:06 -0700900 positions.begin(), 2, *offset, clipRect, textRatio, fallbackTxt,
901 fallbackPos);
joshualitt9bd2daf2015-04-17 09:30:06 -0700902}
903
joshualitt374b2f72015-07-21 08:05:03 -0700904void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
jvanverth157e6482015-09-09 08:05:12 -0700905 const SkPaint& skPaint, GrColor color,
joshualitt9bd2daf2015-04-17 09:30:06 -0700906 const SkMatrix& viewMatrix,
907 const char text[], size_t byteLength,
908 const SkScalar pos[], int scalarsPerPosition,
909 const SkPoint& offset, const SkIRect& clipRect,
910 SkScalar textRatio,
911 SkTDArray<char>* fallbackTxt,
912 SkTDArray<SkScalar>* fallbackPos) {
913
halcanary96fcdcc2015-08-27 07:41:13 -0700914 SkASSERT(byteLength == 0 || text != nullptr);
joshualitt9bd2daf2015-04-17 09:30:06 -0700915 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
916
917 // nothing to draw
halcanary96fcdcc2015-08-27 07:41:13 -0700918 if (text == nullptr || byteLength == 0) {
joshualitt9bd2daf2015-04-17 09:30:06 -0700919 return;
920 }
921
halcanary96fcdcc2015-08-27 07:41:13 -0700922 fCurrStrike = nullptr;
joshualitt9bd2daf2015-04-17 09:30:06 -0700923
924 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
jvanverth157e6482015-09-09 08:05:12 -0700925 SkGlyphCache* cache = this->setupCache(&blob->fRuns[runIndex], skPaint, nullptr, true);
joshualitt9bd2daf2015-04-17 09:30:06 -0700926 GrFontScaler* fontScaler = GetGrFontScaler(cache);
927
928 const char* stop = text + byteLength;
929
930 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) {
931 while (text < stop) {
932 const char* lastText = text;
933 // the last 2 parameters are ignored
934 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
935
936 if (glyph.fWidth) {
937 SkScalar x = offset.x() + pos[0];
938 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
939
940 if (!this->dfAppendGlyph(blob,
941 runIndex,
joshualitt6c2c2b02015-07-24 10:37:00 -0700942 glyph,
joshualitt9bd2daf2015-04-17 09:30:06 -0700943 x, y, color, fontScaler, clipRect,
944 textRatio, viewMatrix)) {
945 // couldn't append, send to fallback
946 fallbackTxt->append(SkToInt(text-lastText), lastText);
947 *fallbackPos->append() = pos[0];
948 if (2 == scalarsPerPosition) {
949 *fallbackPos->append() = pos[1];
950 }
951 }
952 }
953 pos += scalarsPerPosition;
954 }
955 } else {
956 SkScalar alignMul = SkPaint::kCenter_Align == skPaint.getTextAlign() ? SK_ScalarHalf
957 : SK_Scalar1;
958 while (text < stop) {
959 const char* lastText = text;
960 // the last 2 parameters are ignored
961 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
962
963 if (glyph.fWidth) {
964 SkScalar x = offset.x() + pos[0];
965 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
966
967 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio;
968 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio;
969
970 if (!this->dfAppendGlyph(blob,
971 runIndex,
joshualitt6c2c2b02015-07-24 10:37:00 -0700972 glyph,
joshualitt9bd2daf2015-04-17 09:30:06 -0700973 x - advanceX, y - advanceY, color,
974 fontScaler,
975 clipRect,
976 textRatio,
977 viewMatrix)) {
978 // couldn't append, send to fallback
979 fallbackTxt->append(SkToInt(text-lastText), lastText);
980 *fallbackPos->append() = pos[0];
981 if (2 == scalarsPerPosition) {
982 *fallbackPos->append() = pos[1];
983 }
984 }
985 }
986 pos += scalarsPerPosition;
987 }
988 }
jvanverth157e6482015-09-09 08:05:12 -0700989
990 SkGlyphCache::AttachCache(cache);
joshualitt9bd2daf2015-04-17 09:30:06 -0700991}
992
joshualitt374b2f72015-07-21 08:05:03 -0700993void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
joshualitt6c2c2b02015-07-24 10:37:00 -0700994 const SkGlyph& skGlyph,
joshualitt9bd2daf2015-04-17 09:30:06 -0700995 int vx, int vy, GrColor color, GrFontScaler* scaler,
996 const SkIRect& clipRect) {
joshualittae32c102015-04-21 09:37:57 -0700997 Run& run = blob->fRuns[runIndex];
joshualitt9bd2daf2015-04-17 09:30:06 -0700998 if (!fCurrStrike) {
joshualitt1d89e8d2015-04-01 12:40:54 -0700999 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1000 }
1001
joshualitt6c2c2b02015-07-24 10:37:00 -07001002 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
1003 skGlyph.getSubXFixed(),
1004 skGlyph.getSubYFixed(),
1005 GrGlyph::kCoverage_MaskStyle);
1006 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler);
joshualitt010db532015-04-21 10:07:26 -07001007 if (!glyph) {
joshualitt1d89e8d2015-04-01 12:40:54 -07001008 return;
1009 }
1010
1011 int x = vx + glyph->fBounds.fLeft;
1012 int y = vy + glyph->fBounds.fTop;
1013
1014 // keep them as ints until we've done the clip-test
1015 int width = glyph->fBounds.width();
1016 int height = glyph->fBounds.height();
1017
joshualitt2a0e9f32015-04-13 06:12:21 -07001018#if 0
1019 // Not checking the clip bounds might introduce a performance regression. However, its not
1020 // clear if this is still true today with the larger tiles we use in Chrome. For repositionable
1021 // blobs, we want to make sure we have all of the glyphs, so clipping them out is not ideal.
1022 // We could store the cliprect in the key, but then we'd lose the ability to do integer scrolls
1023 // TODO verify this
joshualitt1d89e8d2015-04-01 12:40:54 -07001024 // check if we clipped out
1025 if (clipRect.quickReject(x, y, x + width, y + height)) {
1026 return;
1027 }
joshualitt2a0e9f32015-04-13 06:12:21 -07001028#endif
joshualitt1d89e8d2015-04-01 12:40:54 -07001029
1030 // If the glyph is too large we fall back to paths
joshualitt010db532015-04-21 10:07:26 -07001031 if (glyph->fTooLargeForAtlas) {
joshualitt6c2c2b02015-07-24 10:37:00 -07001032 this->appendGlyphPath(blob, glyph, scaler, skGlyph, SkIntToScalar(vx), SkIntToScalar(vy));
joshualitt1d89e8d2015-04-01 12:40:54 -07001033 return;
1034 }
1035
joshualitt1d89e8d2015-04-01 12:40:54 -07001036 GrMaskFormat format = glyph->fMaskFormat;
1037
1038 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
1039 if (run.fInitialized && subRun->fMaskFormat != format) {
joshualittd9f13ae2015-07-24 11:24:31 -07001040 subRun = &run.push_back();
joshualitt7e97b0b2015-07-31 15:18:08 -07001041 subRun->fStrike.reset(SkRef(fCurrStrike));
1042 } else if (!run.fInitialized) {
1043 subRun->fStrike.reset(SkRef(fCurrStrike));
joshualitt1d89e8d2015-04-01 12:40:54 -07001044 }
1045
1046 run.fInitialized = true;
joshualitt1d89e8d2015-04-01 12:40:54 -07001047
joshualitta751c972015-11-20 13:37:32 -08001048 size_t vertexStride = GrAtlasTextBatch::GetVertexStride(format);
joshualitt1d89e8d2015-04-01 12:40:54 -07001049
1050 SkRect r;
1051 r.fLeft = SkIntToScalar(x);
1052 r.fTop = SkIntToScalar(y);
1053 r.fRight = r.fLeft + SkIntToScalar(width);
1054 r.fBottom = r.fTop + SkIntToScalar(height);
joshualitt9bd2daf2015-04-17 09:30:06 -07001055 subRun->fMaskFormat = format;
1056 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMaskFormat == format,
joshualittae32c102015-04-21 09:37:57 -07001057 glyph);
joshualitt9bd2daf2015-04-17 09:30:06 -07001058}
joshualitt1d89e8d2015-04-01 12:40:54 -07001059
joshualitt374b2f72015-07-21 08:05:03 -07001060bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
joshualitt6c2c2b02015-07-24 10:37:00 -07001061 const SkGlyph& skGlyph,
joshualitt9bd2daf2015-04-17 09:30:06 -07001062 SkScalar sx, SkScalar sy, GrColor color,
1063 GrFontScaler* scaler,
1064 const SkIRect& clipRect,
1065 SkScalar textRatio, const SkMatrix& viewMatrix) {
joshualittae32c102015-04-21 09:37:57 -07001066 Run& run = blob->fRuns[runIndex];
joshualitt9bd2daf2015-04-17 09:30:06 -07001067 if (!fCurrStrike) {
1068 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1069 }
1070
joshualitt6c2c2b02015-07-24 10:37:00 -07001071 GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
1072 skGlyph.getSubXFixed(),
1073 skGlyph.getSubYFixed(),
1074 GrGlyph::kDistance_MaskStyle);
1075 GrGlyph* glyph = fCurrStrike->getGlyph(skGlyph, id, scaler);
joshualitt010db532015-04-21 10:07:26 -07001076 if (!glyph) {
joshualitt9bd2daf2015-04-17 09:30:06 -07001077 return true;
1078 }
1079
1080 // fallback to color glyph support
1081 if (kA8_GrMaskFormat != glyph->fMaskFormat) {
1082 return false;
1083 }
1084
1085 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
1086 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset);
1087 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2 * SK_DistanceFieldInset);
1088 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2 * SK_DistanceFieldInset);
1089
1090 SkScalar scale = textRatio;
1091 dx *= scale;
1092 dy *= scale;
1093 width *= scale;
1094 height *= scale;
1095 sx += dx;
1096 sy += dy;
1097 SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height);
1098
1099#if 0
1100 // check if we clipped out
1101 SkRect dstRect;
1102 viewMatrix.mapRect(&dstRect, glyphRect);
1103 if (clipRect.quickReject(SkScalarTruncToInt(dstRect.left()),
1104 SkScalarTruncToInt(dstRect.top()),
1105 SkScalarTruncToInt(dstRect.right()),
1106 SkScalarTruncToInt(dstRect.bottom()))) {
1107 return true;
1108 }
1109#endif
1110
1111 // TODO combine with the above
1112 // If the glyph is too large we fall back to paths
joshualitt010db532015-04-21 10:07:26 -07001113 if (glyph->fTooLargeForAtlas) {
joshualitt0fe04a22015-08-25 12:05:50 -07001114 this->appendGlyphPath(blob, glyph, scaler, skGlyph, sx - dx, sy - dy, scale, true);
joshualitt9bd2daf2015-04-17 09:30:06 -07001115 return true;
1116 }
1117
joshualitt9bd2daf2015-04-17 09:30:06 -07001118 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
joshualitt7e97b0b2015-07-31 15:18:08 -07001119 if (!run.fInitialized) {
1120 subRun->fStrike.reset(SkRef(fCurrStrike));
1121 }
1122 run.fInitialized = true;
joshualitt9bd2daf2015-04-17 09:30:06 -07001123 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat);
1124 subRun->fMaskFormat = kA8_GrMaskFormat;
1125
joshualitta751c972015-11-20 13:37:32 -08001126 size_t vertexStride = GrAtlasTextBatch::GetVertexStrideDf(kA8_GrMaskFormat,
1127 subRun->fUseLCDText);
joshualitt9bd2daf2015-04-17 09:30:06 -07001128
1129 bool useColorVerts = !subRun->fUseLCDText;
1130 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride, useColorVerts,
joshualittae32c102015-04-21 09:37:57 -07001131 glyph);
joshualitt9bd2daf2015-04-17 09:30:06 -07001132 return true;
1133}
1134
joshualitt374b2f72015-07-21 08:05:03 -07001135inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph* glyph,
joshualitt6c2c2b02015-07-24 10:37:00 -07001136 GrFontScaler* scaler, const SkGlyph& skGlyph,
joshualitt0fe04a22015-08-25 12:05:50 -07001137 SkScalar x, SkScalar y, SkScalar scale,
1138 bool applyVM) {
halcanary96fcdcc2015-08-27 07:41:13 -07001139 if (nullptr == glyph->fPath) {
joshualitt6c2c2b02015-07-24 10:37:00 -07001140 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph);
1141 if (!glyphPath) {
joshualitt9bd2daf2015-04-17 09:30:06 -07001142 return;
1143 }
joshualitt6c2c2b02015-07-24 10:37:00 -07001144
halcanary385fe4d2015-08-26 13:07:48 -07001145 glyph->fPath = new SkPath(*glyphPath);
joshualitt9bd2daf2015-04-17 09:30:06 -07001146 }
joshualitt0fe04a22015-08-25 12:05:50 -07001147 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, scale, applyVM));
joshualitt9bd2daf2015-04-17 09:30:06 -07001148}
1149
joshualitt374b2f72015-07-21 08:05:03 -07001150inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* run,
joshualitt9bd2daf2015-04-17 09:30:06 -07001151 Run::SubRunInfo* subRun,
1152 const SkRect& positions, GrColor color,
1153 size_t vertexStride, bool useVertexColor,
joshualittae32c102015-04-21 09:37:57 -07001154 GrGlyph* glyph) {
1155 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph;
joshualitt9bd2daf2015-04-17 09:30:06 -07001156 run->fVertexBounds.joinNonEmptyArg(positions);
1157 run->fColor = color;
joshualitt1d89e8d2015-04-01 12:40:54 -07001158
1159 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVertexEndIndex);
1160
joshualitt9bd2daf2015-04-17 09:30:06 -07001161 if (useVertexColor) {
joshualitt010db532015-04-21 10:07:26 -07001162 // V0
1163 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1164 position->set(positions.fLeft, positions.fTop);
joshualitt1d89e8d2015-04-01 12:40:54 -07001165 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1166 *colorPtr = color;
joshualitt010db532015-04-21 10:07:26 -07001167 vertex += vertexStride;
joshualitt9bd2daf2015-04-17 09:30:06 -07001168
joshualitt010db532015-04-21 10:07:26 -07001169 // V1
1170 position = reinterpret_cast<SkPoint*>(vertex);
1171 position->set(positions.fLeft, positions.fBottom);
1172 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
joshualitt1d89e8d2015-04-01 12:40:54 -07001173 *colorPtr = color;
joshualitt010db532015-04-21 10:07:26 -07001174 vertex += vertexStride;
joshualitt1d89e8d2015-04-01 12:40:54 -07001175
joshualitt010db532015-04-21 10:07:26 -07001176 // V2
1177 position = reinterpret_cast<SkPoint*>(vertex);
1178 position->set(positions.fRight, positions.fBottom);
1179 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
joshualitt1d89e8d2015-04-01 12:40:54 -07001180 *colorPtr = color;
joshualitt010db532015-04-21 10:07:26 -07001181 vertex += vertexStride;
joshualitt1d89e8d2015-04-01 12:40:54 -07001182
joshualitt010db532015-04-21 10:07:26 -07001183 // V3
1184 position = reinterpret_cast<SkPoint*>(vertex);
1185 position->set(positions.fRight, positions.fTop);
1186 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
joshualitt1d89e8d2015-04-01 12:40:54 -07001187 *colorPtr = color;
joshualitt010db532015-04-21 10:07:26 -07001188 } else {
1189 // V0
1190 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1191 position->set(positions.fLeft, positions.fTop);
1192 vertex += vertexStride;
1193
1194 // V1
1195 position = reinterpret_cast<SkPoint*>(vertex);
1196 position->set(positions.fLeft, positions.fBottom);
1197 vertex += vertexStride;
1198
1199 // V2
1200 position = reinterpret_cast<SkPoint*>(vertex);
1201 position->set(positions.fRight, positions.fBottom);
1202 vertex += vertexStride;
1203
1204 // V3
1205 position = reinterpret_cast<SkPoint*>(vertex);
1206 position->set(positions.fRight, positions.fTop);
joshualitt1d89e8d2015-04-01 12:40:54 -07001207 }
1208
1209 subRun->fGlyphEndIndex++;
joshualitta751c972015-11-20 13:37:32 -08001210 subRun->fVertexEndIndex += vertexStride * GrAtlasTextBatch::kVerticesPerGlyph;
joshualitt1d89e8d2015-04-01 12:40:54 -07001211}
1212
robertphillipsf6703fa2015-09-01 05:36:47 -07001213void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt,
herbe59124e2015-11-18 10:54:39 -08001214 const SkTextBlobRunIterator& it,
robertphillipsccb1b572015-05-27 11:02:55 -07001215 const GrClip& clip, const SkPaint& skPaint,
joshualitt9a27e632015-04-06 10:53:36 -07001216 SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
1217 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
1218 SkPaint runPaint = skPaint;
joshualitt1d89e8d2015-04-01 12:40:54 -07001219
joshualitt9a27e632015-04-06 10:53:36 -07001220 size_t textLen = it.glyphCount() * sizeof(uint16_t);
1221 const SkPoint& offset = it.offset();
joshualitt1d89e8d2015-04-01 12:40:54 -07001222
joshualitt9a27e632015-04-06 10:53:36 -07001223 it.applyFontToPaint(&runPaint);
joshualitt1d89e8d2015-04-01 12:40:54 -07001224
joshualitt9a27e632015-04-06 10:53:36 -07001225 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
1226 return;
joshualitt1d89e8d2015-04-01 12:40:54 -07001227 }
1228
robertphillipsfcf78292015-06-19 11:49:52 -07001229 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
joshualitt9a27e632015-04-06 10:53:36 -07001230
1231 switch (it.positioning()) {
1232 case SkTextBlob::kDefault_Positioning:
robertphillipsf6703fa2015-09-01 05:36:47 -07001233 this->drawTextAsPath(dc, rt, clip, runPaint, viewMatrix,
robertphillipsccb1b572015-05-27 11:02:55 -07001234 (const char *)it.glyphs(),
joshualitt9a27e632015-04-06 10:53:36 -07001235 textLen, x + offset.x(), y + offset.y(), clipBounds);
1236 break;
1237 case SkTextBlob::kHorizontal_Positioning:
robertphillipsf6703fa2015-09-01 05:36:47 -07001238 this->drawPosTextAsPath(dc, rt, clip, runPaint, viewMatrix,
robertphillipsccb1b572015-05-27 11:02:55 -07001239 (const char*)it.glyphs(),
joshualitt9a27e632015-04-06 10:53:36 -07001240 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
1241 clipBounds);
1242 break;
1243 case SkTextBlob::kFull_Positioning:
robertphillipsf6703fa2015-09-01 05:36:47 -07001244 this->drawPosTextAsPath(dc, rt, clip, runPaint, viewMatrix,
robertphillipsccb1b572015-05-27 11:02:55 -07001245 (const char*)it.glyphs(),
joshualitt9a27e632015-04-06 10:53:36 -07001246 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
1247 break;
1248 }
1249}
1250
bsalomonabd30f52015-08-13 13:34:48 -07001251inline GrDrawBatch*
joshualitt374b2f72015-07-21 08:05:03 -07001252GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo& info,
joshualitt79dfb2b2015-05-11 08:58:08 -07001253 int glyphCount, int run, int subRun,
1254 GrColor color, SkScalar transX, SkScalar transY,
1255 const SkPaint& skPaint) {
1256 GrMaskFormat format = info.fMaskFormat;
1257 GrColor subRunColor;
1258 if (kARGB_GrMaskFormat == format) {
1259 uint8_t paintAlpha = skPaint.getAlpha();
1260 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha);
1261 } else {
1262 subRunColor = color;
1263 }
1264
joshualitta751c972015-11-20 13:37:32 -08001265 GrAtlasTextBatch* batch;
joshualitt79dfb2b2015-05-11 08:58:08 -07001266 if (info.fDrawAsDistanceFields) {
1267 SkColor filteredColor;
1268 SkColorFilter* colorFilter = skPaint.getColorFilter();
1269 if (colorFilter) {
1270 filteredColor = colorFilter->filterColor(skPaint.getColor());
1271 } else {
1272 filteredColor = skPaint.getColor();
1273 }
robertphillipsfcf78292015-06-19 11:49:52 -07001274 bool useBGR = SkPixelGeometryIsBGR(fSurfaceProps.pixelGeometry());
joshualitta751c972015-11-20 13:37:32 -08001275 batch = GrAtlasTextBatch::CreateDistanceField(glyphCount, fContext->getBatchFontCache(),
1276 fDistanceAdjustTable, filteredColor,
1277 info.fUseLCDText, useBGR);
joshualitt79dfb2b2015-05-11 08:58:08 -07001278 } else {
joshualitta751c972015-11-20 13:37:32 -08001279 batch = GrAtlasTextBatch::CreateBitmap(format, glyphCount, fContext->getBatchFontCache());
joshualitt79dfb2b2015-05-11 08:58:08 -07001280 }
joshualitta751c972015-11-20 13:37:32 -08001281 GrAtlasTextBatch::Geometry& geometry = batch->geometry();
joshualitt79dfb2b2015-05-11 08:58:08 -07001282 geometry.fBlob = SkRef(cacheBlob);
1283 geometry.fRun = run;
1284 geometry.fSubRun = subRun;
1285 geometry.fColor = subRunColor;
1286 geometry.fTransX = transX;
1287 geometry.fTransY = transY;
1288 batch->init();
1289
1290 return batch;
1291}
1292
robertphillipsf6703fa2015-09-01 05:36:47 -07001293inline void GrAtlasTextContext::flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
joshualitt374b2f72015-07-21 08:05:03 -07001294 GrAtlasTextBlob* cacheBlob, int run, GrColor color,
robertphillipsea461502015-05-26 11:38:03 -07001295 SkScalar transX, SkScalar transY,
1296 const SkPaint& skPaint) {
joshualitt9a27e632015-04-06 10:53:36 -07001297 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); subRun++) {
1298 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun];
1299 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex;
1300 if (0 == glyphCount) {
1301 continue;
1302 }
1303
bsalomonabd30f52015-08-13 13:34:48 -07001304 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyphCount, run,
1305 subRun, color, transX, transY,
1306 skPaint));
robertphillipsf6703fa2015-09-01 05:36:47 -07001307 dc->drawBatch(pipelineBuilder, batch);
joshualitt9a27e632015-04-06 10:53:36 -07001308 }
1309}
1310
herbe59124e2015-11-18 10:54:39 -08001311inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob,
robertphillipsf6703fa2015-09-01 05:36:47 -07001312 GrDrawContext* dc, GrRenderTarget* rt,
robertphillipsccb1b572015-05-27 11:02:55 -07001313 const GrClip& clip, const SkPaint& skPaint,
joshualitt1107e902015-05-11 14:52:11 -07001314 SkScalar transX, SkScalar transY,
1315 const SkIRect& clipBounds) {
joshualittfc072562015-05-13 12:15:06 -07001316 if (!cacheBlob->fBigGlyphs.count()) {
1317 return;
1318 }
1319
joshualitt9a27e632015-04-06 10:53:36 -07001320 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) {
joshualitt374b2f72015-07-21 08:05:03 -07001321 GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i];
joshualitt19e4c022015-05-13 11:23:03 -07001322 bigGlyph.fVx += transX;
1323 bigGlyph.fVy += transY;
joshualitt0fe04a22015-08-25 12:05:50 -07001324 SkMatrix ctm;
1325 ctm.setScale(bigGlyph.fScale, bigGlyph.fScale);
1326 ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
1327 if (bigGlyph.fApplyVM) {
1328 ctm.postConcat(cacheBlob->fViewMatrix);
1329 }
joshualittfc072562015-05-13 12:15:06 -07001330
robertphillipsf6703fa2015-09-01 05:36:47 -07001331 GrBlurUtils::drawPathWithMaskFilter(fContext, dc, rt, clip, bigGlyph.fPath,
joshualitt0fe04a22015-08-25 12:05:50 -07001332 skPaint, ctm, nullptr, clipBounds, false);
joshualitt1d89e8d2015-04-01 12:40:54 -07001333 }
1334}
joshualitt9a27e632015-04-06 10:53:36 -07001335
robertphillips2334fb62015-06-17 05:43:33 -07001336void GrAtlasTextContext::flush(const SkTextBlob* blob,
joshualitt374b2f72015-07-21 08:05:03 -07001337 GrAtlasTextBlob* cacheBlob,
herbe59124e2015-11-18 10:54:39 -08001338 GrDrawContext* dc,
joshualitt9a27e632015-04-06 10:53:36 -07001339 GrRenderTarget* rt,
1340 const SkPaint& skPaint,
1341 const GrPaint& grPaint,
1342 SkDrawFilter* drawFilter,
1343 const GrClip& clip,
1344 const SkMatrix& viewMatrix,
1345 const SkIRect& clipBounds,
joshualitt2a0e9f32015-04-13 06:12:21 -07001346 SkScalar x, SkScalar y,
1347 SkScalar transX, SkScalar transY) {
joshualitt9a27e632015-04-06 10:53:36 -07001348 // We loop through the runs of the blob, flushing each. If any run is too large, then we flush
1349 // it as paths
joshualitt7b670db2015-07-09 13:25:02 -07001350 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
joshualitt9a27e632015-04-06 10:53:36 -07001351
1352 GrColor color = grPaint.getColor();
joshualitt9a27e632015-04-06 10:53:36 -07001353
halcanary33779752015-10-27 14:01:05 -07001354 SkTextBlobRunIterator it(blob);
joshualitt9a27e632015-04-06 10:53:36 -07001355 for (int run = 0; !it.done(); it.next(), run++) {
1356 if (cacheBlob->fRuns[run].fDrawAsPaths) {
robertphillipsf6703fa2015-09-01 05:36:47 -07001357 this->flushRunAsPaths(dc, rt, it, clip, skPaint,
robertphillipsccb1b572015-05-27 11:02:55 -07001358 drawFilter, viewMatrix, clipBounds, x, y);
joshualitt9a27e632015-04-06 10:53:36 -07001359 continue;
1360 }
joshualitt2a0e9f32015-04-13 06:12:21 -07001361 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY);
robertphillipsf6703fa2015-09-01 05:36:47 -07001362 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color,
robertphillipsea461502015-05-26 11:38:03 -07001363 transX, transY, skPaint);
joshualitt9a27e632015-04-06 10:53:36 -07001364 }
1365
1366 // Now flush big glyphs
robertphillipsf6703fa2015-09-01 05:36:47 -07001367 this->flushBigGlyphs(cacheBlob, dc, rt, clip, skPaint, transX, transY, clipBounds);
joshualitt9a27e632015-04-06 10:53:36 -07001368}
1369
joshualitt374b2f72015-07-21 08:05:03 -07001370void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob,
robertphillipsf6703fa2015-09-01 05:36:47 -07001371 GrDrawContext* dc,
joshualitt9a27e632015-04-06 10:53:36 -07001372 GrRenderTarget* rt,
1373 const SkPaint& skPaint,
1374 const GrPaint& grPaint,
joshualitt1107e902015-05-11 14:52:11 -07001375 const GrClip& clip,
1376 const SkIRect& clipBounds) {
joshualitt7b670db2015-07-09 13:25:02 -07001377 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
joshualitt9a27e632015-04-06 10:53:36 -07001378
1379 GrColor color = grPaint.getColor();
joshualitt9a27e632015-04-06 10:53:36 -07001380 for (int run = 0; run < cacheBlob->fRunCount; run++) {
robertphillipsf6703fa2015-09-01 05:36:47 -07001381 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint);
joshualitt9a27e632015-04-06 10:53:36 -07001382 }
1383
1384 // Now flush big glyphs
robertphillipsf6703fa2015-09-01 05:36:47 -07001385 this->flushBigGlyphs(cacheBlob, dc, rt, clip, skPaint, 0, 0, clipBounds);
joshualitt9a27e632015-04-06 10:53:36 -07001386}
joshualitt79dfb2b2015-05-11 08:58:08 -07001387
1388///////////////////////////////////////////////////////////////////////////////////////////////////
1389
1390#ifdef GR_TEST_UTILS
1391
bsalomonabd30f52015-08-13 13:34:48 -07001392DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
joshualitt79dfb2b2015-05-11 08:58:08 -07001393 static uint32_t gContextID = SK_InvalidGenID;
halcanary96fcdcc2015-08-27 07:41:13 -07001394 static GrAtlasTextContext* gTextContext = nullptr;
robertphillipsfcf78292015-06-19 11:49:52 -07001395 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
joshualitt79dfb2b2015-05-11 08:58:08 -07001396
1397 if (context->uniqueID() != gContextID) {
1398 gContextID = context->uniqueID();
halcanary385fe4d2015-08-26 13:07:48 -07001399 delete gTextContext;
robertphillips2334fb62015-06-17 05:43:33 -07001400
joshualitt79dfb2b2015-05-11 08:58:08 -07001401 // We don't yet test the fall back to paths in the GrTextContext base class. This is mostly
1402 // because we don't really want to have a gpu device here.
1403 // We enable distance fields by twiddling a knob on the paint
robertphillipsf6703fa2015-09-01 05:36:47 -07001404 gTextContext = GrAtlasTextContext::Create(context, gSurfaceProps);
joshualitt79dfb2b2015-05-11 08:58:08 -07001405 }
1406
1407 // create dummy render target
1408 GrSurfaceDesc desc;
1409 desc.fFlags = kRenderTarget_GrSurfaceFlag;
1410 desc.fWidth = 1024;
1411 desc.fHeight = 1024;
1412 desc.fConfig = kRGBA_8888_GrPixelConfig;
joshualitt15732062015-05-13 12:15:14 -07001413 desc.fSampleCnt = 0;
halcanary96fcdcc2015-08-27 07:41:13 -07001414 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, true, nullptr, 0));
joshualitt79dfb2b2015-05-11 08:58:08 -07001415 SkASSERT(texture);
halcanary96fcdcc2015-08-27 07:41:13 -07001416 SkASSERT(nullptr != texture->asRenderTarget());
joshualitt79dfb2b2015-05-11 08:58:08 -07001417 GrRenderTarget* rt = texture->asRenderTarget();
1418
1419 // Setup dummy SkPaint / GrPaint
1420 GrColor color = GrRandomColor(random);
joshualitt6c891102015-05-13 08:51:49 -07001421 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
joshualitt79dfb2b2015-05-11 08:58:08 -07001422 SkPaint skPaint;
joshualitt79dfb2b2015-05-11 08:58:08 -07001423 skPaint.setColor(color);
1424 skPaint.setLCDRenderText(random->nextBool());
1425 skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool());
1426 skPaint.setSubpixelText(random->nextBool());
1427
1428 GrPaint grPaint;
bsalomonf1b7a1d2015-09-28 06:26:28 -07001429 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &grPaint)) {
joshualitt79dfb2b2015-05-11 08:58:08 -07001430 SkFAIL("couldn't convert paint\n");
1431 }
1432
1433 const char* text = "The quick brown fox jumps over the lazy dog.";
1434 int textLen = (int)strlen(text);
1435
1436 // Setup clip
1437 GrClip clip;
1438 SkIRect noClip = SkIRect::MakeLargest();
1439
1440 // right now we don't handle textblobs, nor do we handle drawPosText. Since we only
1441 // intend to test the batch with this unit test, that is okay.
joshualitt374b2f72015-07-21 08:05:03 -07001442 SkAutoTUnref<GrAtlasTextBlob> blob(
joshualitt79dfb2b2015-05-11 08:58:08 -07001443 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMatrix, text,
1444 static_cast<size_t>(textLen), 0, 0, noClip));
1445
1446 SkScalar transX = static_cast<SkScalar>(random->nextU());
1447 SkScalar transY = static_cast<SkScalar>(random->nextU());
joshualitt374b2f72015-07-21 08:05:03 -07001448 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0];
joshualitt79dfb2b2015-05-11 08:58:08 -07001449 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, transY, skPaint);
1450}
1451
1452#endif