1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrAtlasTextBlob.h"
9 #include "GrBlurUtils.h"
10 #include "GrClip.h"
11 #include "GrContext.h"
12 #include "GrTextUtils.h"
13 #include "SkColorFilter.h"
14 #include "SkDrawFilter.h"
15 #include "SkGlyphCache.h"
16 #include "SkMaskFilterBase.h"
17 #include "SkTextBlobRunIterator.h"
18 #include "SkTextToPathIter.h"
19 #include "ops/GrAtlasTextOp.h"
20
Make(GrMemoryPool * pool,int glyphCount,int runCount)21 sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount, int runCount) {
22 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
23 // and size for the glyphIds array.
24 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
25 size_t size = sizeof(GrAtlasTextBlob) +
26 verticesCount +
27 glyphCount * sizeof(GrGlyph**) +
28 sizeof(GrAtlasTextBlob::Run) * runCount;
29
30 void* allocation;
31 if (pool) {
32 allocation = pool->allocate(size);
33 } else {
34 allocation = ::operator new (size);
35 }
36 if (CACHE_SANITY_CHECK) {
37 sk_bzero(allocation, size);
38 }
39
40 sk_sp<GrAtlasTextBlob> cacheBlob(new (allocation) GrAtlasTextBlob);
41 cacheBlob->fSize = size;
42
43 // setup offsets for vertices / glyphs
44 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<char*>(cacheBlob.get());
45 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount);
46 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
47
48 // Initialize runs
49 for (int i = 0; i < runCount; i++) {
50 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
51 }
52 cacheBlob->fRunCount = runCount;
53 cacheBlob->fPool = pool;
54 return cacheBlob;
55 }
56
setupCache(int runIndex,const SkSurfaceProps & props,SkScalerContextFlags scalerContextFlags,const SkPaint & skPaint,const SkMatrix * viewMatrix)57 SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex,
58 const SkSurfaceProps& props,
59 SkScalerContextFlags scalerContextFlags,
60 const SkPaint& skPaint,
61 const SkMatrix* viewMatrix) {
62 GrAtlasTextBlob::Run* run = &fRuns[runIndex];
63
64 // if we have an override descriptor for the run, then we should use that
65 SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() :
66 &run->fDescriptor;
67 SkScalerContextEffects effects;
68 SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
69 skPaint, &props, scalerContextFlags, viewMatrix, desc, &effects);
70 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
71 run->fPathEffect = sk_ref_sp(effects.fPathEffect);
72 run->fMaskFilter = sk_ref_sp(effects.fMaskFilter);
73 return SkGlyphCache::DetachCache(run->fTypeface.get(), effects, desc->getDesc());
74 }
75
appendGlyph(int runIndex,const SkRect & positions,GrColor color,sk_sp<GrTextStrike> strike,GrGlyph * glyph,SkGlyphCache * cache,const SkGlyph & skGlyph,SkScalar x,SkScalar y,SkScalar scale,bool preTransformed)76 void GrAtlasTextBlob::appendGlyph(int runIndex,
77 const SkRect& positions,
78 GrColor color,
79 sk_sp<GrTextStrike> strike,
80 GrGlyph* glyph,
81 SkGlyphCache* cache, const SkGlyph& skGlyph,
82 SkScalar x, SkScalar y, SkScalar scale, bool preTransformed) {
83 if (positions.isEmpty()) {
84 return;
85 }
86
87 // If the glyph is too large we fall back to paths
88 if (glyph->fTooLargeForAtlas) {
89 if (nullptr == glyph->fPath) {
90 const SkPath* glyphPath = cache->findPath(skGlyph);
91 if (!glyphPath) {
92 return;
93 }
94
95 glyph->fPath = new SkPath(*glyphPath);
96 }
97 this->appendPathGlyph(runIndex, *glyph->fPath, x, y, scale, preTransformed);
98 return;
99 }
100
101 Run& run = fRuns[runIndex];
102 GrMaskFormat format = glyph->fMaskFormat;
103
104 Run::SubRunInfo* subRun = &run.fSubRunInfo.back();
105 if (run.fInitialized && subRun->maskFormat() != format) {
106 subRun = &run.push_back();
107 subRun->setStrike(std::move(strike));
108 } else if (!run.fInitialized) {
109 subRun->setStrike(std::move(strike));
110 }
111
112 run.fInitialized = true;
113
114 bool hasW = subRun->hasWCoord();
115 // DF glyphs drawn in perspective must always have a w coord.
116 SkASSERT(hasW || !subRun->drawAsDistanceFields() || !fInitialViewMatrix.hasPerspective());
117 // Non-DF glyphs should never have a w coord.
118 SkASSERT(!hasW || subRun->drawAsDistanceFields());
119
120 size_t vertexStride = GetVertexStride(format, hasW);
121
122 subRun->setMaskFormat(format);
123
124 subRun->joinGlyphBounds(positions);
125 subRun->setColor(color);
126
127 intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());
128
129 // We always write the third position component used by SDFs. If it is unused it gets
130 // overwritten. Similarly, we always write the color and the blob will later overwrite it
131 // with texture coords if it is unused.
132 size_t colorOffset = hasW ? sizeof(SkPoint3) : sizeof(SkPoint);
133 // V0
134 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fTop, 1.f};
135 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
136 vertex += vertexStride;
137
138 // V1
139 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fBottom, 1.f};
140 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
141 vertex += vertexStride;
142
143 // V2
144 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fTop, 1.f};
145 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
146 vertex += vertexStride;
147
148 // V3
149 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fBottom, 1.f};
150 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
151
152 subRun->appendVertices(vertexStride);
153 fGlyphs[subRun->glyphEndIndex()] = glyph;
154 subRun->glyphAppended();
155 }
156
appendPathGlyph(int runIndex,const SkPath & path,SkScalar x,SkScalar y,SkScalar scale,bool preTransformed)157 void GrAtlasTextBlob::appendPathGlyph(int runIndex, const SkPath& path, SkScalar x, SkScalar y,
158 SkScalar scale, bool preTransformed) {
159 Run& run = fRuns[runIndex];
160 run.fPathGlyphs.push_back(GrAtlasTextBlob::Run::PathGlyph(path, x, y, scale, preTransformed));
161 }
162
mustRegenerate(const GrTextUtils::Paint & paint,const SkMaskFilterBase::BlurRec & blurRec,const SkMatrix & viewMatrix,SkScalar x,SkScalar y)163 bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint,
164 const SkMaskFilterBase::BlurRec& blurRec,
165 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
166 // If we have LCD text then our canonical color will be set to transparent, in this case we have
167 // to regenerate the blob on any color change
168 // We use the grPaint to get any color filter effects
169 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
170 fLuminanceColor != paint.luminanceColor()) {
171 return true;
172 }
173
174 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
175 return true;
176 }
177
178 /** This could be relaxed for blobs with only distance field glyphs. */
179 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
180 return true;
181 }
182
183 // We only cache one masked version
184 if (fKey.fHasBlur &&
185 (fBlurRec.fSigma != blurRec.fSigma ||
186 fBlurRec.fStyle != blurRec.fStyle ||
187 fBlurRec.fQuality != blurRec.fQuality)) {
188 return true;
189 }
190
191 // Similarly, we only cache one version for each style
192 if (fKey.fStyle != SkPaint::kFill_Style &&
193 (fStrokeInfo.fFrameWidth != paint.skPaint().getStrokeWidth() ||
194 fStrokeInfo.fMiterLimit != paint.skPaint().getStrokeMiter() ||
195 fStrokeInfo.fJoin != paint.skPaint().getStrokeJoin())) {
196 return true;
197 }
198
199 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
200 // for mixed blobs if this becomes an issue.
201 if (this->hasBitmap() && this->hasDistanceField()) {
202 // Identical viewmatrices and we can reuse in all cases
203 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
204 return false;
205 }
206 return true;
207 }
208
209 if (this->hasBitmap()) {
210 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
211 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
212 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
213 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
214 return true;
215 }
216
217 // We can update the positions in the cachedtextblobs without regenerating the whole blob,
218 // but only for integer translations.
219 // This cool bit of math will determine the necessary translation to apply to the already
220 // generated vertex coordinates to move them to the correct position
221 SkScalar transX = viewMatrix.getTranslateX() +
222 viewMatrix.getScaleX() * (x - fInitialX) +
223 viewMatrix.getSkewX() * (y - fInitialY) -
224 fInitialViewMatrix.getTranslateX();
225 SkScalar transY = viewMatrix.getTranslateY() +
226 viewMatrix.getSkewY() * (x - fInitialX) +
227 viewMatrix.getScaleY() * (y - fInitialY) -
228 fInitialViewMatrix.getTranslateY();
229 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
230 return true;
231 }
232 } else if (this->hasDistanceField()) {
233 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
234 // distance field being generated, so we have to regenerate in those cases
235 SkScalar newMaxScale = viewMatrix.getMaxScale();
236 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
237 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
238 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
239 return true;
240 }
241 }
242
243 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
244 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
245 // the blob anyways at flush time, so no need to regenerate explicitly
246 return false;
247 }
248
makeOp(const Run::SubRunInfo & info,int glyphCount,uint16_t run,uint16_t subRun,const SkMatrix & viewMatrix,SkScalar x,SkScalar y,const SkIRect & clipRect,const GrTextUtils::Paint & paint,const SkSurfaceProps & props,const GrDistanceFieldAdjustTable * distanceAdjustTable,GrRestrictedAtlasManager * restrictedAtlasManager,GrTextUtils::Target * target)249 inline std::unique_ptr<GrAtlasTextOp> GrAtlasTextBlob::makeOp(
250 const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun,
251 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
252 const GrTextUtils::Paint& paint, const SkSurfaceProps& props,
253 const GrDistanceFieldAdjustTable* distanceAdjustTable,
254 GrRestrictedAtlasManager* restrictedAtlasManager, GrTextUtils::Target* target) {
255 GrMaskFormat format = info.maskFormat();
256
257 GrPaint grPaint;
258 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
259 std::unique_ptr<GrAtlasTextOp> op;
260 if (info.drawAsDistanceFields()) {
261 bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
262 op = GrAtlasTextOp::MakeDistanceField(
263 std::move(grPaint), glyphCount, restrictedAtlasManager, distanceAdjustTable,
264 target->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(),
265 info.hasUseLCDText(), useBGR, info.isAntiAliased());
266 } else {
267 op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format,
268 glyphCount, restrictedAtlasManager);
269 }
270 GrAtlasTextOp::Geometry& geometry = op->geometry();
271 geometry.fViewMatrix = viewMatrix;
272 geometry.fClipRect = clipRect;
273 geometry.fBlob = SkRef(this);
274 geometry.fRun = run;
275 geometry.fSubRun = subRun;
276 geometry.fColor =
277 info.maskFormat() == kARGB_GrMaskFormat ? GrColor_WHITE : paint.filteredPremulColor();
278 geometry.fX = x;
279 geometry.fY = y;
280 op->init();
281 return op;
282 }
283
calculate_translation(bool applyVM,const SkMatrix & newViewMatrix,SkScalar newX,SkScalar newY,const SkMatrix & currentViewMatrix,SkScalar currentX,SkScalar currentY,SkScalar * transX,SkScalar * transY)284 static void calculate_translation(bool applyVM,
285 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
286 const SkMatrix& currentViewMatrix, SkScalar currentX,
287 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
288 if (applyVM) {
289 *transX = newViewMatrix.getTranslateX() +
290 newViewMatrix.getScaleX() * (newX - currentX) +
291 newViewMatrix.getSkewX() * (newY - currentY) -
292 currentViewMatrix.getTranslateX();
293
294 *transY = newViewMatrix.getTranslateY() +
295 newViewMatrix.getSkewY() * (newX - currentX) +
296 newViewMatrix.getScaleY() * (newY - currentY) -
297 currentViewMatrix.getTranslateY();
298 } else {
299 *transX = newX - currentX;
300 *transY = newY - currentY;
301 }
302 }
303
flush(GrRestrictedAtlasManager * restrictedAtlasManager,GrTextUtils::Target * target,const SkSurfaceProps & props,const GrDistanceFieldAdjustTable * distanceAdjustTable,const GrTextUtils::Paint & paint,const GrClip & clip,const SkMatrix & viewMatrix,const SkIRect & clipBounds,SkScalar x,SkScalar y)304 void GrAtlasTextBlob::flush(GrRestrictedAtlasManager* restrictedAtlasManager,
305 GrTextUtils::Target* target, const SkSurfaceProps& props,
306 const GrDistanceFieldAdjustTable* distanceAdjustTable,
307 const GrTextUtils::Paint& paint, const GrClip& clip,
308 const SkMatrix& viewMatrix, const SkIRect& clipBounds,
309 SkScalar x, SkScalar y) {
310
311 // GrAtlasTextBlob::makeOp only takes uint16_t values for run and subRun indices.
312 // Encountering something larger than this is highly unlikely, so we'll just not draw it.
313 int lastRun = SkTMin(fRunCount, (1 << 16)) - 1;
314 GrTextUtils::RunPaint runPaint(&paint, nullptr, props);
315 for (int runIndex = 0; runIndex <= lastRun; runIndex++) {
316 Run& run = fRuns[runIndex];
317
318 // first flush any path glyphs
319 if (run.fPathGlyphs.count()) {
320 SkScalar transX, transY;
321 uint16_t paintFlags = run.fPaintFlags;
322 if (!runPaint.modifyForRun(
323 [paintFlags](SkPaint* p) {
324 p->setFlags((p->getFlags() & ~Run::kPaintFlagsMask) | paintFlags);
325 })) {
326 continue;
327 }
328 for (int i = 0; i < run.fPathGlyphs.count(); i++) {
329 GrAtlasTextBlob::Run::PathGlyph& pathGlyph = run.fPathGlyphs[i];
330 calculate_translation(pathGlyph.fPreTransformed, viewMatrix, x, y,
331 fInitialViewMatrix, fInitialX, fInitialY, &transX, &transY);
332 const SkMatrix& ctm = pathGlyph.fPreTransformed ? SkMatrix::I() : viewMatrix;
333 SkMatrix pathMatrix;
334 pathMatrix.setScale(pathGlyph.fScale, pathGlyph.fScale);
335 pathMatrix.postTranslate(pathGlyph.fX + transX, pathGlyph.fY + transY);
336 target->drawPath(clip, pathGlyph.fPath, runPaint, ctm, &pathMatrix, clipBounds);
337 }
338 }
339
340 // then flush each subrun, if any
341 if (!run.fInitialized) {
342 continue;
343 }
344 int lastSubRun = SkTMin(run.fSubRunInfo.count(), 1 << 16) - 1;
345 for (int subRun = 0; subRun <= lastSubRun; subRun++) {
346 const Run::SubRunInfo& info = run.fSubRunInfo[subRun];
347 int glyphCount = info.glyphCount();
348 if (0 == glyphCount) {
349 continue;
350 }
351
352 bool skipClip = false;
353 bool submitOp = true;
354 SkIRect clipRect = SkIRect::MakeEmpty();
355 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
356 SkRRect clipRRect;
357 GrAA aa;
358 // We can clip geometrically if we're not using SDFs,
359 // and we have an axis-aligned rectangular non-AA clip
360 if (!info.drawAsDistanceFields() && clip.isRRect(rtBounds, &clipRRect, &aa) &&
361 clipRRect.isRect() && GrAA::kNo == aa) {
362 skipClip = true;
363 // We only need to do clipping work if the subrun isn't contained by the clip
364 SkRect subRunBounds;
365 this->computeSubRunBounds(&subRunBounds, runIndex, subRun, viewMatrix, x, y);
366 if (!clipRRect.getBounds().contains(subRunBounds)) {
367 // If the subrun is completely outside, don't add an op for it
368 if (!clipRRect.getBounds().intersects(subRunBounds)) {
369 submitOp = false;
370 }
371 else {
372 clipRRect.getBounds().round(&clipRect);
373 }
374 }
375 }
376
377 if (submitOp) {
378 auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y,
379 clipRect, std::move(paint), props, distanceAdjustTable,
380 restrictedAtlasManager, target);
381 if (op) {
382 if (skipClip) {
383 target->addDrawOp(GrNoClip(), std::move(op));
384 }
385 else {
386 target->addDrawOp(clip, std::move(op));
387 }
388 }
389 }
390 }
391
392 }
393 }
394
test_makeOp(int glyphCount,uint16_t run,uint16_t subRun,const SkMatrix & viewMatrix,SkScalar x,SkScalar y,const GrTextUtils::Paint & paint,const SkSurfaceProps & props,const GrDistanceFieldAdjustTable * distanceAdjustTable,GrRestrictedAtlasManager * restrictedAtlasManager,GrTextUtils::Target * target)395 std::unique_ptr<GrDrawOp> GrAtlasTextBlob::test_makeOp(
396 int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix,
397 SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props,
398 const GrDistanceFieldAdjustTable* distanceAdjustTable,
399 GrRestrictedAtlasManager* restrictedAtlasManager, GrTextUtils::Target* target) {
400 const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun];
401 SkIRect emptyRect = SkIRect::MakeEmpty();
402 return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect, paint, props,
403 distanceAdjustTable, restrictedAtlasManager, target);
404 }
405
AssertEqual(const GrAtlasTextBlob & l,const GrAtlasTextBlob & r)406 void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
407 SkASSERT_RELEASE(l.fSize == r.fSize);
408 SkASSERT_RELEASE(l.fPool == r.fPool);
409
410 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
411 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
412 SkASSERT_RELEASE(l.fBlurRec.fQuality == r.fBlurRec.fQuality);
413
414 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
415 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
416 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
417
418 SkASSERT_RELEASE(l.fKey == r.fKey);
419 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
420 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
421 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
422 SkASSERT_RELEASE(l.fTextType == r.fTextType);
423
424 SkASSERT_RELEASE(l.fRunCount == r.fRunCount);
425 for (int i = 0; i < l.fRunCount; i++) {
426 const Run& lRun = l.fRuns[i];
427 const Run& rRun = r.fRuns[i];
428
429 if (lRun.fTypeface.get()) {
430 SkASSERT_RELEASE(rRun.fTypeface.get());
431 SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface.get(), rRun.fTypeface.get()));
432 } else {
433 SkASSERT_RELEASE(!rRun.fTypeface.get());
434 }
435
436
437 SkASSERT_RELEASE(lRun.fDescriptor.getDesc());
438 SkASSERT_RELEASE(rRun.fDescriptor.getDesc());
439 SkASSERT_RELEASE(*lRun.fDescriptor.getDesc() == *rRun.fDescriptor.getDesc());
440
441 if (lRun.fOverrideDescriptor.get()) {
442 SkASSERT_RELEASE(lRun.fOverrideDescriptor->getDesc());
443 SkASSERT_RELEASE(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());
444 SkASSERT_RELEASE(*lRun.fOverrideDescriptor->getDesc() ==
445 *rRun.fOverrideDescriptor->getDesc());
446 } else {
447 SkASSERT_RELEASE(!rRun.fOverrideDescriptor.get());
448 }
449
450 // color can be changed
451 //SkASSERT(lRun.fColor == rRun.fColor);
452 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
453
454 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
455 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
456 const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j];
457 const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j];
458
459 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
460 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
461
462 if (lSubRun.strike()) {
463 SkASSERT_RELEASE(rSubRun.strike());
464 SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) ==
465 GrTextStrike::GetKey(*rSubRun.strike()));
466
467 } else {
468 SkASSERT_RELEASE(!rSubRun.strike());
469 }
470
471 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
472 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
473 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
474 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
475 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
476 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
477 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
478 }
479
480 SkASSERT_RELEASE(lRun.fPathGlyphs.count() == rRun.fPathGlyphs.count());
481 for (int i = 0; i < lRun.fPathGlyphs.count(); i++) {
482 const Run::PathGlyph& lPathGlyph = lRun.fPathGlyphs[i];
483 const Run::PathGlyph& rPathGlyph = rRun.fPathGlyphs[i];
484
485 SkASSERT_RELEASE(lPathGlyph.fPath == rPathGlyph.fPath);
486 // We can't assert that these have the same translations
487 }
488 }
489 }
490
computeTranslation(const SkMatrix & viewMatrix,SkScalar x,SkScalar y,SkScalar * transX,SkScalar * transY)491 void GrAtlasTextBlob::Run::SubRunInfo::computeTranslation(const SkMatrix& viewMatrix,
492 SkScalar x, SkScalar y, SkScalar* transX,
493 SkScalar* transY) {
494 calculate_translation(!this->drawAsDistanceFields(), viewMatrix, x, y,
495 fCurrentViewMatrix, fX, fY, transX, transY);
496 fCurrentViewMatrix = viewMatrix;
497 fX = x;
498 fY = y;
499 }
500