blob: 2775098eccc436096aac1d4ab109afbb326b1492 [file] [log] [blame]
joshualitt259fbf12015-07-21 11:39:34 -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
8#include "GrAtlasTextBlob.h"
9
joshualitt2e2202e2015-12-10 11:22:08 -080010#include "GrBlurUtils.h"
11#include "GrContext.h"
12#include "GrDrawContext.h"
joshualitt0a42e682015-12-10 13:20:58 -080013#include "GrTextUtils.h"
joshualitt2e2202e2015-12-10 11:22:08 -080014#include "SkColorFilter.h"
15#include "SkDrawFilter.h"
joshualitte76b4bb2015-12-28 07:23:58 -080016#include "SkGlyphCache.h"
joshualitt2e2202e2015-12-10 11:22:08 -080017#include "SkTextBlobRunIterator.h"
18#include "batches/GrAtlasTextBatch.h"
19
joshualitt92303772016-02-10 11:55:52 -080020GrAtlasTextBlob* GrAtlasTextBlob::Create(GrMemoryPool* pool, int glyphCount, int runCount) {
21 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
22 // and size for the glyphIds array.
23 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
24 size_t size = sizeof(GrAtlasTextBlob) +
25 verticesCount +
26 glyphCount * sizeof(GrGlyph**) +
27 sizeof(GrAtlasTextBlob::Run) * runCount;
28
29 void* allocation = pool->allocate(size);
30 if (CACHE_SANITY_CHECK) {
31 sk_bzero(allocation, size);
32 }
33
34 GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob;
35 cacheBlob->fSize = size;
36
37 // setup offsets for vertices / glyphs
38 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned char*>(cacheBlob);
39 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount);
40 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
41
42 // Initialize runs
43 for (int i = 0; i < runCount; i++) {
44 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
45 }
46 cacheBlob->fRunCount = runCount;
47 cacheBlob->fPool = pool;
48 return cacheBlob;
49}
50
51
joshualitte76b4bb2015-12-28 07:23:58 -080052SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex,
53 const SkSurfaceProps& props,
54 const SkPaint& skPaint,
55 const SkMatrix* viewMatrix,
56 bool noGamma) {
57 GrAtlasTextBlob::Run* run = &fRuns[runIndex];
58
59 // if we have an override descriptor for the run, then we should use that
60 SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() :
61 &run->fDescriptor;
62 skPaint.getScalerContextDescriptor(desc, props, viewMatrix, noGamma);
63 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
64 return SkGlyphCache::DetachCache(run->fTypeface, desc->getDesc());
65}
66
joshualittf528e0d2015-12-09 06:42:52 -080067void GrAtlasTextBlob::appendGlyph(int runIndex,
68 const SkRect& positions,
69 GrColor color,
70 GrBatchTextStrike* strike,
joshualitta06e6ab2015-12-10 08:54:41 -080071 GrGlyph* glyph,
72 GrFontScaler* scaler, const SkGlyph& skGlyph,
73 SkScalar x, SkScalar y, SkScalar scale, bool applyVM) {
74
75 // If the glyph is too large we fall back to paths
76 if (glyph->fTooLargeForAtlas) {
77 this->appendLargeGlyph(glyph, scaler, skGlyph, x, y, scale, applyVM);
78 return;
79 }
80
joshualittf528e0d2015-12-09 06:42:52 -080081 Run& run = fRuns[runIndex];
82 GrMaskFormat format = glyph->fMaskFormat;
83
84 Run::SubRunInfo* subRun = &run.fSubRunInfo.back();
85 if (run.fInitialized && subRun->maskFormat() != format) {
86 subRun = &run.push_back();
87 subRun->setStrike(strike);
88 } else if (!run.fInitialized) {
89 subRun->setStrike(strike);
90 }
91
92 run.fInitialized = true;
93
94 size_t vertexStride = GetVertexStride(format);
95
96 subRun->setMaskFormat(format);
97
joshualitt7481e752016-01-22 06:08:48 -080098 subRun->joinGlyphBounds(positions);
joshualittf9e658b2015-12-09 09:26:44 -080099 subRun->setColor(color);
joshualitt18b072d2015-12-07 12:26:12 -0800100
101 intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());
102
joshualittf528e0d2015-12-09 06:42:52 -0800103 if (kARGB_GrMaskFormat != glyph->fMaskFormat) {
joshualitt18b072d2015-12-07 12:26:12 -0800104 // V0
105 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
106 position->set(positions.fLeft, positions.fTop);
107 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
108 *colorPtr = color;
109 vertex += vertexStride;
110
111 // V1
112 position = reinterpret_cast<SkPoint*>(vertex);
113 position->set(positions.fLeft, positions.fBottom);
114 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
115 *colorPtr = color;
116 vertex += vertexStride;
117
118 // V2
119 position = reinterpret_cast<SkPoint*>(vertex);
120 position->set(positions.fRight, positions.fBottom);
121 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
122 *colorPtr = color;
123 vertex += vertexStride;
124
125 // V3
126 position = reinterpret_cast<SkPoint*>(vertex);
127 position->set(positions.fRight, positions.fTop);
128 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
129 *colorPtr = color;
130 } else {
131 // V0
132 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
133 position->set(positions.fLeft, positions.fTop);
134 vertex += vertexStride;
135
136 // V1
137 position = reinterpret_cast<SkPoint*>(vertex);
138 position->set(positions.fLeft, positions.fBottom);
139 vertex += vertexStride;
140
141 // V2
142 position = reinterpret_cast<SkPoint*>(vertex);
143 position->set(positions.fRight, positions.fBottom);
144 vertex += vertexStride;
145
146 // V3
147 position = reinterpret_cast<SkPoint*>(vertex);
148 position->set(positions.fRight, positions.fTop);
149 }
150 subRun->appendVertices(vertexStride);
151 fGlyphs[subRun->glyphEndIndex()] = glyph;
152 subRun->glyphAppended();
153}
154
joshualitta06e6ab2015-12-10 08:54:41 -0800155void GrAtlasTextBlob::appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& skGlyph,
156 SkScalar x, SkScalar y, SkScalar scale, bool applyVM) {
157 if (nullptr == glyph->fPath) {
158 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph);
159 if (!glyphPath) {
160 return;
161 }
162
163 glyph->fPath = new SkPath(*glyphPath);
164 }
165 fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, scale, applyVM));
166}
167
joshualittfd5f6c12015-12-10 07:44:50 -0800168bool GrAtlasTextBlob::mustRegenerate(SkScalar* outTransX, SkScalar* outTransY,
169 const SkPaint& paint,
170 GrColor color, const SkMaskFilter::BlurRec& blurRec,
171 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
172 // If we have LCD text then our canonical color will be set to transparent, in this case we have
173 // to regenerate the blob on any color change
174 // We use the grPaint to get any color filter effects
175 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
176 fPaintColor != color) {
177 return true;
178 }
179
180 if (fViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
181 return true;
182 }
183
184 if (fViewMatrix.hasPerspective() && !fViewMatrix.cheapEqualTo(viewMatrix)) {
185 return true;
186 }
187
188 // We only cache one masked version
189 if (fKey.fHasBlur &&
190 (fBlurRec.fSigma != blurRec.fSigma ||
191 fBlurRec.fStyle != blurRec.fStyle ||
192 fBlurRec.fQuality != blurRec.fQuality)) {
193 return true;
194 }
195
196 // Similarly, we only cache one version for each style
197 if (fKey.fStyle != SkPaint::kFill_Style &&
198 (fStrokeInfo.fFrameWidth != paint.getStrokeWidth() ||
199 fStrokeInfo.fMiterLimit != paint.getStrokeMiter() ||
200 fStrokeInfo.fJoin != paint.getStrokeJoin())) {
201 return true;
202 }
203
204 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
205 // for mixed blobs if this becomes an issue.
206 if (this->hasBitmap() && this->hasDistanceField()) {
207 // Identical viewmatrices and we can reuse in all cases
208 if (fViewMatrix.cheapEqualTo(viewMatrix) && x == fX && y == fY) {
209 return false;
210 }
211 return true;
212 }
213
214 if (this->hasBitmap()) {
215 if (fViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
216 fViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
217 fViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
218 fViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
219 return true;
220 }
221
222 // We can update the positions in the cachedtextblobs without regenerating the whole blob,
223 // but only for integer translations.
224 // This cool bit of math will determine the necessary translation to apply to the already
225 // generated vertex coordinates to move them to the correct position
226 SkScalar transX = viewMatrix.getTranslateX() +
227 viewMatrix.getScaleX() * (x - fX) +
228 viewMatrix.getSkewX() * (y - fY) -
229 fViewMatrix.getTranslateX();
230 SkScalar transY = viewMatrix.getTranslateY() +
231 viewMatrix.getSkewY() * (x - fX) +
232 viewMatrix.getScaleY() * (y - fY) -
233 fViewMatrix.getTranslateY();
234 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY) ) {
235 return true;
236 }
237
238 (*outTransX) = transX;
239 (*outTransY) = transY;
240 } else if (this->hasDistanceField()) {
241 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
242 // distance field being generated, so we have to regenerate in those cases
243 SkScalar newMaxScale = viewMatrix.getMaxScale();
244 SkScalar oldMaxScale = fViewMatrix.getMaxScale();
245 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
246 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
247 return true;
248 }
249
250 (*outTransX) = x - fX;
251 (*outTransY) = y - fY;
252 }
253
joshualittfd5f6c12015-12-10 07:44:50 -0800254 // If we can reuse the blob, then make sure we update the blob's viewmatrix, and x/y
255 // offsets. Note, we offset the vertex bounds right before flushing
256 fViewMatrix = viewMatrix;
257 fX = x;
258 fY = y;
259
260 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
261 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
262 // the blob anyways at flush time, so no need to regenerate explicitly
263 return false;
264}
265
joshualitt323c2eb2016-01-20 06:48:47 -0800266inline GrDrawBatch* GrAtlasTextBlob::createBatch(
267 const Run::SubRunInfo& info,
268 int glyphCount, int run, int subRun,
269 GrColor color, SkScalar transX, SkScalar transY,
270 const SkPaint& skPaint, const SkSurfaceProps& props,
271 const GrDistanceFieldAdjustTable* distanceAdjustTable,
272 GrBatchFontCache* cache) {
joshualitt2e2202e2015-12-10 11:22:08 -0800273 GrMaskFormat format = info.maskFormat();
274 GrColor subRunColor;
275 if (kARGB_GrMaskFormat == format) {
276 uint8_t paintAlpha = skPaint.getAlpha();
277 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha);
278 } else {
279 subRunColor = color;
280 }
281
282 GrAtlasTextBatch* batch;
283 if (info.drawAsDistanceFields()) {
284 SkColor filteredColor;
285 SkColorFilter* colorFilter = skPaint.getColorFilter();
286 if (colorFilter) {
287 filteredColor = colorFilter->filterColor(skPaint.getColor());
288 } else {
289 filteredColor = skPaint.getColor();
290 }
291 bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
292 batch = GrAtlasTextBatch::CreateDistanceField(glyphCount, cache,
293 distanceAdjustTable, filteredColor,
294 info.hasUseLCDText(), useBGR);
295 } else {
296 batch = GrAtlasTextBatch::CreateBitmap(format, glyphCount, cache);
297 }
298 GrAtlasTextBatch::Geometry& geometry = batch->geometry();
299 geometry.fBlob = SkRef(this);
300 geometry.fRun = run;
301 geometry.fSubRun = subRun;
302 geometry.fColor = subRunColor;
303 geometry.fTransX = transX;
304 geometry.fTransY = transY;
305 batch->init();
306
307 return batch;
308}
309
310inline
311void GrAtlasTextBlob::flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
312 int run, GrColor color,
313 SkScalar transX, SkScalar transY,
314 const SkPaint& skPaint, const SkSurfaceProps& props,
315 const GrDistanceFieldAdjustTable* distanceAdjustTable,
316 GrBatchFontCache* cache) {
317 for (int subRun = 0; subRun < fRuns[run].fSubRunInfo.count(); subRun++) {
318 const Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun];
319 int glyphCount = info.glyphCount();
320 if (0 == glyphCount) {
321 continue;
322 }
323
324 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(info, glyphCount, run,
325 subRun, color, transX, transY,
326 skPaint, props,
327 distanceAdjustTable, cache));
328 dc->drawBatch(pipelineBuilder, batch);
329 }
330}
331
332void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrDrawContext* dc,
333 const GrClip& clip, const SkPaint& skPaint,
334 SkScalar transX, SkScalar transY,
335 const SkIRect& clipBounds) {
336 for (int i = 0; i < fBigGlyphs.count(); i++) {
337 GrAtlasTextBlob::BigGlyph& bigGlyph = fBigGlyphs[i];
338 bigGlyph.fVx += transX;
339 bigGlyph.fVy += transY;
340 SkMatrix ctm;
341 ctm.setScale(bigGlyph.fScale, bigGlyph.fScale);
342 ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
343 if (bigGlyph.fApplyVM) {
344 ctm.postConcat(fViewMatrix);
345 }
346
347 GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, bigGlyph.fPath,
348 skPaint, ctm, nullptr, clipBounds, false);
349 }
350}
351
joshualitt0a42e682015-12-10 13:20:58 -0800352void GrAtlasTextBlob::flushRunAsPaths(GrContext* context, GrDrawContext* dc,
joshualitt2e2202e2015-12-10 11:22:08 -0800353 const SkSurfaceProps& props,
354 const SkTextBlobRunIterator& it,
355 const GrClip& clip, const SkPaint& skPaint,
356 SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
357 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
358 SkPaint runPaint = skPaint;
359
360 size_t textLen = it.glyphCount() * sizeof(uint16_t);
361 const SkPoint& offset = it.offset();
362
363 it.applyFontToPaint(&runPaint);
364
365 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
366 return;
367 }
368
369 runPaint.setFlags(GrTextContext::FilterTextFlags(props, runPaint));
370
371 switch (it.positioning()) {
372 case SkTextBlob::kDefault_Positioning:
joshualitt0a42e682015-12-10 13:20:58 -0800373 GrTextUtils::DrawTextAsPath(context, dc, clip, runPaint, viewMatrix,
joshualitt2e2202e2015-12-10 11:22:08 -0800374 (const char *)it.glyphs(),
375 textLen, x + offset.x(), y + offset.y(), clipBounds);
376 break;
377 case SkTextBlob::kHorizontal_Positioning:
joshualitt0a42e682015-12-10 13:20:58 -0800378 GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, runPaint, viewMatrix,
joshualitt2e2202e2015-12-10 11:22:08 -0800379 (const char*)it.glyphs(),
380 textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
381 clipBounds);
382 break;
383 case SkTextBlob::kFull_Positioning:
joshualitt0a42e682015-12-10 13:20:58 -0800384 GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, runPaint, viewMatrix,
joshualitt2e2202e2015-12-10 11:22:08 -0800385 (const char*)it.glyphs(),
386 textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
387 break;
388 }
389}
390
joshualitt0a42e682015-12-10 13:20:58 -0800391void GrAtlasTextBlob::flushCached(GrContext* context,
joshualitt2e2202e2015-12-10 11:22:08 -0800392 GrDrawContext* dc,
joshualitt0a42e682015-12-10 13:20:58 -0800393 const SkTextBlob* blob,
joshualitt2e2202e2015-12-10 11:22:08 -0800394 const SkSurfaceProps& props,
395 const GrDistanceFieldAdjustTable* distanceAdjustTable,
396 const SkPaint& skPaint,
397 const GrPaint& grPaint,
398 SkDrawFilter* drawFilter,
399 const GrClip& clip,
400 const SkMatrix& viewMatrix,
401 const SkIRect& clipBounds,
402 SkScalar x, SkScalar y,
403 SkScalar transX, SkScalar transY) {
404 // We loop through the runs of the blob, flushing each. If any run is too large, then we flush
405 // it as paths
406 GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
407
408 GrColor color = grPaint.getColor();
409
410 SkTextBlobRunIterator it(blob);
411 for (int run = 0; !it.done(); it.next(), run++) {
412 if (fRuns[run].fDrawAsPaths) {
joshualitt0a42e682015-12-10 13:20:58 -0800413 this->flushRunAsPaths(context, dc, props, it, clip, skPaint,
joshualitt2e2202e2015-12-10 11:22:08 -0800414 drawFilter, viewMatrix, clipBounds, x, y);
415 continue;
416 }
joshualitt2e2202e2015-12-10 11:22:08 -0800417 this->flushRun(dc, &pipelineBuilder, run, color,
418 transX, transY, skPaint, props,
419 distanceAdjustTable, context->getBatchFontCache());
420 }
421
422 // Now flush big glyphs
423 this->flushBigGlyphs(context, dc, clip, skPaint, transX, transY, clipBounds);
424}
425
426void GrAtlasTextBlob::flushThrowaway(GrContext* context,
427 GrDrawContext* dc,
428 const SkSurfaceProps& props,
429 const GrDistanceFieldAdjustTable* distanceAdjustTable,
430 const SkPaint& skPaint,
431 const GrPaint& grPaint,
432 const GrClip& clip,
433 const SkIRect& clipBounds) {
434 GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
435
436 GrColor color = grPaint.getColor();
437 for (int run = 0; run < fRunCount; run++) {
438 this->flushRun(dc, &pipelineBuilder, run, color, 0, 0, skPaint, props,
439 distanceAdjustTable, context->getBatchFontCache());
440 }
441
442 // Now flush big glyphs
443 this->flushBigGlyphs(context, dc, clip, skPaint, 0, 0, clipBounds);
444}
445
joshualitt323c2eb2016-01-20 06:48:47 -0800446GrDrawBatch* GrAtlasTextBlob::test_createBatch(
447 int glyphCount, int run, int subRun,
448 GrColor color, SkScalar transX, SkScalar transY,
449 const SkPaint& skPaint, const SkSurfaceProps& props,
450 const GrDistanceFieldAdjustTable* distanceAdjustTable,
451 GrBatchFontCache* cache) {
joshualitt7481e752016-01-22 06:08:48 -0800452 const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun];
453 return this->createBatch(info, glyphCount, run, subRun, color, transX, transY, skPaint,
joshualitt323c2eb2016-01-20 06:48:47 -0800454 props, distanceAdjustTable, cache);
455}
joshualitt2e2202e2015-12-10 11:22:08 -0800456
joshualitt259fbf12015-07-21 11:39:34 -0700457void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800458 SkASSERT_RELEASE(l.fSize == r.fSize);
459 SkASSERT_RELEASE(l.fPool == r.fPool);
joshualitt259fbf12015-07-21 11:39:34 -0700460
joshualitt2f2ee832016-02-10 08:52:24 -0800461 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
462 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
463 SkASSERT_RELEASE(l.fBlurRec.fQuality == r.fBlurRec.fQuality);
joshualitt259fbf12015-07-21 11:39:34 -0700464
joshualitt2f2ee832016-02-10 08:52:24 -0800465 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
466 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
467 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700468
joshualitt2f2ee832016-02-10 08:52:24 -0800469 SkASSERT_RELEASE(l.fBigGlyphs.count() == r.fBigGlyphs.count());
joshualitt259fbf12015-07-21 11:39:34 -0700470 for (int i = 0; i < l.fBigGlyphs.count(); i++) {
471 const BigGlyph& lBigGlyph = l.fBigGlyphs[i];
472 const BigGlyph& rBigGlyph = r.fBigGlyphs[i];
473
joshualitt2f2ee832016-02-10 08:52:24 -0800474 SkASSERT_RELEASE(lBigGlyph.fPath == rBigGlyph.fPath);
joshualitt259fbf12015-07-21 11:39:34 -0700475 // We can't assert that these have the same translations
476 }
477
joshualitt2f2ee832016-02-10 08:52:24 -0800478 SkASSERT_RELEASE(l.fKey == r.fKey);
479 SkASSERT_RELEASE(l.fViewMatrix.cheapEqualTo(r.fViewMatrix));
480 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
481 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
482 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
483 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700484
joshualitt2f2ee832016-02-10 08:52:24 -0800485 SkASSERT_RELEASE(l.fRunCount == r.fRunCount);
joshualitt259fbf12015-07-21 11:39:34 -0700486 for (int i = 0; i < l.fRunCount; i++) {
487 const Run& lRun = l.fRuns[i];
488 const Run& rRun = r.fRuns[i];
489
joshualitt259fbf12015-07-21 11:39:34 -0700490 if (lRun.fTypeface.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800491 SkASSERT_RELEASE(rRun.fTypeface.get());
492 SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface, rRun.fTypeface));
joshualitt259fbf12015-07-21 11:39:34 -0700493 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800494 SkASSERT_RELEASE(!rRun.fTypeface.get());
joshualitt259fbf12015-07-21 11:39:34 -0700495 }
496
joshualitt259fbf12015-07-21 11:39:34 -0700497
joshualitt2f2ee832016-02-10 08:52:24 -0800498 SkASSERT_RELEASE(lRun.fDescriptor.getDesc());
499 SkASSERT_RELEASE(rRun.fDescriptor.getDesc());
500 SkASSERT_RELEASE(lRun.fDescriptor.getDesc()->equals(*rRun.fDescriptor.getDesc()));
joshualitt259fbf12015-07-21 11:39:34 -0700501
502 if (lRun.fOverrideDescriptor.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800503 SkASSERT_RELEASE(lRun.fOverrideDescriptor->getDesc());
504 SkASSERT_RELEASE(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());
505 SkASSERT_RELEASE(lRun.fOverrideDescriptor->getDesc()->equals(
joshualitt259fbf12015-07-21 11:39:34 -0700506 *rRun.fOverrideDescriptor->getDesc()));
507 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800508 SkASSERT_RELEASE(!rRun.fOverrideDescriptor.get());
joshualitt259fbf12015-07-21 11:39:34 -0700509 }
510
511 // color can be changed
512 //SkASSERT(lRun.fColor == rRun.fColor);
joshualitt2f2ee832016-02-10 08:52:24 -0800513 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
514 SkASSERT_RELEASE(lRun.fDrawAsPaths == rRun.fDrawAsPaths);
joshualitt259fbf12015-07-21 11:39:34 -0700515
joshualitt2f2ee832016-02-10 08:52:24 -0800516 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
joshualitt259fbf12015-07-21 11:39:34 -0700517 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
518 const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j];
519 const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j];
520
joshualitt2f2ee832016-02-10 08:52:24 -0800521 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
522 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700523
joshualitt2f2ee832016-02-10 08:52:24 -0800524 if (lSubRun.strike()) {
525 SkASSERT_RELEASE(rSubRun.strike());
526 SkASSERT_RELEASE(GrBatchTextStrike::GetKey(*lSubRun.strike()) ==
527 GrBatchTextStrike::GetKey(*rSubRun.strike()));
528
529 } else {
530 SkASSERT_RELEASE(!rSubRun.strike());
531 }
532
533 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
534 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
535 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
536 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
537 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
538 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
539 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
joshualitt259fbf12015-07-21 11:39:34 -0700540 }
541 }
542}