blob: 6705be87e35fa2fe0500e91d786c0cd3445a4cc0 [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,
27 int runCount,
28 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;
35 size_t vertex = sk_align<alignof(char)> (blobStart + sizeof(GrTextBlob) * 1);
Ben Wagner75d6db72018-09-20 14:39:39 -040036 size_t glyphs = sk_align<alignof(GrGlyph*)> (vertex + sizeof(char) * verticesCount);
37 size_t runs = sk_align<alignof(GrTextBlob::Run)>(glyphs + sizeof(GrGlyph*) * glyphCount);
38 size_t size = (runs + sizeof(GrTextBlob::Run) * runCount);
joshualitt92303772016-02-10 11:55:52 -080039
Herb Derbyb12175f2018-05-23 16:38:09 -040040 void* allocation = ::operator new (size);
41
joshualitt92303772016-02-10 11:55:52 -080042 if (CACHE_SANITY_CHECK) {
43 sk_bzero(allocation, size);
44 }
45
Herb Derbya00da612019-03-04 17:10:01 -050046 sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{strikeCache}};
Herb Derbyf7d5d742018-11-16 13:24:32 -050047 blob->fSize = size;
joshualitt92303772016-02-10 11:55:52 -080048
49 // setup offsets for vertices / glyphs
Herb Derbyf7d5d742018-11-16 13:24:32 -050050 blob->fVertices = SkTAddOffset<char>(blob.get(), vertex);
51 blob->fGlyphs = SkTAddOffset<GrGlyph*>(blob.get(), glyphs);
52 blob->fRuns = SkTAddOffset<GrTextBlob::Run>(blob.get(), runs);
joshualitt92303772016-02-10 11:55:52 -080053
54 // Initialize runs
55 for (int i = 0; i < runCount; i++) {
Herb Derby5424a5e2018-11-14 12:04:38 -050056 new (&blob->fRuns[i]) GrTextBlob::Run{blob.get(), color};
joshualitt92303772016-02-10 11:55:52 -080057 }
Herb Derbyf7d5d742018-11-16 13:24:32 -050058 blob->fRunCountLimit = runCount;
59 return blob;
joshualitt92303772016-02-10 11:55:52 -080060}
61
Herb Derby36a54c12019-06-06 10:50:56 -040062void GrTextBlob::Run::setupFont(const SkStrikeSpec& strikeSpec) {
Herb Derbye7efd082019-05-28 11:30:33 -040063
64 if (fFallbackStrikeSpec != nullptr) {
65 *fFallbackStrikeSpec = strikeSpec;
66 } else {
67 fStrikeSpec = strikeSpec;
68 }
Herbert Derby86dbae92019-01-03 13:10:59 -050069}
70
Herb Derby2bb343c2018-11-08 15:03:48 -050071void GrTextBlob::Run::appendPathGlyph(const SkPath& path, SkPoint position,
Jim Van Verth54d9c882018-02-08 16:14:48 -050072 SkScalar scale, bool preTransformed) {
Herb Derby2bb343c2018-11-08 15:03:48 -050073 fPathGlyphs.push_back(PathGlyph(path, position.x(), position.y(), scale, preTransformed));
joshualitta06e6ab2015-12-10 08:54:41 -080074}
75
Herb Derby0edb2142018-10-16 17:04:11 -040076bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosition,
77 const SkMaskFilterBase::BlurRec& blurRec,
78 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
joshualittfd5f6c12015-12-10 07:44:50 -080079 // If we have LCD text then our canonical color will be set to transparent, in this case we have
80 // to regenerate the blob on any color change
81 // We use the grPaint to get any color filter effects
82 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
Mike Reedec7278e2019-02-01 14:00:34 -050083 fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) {
joshualittfd5f6c12015-12-10 07:44:50 -080084 return true;
85 }
86
joshualitt8e0ef292016-02-19 14:13:03 -080087 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
joshualittfd5f6c12015-12-10 07:44:50 -080088 return true;
89 }
90
Brian Salomon5c6ac642017-12-19 11:09:32 -050091 /** This could be relaxed for blobs with only distance field glyphs. */
joshualitt8e0ef292016-02-19 14:13:03 -080092 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
joshualittfd5f6c12015-12-10 07:44:50 -080093 return true;
94 }
95
96 // We only cache one masked version
97 if (fKey.fHasBlur &&
Mike Reed1be1f8d2018-03-14 13:01:17 -040098 (fBlurRec.fSigma != blurRec.fSigma || fBlurRec.fStyle != blurRec.fStyle)) {
joshualittfd5f6c12015-12-10 07:44:50 -080099 return true;
100 }
101
102 // Similarly, we only cache one version for each style
103 if (fKey.fStyle != SkPaint::kFill_Style &&
Herb Derbybc6f9c92018-08-08 13:58:45 -0400104 (fStrokeInfo.fFrameWidth != paint.getStrokeWidth() ||
105 fStrokeInfo.fMiterLimit != paint.getStrokeMiter() ||
106 fStrokeInfo.fJoin != paint.getStrokeJoin())) {
joshualittfd5f6c12015-12-10 07:44:50 -0800107 return true;
108 }
109
110 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
111 // for mixed blobs if this becomes an issue.
112 if (this->hasBitmap() && this->hasDistanceField()) {
113 // Identical viewmatrices and we can reuse in all cases
joshualitt8e0ef292016-02-19 14:13:03 -0800114 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
joshualittfd5f6c12015-12-10 07:44:50 -0800115 return false;
116 }
117 return true;
118 }
119
120 if (this->hasBitmap()) {
joshualitt8e0ef292016-02-19 14:13:03 -0800121 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
122 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
123 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
124 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800125 return true;
126 }
127
Herb Derby9830fc42019-09-12 10:58:26 -0400128 // TODO(herb): this is not needed for full pixel glyph choice, but is needed to adjust
129 // the quads properly. Devise a system that regenerates the quads from original data
130 // using the transform to allow this to be used in general.
131
132 // We can update the positions in the text blob without regenerating the whole
133 // blob, but only for integer translations.
134 // This cool bit of math will determine the necessary translation to apply to the
135 // already generated vertex coordinates to move them to the correct position.
136 // Figure out the translation in view space given a translation in source space.
137 SkScalar transX = viewMatrix.getTranslateX() +
138 viewMatrix.getScaleX() * (x - fInitialX) +
139 viewMatrix.getSkewX() * (y - fInitialY) -
140 fInitialViewMatrix.getTranslateX();
141 SkScalar transY = viewMatrix.getTranslateY() +
142 viewMatrix.getSkewY() * (x - fInitialX) +
143 viewMatrix.getScaleY() * (y - fInitialY) -
144 fInitialViewMatrix.getTranslateY();
145 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
146 return true;
joshualittfd5f6c12015-12-10 07:44:50 -0800147 }
joshualittfd5f6c12015-12-10 07:44:50 -0800148 } else if (this->hasDistanceField()) {
149 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
150 // distance field being generated, so we have to regenerate in those cases
151 SkScalar newMaxScale = viewMatrix.getMaxScale();
joshualitt8e0ef292016-02-19 14:13:03 -0800152 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
joshualittfd5f6c12015-12-10 07:44:50 -0800153 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
154 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
155 return true;
156 }
joshualittfd5f6c12015-12-10 07:44:50 -0800157 }
158
joshualittfd5f6c12015-12-10 07:44:50 -0800159 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
160 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
161 // the blob anyways at flush time, so no need to regenerate explicitly
162 return false;
163}
164
Herb Derby86240592018-05-24 16:12:31 -0400165inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(
Herb Derby69ff8952018-11-12 11:39:12 -0500166 const SubRun& info, int glyphCount, uint16_t run, uint16_t subRun,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400167 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
Brian Osmancf860852018-10-31 14:04:39 -0400168 const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps& props,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400169 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextTarget* target) {
joshualitt2e2202e2015-12-10 11:22:08 -0800170 GrMaskFormat format = info.maskFormat();
joshualitt2e2202e2015-12-10 11:22:08 -0800171
Brian Salomon44acb5b2017-07-18 19:59:24 -0400172 GrPaint grPaint;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400173 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
Brian Salomonf8334782017-01-03 09:42:58 -0500174 std::unique_ptr<GrAtlasTextOp> op;
joshualitt2e2202e2015-12-10 11:22:08 -0800175 if (info.drawAsDistanceFields()) {
Brian Osman34ec3742018-07-03 10:40:57 -0400176 // TODO: Can we be even smarter based on the dest transfer function?
Brian Salomon44acb5b2017-07-18 19:59:24 -0400177 op = GrAtlasTextOp::MakeDistanceField(
Robert Phillips7c525e62018-06-12 10:11:12 -0400178 target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable,
Mike Reedec7278e2019-02-01 14:00:34 -0500179 target->colorSpaceInfo().isLinearlyBlended(),
180 SkPaintPriv::ComputeLuminanceColor(paint),
Ben Wagner4c329562018-04-18 16:04:46 -0400181 props, info.isAntiAliased(), info.hasUseLCDText());
joshualitt2e2202e2015-12-10 11:22:08 -0800182 } else {
Robert Phillips7c525e62018-06-12 10:11:12 -0400183 op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount,
Jim Van Verthb515ae72018-05-23 16:44:55 -0400184 info.needsTransform());
joshualitt2e2202e2015-12-10 11:22:08 -0800185 }
Brian Salomon09d994e2016-12-21 11:14:46 -0500186 GrAtlasTextOp::Geometry& geometry = op->geometry();
joshualitt8e0ef292016-02-19 14:13:03 -0800187 geometry.fViewMatrix = viewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400188 geometry.fClipRect = clipRect;
joshualitt2e2202e2015-12-10 11:22:08 -0800189 geometry.fBlob = SkRef(this);
190 geometry.fRun = run;
191 geometry.fSubRun = subRun;
Brian Osmancf860852018-10-31 14:04:39 -0400192 geometry.fColor = info.maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE : filteredColor;
joshualitt8e0ef292016-02-19 14:13:03 -0800193 geometry.fX = x;
194 geometry.fY = y;
Brian Salomon09d994e2016-12-21 11:14:46 -0500195 op->init();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400196 return op;
joshualitt2e2202e2015-12-10 11:22:08 -0800197}
198
joshualitt8e0ef292016-02-19 14:13:03 -0800199static void calculate_translation(bool applyVM,
200 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
201 const SkMatrix& currentViewMatrix, SkScalar currentX,
202 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
203 if (applyVM) {
204 *transX = newViewMatrix.getTranslateX() +
205 newViewMatrix.getScaleX() * (newX - currentX) +
206 newViewMatrix.getSkewX() * (newY - currentY) -
207 currentViewMatrix.getTranslateX();
208
209 *transY = newViewMatrix.getTranslateY() +
210 newViewMatrix.getSkewY() * (newX - currentX) +
211 newViewMatrix.getScaleY() * (newY - currentY) -
212 currentViewMatrix.getTranslateY();
213 } else {
214 *transX = newX - currentX;
215 *transY = newY - currentY;
216 }
217}
218
Herb Derbyc1b482c2018-08-09 15:02:27 -0400219void GrTextBlob::flush(GrTextTarget* target, const SkSurfaceProps& props,
220 const GrDistanceFieldAdjustTable* distanceAdjustTable,
Brian Osmancf860852018-10-31 14:04:39 -0400221 const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip,
Robert Phillipse4643cc2018-08-14 13:01:29 -0400222 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
Jim Van Verth54d9c882018-02-08 16:14:48 -0500223
Herb Derby86240592018-05-24 16:12:31 -0400224 // GrTextBlob::makeOp only takes uint16_t values for run and subRun indices.
Jim Van Verth54d9c882018-02-08 16:14:48 -0500225 // Encountering something larger than this is highly unlikely, so we'll just not draw it.
Herb Derby2bb343c2018-11-08 15:03:48 -0500226 int lastRun = SkTMin(fRunCountLimit, (1 << 16)) - 1;
Herb Derbydac1ed52018-09-12 17:04:21 -0400227 // For each run in the GrTextBlob we're going to churn through all the glyphs.
228 // Each run is broken into a path part and a Mask / DFT / ARGB part.
Jim Van Verth54d9c882018-02-08 16:14:48 -0500229 for (int runIndex = 0; runIndex <= lastRun; runIndex++) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400230
Jim Van Verth54d9c882018-02-08 16:14:48 -0500231 Run& run = fRuns[runIndex];
232
233 // first flush any path glyphs
234 if (run.fPathGlyphs.count()) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400235 SkPaint runPaint{paint};
Mike Reed48b958b2018-12-03 13:09:02 -0500236 runPaint.setAntiAlias(run.fAntiAlias);
Herb Derby9f491482018-08-08 11:53:00 -0400237
Jim Van Verth54d9c882018-02-08 16:14:48 -0500238 for (int i = 0; i < run.fPathGlyphs.count(); i++) {
Herb Derby86240592018-05-24 16:12:31 -0400239 GrTextBlob::Run::PathGlyph& pathGlyph = run.fPathGlyphs[i];
Robert Phillips137ca522018-08-15 10:14:33 -0400240
Herb Derbydac1ed52018-09-12 17:04:21 -0400241 SkMatrix ctm;
Robert Phillips137ca522018-08-15 10:14:33 -0400242 const SkPath* path = &pathGlyph.fPath;
Herb Derbydac1ed52018-09-12 17:04:21 -0400243
244 // TmpPath must be in the same scope as GrShape shape below.
Robert Phillips137ca522018-08-15 10:14:33 -0400245 SkTLazy<SkPath> tmpPath;
246
Herb Derbydac1ed52018-09-12 17:04:21 -0400247 // The glyph positions and glyph outlines are either in device space or in source
248 // space based on fPreTransformed.
249 if (!pathGlyph.fPreTransformed) {
250 // Positions and outlines are in source space.
Robert Phillips137ca522018-08-15 10:14:33 -0400251
Herb Derbydac1ed52018-09-12 17:04:21 -0400252 ctm = viewMatrix;
Robert Phillipsd20d2612018-08-28 10:09:01 -0400253
Herb Derbydac1ed52018-09-12 17:04:21 -0400254 SkMatrix pathMatrix = SkMatrix::MakeScale(pathGlyph.fScale, pathGlyph.fScale);
Robert Phillipsd20d2612018-08-28 10:09:01 -0400255
Herb Derbydac1ed52018-09-12 17:04:21 -0400256 // The origin for the blob may have changed, so figure out the delta.
257 SkVector originShift = SkPoint{x, y} - SkPoint{fInitialX, fInitialY};
258
259 // Shift the original glyph location in source space to the position of the new
260 // blob.
261 pathMatrix.postTranslate(originShift.x() + pathGlyph.fX,
262 originShift.y() + pathGlyph.fY);
263
264 // If there are shaders, blurs or styles, the path must be scaled into source
265 // space independently of the CTM. This allows the CTM to be correct for the
266 // different effects.
267 GrStyle style(runPaint);
268 bool scalePath = runPaint.getShader()
269 || style.applies()
270 || runPaint.getMaskFilter();
271 if (!scalePath) {
272 // Scale can be applied to CTM -- no effects.
273
274 ctm.preConcat(pathMatrix);
275 } else {
276 // Scale the outline into source space.
277
278 // Transform the path form the normalized outline to source space. This
279 // way the CTM will remain the same so it can be used by the effects.
280 SkPath* sourceOutline = tmpPath.init();
281 path->transform(pathMatrix, sourceOutline);
282 sourceOutline->setIsVolatile(true);
283 path = sourceOutline;
284 }
285
286
Robert Phillipsd20d2612018-08-28 10:09:01 -0400287 } else {
Herb Derbydac1ed52018-09-12 17:04:21 -0400288 // Positions and outlines are in device space.
289
290 SkPoint originalOrigin = {fInitialX, fInitialY};
291 fInitialViewMatrix.mapPoints(&originalOrigin, 1);
292
293 SkPoint newOrigin = {x, y};
294 viewMatrix.mapPoints(&newOrigin, 1);
295
296 // The origin shift in device space.
297 SkPoint originShift = newOrigin - originalOrigin;
298
299 // Shift the original glyph location in device space to the position of the
300 // new blob.
301 ctm = SkMatrix::MakeTrans(originShift.x() + pathGlyph.fX,
302 originShift.y() + pathGlyph.fY);
Robert Phillips137ca522018-08-15 10:14:33 -0400303 }
304
Robert Phillips46a13382018-08-23 13:53:01 -0400305 // TODO: we are losing the mutability of the path here
306 GrShape shape(*path, paint);
307
Herb Derbydac1ed52018-09-12 17:04:21 -0400308 target->drawShape(clip, runPaint, ctm, shape);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500309 }
joshualitt2e2202e2015-12-10 11:22:08 -0800310 }
joshualitt2e2202e2015-12-10 11:22:08 -0800311
Jim Van Verth54d9c882018-02-08 16:14:48 -0500312 // then flush each subrun, if any
313 if (!run.fInitialized) {
Jim Van Verth89737de2018-02-06 21:30:20 +0000314 continue;
315 }
Herb Derbydac1ed52018-09-12 17:04:21 -0400316
Jim Van Verth54d9c882018-02-08 16:14:48 -0500317 int lastSubRun = SkTMin(run.fSubRunInfo.count(), 1 << 16) - 1;
318 for (int subRun = 0; subRun <= lastSubRun; subRun++) {
Herb Derby69ff8952018-11-12 11:39:12 -0500319 const SubRun& info = run.fSubRunInfo[subRun];
Jim Van Verth54d9c882018-02-08 16:14:48 -0500320 int glyphCount = info.glyphCount();
321 if (0 == glyphCount) {
322 continue;
323 }
324
325 bool skipClip = false;
326 bool submitOp = true;
327 SkIRect clipRect = SkIRect::MakeEmpty();
328 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
329 SkRRect clipRRect;
330 GrAA aa;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400331 // We can clip geometrically if we're not using SDFs or transformed glyphs,
Jim Van Verth54d9c882018-02-08 16:14:48 -0500332 // and we have an axis-aligned rectangular non-AA clip
Jim Van Verthb515ae72018-05-23 16:44:55 -0400333 if (!info.drawAsDistanceFields() && !info.needsTransform() &&
Jim Van Verthcf838c72018-03-05 14:40:36 -0500334 clip.isRRect(rtBounds, &clipRRect, &aa) &&
Jim Van Verth54d9c882018-02-08 16:14:48 -0500335 clipRRect.isRect() && GrAA::kNo == aa) {
336 skipClip = true;
337 // We only need to do clipping work if the subrun isn't contained by the clip
338 SkRect subRunBounds;
Jim Van Verth70276912018-06-01 13:46:46 -0400339 this->computeSubRunBounds(&subRunBounds, runIndex, subRun, viewMatrix, x, y,
340 false);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500341 if (!clipRRect.getBounds().contains(subRunBounds)) {
342 // If the subrun is completely outside, don't add an op for it
343 if (!clipRRect.getBounds().intersects(subRunBounds)) {
344 submitOp = false;
345 }
346 else {
347 clipRRect.getBounds().round(&clipRect);
348 }
349 }
350 }
351
352 if (submitOp) {
353 auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400354 clipRect, paint, filteredColor, props, distanceAdjustTable,
Robert Phillips5a66efb2018-03-07 15:13:18 -0500355 target);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500356 if (op) {
357 if (skipClip) {
358 target->addDrawOp(GrNoClip(), std::move(op));
359 }
360 else {
361 target->addDrawOp(clip, std::move(op));
362 }
363 }
364 }
365 }
366
Jim Van Verth89737de2018-02-06 21:30:20 +0000367 }
Jim Van Verth89737de2018-02-06 21:30:20 +0000368}
369
Herb Derby86240592018-05-24 16:12:31 -0400370std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400371 int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix,
Brian Osmancf860852018-10-31 14:04:39 -0400372 SkScalar x, SkScalar y, const SkPaint& paint, const SkPMColor4f& filteredColor,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400373 const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400374 GrTextTarget* target) {
Herb Derby69ff8952018-11-12 11:39:12 -0500375 const GrTextBlob::SubRun& info = fRuns[run].fSubRunInfo[subRun];
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400376 SkIRect emptyRect = SkIRect::MakeEmpty();
Herb Derbybc6f9c92018-08-08 13:58:45 -0400377 return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect,
378 paint, filteredColor, props, distanceAdjustTable, target);
joshualitt323c2eb2016-01-20 06:48:47 -0800379}
joshualitt2e2202e2015-12-10 11:22:08 -0800380
Herb Derby86240592018-05-24 16:12:31 -0400381void GrTextBlob::AssertEqual(const GrTextBlob& l, const GrTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800382 SkASSERT_RELEASE(l.fSize == r.fSize);
joshualitt259fbf12015-07-21 11:39:34 -0700383
joshualitt2f2ee832016-02-10 08:52:24 -0800384 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
385 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
joshualitt259fbf12015-07-21 11:39:34 -0700386
joshualitt2f2ee832016-02-10 08:52:24 -0800387 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
388 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
389 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700390
joshualitt2f2ee832016-02-10 08:52:24 -0800391 SkASSERT_RELEASE(l.fKey == r.fKey);
joshualitt2f2ee832016-02-10 08:52:24 -0800392 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
393 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
394 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
395 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700396
Herb Derby2bb343c2018-11-08 15:03:48 -0500397 SkASSERT_RELEASE(l.fRunCountLimit == r.fRunCountLimit);
398 for (int i = 0; i < l.fRunCountLimit; i++) {
joshualitt259fbf12015-07-21 11:39:34 -0700399 const Run& lRun = l.fRuns[i];
400 const Run& rRun = r.fRuns[i];
401
Herb Derbye7efd082019-05-28 11:30:33 -0400402 SkASSERT_RELEASE(lRun.fStrikeSpec.descriptor() == rRun.fStrikeSpec.descriptor());
joshualitt259fbf12015-07-21 11:39:34 -0700403
404 // color can be changed
405 //SkASSERT(lRun.fColor == rRun.fColor);
joshualitt2f2ee832016-02-10 08:52:24 -0800406 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
joshualitt259fbf12015-07-21 11:39:34 -0700407
joshualitt2f2ee832016-02-10 08:52:24 -0800408 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
joshualitt259fbf12015-07-21 11:39:34 -0700409 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
Herb Derby69ff8952018-11-12 11:39:12 -0500410 const SubRun& lSubRun = lRun.fSubRunInfo[j];
411 const SubRun& rSubRun = rRun.fSubRunInfo[j];
joshualitt259fbf12015-07-21 11:39:34 -0700412
joshualitt2f2ee832016-02-10 08:52:24 -0800413 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
414 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700415
joshualitt2f2ee832016-02-10 08:52:24 -0800416 if (lSubRun.strike()) {
417 SkASSERT_RELEASE(rSubRun.strike());
Robert Phillipscaf1ebb2018-03-01 14:28:44 -0500418 SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) ==
419 GrTextStrike::GetKey(*rSubRun.strike()));
joshualitt2f2ee832016-02-10 08:52:24 -0800420
421 } else {
422 SkASSERT_RELEASE(!rSubRun.strike());
423 }
424
425 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
426 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
427 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
428 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
429 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
430 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
431 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
joshualitt259fbf12015-07-21 11:39:34 -0700432 }
Jim Van Verth54d9c882018-02-08 16:14:48 -0500433
434 SkASSERT_RELEASE(lRun.fPathGlyphs.count() == rRun.fPathGlyphs.count());
435 for (int i = 0; i < lRun.fPathGlyphs.count(); i++) {
436 const Run::PathGlyph& lPathGlyph = lRun.fPathGlyphs[i];
437 const Run::PathGlyph& rPathGlyph = rRun.fPathGlyphs[i];
438
439 SkASSERT_RELEASE(lPathGlyph.fPath == rPathGlyph.fPath);
440 // We can't assert that these have the same translations
441 }
joshualitt259fbf12015-07-21 11:39:34 -0700442 }
443}
joshualitt8e0ef292016-02-19 14:13:03 -0800444
Herb Derby69ff8952018-11-12 11:39:12 -0500445void GrTextBlob::SubRun::computeTranslation(const SkMatrix& viewMatrix,
446 SkScalar x, SkScalar y, SkScalar* transX,
447 SkScalar* transY) {
Herb Derby5f7b0142018-12-14 16:47:45 -0500448 // Don't use the matrix to translate on distance field for fallback subruns.
449 calculate_translation(!this->drawAsDistanceFields() && !this->isFallback(), viewMatrix,
450 x, y, fCurrentViewMatrix, fX, fY, transX, transY);
joshualitt8e0ef292016-02-19 14:13:03 -0800451 fCurrentViewMatrix = viewMatrix;
452 fX = x;
453 fY = y;
454}