blob: 8feaa1a459eea1d51ccade1d5018492e02796426 [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
Herb Derby86240592018-05-24 16:12:31 -04008#include "GrTextBlob.h"
joshualitt2e2202e2015-12-10 11:22:08 -08009#include "GrBlurUtils.h"
Jim Van Verth58c3cce2017-10-19 15:50:24 -040010#include "GrClip.h"
joshualitt2e2202e2015-12-10 11:22:08 -080011#include "GrContext.h"
Robert Phillips46a13382018-08-23 13:53:01 -040012#include "GrShape.h"
Robert Phillips137ca522018-08-15 10:14:33 -040013#include "GrStyle.h"
Herb Derbyc1b482c2018-08-09 15:02:27 -040014#include "GrTextTarget.h"
joshualitt2e2202e2015-12-10 11:22:08 -080015#include "SkColorFilter.h"
Mike Reed80747ef2018-01-23 15:29:32 -050016#include "SkMaskFilterBase.h"
Mike Reedec7278e2019-02-01 14:00:34 -050017#include "SkPaintPriv.h"
Brian Salomon89527432016-12-16 09:52:16 -050018#include "ops/GrAtlasTextOp.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 Derby5424a5e2018-11-14 12:04:38 -050026sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount, int runCount, GrColor color) {
Herb Derby86240592018-05-24 16:12:31 -040027 // We allocate size for the GrTextBlob itself, plus size for the vertices array,
joshualitt92303772016-02-10 11:55:52 -080028 // and size for the glyphIds array.
29 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
Ben Wagner75d6db72018-09-20 14:39:39 -040030
Herb Derbyf7d5d742018-11-16 13:24:32 -050031 size_t blobStart = 0;
32 size_t vertex = sk_align<alignof(char)> (blobStart + sizeof(GrTextBlob) * 1);
Ben Wagner75d6db72018-09-20 14:39:39 -040033 size_t glyphs = sk_align<alignof(GrGlyph*)> (vertex + sizeof(char) * verticesCount);
34 size_t runs = sk_align<alignof(GrTextBlob::Run)>(glyphs + sizeof(GrGlyph*) * glyphCount);
35 size_t size = (runs + sizeof(GrTextBlob::Run) * runCount);
joshualitt92303772016-02-10 11:55:52 -080036
Herb Derbyb12175f2018-05-23 16:38:09 -040037 void* allocation = ::operator new (size);
38
joshualitt92303772016-02-10 11:55:52 -080039 if (CACHE_SANITY_CHECK) {
40 sk_bzero(allocation, size);
41 }
42
Herb Derbyf7d5d742018-11-16 13:24:32 -050043 sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{}};
44 blob->fSize = size;
joshualitt92303772016-02-10 11:55:52 -080045
46 // setup offsets for vertices / glyphs
Herb Derbyf7d5d742018-11-16 13:24:32 -050047 blob->fVertices = SkTAddOffset<char>(blob.get(), vertex);
48 blob->fGlyphs = SkTAddOffset<GrGlyph*>(blob.get(), glyphs);
49 blob->fRuns = SkTAddOffset<GrTextBlob::Run>(blob.get(), runs);
joshualitt92303772016-02-10 11:55:52 -080050
51 // Initialize runs
52 for (int i = 0; i < runCount; i++) {
Herb Derby5424a5e2018-11-14 12:04:38 -050053 new (&blob->fRuns[i]) GrTextBlob::Run{blob.get(), color};
joshualitt92303772016-02-10 11:55:52 -080054 }
Herb Derbyf7d5d742018-11-16 13:24:32 -050055 blob->fRunCountLimit = runCount;
56 return blob;
joshualitt92303772016-02-10 11:55:52 -080057}
58
Herb Derbya4c64872019-02-13 11:46:19 -050059void GrTextBlob::Run::setupFont(const SkStrikeSpec& strikeSpec) {
60 fTypeface = sk_ref_sp(&strikeSpec.typeface());
61 fPathEffect = sk_ref_sp(strikeSpec.effects().fPathEffect);
62 fMaskFilter = sk_ref_sp(strikeSpec.effects().fMaskFilter);
Herbert Derby86dbae92019-01-03 13:10:59 -050063 // if we have an override descriptor for the run, then we should use that
64 SkAutoDescriptor* desc =
65 fARGBFallbackDescriptor.get() ? fARGBFallbackDescriptor.get() : &fDescriptor;
66 // Set up the descriptor for possible cache lookups during regen.
Herb Derbya4c64872019-02-13 11:46:19 -050067 desc->reset(strikeSpec.desc());
Herbert Derby86dbae92019-01-03 13:10:59 -050068}
69
Herb Derby2bb343c2018-11-08 15:03:48 -050070void GrTextBlob::Run::appendPathGlyph(const SkPath& path, SkPoint position,
Jim Van Verth54d9c882018-02-08 16:14:48 -050071 SkScalar scale, bool preTransformed) {
Herb Derby2bb343c2018-11-08 15:03:48 -050072 fPathGlyphs.push_back(PathGlyph(path, position.x(), position.y(), scale, preTransformed));
joshualitta06e6ab2015-12-10 08:54:41 -080073}
74
Herb Derby0edb2142018-10-16 17:04:11 -040075bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosition,
76 const SkMaskFilterBase::BlurRec& blurRec,
77 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
joshualittfd5f6c12015-12-10 07:44:50 -080078 // If we have LCD text then our canonical color will be set to transparent, in this case we have
79 // to regenerate the blob on any color change
80 // We use the grPaint to get any color filter effects
81 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
Mike Reedec7278e2019-02-01 14:00:34 -050082 fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) {
joshualittfd5f6c12015-12-10 07:44:50 -080083 return true;
84 }
85
joshualitt8e0ef292016-02-19 14:13:03 -080086 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
joshualittfd5f6c12015-12-10 07:44:50 -080087 return true;
88 }
89
Brian Salomon5c6ac642017-12-19 11:09:32 -050090 /** This could be relaxed for blobs with only distance field glyphs. */
joshualitt8e0ef292016-02-19 14:13:03 -080091 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
joshualittfd5f6c12015-12-10 07:44:50 -080092 return true;
93 }
94
95 // We only cache one masked version
96 if (fKey.fHasBlur &&
Mike Reed1be1f8d2018-03-14 13:01:17 -040097 (fBlurRec.fSigma != blurRec.fSigma || fBlurRec.fStyle != blurRec.fStyle)) {
joshualittfd5f6c12015-12-10 07:44:50 -080098 return true;
99 }
100
101 // Similarly, we only cache one version for each style
102 if (fKey.fStyle != SkPaint::kFill_Style &&
Herb Derbybc6f9c92018-08-08 13:58:45 -0400103 (fStrokeInfo.fFrameWidth != paint.getStrokeWidth() ||
104 fStrokeInfo.fMiterLimit != paint.getStrokeMiter() ||
105 fStrokeInfo.fJoin != paint.getStrokeJoin())) {
joshualittfd5f6c12015-12-10 07:44:50 -0800106 return true;
107 }
108
109 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
110 // for mixed blobs if this becomes an issue.
111 if (this->hasBitmap() && this->hasDistanceField()) {
112 // Identical viewmatrices and we can reuse in all cases
joshualitt8e0ef292016-02-19 14:13:03 -0800113 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
joshualittfd5f6c12015-12-10 07:44:50 -0800114 return false;
115 }
116 return true;
117 }
118
119 if (this->hasBitmap()) {
joshualitt8e0ef292016-02-19 14:13:03 -0800120 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
121 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
122 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
123 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800124 return true;
125 }
126
Herb Derbycb65ce72018-10-17 11:39:41 -0400127 // If the text blob only has full pixel glyphs, then fractional part of the position does
128 // not affect the SkGlyphs used.
129 if (anyRunHasSubpixelPosition) {
130 // We can update the positions in the text blob without regenerating the whole
Herb Derby0edb2142018-10-16 17:04:11 -0400131 // blob, but only for integer translations.
132 // This cool bit of math will determine the necessary translation to apply to the
133 // already generated vertex coordinates to move them to the correct position.
134 SkScalar transX = viewMatrix.getTranslateX() +
135 viewMatrix.getScaleX() * (x - fInitialX) +
136 viewMatrix.getSkewX() * (y - fInitialY) -
137 fInitialViewMatrix.getTranslateX();
138 SkScalar transY = viewMatrix.getTranslateY() +
139 viewMatrix.getSkewY() * (x - fInitialX) +
140 viewMatrix.getScaleY() * (y - fInitialY) -
141 fInitialViewMatrix.getTranslateY();
142 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
143 return true;
144 }
joshualittfd5f6c12015-12-10 07:44:50 -0800145 }
joshualittfd5f6c12015-12-10 07:44:50 -0800146 } else if (this->hasDistanceField()) {
147 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
148 // distance field being generated, so we have to regenerate in those cases
149 SkScalar newMaxScale = viewMatrix.getMaxScale();
joshualitt8e0ef292016-02-19 14:13:03 -0800150 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
joshualittfd5f6c12015-12-10 07:44:50 -0800151 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
152 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
153 return true;
154 }
joshualittfd5f6c12015-12-10 07:44:50 -0800155 }
156
joshualittfd5f6c12015-12-10 07:44:50 -0800157 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
158 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
159 // the blob anyways at flush time, so no need to regenerate explicitly
160 return false;
161}
162
Herb Derby86240592018-05-24 16:12:31 -0400163inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(
Herb Derby69ff8952018-11-12 11:39:12 -0500164 const SubRun& info, int glyphCount, uint16_t run, uint16_t subRun,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400165 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
Brian Osmancf860852018-10-31 14:04:39 -0400166 const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps& props,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400167 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextTarget* target) {
joshualitt2e2202e2015-12-10 11:22:08 -0800168 GrMaskFormat format = info.maskFormat();
joshualitt2e2202e2015-12-10 11:22:08 -0800169
Brian Salomon44acb5b2017-07-18 19:59:24 -0400170 GrPaint grPaint;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400171 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
Brian Salomonf8334782017-01-03 09:42:58 -0500172 std::unique_ptr<GrAtlasTextOp> op;
joshualitt2e2202e2015-12-10 11:22:08 -0800173 if (info.drawAsDistanceFields()) {
Brian Osman34ec3742018-07-03 10:40:57 -0400174 // TODO: Can we be even smarter based on the dest transfer function?
Brian Salomon44acb5b2017-07-18 19:59:24 -0400175 op = GrAtlasTextOp::MakeDistanceField(
Robert Phillips7c525e62018-06-12 10:11:12 -0400176 target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable,
Mike Reedec7278e2019-02-01 14:00:34 -0500177 target->colorSpaceInfo().isLinearlyBlended(),
178 SkPaintPriv::ComputeLuminanceColor(paint),
Ben Wagner4c329562018-04-18 16:04:46 -0400179 props, info.isAntiAliased(), info.hasUseLCDText());
joshualitt2e2202e2015-12-10 11:22:08 -0800180 } else {
Robert Phillips7c525e62018-06-12 10:11:12 -0400181 op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount,
Jim Van Verthb515ae72018-05-23 16:44:55 -0400182 info.needsTransform());
joshualitt2e2202e2015-12-10 11:22:08 -0800183 }
Brian Salomon09d994e2016-12-21 11:14:46 -0500184 GrAtlasTextOp::Geometry& geometry = op->geometry();
joshualitt8e0ef292016-02-19 14:13:03 -0800185 geometry.fViewMatrix = viewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400186 geometry.fClipRect = clipRect;
joshualitt2e2202e2015-12-10 11:22:08 -0800187 geometry.fBlob = SkRef(this);
188 geometry.fRun = run;
189 geometry.fSubRun = subRun;
Brian Osmancf860852018-10-31 14:04:39 -0400190 geometry.fColor = info.maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE : filteredColor;
joshualitt8e0ef292016-02-19 14:13:03 -0800191 geometry.fX = x;
192 geometry.fY = y;
Brian Salomon09d994e2016-12-21 11:14:46 -0500193 op->init();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400194 return op;
joshualitt2e2202e2015-12-10 11:22:08 -0800195}
196
joshualitt8e0ef292016-02-19 14:13:03 -0800197static void calculate_translation(bool applyVM,
198 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
199 const SkMatrix& currentViewMatrix, SkScalar currentX,
200 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
201 if (applyVM) {
202 *transX = newViewMatrix.getTranslateX() +
203 newViewMatrix.getScaleX() * (newX - currentX) +
204 newViewMatrix.getSkewX() * (newY - currentY) -
205 currentViewMatrix.getTranslateX();
206
207 *transY = newViewMatrix.getTranslateY() +
208 newViewMatrix.getSkewY() * (newX - currentX) +
209 newViewMatrix.getScaleY() * (newY - currentY) -
210 currentViewMatrix.getTranslateY();
211 } else {
212 *transX = newX - currentX;
213 *transY = newY - currentY;
214 }
215}
216
Herb Derbyc1b482c2018-08-09 15:02:27 -0400217void GrTextBlob::flush(GrTextTarget* target, const SkSurfaceProps& props,
218 const GrDistanceFieldAdjustTable* distanceAdjustTable,
Brian Osmancf860852018-10-31 14:04:39 -0400219 const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip,
Robert Phillipse4643cc2018-08-14 13:01:29 -0400220 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
Jim Van Verth54d9c882018-02-08 16:14:48 -0500221
Herb Derby86240592018-05-24 16:12:31 -0400222 // GrTextBlob::makeOp only takes uint16_t values for run and subRun indices.
Jim Van Verth54d9c882018-02-08 16:14:48 -0500223 // Encountering something larger than this is highly unlikely, so we'll just not draw it.
Herb Derby2bb343c2018-11-08 15:03:48 -0500224 int lastRun = SkTMin(fRunCountLimit, (1 << 16)) - 1;
Herb Derbydac1ed52018-09-12 17:04:21 -0400225 // For each run in the GrTextBlob we're going to churn through all the glyphs.
226 // Each run is broken into a path part and a Mask / DFT / ARGB part.
Jim Van Verth54d9c882018-02-08 16:14:48 -0500227 for (int runIndex = 0; runIndex <= lastRun; runIndex++) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400228
Jim Van Verth54d9c882018-02-08 16:14:48 -0500229 Run& run = fRuns[runIndex];
230
231 // first flush any path glyphs
232 if (run.fPathGlyphs.count()) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400233 SkPaint runPaint{paint};
Mike Reed48b958b2018-12-03 13:09:02 -0500234 runPaint.setAntiAlias(run.fAntiAlias);
Herb Derby9f491482018-08-08 11:53:00 -0400235
Jim Van Verth54d9c882018-02-08 16:14:48 -0500236 for (int i = 0; i < run.fPathGlyphs.count(); i++) {
Herb Derby86240592018-05-24 16:12:31 -0400237 GrTextBlob::Run::PathGlyph& pathGlyph = run.fPathGlyphs[i];
Robert Phillips137ca522018-08-15 10:14:33 -0400238
Herb Derbydac1ed52018-09-12 17:04:21 -0400239 SkMatrix ctm;
Robert Phillips137ca522018-08-15 10:14:33 -0400240 const SkPath* path = &pathGlyph.fPath;
Herb Derbydac1ed52018-09-12 17:04:21 -0400241
242 // TmpPath must be in the same scope as GrShape shape below.
Robert Phillips137ca522018-08-15 10:14:33 -0400243 SkTLazy<SkPath> tmpPath;
244
Herb Derbydac1ed52018-09-12 17:04:21 -0400245 // The glyph positions and glyph outlines are either in device space or in source
246 // space based on fPreTransformed.
247 if (!pathGlyph.fPreTransformed) {
248 // Positions and outlines are in source space.
Robert Phillips137ca522018-08-15 10:14:33 -0400249
Herb Derbydac1ed52018-09-12 17:04:21 -0400250 ctm = viewMatrix;
Robert Phillipsd20d2612018-08-28 10:09:01 -0400251
Herb Derbydac1ed52018-09-12 17:04:21 -0400252 SkMatrix pathMatrix = SkMatrix::MakeScale(pathGlyph.fScale, pathGlyph.fScale);
Robert Phillipsd20d2612018-08-28 10:09:01 -0400253
Herb Derbydac1ed52018-09-12 17:04:21 -0400254 // The origin for the blob may have changed, so figure out the delta.
255 SkVector originShift = SkPoint{x, y} - SkPoint{fInitialX, fInitialY};
256
257 // Shift the original glyph location in source space to the position of the new
258 // blob.
259 pathMatrix.postTranslate(originShift.x() + pathGlyph.fX,
260 originShift.y() + pathGlyph.fY);
261
262 // If there are shaders, blurs or styles, the path must be scaled into source
263 // space independently of the CTM. This allows the CTM to be correct for the
264 // different effects.
265 GrStyle style(runPaint);
266 bool scalePath = runPaint.getShader()
267 || style.applies()
268 || runPaint.getMaskFilter();
269 if (!scalePath) {
270 // Scale can be applied to CTM -- no effects.
271
272 ctm.preConcat(pathMatrix);
273 } else {
274 // Scale the outline into source space.
275
276 // Transform the path form the normalized outline to source space. This
277 // way the CTM will remain the same so it can be used by the effects.
278 SkPath* sourceOutline = tmpPath.init();
279 path->transform(pathMatrix, sourceOutline);
280 sourceOutline->setIsVolatile(true);
281 path = sourceOutline;
282 }
283
284
Robert Phillipsd20d2612018-08-28 10:09:01 -0400285 } else {
Herb Derbydac1ed52018-09-12 17:04:21 -0400286 // Positions and outlines are in device space.
287
288 SkPoint originalOrigin = {fInitialX, fInitialY};
289 fInitialViewMatrix.mapPoints(&originalOrigin, 1);
290
291 SkPoint newOrigin = {x, y};
292 viewMatrix.mapPoints(&newOrigin, 1);
293
294 // The origin shift in device space.
295 SkPoint originShift = newOrigin - originalOrigin;
296
297 // Shift the original glyph location in device space to the position of the
298 // new blob.
299 ctm = SkMatrix::MakeTrans(originShift.x() + pathGlyph.fX,
300 originShift.y() + pathGlyph.fY);
Robert Phillips137ca522018-08-15 10:14:33 -0400301 }
302
Robert Phillips46a13382018-08-23 13:53:01 -0400303 // TODO: we are losing the mutability of the path here
304 GrShape shape(*path, paint);
305
Herb Derbydac1ed52018-09-12 17:04:21 -0400306 target->drawShape(clip, runPaint, ctm, shape);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500307 }
joshualitt2e2202e2015-12-10 11:22:08 -0800308 }
joshualitt2e2202e2015-12-10 11:22:08 -0800309
Jim Van Verth54d9c882018-02-08 16:14:48 -0500310 // then flush each subrun, if any
311 if (!run.fInitialized) {
Jim Van Verth89737de2018-02-06 21:30:20 +0000312 continue;
313 }
Herb Derbydac1ed52018-09-12 17:04:21 -0400314
Jim Van Verth54d9c882018-02-08 16:14:48 -0500315 int lastSubRun = SkTMin(run.fSubRunInfo.count(), 1 << 16) - 1;
316 for (int subRun = 0; subRun <= lastSubRun; subRun++) {
Herb Derby69ff8952018-11-12 11:39:12 -0500317 const SubRun& info = run.fSubRunInfo[subRun];
Jim Van Verth54d9c882018-02-08 16:14:48 -0500318 int glyphCount = info.glyphCount();
319 if (0 == glyphCount) {
320 continue;
321 }
322
323 bool skipClip = false;
324 bool submitOp = true;
325 SkIRect clipRect = SkIRect::MakeEmpty();
326 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
327 SkRRect clipRRect;
328 GrAA aa;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400329 // We can clip geometrically if we're not using SDFs or transformed glyphs,
Jim Van Verth54d9c882018-02-08 16:14:48 -0500330 // and we have an axis-aligned rectangular non-AA clip
Jim Van Verthb515ae72018-05-23 16:44:55 -0400331 if (!info.drawAsDistanceFields() && !info.needsTransform() &&
Jim Van Verthcf838c72018-03-05 14:40:36 -0500332 clip.isRRect(rtBounds, &clipRRect, &aa) &&
Jim Van Verth54d9c882018-02-08 16:14:48 -0500333 clipRRect.isRect() && GrAA::kNo == aa) {
334 skipClip = true;
335 // We only need to do clipping work if the subrun isn't contained by the clip
336 SkRect subRunBounds;
Jim Van Verth70276912018-06-01 13:46:46 -0400337 this->computeSubRunBounds(&subRunBounds, runIndex, subRun, viewMatrix, x, y,
338 false);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500339 if (!clipRRect.getBounds().contains(subRunBounds)) {
340 // If the subrun is completely outside, don't add an op for it
341 if (!clipRRect.getBounds().intersects(subRunBounds)) {
342 submitOp = false;
343 }
344 else {
345 clipRRect.getBounds().round(&clipRect);
346 }
347 }
348 }
349
350 if (submitOp) {
351 auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400352 clipRect, paint, filteredColor, props, distanceAdjustTable,
Robert Phillips5a66efb2018-03-07 15:13:18 -0500353 target);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500354 if (op) {
355 if (skipClip) {
356 target->addDrawOp(GrNoClip(), std::move(op));
357 }
358 else {
359 target->addDrawOp(clip, std::move(op));
360 }
361 }
362 }
363 }
364
Jim Van Verth89737de2018-02-06 21:30:20 +0000365 }
Jim Van Verth89737de2018-02-06 21:30:20 +0000366}
367
Herb Derby86240592018-05-24 16:12:31 -0400368std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400369 int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix,
Brian Osmancf860852018-10-31 14:04:39 -0400370 SkScalar x, SkScalar y, const SkPaint& paint, const SkPMColor4f& filteredColor,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400371 const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400372 GrTextTarget* target) {
Herb Derby69ff8952018-11-12 11:39:12 -0500373 const GrTextBlob::SubRun& info = fRuns[run].fSubRunInfo[subRun];
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400374 SkIRect emptyRect = SkIRect::MakeEmpty();
Herb Derbybc6f9c92018-08-08 13:58:45 -0400375 return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect,
376 paint, filteredColor, props, distanceAdjustTable, target);
joshualitt323c2eb2016-01-20 06:48:47 -0800377}
joshualitt2e2202e2015-12-10 11:22:08 -0800378
Herb Derby86240592018-05-24 16:12:31 -0400379void GrTextBlob::AssertEqual(const GrTextBlob& l, const GrTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800380 SkASSERT_RELEASE(l.fSize == r.fSize);
joshualitt259fbf12015-07-21 11:39:34 -0700381
joshualitt2f2ee832016-02-10 08:52:24 -0800382 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
383 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
joshualitt259fbf12015-07-21 11:39:34 -0700384
joshualitt2f2ee832016-02-10 08:52:24 -0800385 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
386 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
387 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700388
joshualitt2f2ee832016-02-10 08:52:24 -0800389 SkASSERT_RELEASE(l.fKey == r.fKey);
joshualitt2f2ee832016-02-10 08:52:24 -0800390 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
391 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
392 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
393 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700394
Herb Derby2bb343c2018-11-08 15:03:48 -0500395 SkASSERT_RELEASE(l.fRunCountLimit == r.fRunCountLimit);
396 for (int i = 0; i < l.fRunCountLimit; i++) {
joshualitt259fbf12015-07-21 11:39:34 -0700397 const Run& lRun = l.fRuns[i];
398 const Run& rRun = r.fRuns[i];
399
joshualitt259fbf12015-07-21 11:39:34 -0700400 if (lRun.fTypeface.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800401 SkASSERT_RELEASE(rRun.fTypeface.get());
Hal Canary144caf52016-11-07 17:57:18 -0500402 SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface.get(), rRun.fTypeface.get()));
joshualitt259fbf12015-07-21 11:39:34 -0700403 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800404 SkASSERT_RELEASE(!rRun.fTypeface.get());
joshualitt259fbf12015-07-21 11:39:34 -0700405 }
406
joshualitt259fbf12015-07-21 11:39:34 -0700407
joshualitt2f2ee832016-02-10 08:52:24 -0800408 SkASSERT_RELEASE(lRun.fDescriptor.getDesc());
409 SkASSERT_RELEASE(rRun.fDescriptor.getDesc());
bsalomonc5d07fa2016-05-17 10:17:45 -0700410 SkASSERT_RELEASE(*lRun.fDescriptor.getDesc() == *rRun.fDescriptor.getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700411
Herb Derby317adf72018-11-16 17:29:29 -0500412 if (lRun.fARGBFallbackDescriptor.get()) {
413 SkASSERT_RELEASE(lRun.fARGBFallbackDescriptor->getDesc());
414 SkASSERT_RELEASE(rRun.fARGBFallbackDescriptor.get() && rRun.fARGBFallbackDescriptor->getDesc());
415 SkASSERT_RELEASE(*lRun.fARGBFallbackDescriptor->getDesc() ==
416 *rRun.fARGBFallbackDescriptor->getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700417 } else {
Herb Derby317adf72018-11-16 17:29:29 -0500418 SkASSERT_RELEASE(!rRun.fARGBFallbackDescriptor.get());
joshualitt259fbf12015-07-21 11:39:34 -0700419 }
420
421 // color can be changed
422 //SkASSERT(lRun.fColor == rRun.fColor);
joshualitt2f2ee832016-02-10 08:52:24 -0800423 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
joshualitt259fbf12015-07-21 11:39:34 -0700424
joshualitt2f2ee832016-02-10 08:52:24 -0800425 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
joshualitt259fbf12015-07-21 11:39:34 -0700426 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
Herb Derby69ff8952018-11-12 11:39:12 -0500427 const SubRun& lSubRun = lRun.fSubRunInfo[j];
428 const SubRun& rSubRun = rRun.fSubRunInfo[j];
joshualitt259fbf12015-07-21 11:39:34 -0700429
joshualitt2f2ee832016-02-10 08:52:24 -0800430 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
431 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700432
joshualitt2f2ee832016-02-10 08:52:24 -0800433 if (lSubRun.strike()) {
434 SkASSERT_RELEASE(rSubRun.strike());
Robert Phillipscaf1ebb2018-03-01 14:28:44 -0500435 SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) ==
436 GrTextStrike::GetKey(*rSubRun.strike()));
joshualitt2f2ee832016-02-10 08:52:24 -0800437
438 } else {
439 SkASSERT_RELEASE(!rSubRun.strike());
440 }
441
442 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
443 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
444 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
445 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
446 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
447 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
448 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
joshualitt259fbf12015-07-21 11:39:34 -0700449 }
Jim Van Verth54d9c882018-02-08 16:14:48 -0500450
451 SkASSERT_RELEASE(lRun.fPathGlyphs.count() == rRun.fPathGlyphs.count());
452 for (int i = 0; i < lRun.fPathGlyphs.count(); i++) {
453 const Run::PathGlyph& lPathGlyph = lRun.fPathGlyphs[i];
454 const Run::PathGlyph& rPathGlyph = rRun.fPathGlyphs[i];
455
456 SkASSERT_RELEASE(lPathGlyph.fPath == rPathGlyph.fPath);
457 // We can't assert that these have the same translations
458 }
joshualitt259fbf12015-07-21 11:39:34 -0700459 }
460}
joshualitt8e0ef292016-02-19 14:13:03 -0800461
Herb Derby69ff8952018-11-12 11:39:12 -0500462void GrTextBlob::SubRun::computeTranslation(const SkMatrix& viewMatrix,
463 SkScalar x, SkScalar y, SkScalar* transX,
464 SkScalar* transY) {
Herb Derby5f7b0142018-12-14 16:47:45 -0500465 // Don't use the matrix to translate on distance field for fallback subruns.
466 calculate_translation(!this->drawAsDistanceFields() && !this->isFallback(), viewMatrix,
467 x, y, fCurrentViewMatrix, fX, fY, transX, transY);
joshualitt8e0ef292016-02-19 14:13:03 -0800468 fCurrentViewMatrix = viewMatrix;
469 fX = x;
470 fY = y;
471}