blob: 118b0b0a02e2c88d9f00be47bb42c098ea97b89a [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkColorFilter.h"
9#include "include/gpu/GrContext.h"
10#include "src/core/SkMaskFilterBase.h"
11#include "src/core/SkPaintPriv.h"
12#include "src/gpu/GrBlurUtils.h"
13#include "src/gpu/GrClip.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrStyle.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040015#include "src/gpu/geometry/GrShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/ops/GrAtlasTextOp.h"
17#include "src/gpu/text/GrTextBlob.h"
18#include "src/gpu/text/GrTextTarget.h"
Ben Wagner75d6db72018-09-20 14:39:39 -040019
Mike Klein79aea6a2018-06-11 10:45:26 -040020#include <new>
joshualitt2e2202e2015-12-10 11:22:08 -080021
Ben Wagner75d6db72018-09-20 14:39:39 -040022template <size_t N> static size_t sk_align(size_t s) {
23 return ((s + (N-1)) / N) * N;
24}
25
Herb Derbya00da612019-03-04 17:10:01 -050026sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount,
Herb Derby1b8dcd12019-11-15 15:21:15 -050027 bool forceWForDistanceFields,
Herb Derbya00da612019-03-04 17:10:01 -050028 GrColor color,
29 GrStrikeCache* strikeCache) {
Herb Derby86240592018-05-24 16:12:31 -040030 // We allocate size for the GrTextBlob itself, plus size for the vertices array,
joshualitt92303772016-02-10 11:55:52 -080031 // and size for the glyphIds array.
32 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
Ben Wagner75d6db72018-09-20 14:39:39 -040033
Herb Derbyf7d5d742018-11-16 13:24:32 -050034 size_t blobStart = 0;
Herb Derby1b8dcd12019-11-15 15:21:15 -050035 size_t vertex = sk_align<alignof(char)> (blobStart + sizeof(GrTextBlob) * 1);
36 size_t glyphs = sk_align<alignof(GrGlyph*)> (vertex + sizeof(char) * verticesCount);
37 size_t size = (glyphs + sizeof(GrGlyph*) * glyphCount);
joshualitt92303772016-02-10 11:55:52 -080038
Herb Derbyb12175f2018-05-23 16:38:09 -040039 void* allocation = ::operator new (size);
40
joshualitt92303772016-02-10 11:55:52 -080041 if (CACHE_SANITY_CHECK) {
42 sk_bzero(allocation, size);
43 }
44
Herb Derby1b8dcd12019-11-15 15:21:15 -050045 sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{strikeCache, color, forceWForDistanceFields}};
Herb Derbyf7d5d742018-11-16 13:24:32 -050046 blob->fSize = size;
joshualitt92303772016-02-10 11:55:52 -080047
48 // setup offsets for vertices / glyphs
Herb Derbyf7d5d742018-11-16 13:24:32 -050049 blob->fVertices = SkTAddOffset<char>(blob.get(), vertex);
Herb Derby1b8dcd12019-11-15 15:21:15 -050050 blob->fGlyphs = SkTAddOffset<GrGlyph*>(blob.get(), glyphs);
joshualitt92303772016-02-10 11:55:52 -080051
Herb Derbyf7d5d742018-11-16 13:24:32 -050052 return blob;
joshualitt92303772016-02-10 11:55:52 -080053}
54
Herb Derby0edb2142018-10-16 17:04:11 -040055bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosition,
56 const SkMaskFilterBase::BlurRec& blurRec,
57 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
joshualittfd5f6c12015-12-10 07:44:50 -080058 // If we have LCD text then our canonical color will be set to transparent, in this case we have
59 // to regenerate the blob on any color change
60 // We use the grPaint to get any color filter effects
61 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
Mike Reedec7278e2019-02-01 14:00:34 -050062 fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) {
joshualittfd5f6c12015-12-10 07:44:50 -080063 return true;
64 }
65
joshualitt8e0ef292016-02-19 14:13:03 -080066 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
joshualittfd5f6c12015-12-10 07:44:50 -080067 return true;
68 }
69
Brian Salomon5c6ac642017-12-19 11:09:32 -050070 /** This could be relaxed for blobs with only distance field glyphs. */
joshualitt8e0ef292016-02-19 14:13:03 -080071 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
joshualittfd5f6c12015-12-10 07:44:50 -080072 return true;
73 }
74
75 // We only cache one masked version
76 if (fKey.fHasBlur &&
Mike Reed1be1f8d2018-03-14 13:01:17 -040077 (fBlurRec.fSigma != blurRec.fSigma || fBlurRec.fStyle != blurRec.fStyle)) {
joshualittfd5f6c12015-12-10 07:44:50 -080078 return true;
79 }
80
81 // Similarly, we only cache one version for each style
82 if (fKey.fStyle != SkPaint::kFill_Style &&
Herb Derbybc6f9c92018-08-08 13:58:45 -040083 (fStrokeInfo.fFrameWidth != paint.getStrokeWidth() ||
84 fStrokeInfo.fMiterLimit != paint.getStrokeMiter() ||
85 fStrokeInfo.fJoin != paint.getStrokeJoin())) {
joshualittfd5f6c12015-12-10 07:44:50 -080086 return true;
87 }
88
89 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
90 // for mixed blobs if this becomes an issue.
91 if (this->hasBitmap() && this->hasDistanceField()) {
92 // Identical viewmatrices and we can reuse in all cases
joshualitt8e0ef292016-02-19 14:13:03 -080093 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
joshualittfd5f6c12015-12-10 07:44:50 -080094 return false;
95 }
96 return true;
97 }
98
99 if (this->hasBitmap()) {
joshualitt8e0ef292016-02-19 14:13:03 -0800100 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
101 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
102 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
103 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800104 return true;
105 }
106
Herb Derby9830fc42019-09-12 10:58:26 -0400107 // TODO(herb): this is not needed for full pixel glyph choice, but is needed to adjust
108 // the quads properly. Devise a system that regenerates the quads from original data
109 // using the transform to allow this to be used in general.
110
111 // We can update the positions in the text blob without regenerating the whole
112 // blob, but only for integer translations.
113 // This cool bit of math will determine the necessary translation to apply to the
114 // already generated vertex coordinates to move them to the correct position.
115 // Figure out the translation in view space given a translation in source space.
116 SkScalar transX = viewMatrix.getTranslateX() +
117 viewMatrix.getScaleX() * (x - fInitialX) +
118 viewMatrix.getSkewX() * (y - fInitialY) -
119 fInitialViewMatrix.getTranslateX();
120 SkScalar transY = viewMatrix.getTranslateY() +
121 viewMatrix.getSkewY() * (x - fInitialX) +
122 viewMatrix.getScaleY() * (y - fInitialY) -
123 fInitialViewMatrix.getTranslateY();
124 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
125 return true;
joshualittfd5f6c12015-12-10 07:44:50 -0800126 }
joshualittfd5f6c12015-12-10 07:44:50 -0800127 } else if (this->hasDistanceField()) {
128 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
129 // distance field being generated, so we have to regenerate in those cases
130 SkScalar newMaxScale = viewMatrix.getMaxScale();
joshualitt8e0ef292016-02-19 14:13:03 -0800131 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
joshualittfd5f6c12015-12-10 07:44:50 -0800132 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
133 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
134 return true;
135 }
joshualittfd5f6c12015-12-10 07:44:50 -0800136 }
137
joshualittfd5f6c12015-12-10 07:44:50 -0800138 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
139 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
140 // the blob anyways at flush time, so no need to regenerate explicitly
141 return false;
142}
143
Herb Derby86240592018-05-24 16:12:31 -0400144inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(
Herb Derbya6c4a302019-11-21 11:58:10 -0500145 SubRun& info, int glyphCount,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400146 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
Brian Osmancf860852018-10-31 14:04:39 -0400147 const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps& props,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400148 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextTarget* target) {
joshualitt2e2202e2015-12-10 11:22:08 -0800149 GrMaskFormat format = info.maskFormat();
joshualitt2e2202e2015-12-10 11:22:08 -0800150
Brian Salomon44acb5b2017-07-18 19:59:24 -0400151 GrPaint grPaint;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400152 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
Brian Salomonf8334782017-01-03 09:42:58 -0500153 std::unique_ptr<GrAtlasTextOp> op;
joshualitt2e2202e2015-12-10 11:22:08 -0800154 if (info.drawAsDistanceFields()) {
Brian Osman34ec3742018-07-03 10:40:57 -0400155 // TODO: Can we be even smarter based on the dest transfer function?
Brian Salomon44acb5b2017-07-18 19:59:24 -0400156 op = GrAtlasTextOp::MakeDistanceField(
Robert Phillips7c525e62018-06-12 10:11:12 -0400157 target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable,
Brian Salomon4bc0c1f2019-09-30 15:12:27 -0400158 target->colorInfo().isLinearlyBlended(), SkPaintPriv::ComputeLuminanceColor(paint),
Ben Wagner4c329562018-04-18 16:04:46 -0400159 props, info.isAntiAliased(), info.hasUseLCDText());
joshualitt2e2202e2015-12-10 11:22:08 -0800160 } else {
Robert Phillips7c525e62018-06-12 10:11:12 -0400161 op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount,
Jim Van Verthb515ae72018-05-23 16:44:55 -0400162 info.needsTransform());
joshualitt2e2202e2015-12-10 11:22:08 -0800163 }
Brian Salomon09d994e2016-12-21 11:14:46 -0500164 GrAtlasTextOp::Geometry& geometry = op->geometry();
joshualitt8e0ef292016-02-19 14:13:03 -0800165 geometry.fViewMatrix = viewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400166 geometry.fClipRect = clipRect;
joshualitt2e2202e2015-12-10 11:22:08 -0800167 geometry.fBlob = SkRef(this);
Herb Derby660c2ff2019-11-14 18:22:41 -0500168 geometry.fSubRunPtr = &info;
Brian Osmancf860852018-10-31 14:04:39 -0400169 geometry.fColor = info.maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE : filteredColor;
joshualitt8e0ef292016-02-19 14:13:03 -0800170 geometry.fX = x;
171 geometry.fY = y;
Brian Salomon09d994e2016-12-21 11:14:46 -0500172 op->init();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400173 return op;
joshualitt2e2202e2015-12-10 11:22:08 -0800174}
175
joshualitt8e0ef292016-02-19 14:13:03 -0800176static void calculate_translation(bool applyVM,
177 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
178 const SkMatrix& currentViewMatrix, SkScalar currentX,
179 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
180 if (applyVM) {
181 *transX = newViewMatrix.getTranslateX() +
182 newViewMatrix.getScaleX() * (newX - currentX) +
183 newViewMatrix.getSkewX() * (newY - currentY) -
184 currentViewMatrix.getTranslateX();
185
186 *transY = newViewMatrix.getTranslateY() +
187 newViewMatrix.getSkewY() * (newX - currentX) +
188 newViewMatrix.getScaleY() * (newY - currentY) -
189 currentViewMatrix.getTranslateY();
190 } else {
191 *transX = newX - currentX;
192 *transY = newY - currentY;
193 }
194}
195
Herb Derbyc1b482c2018-08-09 15:02:27 -0400196void GrTextBlob::flush(GrTextTarget* target, const SkSurfaceProps& props,
197 const GrDistanceFieldAdjustTable* distanceAdjustTable,
Brian Osmancf860852018-10-31 14:04:39 -0400198 const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip,
Robert Phillipse4643cc2018-08-14 13:01:29 -0400199 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
Jim Van Verth54d9c882018-02-08 16:14:48 -0500200
Herb Derby1b8dcd12019-11-15 15:21:15 -0500201 for (auto& subRun : fSubRuns) {
202 if (subRun.drawAsPaths()) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400203 SkPaint runPaint{paint};
Herb Derby1b8dcd12019-11-15 15:21:15 -0500204 runPaint.setAntiAlias(subRun.isAntiAliased());
205 // If there are shaders, blurs or styles, the path must be scaled into source
206 // space independently of the CTM. This allows the CTM to be correct for the
207 // different effects.
208 GrStyle style(runPaint);
Herb Derby9f491482018-08-08 11:53:00 -0400209
Herb Derby1b8dcd12019-11-15 15:21:15 -0500210 bool scalePath = runPaint.getShader()
211 || style.applies()
212 || runPaint.getMaskFilter();
Robert Phillips137ca522018-08-15 10:14:33 -0400213
Herb Derby1b8dcd12019-11-15 15:21:15 -0500214 // The origin for the blob may have changed, so figure out the delta.
215 SkVector originShift = SkPoint{x, y} - SkPoint{fInitialX, fInitialY};
216
217 for (const auto& pathGlyph : subRun.fPaths) {
218 SkMatrix ctm{viewMatrix};
219 SkMatrix pathMatrix = SkMatrix::MakeScale(subRun.fStrikeSpec.strikeToSourceRatio());
220 // Shift the original glyph location in source space to the position of the new
221 // blob.
222 pathMatrix.postTranslate(originShift.x() + pathGlyph.fOrigin.x(),
223 originShift.y() + pathGlyph.fOrigin.y());
Herb Derbydac1ed52018-09-12 17:04:21 -0400224
225 // TmpPath must be in the same scope as GrShape shape below.
Robert Phillips137ca522018-08-15 10:14:33 -0400226 SkTLazy<SkPath> tmpPath;
Herb Derby1b8dcd12019-11-15 15:21:15 -0500227 const SkPath* path = &pathGlyph.fPath;
Herb Derby2984d262019-11-20 14:40:39 -0500228 if (!scalePath) {
229 // Scale can be applied to CTM -- no effects.
Herb Derby2984d262019-11-20 14:40:39 -0500230 ctm.preConcat(pathMatrix);
Robert Phillipsd20d2612018-08-28 10:09:01 -0400231 } else {
Herb Derby2984d262019-11-20 14:40:39 -0500232 // Scale the outline into source space.
Herb Derbydac1ed52018-09-12 17:04:21 -0400233
Herb Derby2984d262019-11-20 14:40:39 -0500234 // Transform the path form the normalized outline to source space. This
235 // way the CTM will remain the same so it can be used by the effects.
236 SkPath* sourceOutline = tmpPath.init();
237 path->transform(pathMatrix, sourceOutline);
238 sourceOutline->setIsVolatile(true);
239 path = sourceOutline;
Robert Phillips137ca522018-08-15 10:14:33 -0400240 }
241
Robert Phillips46a13382018-08-23 13:53:01 -0400242 // TODO: we are losing the mutability of the path here
243 GrShape shape(*path, paint);
Herb Derbydac1ed52018-09-12 17:04:21 -0400244 target->drawShape(clip, runPaint, ctm, shape);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500245 }
Herb Derby1b8dcd12019-11-15 15:21:15 -0500246 } else {
247 int glyphCount = subRun.glyphCount();
Jim Van Verth54d9c882018-02-08 16:14:48 -0500248 if (0 == glyphCount) {
249 continue;
250 }
251
252 bool skipClip = false;
253 bool submitOp = true;
254 SkIRect clipRect = SkIRect::MakeEmpty();
255 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
256 SkRRect clipRRect;
257 GrAA aa;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400258 // We can clip geometrically if we're not using SDFs or transformed glyphs,
Jim Van Verth54d9c882018-02-08 16:14:48 -0500259 // and we have an axis-aligned rectangular non-AA clip
Herb Derby1b8dcd12019-11-15 15:21:15 -0500260 if (!subRun.drawAsDistanceFields() && !subRun.needsTransform() &&
Jim Van Verthcf838c72018-03-05 14:40:36 -0500261 clip.isRRect(rtBounds, &clipRRect, &aa) &&
Jim Van Verth54d9c882018-02-08 16:14:48 -0500262 clipRRect.isRect() && GrAA::kNo == aa) {
263 skipClip = true;
264 // We only need to do clipping work if the subrun isn't contained by the clip
265 SkRect subRunBounds;
Herb Derby1b8dcd12019-11-15 15:21:15 -0500266 this->computeSubRunBounds(&subRunBounds, subRun, viewMatrix, x, y, false);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500267 if (!clipRRect.getBounds().contains(subRunBounds)) {
268 // If the subrun is completely outside, don't add an op for it
269 if (!clipRRect.getBounds().intersects(subRunBounds)) {
270 submitOp = false;
271 }
272 else {
273 clipRRect.getBounds().round(&clipRect);
274 }
275 }
276 }
277
278 if (submitOp) {
Herb Derby1b8dcd12019-11-15 15:21:15 -0500279 auto op = this->makeOp(subRun, glyphCount, viewMatrix, x, y,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400280 clipRect, paint, filteredColor, props, distanceAdjustTable,
Robert Phillips5a66efb2018-03-07 15:13:18 -0500281 target);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500282 if (op) {
283 if (skipClip) {
284 target->addDrawOp(GrNoClip(), std::move(op));
285 }
286 else {
287 target->addDrawOp(clip, std::move(op));
288 }
289 }
290 }
291 }
Jim Van Verth89737de2018-02-06 21:30:20 +0000292 }
Jim Van Verth89737de2018-02-06 21:30:20 +0000293}
294
Herb Derby86240592018-05-24 16:12:31 -0400295std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(
Herb Derbya6c4a302019-11-21 11:58:10 -0500296 int glyphCount, const SkMatrix& viewMatrix,
Brian Osmancf860852018-10-31 14:04:39 -0400297 SkScalar x, SkScalar y, const SkPaint& paint, const SkPMColor4f& filteredColor,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400298 const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400299 GrTextTarget* target) {
Herb Derby1b8dcd12019-11-15 15:21:15 -0500300 GrTextBlob::SubRun& info = fSubRuns[0];
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400301 SkIRect emptyRect = SkIRect::MakeEmpty();
Herb Derbya6c4a302019-11-21 11:58:10 -0500302 return this->makeOp(info, glyphCount, viewMatrix, x, y, emptyRect,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400303 paint, filteredColor, props, distanceAdjustTable, target);
joshualitt323c2eb2016-01-20 06:48:47 -0800304}
joshualitt2e2202e2015-12-10 11:22:08 -0800305
Herb Derby86240592018-05-24 16:12:31 -0400306void GrTextBlob::AssertEqual(const GrTextBlob& l, const GrTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800307 SkASSERT_RELEASE(l.fSize == r.fSize);
joshualitt259fbf12015-07-21 11:39:34 -0700308
joshualitt2f2ee832016-02-10 08:52:24 -0800309 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
310 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
joshualitt259fbf12015-07-21 11:39:34 -0700311
joshualitt2f2ee832016-02-10 08:52:24 -0800312 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
313 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
314 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700315
joshualitt2f2ee832016-02-10 08:52:24 -0800316 SkASSERT_RELEASE(l.fKey == r.fKey);
joshualitt2f2ee832016-02-10 08:52:24 -0800317 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
318 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
319 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
320 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700321
Herb Derby1b8dcd12019-11-15 15:21:15 -0500322 for(auto t : SkMakeZip(l.fSubRuns, r.fSubRuns)) {
323 const SubRun& lSubRun = std::get<0>(t);
324 const SubRun& rSubRun = std::get<1>(t);
325 SkASSERT(lSubRun.drawAsPaths() == rSubRun.drawAsPaths());
326 if (!lSubRun.drawAsPaths()) {
joshualitt259fbf12015-07-21 11:39:34 -0700327
joshualitt2f2ee832016-02-10 08:52:24 -0800328 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
329 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700330
joshualitt2f2ee832016-02-10 08:52:24 -0800331 if (lSubRun.strike()) {
332 SkASSERT_RELEASE(rSubRun.strike());
Robert Phillipscaf1ebb2018-03-01 14:28:44 -0500333 SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) ==
334 GrTextStrike::GetKey(*rSubRun.strike()));
joshualitt2f2ee832016-02-10 08:52:24 -0800335
336 } else {
337 SkASSERT_RELEASE(!rSubRun.strike());
338 }
339
340 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
joshualitt2f2ee832016-02-10 08:52:24 -0800341 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
joshualitt2f2ee832016-02-10 08:52:24 -0800342 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
343 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
344 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
Herb Derby1b8dcd12019-11-15 15:21:15 -0500345 } else {
346 SkASSERT_RELEASE(lSubRun.fPaths.size() == rSubRun.fPaths.size());
347 for(auto p : SkMakeZip(lSubRun.fPaths, rSubRun.fPaths)) {
348 const PathGlyph& lPath = std::get<0>(p);
349 const PathGlyph& rPath = std::get<1>(p);
350 SkASSERT_RELEASE(lPath.fPath == rPath.fPath);
351 // We can't assert that these have the same translations
352 }
Jim Van Verth54d9c882018-02-08 16:14:48 -0500353 }
joshualitt259fbf12015-07-21 11:39:34 -0700354 }
355}
joshualitt8e0ef292016-02-19 14:13:03 -0800356
Herb Derby69ff8952018-11-12 11:39:12 -0500357void GrTextBlob::SubRun::computeTranslation(const SkMatrix& viewMatrix,
358 SkScalar x, SkScalar y, SkScalar* transX,
359 SkScalar* transY) {
Herb Derby5f7b0142018-12-14 16:47:45 -0500360 // Don't use the matrix to translate on distance field for fallback subruns.
Herb Derbyd667e612019-11-18 18:58:20 -0500361 calculate_translation(!this->drawAsDistanceFields() && !this->needsTransform(), viewMatrix,
Herb Derby5f7b0142018-12-14 16:47:45 -0500362 x, y, fCurrentViewMatrix, fX, fY, transX, transY);
joshualitt8e0ef292016-02-19 14:13:03 -0800363 fCurrentViewMatrix = viewMatrix;
364 fX = x;
365 fY = y;
366}